2 * Copyright © 2008 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Keith Packard <keithp@keithp.com>
28 #include <linux/i2c.h>
29 #include <linux/slab.h>
30 #include <linux/export.h>
31 #include <linux/types.h>
32 #include <linux/notifier.h>
33 #include <linux/reboot.h>
34 #include <asm/byteorder.h>
36 #include <drm/drm_atomic_helper.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_crtc_helper.h>
39 #include <drm/drm_dp_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_hdcp.h>
42 #include "intel_drv.h"
43 #include <drm/i915_drm.h>
46 #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
47 #define DP_DPRX_ESI_LEN 14
49 /* Compliance test status bits */
50 #define INTEL_DP_RESOLUTION_SHIFT_MASK 0
51 #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
52 #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
53 #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
60 static const struct dp_link_dpll gen4_dpll[] = {
62 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
64 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
67 static const struct dp_link_dpll pch_dpll[] = {
69 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
71 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
74 static const struct dp_link_dpll vlv_dpll[] = {
76 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
78 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
82 * CHV supports eDP 1.4 that have more link rates.
83 * Below only provides the fixed rate but exclude variable rate.
85 static const struct dp_link_dpll chv_dpll[] = {
87 * CHV requires to program fractional division for m2.
88 * m2 is stored in fixed point format using formula below
89 * (m2_int << 22) | m2_fraction
91 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
92 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
93 { 270000, /* m2_int = 27, m2_fraction = 0 */
94 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
95 { 540000, /* m2_int = 27, m2_fraction = 0 */
96 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
100 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
101 * @intel_dp: DP struct
103 * If a CPU or PCH DP output is attached to an eDP panel, this function
104 * will return true, and false otherwise.
106 bool intel_dp_is_edp(struct intel_dp *intel_dp)
108 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
110 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
113 static struct drm_device *intel_dp_to_dev(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.base.dev;
120 static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
122 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
125 static void intel_dp_link_down(struct intel_encoder *encoder,
126 const struct intel_crtc_state *old_crtc_state);
127 static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
128 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
129 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
130 const struct intel_crtc_state *crtc_state);
131 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
133 static void intel_dp_unset_edid(struct intel_dp *intel_dp);
135 /* update sink rates from dpcd */
136 static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
138 static const int dp_rates[] = {
139 162000, 270000, 540000, 810000
143 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]);
145 for (i = 0; i < ARRAY_SIZE(dp_rates); i++) {
146 if (dp_rates[i] > max_rate)
148 intel_dp->sink_rates[i] = dp_rates[i];
151 intel_dp->num_sink_rates = i;
154 /* Get length of rates array potentially limited by max_rate. */
155 static int intel_dp_rate_limit_len(const int *rates, int len, int max_rate)
159 /* Limit results by potentially reduced max rate */
160 for (i = 0; i < len; i++) {
161 if (rates[len - i - 1] <= max_rate)
168 /* Get length of common rates array potentially limited by max_rate. */
169 static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp,
172 return intel_dp_rate_limit_len(intel_dp->common_rates,
173 intel_dp->num_common_rates, max_rate);
176 /* Theoretical max between source and sink */
177 static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
179 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
182 /* Theoretical max between source and sink */
183 static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
185 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
186 int source_max = intel_dig_port->max_lanes;
187 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
189 return min(source_max, sink_max);
192 int intel_dp_max_lane_count(struct intel_dp *intel_dp)
194 return intel_dp->max_link_lane_count;
198 intel_dp_link_required(int pixel_clock, int bpp)
200 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
201 return DIV_ROUND_UP(pixel_clock * bpp, 8);
205 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
207 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
208 * link rate that is generally expressed in Gbps. Since, 8 bits of data
209 * is transmitted every LS_Clk per lane, there is no need to account for
210 * the channel encoding that is done in the PHY layer here.
213 return max_link_clock * max_lanes;
217 intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
219 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
220 struct intel_encoder *encoder = &intel_dig_port->base;
221 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
222 int max_dotclk = dev_priv->max_dotclk_freq;
225 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
227 if (type != DP_DS_PORT_TYPE_VGA)
230 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
231 intel_dp->downstream_ports);
233 if (ds_max_dotclk != 0)
234 max_dotclk = min(max_dotclk, ds_max_dotclk);
239 static int cnl_max_source_rate(struct intel_dp *intel_dp)
241 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
242 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
243 enum port port = dig_port->base.port;
245 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
247 /* Low voltage SKUs are limited to max of 5.4G */
248 if (voltage == VOLTAGE_INFO_0_85V)
251 /* For this SKU 8.1G is supported in all ports */
252 if (IS_CNL_WITH_PORT_F(dev_priv))
255 /* For other SKUs, max rate on ports A and D is 5.4G */
256 if (port == PORT_A || port == PORT_D)
263 intel_dp_set_source_rates(struct intel_dp *intel_dp)
265 /* The values must be in increasing order */
266 static const int cnl_rates[] = {
267 162000, 216000, 270000, 324000, 432000, 540000, 648000, 810000
269 static const int bxt_rates[] = {
270 162000, 216000, 243000, 270000, 324000, 432000, 540000
272 static const int skl_rates[] = {
273 162000, 216000, 270000, 324000, 432000, 540000
275 static const int hsw_rates[] = {
276 162000, 270000, 540000
278 static const int g4x_rates[] = {
281 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
282 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
283 const struct ddi_vbt_port_info *info =
284 &dev_priv->vbt.ddi_port_info[dig_port->base.port];
285 const int *source_rates;
286 int size, max_rate = 0, vbt_max_rate = info->dp_max_link_rate;
288 /* This should only be done once */
289 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
291 if (IS_CANNONLAKE(dev_priv)) {
292 source_rates = cnl_rates;
293 size = ARRAY_SIZE(cnl_rates);
294 max_rate = cnl_max_source_rate(intel_dp);
295 } else if (IS_GEN9_LP(dev_priv)) {
296 source_rates = bxt_rates;
297 size = ARRAY_SIZE(bxt_rates);
298 } else if (IS_GEN9_BC(dev_priv)) {
299 source_rates = skl_rates;
300 size = ARRAY_SIZE(skl_rates);
301 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
302 IS_BROADWELL(dev_priv)) {
303 source_rates = hsw_rates;
304 size = ARRAY_SIZE(hsw_rates);
306 source_rates = g4x_rates;
307 size = ARRAY_SIZE(g4x_rates);
310 if (max_rate && vbt_max_rate)
311 max_rate = min(max_rate, vbt_max_rate);
312 else if (vbt_max_rate)
313 max_rate = vbt_max_rate;
316 size = intel_dp_rate_limit_len(source_rates, size, max_rate);
318 intel_dp->source_rates = source_rates;
319 intel_dp->num_source_rates = size;
322 static int intersect_rates(const int *source_rates, int source_len,
323 const int *sink_rates, int sink_len,
326 int i = 0, j = 0, k = 0;
328 while (i < source_len && j < sink_len) {
329 if (source_rates[i] == sink_rates[j]) {
330 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
332 common_rates[k] = source_rates[i];
336 } else if (source_rates[i] < sink_rates[j]) {
345 /* return index of rate in rates array, or -1 if not found */
346 static int intel_dp_rate_index(const int *rates, int len, int rate)
350 for (i = 0; i < len; i++)
351 if (rate == rates[i])
357 static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
359 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
361 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
362 intel_dp->num_source_rates,
363 intel_dp->sink_rates,
364 intel_dp->num_sink_rates,
365 intel_dp->common_rates);
367 /* Paranoia, there should always be something in common. */
368 if (WARN_ON(intel_dp->num_common_rates == 0)) {
369 intel_dp->common_rates[0] = 162000;
370 intel_dp->num_common_rates = 1;
374 static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
378 * FIXME: we need to synchronize the current link parameters with
379 * hardware readout. Currently fast link training doesn't work on
382 if (link_rate == 0 ||
383 link_rate > intel_dp->max_link_rate)
386 if (lane_count == 0 ||
387 lane_count > intel_dp_max_lane_count(intel_dp))
393 int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
394 int link_rate, uint8_t lane_count)
398 index = intel_dp_rate_index(intel_dp->common_rates,
399 intel_dp->num_common_rates,
402 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
403 intel_dp->max_link_lane_count = lane_count;
404 } else if (lane_count > 1) {
405 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
406 intel_dp->max_link_lane_count = lane_count >> 1;
408 DRM_ERROR("Link Training Unsuccessful\n");
415 static enum drm_mode_status
416 intel_dp_mode_valid(struct drm_connector *connector,
417 struct drm_display_mode *mode)
419 struct intel_dp *intel_dp = intel_attached_dp(connector);
420 struct intel_connector *intel_connector = to_intel_connector(connector);
421 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
422 int target_clock = mode->clock;
423 int max_rate, mode_rate, max_lanes, max_link_clock;
426 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
428 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
429 if (mode->hdisplay > fixed_mode->hdisplay)
432 if (mode->vdisplay > fixed_mode->vdisplay)
435 target_clock = fixed_mode->clock;
438 max_link_clock = intel_dp_max_link_rate(intel_dp);
439 max_lanes = intel_dp_max_lane_count(intel_dp);
441 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
442 mode_rate = intel_dp_link_required(target_clock, 18);
444 if (mode_rate > max_rate || target_clock > max_dotclk)
445 return MODE_CLOCK_HIGH;
447 if (mode->clock < 10000)
448 return MODE_CLOCK_LOW;
450 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
451 return MODE_H_ILLEGAL;
456 uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
463 for (i = 0; i < src_bytes; i++)
464 v |= ((uint32_t) src[i]) << ((3-i) * 8);
468 static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
473 for (i = 0; i < dst_bytes; i++)
474 dst[i] = src >> ((3-i) * 8);
478 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp);
480 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
481 bool force_disable_vdd);
483 intel_dp_pps_init(struct intel_dp *intel_dp);
485 static void pps_lock(struct intel_dp *intel_dp)
487 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
490 * See intel_power_sequencer_reset() why we need
491 * a power domain reference here.
493 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
495 mutex_lock(&dev_priv->pps_mutex);
498 static void pps_unlock(struct intel_dp *intel_dp)
500 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
502 mutex_unlock(&dev_priv->pps_mutex);
504 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
508 vlv_power_sequencer_kick(struct intel_dp *intel_dp)
510 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
511 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
512 enum pipe pipe = intel_dp->pps_pipe;
513 bool pll_enabled, release_cl_override = false;
514 enum dpio_phy phy = DPIO_PHY(pipe);
515 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
518 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
519 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
520 pipe_name(pipe), port_name(intel_dig_port->base.port)))
523 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
524 pipe_name(pipe), port_name(intel_dig_port->base.port));
526 /* Preserve the BIOS-computed detected bit. This is
527 * supposed to be read-only.
529 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
530 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
531 DP |= DP_PORT_WIDTH(1);
532 DP |= DP_LINK_TRAIN_PAT_1;
534 if (IS_CHERRYVIEW(dev_priv))
535 DP |= DP_PIPE_SELECT_CHV(pipe);
536 else if (pipe == PIPE_B)
537 DP |= DP_PIPEB_SELECT;
539 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
542 * The DPLL for the pipe must be enabled for this to work.
543 * So enable temporarily it if it's not already enabled.
546 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
547 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
549 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
550 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
551 DRM_ERROR("Failed to force on pll for pipe %c!\n",
558 * Similar magic as in intel_dp_enable_port().
559 * We _must_ do this port enable + disable trick
560 * to make this power seqeuencer lock onto the port.
561 * Otherwise even VDD force bit won't work.
563 I915_WRITE(intel_dp->output_reg, DP);
564 POSTING_READ(intel_dp->output_reg);
566 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
567 POSTING_READ(intel_dp->output_reg);
569 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
570 POSTING_READ(intel_dp->output_reg);
573 vlv_force_pll_off(dev_priv, pipe);
575 if (release_cl_override)
576 chv_phy_powergate_ch(dev_priv, phy, ch, false);
580 static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
582 struct intel_encoder *encoder;
583 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
586 * We don't have power sequencer currently.
587 * Pick one that's not used by other ports.
589 for_each_intel_encoder(&dev_priv->drm, encoder) {
590 struct intel_dp *intel_dp;
592 if (encoder->type != INTEL_OUTPUT_DP &&
593 encoder->type != INTEL_OUTPUT_EDP)
596 intel_dp = enc_to_intel_dp(&encoder->base);
598 if (encoder->type == INTEL_OUTPUT_EDP) {
599 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
600 intel_dp->active_pipe != intel_dp->pps_pipe);
602 if (intel_dp->pps_pipe != INVALID_PIPE)
603 pipes &= ~(1 << intel_dp->pps_pipe);
605 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
607 if (intel_dp->active_pipe != INVALID_PIPE)
608 pipes &= ~(1 << intel_dp->active_pipe);
615 return ffs(pipes) - 1;
619 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
621 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
622 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
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 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
631 intel_dp->active_pipe != intel_dp->pps_pipe);
633 if (intel_dp->pps_pipe != INVALID_PIPE)
634 return intel_dp->pps_pipe;
636 pipe = vlv_find_free_pps(dev_priv);
639 * Didn't find one. This should not happen since there
640 * are two power sequencers and up to two eDP ports.
642 if (WARN_ON(pipe == INVALID_PIPE))
645 vlv_steal_power_sequencer(dev_priv, pipe);
646 intel_dp->pps_pipe = pipe;
648 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
649 pipe_name(intel_dp->pps_pipe),
650 port_name(intel_dig_port->base.port));
652 /* init power sequencer on this pipe and port */
653 intel_dp_init_panel_power_sequencer(intel_dp);
654 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
657 * Even vdd force doesn't work until we've made
658 * the power sequencer lock in on the port.
660 vlv_power_sequencer_kick(intel_dp);
662 return intel_dp->pps_pipe;
666 bxt_power_sequencer_idx(struct intel_dp *intel_dp)
668 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
669 int backlight_controller = dev_priv->vbt.backlight.controller;
671 lockdep_assert_held(&dev_priv->pps_mutex);
673 /* We should never land here with regular DP ports */
674 WARN_ON(!intel_dp_is_edp(intel_dp));
676 if (!intel_dp->pps_reset)
677 return backlight_controller;
679 intel_dp->pps_reset = false;
682 * Only the HW needs to be reprogrammed, the SW state is fixed and
683 * has been setup during connector init.
685 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
687 return backlight_controller;
690 typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
693 static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
696 return I915_READ(PP_STATUS(pipe)) & PP_ON;
699 static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
702 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
705 static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
712 vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
714 vlv_pipe_check pipe_check)
718 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
719 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
720 PANEL_PORT_SELECT_MASK;
722 if (port_sel != PANEL_PORT_SELECT_VLV(port))
725 if (!pipe_check(dev_priv, pipe))
735 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
737 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
738 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
739 enum port port = intel_dig_port->base.port;
741 lockdep_assert_held(&dev_priv->pps_mutex);
743 /* try to find a pipe with this port selected */
744 /* first pick one where the panel is on */
745 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
747 /* didn't find one? pick one where vdd is on */
748 if (intel_dp->pps_pipe == INVALID_PIPE)
749 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
750 vlv_pipe_has_vdd_on);
751 /* didn't find one? pick one with just the correct port */
752 if (intel_dp->pps_pipe == INVALID_PIPE)
753 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
756 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
757 if (intel_dp->pps_pipe == INVALID_PIPE) {
758 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
763 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
764 port_name(port), pipe_name(intel_dp->pps_pipe));
766 intel_dp_init_panel_power_sequencer(intel_dp);
767 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
770 void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
772 struct intel_encoder *encoder;
774 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
775 !IS_GEN9_LP(dev_priv)))
779 * We can't grab pps_mutex here due to deadlock with power_domain
780 * mutex when power_domain functions are called while holding pps_mutex.
781 * That also means that in order to use pps_pipe the code needs to
782 * hold both a power domain reference and pps_mutex, and the power domain
783 * reference get/put must be done while _not_ holding pps_mutex.
784 * pps_{lock,unlock}() do these steps in the correct order, so one
785 * should use them always.
788 for_each_intel_encoder(&dev_priv->drm, encoder) {
789 struct intel_dp *intel_dp;
791 if (encoder->type != INTEL_OUTPUT_DP &&
792 encoder->type != INTEL_OUTPUT_EDP &&
793 encoder->type != INTEL_OUTPUT_DDI)
796 intel_dp = enc_to_intel_dp(&encoder->base);
798 /* Skip pure DVI/HDMI DDI encoders */
799 if (!i915_mmio_reg_valid(intel_dp->output_reg))
802 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
804 if (encoder->type != INTEL_OUTPUT_EDP)
807 if (IS_GEN9_LP(dev_priv))
808 intel_dp->pps_reset = true;
810 intel_dp->pps_pipe = INVALID_PIPE;
814 struct pps_registers {
822 static void intel_pps_get_registers(struct intel_dp *intel_dp,
823 struct pps_registers *regs)
825 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
828 memset(regs, 0, sizeof(*regs));
830 if (IS_GEN9_LP(dev_priv))
831 pps_idx = bxt_power_sequencer_idx(intel_dp);
832 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
833 pps_idx = vlv_power_sequencer_pipe(intel_dp);
835 regs->pp_ctrl = PP_CONTROL(pps_idx);
836 regs->pp_stat = PP_STATUS(pps_idx);
837 regs->pp_on = PP_ON_DELAYS(pps_idx);
838 regs->pp_off = PP_OFF_DELAYS(pps_idx);
839 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) &&
840 !HAS_PCH_ICP(dev_priv))
841 regs->pp_div = PP_DIVISOR(pps_idx);
845 _pp_ctrl_reg(struct intel_dp *intel_dp)
847 struct pps_registers regs;
849 intel_pps_get_registers(intel_dp, ®s);
855 _pp_stat_reg(struct intel_dp *intel_dp)
857 struct pps_registers regs;
859 intel_pps_get_registers(intel_dp, ®s);
864 /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
865 This function only applicable when panel PM state is not to be tracked */
866 static int edp_notify_handler(struct notifier_block *this, unsigned long code,
869 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
871 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
873 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
878 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
879 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
880 i915_reg_t pp_ctrl_reg, pp_div_reg;
883 pp_ctrl_reg = PP_CONTROL(pipe);
884 pp_div_reg = PP_DIVISOR(pipe);
885 pp_div = I915_READ(pp_div_reg);
886 pp_div &= PP_REFERENCE_DIVIDER_MASK;
888 /* 0x1F write to PP_DIV_REG sets max cycle delay */
889 I915_WRITE(pp_div_reg, pp_div | 0x1F);
890 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
891 msleep(intel_dp->panel_power_cycle_delay);
894 pps_unlock(intel_dp);
899 static bool edp_have_panel_power(struct intel_dp *intel_dp)
901 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
903 lockdep_assert_held(&dev_priv->pps_mutex);
905 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
906 intel_dp->pps_pipe == INVALID_PIPE)
909 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
912 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
914 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
916 lockdep_assert_held(&dev_priv->pps_mutex);
918 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
919 intel_dp->pps_pipe == INVALID_PIPE)
922 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
926 intel_dp_check_edp(struct intel_dp *intel_dp)
928 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
930 if (!intel_dp_is_edp(intel_dp))
933 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
934 WARN(1, "eDP powered off while attempting aux channel communication.\n");
935 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
936 I915_READ(_pp_stat_reg(intel_dp)),
937 I915_READ(_pp_ctrl_reg(intel_dp)));
942 intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
944 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
945 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
949 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
951 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
952 msecs_to_jiffies_timeout(10));
954 done = wait_for(C, 10) == 0;
956 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
963 static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
965 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
971 * The clock divider is based off the hrawclk, and would like to run at
972 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
974 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
977 static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
979 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
985 * The clock divider is based off the cdclk or PCH rawclk, and would
986 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
987 * divide by 2000 and use that
989 if (intel_dp->aux_ch == AUX_CH_A)
990 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
992 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
995 static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
997 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
999 if (intel_dp->aux_ch != AUX_CH_A && HAS_PCH_LPT_H(dev_priv)) {
1000 /* Workaround for non-ULT HSW */
1008 return ilk_get_aux_clock_divider(intel_dp, index);
1011 static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1014 * SKL doesn't need us to program the AUX clock divider (Hardware will
1015 * derive the clock from CDCLK automatically). We still implement the
1016 * get_aux_clock_divider vfunc to plug-in into the existing code.
1018 return index ? 0 : 1;
1021 static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1024 uint32_t aux_clock_divider)
1026 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1027 struct drm_i915_private *dev_priv =
1028 to_i915(intel_dig_port->base.base.dev);
1029 uint32_t precharge, timeout;
1031 if (IS_GEN6(dev_priv))
1036 if (IS_BROADWELL(dev_priv))
1037 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1039 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1041 return DP_AUX_CH_CTL_SEND_BUSY |
1042 DP_AUX_CH_CTL_DONE |
1043 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1044 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1046 DP_AUX_CH_CTL_RECEIVE_ERROR |
1047 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1048 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1049 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
1052 static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1057 return DP_AUX_CH_CTL_SEND_BUSY |
1058 DP_AUX_CH_CTL_DONE |
1059 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1060 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1061 DP_AUX_CH_CTL_TIME_OUT_MAX |
1062 DP_AUX_CH_CTL_RECEIVE_ERROR |
1063 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1064 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
1065 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1068 static uint32_t intel_dp_get_aux_send_ctl(struct intel_dp *intel_dp,
1071 uint32_t aux_clock_divider,
1078 val |= DP_AUX_CH_CTL_AUX_AKSV_SELECT;
1081 return val | intel_dp->get_aux_send_ctl(intel_dp,
1088 intel_dp_aux_ch(struct intel_dp *intel_dp,
1089 const uint8_t *send, int send_bytes,
1090 uint8_t *recv, int recv_size, bool aksv_write)
1092 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1093 struct drm_i915_private *dev_priv =
1094 to_i915(intel_dig_port->base.base.dev);
1095 i915_reg_t ch_ctl, ch_data[5];
1096 uint32_t aux_clock_divider;
1097 int i, ret, recv_bytes;
1100 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
1103 ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
1104 for (i = 0; i < ARRAY_SIZE(ch_data); i++)
1105 ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i);
1110 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1111 * In such cases we want to leave VDD enabled and it's up to upper layers
1112 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1115 vdd = edp_panel_vdd_on(intel_dp);
1117 /* dp aux is extremely sensitive to irq latency, hence request the
1118 * lowest possible wakeup latency and so prevent the cpu from going into
1119 * deep sleep states.
1121 pm_qos_update_request(&dev_priv->pm_qos, 0);
1123 intel_dp_check_edp(intel_dp);
1125 /* Try to wait for any previous AUX channel activity */
1126 for (try = 0; try < 3; try++) {
1127 status = I915_READ_NOTRACE(ch_ctl);
1128 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1134 static u32 last_status = -1;
1135 const u32 status = I915_READ(ch_ctl);
1137 if (status != last_status) {
1138 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1140 last_status = status;
1147 /* Only 5 data registers! */
1148 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1153 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
1154 u32 send_ctl = intel_dp_get_aux_send_ctl(intel_dp,
1160 /* Must try at least 3 times according to DP spec */
1161 for (try = 0; try < 5; try++) {
1162 /* Load the send data into the aux channel data registers */
1163 for (i = 0; i < send_bytes; i += 4)
1164 I915_WRITE(ch_data[i >> 2],
1165 intel_dp_pack_aux(send + i,
1168 /* Send the command and wait for it to complete */
1169 I915_WRITE(ch_ctl, send_ctl);
1171 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
1173 /* Clear done status and any errors */
1176 DP_AUX_CH_CTL_DONE |
1177 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1178 DP_AUX_CH_CTL_RECEIVE_ERROR);
1180 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1181 * 400us delay required for errors and timeouts
1182 * Timeout errors from the HW already meet this
1183 * requirement so skip to next iteration
1185 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
1188 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1189 usleep_range(400, 500);
1192 if (status & DP_AUX_CH_CTL_DONE)
1197 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
1198 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
1204 /* Check for timeout or receive error.
1205 * Timeouts occur when the sink is not connected
1207 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1208 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
1213 /* Timeouts occur when the device isn't connected, so they're
1214 * "normal" -- don't fill the kernel log with these */
1215 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
1216 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
1221 /* Unload any bytes sent back from the other side */
1222 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1223 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
1226 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1227 * We have no idea of what happened so we return -EBUSY so
1228 * drm layer takes care for the necessary retries.
1230 if (recv_bytes == 0 || recv_bytes > 20) {
1231 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1237 if (recv_bytes > recv_size)
1238 recv_bytes = recv_size;
1240 for (i = 0; i < recv_bytes; i += 4)
1241 intel_dp_unpack_aux(I915_READ(ch_data[i >> 2]),
1242 recv + i, recv_bytes - i);
1246 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1249 edp_panel_vdd_off(intel_dp, false);
1251 pps_unlock(intel_dp);
1256 #define BARE_ADDRESS_SIZE 3
1257 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
1259 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
1261 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1262 uint8_t txbuf[20], rxbuf[20];
1263 size_t txsize, rxsize;
1266 txbuf[0] = (msg->request << 4) |
1267 ((msg->address >> 16) & 0xf);
1268 txbuf[1] = (msg->address >> 8) & 0xff;
1269 txbuf[2] = msg->address & 0xff;
1270 txbuf[3] = msg->size - 1;
1272 switch (msg->request & ~DP_AUX_I2C_MOT) {
1273 case DP_AUX_NATIVE_WRITE:
1274 case DP_AUX_I2C_WRITE:
1275 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
1276 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
1277 rxsize = 2; /* 0 or 1 data bytes */
1279 if (WARN_ON(txsize > 20))
1282 WARN_ON(!msg->buffer != !msg->size);
1285 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
1287 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize,
1290 msg->reply = rxbuf[0] >> 4;
1293 /* Number of bytes written in a short write. */
1294 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1296 /* Return payload size. */
1302 case DP_AUX_NATIVE_READ:
1303 case DP_AUX_I2C_READ:
1304 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
1305 rxsize = msg->size + 1;
1307 if (WARN_ON(rxsize > 20))
1310 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize,
1313 msg->reply = rxbuf[0] >> 4;
1315 * Assume happy day, and copy the data. The caller is
1316 * expected to check msg->reply before touching it.
1318 * Return payload size.
1321 memcpy(msg->buffer, rxbuf + 1, ret);
1333 static enum aux_ch intel_aux_ch(struct intel_dp *intel_dp)
1335 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1336 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1337 enum port port = encoder->port;
1338 const struct ddi_vbt_port_info *info =
1339 &dev_priv->vbt.ddi_port_info[port];
1342 if (!info->alternate_aux_channel) {
1343 aux_ch = (enum aux_ch) port;
1345 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1346 aux_ch_name(aux_ch), port_name(port));
1350 switch (info->alternate_aux_channel) {
1367 MISSING_CASE(info->alternate_aux_channel);
1372 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1373 aux_ch_name(aux_ch), port_name(port));
1378 static enum intel_display_power_domain
1379 intel_aux_power_domain(struct intel_dp *intel_dp)
1381 switch (intel_dp->aux_ch) {
1383 return POWER_DOMAIN_AUX_A;
1385 return POWER_DOMAIN_AUX_B;
1387 return POWER_DOMAIN_AUX_C;
1389 return POWER_DOMAIN_AUX_D;
1391 return POWER_DOMAIN_AUX_F;
1393 MISSING_CASE(intel_dp->aux_ch);
1394 return POWER_DOMAIN_AUX_A;
1398 static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp)
1400 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1401 enum aux_ch aux_ch = intel_dp->aux_ch;
1407 return DP_AUX_CH_CTL(aux_ch);
1409 MISSING_CASE(aux_ch);
1410 return DP_AUX_CH_CTL(AUX_CH_B);
1414 static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index)
1416 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1417 enum aux_ch aux_ch = intel_dp->aux_ch;
1423 return DP_AUX_CH_DATA(aux_ch, index);
1425 MISSING_CASE(aux_ch);
1426 return DP_AUX_CH_DATA(AUX_CH_B, index);
1430 static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp)
1432 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1433 enum aux_ch aux_ch = intel_dp->aux_ch;
1437 return DP_AUX_CH_CTL(aux_ch);
1441 return PCH_DP_AUX_CH_CTL(aux_ch);
1443 MISSING_CASE(aux_ch);
1444 return DP_AUX_CH_CTL(AUX_CH_A);
1448 static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index)
1450 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1451 enum aux_ch aux_ch = intel_dp->aux_ch;
1455 return DP_AUX_CH_DATA(aux_ch, index);
1459 return PCH_DP_AUX_CH_DATA(aux_ch, index);
1461 MISSING_CASE(aux_ch);
1462 return DP_AUX_CH_DATA(AUX_CH_A, index);
1466 static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp)
1468 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1469 enum aux_ch aux_ch = intel_dp->aux_ch;
1477 return DP_AUX_CH_CTL(aux_ch);
1479 MISSING_CASE(aux_ch);
1480 return DP_AUX_CH_CTL(AUX_CH_A);
1484 static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index)
1486 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1487 enum aux_ch aux_ch = intel_dp->aux_ch;
1495 return DP_AUX_CH_DATA(aux_ch, index);
1497 MISSING_CASE(aux_ch);
1498 return DP_AUX_CH_DATA(AUX_CH_A, index);
1503 intel_dp_aux_fini(struct intel_dp *intel_dp)
1505 kfree(intel_dp->aux.name);
1509 intel_dp_aux_init(struct intel_dp *intel_dp)
1511 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1512 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1514 intel_dp->aux_ch = intel_aux_ch(intel_dp);
1515 intel_dp->aux_power_domain = intel_aux_power_domain(intel_dp);
1517 if (INTEL_GEN(dev_priv) >= 9) {
1518 intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg;
1519 intel_dp->aux_ch_data_reg = skl_aux_data_reg;
1520 } else if (HAS_PCH_SPLIT(dev_priv)) {
1521 intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg;
1522 intel_dp->aux_ch_data_reg = ilk_aux_data_reg;
1524 intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg;
1525 intel_dp->aux_ch_data_reg = g4x_aux_data_reg;
1528 if (INTEL_GEN(dev_priv) >= 9)
1529 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
1530 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
1531 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
1532 else if (HAS_PCH_SPLIT(dev_priv))
1533 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
1535 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
1537 if (INTEL_GEN(dev_priv) >= 9)
1538 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
1540 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
1542 drm_dp_aux_init(&intel_dp->aux);
1544 /* Failure to allocate our preferred name is not critical */
1545 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c",
1546 port_name(encoder->port));
1547 intel_dp->aux.transfer = intel_dp_aux_transfer;
1550 bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
1552 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
1554 return max_rate >= 540000;
1558 intel_dp_set_clock(struct intel_encoder *encoder,
1559 struct intel_crtc_state *pipe_config)
1561 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1562 const struct dp_link_dpll *divisor = NULL;
1565 if (IS_G4X(dev_priv)) {
1566 divisor = gen4_dpll;
1567 count = ARRAY_SIZE(gen4_dpll);
1568 } else if (HAS_PCH_SPLIT(dev_priv)) {
1570 count = ARRAY_SIZE(pch_dpll);
1571 } else if (IS_CHERRYVIEW(dev_priv)) {
1573 count = ARRAY_SIZE(chv_dpll);
1574 } else if (IS_VALLEYVIEW(dev_priv)) {
1576 count = ARRAY_SIZE(vlv_dpll);
1579 if (divisor && count) {
1580 for (i = 0; i < count; i++) {
1581 if (pipe_config->port_clock == divisor[i].clock) {
1582 pipe_config->dpll = divisor[i].dpll;
1583 pipe_config->clock_set = true;
1590 static void snprintf_int_array(char *str, size_t len,
1591 const int *array, int nelem)
1597 for (i = 0; i < nelem; i++) {
1598 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
1606 static void intel_dp_print_rates(struct intel_dp *intel_dp)
1608 char str[128]; /* FIXME: too big for stack? */
1610 if ((drm_debug & DRM_UT_KMS) == 0)
1613 snprintf_int_array(str, sizeof(str),
1614 intel_dp->source_rates, intel_dp->num_source_rates);
1615 DRM_DEBUG_KMS("source rates: %s\n", str);
1617 snprintf_int_array(str, sizeof(str),
1618 intel_dp->sink_rates, intel_dp->num_sink_rates);
1619 DRM_DEBUG_KMS("sink rates: %s\n", str);
1621 snprintf_int_array(str, sizeof(str),
1622 intel_dp->common_rates, intel_dp->num_common_rates);
1623 DRM_DEBUG_KMS("common rates: %s\n", str);
1627 intel_dp_max_link_rate(struct intel_dp *intel_dp)
1631 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
1632 if (WARN_ON(len <= 0))
1635 return intel_dp->common_rates[len - 1];
1638 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1640 int i = intel_dp_rate_index(intel_dp->sink_rates,
1641 intel_dp->num_sink_rates, rate);
1649 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1650 uint8_t *link_bw, uint8_t *rate_select)
1652 /* eDP 1.4 rate select method. */
1653 if (intel_dp->use_rate_select) {
1656 intel_dp_rate_select(intel_dp, port_clock);
1658 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1663 static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1664 struct intel_crtc_state *pipe_config)
1668 bpp = pipe_config->pipe_bpp;
1669 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1672 bpp = min(bpp, 3*bpc);
1674 /* For DP Compliance we override the computed bpp for the pipe */
1675 if (intel_dp->compliance.test_data.bpc != 0) {
1676 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1677 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1678 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1679 pipe_config->pipe_bpp);
1684 static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1685 struct drm_display_mode *m2)
1690 bres = (m1->hdisplay == m2->hdisplay &&
1691 m1->hsync_start == m2->hsync_start &&
1692 m1->hsync_end == m2->hsync_end &&
1693 m1->htotal == m2->htotal &&
1694 m1->vdisplay == m2->vdisplay &&
1695 m1->vsync_start == m2->vsync_start &&
1696 m1->vsync_end == m2->vsync_end &&
1697 m1->vtotal == m2->vtotal);
1702 intel_dp_compute_config(struct intel_encoder *encoder,
1703 struct intel_crtc_state *pipe_config,
1704 struct drm_connector_state *conn_state)
1706 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1707 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1708 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1709 enum port port = encoder->port;
1710 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
1711 struct intel_connector *intel_connector = intel_dp->attached_connector;
1712 struct intel_digital_connector_state *intel_conn_state =
1713 to_intel_digital_connector_state(conn_state);
1714 int lane_count, clock;
1715 int min_lane_count = 1;
1716 int max_lane_count = intel_dp_max_lane_count(intel_dp);
1717 /* Conveniently, the link BW constants become indices with a shift...*/
1721 int link_avail, link_clock;
1723 uint8_t link_bw, rate_select;
1724 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1725 DP_DPCD_QUIRK_LIMITED_M_N);
1727 common_len = intel_dp_common_len_rate_limit(intel_dp,
1728 intel_dp->max_link_rate);
1730 /* No common link rates between source and sink */
1731 WARN_ON(common_len <= 0);
1733 max_clock = common_len - 1;
1735 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
1736 pipe_config->has_pch_encoder = true;
1738 pipe_config->has_drrs = false;
1739 if (IS_G4X(dev_priv) || port == PORT_A)
1740 pipe_config->has_audio = false;
1741 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
1742 pipe_config->has_audio = intel_dp->has_audio;
1744 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
1746 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1747 struct drm_display_mode *panel_mode =
1748 intel_connector->panel.alt_fixed_mode;
1749 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1751 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1752 panel_mode = intel_connector->panel.fixed_mode;
1754 drm_mode_debug_printmodeline(panel_mode);
1756 intel_fixed_panel_mode(panel_mode, adjusted_mode);
1758 if (INTEL_GEN(dev_priv) >= 9) {
1760 ret = skl_update_scaler_crtc(pipe_config);
1765 if (HAS_GMCH_DISPLAY(dev_priv))
1766 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1767 conn_state->scaling_mode);
1769 intel_pch_panel_fitting(intel_crtc, pipe_config,
1770 conn_state->scaling_mode);
1773 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1774 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
1777 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
1780 /* Use values requested by Compliance Test Request */
1781 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1784 /* Validate the compliance test data since max values
1785 * might have changed due to link train fallback.
1787 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1788 intel_dp->compliance.test_lane_count)) {
1789 index = intel_dp_rate_index(intel_dp->common_rates,
1790 intel_dp->num_common_rates,
1791 intel_dp->compliance.test_link_rate);
1793 min_clock = max_clock = index;
1794 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1797 DRM_DEBUG_KMS("DP link computation with max lane count %i "
1798 "max bw %d pixel clock %iKHz\n",
1799 max_lane_count, intel_dp->common_rates[max_clock],
1800 adjusted_mode->crtc_clock);
1802 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1803 * bpc in between. */
1804 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
1805 if (intel_dp_is_edp(intel_dp)) {
1807 /* Get bpp from vbt only for panels that dont have bpp in edid */
1808 if (intel_connector->base.display_info.bpc == 0 &&
1809 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
1810 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
1811 dev_priv->vbt.edp.bpp);
1812 bpp = dev_priv->vbt.edp.bpp;
1816 * Use the maximum clock and number of lanes the eDP panel
1817 * advertizes being capable of. The panels are generally
1818 * designed to support only a single clock and lane
1819 * configuration, and typically these values correspond to the
1820 * native resolution of the panel.
1822 min_lane_count = max_lane_count;
1823 min_clock = max_clock;
1826 for (; bpp >= 6*3; bpp -= 2*3) {
1827 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1830 for (clock = min_clock; clock <= max_clock; clock++) {
1831 for (lane_count = min_lane_count;
1832 lane_count <= max_lane_count;
1835 link_clock = intel_dp->common_rates[clock];
1836 link_avail = intel_dp_max_data_rate(link_clock,
1839 if (mode_rate <= link_avail) {
1849 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
1852 * CEA-861-E - 5.1 Default Encoding Parameters
1853 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1855 pipe_config->limited_color_range =
1857 drm_default_rgb_quant_range(adjusted_mode) ==
1858 HDMI_QUANTIZATION_RANGE_LIMITED;
1860 pipe_config->limited_color_range =
1861 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
1864 pipe_config->lane_count = lane_count;
1866 pipe_config->pipe_bpp = bpp;
1867 pipe_config->port_clock = intel_dp->common_rates[clock];
1869 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1870 &link_bw, &rate_select);
1872 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1873 link_bw, rate_select, pipe_config->lane_count,
1874 pipe_config->port_clock, bpp);
1875 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1876 mode_rate, link_avail);
1878 intel_link_compute_m_n(bpp, lane_count,
1879 adjusted_mode->crtc_clock,
1880 pipe_config->port_clock,
1881 &pipe_config->dp_m_n,
1884 if (intel_connector->panel.downclock_mode != NULL &&
1885 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
1886 pipe_config->has_drrs = true;
1887 intel_link_compute_m_n(bpp, lane_count,
1888 intel_connector->panel.downclock_mode->clock,
1889 pipe_config->port_clock,
1890 &pipe_config->dp_m2_n2,
1895 * DPLL0 VCO may need to be adjusted to get the correct
1896 * clock for eDP. This will affect cdclk as well.
1898 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
1901 switch (pipe_config->port_clock / 2) {
1911 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
1914 if (!HAS_DDI(dev_priv))
1915 intel_dp_set_clock(encoder, pipe_config);
1917 intel_psr_compute_config(intel_dp, pipe_config);
1922 void intel_dp_set_link_params(struct intel_dp *intel_dp,
1923 int link_rate, uint8_t lane_count,
1926 intel_dp->link_rate = link_rate;
1927 intel_dp->lane_count = lane_count;
1928 intel_dp->link_mst = link_mst;
1931 static void intel_dp_prepare(struct intel_encoder *encoder,
1932 const struct intel_crtc_state *pipe_config)
1934 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1935 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1936 enum port port = encoder->port;
1937 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
1938 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1940 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1941 pipe_config->lane_count,
1942 intel_crtc_has_type(pipe_config,
1943 INTEL_OUTPUT_DP_MST));
1946 * There are four kinds of DP registers:
1953 * IBX PCH and CPU are the same for almost everything,
1954 * except that the CPU DP PLL is configured in this
1957 * CPT PCH is quite different, having many bits moved
1958 * to the TRANS_DP_CTL register instead. That
1959 * configuration happens (oddly) in ironlake_pch_enable
1962 /* Preserve the BIOS-computed detected bit. This is
1963 * supposed to be read-only.
1965 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
1967 /* Handle DP bits in common between all three register formats */
1968 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
1969 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
1971 /* Split out the IBX/CPU vs CPT settings */
1973 if (IS_GEN7(dev_priv) && port == PORT_A) {
1974 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1975 intel_dp->DP |= DP_SYNC_HS_HIGH;
1976 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1977 intel_dp->DP |= DP_SYNC_VS_HIGH;
1978 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1980 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1981 intel_dp->DP |= DP_ENHANCED_FRAMING;
1983 intel_dp->DP |= crtc->pipe << 29;
1984 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
1987 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1989 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1990 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1991 trans_dp |= TRANS_DP_ENH_FRAMING;
1993 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1994 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
1996 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
1997 intel_dp->DP |= DP_COLOR_RANGE_16_235;
1999 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2000 intel_dp->DP |= DP_SYNC_HS_HIGH;
2001 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2002 intel_dp->DP |= DP_SYNC_VS_HIGH;
2003 intel_dp->DP |= DP_LINK_TRAIN_OFF;
2005 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2006 intel_dp->DP |= DP_ENHANCED_FRAMING;
2008 if (IS_CHERRYVIEW(dev_priv))
2009 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
2010 else if (crtc->pipe == PIPE_B)
2011 intel_dp->DP |= DP_PIPEB_SELECT;
2015 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
2016 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
2018 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
2019 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
2021 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
2022 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
2024 static void intel_pps_verify_state(struct intel_dp *intel_dp);
2026 static void wait_panel_status(struct intel_dp *intel_dp,
2030 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2031 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2033 lockdep_assert_held(&dev_priv->pps_mutex);
2035 intel_pps_verify_state(intel_dp);
2037 pp_stat_reg = _pp_stat_reg(intel_dp);
2038 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2040 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
2042 I915_READ(pp_stat_reg),
2043 I915_READ(pp_ctrl_reg));
2045 if (intel_wait_for_register(dev_priv,
2046 pp_stat_reg, mask, value,
2048 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
2049 I915_READ(pp_stat_reg),
2050 I915_READ(pp_ctrl_reg));
2052 DRM_DEBUG_KMS("Wait complete\n");
2055 static void wait_panel_on(struct intel_dp *intel_dp)
2057 DRM_DEBUG_KMS("Wait for panel power on\n");
2058 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
2061 static void wait_panel_off(struct intel_dp *intel_dp)
2063 DRM_DEBUG_KMS("Wait for panel power off time\n");
2064 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
2067 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
2069 ktime_t panel_power_on_time;
2070 s64 panel_power_off_duration;
2072 DRM_DEBUG_KMS("Wait for panel power cycle\n");
2074 /* take the difference of currrent time and panel power off time
2075 * and then make panel wait for t11_t12 if needed. */
2076 panel_power_on_time = ktime_get_boottime();
2077 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2079 /* When we disable the VDD override bit last we have to do the manual
2081 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2082 wait_remaining_ms_from_jiffies(jiffies,
2083 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
2085 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
2088 static void wait_backlight_on(struct intel_dp *intel_dp)
2090 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2091 intel_dp->backlight_on_delay);
2094 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
2096 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2097 intel_dp->backlight_off_delay);
2100 /* Read the current pp_control value, unlocking the register if it
2104 static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
2106 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2109 lockdep_assert_held(&dev_priv->pps_mutex);
2111 control = I915_READ(_pp_ctrl_reg(intel_dp));
2112 if (WARN_ON(!HAS_DDI(dev_priv) &&
2113 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
2114 control &= ~PANEL_UNLOCK_MASK;
2115 control |= PANEL_UNLOCK_REGS;
2121 * Must be paired with edp_panel_vdd_off().
2122 * Must hold pps_mutex around the whole on/off sequence.
2123 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2125 static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
2127 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2128 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2130 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2131 bool need_to_disable = !intel_dp->want_panel_vdd;
2133 lockdep_assert_held(&dev_priv->pps_mutex);
2135 if (!intel_dp_is_edp(intel_dp))
2138 cancel_delayed_work(&intel_dp->panel_vdd_work);
2139 intel_dp->want_panel_vdd = true;
2141 if (edp_have_panel_vdd(intel_dp))
2142 return need_to_disable;
2144 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
2146 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2147 port_name(intel_dig_port->base.port));
2149 if (!edp_have_panel_power(intel_dp))
2150 wait_panel_power_cycle(intel_dp);
2152 pp = ironlake_get_pp_control(intel_dp);
2153 pp |= EDP_FORCE_VDD;
2155 pp_stat_reg = _pp_stat_reg(intel_dp);
2156 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2158 I915_WRITE(pp_ctrl_reg, pp);
2159 POSTING_READ(pp_ctrl_reg);
2160 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2161 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2163 * If the panel wasn't on, delay before accessing aux channel
2165 if (!edp_have_panel_power(intel_dp)) {
2166 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2167 port_name(intel_dig_port->base.port));
2168 msleep(intel_dp->panel_power_up_delay);
2171 return need_to_disable;
2175 * Must be paired with intel_edp_panel_vdd_off() or
2176 * intel_edp_panel_off().
2177 * Nested calls to these functions are not allowed since
2178 * we drop the lock. Caller must use some higher level
2179 * locking to prevent nested calls from other threads.
2181 void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
2185 if (!intel_dp_is_edp(intel_dp))
2189 vdd = edp_panel_vdd_on(intel_dp);
2190 pps_unlock(intel_dp);
2192 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
2193 port_name(dp_to_dig_port(intel_dp)->base.port));
2196 static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
2198 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2199 struct intel_digital_port *intel_dig_port =
2200 dp_to_dig_port(intel_dp);
2202 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2204 lockdep_assert_held(&dev_priv->pps_mutex);
2206 WARN_ON(intel_dp->want_panel_vdd);
2208 if (!edp_have_panel_vdd(intel_dp))
2211 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2212 port_name(intel_dig_port->base.port));
2214 pp = ironlake_get_pp_control(intel_dp);
2215 pp &= ~EDP_FORCE_VDD;
2217 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2218 pp_stat_reg = _pp_stat_reg(intel_dp);
2220 I915_WRITE(pp_ctrl_reg, pp);
2221 POSTING_READ(pp_ctrl_reg);
2223 /* Make sure sequencer is idle before allowing subsequent activity */
2224 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2225 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2227 if ((pp & PANEL_POWER_ON) == 0)
2228 intel_dp->panel_power_off_time = ktime_get_boottime();
2230 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
2233 static void edp_panel_vdd_work(struct work_struct *__work)
2235 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2236 struct intel_dp, panel_vdd_work);
2239 if (!intel_dp->want_panel_vdd)
2240 edp_panel_vdd_off_sync(intel_dp);
2241 pps_unlock(intel_dp);
2244 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2246 unsigned long delay;
2249 * Queue the timer to fire a long time from now (relative to the power
2250 * down delay) to keep the panel power up across a sequence of
2253 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2254 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2258 * Must be paired with edp_panel_vdd_on().
2259 * Must hold pps_mutex around the whole on/off sequence.
2260 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2262 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
2264 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2266 lockdep_assert_held(&dev_priv->pps_mutex);
2268 if (!intel_dp_is_edp(intel_dp))
2271 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
2272 port_name(dp_to_dig_port(intel_dp)->base.port));
2274 intel_dp->want_panel_vdd = false;
2277 edp_panel_vdd_off_sync(intel_dp);
2279 edp_panel_vdd_schedule_off(intel_dp);
2282 static void edp_panel_on(struct intel_dp *intel_dp)
2284 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2286 i915_reg_t pp_ctrl_reg;
2288 lockdep_assert_held(&dev_priv->pps_mutex);
2290 if (!intel_dp_is_edp(intel_dp))
2293 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2294 port_name(dp_to_dig_port(intel_dp)->base.port));
2296 if (WARN(edp_have_panel_power(intel_dp),
2297 "eDP port %c panel power already on\n",
2298 port_name(dp_to_dig_port(intel_dp)->base.port)))
2301 wait_panel_power_cycle(intel_dp);
2303 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2304 pp = ironlake_get_pp_control(intel_dp);
2305 if (IS_GEN5(dev_priv)) {
2306 /* ILK workaround: disable reset around power sequence */
2307 pp &= ~PANEL_POWER_RESET;
2308 I915_WRITE(pp_ctrl_reg, pp);
2309 POSTING_READ(pp_ctrl_reg);
2312 pp |= PANEL_POWER_ON;
2313 if (!IS_GEN5(dev_priv))
2314 pp |= PANEL_POWER_RESET;
2316 I915_WRITE(pp_ctrl_reg, pp);
2317 POSTING_READ(pp_ctrl_reg);
2319 wait_panel_on(intel_dp);
2320 intel_dp->last_power_on = jiffies;
2322 if (IS_GEN5(dev_priv)) {
2323 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
2324 I915_WRITE(pp_ctrl_reg, pp);
2325 POSTING_READ(pp_ctrl_reg);
2329 void intel_edp_panel_on(struct intel_dp *intel_dp)
2331 if (!intel_dp_is_edp(intel_dp))
2335 edp_panel_on(intel_dp);
2336 pps_unlock(intel_dp);
2340 static void edp_panel_off(struct intel_dp *intel_dp)
2342 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2344 i915_reg_t pp_ctrl_reg;
2346 lockdep_assert_held(&dev_priv->pps_mutex);
2348 if (!intel_dp_is_edp(intel_dp))
2351 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2352 port_name(dp_to_dig_port(intel_dp)->base.port));
2354 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2355 port_name(dp_to_dig_port(intel_dp)->base.port));
2357 pp = ironlake_get_pp_control(intel_dp);
2358 /* We need to switch off panel power _and_ force vdd, for otherwise some
2359 * panels get very unhappy and cease to work. */
2360 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
2363 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2365 intel_dp->want_panel_vdd = false;
2367 I915_WRITE(pp_ctrl_reg, pp);
2368 POSTING_READ(pp_ctrl_reg);
2370 wait_panel_off(intel_dp);
2371 intel_dp->panel_power_off_time = ktime_get_boottime();
2373 /* We got a reference when we enabled the VDD. */
2374 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
2377 void intel_edp_panel_off(struct intel_dp *intel_dp)
2379 if (!intel_dp_is_edp(intel_dp))
2383 edp_panel_off(intel_dp);
2384 pps_unlock(intel_dp);
2387 /* Enable backlight in the panel power control. */
2388 static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
2390 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2392 i915_reg_t pp_ctrl_reg;
2395 * If we enable the backlight right away following a panel power
2396 * on, we may see slight flicker as the panel syncs with the eDP
2397 * link. So delay a bit to make sure the image is solid before
2398 * allowing it to appear.
2400 wait_backlight_on(intel_dp);
2404 pp = ironlake_get_pp_control(intel_dp);
2405 pp |= EDP_BLC_ENABLE;
2407 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2409 I915_WRITE(pp_ctrl_reg, pp);
2410 POSTING_READ(pp_ctrl_reg);
2412 pps_unlock(intel_dp);
2415 /* Enable backlight PWM and backlight PP control. */
2416 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2417 const struct drm_connector_state *conn_state)
2419 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2421 if (!intel_dp_is_edp(intel_dp))
2424 DRM_DEBUG_KMS("\n");
2426 intel_panel_enable_backlight(crtc_state, conn_state);
2427 _intel_edp_backlight_on(intel_dp);
2430 /* Disable backlight in the panel power control. */
2431 static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
2433 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2435 i915_reg_t pp_ctrl_reg;
2437 if (!intel_dp_is_edp(intel_dp))
2442 pp = ironlake_get_pp_control(intel_dp);
2443 pp &= ~EDP_BLC_ENABLE;
2445 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2447 I915_WRITE(pp_ctrl_reg, pp);
2448 POSTING_READ(pp_ctrl_reg);
2450 pps_unlock(intel_dp);
2452 intel_dp->last_backlight_off = jiffies;
2453 edp_wait_backlight_off(intel_dp);
2456 /* Disable backlight PP control and backlight PWM. */
2457 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
2459 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2461 if (!intel_dp_is_edp(intel_dp))
2464 DRM_DEBUG_KMS("\n");
2466 _intel_edp_backlight_off(intel_dp);
2467 intel_panel_disable_backlight(old_conn_state);
2471 * Hook for controlling the panel power control backlight through the bl_power
2472 * sysfs attribute. Take care to handle multiple calls.
2474 static void intel_edp_backlight_power(struct intel_connector *connector,
2477 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
2481 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
2482 pps_unlock(intel_dp);
2484 if (is_enabled == enable)
2487 DRM_DEBUG_KMS("panel power control backlight %s\n",
2488 enable ? "enable" : "disable");
2491 _intel_edp_backlight_on(intel_dp);
2493 _intel_edp_backlight_off(intel_dp);
2496 static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2498 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2499 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2500 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2502 I915_STATE_WARN(cur_state != state,
2503 "DP port %c state assertion failure (expected %s, current %s)\n",
2504 port_name(dig_port->base.port),
2505 onoff(state), onoff(cur_state));
2507 #define assert_dp_port_disabled(d) assert_dp_port((d), false)
2509 static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2511 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2513 I915_STATE_WARN(cur_state != state,
2514 "eDP PLL state assertion failure (expected %s, current %s)\n",
2515 onoff(state), onoff(cur_state));
2517 #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2518 #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2520 static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2521 const struct intel_crtc_state *pipe_config)
2523 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2524 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2526 assert_pipe_disabled(dev_priv, crtc->pipe);
2527 assert_dp_port_disabled(intel_dp);
2528 assert_edp_pll_disabled(dev_priv);
2530 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
2531 pipe_config->port_clock);
2533 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2535 if (pipe_config->port_clock == 162000)
2536 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2538 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2540 I915_WRITE(DP_A, intel_dp->DP);
2545 * [DevILK] Work around required when enabling DP PLL
2546 * while a pipe is enabled going to FDI:
2547 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2548 * 2. Program DP PLL enable
2550 if (IS_GEN5(dev_priv))
2551 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
2553 intel_dp->DP |= DP_PLL_ENABLE;
2555 I915_WRITE(DP_A, intel_dp->DP);
2560 static void ironlake_edp_pll_off(struct intel_dp *intel_dp,
2561 const struct intel_crtc_state *old_crtc_state)
2563 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
2564 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2566 assert_pipe_disabled(dev_priv, crtc->pipe);
2567 assert_dp_port_disabled(intel_dp);
2568 assert_edp_pll_enabled(dev_priv);
2570 DRM_DEBUG_KMS("disabling eDP PLL\n");
2572 intel_dp->DP &= ~DP_PLL_ENABLE;
2574 I915_WRITE(DP_A, intel_dp->DP);
2579 static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2582 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2583 * be capable of signalling downstream hpd with a long pulse.
2584 * Whether or not that means D3 is safe to use is not clear,
2585 * but let's assume so until proven otherwise.
2587 * FIXME should really check all downstream ports...
2589 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2590 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2591 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2594 /* If the sink supports it, try to set the power state appropriately */
2595 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
2599 /* Should have a valid DPCD by this point */
2600 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2603 if (mode != DRM_MODE_DPMS_ON) {
2604 if (downstream_hpd_needs_d0(intel_dp))
2607 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2610 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2613 * When turning on, we need to retry for 1ms to give the sink
2616 for (i = 0; i < 3; i++) {
2617 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2624 if (ret == 1 && lspcon->active)
2625 lspcon_wait_pcon_mode(lspcon);
2629 DRM_DEBUG_KMS("failed to %s sink power state\n",
2630 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
2633 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2636 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2637 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2638 enum port port = encoder->port;
2642 if (!intel_display_power_get_if_enabled(dev_priv,
2643 encoder->power_domain))
2648 tmp = I915_READ(intel_dp->output_reg);
2650 if (!(tmp & DP_PORT_EN))
2653 if (IS_GEN7(dev_priv) && port == PORT_A) {
2654 *pipe = PORT_TO_PIPE_CPT(tmp);
2655 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2658 for_each_pipe(dev_priv, p) {
2659 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2660 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2668 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
2669 i915_mmio_reg_offset(intel_dp->output_reg));
2670 } else if (IS_CHERRYVIEW(dev_priv)) {
2671 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2673 *pipe = PORT_TO_PIPE(tmp);
2679 intel_display_power_put(dev_priv, encoder->power_domain);
2684 static void intel_dp_get_config(struct intel_encoder *encoder,
2685 struct intel_crtc_state *pipe_config)
2687 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2688 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2690 enum port port = encoder->port;
2691 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2693 if (encoder->type == INTEL_OUTPUT_EDP)
2694 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2696 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
2698 tmp = I915_READ(intel_dp->output_reg);
2700 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
2702 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2703 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2705 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
2706 flags |= DRM_MODE_FLAG_PHSYNC;
2708 flags |= DRM_MODE_FLAG_NHSYNC;
2710 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
2711 flags |= DRM_MODE_FLAG_PVSYNC;
2713 flags |= DRM_MODE_FLAG_NVSYNC;
2715 if (tmp & DP_SYNC_HS_HIGH)
2716 flags |= DRM_MODE_FLAG_PHSYNC;
2718 flags |= DRM_MODE_FLAG_NHSYNC;
2720 if (tmp & DP_SYNC_VS_HIGH)
2721 flags |= DRM_MODE_FLAG_PVSYNC;
2723 flags |= DRM_MODE_FLAG_NVSYNC;
2726 pipe_config->base.adjusted_mode.flags |= flags;
2728 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
2729 pipe_config->limited_color_range = true;
2731 pipe_config->lane_count =
2732 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2734 intel_dp_get_m_n(crtc, pipe_config);
2736 if (port == PORT_A) {
2737 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
2738 pipe_config->port_clock = 162000;
2740 pipe_config->port_clock = 270000;
2743 pipe_config->base.adjusted_mode.crtc_clock =
2744 intel_dotclock_calculate(pipe_config->port_clock,
2745 &pipe_config->dp_m_n);
2747 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2748 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
2750 * This is a big fat ugly hack.
2752 * Some machines in UEFI boot mode provide us a VBT that has 18
2753 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2754 * unknown we fail to light up. Yet the same BIOS boots up with
2755 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2756 * max, not what it tells us to use.
2758 * Note: This will still be broken if the eDP panel is not lit
2759 * up by the BIOS, and thus we can't get the mode at module
2762 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2763 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2764 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
2768 static void intel_disable_dp(struct intel_encoder *encoder,
2769 const struct intel_crtc_state *old_crtc_state,
2770 const struct drm_connector_state *old_conn_state)
2772 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2774 if (old_crtc_state->has_audio)
2775 intel_audio_codec_disable(encoder,
2776 old_crtc_state, old_conn_state);
2778 /* Make sure the panel is off before trying to change the mode. But also
2779 * ensure that we have vdd while we switch off the panel. */
2780 intel_edp_panel_vdd_on(intel_dp);
2781 intel_edp_backlight_off(old_conn_state);
2782 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2783 intel_edp_panel_off(intel_dp);
2786 static void g4x_disable_dp(struct intel_encoder *encoder,
2787 const struct intel_crtc_state *old_crtc_state,
2788 const struct drm_connector_state *old_conn_state)
2790 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2792 /* disable the port before the pipe on g4x */
2793 intel_dp_link_down(encoder, old_crtc_state);
2796 static void ilk_disable_dp(struct intel_encoder *encoder,
2797 const struct intel_crtc_state *old_crtc_state,
2798 const struct drm_connector_state *old_conn_state)
2800 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2803 static void vlv_disable_dp(struct intel_encoder *encoder,
2804 const struct intel_crtc_state *old_crtc_state,
2805 const struct drm_connector_state *old_conn_state)
2807 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2809 intel_psr_disable(intel_dp, old_crtc_state);
2811 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2814 static void ilk_post_disable_dp(struct intel_encoder *encoder,
2815 const struct intel_crtc_state *old_crtc_state,
2816 const struct drm_connector_state *old_conn_state)
2818 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2819 enum port port = encoder->port;
2821 intel_dp_link_down(encoder, old_crtc_state);
2823 /* Only ilk+ has port A */
2825 ironlake_edp_pll_off(intel_dp, old_crtc_state);
2828 static void vlv_post_disable_dp(struct intel_encoder *encoder,
2829 const struct intel_crtc_state *old_crtc_state,
2830 const struct drm_connector_state *old_conn_state)
2832 intel_dp_link_down(encoder, old_crtc_state);
2835 static void chv_post_disable_dp(struct intel_encoder *encoder,
2836 const struct intel_crtc_state *old_crtc_state,
2837 const struct drm_connector_state *old_conn_state)
2839 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2841 intel_dp_link_down(encoder, old_crtc_state);
2843 mutex_lock(&dev_priv->sb_lock);
2845 /* Assert data lane reset */
2846 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
2848 mutex_unlock(&dev_priv->sb_lock);
2852 _intel_dp_set_link_train(struct intel_dp *intel_dp,
2854 uint8_t dp_train_pat)
2856 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2857 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2858 enum port port = intel_dig_port->base.port;
2860 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2861 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2862 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2864 if (HAS_DDI(dev_priv)) {
2865 uint32_t temp = I915_READ(DP_TP_CTL(port));
2867 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2868 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2870 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2872 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2873 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2874 case DP_TRAINING_PATTERN_DISABLE:
2875 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2878 case DP_TRAINING_PATTERN_1:
2879 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2881 case DP_TRAINING_PATTERN_2:
2882 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2884 case DP_TRAINING_PATTERN_3:
2885 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2888 I915_WRITE(DP_TP_CTL(port), temp);
2890 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
2891 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
2892 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2894 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2895 case DP_TRAINING_PATTERN_DISABLE:
2896 *DP |= DP_LINK_TRAIN_OFF_CPT;
2898 case DP_TRAINING_PATTERN_1:
2899 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2901 case DP_TRAINING_PATTERN_2:
2902 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2904 case DP_TRAINING_PATTERN_3:
2905 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
2906 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2911 if (IS_CHERRYVIEW(dev_priv))
2912 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2914 *DP &= ~DP_LINK_TRAIN_MASK;
2916 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2917 case DP_TRAINING_PATTERN_DISABLE:
2918 *DP |= DP_LINK_TRAIN_OFF;
2920 case DP_TRAINING_PATTERN_1:
2921 *DP |= DP_LINK_TRAIN_PAT_1;
2923 case DP_TRAINING_PATTERN_2:
2924 *DP |= DP_LINK_TRAIN_PAT_2;
2926 case DP_TRAINING_PATTERN_3:
2927 if (IS_CHERRYVIEW(dev_priv)) {
2928 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2930 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
2931 *DP |= DP_LINK_TRAIN_PAT_2;
2938 static void intel_dp_enable_port(struct intel_dp *intel_dp,
2939 const struct intel_crtc_state *old_crtc_state)
2941 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2943 /* enable with pattern 1 (as per spec) */
2945 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
2948 * Magic for VLV/CHV. We _must_ first set up the register
2949 * without actually enabling the port, and then do another
2950 * write to enable the port. Otherwise link training will
2951 * fail when the power sequencer is freshly used for this port.
2953 intel_dp->DP |= DP_PORT_EN;
2954 if (old_crtc_state->has_audio)
2955 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
2957 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2958 POSTING_READ(intel_dp->output_reg);
2961 static void intel_enable_dp(struct intel_encoder *encoder,
2962 const struct intel_crtc_state *pipe_config,
2963 const struct drm_connector_state *conn_state)
2965 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2966 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2967 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2968 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
2969 enum pipe pipe = crtc->pipe;
2971 if (WARN_ON(dp_reg & DP_PORT_EN))
2976 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2977 vlv_init_panel_power_sequencer(encoder, pipe_config);
2979 intel_dp_enable_port(intel_dp, pipe_config);
2981 edp_panel_vdd_on(intel_dp);
2982 edp_panel_on(intel_dp);
2983 edp_panel_vdd_off(intel_dp, true);
2985 pps_unlock(intel_dp);
2987 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
2988 unsigned int lane_mask = 0x0;
2990 if (IS_CHERRYVIEW(dev_priv))
2991 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
2993 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2997 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2998 intel_dp_start_link_train(intel_dp);
2999 intel_dp_stop_link_train(intel_dp);
3001 if (pipe_config->has_audio) {
3002 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
3004 intel_audio_codec_enable(encoder, pipe_config, conn_state);
3008 static void g4x_enable_dp(struct intel_encoder *encoder,
3009 const struct intel_crtc_state *pipe_config,
3010 const struct drm_connector_state *conn_state)
3012 intel_enable_dp(encoder, pipe_config, conn_state);
3013 intel_edp_backlight_on(pipe_config, conn_state);
3016 static void vlv_enable_dp(struct intel_encoder *encoder,
3017 const struct intel_crtc_state *pipe_config,
3018 const struct drm_connector_state *conn_state)
3020 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3022 intel_edp_backlight_on(pipe_config, conn_state);
3023 intel_psr_enable(intel_dp, pipe_config);
3026 static void g4x_pre_enable_dp(struct intel_encoder *encoder,
3027 const struct intel_crtc_state *pipe_config,
3028 const struct drm_connector_state *conn_state)
3030 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3031 enum port port = encoder->port;
3033 intel_dp_prepare(encoder, pipe_config);
3035 /* Only ilk+ has port A */
3037 ironlake_edp_pll_on(intel_dp, pipe_config);
3040 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
3042 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3043 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
3044 enum pipe pipe = intel_dp->pps_pipe;
3045 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
3047 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
3049 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
3052 edp_panel_vdd_off_sync(intel_dp);
3055 * VLV seems to get confused when multiple power seqeuencers
3056 * have the same port selected (even if only one has power/vdd
3057 * enabled). The failure manifests as vlv_wait_port_ready() failing
3058 * CHV on the other hand doesn't seem to mind having the same port
3059 * selected in multiple power seqeuencers, but let's clear the
3060 * port select always when logically disconnecting a power sequencer
3063 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
3064 pipe_name(pipe), port_name(intel_dig_port->base.port));
3065 I915_WRITE(pp_on_reg, 0);
3066 POSTING_READ(pp_on_reg);
3068 intel_dp->pps_pipe = INVALID_PIPE;
3071 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
3074 struct intel_encoder *encoder;
3076 lockdep_assert_held(&dev_priv->pps_mutex);
3078 for_each_intel_encoder(&dev_priv->drm, encoder) {
3079 struct intel_dp *intel_dp;
3082 if (encoder->type != INTEL_OUTPUT_DP &&
3083 encoder->type != INTEL_OUTPUT_EDP)
3086 intel_dp = enc_to_intel_dp(&encoder->base);
3087 port = dp_to_dig_port(intel_dp)->base.port;
3089 WARN(intel_dp->active_pipe == pipe,
3090 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3091 pipe_name(pipe), port_name(port));
3093 if (intel_dp->pps_pipe != pipe)
3096 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
3097 pipe_name(pipe), port_name(port));
3099 /* make sure vdd is off before we steal it */
3100 vlv_detach_power_sequencer(intel_dp);
3104 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
3105 const struct intel_crtc_state *crtc_state)
3107 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3108 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3109 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3111 lockdep_assert_held(&dev_priv->pps_mutex);
3113 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
3115 if (intel_dp->pps_pipe != INVALID_PIPE &&
3116 intel_dp->pps_pipe != crtc->pipe) {
3118 * If another power sequencer was being used on this
3119 * port previously make sure to turn off vdd there while
3120 * we still have control of it.
3122 vlv_detach_power_sequencer(intel_dp);
3126 * We may be stealing the power
3127 * sequencer from another port.
3129 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
3131 intel_dp->active_pipe = crtc->pipe;
3133 if (!intel_dp_is_edp(intel_dp))
3136 /* now it's all ours */
3137 intel_dp->pps_pipe = crtc->pipe;
3139 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3140 pipe_name(intel_dp->pps_pipe), port_name(encoder->port));
3142 /* init power sequencer on this pipe and port */
3143 intel_dp_init_panel_power_sequencer(intel_dp);
3144 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
3147 static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3148 const struct intel_crtc_state *pipe_config,
3149 const struct drm_connector_state *conn_state)
3151 vlv_phy_pre_encoder_enable(encoder, pipe_config);
3153 intel_enable_dp(encoder, pipe_config, conn_state);
3156 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3157 const struct intel_crtc_state *pipe_config,
3158 const struct drm_connector_state *conn_state)
3160 intel_dp_prepare(encoder, pipe_config);
3162 vlv_phy_pre_pll_enable(encoder, pipe_config);
3165 static void chv_pre_enable_dp(struct intel_encoder *encoder,
3166 const struct intel_crtc_state *pipe_config,
3167 const struct drm_connector_state *conn_state)
3169 chv_phy_pre_encoder_enable(encoder, pipe_config);
3171 intel_enable_dp(encoder, pipe_config, conn_state);
3173 /* Second common lane will stay alive on its own now */
3174 chv_phy_release_cl2_override(encoder);
3177 static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3178 const struct intel_crtc_state *pipe_config,
3179 const struct drm_connector_state *conn_state)
3181 intel_dp_prepare(encoder, pipe_config);
3183 chv_phy_pre_pll_enable(encoder, pipe_config);
3186 static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3187 const struct intel_crtc_state *old_crtc_state,
3188 const struct drm_connector_state *old_conn_state)
3190 chv_phy_post_pll_disable(encoder, old_crtc_state);
3194 * Fetch AUX CH registers 0x202 - 0x207 which contain
3195 * link status information
3198 intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
3200 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3201 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
3204 /* These are source-specific values. */
3206 intel_dp_voltage_max(struct intel_dp *intel_dp)
3208 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3209 enum port port = dp_to_dig_port(intel_dp)->base.port;
3211 if (INTEL_GEN(dev_priv) >= 9) {
3212 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3213 return intel_ddi_dp_voltage_max(encoder);
3214 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3215 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3216 else if (IS_GEN7(dev_priv) && port == PORT_A)
3217 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3218 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
3219 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3221 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3225 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3227 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3228 enum port port = dp_to_dig_port(intel_dp)->base.port;
3230 if (INTEL_GEN(dev_priv) >= 9) {
3231 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3232 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3233 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3234 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3235 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3236 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3237 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3238 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3239 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3241 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3243 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3244 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3245 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3246 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3247 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3248 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3249 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3250 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3251 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3253 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3255 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3256 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3257 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3258 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3259 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3260 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3261 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3262 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3263 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3265 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3267 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
3268 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3269 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3270 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3273 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3275 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3278 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3279 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3280 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3281 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3282 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3283 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3284 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3285 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3287 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3292 static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
3294 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3295 unsigned long demph_reg_value, preemph_reg_value,
3296 uniqtranscale_reg_value;
3297 uint8_t train_set = intel_dp->train_set[0];
3299 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3300 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3301 preemph_reg_value = 0x0004000;
3302 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3303 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3304 demph_reg_value = 0x2B405555;
3305 uniqtranscale_reg_value = 0x552AB83A;
3307 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3308 demph_reg_value = 0x2B404040;
3309 uniqtranscale_reg_value = 0x5548B83A;
3311 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3312 demph_reg_value = 0x2B245555;
3313 uniqtranscale_reg_value = 0x5560B83A;
3315 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3316 demph_reg_value = 0x2B405555;
3317 uniqtranscale_reg_value = 0x5598DA3A;
3323 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3324 preemph_reg_value = 0x0002000;
3325 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3326 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3327 demph_reg_value = 0x2B404040;
3328 uniqtranscale_reg_value = 0x5552B83A;
3330 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3331 demph_reg_value = 0x2B404848;
3332 uniqtranscale_reg_value = 0x5580B83A;
3334 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3335 demph_reg_value = 0x2B404040;
3336 uniqtranscale_reg_value = 0x55ADDA3A;
3342 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3343 preemph_reg_value = 0x0000000;
3344 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3345 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3346 demph_reg_value = 0x2B305555;
3347 uniqtranscale_reg_value = 0x5570B83A;
3349 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3350 demph_reg_value = 0x2B2B4040;
3351 uniqtranscale_reg_value = 0x55ADDA3A;
3357 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3358 preemph_reg_value = 0x0006000;
3359 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3360 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3361 demph_reg_value = 0x1B405555;
3362 uniqtranscale_reg_value = 0x55ADDA3A;
3372 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3373 uniqtranscale_reg_value, 0);
3378 static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
3380 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3381 u32 deemph_reg_value, margin_reg_value;
3382 bool uniq_trans_scale = false;
3383 uint8_t train_set = intel_dp->train_set[0];
3385 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3386 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3387 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3388 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3389 deemph_reg_value = 128;
3390 margin_reg_value = 52;
3392 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3393 deemph_reg_value = 128;
3394 margin_reg_value = 77;
3396 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3397 deemph_reg_value = 128;
3398 margin_reg_value = 102;
3400 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3401 deemph_reg_value = 128;
3402 margin_reg_value = 154;
3403 uniq_trans_scale = true;
3409 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3410 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3411 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3412 deemph_reg_value = 85;
3413 margin_reg_value = 78;
3415 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3416 deemph_reg_value = 85;
3417 margin_reg_value = 116;
3419 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3420 deemph_reg_value = 85;
3421 margin_reg_value = 154;
3427 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3428 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3429 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3430 deemph_reg_value = 64;
3431 margin_reg_value = 104;
3433 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3434 deemph_reg_value = 64;
3435 margin_reg_value = 154;
3441 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3442 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3443 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3444 deemph_reg_value = 43;
3445 margin_reg_value = 154;
3455 chv_set_phy_signal_level(encoder, deemph_reg_value,
3456 margin_reg_value, uniq_trans_scale);
3462 gen4_signal_levels(uint8_t train_set)
3464 uint32_t signal_levels = 0;
3466 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3467 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3469 signal_levels |= DP_VOLTAGE_0_4;
3471 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3472 signal_levels |= DP_VOLTAGE_0_6;
3474 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3475 signal_levels |= DP_VOLTAGE_0_8;
3477 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3478 signal_levels |= DP_VOLTAGE_1_2;
3481 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3482 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3484 signal_levels |= DP_PRE_EMPHASIS_0;
3486 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3487 signal_levels |= DP_PRE_EMPHASIS_3_5;
3489 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3490 signal_levels |= DP_PRE_EMPHASIS_6;
3492 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3493 signal_levels |= DP_PRE_EMPHASIS_9_5;
3496 return signal_levels;
3499 /* Gen6's DP voltage swing and pre-emphasis control */
3501 gen6_edp_signal_levels(uint8_t train_set)
3503 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3504 DP_TRAIN_PRE_EMPHASIS_MASK);
3505 switch (signal_levels) {
3506 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3507 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3508 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3509 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3510 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
3511 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3512 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3513 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
3514 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3515 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3516 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
3517 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3518 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3519 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
3521 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3522 "0x%x\n", signal_levels);
3523 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3527 /* Gen7's DP voltage swing and pre-emphasis control */
3529 gen7_edp_signal_levels(uint8_t train_set)
3531 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3532 DP_TRAIN_PRE_EMPHASIS_MASK);
3533 switch (signal_levels) {
3534 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3535 return EDP_LINK_TRAIN_400MV_0DB_IVB;
3536 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3537 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
3538 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3539 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3541 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3542 return EDP_LINK_TRAIN_600MV_0DB_IVB;
3543 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3544 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3546 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3547 return EDP_LINK_TRAIN_800MV_0DB_IVB;
3548 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3549 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3552 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3553 "0x%x\n", signal_levels);
3554 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3559 intel_dp_set_signal_levels(struct intel_dp *intel_dp)
3561 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3562 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3563 enum port port = intel_dig_port->base.port;
3564 uint32_t signal_levels, mask = 0;
3565 uint8_t train_set = intel_dp->train_set[0];
3567 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3568 signal_levels = bxt_signal_levels(intel_dp);
3569 } else if (HAS_DDI(dev_priv)) {
3570 signal_levels = ddi_signal_levels(intel_dp);
3571 mask = DDI_BUF_EMP_MASK;
3572 } else if (IS_CHERRYVIEW(dev_priv)) {
3573 signal_levels = chv_signal_levels(intel_dp);
3574 } else if (IS_VALLEYVIEW(dev_priv)) {
3575 signal_levels = vlv_signal_levels(intel_dp);
3576 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
3577 signal_levels = gen7_edp_signal_levels(train_set);
3578 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
3579 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
3580 signal_levels = gen6_edp_signal_levels(train_set);
3581 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3583 signal_levels = gen4_signal_levels(train_set);
3584 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3588 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3590 DRM_DEBUG_KMS("Using vswing level %d\n",
3591 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3592 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3593 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3594 DP_TRAIN_PRE_EMPHASIS_SHIFT);
3596 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
3598 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3599 POSTING_READ(intel_dp->output_reg);
3603 intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3604 uint8_t dp_train_pat)
3606 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3607 struct drm_i915_private *dev_priv =
3608 to_i915(intel_dig_port->base.base.dev);
3610 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
3612 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3613 POSTING_READ(intel_dp->output_reg);
3616 void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
3618 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3619 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3620 enum port port = intel_dig_port->base.port;
3623 if (!HAS_DDI(dev_priv))
3626 val = I915_READ(DP_TP_CTL(port));
3627 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3628 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3629 I915_WRITE(DP_TP_CTL(port), val);
3632 * On PORT_A we can have only eDP in SST mode. There the only reason
3633 * we need to set idle transmission mode is to work around a HW issue
3634 * where we enable the pipe while not in idle link-training mode.
3635 * In this case there is requirement to wait for a minimum number of
3636 * idle patterns to be sent.
3641 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3642 DP_TP_STATUS_IDLE_DONE,
3643 DP_TP_STATUS_IDLE_DONE,
3645 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3649 intel_dp_link_down(struct intel_encoder *encoder,
3650 const struct intel_crtc_state *old_crtc_state)
3652 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3653 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3654 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
3655 enum port port = encoder->port;
3656 uint32_t DP = intel_dp->DP;
3658 if (WARN_ON(HAS_DDI(dev_priv)))
3661 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
3664 DRM_DEBUG_KMS("\n");
3666 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
3667 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
3668 DP &= ~DP_LINK_TRAIN_MASK_CPT;
3669 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
3671 if (IS_CHERRYVIEW(dev_priv))
3672 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3674 DP &= ~DP_LINK_TRAIN_MASK;
3675 DP |= DP_LINK_TRAIN_PAT_IDLE;
3677 I915_WRITE(intel_dp->output_reg, DP);
3678 POSTING_READ(intel_dp->output_reg);
3680 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3681 I915_WRITE(intel_dp->output_reg, DP);
3682 POSTING_READ(intel_dp->output_reg);
3685 * HW workaround for IBX, we need to move the port
3686 * to transcoder A after disabling it to allow the
3687 * matching HDMI port to be enabled on transcoder A.
3689 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
3691 * We get CPU/PCH FIFO underruns on the other pipe when
3692 * doing the workaround. Sweep them under the rug.
3694 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3695 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3697 /* always enable with pattern 1 (as per spec) */
3698 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3699 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3700 I915_WRITE(intel_dp->output_reg, DP);
3701 POSTING_READ(intel_dp->output_reg);
3704 I915_WRITE(intel_dp->output_reg, DP);
3705 POSTING_READ(intel_dp->output_reg);
3707 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
3708 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3709 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3712 msleep(intel_dp->panel_power_down_delay);
3716 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3718 intel_dp->active_pipe = INVALID_PIPE;
3719 pps_unlock(intel_dp);
3724 intel_dp_read_dpcd(struct intel_dp *intel_dp)
3726 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3727 sizeof(intel_dp->dpcd)) < 0)
3728 return false; /* aux transfer failed */
3730 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
3732 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3736 intel_edp_init_dpcd(struct intel_dp *intel_dp)
3738 struct drm_i915_private *dev_priv =
3739 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3741 /* this function is meant to be called only once */
3742 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3744 if (!intel_dp_read_dpcd(intel_dp))
3747 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3748 drm_dp_is_branch(intel_dp->dpcd));
3750 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3751 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3752 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3754 intel_psr_init_dpcd(intel_dp);
3757 * Read the eDP display control registers.
3759 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
3760 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
3761 * set, but require eDP 1.4+ detection (e.g. for supported link rates
3762 * method). The display control registers should read zero if they're
3763 * not supported anyway.
3765 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
3766 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3767 sizeof(intel_dp->edp_dpcd))
3768 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3769 intel_dp->edp_dpcd);
3771 /* Read the eDP 1.4+ supported link rates. */
3772 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
3773 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3776 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3777 sink_rates, sizeof(sink_rates));
3779 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3780 int val = le16_to_cpu(sink_rates[i]);
3785 /* Value read multiplied by 200kHz gives the per-lane
3786 * link rate in kHz. The source rates are, however,
3787 * stored in terms of LS_Clk kHz. The full conversion
3788 * back to symbols is
3789 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3791 intel_dp->sink_rates[i] = (val * 200) / 10;
3793 intel_dp->num_sink_rates = i;
3797 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
3798 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
3800 if (intel_dp->num_sink_rates)
3801 intel_dp->use_rate_select = true;
3803 intel_dp_set_sink_rates(intel_dp);
3805 intel_dp_set_common_rates(intel_dp);
3812 intel_dp_get_dpcd(struct intel_dp *intel_dp)
3816 if (!intel_dp_read_dpcd(intel_dp))
3819 /* Don't clobber cached eDP rates. */
3820 if (!intel_dp_is_edp(intel_dp)) {
3821 intel_dp_set_sink_rates(intel_dp);
3822 intel_dp_set_common_rates(intel_dp);
3825 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
3829 * Sink count can change between short pulse hpd hence
3830 * a member variable in intel_dp will track any changes
3831 * between short pulse interrupts.
3833 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
3836 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3837 * a dongle is present but no display. Unless we require to know
3838 * if a dongle is present or not, we don't need to update
3839 * downstream port information. So, an early return here saves
3840 * time from performing other operations which are not required.
3842 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
3845 if (!drm_dp_is_branch(intel_dp->dpcd))
3846 return true; /* native DP sink */
3848 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3849 return true; /* no per-port downstream info */
3851 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3852 intel_dp->downstream_ports,
3853 DP_MAX_DOWNSTREAM_PORTS) < 0)
3854 return false; /* downstream port status fetch failed */
3860 intel_dp_can_mst(struct intel_dp *intel_dp)
3864 if (!i915_modparams.enable_dp_mst)
3867 if (!intel_dp->can_mst)
3870 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3873 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
3876 return mstm_cap & DP_MST_CAP;
3880 intel_dp_configure_mst(struct intel_dp *intel_dp)
3882 if (!i915_modparams.enable_dp_mst)
3885 if (!intel_dp->can_mst)
3888 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3890 if (intel_dp->is_mst)
3891 DRM_DEBUG_KMS("Sink is MST capable\n");
3893 DRM_DEBUG_KMS("Sink is not MST capable\n");
3895 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3899 static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp,
3900 struct intel_crtc_state *crtc_state, bool disable_wa)
3902 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3903 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3904 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3910 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
3911 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
3916 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3917 buf & ~DP_TEST_SINK_START) < 0) {
3918 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
3924 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3926 if (drm_dp_dpcd_readb(&intel_dp->aux,
3927 DP_TEST_SINK_MISC, &buf) < 0) {
3931 count = buf & DP_TEST_COUNT_MASK;
3932 } while (--attempts && count);
3934 if (attempts == 0) {
3935 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
3941 hsw_enable_ips(crtc_state);
3945 static int intel_dp_sink_crc_start(struct intel_dp *intel_dp,
3946 struct intel_crtc_state *crtc_state)
3948 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3949 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3950 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3954 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3957 if (!(buf & DP_TEST_CRC_SUPPORTED))
3960 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3963 if (buf & DP_TEST_SINK_START) {
3964 ret = intel_dp_sink_crc_stop(intel_dp, crtc_state, false);
3969 hsw_disable_ips(crtc_state);
3971 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3972 buf | DP_TEST_SINK_START) < 0) {
3973 hsw_enable_ips(crtc_state);
3977 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3981 int intel_dp_sink_crc(struct intel_dp *intel_dp, struct intel_crtc_state *crtc_state, u8 *crc)
3983 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3984 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3985 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3990 ret = intel_dp_sink_crc_start(intel_dp, crtc_state);
3995 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3997 if (drm_dp_dpcd_readb(&intel_dp->aux,
3998 DP_TEST_SINK_MISC, &buf) < 0) {
4002 count = buf & DP_TEST_COUNT_MASK;
4004 } while (--attempts && count == 0);
4006 if (attempts == 0) {
4007 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
4012 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
4018 intel_dp_sink_crc_stop(intel_dp, crtc_state, true);
4023 intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4025 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
4026 sink_irq_vector) == 1;
4030 intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4032 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4033 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4037 static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
4041 uint8_t test_lane_count, test_link_bw;
4045 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4046 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4050 DRM_DEBUG_KMS("Lane count read failed\n");
4053 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
4055 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4058 DRM_DEBUG_KMS("Link Rate read failed\n");
4061 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
4063 /* Validate the requested link rate and lane count */
4064 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4068 intel_dp->compliance.test_lane_count = test_lane_count;
4069 intel_dp->compliance.test_link_rate = test_link_rate;
4074 static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4076 uint8_t test_pattern;
4078 __be16 h_width, v_height;
4081 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
4082 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4085 DRM_DEBUG_KMS("Test pattern read failed\n");
4088 if (test_pattern != DP_COLOR_RAMP)
4091 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4094 DRM_DEBUG_KMS("H Width read failed\n");
4098 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4101 DRM_DEBUG_KMS("V Height read failed\n");
4105 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4108 DRM_DEBUG_KMS("TEST MISC read failed\n");
4111 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4113 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4115 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4116 case DP_TEST_BIT_DEPTH_6:
4117 intel_dp->compliance.test_data.bpc = 6;
4119 case DP_TEST_BIT_DEPTH_8:
4120 intel_dp->compliance.test_data.bpc = 8;
4126 intel_dp->compliance.test_data.video_pattern = test_pattern;
4127 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4128 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4129 /* Set test active flag here so userspace doesn't interrupt things */
4130 intel_dp->compliance.test_active = 1;
4135 static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4137 uint8_t test_result = DP_TEST_ACK;
4138 struct intel_connector *intel_connector = intel_dp->attached_connector;
4139 struct drm_connector *connector = &intel_connector->base;
4141 if (intel_connector->detect_edid == NULL ||
4142 connector->edid_corrupt ||
4143 intel_dp->aux.i2c_defer_count > 6) {
4144 /* Check EDID read for NACKs, DEFERs and corruption
4145 * (DP CTS 1.2 Core r1.1)
4146 * 4.2.2.4 : Failed EDID read, I2C_NAK
4147 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4148 * 4.2.2.6 : EDID corruption detected
4149 * Use failsafe mode for all cases
4151 if (intel_dp->aux.i2c_nack_count > 0 ||
4152 intel_dp->aux.i2c_defer_count > 0)
4153 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4154 intel_dp->aux.i2c_nack_count,
4155 intel_dp->aux.i2c_defer_count);
4156 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
4158 struct edid *block = intel_connector->detect_edid;
4160 /* We have to write the checksum
4161 * of the last block read
4163 block += intel_connector->detect_edid->extensions;
4165 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4166 block->checksum) <= 0)
4167 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4169 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
4170 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
4173 /* Set test active flag here so userspace doesn't interrupt things */
4174 intel_dp->compliance.test_active = 1;
4179 static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4181 uint8_t test_result = DP_TEST_NAK;
4185 static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4187 uint8_t response = DP_TEST_NAK;
4188 uint8_t request = 0;
4191 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
4193 DRM_DEBUG_KMS("Could not read test request from sink\n");
4198 case DP_TEST_LINK_TRAINING:
4199 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
4200 response = intel_dp_autotest_link_training(intel_dp);
4202 case DP_TEST_LINK_VIDEO_PATTERN:
4203 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
4204 response = intel_dp_autotest_video_pattern(intel_dp);
4206 case DP_TEST_LINK_EDID_READ:
4207 DRM_DEBUG_KMS("EDID test requested\n");
4208 response = intel_dp_autotest_edid(intel_dp);
4210 case DP_TEST_LINK_PHY_TEST_PATTERN:
4211 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
4212 response = intel_dp_autotest_phy_pattern(intel_dp);
4215 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
4219 if (response & DP_TEST_ACK)
4220 intel_dp->compliance.test_type = request;
4223 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
4225 DRM_DEBUG_KMS("Could not write test response to sink\n");
4229 intel_dp_check_mst_status(struct intel_dp *intel_dp)
4233 if (intel_dp->is_mst) {
4234 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
4238 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4242 /* check link status - esi[10] = 0x200c */
4243 if (intel_dp->active_mst_links &&
4244 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
4245 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4246 intel_dp_start_link_train(intel_dp);
4247 intel_dp_stop_link_train(intel_dp);
4250 DRM_DEBUG_KMS("got esi %3ph\n", esi);
4251 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4254 for (retry = 0; retry < 3; retry++) {
4256 wret = drm_dp_dpcd_write(&intel_dp->aux,
4257 DP_SINK_COUNT_ESI+1,
4264 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4266 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
4274 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4275 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4276 intel_dp->is_mst = false;
4277 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4278 /* send a hotplug event */
4279 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4286 intel_dp_retrain_link(struct intel_dp *intel_dp)
4288 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4289 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4290 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4292 /* Suppress underruns caused by re-training */
4293 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4294 if (crtc->config->has_pch_encoder)
4295 intel_set_pch_fifo_underrun_reporting(dev_priv,
4296 intel_crtc_pch_transcoder(crtc), false);
4298 intel_dp_start_link_train(intel_dp);
4299 intel_dp_stop_link_train(intel_dp);
4301 /* Keep underrun reporting disabled until things are stable */
4302 intel_wait_for_vblank(dev_priv, crtc->pipe);
4304 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4305 if (crtc->config->has_pch_encoder)
4306 intel_set_pch_fifo_underrun_reporting(dev_priv,
4307 intel_crtc_pch_transcoder(crtc), true);
4311 intel_dp_check_link_status(struct intel_dp *intel_dp)
4313 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4314 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4315 struct drm_connector_state *conn_state =
4316 intel_dp->attached_connector->base.state;
4317 u8 link_status[DP_LINK_STATUS_SIZE];
4319 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
4321 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4322 DRM_ERROR("Failed to get link status\n");
4326 if (!conn_state->crtc)
4329 WARN_ON(!drm_modeset_is_locked(&conn_state->crtc->mutex));
4331 if (!conn_state->crtc->state->active)
4334 if (conn_state->commit &&
4335 !try_wait_for_completion(&conn_state->commit->hw_done))
4339 * Validate the cached values of intel_dp->link_rate and
4340 * intel_dp->lane_count before attempting to retrain.
4342 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4343 intel_dp->lane_count))
4346 /* Retrain if Channel EQ or CR not ok */
4347 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
4348 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4349 intel_encoder->base.name);
4351 intel_dp_retrain_link(intel_dp);
4356 * According to DP spec
4359 * 2. Configure link according to Receiver Capabilities
4360 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4361 * 4. Check link status on receipt of hot-plug interrupt
4363 * intel_dp_short_pulse - handles short pulse interrupts
4364 * when full detection is not required.
4365 * Returns %true if short pulse is handled and full detection
4366 * is NOT required and %false otherwise.
4369 intel_dp_short_pulse(struct intel_dp *intel_dp)
4371 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4372 u8 sink_irq_vector = 0;
4373 u8 old_sink_count = intel_dp->sink_count;
4377 * Clearing compliance test variables to allow capturing
4378 * of values for next automated test request.
4380 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
4383 * Now read the DPCD to see if it's actually running
4384 * If the current value of sink count doesn't match with
4385 * the value that was stored earlier or dpcd read failed
4386 * we need to do full detection
4388 ret = intel_dp_get_dpcd(intel_dp);
4390 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4391 /* No need to proceed if we are going to do full detect */
4395 /* Try to read the source of the interrupt */
4396 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4397 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4398 sink_irq_vector != 0) {
4399 /* Clear interrupt source */
4400 drm_dp_dpcd_writeb(&intel_dp->aux,
4401 DP_DEVICE_SERVICE_IRQ_VECTOR,
4404 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4405 intel_dp_handle_test_request(intel_dp);
4406 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4407 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4410 intel_dp_check_link_status(intel_dp);
4412 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4413 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4414 /* Send a Hotplug Uevent to userspace to start modeset */
4415 drm_kms_helper_hotplug_event(&dev_priv->drm);
4421 /* XXX this is probably wrong for multiple downstream ports */
4422 static enum drm_connector_status
4423 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
4425 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
4426 uint8_t *dpcd = intel_dp->dpcd;
4430 lspcon_resume(lspcon);
4432 if (!intel_dp_get_dpcd(intel_dp))
4433 return connector_status_disconnected;
4435 if (intel_dp_is_edp(intel_dp))
4436 return connector_status_connected;
4438 /* if there's no downstream port, we're done */
4439 if (!drm_dp_is_branch(dpcd))
4440 return connector_status_connected;
4442 /* If we're HPD-aware, SINK_COUNT changes dynamically */
4443 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4444 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
4446 return intel_dp->sink_count ?
4447 connector_status_connected : connector_status_disconnected;
4450 if (intel_dp_can_mst(intel_dp))
4451 return connector_status_connected;
4453 /* If no HPD, poke DDC gently */
4454 if (drm_probe_ddc(&intel_dp->aux.ddc))
4455 return connector_status_connected;
4457 /* Well we tried, say unknown for unreliable port types */
4458 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4459 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4460 if (type == DP_DS_PORT_TYPE_VGA ||
4461 type == DP_DS_PORT_TYPE_NON_EDID)
4462 return connector_status_unknown;
4464 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4465 DP_DWN_STRM_PORT_TYPE_MASK;
4466 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4467 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4468 return connector_status_unknown;
4471 /* Anything else is out of spec, warn and ignore */
4472 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
4473 return connector_status_disconnected;
4476 static enum drm_connector_status
4477 edp_detect(struct intel_dp *intel_dp)
4479 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4480 enum drm_connector_status status;
4482 status = intel_panel_detect(dev_priv);
4483 if (status == connector_status_unknown)
4484 status = connector_status_connected;
4489 static bool ibx_digital_port_connected(struct intel_encoder *encoder)
4491 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4494 switch (encoder->hpd_pin) {
4496 bit = SDE_PORTB_HOTPLUG;
4499 bit = SDE_PORTC_HOTPLUG;
4502 bit = SDE_PORTD_HOTPLUG;
4505 MISSING_CASE(encoder->hpd_pin);
4509 return I915_READ(SDEISR) & bit;
4512 static bool cpt_digital_port_connected(struct intel_encoder *encoder)
4514 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4517 switch (encoder->hpd_pin) {
4519 bit = SDE_PORTB_HOTPLUG_CPT;
4522 bit = SDE_PORTC_HOTPLUG_CPT;
4525 bit = SDE_PORTD_HOTPLUG_CPT;
4528 MISSING_CASE(encoder->hpd_pin);
4532 return I915_READ(SDEISR) & bit;
4535 static bool spt_digital_port_connected(struct intel_encoder *encoder)
4537 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4540 switch (encoder->hpd_pin) {
4542 bit = SDE_PORTA_HOTPLUG_SPT;
4545 bit = SDE_PORTE_HOTPLUG_SPT;
4548 return cpt_digital_port_connected(encoder);
4551 return I915_READ(SDEISR) & bit;
4554 static bool g4x_digital_port_connected(struct intel_encoder *encoder)
4556 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4559 switch (encoder->hpd_pin) {
4561 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4564 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4567 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4570 MISSING_CASE(encoder->hpd_pin);
4574 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4577 static bool gm45_digital_port_connected(struct intel_encoder *encoder)
4579 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4582 switch (encoder->hpd_pin) {
4584 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
4587 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
4590 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
4593 MISSING_CASE(encoder->hpd_pin);
4597 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4600 static bool ilk_digital_port_connected(struct intel_encoder *encoder)
4602 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4604 if (encoder->hpd_pin == HPD_PORT_A)
4605 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4607 return ibx_digital_port_connected(encoder);
4610 static bool snb_digital_port_connected(struct intel_encoder *encoder)
4612 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4614 if (encoder->hpd_pin == HPD_PORT_A)
4615 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4617 return cpt_digital_port_connected(encoder);
4620 static bool ivb_digital_port_connected(struct intel_encoder *encoder)
4622 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4624 if (encoder->hpd_pin == HPD_PORT_A)
4625 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4627 return cpt_digital_port_connected(encoder);
4630 static bool bdw_digital_port_connected(struct intel_encoder *encoder)
4632 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4634 if (encoder->hpd_pin == HPD_PORT_A)
4635 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4637 return cpt_digital_port_connected(encoder);
4640 static bool bxt_digital_port_connected(struct intel_encoder *encoder)
4642 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4645 switch (encoder->hpd_pin) {
4647 bit = BXT_DE_PORT_HP_DDIA;
4650 bit = BXT_DE_PORT_HP_DDIB;
4653 bit = BXT_DE_PORT_HP_DDIC;
4656 MISSING_CASE(encoder->hpd_pin);
4660 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4664 * intel_digital_port_connected - is the specified port connected?
4665 * @encoder: intel_encoder
4667 * Return %true if port is connected, %false otherwise.
4669 bool intel_digital_port_connected(struct intel_encoder *encoder)
4671 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4673 if (HAS_GMCH_DISPLAY(dev_priv)) {
4674 if (IS_GM45(dev_priv))
4675 return gm45_digital_port_connected(encoder);
4677 return g4x_digital_port_connected(encoder);
4680 if (IS_GEN5(dev_priv))
4681 return ilk_digital_port_connected(encoder);
4682 else if (IS_GEN6(dev_priv))
4683 return snb_digital_port_connected(encoder);
4684 else if (IS_GEN7(dev_priv))
4685 return ivb_digital_port_connected(encoder);
4686 else if (IS_GEN8(dev_priv))
4687 return bdw_digital_port_connected(encoder);
4688 else if (IS_GEN9_LP(dev_priv))
4689 return bxt_digital_port_connected(encoder);
4691 return spt_digital_port_connected(encoder);
4694 static struct edid *
4695 intel_dp_get_edid(struct intel_dp *intel_dp)
4697 struct intel_connector *intel_connector = intel_dp->attached_connector;
4699 /* use cached edid if we have one */
4700 if (intel_connector->edid) {
4702 if (IS_ERR(intel_connector->edid))
4705 return drm_edid_duplicate(intel_connector->edid);
4707 return drm_get_edid(&intel_connector->base,
4708 &intel_dp->aux.ddc);
4712 intel_dp_set_edid(struct intel_dp *intel_dp)
4714 struct intel_connector *intel_connector = intel_dp->attached_connector;
4717 intel_dp_unset_edid(intel_dp);
4718 edid = intel_dp_get_edid(intel_dp);
4719 intel_connector->detect_edid = edid;
4721 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4725 intel_dp_unset_edid(struct intel_dp *intel_dp)
4727 struct intel_connector *intel_connector = intel_dp->attached_connector;
4729 kfree(intel_connector->detect_edid);
4730 intel_connector->detect_edid = NULL;
4732 intel_dp->has_audio = false;
4736 intel_dp_long_pulse(struct intel_connector *connector)
4738 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
4739 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
4740 enum drm_connector_status status;
4741 u8 sink_irq_vector = 0;
4743 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
4745 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
4747 /* Can't disconnect eDP, but you can close the lid... */
4748 if (intel_dp_is_edp(intel_dp))
4749 status = edp_detect(intel_dp);
4750 else if (intel_digital_port_connected(&dp_to_dig_port(intel_dp)->base))
4751 status = intel_dp_detect_dpcd(intel_dp);
4753 status = connector_status_disconnected;
4755 if (status == connector_status_disconnected) {
4756 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
4758 if (intel_dp->is_mst) {
4759 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4761 intel_dp->mst_mgr.mst_state);
4762 intel_dp->is_mst = false;
4763 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4770 if (intel_dp->reset_link_params) {
4771 /* Initial max link lane count */
4772 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
4774 /* Initial max link rate */
4775 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
4777 intel_dp->reset_link_params = false;
4780 intel_dp_print_rates(intel_dp);
4782 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4783 drm_dp_is_branch(intel_dp->dpcd));
4785 intel_dp_configure_mst(intel_dp);
4787 if (intel_dp->is_mst) {
4789 * If we are in MST mode then this connector
4790 * won't appear connected or have anything
4793 status = connector_status_disconnected;
4797 * If display is now connected check links status,
4798 * there has been known issues of link loss triggerring
4801 * Some sinks (eg. ASUS PB287Q) seem to perform some
4802 * weird HPD ping pong during modesets. So we can apparently
4803 * end up with HPD going low during a modeset, and then
4804 * going back up soon after. And once that happens we must
4805 * retrain the link to get a picture. That's in case no
4806 * userspace component reacted to intermittent HPD dip.
4808 intel_dp_check_link_status(intel_dp);
4812 * Clearing NACK and defer counts to get their exact values
4813 * while reading EDID which are required by Compliance tests
4814 * 4.2.2.4 and 4.2.2.5
4816 intel_dp->aux.i2c_nack_count = 0;
4817 intel_dp->aux.i2c_defer_count = 0;
4819 intel_dp_set_edid(intel_dp);
4820 if (intel_dp_is_edp(intel_dp) || connector->detect_edid)
4821 status = connector_status_connected;
4822 intel_dp->detect_done = true;
4824 /* Try to read the source of the interrupt */
4825 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4826 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4827 sink_irq_vector != 0) {
4828 /* Clear interrupt source */
4829 drm_dp_dpcd_writeb(&intel_dp->aux,
4830 DP_DEVICE_SERVICE_IRQ_VECTOR,
4833 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4834 intel_dp_handle_test_request(intel_dp);
4835 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4836 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4840 if (status != connector_status_connected && !intel_dp->is_mst)
4841 intel_dp_unset_edid(intel_dp);
4843 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
4848 intel_dp_detect(struct drm_connector *connector,
4849 struct drm_modeset_acquire_ctx *ctx,
4852 struct intel_dp *intel_dp = intel_attached_dp(connector);
4853 int status = connector->status;
4855 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4856 connector->base.id, connector->name);
4858 /* If full detect is not performed yet, do a full detect */
4859 if (!intel_dp->detect_done) {
4860 struct drm_crtc *crtc;
4863 crtc = connector->state->crtc;
4865 ret = drm_modeset_lock(&crtc->mutex, ctx);
4870 status = intel_dp_long_pulse(intel_dp->attached_connector);
4873 intel_dp->detect_done = false;
4879 intel_dp_force(struct drm_connector *connector)
4881 struct intel_dp *intel_dp = intel_attached_dp(connector);
4882 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4883 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
4885 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4886 connector->base.id, connector->name);
4887 intel_dp_unset_edid(intel_dp);
4889 if (connector->status != connector_status_connected)
4892 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
4894 intel_dp_set_edid(intel_dp);
4896 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
4899 static int intel_dp_get_modes(struct drm_connector *connector)
4901 struct intel_connector *intel_connector = to_intel_connector(connector);
4904 edid = intel_connector->detect_edid;
4906 int ret = intel_connector_update_modes(connector, edid);
4911 /* if eDP has no EDID, fall back to fixed mode */
4912 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
4913 intel_connector->panel.fixed_mode) {
4914 struct drm_display_mode *mode;
4916 mode = drm_mode_duplicate(connector->dev,
4917 intel_connector->panel.fixed_mode);
4919 drm_mode_probed_add(connector, mode);
4928 intel_dp_connector_register(struct drm_connector *connector)
4930 struct intel_dp *intel_dp = intel_attached_dp(connector);
4933 ret = intel_connector_register(connector);
4937 i915_debugfs_connector_add(connector);
4939 DRM_DEBUG_KMS("registering %s bus for %s\n",
4940 intel_dp->aux.name, connector->kdev->kobj.name);
4942 intel_dp->aux.dev = connector->kdev;
4943 return drm_dp_aux_register(&intel_dp->aux);
4947 intel_dp_connector_unregister(struct drm_connector *connector)
4949 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4950 intel_connector_unregister(connector);
4954 intel_dp_connector_destroy(struct drm_connector *connector)
4956 struct intel_connector *intel_connector = to_intel_connector(connector);
4958 kfree(intel_connector->detect_edid);
4960 if (!IS_ERR_OR_NULL(intel_connector->edid))
4961 kfree(intel_connector->edid);
4964 * Can't call intel_dp_is_edp() since the encoder may have been
4965 * destroyed already.
4967 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4968 intel_panel_fini(&intel_connector->panel);
4970 drm_connector_cleanup(connector);
4974 void intel_dp_encoder_destroy(struct drm_encoder *encoder)
4976 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4977 struct intel_dp *intel_dp = &intel_dig_port->dp;
4979 intel_dp_mst_encoder_cleanup(intel_dig_port);
4980 if (intel_dp_is_edp(intel_dp)) {
4981 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4983 * vdd might still be enabled do to the delayed vdd off.
4984 * Make sure vdd is actually turned off here.
4987 edp_panel_vdd_off_sync(intel_dp);
4988 pps_unlock(intel_dp);
4990 if (intel_dp->edp_notifier.notifier_call) {
4991 unregister_reboot_notifier(&intel_dp->edp_notifier);
4992 intel_dp->edp_notifier.notifier_call = NULL;
4996 intel_dp_aux_fini(intel_dp);
4998 drm_encoder_cleanup(encoder);
4999 kfree(intel_dig_port);
5002 void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
5004 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
5006 if (!intel_dp_is_edp(intel_dp))
5010 * vdd might still be enabled do to the delayed vdd off.
5011 * Make sure vdd is actually turned off here.
5013 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5015 edp_panel_vdd_off_sync(intel_dp);
5016 pps_unlock(intel_dp);
5020 int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *intel_dig_port,
5023 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_dig_port->base.base);
5024 uint8_t txbuf[4], rxbuf[2], reply = 0;
5028 /* Output An first, that's easy */
5029 dpcd_ret = drm_dp_dpcd_write(&intel_dig_port->dp.aux, DP_AUX_HDCP_AN,
5030 an, DRM_HDCP_AN_LEN);
5031 if (dpcd_ret != DRM_HDCP_AN_LEN) {
5032 DRM_ERROR("Failed to write An over DP/AUX (%zd)\n", dpcd_ret);
5033 return dpcd_ret >= 0 ? -EIO : dpcd_ret;
5037 * Since Aksv is Oh-So-Secret, we can't access it in software. So in
5038 * order to get it on the wire, we need to create the AUX header as if
5039 * we were writing the data, and then tickle the hardware to output the
5040 * data once the header is sent out.
5042 txbuf[0] = (DP_AUX_NATIVE_WRITE << 4) |
5043 ((DP_AUX_HDCP_AKSV >> 16) & 0xf);
5044 txbuf[1] = (DP_AUX_HDCP_AKSV >> 8) & 0xff;
5045 txbuf[2] = DP_AUX_HDCP_AKSV & 0xff;
5046 txbuf[3] = DRM_HDCP_KSV_LEN - 1;
5048 ret = intel_dp_aux_ch(intel_dp, txbuf, sizeof(txbuf), rxbuf,
5049 sizeof(rxbuf), true);
5051 DRM_ERROR("Write Aksv over DP/AUX failed (%d)\n", ret);
5053 } else if (ret == 0) {
5054 DRM_ERROR("Aksv write over DP/AUX was empty\n");
5058 reply = (rxbuf[0] >> 4) & DP_AUX_NATIVE_REPLY_MASK;
5059 return reply == DP_AUX_NATIVE_REPLY_ACK ? 0 : -EIO;
5062 static int intel_dp_hdcp_read_bksv(struct intel_digital_port *intel_dig_port,
5066 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BKSV, bksv,
5068 if (ret != DRM_HDCP_KSV_LEN) {
5069 DRM_ERROR("Read Bksv from DP/AUX failed (%zd)\n", ret);
5070 return ret >= 0 ? -EIO : ret;
5075 static int intel_dp_hdcp_read_bstatus(struct intel_digital_port *intel_dig_port,
5080 * For some reason the HDMI and DP HDCP specs call this register
5081 * definition by different names. In the HDMI spec, it's called BSTATUS,
5082 * but in DP it's called BINFO.
5084 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BINFO,
5085 bstatus, DRM_HDCP_BSTATUS_LEN);
5086 if (ret != DRM_HDCP_BSTATUS_LEN) {
5087 DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret);
5088 return ret >= 0 ? -EIO : ret;
5094 int intel_dp_hdcp_read_bcaps(struct intel_digital_port *intel_dig_port,
5099 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BCAPS,
5102 DRM_ERROR("Read bcaps from DP/AUX failed (%zd)\n", ret);
5103 return ret >= 0 ? -EIO : ret;
5110 int intel_dp_hdcp_repeater_present(struct intel_digital_port *intel_dig_port,
5111 bool *repeater_present)
5116 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
5120 *repeater_present = bcaps & DP_BCAPS_REPEATER_PRESENT;
5125 int intel_dp_hdcp_read_ri_prime(struct intel_digital_port *intel_dig_port,
5129 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_RI_PRIME,
5130 ri_prime, DRM_HDCP_RI_LEN);
5131 if (ret != DRM_HDCP_RI_LEN) {
5132 DRM_ERROR("Read Ri' from DP/AUX failed (%zd)\n", ret);
5133 return ret >= 0 ? -EIO : ret;
5139 int intel_dp_hdcp_read_ksv_ready(struct intel_digital_port *intel_dig_port,
5144 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
5147 DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret);
5148 return ret >= 0 ? -EIO : ret;
5150 *ksv_ready = bstatus & DP_BSTATUS_READY;
5155 int intel_dp_hdcp_read_ksv_fifo(struct intel_digital_port *intel_dig_port,
5156 int num_downstream, u8 *ksv_fifo)
5161 /* KSV list is read via 15 byte window (3 entries @ 5 bytes each) */
5162 for (i = 0; i < num_downstream; i += 3) {
5163 size_t len = min(num_downstream - i, 3) * DRM_HDCP_KSV_LEN;
5164 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
5165 DP_AUX_HDCP_KSV_FIFO,
5166 ksv_fifo + i * DRM_HDCP_KSV_LEN,
5169 DRM_ERROR("Read ksv[%d] from DP/AUX failed (%zd)\n", i,
5171 return ret >= 0 ? -EIO : ret;
5178 int intel_dp_hdcp_read_v_prime_part(struct intel_digital_port *intel_dig_port,
5183 if (i >= DRM_HDCP_V_PRIME_NUM_PARTS)
5186 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
5187 DP_AUX_HDCP_V_PRIME(i), part,
5188 DRM_HDCP_V_PRIME_PART_LEN);
5189 if (ret != DRM_HDCP_V_PRIME_PART_LEN) {
5190 DRM_ERROR("Read v'[%d] from DP/AUX failed (%zd)\n", i, ret);
5191 return ret >= 0 ? -EIO : ret;
5197 int intel_dp_hdcp_toggle_signalling(struct intel_digital_port *intel_dig_port,
5200 /* Not used for single stream DisplayPort setups */
5205 bool intel_dp_hdcp_check_link(struct intel_digital_port *intel_dig_port)
5210 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
5213 DRM_ERROR("Read bstatus from DP/AUX failed (%zd)\n", ret);
5217 return !(bstatus & (DP_BSTATUS_LINK_FAILURE | DP_BSTATUS_REAUTH_REQ));
5221 int intel_dp_hdcp_capable(struct intel_digital_port *intel_dig_port,
5227 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
5231 *hdcp_capable = bcaps & DP_BCAPS_HDCP_CAPABLE;
5235 static const struct intel_hdcp_shim intel_dp_hdcp_shim = {
5236 .write_an_aksv = intel_dp_hdcp_write_an_aksv,
5237 .read_bksv = intel_dp_hdcp_read_bksv,
5238 .read_bstatus = intel_dp_hdcp_read_bstatus,
5239 .repeater_present = intel_dp_hdcp_repeater_present,
5240 .read_ri_prime = intel_dp_hdcp_read_ri_prime,
5241 .read_ksv_ready = intel_dp_hdcp_read_ksv_ready,
5242 .read_ksv_fifo = intel_dp_hdcp_read_ksv_fifo,
5243 .read_v_prime_part = intel_dp_hdcp_read_v_prime_part,
5244 .toggle_signalling = intel_dp_hdcp_toggle_signalling,
5245 .check_link = intel_dp_hdcp_check_link,
5246 .hdcp_capable = intel_dp_hdcp_capable,
5249 static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
5251 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5253 lockdep_assert_held(&dev_priv->pps_mutex);
5255 if (!edp_have_panel_vdd(intel_dp))
5259 * The VDD bit needs a power domain reference, so if the bit is
5260 * already enabled when we boot or resume, grab this reference and
5261 * schedule a vdd off, so we don't hold on to the reference
5264 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
5265 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
5267 edp_panel_vdd_schedule_off(intel_dp);
5270 static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5272 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5274 if ((intel_dp->DP & DP_PORT_EN) == 0)
5275 return INVALID_PIPE;
5277 if (IS_CHERRYVIEW(dev_priv))
5278 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5280 return PORT_TO_PIPE(intel_dp->DP);
5283 void intel_dp_encoder_reset(struct drm_encoder *encoder)
5285 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
5286 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5287 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
5289 if (!HAS_DDI(dev_priv))
5290 intel_dp->DP = I915_READ(intel_dp->output_reg);
5293 lspcon_resume(lspcon);
5295 intel_dp->reset_link_params = true;
5299 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5300 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5302 if (intel_dp_is_edp(intel_dp)) {
5303 /* Reinit the power sequencer, in case BIOS did something with it. */
5304 intel_dp_pps_init(intel_dp);
5305 intel_edp_panel_vdd_sanitize(intel_dp);
5308 pps_unlock(intel_dp);
5311 static const struct drm_connector_funcs intel_dp_connector_funcs = {
5312 .force = intel_dp_force,
5313 .fill_modes = drm_helper_probe_single_connector_modes,
5314 .atomic_get_property = intel_digital_connector_atomic_get_property,
5315 .atomic_set_property = intel_digital_connector_atomic_set_property,
5316 .late_register = intel_dp_connector_register,
5317 .early_unregister = intel_dp_connector_unregister,
5318 .destroy = intel_dp_connector_destroy,
5319 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
5320 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
5323 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5324 .detect_ctx = intel_dp_detect,
5325 .get_modes = intel_dp_get_modes,
5326 .mode_valid = intel_dp_mode_valid,
5327 .atomic_check = intel_digital_connector_atomic_check,
5330 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
5331 .reset = intel_dp_encoder_reset,
5332 .destroy = intel_dp_encoder_destroy,
5336 intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5338 struct intel_dp *intel_dp = &intel_dig_port->dp;
5339 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5340 enum irqreturn ret = IRQ_NONE;
5342 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5344 * vdd off can generate a long pulse on eDP which
5345 * would require vdd on to handle it, and thus we
5346 * would end up in an endless cycle of
5347 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5349 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5350 port_name(intel_dig_port->base.port));
5354 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5355 port_name(intel_dig_port->base.port),
5356 long_hpd ? "long" : "short");
5359 intel_dp->reset_link_params = true;
5360 intel_dp->detect_done = false;
5364 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
5366 if (intel_dp->is_mst) {
5367 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5369 * If we were in MST mode, and device is not
5370 * there, get out of MST mode
5372 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5373 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5374 intel_dp->is_mst = false;
5375 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5377 intel_dp->detect_done = false;
5382 if (!intel_dp->is_mst) {
5383 struct drm_modeset_acquire_ctx ctx;
5384 struct drm_connector *connector = &intel_dp->attached_connector->base;
5385 struct drm_crtc *crtc;
5387 bool handled = false;
5389 drm_modeset_acquire_init(&ctx, 0);
5391 iret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, &ctx);
5395 crtc = connector->state->crtc;
5397 iret = drm_modeset_lock(&crtc->mutex, &ctx);
5402 handled = intel_dp_short_pulse(intel_dp);
5405 if (iret == -EDEADLK) {
5406 drm_modeset_backoff(&ctx);
5410 drm_modeset_drop_locks(&ctx);
5411 drm_modeset_acquire_fini(&ctx);
5412 WARN(iret, "Acquiring modeset locks failed with %i\n", iret);
5414 /* Short pulse can signify loss of hdcp authentication */
5415 intel_hdcp_check_link(intel_dp->attached_connector);
5418 intel_dp->detect_done = false;
5426 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
5431 /* check the VBT to see whether the eDP is on another port */
5432 bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
5435 * eDP not supported on g4x. so bail out early just
5436 * for a bit extra safety in case the VBT is bonkers.
5438 if (INTEL_GEN(dev_priv) < 5)
5441 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
5444 return intel_bios_is_port_edp(dev_priv, port);
5448 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5450 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5451 enum port port = dp_to_dig_port(intel_dp)->base.port;
5453 if (!IS_G4X(dev_priv) && port != PORT_A)
5454 intel_attach_force_audio_property(connector);
5456 intel_attach_broadcast_rgb_property(connector);
5458 if (intel_dp_is_edp(intel_dp)) {
5459 u32 allowed_scalers;
5461 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5462 if (!HAS_GMCH_DISPLAY(dev_priv))
5463 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5465 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5467 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
5472 static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5474 intel_dp->panel_power_off_time = ktime_get_boottime();
5475 intel_dp->last_power_on = jiffies;
5476 intel_dp->last_backlight_off = jiffies;
5480 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
5482 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5483 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
5484 struct pps_registers regs;
5486 intel_pps_get_registers(intel_dp, ®s);
5488 /* Workaround: Need to write PP_CONTROL with the unlock key as
5489 * the very first thing. */
5490 pp_ctl = ironlake_get_pp_control(intel_dp);
5492 pp_on = I915_READ(regs.pp_on);
5493 pp_off = I915_READ(regs.pp_off);
5494 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) &&
5495 !HAS_PCH_ICP(dev_priv)) {
5496 I915_WRITE(regs.pp_ctrl, pp_ctl);
5497 pp_div = I915_READ(regs.pp_div);
5500 /* Pull timing values out of registers */
5501 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5502 PANEL_POWER_UP_DELAY_SHIFT;
5504 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5505 PANEL_LIGHT_ON_DELAY_SHIFT;
5507 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5508 PANEL_LIGHT_OFF_DELAY_SHIFT;
5510 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5511 PANEL_POWER_DOWN_DELAY_SHIFT;
5513 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5514 HAS_PCH_ICP(dev_priv)) {
5515 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5516 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
5518 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
5519 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
5524 intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5526 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5528 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5532 intel_pps_verify_state(struct intel_dp *intel_dp)
5534 struct edp_power_seq hw;
5535 struct edp_power_seq *sw = &intel_dp->pps_delays;
5537 intel_pps_readout_hw_state(intel_dp, &hw);
5539 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5540 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5541 DRM_ERROR("PPS state mismatch\n");
5542 intel_pps_dump_state("sw", sw);
5543 intel_pps_dump_state("hw", &hw);
5548 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp)
5550 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5551 struct edp_power_seq cur, vbt, spec,
5552 *final = &intel_dp->pps_delays;
5554 lockdep_assert_held(&dev_priv->pps_mutex);
5556 /* already initialized? */
5557 if (final->t11_t12 != 0)
5560 intel_pps_readout_hw_state(intel_dp, &cur);
5562 intel_pps_dump_state("cur", &cur);
5564 vbt = dev_priv->vbt.edp.pps;
5565 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5566 * of 500ms appears to be too short. Ocassionally the panel
5567 * just fails to power back on. Increasing the delay to 800ms
5568 * seems sufficient to avoid this problem.
5570 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
5571 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
5572 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5575 /* T11_T12 delay is special and actually in units of 100ms, but zero
5576 * based in the hw (so we need to add 100 ms). But the sw vbt
5577 * table multiplies it with 1000 to make it in units of 100usec,
5579 vbt.t11_t12 += 100 * 10;
5581 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5582 * our hw here, which are all in 100usec. */
5583 spec.t1_t3 = 210 * 10;
5584 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5585 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5586 spec.t10 = 500 * 10;
5587 /* This one is special and actually in units of 100ms, but zero
5588 * based in the hw (so we need to add 100 ms). But the sw vbt
5589 * table multiplies it with 1000 to make it in units of 100usec,
5591 spec.t11_t12 = (510 + 100) * 10;
5593 intel_pps_dump_state("vbt", &vbt);
5595 /* Use the max of the register settings and vbt. If both are
5596 * unset, fall back to the spec limits. */
5597 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
5599 max(cur.field, vbt.field))
5600 assign_final(t1_t3);
5604 assign_final(t11_t12);
5607 #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
5608 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5609 intel_dp->backlight_on_delay = get_delay(t8);
5610 intel_dp->backlight_off_delay = get_delay(t9);
5611 intel_dp->panel_power_down_delay = get_delay(t10);
5612 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5615 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5616 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5617 intel_dp->panel_power_cycle_delay);
5619 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5620 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
5623 * We override the HW backlight delays to 1 because we do manual waits
5624 * on them. For T8, even BSpec recommends doing it. For T9, if we
5625 * don't do this, we'll end up waiting for the backlight off delay
5626 * twice: once when we do the manual sleep, and once when we disable
5627 * the panel and wait for the PP_STATUS bit to become zero.
5633 * HW has only a 100msec granularity for t11_t12 so round it up
5636 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
5640 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
5641 bool force_disable_vdd)
5643 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5644 u32 pp_on, pp_off, pp_div, port_sel = 0;
5645 int div = dev_priv->rawclk_freq / 1000;
5646 struct pps_registers regs;
5647 enum port port = dp_to_dig_port(intel_dp)->base.port;
5648 const struct edp_power_seq *seq = &intel_dp->pps_delays;
5650 lockdep_assert_held(&dev_priv->pps_mutex);
5652 intel_pps_get_registers(intel_dp, ®s);
5655 * On some VLV machines the BIOS can leave the VDD
5656 * enabled even on power seqeuencers which aren't
5657 * hooked up to any port. This would mess up the
5658 * power domain tracking the first time we pick
5659 * one of these power sequencers for use since
5660 * edp_panel_vdd_on() would notice that the VDD was
5661 * already on and therefore wouldn't grab the power
5662 * domain reference. Disable VDD first to avoid this.
5663 * This also avoids spuriously turning the VDD on as
5664 * soon as the new power seqeuencer gets initialized.
5666 if (force_disable_vdd) {
5667 u32 pp = ironlake_get_pp_control(intel_dp);
5669 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5671 if (pp & EDP_FORCE_VDD)
5672 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5674 pp &= ~EDP_FORCE_VDD;
5676 I915_WRITE(regs.pp_ctrl, pp);
5679 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
5680 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5681 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
5682 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
5683 /* Compute the divisor for the pp clock, simply match the Bspec
5685 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5686 HAS_PCH_ICP(dev_priv)) {
5687 pp_div = I915_READ(regs.pp_ctrl);
5688 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5689 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5690 << BXT_POWER_CYCLE_DELAY_SHIFT);
5692 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5693 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5694 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5697 /* Haswell doesn't have any port selection bits for the panel
5698 * power sequencer any more. */
5699 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5700 port_sel = PANEL_PORT_SELECT_VLV(port);
5701 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
5703 port_sel = PANEL_PORT_SELECT_DPA;
5705 port_sel = PANEL_PORT_SELECT_DPD;
5710 I915_WRITE(regs.pp_on, pp_on);
5711 I915_WRITE(regs.pp_off, pp_off);
5712 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5713 HAS_PCH_ICP(dev_priv))
5714 I915_WRITE(regs.pp_ctrl, pp_div);
5716 I915_WRITE(regs.pp_div, pp_div);
5718 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
5719 I915_READ(regs.pp_on),
5720 I915_READ(regs.pp_off),
5721 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5722 HAS_PCH_ICP(dev_priv)) ?
5723 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5724 I915_READ(regs.pp_div));
5727 static void intel_dp_pps_init(struct intel_dp *intel_dp)
5729 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5731 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5732 vlv_initial_power_sequencer_setup(intel_dp);
5734 intel_dp_init_panel_power_sequencer(intel_dp);
5735 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
5740 * intel_dp_set_drrs_state - program registers for RR switch to take effect
5741 * @dev_priv: i915 device
5742 * @crtc_state: a pointer to the active intel_crtc_state
5743 * @refresh_rate: RR to be programmed
5745 * This function gets called when refresh rate (RR) has to be changed from
5746 * one frequency to another. Switches can be between high and low RR
5747 * supported by the panel or to any other RR based on media playback (in
5748 * this case, RR value needs to be passed from user space).
5750 * The caller of this function needs to take a lock on dev_priv->drrs.
5752 static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5753 const struct intel_crtc_state *crtc_state,
5756 struct intel_encoder *encoder;
5757 struct intel_digital_port *dig_port = NULL;
5758 struct intel_dp *intel_dp = dev_priv->drrs.dp;
5759 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
5760 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
5762 if (refresh_rate <= 0) {
5763 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5767 if (intel_dp == NULL) {
5768 DRM_DEBUG_KMS("DRRS not supported.\n");
5772 dig_port = dp_to_dig_port(intel_dp);
5773 encoder = &dig_port->base;
5776 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5780 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
5781 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5785 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5787 index = DRRS_LOW_RR;
5789 if (index == dev_priv->drrs.refresh_rate_type) {
5791 "DRRS requested for previously set RR...ignoring\n");
5795 if (!crtc_state->base.active) {
5796 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5800 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
5803 intel_dp_set_m_n(intel_crtc, M1_N1);
5806 intel_dp_set_m_n(intel_crtc, M2_N2);
5810 DRM_ERROR("Unsupported refreshrate type\n");
5812 } else if (INTEL_GEN(dev_priv) > 6) {
5813 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
5816 val = I915_READ(reg);
5817 if (index > DRRS_HIGH_RR) {
5818 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5819 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5821 val |= PIPECONF_EDP_RR_MODE_SWITCH;
5823 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5824 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5826 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
5828 I915_WRITE(reg, val);
5831 dev_priv->drrs.refresh_rate_type = index;
5833 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5837 * intel_edp_drrs_enable - init drrs struct if supported
5838 * @intel_dp: DP struct
5839 * @crtc_state: A pointer to the active crtc state.
5841 * Initializes frontbuffer_bits and drrs.dp
5843 void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5844 const struct intel_crtc_state *crtc_state)
5846 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5848 if (!crtc_state->has_drrs) {
5849 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5853 if (dev_priv->psr.enabled) {
5854 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5858 mutex_lock(&dev_priv->drrs.mutex);
5859 if (WARN_ON(dev_priv->drrs.dp)) {
5860 DRM_ERROR("DRRS already enabled\n");
5864 dev_priv->drrs.busy_frontbuffer_bits = 0;
5866 dev_priv->drrs.dp = intel_dp;
5869 mutex_unlock(&dev_priv->drrs.mutex);
5873 * intel_edp_drrs_disable - Disable DRRS
5874 * @intel_dp: DP struct
5875 * @old_crtc_state: Pointer to old crtc_state.
5878 void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5879 const struct intel_crtc_state *old_crtc_state)
5881 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5883 if (!old_crtc_state->has_drrs)
5886 mutex_lock(&dev_priv->drrs.mutex);
5887 if (!dev_priv->drrs.dp) {
5888 mutex_unlock(&dev_priv->drrs.mutex);
5892 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5893 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5894 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
5896 dev_priv->drrs.dp = NULL;
5897 mutex_unlock(&dev_priv->drrs.mutex);
5899 cancel_delayed_work_sync(&dev_priv->drrs.work);
5902 static void intel_edp_drrs_downclock_work(struct work_struct *work)
5904 struct drm_i915_private *dev_priv =
5905 container_of(work, typeof(*dev_priv), drrs.work.work);
5906 struct intel_dp *intel_dp;
5908 mutex_lock(&dev_priv->drrs.mutex);
5910 intel_dp = dev_priv->drrs.dp;
5916 * The delayed work can race with an invalidate hence we need to
5920 if (dev_priv->drrs.busy_frontbuffer_bits)
5923 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5924 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5926 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5927 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5931 mutex_unlock(&dev_priv->drrs.mutex);
5935 * intel_edp_drrs_invalidate - Disable Idleness DRRS
5936 * @dev_priv: i915 device
5937 * @frontbuffer_bits: frontbuffer plane tracking bits
5939 * This function gets called everytime rendering on the given planes start.
5940 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
5942 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5944 void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5945 unsigned int frontbuffer_bits)
5947 struct drm_crtc *crtc;
5950 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
5953 cancel_delayed_work(&dev_priv->drrs.work);
5955 mutex_lock(&dev_priv->drrs.mutex);
5956 if (!dev_priv->drrs.dp) {
5957 mutex_unlock(&dev_priv->drrs.mutex);
5961 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5962 pipe = to_intel_crtc(crtc)->pipe;
5964 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5965 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5967 /* invalidate means busy screen hence upclock */
5968 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5969 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5970 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
5972 mutex_unlock(&dev_priv->drrs.mutex);
5976 * intel_edp_drrs_flush - Restart Idleness DRRS
5977 * @dev_priv: i915 device
5978 * @frontbuffer_bits: frontbuffer plane tracking bits
5980 * This function gets called every time rendering on the given planes has
5981 * completed or flip on a crtc is completed. So DRRS should be upclocked
5982 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5983 * if no other planes are dirty.
5985 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5987 void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5988 unsigned int frontbuffer_bits)
5990 struct drm_crtc *crtc;
5993 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
5996 cancel_delayed_work(&dev_priv->drrs.work);
5998 mutex_lock(&dev_priv->drrs.mutex);
5999 if (!dev_priv->drrs.dp) {
6000 mutex_unlock(&dev_priv->drrs.mutex);
6004 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
6005 pipe = to_intel_crtc(crtc)->pipe;
6007 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
6008 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
6010 /* flush means busy screen hence upclock */
6011 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
6012 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
6013 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
6016 * flush also means no more activity hence schedule downclock, if all
6017 * other fbs are quiescent too
6019 if (!dev_priv->drrs.busy_frontbuffer_bits)
6020 schedule_delayed_work(&dev_priv->drrs.work,
6021 msecs_to_jiffies(1000));
6022 mutex_unlock(&dev_priv->drrs.mutex);
6026 * DOC: Display Refresh Rate Switching (DRRS)
6028 * Display Refresh Rate Switching (DRRS) is a power conservation feature
6029 * which enables swtching between low and high refresh rates,
6030 * dynamically, based on the usage scenario. This feature is applicable
6031 * for internal panels.
6033 * Indication that the panel supports DRRS is given by the panel EDID, which
6034 * would list multiple refresh rates for one resolution.
6036 * DRRS is of 2 types - static and seamless.
6037 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
6038 * (may appear as a blink on screen) and is used in dock-undock scenario.
6039 * Seamless DRRS involves changing RR without any visual effect to the user
6040 * and can be used during normal system usage. This is done by programming
6041 * certain registers.
6043 * Support for static/seamless DRRS may be indicated in the VBT based on
6044 * inputs from the panel spec.
6046 * DRRS saves power by switching to low RR based on usage scenarios.
6048 * The implementation is based on frontbuffer tracking implementation. When
6049 * there is a disturbance on the screen triggered by user activity or a periodic
6050 * system activity, DRRS is disabled (RR is changed to high RR). When there is
6051 * no movement on screen, after a timeout of 1 second, a switch to low RR is
6054 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
6055 * and intel_edp_drrs_flush() are called.
6057 * DRRS can be further extended to support other internal panels and also
6058 * the scenario of video playback wherein RR is set based on the rate
6059 * requested by userspace.
6063 * intel_dp_drrs_init - Init basic DRRS work and mutex.
6064 * @connector: eDP connector
6065 * @fixed_mode: preferred mode of panel
6067 * This function is called only once at driver load to initialize basic
6071 * Downclock mode if panel supports it, else return NULL.
6072 * DRRS support is determined by the presence of downclock mode (apart
6073 * from VBT setting).
6075 static struct drm_display_mode *
6076 intel_dp_drrs_init(struct intel_connector *connector,
6077 struct drm_display_mode *fixed_mode)
6079 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
6080 struct drm_display_mode *downclock_mode = NULL;
6082 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
6083 mutex_init(&dev_priv->drrs.mutex);
6085 if (INTEL_GEN(dev_priv) <= 6) {
6086 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
6090 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
6091 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
6095 downclock_mode = intel_find_panel_downclock(dev_priv, fixed_mode,
6098 if (!downclock_mode) {
6099 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
6103 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
6105 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
6106 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
6107 return downclock_mode;
6110 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
6111 struct intel_connector *intel_connector)
6113 struct drm_device *dev = intel_dp_to_dev(intel_dp);
6114 struct drm_i915_private *dev_priv = to_i915(dev);
6115 struct drm_connector *connector = &intel_connector->base;
6116 struct drm_display_mode *fixed_mode = NULL;
6117 struct drm_display_mode *alt_fixed_mode = NULL;
6118 struct drm_display_mode *downclock_mode = NULL;
6120 struct drm_display_mode *scan;
6122 enum pipe pipe = INVALID_PIPE;
6124 if (!intel_dp_is_edp(intel_dp))
6128 * On IBX/CPT we may get here with LVDS already registered. Since the
6129 * driver uses the only internal power sequencer available for both
6130 * eDP and LVDS bail out early in this case to prevent interfering
6131 * with an already powered-on LVDS power sequencer.
6133 if (intel_get_lvds_encoder(&dev_priv->drm)) {
6134 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
6135 DRM_INFO("LVDS was detected, not registering eDP\n");
6142 intel_dp_init_panel_power_timestamps(intel_dp);
6143 intel_dp_pps_init(intel_dp);
6144 intel_edp_panel_vdd_sanitize(intel_dp);
6146 pps_unlock(intel_dp);
6148 /* Cache DPCD and EDID for edp. */
6149 has_dpcd = intel_edp_init_dpcd(intel_dp);
6152 /* if this fails, presume the device is a ghost */
6153 DRM_INFO("failed to retrieve link info, disabling eDP\n");
6157 mutex_lock(&dev->mode_config.mutex);
6158 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
6160 if (drm_add_edid_modes(connector, edid)) {
6161 drm_mode_connector_update_edid_property(connector,
6165 edid = ERR_PTR(-EINVAL);
6168 edid = ERR_PTR(-ENOENT);
6170 intel_connector->edid = edid;
6172 /* prefer fixed mode from EDID if available, save an alt mode also */
6173 list_for_each_entry(scan, &connector->probed_modes, head) {
6174 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
6175 fixed_mode = drm_mode_duplicate(dev, scan);
6176 downclock_mode = intel_dp_drrs_init(
6177 intel_connector, fixed_mode);
6178 } else if (!alt_fixed_mode) {
6179 alt_fixed_mode = drm_mode_duplicate(dev, scan);
6183 /* fallback to VBT if available for eDP */
6184 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
6185 fixed_mode = drm_mode_duplicate(dev,
6186 dev_priv->vbt.lfp_lvds_vbt_mode);
6188 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
6189 connector->display_info.width_mm = fixed_mode->width_mm;
6190 connector->display_info.height_mm = fixed_mode->height_mm;
6193 mutex_unlock(&dev->mode_config.mutex);
6195 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
6196 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
6197 register_reboot_notifier(&intel_dp->edp_notifier);
6200 * Figure out the current pipe for the initial backlight setup.
6201 * If the current pipe isn't valid, try the PPS pipe, and if that
6202 * fails just assume pipe A.
6204 pipe = vlv_active_pipe(intel_dp);
6206 if (pipe != PIPE_A && pipe != PIPE_B)
6207 pipe = intel_dp->pps_pipe;
6209 if (pipe != PIPE_A && pipe != PIPE_B)
6212 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
6216 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
6218 intel_connector->panel.backlight.power = intel_edp_backlight_power;
6219 intel_panel_setup_backlight(connector, pipe);
6224 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
6226 * vdd might still be enabled do to the delayed vdd off.
6227 * Make sure vdd is actually turned off here.
6230 edp_panel_vdd_off_sync(intel_dp);
6231 pps_unlock(intel_dp);
6236 static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
6238 struct intel_connector *intel_connector;
6239 struct drm_connector *connector;
6241 intel_connector = container_of(work, typeof(*intel_connector),
6242 modeset_retry_work);
6243 connector = &intel_connector->base;
6244 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
6247 /* Grab the locks before changing connector property*/
6248 mutex_lock(&connector->dev->mode_config.mutex);
6249 /* Set connector link status to BAD and send a Uevent to notify
6250 * userspace to do a modeset.
6252 drm_mode_connector_set_link_status_property(connector,
6253 DRM_MODE_LINK_STATUS_BAD);
6254 mutex_unlock(&connector->dev->mode_config.mutex);
6255 /* Send Hotplug uevent so userspace can reprobe */
6256 drm_kms_helper_hotplug_event(connector->dev);
6260 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6261 struct intel_connector *intel_connector)
6263 struct drm_connector *connector = &intel_connector->base;
6264 struct intel_dp *intel_dp = &intel_dig_port->dp;
6265 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6266 struct drm_device *dev = intel_encoder->base.dev;
6267 struct drm_i915_private *dev_priv = to_i915(dev);
6268 enum port port = intel_encoder->port;
6271 /* Initialize the work for modeset in case of link train failure */
6272 INIT_WORK(&intel_connector->modeset_retry_work,
6273 intel_dp_modeset_retry_work_fn);
6275 if (WARN(intel_dig_port->max_lanes < 1,
6276 "Not enough lanes (%d) for DP on port %c\n",
6277 intel_dig_port->max_lanes, port_name(port)))
6280 intel_dp_set_source_rates(intel_dp);
6282 intel_dp->reset_link_params = true;
6283 intel_dp->pps_pipe = INVALID_PIPE;
6284 intel_dp->active_pipe = INVALID_PIPE;
6286 /* intel_dp vfuncs */
6287 if (HAS_DDI(dev_priv))
6288 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6290 /* Preserve the current hw state. */
6291 intel_dp->DP = I915_READ(intel_dp->output_reg);
6292 intel_dp->attached_connector = intel_connector;
6294 if (intel_dp_is_port_edp(dev_priv, port))
6295 type = DRM_MODE_CONNECTOR_eDP;
6297 type = DRM_MODE_CONNECTOR_DisplayPort;
6299 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6300 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6303 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6304 * for DP the encoder type can be set by the caller to
6305 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6307 if (type == DRM_MODE_CONNECTOR_eDP)
6308 intel_encoder->type = INTEL_OUTPUT_EDP;
6310 /* eDP only on port B and/or C on vlv/chv */
6311 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
6312 intel_dp_is_edp(intel_dp) &&
6313 port != PORT_B && port != PORT_C))
6316 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6317 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6320 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
6321 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6323 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
6324 connector->interlace_allowed = true;
6325 connector->doublescan_allowed = 0;
6327 intel_encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port);
6329 intel_dp_aux_init(intel_dp);
6331 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
6332 edp_panel_vdd_work);
6334 intel_connector_attach_encoder(intel_connector, intel_encoder);
6336 if (HAS_DDI(dev_priv))
6337 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6339 intel_connector->get_hw_state = intel_connector_get_hw_state;
6341 /* init MST on ports that can support it */
6342 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
6343 (port == PORT_B || port == PORT_C ||
6344 port == PORT_D || port == PORT_F))
6345 intel_dp_mst_encoder_init(intel_dig_port,
6346 intel_connector->base.base.id);
6348 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
6349 intel_dp_aux_fini(intel_dp);
6350 intel_dp_mst_encoder_cleanup(intel_dig_port);
6354 intel_dp_add_properties(intel_dp, connector);
6356 if (is_hdcp_supported(dev_priv, port) && !intel_dp_is_edp(intel_dp)) {
6357 int ret = intel_hdcp_init(intel_connector, &intel_dp_hdcp_shim);
6359 DRM_DEBUG_KMS("HDCP init failed, skipping.\n");
6362 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6363 * 0xd. Failure to do so will result in spurious interrupts being
6364 * generated on the port when a cable is not attached.
6366 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
6367 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6368 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6374 drm_connector_cleanup(connector);
6379 bool intel_dp_init(struct drm_i915_private *dev_priv,
6380 i915_reg_t output_reg,
6383 struct intel_digital_port *intel_dig_port;
6384 struct intel_encoder *intel_encoder;
6385 struct drm_encoder *encoder;
6386 struct intel_connector *intel_connector;
6388 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
6389 if (!intel_dig_port)
6392 intel_connector = intel_connector_alloc();
6393 if (!intel_connector)
6394 goto err_connector_alloc;
6396 intel_encoder = &intel_dig_port->base;
6397 encoder = &intel_encoder->base;
6399 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6400 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6401 "DP %c", port_name(port)))
6402 goto err_encoder_init;
6404 intel_encoder->compute_config = intel_dp_compute_config;
6405 intel_encoder->get_hw_state = intel_dp_get_hw_state;
6406 intel_encoder->get_config = intel_dp_get_config;
6407 intel_encoder->suspend = intel_dp_encoder_suspend;
6408 if (IS_CHERRYVIEW(dev_priv)) {
6409 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
6410 intel_encoder->pre_enable = chv_pre_enable_dp;
6411 intel_encoder->enable = vlv_enable_dp;
6412 intel_encoder->disable = vlv_disable_dp;
6413 intel_encoder->post_disable = chv_post_disable_dp;
6414 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
6415 } else if (IS_VALLEYVIEW(dev_priv)) {
6416 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
6417 intel_encoder->pre_enable = vlv_pre_enable_dp;
6418 intel_encoder->enable = vlv_enable_dp;
6419 intel_encoder->disable = vlv_disable_dp;
6420 intel_encoder->post_disable = vlv_post_disable_dp;
6421 } else if (INTEL_GEN(dev_priv) >= 5) {
6422 intel_encoder->pre_enable = g4x_pre_enable_dp;
6423 intel_encoder->enable = g4x_enable_dp;
6424 intel_encoder->disable = ilk_disable_dp;
6425 intel_encoder->post_disable = ilk_post_disable_dp;
6427 intel_encoder->pre_enable = g4x_pre_enable_dp;
6428 intel_encoder->enable = g4x_enable_dp;
6429 intel_encoder->disable = g4x_disable_dp;
6432 intel_dig_port->dp.output_reg = output_reg;
6433 intel_dig_port->max_lanes = 4;
6435 intel_encoder->type = INTEL_OUTPUT_DP;
6436 intel_encoder->power_domain = intel_port_to_power_domain(port);
6437 if (IS_CHERRYVIEW(dev_priv)) {
6439 intel_encoder->crtc_mask = 1 << 2;
6441 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6443 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6445 intel_encoder->cloneable = 0;
6446 intel_encoder->port = port;
6448 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
6449 dev_priv->hotplug.irq_port[port] = intel_dig_port;
6452 intel_infoframe_init(intel_dig_port);
6454 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6455 goto err_init_connector;
6460 drm_encoder_cleanup(encoder);
6462 kfree(intel_connector);
6463 err_connector_alloc:
6464 kfree(intel_dig_port);
6468 void intel_dp_mst_suspend(struct drm_device *dev)
6470 struct drm_i915_private *dev_priv = to_i915(dev);
6474 for (i = 0; i < I915_MAX_PORTS; i++) {
6475 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
6477 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
6480 if (intel_dig_port->dp.is_mst)
6481 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
6485 void intel_dp_mst_resume(struct drm_device *dev)
6487 struct drm_i915_private *dev_priv = to_i915(dev);
6490 for (i = 0; i < I915_MAX_PORTS; i++) {
6491 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
6494 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
6497 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6499 intel_dp_check_mst_status(&intel_dig_port->dp);