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/export.h>
29 #include <linux/i2c.h>
30 #include <linux/notifier.h>
31 #include <linux/reboot.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
35 #include <asm/byteorder.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_dp_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_hdcp.h>
42 #include <drm/drm_probe_helper.h>
43 #include <drm/i915_drm.h>
45 #include "i915_debugfs.h"
47 #include "intel_atomic.h"
48 #include "intel_audio.h"
49 #include "intel_connector.h"
50 #include "intel_ddi.h"
52 #include "intel_dp_link_training.h"
53 #include "intel_dp_mst.h"
54 #include "intel_dpio_phy.h"
55 #include "intel_drv.h"
56 #include "intel_fifo_underrun.h"
57 #include "intel_hdcp.h"
58 #include "intel_hdmi.h"
59 #include "intel_hotplug.h"
60 #include "intel_lspcon.h"
61 #include "intel_lvds.h"
62 #include "intel_panel.h"
63 #include "intel_psr.h"
64 #include "intel_sideband.h"
65 #include "intel_vdsc.h"
67 #define DP_DPRX_ESI_LEN 14
69 /* DP DSC small joiner has 2 FIFOs each of 640 x 6 bytes */
70 #define DP_DSC_MAX_SMALL_JOINER_RAM_BUFFER 61440
71 #define DP_DSC_MIN_SUPPORTED_BPC 8
72 #define DP_DSC_MAX_SUPPORTED_BPC 10
74 /* DP DSC throughput values used for slice count calculations KPixels/s */
75 #define DP_DSC_PEAK_PIXEL_RATE 2720000
76 #define DP_DSC_MAX_ENC_THROUGHPUT_0 340000
77 #define DP_DSC_MAX_ENC_THROUGHPUT_1 400000
79 /* DP DSC FEC Overhead factor = (100 - 2.4)/100 */
80 #define DP_DSC_FEC_OVERHEAD_FACTOR 976
82 /* Compliance test status bits */
83 #define INTEL_DP_RESOLUTION_SHIFT_MASK 0
84 #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
85 #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
86 #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
93 static const struct dp_link_dpll g4x_dpll[] = {
95 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
97 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
100 static const struct dp_link_dpll pch_dpll[] = {
102 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
104 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
107 static const struct dp_link_dpll vlv_dpll[] = {
109 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
111 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
115 * CHV supports eDP 1.4 that have more link rates.
116 * Below only provides the fixed rate but exclude variable rate.
118 static const struct dp_link_dpll chv_dpll[] = {
120 * CHV requires to program fractional division for m2.
121 * m2 is stored in fixed point format using formula below
122 * (m2_int << 22) | m2_fraction
124 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
125 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
126 { 270000, /* m2_int = 27, m2_fraction = 0 */
127 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
130 /* Constants for DP DSC configurations */
131 static const u8 valid_dsc_bpp[] = {6, 8, 10, 12, 15};
133 /* With Single pipe configuration, HW is capable of supporting maximum
134 * of 4 slices per line.
136 static const u8 valid_dsc_slicecount[] = {1, 2, 4};
139 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
140 * @intel_dp: DP struct
142 * If a CPU or PCH DP output is attached to an eDP panel, this function
143 * will return true, and false otherwise.
145 bool intel_dp_is_edp(struct intel_dp *intel_dp)
147 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
149 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
152 static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
154 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
157 static void intel_dp_link_down(struct intel_encoder *encoder,
158 const struct intel_crtc_state *old_crtc_state);
159 static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
160 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
161 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
162 const struct intel_crtc_state *crtc_state);
163 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
165 static void intel_dp_unset_edid(struct intel_dp *intel_dp);
167 /* update sink rates from dpcd */
168 static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
170 static const int dp_rates[] = {
171 162000, 270000, 540000, 810000
175 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]);
177 for (i = 0; i < ARRAY_SIZE(dp_rates); i++) {
178 if (dp_rates[i] > max_rate)
180 intel_dp->sink_rates[i] = dp_rates[i];
183 intel_dp->num_sink_rates = i;
186 /* Get length of rates array potentially limited by max_rate. */
187 static int intel_dp_rate_limit_len(const int *rates, int len, int max_rate)
191 /* Limit results by potentially reduced max rate */
192 for (i = 0; i < len; i++) {
193 if (rates[len - i - 1] <= max_rate)
200 /* Get length of common rates array potentially limited by max_rate. */
201 static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp,
204 return intel_dp_rate_limit_len(intel_dp->common_rates,
205 intel_dp->num_common_rates, max_rate);
208 /* Theoretical max between source and sink */
209 static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
211 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
214 static int intel_dp_get_fia_supported_lane_count(struct intel_dp *intel_dp)
216 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
217 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
218 enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port);
219 intel_wakeref_t wakeref;
222 if (tc_port == PORT_TC_NONE || dig_port->tc_type != TC_PORT_TYPEC)
226 with_intel_display_power(dev_priv, POWER_DOMAIN_DISPLAY_CORE, wakeref)
227 lane_info = (I915_READ(PORT_TX_DFLEXDPSP) &
228 DP_LANE_ASSIGNMENT_MASK(tc_port)) >>
229 DP_LANE_ASSIGNMENT_SHIFT(tc_port);
233 MISSING_CASE(lane_info);
247 /* Theoretical max between source and sink */
248 static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
250 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
251 int source_max = intel_dig_port->max_lanes;
252 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
253 int fia_max = intel_dp_get_fia_supported_lane_count(intel_dp);
255 return min3(source_max, sink_max, fia_max);
258 int intel_dp_max_lane_count(struct intel_dp *intel_dp)
260 return intel_dp->max_link_lane_count;
264 intel_dp_link_required(int pixel_clock, int bpp)
266 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
267 return DIV_ROUND_UP(pixel_clock * bpp, 8);
271 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
273 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
274 * link rate that is generally expressed in Gbps. Since, 8 bits of data
275 * is transmitted every LS_Clk per lane, there is no need to account for
276 * the channel encoding that is done in the PHY layer here.
279 return max_link_clock * max_lanes;
283 intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
285 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
286 struct intel_encoder *encoder = &intel_dig_port->base;
287 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
288 int max_dotclk = dev_priv->max_dotclk_freq;
291 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
293 if (type != DP_DS_PORT_TYPE_VGA)
296 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
297 intel_dp->downstream_ports);
299 if (ds_max_dotclk != 0)
300 max_dotclk = min(max_dotclk, ds_max_dotclk);
305 static int cnl_max_source_rate(struct intel_dp *intel_dp)
307 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
308 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
309 enum port port = dig_port->base.port;
311 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
313 /* Low voltage SKUs are limited to max of 5.4G */
314 if (voltage == VOLTAGE_INFO_0_85V)
317 /* For this SKU 8.1G is supported in all ports */
318 if (IS_CNL_WITH_PORT_F(dev_priv))
321 /* For other SKUs, max rate on ports A and D is 5.4G */
322 if (port == PORT_A || port == PORT_D)
328 static int icl_max_source_rate(struct intel_dp *intel_dp)
330 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
331 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
332 enum port port = dig_port->base.port;
334 if (intel_port_is_combophy(dev_priv, port) &&
335 !intel_dp_is_edp(intel_dp))
342 intel_dp_set_source_rates(struct intel_dp *intel_dp)
344 /* The values must be in increasing order */
345 static const int cnl_rates[] = {
346 162000, 216000, 270000, 324000, 432000, 540000, 648000, 810000
348 static const int bxt_rates[] = {
349 162000, 216000, 243000, 270000, 324000, 432000, 540000
351 static const int skl_rates[] = {
352 162000, 216000, 270000, 324000, 432000, 540000
354 static const int hsw_rates[] = {
355 162000, 270000, 540000
357 static const int g4x_rates[] = {
360 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
361 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
362 const struct ddi_vbt_port_info *info =
363 &dev_priv->vbt.ddi_port_info[dig_port->base.port];
364 const int *source_rates;
365 int size, max_rate = 0, vbt_max_rate = info->dp_max_link_rate;
367 /* This should only be done once */
368 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
370 if (INTEL_GEN(dev_priv) >= 10) {
371 source_rates = cnl_rates;
372 size = ARRAY_SIZE(cnl_rates);
373 if (IS_GEN(dev_priv, 10))
374 max_rate = cnl_max_source_rate(intel_dp);
376 max_rate = icl_max_source_rate(intel_dp);
377 } else if (IS_GEN9_LP(dev_priv)) {
378 source_rates = bxt_rates;
379 size = ARRAY_SIZE(bxt_rates);
380 } else if (IS_GEN9_BC(dev_priv)) {
381 source_rates = skl_rates;
382 size = ARRAY_SIZE(skl_rates);
383 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
384 IS_BROADWELL(dev_priv)) {
385 source_rates = hsw_rates;
386 size = ARRAY_SIZE(hsw_rates);
388 source_rates = g4x_rates;
389 size = ARRAY_SIZE(g4x_rates);
392 if (max_rate && vbt_max_rate)
393 max_rate = min(max_rate, vbt_max_rate);
394 else if (vbt_max_rate)
395 max_rate = vbt_max_rate;
398 size = intel_dp_rate_limit_len(source_rates, size, max_rate);
400 intel_dp->source_rates = source_rates;
401 intel_dp->num_source_rates = size;
404 static int intersect_rates(const int *source_rates, int source_len,
405 const int *sink_rates, int sink_len,
408 int i = 0, j = 0, k = 0;
410 while (i < source_len && j < sink_len) {
411 if (source_rates[i] == sink_rates[j]) {
412 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
414 common_rates[k] = source_rates[i];
418 } else if (source_rates[i] < sink_rates[j]) {
427 /* return index of rate in rates array, or -1 if not found */
428 static int intel_dp_rate_index(const int *rates, int len, int rate)
432 for (i = 0; i < len; i++)
433 if (rate == rates[i])
439 static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
441 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
443 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
444 intel_dp->num_source_rates,
445 intel_dp->sink_rates,
446 intel_dp->num_sink_rates,
447 intel_dp->common_rates);
449 /* Paranoia, there should always be something in common. */
450 if (WARN_ON(intel_dp->num_common_rates == 0)) {
451 intel_dp->common_rates[0] = 162000;
452 intel_dp->num_common_rates = 1;
456 static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
460 * FIXME: we need to synchronize the current link parameters with
461 * hardware readout. Currently fast link training doesn't work on
464 if (link_rate == 0 ||
465 link_rate > intel_dp->max_link_rate)
468 if (lane_count == 0 ||
469 lane_count > intel_dp_max_lane_count(intel_dp))
475 static bool intel_dp_can_link_train_fallback_for_edp(struct intel_dp *intel_dp,
479 const struct drm_display_mode *fixed_mode =
480 intel_dp->attached_connector->panel.fixed_mode;
481 int mode_rate, max_rate;
483 mode_rate = intel_dp_link_required(fixed_mode->clock, 18);
484 max_rate = intel_dp_max_data_rate(link_rate, lane_count);
485 if (mode_rate > max_rate)
491 int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
492 int link_rate, u8 lane_count)
496 index = intel_dp_rate_index(intel_dp->common_rates,
497 intel_dp->num_common_rates,
500 if (intel_dp_is_edp(intel_dp) &&
501 !intel_dp_can_link_train_fallback_for_edp(intel_dp,
502 intel_dp->common_rates[index - 1],
504 DRM_DEBUG_KMS("Retrying Link training for eDP with same parameters\n");
507 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
508 intel_dp->max_link_lane_count = lane_count;
509 } else if (lane_count > 1) {
510 if (intel_dp_is_edp(intel_dp) &&
511 !intel_dp_can_link_train_fallback_for_edp(intel_dp,
512 intel_dp_max_common_rate(intel_dp),
514 DRM_DEBUG_KMS("Retrying Link training for eDP with same parameters\n");
517 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
518 intel_dp->max_link_lane_count = lane_count >> 1;
520 DRM_ERROR("Link Training Unsuccessful\n");
527 static enum drm_mode_status
528 intel_dp_mode_valid(struct drm_connector *connector,
529 struct drm_display_mode *mode)
531 struct intel_dp *intel_dp = intel_attached_dp(connector);
532 struct intel_connector *intel_connector = to_intel_connector(connector);
533 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
534 struct drm_i915_private *dev_priv = to_i915(connector->dev);
535 int target_clock = mode->clock;
536 int max_rate, mode_rate, max_lanes, max_link_clock;
538 u16 dsc_max_output_bpp = 0;
539 u8 dsc_slice_count = 0;
541 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
542 return MODE_NO_DBLESCAN;
544 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
546 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
547 if (mode->hdisplay > fixed_mode->hdisplay)
550 if (mode->vdisplay > fixed_mode->vdisplay)
553 target_clock = fixed_mode->clock;
556 max_link_clock = intel_dp_max_link_rate(intel_dp);
557 max_lanes = intel_dp_max_lane_count(intel_dp);
559 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
560 mode_rate = intel_dp_link_required(target_clock, 18);
563 * Output bpp is stored in 6.4 format so right shift by 4 to get the
564 * integer value since we support only integer values of bpp.
566 if ((INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) &&
567 drm_dp_sink_supports_dsc(intel_dp->dsc_dpcd)) {
568 if (intel_dp_is_edp(intel_dp)) {
570 drm_edp_dsc_sink_output_bpp(intel_dp->dsc_dpcd) >> 4;
572 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
574 } else if (drm_dp_sink_supports_fec(intel_dp->fec_capable)) {
576 intel_dp_dsc_get_output_bpp(max_link_clock,
579 mode->hdisplay) >> 4;
581 intel_dp_dsc_get_slice_count(intel_dp,
587 if ((mode_rate > max_rate && !(dsc_max_output_bpp && dsc_slice_count)) ||
588 target_clock > max_dotclk)
589 return MODE_CLOCK_HIGH;
591 if (mode->clock < 10000)
592 return MODE_CLOCK_LOW;
594 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
595 return MODE_H_ILLEGAL;
600 u32 intel_dp_pack_aux(const u8 *src, int src_bytes)
607 for (i = 0; i < src_bytes; i++)
608 v |= ((u32)src[i]) << ((3 - i) * 8);
612 static void intel_dp_unpack_aux(u32 src, u8 *dst, int dst_bytes)
617 for (i = 0; i < dst_bytes; i++)
618 dst[i] = src >> ((3-i) * 8);
622 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp);
624 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
625 bool force_disable_vdd);
627 intel_dp_pps_init(struct intel_dp *intel_dp);
629 static intel_wakeref_t
630 pps_lock(struct intel_dp *intel_dp)
632 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
633 intel_wakeref_t wakeref;
636 * See intel_power_sequencer_reset() why we need
637 * a power domain reference here.
639 wakeref = intel_display_power_get(dev_priv,
640 intel_aux_power_domain(dp_to_dig_port(intel_dp)));
642 mutex_lock(&dev_priv->pps_mutex);
647 static intel_wakeref_t
648 pps_unlock(struct intel_dp *intel_dp, intel_wakeref_t wakeref)
650 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
652 mutex_unlock(&dev_priv->pps_mutex);
653 intel_display_power_put(dev_priv,
654 intel_aux_power_domain(dp_to_dig_port(intel_dp)),
659 #define with_pps_lock(dp, wf) \
660 for ((wf) = pps_lock(dp); (wf); (wf) = pps_unlock((dp), (wf)))
663 vlv_power_sequencer_kick(struct intel_dp *intel_dp)
665 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
666 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
667 enum pipe pipe = intel_dp->pps_pipe;
668 bool pll_enabled, release_cl_override = false;
669 enum dpio_phy phy = DPIO_PHY(pipe);
670 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
673 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
674 "skipping pipe %c power sequencer kick due to port %c being active\n",
675 pipe_name(pipe), port_name(intel_dig_port->base.port)))
678 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
679 pipe_name(pipe), port_name(intel_dig_port->base.port));
681 /* Preserve the BIOS-computed detected bit. This is
682 * supposed to be read-only.
684 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
685 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
686 DP |= DP_PORT_WIDTH(1);
687 DP |= DP_LINK_TRAIN_PAT_1;
689 if (IS_CHERRYVIEW(dev_priv))
690 DP |= DP_PIPE_SEL_CHV(pipe);
692 DP |= DP_PIPE_SEL(pipe);
694 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
697 * The DPLL for the pipe must be enabled for this to work.
698 * So enable temporarily it if it's not already enabled.
701 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
702 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
704 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
705 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
706 DRM_ERROR("Failed to force on pll for pipe %c!\n",
713 * Similar magic as in intel_dp_enable_port().
714 * We _must_ do this port enable + disable trick
715 * to make this power sequencer lock onto the port.
716 * Otherwise even VDD force bit won't work.
718 I915_WRITE(intel_dp->output_reg, DP);
719 POSTING_READ(intel_dp->output_reg);
721 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
722 POSTING_READ(intel_dp->output_reg);
724 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
725 POSTING_READ(intel_dp->output_reg);
728 vlv_force_pll_off(dev_priv, pipe);
730 if (release_cl_override)
731 chv_phy_powergate_ch(dev_priv, phy, ch, false);
735 static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
737 struct intel_encoder *encoder;
738 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
741 * We don't have power sequencer currently.
742 * Pick one that's not used by other ports.
744 for_each_intel_dp(&dev_priv->drm, encoder) {
745 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
747 if (encoder->type == INTEL_OUTPUT_EDP) {
748 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
749 intel_dp->active_pipe != intel_dp->pps_pipe);
751 if (intel_dp->pps_pipe != INVALID_PIPE)
752 pipes &= ~(1 << intel_dp->pps_pipe);
754 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
756 if (intel_dp->active_pipe != INVALID_PIPE)
757 pipes &= ~(1 << intel_dp->active_pipe);
764 return ffs(pipes) - 1;
768 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
770 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
771 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
774 lockdep_assert_held(&dev_priv->pps_mutex);
776 /* We should never land here with regular DP ports */
777 WARN_ON(!intel_dp_is_edp(intel_dp));
779 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
780 intel_dp->active_pipe != intel_dp->pps_pipe);
782 if (intel_dp->pps_pipe != INVALID_PIPE)
783 return intel_dp->pps_pipe;
785 pipe = vlv_find_free_pps(dev_priv);
788 * Didn't find one. This should not happen since there
789 * are two power sequencers and up to two eDP ports.
791 if (WARN_ON(pipe == INVALID_PIPE))
794 vlv_steal_power_sequencer(dev_priv, pipe);
795 intel_dp->pps_pipe = pipe;
797 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
798 pipe_name(intel_dp->pps_pipe),
799 port_name(intel_dig_port->base.port));
801 /* init power sequencer on this pipe and port */
802 intel_dp_init_panel_power_sequencer(intel_dp);
803 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
806 * Even vdd force doesn't work until we've made
807 * the power sequencer lock in on the port.
809 vlv_power_sequencer_kick(intel_dp);
811 return intel_dp->pps_pipe;
815 bxt_power_sequencer_idx(struct intel_dp *intel_dp)
817 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
818 int backlight_controller = dev_priv->vbt.backlight.controller;
820 lockdep_assert_held(&dev_priv->pps_mutex);
822 /* We should never land here with regular DP ports */
823 WARN_ON(!intel_dp_is_edp(intel_dp));
825 if (!intel_dp->pps_reset)
826 return backlight_controller;
828 intel_dp->pps_reset = false;
831 * Only the HW needs to be reprogrammed, the SW state is fixed and
832 * has been setup during connector init.
834 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
836 return backlight_controller;
839 typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
842 static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
845 return I915_READ(PP_STATUS(pipe)) & PP_ON;
848 static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
851 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
854 static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
861 vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
863 vlv_pipe_check pipe_check)
867 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
868 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
869 PANEL_PORT_SELECT_MASK;
871 if (port_sel != PANEL_PORT_SELECT_VLV(port))
874 if (!pipe_check(dev_priv, pipe))
884 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
886 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
887 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
888 enum port port = intel_dig_port->base.port;
890 lockdep_assert_held(&dev_priv->pps_mutex);
892 /* try to find a pipe with this port selected */
893 /* first pick one where the panel is on */
894 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
896 /* didn't find one? pick one where vdd is on */
897 if (intel_dp->pps_pipe == INVALID_PIPE)
898 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
899 vlv_pipe_has_vdd_on);
900 /* didn't find one? pick one with just the correct port */
901 if (intel_dp->pps_pipe == INVALID_PIPE)
902 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
905 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
906 if (intel_dp->pps_pipe == INVALID_PIPE) {
907 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
912 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
913 port_name(port), pipe_name(intel_dp->pps_pipe));
915 intel_dp_init_panel_power_sequencer(intel_dp);
916 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
919 void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
921 struct intel_encoder *encoder;
923 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
924 !IS_GEN9_LP(dev_priv)))
928 * We can't grab pps_mutex here due to deadlock with power_domain
929 * mutex when power_domain functions are called while holding pps_mutex.
930 * That also means that in order to use pps_pipe the code needs to
931 * hold both a power domain reference and pps_mutex, and the power domain
932 * reference get/put must be done while _not_ holding pps_mutex.
933 * pps_{lock,unlock}() do these steps in the correct order, so one
934 * should use them always.
937 for_each_intel_dp(&dev_priv->drm, encoder) {
938 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
940 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
942 if (encoder->type != INTEL_OUTPUT_EDP)
945 if (IS_GEN9_LP(dev_priv))
946 intel_dp->pps_reset = true;
948 intel_dp->pps_pipe = INVALID_PIPE;
952 struct pps_registers {
960 static void intel_pps_get_registers(struct intel_dp *intel_dp,
961 struct pps_registers *regs)
963 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
966 memset(regs, 0, sizeof(*regs));
968 if (IS_GEN9_LP(dev_priv))
969 pps_idx = bxt_power_sequencer_idx(intel_dp);
970 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
971 pps_idx = vlv_power_sequencer_pipe(intel_dp);
973 regs->pp_ctrl = PP_CONTROL(pps_idx);
974 regs->pp_stat = PP_STATUS(pps_idx);
975 regs->pp_on = PP_ON_DELAYS(pps_idx);
976 regs->pp_off = PP_OFF_DELAYS(pps_idx);
978 /* Cycle delay moved from PP_DIVISOR to PP_CONTROL */
979 if (IS_GEN9_LP(dev_priv) || INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
980 regs->pp_div = INVALID_MMIO_REG;
982 regs->pp_div = PP_DIVISOR(pps_idx);
986 _pp_ctrl_reg(struct intel_dp *intel_dp)
988 struct pps_registers regs;
990 intel_pps_get_registers(intel_dp, ®s);
996 _pp_stat_reg(struct intel_dp *intel_dp)
998 struct pps_registers regs;
1000 intel_pps_get_registers(intel_dp, ®s);
1002 return regs.pp_stat;
1005 /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
1006 This function only applicable when panel PM state is not to be tracked */
1007 static int edp_notify_handler(struct notifier_block *this, unsigned long code,
1010 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
1012 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1013 intel_wakeref_t wakeref;
1015 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
1018 with_pps_lock(intel_dp, wakeref) {
1019 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1020 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
1021 i915_reg_t pp_ctrl_reg, pp_div_reg;
1024 pp_ctrl_reg = PP_CONTROL(pipe);
1025 pp_div_reg = PP_DIVISOR(pipe);
1026 pp_div = I915_READ(pp_div_reg);
1027 pp_div &= PP_REFERENCE_DIVIDER_MASK;
1029 /* 0x1F write to PP_DIV_REG sets max cycle delay */
1030 I915_WRITE(pp_div_reg, pp_div | 0x1F);
1031 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS);
1032 msleep(intel_dp->panel_power_cycle_delay);
1039 static bool edp_have_panel_power(struct intel_dp *intel_dp)
1041 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1043 lockdep_assert_held(&dev_priv->pps_mutex);
1045 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1046 intel_dp->pps_pipe == INVALID_PIPE)
1049 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
1052 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
1054 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1056 lockdep_assert_held(&dev_priv->pps_mutex);
1058 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1059 intel_dp->pps_pipe == INVALID_PIPE)
1062 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
1066 intel_dp_check_edp(struct intel_dp *intel_dp)
1068 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1070 if (!intel_dp_is_edp(intel_dp))
1073 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
1074 WARN(1, "eDP powered off while attempting aux channel communication.\n");
1075 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
1076 I915_READ(_pp_stat_reg(intel_dp)),
1077 I915_READ(_pp_ctrl_reg(intel_dp)));
1082 intel_dp_aux_wait_done(struct intel_dp *intel_dp)
1084 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1085 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
1089 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1090 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
1091 msecs_to_jiffies_timeout(10));
1093 /* just trace the final value */
1094 trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
1097 DRM_ERROR("dp aux hw did not signal timeout!\n");
1103 static u32 g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1105 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1111 * The clock divider is based off the hrawclk, and would like to run at
1112 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
1114 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
1117 static u32 ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1119 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1120 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1126 * The clock divider is based off the cdclk or PCH rawclk, and would
1127 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
1128 * divide by 2000 and use that
1130 if (dig_port->aux_ch == AUX_CH_A)
1131 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
1133 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
1136 static u32 hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1138 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1139 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1141 if (dig_port->aux_ch != AUX_CH_A && HAS_PCH_LPT_H(dev_priv)) {
1142 /* Workaround for non-ULT HSW */
1150 return ilk_get_aux_clock_divider(intel_dp, index);
1153 static u32 skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1156 * SKL doesn't need us to program the AUX clock divider (Hardware will
1157 * derive the clock from CDCLK automatically). We still implement the
1158 * get_aux_clock_divider vfunc to plug-in into the existing code.
1160 return index ? 0 : 1;
1163 static u32 g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1165 u32 aux_clock_divider)
1167 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1168 struct drm_i915_private *dev_priv =
1169 to_i915(intel_dig_port->base.base.dev);
1170 u32 precharge, timeout;
1172 if (IS_GEN(dev_priv, 6))
1177 if (IS_BROADWELL(dev_priv))
1178 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1180 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1182 return DP_AUX_CH_CTL_SEND_BUSY |
1183 DP_AUX_CH_CTL_DONE |
1184 DP_AUX_CH_CTL_INTERRUPT |
1185 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1187 DP_AUX_CH_CTL_RECEIVE_ERROR |
1188 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1189 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1190 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
1193 static u32 skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1197 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1200 ret = DP_AUX_CH_CTL_SEND_BUSY |
1201 DP_AUX_CH_CTL_DONE |
1202 DP_AUX_CH_CTL_INTERRUPT |
1203 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1204 DP_AUX_CH_CTL_TIME_OUT_MAX |
1205 DP_AUX_CH_CTL_RECEIVE_ERROR |
1206 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1207 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
1208 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1210 if (intel_dig_port->tc_type == TC_PORT_TBT)
1211 ret |= DP_AUX_CH_CTL_TBT_IO;
1217 intel_dp_aux_xfer(struct intel_dp *intel_dp,
1218 const u8 *send, int send_bytes,
1219 u8 *recv, int recv_size,
1220 u32 aux_send_ctl_flags)
1222 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1223 struct drm_i915_private *dev_priv =
1224 to_i915(intel_dig_port->base.base.dev);
1225 i915_reg_t ch_ctl, ch_data[5];
1226 u32 aux_clock_divider;
1227 enum intel_display_power_domain aux_domain =
1228 intel_aux_power_domain(intel_dig_port);
1229 intel_wakeref_t aux_wakeref;
1230 intel_wakeref_t pps_wakeref;
1231 int i, ret, recv_bytes;
1236 ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
1237 for (i = 0; i < ARRAY_SIZE(ch_data); i++)
1238 ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i);
1240 aux_wakeref = intel_display_power_get(dev_priv, aux_domain);
1241 pps_wakeref = pps_lock(intel_dp);
1244 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1245 * In such cases we want to leave VDD enabled and it's up to upper layers
1246 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1249 vdd = edp_panel_vdd_on(intel_dp);
1251 /* dp aux is extremely sensitive to irq latency, hence request the
1252 * lowest possible wakeup latency and so prevent the cpu from going into
1253 * deep sleep states.
1255 pm_qos_update_request(&dev_priv->pm_qos, 0);
1257 intel_dp_check_edp(intel_dp);
1259 /* Try to wait for any previous AUX channel activity */
1260 for (try = 0; try < 3; try++) {
1261 status = I915_READ_NOTRACE(ch_ctl);
1262 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1266 /* just trace the final value */
1267 trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
1270 static u32 last_status = -1;
1271 const u32 status = I915_READ(ch_ctl);
1273 if (status != last_status) {
1274 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1276 last_status = status;
1283 /* Only 5 data registers! */
1284 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1289 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
1290 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1294 send_ctl |= aux_send_ctl_flags;
1296 /* Must try at least 3 times according to DP spec */
1297 for (try = 0; try < 5; try++) {
1298 /* Load the send data into the aux channel data registers */
1299 for (i = 0; i < send_bytes; i += 4)
1300 I915_WRITE(ch_data[i >> 2],
1301 intel_dp_pack_aux(send + i,
1304 /* Send the command and wait for it to complete */
1305 I915_WRITE(ch_ctl, send_ctl);
1307 status = intel_dp_aux_wait_done(intel_dp);
1309 /* Clear done status and any errors */
1312 DP_AUX_CH_CTL_DONE |
1313 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1314 DP_AUX_CH_CTL_RECEIVE_ERROR);
1316 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1317 * 400us delay required for errors and timeouts
1318 * Timeout errors from the HW already meet this
1319 * requirement so skip to next iteration
1321 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
1324 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1325 usleep_range(400, 500);
1328 if (status & DP_AUX_CH_CTL_DONE)
1333 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
1334 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
1340 /* Check for timeout or receive error.
1341 * Timeouts occur when the sink is not connected
1343 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1344 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
1349 /* Timeouts occur when the device isn't connected, so they're
1350 * "normal" -- don't fill the kernel log with these */
1351 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
1352 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
1357 /* Unload any bytes sent back from the other side */
1358 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1359 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
1362 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1363 * We have no idea of what happened so we return -EBUSY so
1364 * drm layer takes care for the necessary retries.
1366 if (recv_bytes == 0 || recv_bytes > 20) {
1367 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1373 if (recv_bytes > recv_size)
1374 recv_bytes = recv_size;
1376 for (i = 0; i < recv_bytes; i += 4)
1377 intel_dp_unpack_aux(I915_READ(ch_data[i >> 2]),
1378 recv + i, recv_bytes - i);
1382 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1385 edp_panel_vdd_off(intel_dp, false);
1387 pps_unlock(intel_dp, pps_wakeref);
1388 intel_display_power_put_async(dev_priv, aux_domain, aux_wakeref);
1393 #define BARE_ADDRESS_SIZE 3
1394 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
1397 intel_dp_aux_header(u8 txbuf[HEADER_SIZE],
1398 const struct drm_dp_aux_msg *msg)
1400 txbuf[0] = (msg->request << 4) | ((msg->address >> 16) & 0xf);
1401 txbuf[1] = (msg->address >> 8) & 0xff;
1402 txbuf[2] = msg->address & 0xff;
1403 txbuf[3] = msg->size - 1;
1407 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
1409 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1410 u8 txbuf[20], rxbuf[20];
1411 size_t txsize, rxsize;
1414 intel_dp_aux_header(txbuf, msg);
1416 switch (msg->request & ~DP_AUX_I2C_MOT) {
1417 case DP_AUX_NATIVE_WRITE:
1418 case DP_AUX_I2C_WRITE:
1419 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
1420 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
1421 rxsize = 2; /* 0 or 1 data bytes */
1423 if (WARN_ON(txsize > 20))
1426 WARN_ON(!msg->buffer != !msg->size);
1429 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
1431 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
1434 msg->reply = rxbuf[0] >> 4;
1437 /* Number of bytes written in a short write. */
1438 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1440 /* Return payload size. */
1446 case DP_AUX_NATIVE_READ:
1447 case DP_AUX_I2C_READ:
1448 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
1449 rxsize = msg->size + 1;
1451 if (WARN_ON(rxsize > 20))
1454 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
1457 msg->reply = rxbuf[0] >> 4;
1459 * Assume happy day, and copy the data. The caller is
1460 * expected to check msg->reply before touching it.
1462 * Return payload size.
1465 memcpy(msg->buffer, rxbuf + 1, ret);
1478 static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp)
1480 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1481 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1482 enum aux_ch aux_ch = dig_port->aux_ch;
1488 return DP_AUX_CH_CTL(aux_ch);
1490 MISSING_CASE(aux_ch);
1491 return DP_AUX_CH_CTL(AUX_CH_B);
1495 static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index)
1497 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1498 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1499 enum aux_ch aux_ch = dig_port->aux_ch;
1505 return DP_AUX_CH_DATA(aux_ch, index);
1507 MISSING_CASE(aux_ch);
1508 return DP_AUX_CH_DATA(AUX_CH_B, index);
1512 static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp)
1514 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1515 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1516 enum aux_ch aux_ch = dig_port->aux_ch;
1520 return DP_AUX_CH_CTL(aux_ch);
1524 return PCH_DP_AUX_CH_CTL(aux_ch);
1526 MISSING_CASE(aux_ch);
1527 return DP_AUX_CH_CTL(AUX_CH_A);
1531 static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index)
1533 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1534 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1535 enum aux_ch aux_ch = dig_port->aux_ch;
1539 return DP_AUX_CH_DATA(aux_ch, index);
1543 return PCH_DP_AUX_CH_DATA(aux_ch, index);
1545 MISSING_CASE(aux_ch);
1546 return DP_AUX_CH_DATA(AUX_CH_A, index);
1550 static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp)
1552 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1553 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1554 enum aux_ch aux_ch = dig_port->aux_ch;
1563 return DP_AUX_CH_CTL(aux_ch);
1565 MISSING_CASE(aux_ch);
1566 return DP_AUX_CH_CTL(AUX_CH_A);
1570 static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index)
1572 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1573 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1574 enum aux_ch aux_ch = dig_port->aux_ch;
1583 return DP_AUX_CH_DATA(aux_ch, index);
1585 MISSING_CASE(aux_ch);
1586 return DP_AUX_CH_DATA(AUX_CH_A, index);
1591 intel_dp_aux_fini(struct intel_dp *intel_dp)
1593 kfree(intel_dp->aux.name);
1597 intel_dp_aux_init(struct intel_dp *intel_dp)
1599 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1600 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1601 struct intel_encoder *encoder = &dig_port->base;
1603 if (INTEL_GEN(dev_priv) >= 9) {
1604 intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg;
1605 intel_dp->aux_ch_data_reg = skl_aux_data_reg;
1606 } else if (HAS_PCH_SPLIT(dev_priv)) {
1607 intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg;
1608 intel_dp->aux_ch_data_reg = ilk_aux_data_reg;
1610 intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg;
1611 intel_dp->aux_ch_data_reg = g4x_aux_data_reg;
1614 if (INTEL_GEN(dev_priv) >= 9)
1615 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
1616 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
1617 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
1618 else if (HAS_PCH_SPLIT(dev_priv))
1619 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
1621 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
1623 if (INTEL_GEN(dev_priv) >= 9)
1624 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
1626 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
1628 drm_dp_aux_init(&intel_dp->aux);
1630 /* Failure to allocate our preferred name is not critical */
1631 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c",
1632 port_name(encoder->port));
1633 intel_dp->aux.transfer = intel_dp_aux_transfer;
1636 bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
1638 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
1640 return max_rate >= 540000;
1643 bool intel_dp_source_supports_hbr3(struct intel_dp *intel_dp)
1645 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
1647 return max_rate >= 810000;
1651 intel_dp_set_clock(struct intel_encoder *encoder,
1652 struct intel_crtc_state *pipe_config)
1654 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1655 const struct dp_link_dpll *divisor = NULL;
1658 if (IS_G4X(dev_priv)) {
1660 count = ARRAY_SIZE(g4x_dpll);
1661 } else if (HAS_PCH_SPLIT(dev_priv)) {
1663 count = ARRAY_SIZE(pch_dpll);
1664 } else if (IS_CHERRYVIEW(dev_priv)) {
1666 count = ARRAY_SIZE(chv_dpll);
1667 } else if (IS_VALLEYVIEW(dev_priv)) {
1669 count = ARRAY_SIZE(vlv_dpll);
1672 if (divisor && count) {
1673 for (i = 0; i < count; i++) {
1674 if (pipe_config->port_clock == divisor[i].clock) {
1675 pipe_config->dpll = divisor[i].dpll;
1676 pipe_config->clock_set = true;
1683 static void snprintf_int_array(char *str, size_t len,
1684 const int *array, int nelem)
1690 for (i = 0; i < nelem; i++) {
1691 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
1699 static void intel_dp_print_rates(struct intel_dp *intel_dp)
1701 char str[128]; /* FIXME: too big for stack? */
1703 if ((drm_debug & DRM_UT_KMS) == 0)
1706 snprintf_int_array(str, sizeof(str),
1707 intel_dp->source_rates, intel_dp->num_source_rates);
1708 DRM_DEBUG_KMS("source rates: %s\n", str);
1710 snprintf_int_array(str, sizeof(str),
1711 intel_dp->sink_rates, intel_dp->num_sink_rates);
1712 DRM_DEBUG_KMS("sink rates: %s\n", str);
1714 snprintf_int_array(str, sizeof(str),
1715 intel_dp->common_rates, intel_dp->num_common_rates);
1716 DRM_DEBUG_KMS("common rates: %s\n", str);
1720 intel_dp_max_link_rate(struct intel_dp *intel_dp)
1724 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
1725 if (WARN_ON(len <= 0))
1728 return intel_dp->common_rates[len - 1];
1731 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1733 int i = intel_dp_rate_index(intel_dp->sink_rates,
1734 intel_dp->num_sink_rates, rate);
1742 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1743 u8 *link_bw, u8 *rate_select)
1745 /* eDP 1.4 rate select method. */
1746 if (intel_dp->use_rate_select) {
1749 intel_dp_rate_select(intel_dp, port_clock);
1751 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1756 static bool intel_dp_source_supports_fec(struct intel_dp *intel_dp,
1757 const struct intel_crtc_state *pipe_config)
1759 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1761 return INTEL_GEN(dev_priv) >= 11 &&
1762 pipe_config->cpu_transcoder != TRANSCODER_A;
1765 static bool intel_dp_supports_fec(struct intel_dp *intel_dp,
1766 const struct intel_crtc_state *pipe_config)
1768 return intel_dp_source_supports_fec(intel_dp, pipe_config) &&
1769 drm_dp_sink_supports_fec(intel_dp->fec_capable);
1772 static bool intel_dp_source_supports_dsc(struct intel_dp *intel_dp,
1773 const struct intel_crtc_state *pipe_config)
1775 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1777 return INTEL_GEN(dev_priv) >= 10 &&
1778 pipe_config->cpu_transcoder != TRANSCODER_A;
1781 static bool intel_dp_supports_dsc(struct intel_dp *intel_dp,
1782 const struct intel_crtc_state *pipe_config)
1784 if (!intel_dp_is_edp(intel_dp) && !pipe_config->fec_enable)
1787 return intel_dp_source_supports_dsc(intel_dp, pipe_config) &&
1788 drm_dp_sink_supports_dsc(intel_dp->dsc_dpcd);
1791 static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1792 struct intel_crtc_state *pipe_config)
1794 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1795 struct intel_connector *intel_connector = intel_dp->attached_connector;
1798 bpp = pipe_config->pipe_bpp;
1799 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1802 bpp = min(bpp, 3*bpc);
1804 if (intel_dp_is_edp(intel_dp)) {
1805 /* Get bpp from vbt only for panels that dont have bpp in edid */
1806 if (intel_connector->base.display_info.bpc == 0 &&
1807 dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp) {
1808 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
1809 dev_priv->vbt.edp.bpp);
1810 bpp = dev_priv->vbt.edp.bpp;
1817 /* Adjust link config limits based on compliance test requests. */
1819 intel_dp_adjust_compliance_config(struct intel_dp *intel_dp,
1820 struct intel_crtc_state *pipe_config,
1821 struct link_config_limits *limits)
1823 /* For DP Compliance we override the computed bpp for the pipe */
1824 if (intel_dp->compliance.test_data.bpc != 0) {
1825 int bpp = 3 * intel_dp->compliance.test_data.bpc;
1827 limits->min_bpp = limits->max_bpp = bpp;
1828 pipe_config->dither_force_disable = bpp == 6 * 3;
1830 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n", bpp);
1833 /* Use values requested by Compliance Test Request */
1834 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1837 /* Validate the compliance test data since max values
1838 * might have changed due to link train fallback.
1840 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1841 intel_dp->compliance.test_lane_count)) {
1842 index = intel_dp_rate_index(intel_dp->common_rates,
1843 intel_dp->num_common_rates,
1844 intel_dp->compliance.test_link_rate);
1846 limits->min_clock = limits->max_clock = index;
1847 limits->min_lane_count = limits->max_lane_count =
1848 intel_dp->compliance.test_lane_count;
1853 /* Optimize link config in order: max bpp, min clock, min lanes */
1855 intel_dp_compute_link_config_wide(struct intel_dp *intel_dp,
1856 struct intel_crtc_state *pipe_config,
1857 const struct link_config_limits *limits)
1859 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1860 int bpp, clock, lane_count;
1861 int mode_rate, link_clock, link_avail;
1863 for (bpp = limits->max_bpp; bpp >= limits->min_bpp; bpp -= 2 * 3) {
1864 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1867 for (clock = limits->min_clock; clock <= limits->max_clock; clock++) {
1868 for (lane_count = limits->min_lane_count;
1869 lane_count <= limits->max_lane_count;
1871 link_clock = intel_dp->common_rates[clock];
1872 link_avail = intel_dp_max_data_rate(link_clock,
1875 if (mode_rate <= link_avail) {
1876 pipe_config->lane_count = lane_count;
1877 pipe_config->pipe_bpp = bpp;
1878 pipe_config->port_clock = link_clock;
1889 static int intel_dp_dsc_compute_bpp(struct intel_dp *intel_dp, u8 dsc_max_bpc)
1892 u8 dsc_bpc[3] = {0};
1894 num_bpc = drm_dp_dsc_sink_supported_input_bpcs(intel_dp->dsc_dpcd,
1896 for (i = 0; i < num_bpc; i++) {
1897 if (dsc_max_bpc >= dsc_bpc[i])
1898 return dsc_bpc[i] * 3;
1904 static int intel_dp_dsc_compute_config(struct intel_dp *intel_dp,
1905 struct intel_crtc_state *pipe_config,
1906 struct drm_connector_state *conn_state,
1907 struct link_config_limits *limits)
1909 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1910 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
1911 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1916 pipe_config->fec_enable = !intel_dp_is_edp(intel_dp) &&
1917 intel_dp_supports_fec(intel_dp, pipe_config);
1919 if (!intel_dp_supports_dsc(intel_dp, pipe_config))
1922 dsc_max_bpc = min_t(u8, DP_DSC_MAX_SUPPORTED_BPC,
1923 conn_state->max_requested_bpc);
1925 pipe_bpp = intel_dp_dsc_compute_bpp(intel_dp, dsc_max_bpc);
1926 if (pipe_bpp < DP_DSC_MIN_SUPPORTED_BPC * 3) {
1927 DRM_DEBUG_KMS("No DSC support for less than 8bpc\n");
1932 * For now enable DSC for max bpp, max link rate, max lane count.
1933 * Optimize this later for the minimum possible link rate/lane count
1934 * with DSC enabled for the requested mode.
1936 pipe_config->pipe_bpp = pipe_bpp;
1937 pipe_config->port_clock = intel_dp->common_rates[limits->max_clock];
1938 pipe_config->lane_count = limits->max_lane_count;
1940 if (intel_dp_is_edp(intel_dp)) {
1941 pipe_config->dsc_params.compressed_bpp =
1942 min_t(u16, drm_edp_dsc_sink_output_bpp(intel_dp->dsc_dpcd) >> 4,
1943 pipe_config->pipe_bpp);
1944 pipe_config->dsc_params.slice_count =
1945 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
1948 u16 dsc_max_output_bpp;
1949 u8 dsc_dp_slice_count;
1951 dsc_max_output_bpp =
1952 intel_dp_dsc_get_output_bpp(pipe_config->port_clock,
1953 pipe_config->lane_count,
1954 adjusted_mode->crtc_clock,
1955 adjusted_mode->crtc_hdisplay);
1956 dsc_dp_slice_count =
1957 intel_dp_dsc_get_slice_count(intel_dp,
1958 adjusted_mode->crtc_clock,
1959 adjusted_mode->crtc_hdisplay);
1960 if (!dsc_max_output_bpp || !dsc_dp_slice_count) {
1961 DRM_DEBUG_KMS("Compressed BPP/Slice Count not supported\n");
1964 pipe_config->dsc_params.compressed_bpp = min_t(u16,
1965 dsc_max_output_bpp >> 4,
1966 pipe_config->pipe_bpp);
1967 pipe_config->dsc_params.slice_count = dsc_dp_slice_count;
1970 * VDSC engine operates at 1 Pixel per clock, so if peak pixel rate
1971 * is greater than the maximum Cdclock and if slice count is even
1972 * then we need to use 2 VDSC instances.
1974 if (adjusted_mode->crtc_clock > dev_priv->max_cdclk_freq) {
1975 if (pipe_config->dsc_params.slice_count > 1) {
1976 pipe_config->dsc_params.dsc_split = true;
1978 DRM_DEBUG_KMS("Cannot split stream to use 2 VDSC instances\n");
1983 ret = intel_dp_compute_dsc_params(intel_dp, pipe_config);
1985 DRM_DEBUG_KMS("Cannot compute valid DSC parameters for Input Bpp = %d "
1986 "Compressed BPP = %d\n",
1987 pipe_config->pipe_bpp,
1988 pipe_config->dsc_params.compressed_bpp);
1992 pipe_config->dsc_params.compression_enable = true;
1993 DRM_DEBUG_KMS("DP DSC computed with Input Bpp = %d "
1994 "Compressed Bpp = %d Slice Count = %d\n",
1995 pipe_config->pipe_bpp,
1996 pipe_config->dsc_params.compressed_bpp,
1997 pipe_config->dsc_params.slice_count);
2002 int intel_dp_min_bpp(const struct intel_crtc_state *crtc_state)
2004 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_RGB)
2011 intel_dp_compute_link_config(struct intel_encoder *encoder,
2012 struct intel_crtc_state *pipe_config,
2013 struct drm_connector_state *conn_state)
2015 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
2016 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2017 struct link_config_limits limits;
2021 common_len = intel_dp_common_len_rate_limit(intel_dp,
2022 intel_dp->max_link_rate);
2024 /* No common link rates between source and sink */
2025 WARN_ON(common_len <= 0);
2027 limits.min_clock = 0;
2028 limits.max_clock = common_len - 1;
2030 limits.min_lane_count = 1;
2031 limits.max_lane_count = intel_dp_max_lane_count(intel_dp);
2033 limits.min_bpp = intel_dp_min_bpp(pipe_config);
2034 limits.max_bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
2036 if (intel_dp_is_edp(intel_dp)) {
2038 * Use the maximum clock and number of lanes the eDP panel
2039 * advertizes being capable of. The panels are generally
2040 * designed to support only a single clock and lane
2041 * configuration, and typically these values correspond to the
2042 * native resolution of the panel.
2044 limits.min_lane_count = limits.max_lane_count;
2045 limits.min_clock = limits.max_clock;
2048 intel_dp_adjust_compliance_config(intel_dp, pipe_config, &limits);
2050 DRM_DEBUG_KMS("DP link computation with max lane count %i "
2051 "max rate %d max bpp %d pixel clock %iKHz\n",
2052 limits.max_lane_count,
2053 intel_dp->common_rates[limits.max_clock],
2054 limits.max_bpp, adjusted_mode->crtc_clock);
2057 * Optimize for slow and wide. This is the place to add alternative
2058 * optimization policy.
2060 ret = intel_dp_compute_link_config_wide(intel_dp, pipe_config, &limits);
2062 /* enable compression if the mode doesn't fit available BW */
2063 DRM_DEBUG_KMS("Force DSC en = %d\n", intel_dp->force_dsc_en);
2064 if (ret || intel_dp->force_dsc_en) {
2065 ret = intel_dp_dsc_compute_config(intel_dp, pipe_config,
2066 conn_state, &limits);
2071 if (pipe_config->dsc_params.compression_enable) {
2072 DRM_DEBUG_KMS("DP lane count %d clock %d Input bpp %d Compressed bpp %d\n",
2073 pipe_config->lane_count, pipe_config->port_clock,
2074 pipe_config->pipe_bpp,
2075 pipe_config->dsc_params.compressed_bpp);
2077 DRM_DEBUG_KMS("DP link rate required %i available %i\n",
2078 intel_dp_link_required(adjusted_mode->crtc_clock,
2079 pipe_config->dsc_params.compressed_bpp),
2080 intel_dp_max_data_rate(pipe_config->port_clock,
2081 pipe_config->lane_count));
2083 DRM_DEBUG_KMS("DP lane count %d clock %d bpp %d\n",
2084 pipe_config->lane_count, pipe_config->port_clock,
2085 pipe_config->pipe_bpp);
2087 DRM_DEBUG_KMS("DP link rate required %i available %i\n",
2088 intel_dp_link_required(adjusted_mode->crtc_clock,
2089 pipe_config->pipe_bpp),
2090 intel_dp_max_data_rate(pipe_config->port_clock,
2091 pipe_config->lane_count));
2096 bool intel_dp_limited_color_range(const struct intel_crtc_state *crtc_state,
2097 const struct drm_connector_state *conn_state)
2099 const struct intel_digital_connector_state *intel_conn_state =
2100 to_intel_digital_connector_state(conn_state);
2101 const struct drm_display_mode *adjusted_mode =
2102 &crtc_state->base.adjusted_mode;
2104 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
2107 * CEA-861-E - 5.1 Default Encoding Parameters
2108 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
2110 return crtc_state->pipe_bpp != 18 &&
2111 drm_default_rgb_quant_range(adjusted_mode) ==
2112 HDMI_QUANTIZATION_RANGE_LIMITED;
2114 return intel_conn_state->broadcast_rgb ==
2115 INTEL_BROADCAST_RGB_LIMITED;
2120 intel_dp_compute_config(struct intel_encoder *encoder,
2121 struct intel_crtc_state *pipe_config,
2122 struct drm_connector_state *conn_state)
2124 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2125 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
2126 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2127 struct intel_lspcon *lspcon = enc_to_intel_lspcon(&encoder->base);
2128 enum port port = encoder->port;
2129 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
2130 struct intel_connector *intel_connector = intel_dp->attached_connector;
2131 struct intel_digital_connector_state *intel_conn_state =
2132 to_intel_digital_connector_state(conn_state);
2133 bool constant_n = drm_dp_has_quirk(&intel_dp->desc,
2134 DP_DPCD_QUIRK_CONSTANT_N);
2135 int ret, output_bpp;
2137 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
2138 pipe_config->has_pch_encoder = true;
2140 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
2142 lspcon_ycbcr420_config(&intel_connector->base, pipe_config);
2144 pipe_config->has_drrs = false;
2145 if (IS_G4X(dev_priv) || port == PORT_A)
2146 pipe_config->has_audio = false;
2147 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
2148 pipe_config->has_audio = intel_dp->has_audio;
2150 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
2152 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
2153 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
2156 if (INTEL_GEN(dev_priv) >= 9) {
2157 ret = skl_update_scaler_crtc(pipe_config);
2162 if (HAS_GMCH(dev_priv))
2163 intel_gmch_panel_fitting(intel_crtc, pipe_config,
2164 conn_state->scaling_mode);
2166 intel_pch_panel_fitting(intel_crtc, pipe_config,
2167 conn_state->scaling_mode);
2170 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
2173 if (HAS_GMCH(dev_priv) &&
2174 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
2177 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
2180 ret = intel_dp_compute_link_config(encoder, pipe_config, conn_state);
2184 pipe_config->limited_color_range =
2185 intel_dp_limited_color_range(pipe_config, conn_state);
2187 if (pipe_config->dsc_params.compression_enable)
2188 output_bpp = pipe_config->dsc_params.compressed_bpp;
2190 output_bpp = pipe_config->pipe_bpp;
2192 intel_link_compute_m_n(output_bpp,
2193 pipe_config->lane_count,
2194 adjusted_mode->crtc_clock,
2195 pipe_config->port_clock,
2196 &pipe_config->dp_m_n,
2199 if (intel_connector->panel.downclock_mode != NULL &&
2200 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
2201 pipe_config->has_drrs = true;
2202 intel_link_compute_m_n(output_bpp,
2203 pipe_config->lane_count,
2204 intel_connector->panel.downclock_mode->clock,
2205 pipe_config->port_clock,
2206 &pipe_config->dp_m2_n2,
2210 if (!HAS_DDI(dev_priv))
2211 intel_dp_set_clock(encoder, pipe_config);
2213 intel_psr_compute_config(intel_dp, pipe_config);
2218 void intel_dp_set_link_params(struct intel_dp *intel_dp,
2219 int link_rate, u8 lane_count,
2222 intel_dp->link_trained = false;
2223 intel_dp->link_rate = link_rate;
2224 intel_dp->lane_count = lane_count;
2225 intel_dp->link_mst = link_mst;
2228 static void intel_dp_prepare(struct intel_encoder *encoder,
2229 const struct intel_crtc_state *pipe_config)
2231 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2232 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2233 enum port port = encoder->port;
2234 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2235 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
2237 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
2238 pipe_config->lane_count,
2239 intel_crtc_has_type(pipe_config,
2240 INTEL_OUTPUT_DP_MST));
2243 * There are four kinds of DP registers:
2250 * IBX PCH and CPU are the same for almost everything,
2251 * except that the CPU DP PLL is configured in this
2254 * CPT PCH is quite different, having many bits moved
2255 * to the TRANS_DP_CTL register instead. That
2256 * configuration happens (oddly) in ironlake_pch_enable
2259 /* Preserve the BIOS-computed detected bit. This is
2260 * supposed to be read-only.
2262 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
2264 /* Handle DP bits in common between all three register formats */
2265 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
2266 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
2268 /* Split out the IBX/CPU vs CPT settings */
2270 if (IS_IVYBRIDGE(dev_priv) && port == PORT_A) {
2271 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2272 intel_dp->DP |= DP_SYNC_HS_HIGH;
2273 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2274 intel_dp->DP |= DP_SYNC_VS_HIGH;
2275 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
2277 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2278 intel_dp->DP |= DP_ENHANCED_FRAMING;
2280 intel_dp->DP |= DP_PIPE_SEL_IVB(crtc->pipe);
2281 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2284 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
2286 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2287 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2288 trans_dp |= TRANS_DP_ENH_FRAMING;
2290 trans_dp &= ~TRANS_DP_ENH_FRAMING;
2291 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
2293 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
2294 intel_dp->DP |= DP_COLOR_RANGE_16_235;
2296 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2297 intel_dp->DP |= DP_SYNC_HS_HIGH;
2298 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2299 intel_dp->DP |= DP_SYNC_VS_HIGH;
2300 intel_dp->DP |= DP_LINK_TRAIN_OFF;
2302 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2303 intel_dp->DP |= DP_ENHANCED_FRAMING;
2305 if (IS_CHERRYVIEW(dev_priv))
2306 intel_dp->DP |= DP_PIPE_SEL_CHV(crtc->pipe);
2308 intel_dp->DP |= DP_PIPE_SEL(crtc->pipe);
2312 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
2313 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
2315 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
2316 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
2318 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
2319 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
2321 static void intel_pps_verify_state(struct intel_dp *intel_dp);
2323 static void wait_panel_status(struct intel_dp *intel_dp,
2327 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2328 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2330 lockdep_assert_held(&dev_priv->pps_mutex);
2332 intel_pps_verify_state(intel_dp);
2334 pp_stat_reg = _pp_stat_reg(intel_dp);
2335 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2337 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
2339 I915_READ(pp_stat_reg),
2340 I915_READ(pp_ctrl_reg));
2342 if (intel_wait_for_register(&dev_priv->uncore,
2343 pp_stat_reg, mask, value,
2345 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
2346 I915_READ(pp_stat_reg),
2347 I915_READ(pp_ctrl_reg));
2349 DRM_DEBUG_KMS("Wait complete\n");
2352 static void wait_panel_on(struct intel_dp *intel_dp)
2354 DRM_DEBUG_KMS("Wait for panel power on\n");
2355 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
2358 static void wait_panel_off(struct intel_dp *intel_dp)
2360 DRM_DEBUG_KMS("Wait for panel power off time\n");
2361 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
2364 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
2366 ktime_t panel_power_on_time;
2367 s64 panel_power_off_duration;
2369 DRM_DEBUG_KMS("Wait for panel power cycle\n");
2371 /* take the difference of currrent time and panel power off time
2372 * and then make panel wait for t11_t12 if needed. */
2373 panel_power_on_time = ktime_get_boottime();
2374 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2376 /* When we disable the VDD override bit last we have to do the manual
2378 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2379 wait_remaining_ms_from_jiffies(jiffies,
2380 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
2382 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
2385 static void wait_backlight_on(struct intel_dp *intel_dp)
2387 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2388 intel_dp->backlight_on_delay);
2391 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
2393 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2394 intel_dp->backlight_off_delay);
2397 /* Read the current pp_control value, unlocking the register if it
2401 static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
2403 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2406 lockdep_assert_held(&dev_priv->pps_mutex);
2408 control = I915_READ(_pp_ctrl_reg(intel_dp));
2409 if (WARN_ON(!HAS_DDI(dev_priv) &&
2410 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
2411 control &= ~PANEL_UNLOCK_MASK;
2412 control |= PANEL_UNLOCK_REGS;
2418 * Must be paired with edp_panel_vdd_off().
2419 * Must hold pps_mutex around the whole on/off sequence.
2420 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2422 static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
2424 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2425 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2427 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2428 bool need_to_disable = !intel_dp->want_panel_vdd;
2430 lockdep_assert_held(&dev_priv->pps_mutex);
2432 if (!intel_dp_is_edp(intel_dp))
2435 cancel_delayed_work(&intel_dp->panel_vdd_work);
2436 intel_dp->want_panel_vdd = true;
2438 if (edp_have_panel_vdd(intel_dp))
2439 return need_to_disable;
2441 intel_display_power_get(dev_priv,
2442 intel_aux_power_domain(intel_dig_port));
2444 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2445 port_name(intel_dig_port->base.port));
2447 if (!edp_have_panel_power(intel_dp))
2448 wait_panel_power_cycle(intel_dp);
2450 pp = ironlake_get_pp_control(intel_dp);
2451 pp |= EDP_FORCE_VDD;
2453 pp_stat_reg = _pp_stat_reg(intel_dp);
2454 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2456 I915_WRITE(pp_ctrl_reg, pp);
2457 POSTING_READ(pp_ctrl_reg);
2458 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2459 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2461 * If the panel wasn't on, delay before accessing aux channel
2463 if (!edp_have_panel_power(intel_dp)) {
2464 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2465 port_name(intel_dig_port->base.port));
2466 msleep(intel_dp->panel_power_up_delay);
2469 return need_to_disable;
2473 * Must be paired with intel_edp_panel_vdd_off() or
2474 * intel_edp_panel_off().
2475 * Nested calls to these functions are not allowed since
2476 * we drop the lock. Caller must use some higher level
2477 * locking to prevent nested calls from other threads.
2479 void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
2481 intel_wakeref_t wakeref;
2484 if (!intel_dp_is_edp(intel_dp))
2488 with_pps_lock(intel_dp, wakeref)
2489 vdd = edp_panel_vdd_on(intel_dp);
2490 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
2491 port_name(dp_to_dig_port(intel_dp)->base.port));
2494 static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
2496 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2497 struct intel_digital_port *intel_dig_port =
2498 dp_to_dig_port(intel_dp);
2500 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2502 lockdep_assert_held(&dev_priv->pps_mutex);
2504 WARN_ON(intel_dp->want_panel_vdd);
2506 if (!edp_have_panel_vdd(intel_dp))
2509 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2510 port_name(intel_dig_port->base.port));
2512 pp = ironlake_get_pp_control(intel_dp);
2513 pp &= ~EDP_FORCE_VDD;
2515 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2516 pp_stat_reg = _pp_stat_reg(intel_dp);
2518 I915_WRITE(pp_ctrl_reg, pp);
2519 POSTING_READ(pp_ctrl_reg);
2521 /* Make sure sequencer is idle before allowing subsequent activity */
2522 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2523 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2525 if ((pp & PANEL_POWER_ON) == 0)
2526 intel_dp->panel_power_off_time = ktime_get_boottime();
2528 intel_display_power_put_unchecked(dev_priv,
2529 intel_aux_power_domain(intel_dig_port));
2532 static void edp_panel_vdd_work(struct work_struct *__work)
2534 struct intel_dp *intel_dp =
2535 container_of(to_delayed_work(__work),
2536 struct intel_dp, panel_vdd_work);
2537 intel_wakeref_t wakeref;
2539 with_pps_lock(intel_dp, wakeref) {
2540 if (!intel_dp->want_panel_vdd)
2541 edp_panel_vdd_off_sync(intel_dp);
2545 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2547 unsigned long delay;
2550 * Queue the timer to fire a long time from now (relative to the power
2551 * down delay) to keep the panel power up across a sequence of
2554 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2555 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2559 * Must be paired with edp_panel_vdd_on().
2560 * Must hold pps_mutex around the whole on/off sequence.
2561 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2563 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
2565 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2567 lockdep_assert_held(&dev_priv->pps_mutex);
2569 if (!intel_dp_is_edp(intel_dp))
2572 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
2573 port_name(dp_to_dig_port(intel_dp)->base.port));
2575 intel_dp->want_panel_vdd = false;
2578 edp_panel_vdd_off_sync(intel_dp);
2580 edp_panel_vdd_schedule_off(intel_dp);
2583 static void edp_panel_on(struct intel_dp *intel_dp)
2585 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2587 i915_reg_t pp_ctrl_reg;
2589 lockdep_assert_held(&dev_priv->pps_mutex);
2591 if (!intel_dp_is_edp(intel_dp))
2594 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2595 port_name(dp_to_dig_port(intel_dp)->base.port));
2597 if (WARN(edp_have_panel_power(intel_dp),
2598 "eDP port %c panel power already on\n",
2599 port_name(dp_to_dig_port(intel_dp)->base.port)))
2602 wait_panel_power_cycle(intel_dp);
2604 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2605 pp = ironlake_get_pp_control(intel_dp);
2606 if (IS_GEN(dev_priv, 5)) {
2607 /* ILK workaround: disable reset around power sequence */
2608 pp &= ~PANEL_POWER_RESET;
2609 I915_WRITE(pp_ctrl_reg, pp);
2610 POSTING_READ(pp_ctrl_reg);
2613 pp |= PANEL_POWER_ON;
2614 if (!IS_GEN(dev_priv, 5))
2615 pp |= PANEL_POWER_RESET;
2617 I915_WRITE(pp_ctrl_reg, pp);
2618 POSTING_READ(pp_ctrl_reg);
2620 wait_panel_on(intel_dp);
2621 intel_dp->last_power_on = jiffies;
2623 if (IS_GEN(dev_priv, 5)) {
2624 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
2625 I915_WRITE(pp_ctrl_reg, pp);
2626 POSTING_READ(pp_ctrl_reg);
2630 void intel_edp_panel_on(struct intel_dp *intel_dp)
2632 intel_wakeref_t wakeref;
2634 if (!intel_dp_is_edp(intel_dp))
2637 with_pps_lock(intel_dp, wakeref)
2638 edp_panel_on(intel_dp);
2642 static void edp_panel_off(struct intel_dp *intel_dp)
2644 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2645 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2647 i915_reg_t pp_ctrl_reg;
2649 lockdep_assert_held(&dev_priv->pps_mutex);
2651 if (!intel_dp_is_edp(intel_dp))
2654 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2655 port_name(dig_port->base.port));
2657 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2658 port_name(dig_port->base.port));
2660 pp = ironlake_get_pp_control(intel_dp);
2661 /* We need to switch off panel power _and_ force vdd, for otherwise some
2662 * panels get very unhappy and cease to work. */
2663 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
2666 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2668 intel_dp->want_panel_vdd = false;
2670 I915_WRITE(pp_ctrl_reg, pp);
2671 POSTING_READ(pp_ctrl_reg);
2673 wait_panel_off(intel_dp);
2674 intel_dp->panel_power_off_time = ktime_get_boottime();
2676 /* We got a reference when we enabled the VDD. */
2677 intel_display_power_put_unchecked(dev_priv, intel_aux_power_domain(dig_port));
2680 void intel_edp_panel_off(struct intel_dp *intel_dp)
2682 intel_wakeref_t wakeref;
2684 if (!intel_dp_is_edp(intel_dp))
2687 with_pps_lock(intel_dp, wakeref)
2688 edp_panel_off(intel_dp);
2691 /* Enable backlight in the panel power control. */
2692 static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
2694 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2695 intel_wakeref_t wakeref;
2698 * If we enable the backlight right away following a panel power
2699 * on, we may see slight flicker as the panel syncs with the eDP
2700 * link. So delay a bit to make sure the image is solid before
2701 * allowing it to appear.
2703 wait_backlight_on(intel_dp);
2705 with_pps_lock(intel_dp, wakeref) {
2706 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2709 pp = ironlake_get_pp_control(intel_dp);
2710 pp |= EDP_BLC_ENABLE;
2712 I915_WRITE(pp_ctrl_reg, pp);
2713 POSTING_READ(pp_ctrl_reg);
2717 /* Enable backlight PWM and backlight PP control. */
2718 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2719 const struct drm_connector_state *conn_state)
2721 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2723 if (!intel_dp_is_edp(intel_dp))
2726 DRM_DEBUG_KMS("\n");
2728 intel_panel_enable_backlight(crtc_state, conn_state);
2729 _intel_edp_backlight_on(intel_dp);
2732 /* Disable backlight in the panel power control. */
2733 static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
2735 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2736 intel_wakeref_t wakeref;
2738 if (!intel_dp_is_edp(intel_dp))
2741 with_pps_lock(intel_dp, wakeref) {
2742 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2745 pp = ironlake_get_pp_control(intel_dp);
2746 pp &= ~EDP_BLC_ENABLE;
2748 I915_WRITE(pp_ctrl_reg, pp);
2749 POSTING_READ(pp_ctrl_reg);
2752 intel_dp->last_backlight_off = jiffies;
2753 edp_wait_backlight_off(intel_dp);
2756 /* Disable backlight PP control and backlight PWM. */
2757 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
2759 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2761 if (!intel_dp_is_edp(intel_dp))
2764 DRM_DEBUG_KMS("\n");
2766 _intel_edp_backlight_off(intel_dp);
2767 intel_panel_disable_backlight(old_conn_state);
2771 * Hook for controlling the panel power control backlight through the bl_power
2772 * sysfs attribute. Take care to handle multiple calls.
2774 static void intel_edp_backlight_power(struct intel_connector *connector,
2777 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
2778 intel_wakeref_t wakeref;
2782 with_pps_lock(intel_dp, wakeref)
2783 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
2784 if (is_enabled == enable)
2787 DRM_DEBUG_KMS("panel power control backlight %s\n",
2788 enable ? "enable" : "disable");
2791 _intel_edp_backlight_on(intel_dp);
2793 _intel_edp_backlight_off(intel_dp);
2796 static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2798 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2799 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2800 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2802 I915_STATE_WARN(cur_state != state,
2803 "DP port %c state assertion failure (expected %s, current %s)\n",
2804 port_name(dig_port->base.port),
2805 onoff(state), onoff(cur_state));
2807 #define assert_dp_port_disabled(d) assert_dp_port((d), false)
2809 static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2811 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2813 I915_STATE_WARN(cur_state != state,
2814 "eDP PLL state assertion failure (expected %s, current %s)\n",
2815 onoff(state), onoff(cur_state));
2817 #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2818 #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2820 static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2821 const struct intel_crtc_state *pipe_config)
2823 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2824 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2826 assert_pipe_disabled(dev_priv, crtc->pipe);
2827 assert_dp_port_disabled(intel_dp);
2828 assert_edp_pll_disabled(dev_priv);
2830 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
2831 pipe_config->port_clock);
2833 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2835 if (pipe_config->port_clock == 162000)
2836 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2838 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2840 I915_WRITE(DP_A, intel_dp->DP);
2845 * [DevILK] Work around required when enabling DP PLL
2846 * while a pipe is enabled going to FDI:
2847 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2848 * 2. Program DP PLL enable
2850 if (IS_GEN(dev_priv, 5))
2851 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
2853 intel_dp->DP |= DP_PLL_ENABLE;
2855 I915_WRITE(DP_A, intel_dp->DP);
2860 static void ironlake_edp_pll_off(struct intel_dp *intel_dp,
2861 const struct intel_crtc_state *old_crtc_state)
2863 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
2864 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2866 assert_pipe_disabled(dev_priv, crtc->pipe);
2867 assert_dp_port_disabled(intel_dp);
2868 assert_edp_pll_enabled(dev_priv);
2870 DRM_DEBUG_KMS("disabling eDP PLL\n");
2872 intel_dp->DP &= ~DP_PLL_ENABLE;
2874 I915_WRITE(DP_A, intel_dp->DP);
2879 static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2882 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2883 * be capable of signalling downstream hpd with a long pulse.
2884 * Whether or not that means D3 is safe to use is not clear,
2885 * but let's assume so until proven otherwise.
2887 * FIXME should really check all downstream ports...
2889 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2890 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2891 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2894 void intel_dp_sink_set_decompression_state(struct intel_dp *intel_dp,
2895 const struct intel_crtc_state *crtc_state,
2900 if (!crtc_state->dsc_params.compression_enable)
2903 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_DSC_ENABLE,
2904 enable ? DP_DECOMPRESSION_EN : 0);
2906 DRM_DEBUG_KMS("Failed to %s sink decompression state\n",
2907 enable ? "enable" : "disable");
2910 /* If the sink supports it, try to set the power state appropriately */
2911 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
2915 /* Should have a valid DPCD by this point */
2916 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2919 if (mode != DRM_MODE_DPMS_ON) {
2920 if (downstream_hpd_needs_d0(intel_dp))
2923 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2926 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2929 * When turning on, we need to retry for 1ms to give the sink
2932 for (i = 0; i < 3; i++) {
2933 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2940 if (ret == 1 && lspcon->active)
2941 lspcon_wait_pcon_mode(lspcon);
2945 DRM_DEBUG_KMS("failed to %s sink power state\n",
2946 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
2949 static bool cpt_dp_port_selected(struct drm_i915_private *dev_priv,
2950 enum port port, enum pipe *pipe)
2954 for_each_pipe(dev_priv, p) {
2955 u32 val = I915_READ(TRANS_DP_CTL(p));
2957 if ((val & TRANS_DP_PORT_SEL_MASK) == TRANS_DP_PORT_SEL(port)) {
2963 DRM_DEBUG_KMS("No pipe for DP port %c found\n", port_name(port));
2965 /* must initialize pipe to something for the asserts */
2971 bool intel_dp_port_enabled(struct drm_i915_private *dev_priv,
2972 i915_reg_t dp_reg, enum port port,
2978 val = I915_READ(dp_reg);
2980 ret = val & DP_PORT_EN;
2982 /* asserts want to know the pipe even if the port is disabled */
2983 if (IS_IVYBRIDGE(dev_priv) && port == PORT_A)
2984 *pipe = (val & DP_PIPE_SEL_MASK_IVB) >> DP_PIPE_SEL_SHIFT_IVB;
2985 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
2986 ret &= cpt_dp_port_selected(dev_priv, port, pipe);
2987 else if (IS_CHERRYVIEW(dev_priv))
2988 *pipe = (val & DP_PIPE_SEL_MASK_CHV) >> DP_PIPE_SEL_SHIFT_CHV;
2990 *pipe = (val & DP_PIPE_SEL_MASK) >> DP_PIPE_SEL_SHIFT;
2995 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2998 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2999 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3000 intel_wakeref_t wakeref;
3003 wakeref = intel_display_power_get_if_enabled(dev_priv,
3004 encoder->power_domain);
3008 ret = intel_dp_port_enabled(dev_priv, intel_dp->output_reg,
3009 encoder->port, pipe);
3011 intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
3016 static void intel_dp_get_config(struct intel_encoder *encoder,
3017 struct intel_crtc_state *pipe_config)
3019 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3020 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3022 enum port port = encoder->port;
3023 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
3025 if (encoder->type == INTEL_OUTPUT_EDP)
3026 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
3028 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
3030 tmp = I915_READ(intel_dp->output_reg);
3032 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
3034 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
3035 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
3037 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
3038 flags |= DRM_MODE_FLAG_PHSYNC;
3040 flags |= DRM_MODE_FLAG_NHSYNC;
3042 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
3043 flags |= DRM_MODE_FLAG_PVSYNC;
3045 flags |= DRM_MODE_FLAG_NVSYNC;
3047 if (tmp & DP_SYNC_HS_HIGH)
3048 flags |= DRM_MODE_FLAG_PHSYNC;
3050 flags |= DRM_MODE_FLAG_NHSYNC;
3052 if (tmp & DP_SYNC_VS_HIGH)
3053 flags |= DRM_MODE_FLAG_PVSYNC;
3055 flags |= DRM_MODE_FLAG_NVSYNC;
3058 pipe_config->base.adjusted_mode.flags |= flags;
3060 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
3061 pipe_config->limited_color_range = true;
3063 pipe_config->lane_count =
3064 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
3066 intel_dp_get_m_n(crtc, pipe_config);
3068 if (port == PORT_A) {
3069 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
3070 pipe_config->port_clock = 162000;
3072 pipe_config->port_clock = 270000;
3075 pipe_config->base.adjusted_mode.crtc_clock =
3076 intel_dotclock_calculate(pipe_config->port_clock,
3077 &pipe_config->dp_m_n);
3079 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
3080 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
3082 * This is a big fat ugly hack.
3084 * Some machines in UEFI boot mode provide us a VBT that has 18
3085 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
3086 * unknown we fail to light up. Yet the same BIOS boots up with
3087 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
3088 * max, not what it tells us to use.
3090 * Note: This will still be broken if the eDP panel is not lit
3091 * up by the BIOS, and thus we can't get the mode at module
3094 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
3095 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
3096 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
3100 static void intel_disable_dp(struct intel_encoder *encoder,
3101 const struct intel_crtc_state *old_crtc_state,
3102 const struct drm_connector_state *old_conn_state)
3104 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3106 intel_dp->link_trained = false;
3108 if (old_crtc_state->has_audio)
3109 intel_audio_codec_disable(encoder,
3110 old_crtc_state, old_conn_state);
3112 /* Make sure the panel is off before trying to change the mode. But also
3113 * ensure that we have vdd while we switch off the panel. */
3114 intel_edp_panel_vdd_on(intel_dp);
3115 intel_edp_backlight_off(old_conn_state);
3116 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
3117 intel_edp_panel_off(intel_dp);
3120 static void g4x_disable_dp(struct intel_encoder *encoder,
3121 const struct intel_crtc_state *old_crtc_state,
3122 const struct drm_connector_state *old_conn_state)
3124 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
3127 static void vlv_disable_dp(struct intel_encoder *encoder,
3128 const struct intel_crtc_state *old_crtc_state,
3129 const struct drm_connector_state *old_conn_state)
3131 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
3134 static void g4x_post_disable_dp(struct intel_encoder *encoder,
3135 const struct intel_crtc_state *old_crtc_state,
3136 const struct drm_connector_state *old_conn_state)
3138 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3139 enum port port = encoder->port;
3142 * Bspec does not list a specific disable sequence for g4x DP.
3143 * Follow the ilk+ sequence (disable pipe before the port) for
3144 * g4x DP as it does not suffer from underruns like the normal
3145 * g4x modeset sequence (disable pipe after the port).
3147 intel_dp_link_down(encoder, old_crtc_state);
3149 /* Only ilk+ has port A */
3151 ironlake_edp_pll_off(intel_dp, old_crtc_state);
3154 static void vlv_post_disable_dp(struct intel_encoder *encoder,
3155 const struct intel_crtc_state *old_crtc_state,
3156 const struct drm_connector_state *old_conn_state)
3158 intel_dp_link_down(encoder, old_crtc_state);
3161 static void chv_post_disable_dp(struct intel_encoder *encoder,
3162 const struct intel_crtc_state *old_crtc_state,
3163 const struct drm_connector_state *old_conn_state)
3165 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3167 intel_dp_link_down(encoder, old_crtc_state);
3169 vlv_dpio_get(dev_priv);
3171 /* Assert data lane reset */
3172 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
3174 vlv_dpio_put(dev_priv);
3178 _intel_dp_set_link_train(struct intel_dp *intel_dp,
3182 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3183 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3184 enum port port = intel_dig_port->base.port;
3185 u8 train_pat_mask = drm_dp_training_pattern_mask(intel_dp->dpcd);
3187 if (dp_train_pat & train_pat_mask)
3188 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
3189 dp_train_pat & train_pat_mask);
3191 if (HAS_DDI(dev_priv)) {
3192 u32 temp = I915_READ(DP_TP_CTL(port));
3194 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
3195 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
3197 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
3199 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3200 switch (dp_train_pat & train_pat_mask) {
3201 case DP_TRAINING_PATTERN_DISABLE:
3202 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
3205 case DP_TRAINING_PATTERN_1:
3206 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
3208 case DP_TRAINING_PATTERN_2:
3209 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
3211 case DP_TRAINING_PATTERN_3:
3212 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
3214 case DP_TRAINING_PATTERN_4:
3215 temp |= DP_TP_CTL_LINK_TRAIN_PAT4;
3218 I915_WRITE(DP_TP_CTL(port), temp);
3220 } else if ((IS_IVYBRIDGE(dev_priv) && port == PORT_A) ||
3221 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
3222 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
3224 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
3225 case DP_TRAINING_PATTERN_DISABLE:
3226 *DP |= DP_LINK_TRAIN_OFF_CPT;
3228 case DP_TRAINING_PATTERN_1:
3229 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
3231 case DP_TRAINING_PATTERN_2:
3232 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
3234 case DP_TRAINING_PATTERN_3:
3235 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
3236 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
3241 *DP &= ~DP_LINK_TRAIN_MASK;
3243 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
3244 case DP_TRAINING_PATTERN_DISABLE:
3245 *DP |= DP_LINK_TRAIN_OFF;
3247 case DP_TRAINING_PATTERN_1:
3248 *DP |= DP_LINK_TRAIN_PAT_1;
3250 case DP_TRAINING_PATTERN_2:
3251 *DP |= DP_LINK_TRAIN_PAT_2;
3253 case DP_TRAINING_PATTERN_3:
3254 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
3255 *DP |= DP_LINK_TRAIN_PAT_2;
3261 static void intel_dp_enable_port(struct intel_dp *intel_dp,
3262 const struct intel_crtc_state *old_crtc_state)
3264 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3266 /* enable with pattern 1 (as per spec) */
3268 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
3271 * Magic for VLV/CHV. We _must_ first set up the register
3272 * without actually enabling the port, and then do another
3273 * write to enable the port. Otherwise link training will
3274 * fail when the power sequencer is freshly used for this port.
3276 intel_dp->DP |= DP_PORT_EN;
3277 if (old_crtc_state->has_audio)
3278 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
3280 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3281 POSTING_READ(intel_dp->output_reg);
3284 static void intel_enable_dp(struct intel_encoder *encoder,
3285 const struct intel_crtc_state *pipe_config,
3286 const struct drm_connector_state *conn_state)
3288 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3289 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3290 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
3291 u32 dp_reg = I915_READ(intel_dp->output_reg);
3292 enum pipe pipe = crtc->pipe;
3293 intel_wakeref_t wakeref;
3295 if (WARN_ON(dp_reg & DP_PORT_EN))
3298 with_pps_lock(intel_dp, wakeref) {
3299 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3300 vlv_init_panel_power_sequencer(encoder, pipe_config);
3302 intel_dp_enable_port(intel_dp, pipe_config);
3304 edp_panel_vdd_on(intel_dp);
3305 edp_panel_on(intel_dp);
3306 edp_panel_vdd_off(intel_dp, true);
3309 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3310 unsigned int lane_mask = 0x0;
3312 if (IS_CHERRYVIEW(dev_priv))
3313 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
3315 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
3319 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
3320 intel_dp_start_link_train(intel_dp);
3321 intel_dp_stop_link_train(intel_dp);
3323 if (pipe_config->has_audio) {
3324 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
3326 intel_audio_codec_enable(encoder, pipe_config, conn_state);
3330 static void g4x_enable_dp(struct intel_encoder *encoder,
3331 const struct intel_crtc_state *pipe_config,
3332 const struct drm_connector_state *conn_state)
3334 intel_enable_dp(encoder, pipe_config, conn_state);
3335 intel_edp_backlight_on(pipe_config, conn_state);
3338 static void vlv_enable_dp(struct intel_encoder *encoder,
3339 const struct intel_crtc_state *pipe_config,
3340 const struct drm_connector_state *conn_state)
3342 intel_edp_backlight_on(pipe_config, conn_state);
3345 static void g4x_pre_enable_dp(struct intel_encoder *encoder,
3346 const struct intel_crtc_state *pipe_config,
3347 const struct drm_connector_state *conn_state)
3349 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3350 enum port port = encoder->port;
3352 intel_dp_prepare(encoder, pipe_config);
3354 /* Only ilk+ has port A */
3356 ironlake_edp_pll_on(intel_dp, pipe_config);
3359 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
3361 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3362 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
3363 enum pipe pipe = intel_dp->pps_pipe;
3364 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
3366 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
3368 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
3371 edp_panel_vdd_off_sync(intel_dp);
3374 * VLV seems to get confused when multiple power sequencers
3375 * have the same port selected (even if only one has power/vdd
3376 * enabled). The failure manifests as vlv_wait_port_ready() failing
3377 * CHV on the other hand doesn't seem to mind having the same port
3378 * selected in multiple power sequencers, but let's clear the
3379 * port select always when logically disconnecting a power sequencer
3382 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
3383 pipe_name(pipe), port_name(intel_dig_port->base.port));
3384 I915_WRITE(pp_on_reg, 0);
3385 POSTING_READ(pp_on_reg);
3387 intel_dp->pps_pipe = INVALID_PIPE;
3390 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
3393 struct intel_encoder *encoder;
3395 lockdep_assert_held(&dev_priv->pps_mutex);
3397 for_each_intel_dp(&dev_priv->drm, encoder) {
3398 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3399 enum port port = encoder->port;
3401 WARN(intel_dp->active_pipe == pipe,
3402 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3403 pipe_name(pipe), port_name(port));
3405 if (intel_dp->pps_pipe != pipe)
3408 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
3409 pipe_name(pipe), port_name(port));
3411 /* make sure vdd is off before we steal it */
3412 vlv_detach_power_sequencer(intel_dp);
3416 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
3417 const struct intel_crtc_state *crtc_state)
3419 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3420 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3421 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3423 lockdep_assert_held(&dev_priv->pps_mutex);
3425 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
3427 if (intel_dp->pps_pipe != INVALID_PIPE &&
3428 intel_dp->pps_pipe != crtc->pipe) {
3430 * If another power sequencer was being used on this
3431 * port previously make sure to turn off vdd there while
3432 * we still have control of it.
3434 vlv_detach_power_sequencer(intel_dp);
3438 * We may be stealing the power
3439 * sequencer from another port.
3441 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
3443 intel_dp->active_pipe = crtc->pipe;
3445 if (!intel_dp_is_edp(intel_dp))
3448 /* now it's all ours */
3449 intel_dp->pps_pipe = crtc->pipe;
3451 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3452 pipe_name(intel_dp->pps_pipe), port_name(encoder->port));
3454 /* init power sequencer on this pipe and port */
3455 intel_dp_init_panel_power_sequencer(intel_dp);
3456 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
3459 static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3460 const struct intel_crtc_state *pipe_config,
3461 const struct drm_connector_state *conn_state)
3463 vlv_phy_pre_encoder_enable(encoder, pipe_config);
3465 intel_enable_dp(encoder, pipe_config, conn_state);
3468 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3469 const struct intel_crtc_state *pipe_config,
3470 const struct drm_connector_state *conn_state)
3472 intel_dp_prepare(encoder, pipe_config);
3474 vlv_phy_pre_pll_enable(encoder, pipe_config);
3477 static void chv_pre_enable_dp(struct intel_encoder *encoder,
3478 const struct intel_crtc_state *pipe_config,
3479 const struct drm_connector_state *conn_state)
3481 chv_phy_pre_encoder_enable(encoder, pipe_config);
3483 intel_enable_dp(encoder, pipe_config, conn_state);
3485 /* Second common lane will stay alive on its own now */
3486 chv_phy_release_cl2_override(encoder);
3489 static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3490 const struct intel_crtc_state *pipe_config,
3491 const struct drm_connector_state *conn_state)
3493 intel_dp_prepare(encoder, pipe_config);
3495 chv_phy_pre_pll_enable(encoder, pipe_config);
3498 static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3499 const struct intel_crtc_state *old_crtc_state,
3500 const struct drm_connector_state *old_conn_state)
3502 chv_phy_post_pll_disable(encoder, old_crtc_state);
3506 * Fetch AUX CH registers 0x202 - 0x207 which contain
3507 * link status information
3510 intel_dp_get_link_status(struct intel_dp *intel_dp, u8 link_status[DP_LINK_STATUS_SIZE])
3512 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3513 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
3516 /* These are source-specific values. */
3518 intel_dp_voltage_max(struct intel_dp *intel_dp)
3520 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3521 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3522 enum port port = encoder->port;
3524 if (HAS_DDI(dev_priv))
3525 return intel_ddi_dp_voltage_max(encoder);
3526 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3527 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3528 else if (IS_IVYBRIDGE(dev_priv) && port == PORT_A)
3529 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3530 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
3531 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3533 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3537 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, u8 voltage_swing)
3539 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3540 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3541 enum port port = encoder->port;
3543 if (HAS_DDI(dev_priv)) {
3544 return intel_ddi_dp_pre_emphasis_max(encoder, voltage_swing);
3545 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3546 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3547 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3548 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3549 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3550 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3551 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3552 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3553 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3555 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3557 } else if (IS_IVYBRIDGE(dev_priv) && port == PORT_A) {
3558 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3559 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3560 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3561 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3562 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3563 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3565 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3568 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3569 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3570 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3571 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3572 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3573 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3574 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3575 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3577 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3582 static u32 vlv_signal_levels(struct intel_dp *intel_dp)
3584 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3585 unsigned long demph_reg_value, preemph_reg_value,
3586 uniqtranscale_reg_value;
3587 u8 train_set = intel_dp->train_set[0];
3589 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3590 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3591 preemph_reg_value = 0x0004000;
3592 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3593 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3594 demph_reg_value = 0x2B405555;
3595 uniqtranscale_reg_value = 0x552AB83A;
3597 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3598 demph_reg_value = 0x2B404040;
3599 uniqtranscale_reg_value = 0x5548B83A;
3601 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3602 demph_reg_value = 0x2B245555;
3603 uniqtranscale_reg_value = 0x5560B83A;
3605 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3606 demph_reg_value = 0x2B405555;
3607 uniqtranscale_reg_value = 0x5598DA3A;
3613 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3614 preemph_reg_value = 0x0002000;
3615 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3616 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3617 demph_reg_value = 0x2B404040;
3618 uniqtranscale_reg_value = 0x5552B83A;
3620 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3621 demph_reg_value = 0x2B404848;
3622 uniqtranscale_reg_value = 0x5580B83A;
3624 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3625 demph_reg_value = 0x2B404040;
3626 uniqtranscale_reg_value = 0x55ADDA3A;
3632 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3633 preemph_reg_value = 0x0000000;
3634 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3635 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3636 demph_reg_value = 0x2B305555;
3637 uniqtranscale_reg_value = 0x5570B83A;
3639 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3640 demph_reg_value = 0x2B2B4040;
3641 uniqtranscale_reg_value = 0x55ADDA3A;
3647 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3648 preemph_reg_value = 0x0006000;
3649 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3650 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3651 demph_reg_value = 0x1B405555;
3652 uniqtranscale_reg_value = 0x55ADDA3A;
3662 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3663 uniqtranscale_reg_value, 0);
3668 static u32 chv_signal_levels(struct intel_dp *intel_dp)
3670 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3671 u32 deemph_reg_value, margin_reg_value;
3672 bool uniq_trans_scale = false;
3673 u8 train_set = intel_dp->train_set[0];
3675 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3676 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3677 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3678 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3679 deemph_reg_value = 128;
3680 margin_reg_value = 52;
3682 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3683 deemph_reg_value = 128;
3684 margin_reg_value = 77;
3686 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3687 deemph_reg_value = 128;
3688 margin_reg_value = 102;
3690 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3691 deemph_reg_value = 128;
3692 margin_reg_value = 154;
3693 uniq_trans_scale = true;
3699 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3700 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3701 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3702 deemph_reg_value = 85;
3703 margin_reg_value = 78;
3705 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3706 deemph_reg_value = 85;
3707 margin_reg_value = 116;
3709 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3710 deemph_reg_value = 85;
3711 margin_reg_value = 154;
3717 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3718 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3719 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3720 deemph_reg_value = 64;
3721 margin_reg_value = 104;
3723 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3724 deemph_reg_value = 64;
3725 margin_reg_value = 154;
3731 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3732 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3733 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3734 deemph_reg_value = 43;
3735 margin_reg_value = 154;
3745 chv_set_phy_signal_level(encoder, deemph_reg_value,
3746 margin_reg_value, uniq_trans_scale);
3752 g4x_signal_levels(u8 train_set)
3754 u32 signal_levels = 0;
3756 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3757 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3759 signal_levels |= DP_VOLTAGE_0_4;
3761 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3762 signal_levels |= DP_VOLTAGE_0_6;
3764 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3765 signal_levels |= DP_VOLTAGE_0_8;
3767 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3768 signal_levels |= DP_VOLTAGE_1_2;
3771 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3772 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3774 signal_levels |= DP_PRE_EMPHASIS_0;
3776 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3777 signal_levels |= DP_PRE_EMPHASIS_3_5;
3779 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3780 signal_levels |= DP_PRE_EMPHASIS_6;
3782 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3783 signal_levels |= DP_PRE_EMPHASIS_9_5;
3786 return signal_levels;
3789 /* SNB CPU eDP voltage swing and pre-emphasis control */
3791 snb_cpu_edp_signal_levels(u8 train_set)
3793 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3794 DP_TRAIN_PRE_EMPHASIS_MASK);
3795 switch (signal_levels) {
3796 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3797 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3798 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3799 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3800 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
3801 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3802 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3803 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
3804 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3805 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3806 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
3807 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3808 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3809 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
3811 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3812 "0x%x\n", signal_levels);
3813 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3817 /* IVB CPU eDP voltage swing and pre-emphasis control */
3819 ivb_cpu_edp_signal_levels(u8 train_set)
3821 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3822 DP_TRAIN_PRE_EMPHASIS_MASK);
3823 switch (signal_levels) {
3824 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3825 return EDP_LINK_TRAIN_400MV_0DB_IVB;
3826 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3827 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
3828 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3829 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3831 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3832 return EDP_LINK_TRAIN_600MV_0DB_IVB;
3833 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3834 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3836 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3837 return EDP_LINK_TRAIN_800MV_0DB_IVB;
3838 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3839 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3842 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3843 "0x%x\n", signal_levels);
3844 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3849 intel_dp_set_signal_levels(struct intel_dp *intel_dp)
3851 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3852 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3853 enum port port = intel_dig_port->base.port;
3854 u32 signal_levels, mask = 0;
3855 u8 train_set = intel_dp->train_set[0];
3857 if (IS_GEN9_LP(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
3858 signal_levels = bxt_signal_levels(intel_dp);
3859 } else if (HAS_DDI(dev_priv)) {
3860 signal_levels = ddi_signal_levels(intel_dp);
3861 mask = DDI_BUF_EMP_MASK;
3862 } else if (IS_CHERRYVIEW(dev_priv)) {
3863 signal_levels = chv_signal_levels(intel_dp);
3864 } else if (IS_VALLEYVIEW(dev_priv)) {
3865 signal_levels = vlv_signal_levels(intel_dp);
3866 } else if (IS_IVYBRIDGE(dev_priv) && port == PORT_A) {
3867 signal_levels = ivb_cpu_edp_signal_levels(train_set);
3868 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
3869 } else if (IS_GEN(dev_priv, 6) && port == PORT_A) {
3870 signal_levels = snb_cpu_edp_signal_levels(train_set);
3871 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3873 signal_levels = g4x_signal_levels(train_set);
3874 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3878 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3880 DRM_DEBUG_KMS("Using vswing level %d\n",
3881 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3882 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3883 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3884 DP_TRAIN_PRE_EMPHASIS_SHIFT);
3886 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
3888 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3889 POSTING_READ(intel_dp->output_reg);
3893 intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3896 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3897 struct drm_i915_private *dev_priv =
3898 to_i915(intel_dig_port->base.base.dev);
3900 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
3902 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3903 POSTING_READ(intel_dp->output_reg);
3906 void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
3908 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3909 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3910 enum port port = intel_dig_port->base.port;
3913 if (!HAS_DDI(dev_priv))
3916 val = I915_READ(DP_TP_CTL(port));
3917 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3918 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3919 I915_WRITE(DP_TP_CTL(port), val);
3922 * On PORT_A we can have only eDP in SST mode. There the only reason
3923 * we need to set idle transmission mode is to work around a HW issue
3924 * where we enable the pipe while not in idle link-training mode.
3925 * In this case there is requirement to wait for a minimum number of
3926 * idle patterns to be sent.
3931 if (intel_wait_for_register(&dev_priv->uncore, DP_TP_STATUS(port),
3932 DP_TP_STATUS_IDLE_DONE,
3933 DP_TP_STATUS_IDLE_DONE,
3935 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3939 intel_dp_link_down(struct intel_encoder *encoder,
3940 const struct intel_crtc_state *old_crtc_state)
3942 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3943 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3944 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
3945 enum port port = encoder->port;
3946 u32 DP = intel_dp->DP;
3948 if (WARN_ON(HAS_DDI(dev_priv)))
3951 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
3954 DRM_DEBUG_KMS("\n");
3956 if ((IS_IVYBRIDGE(dev_priv) && port == PORT_A) ||
3957 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
3958 DP &= ~DP_LINK_TRAIN_MASK_CPT;
3959 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
3961 DP &= ~DP_LINK_TRAIN_MASK;
3962 DP |= DP_LINK_TRAIN_PAT_IDLE;
3964 I915_WRITE(intel_dp->output_reg, DP);
3965 POSTING_READ(intel_dp->output_reg);
3967 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3968 I915_WRITE(intel_dp->output_reg, DP);
3969 POSTING_READ(intel_dp->output_reg);
3972 * HW workaround for IBX, we need to move the port
3973 * to transcoder A after disabling it to allow the
3974 * matching HDMI port to be enabled on transcoder A.
3976 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
3978 * We get CPU/PCH FIFO underruns on the other pipe when
3979 * doing the workaround. Sweep them under the rug.
3981 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3982 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3984 /* always enable with pattern 1 (as per spec) */
3985 DP &= ~(DP_PIPE_SEL_MASK | DP_LINK_TRAIN_MASK);
3986 DP |= DP_PORT_EN | DP_PIPE_SEL(PIPE_A) |
3987 DP_LINK_TRAIN_PAT_1;
3988 I915_WRITE(intel_dp->output_reg, DP);
3989 POSTING_READ(intel_dp->output_reg);
3992 I915_WRITE(intel_dp->output_reg, DP);
3993 POSTING_READ(intel_dp->output_reg);
3995 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
3996 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3997 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
4000 msleep(intel_dp->panel_power_down_delay);
4004 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
4005 intel_wakeref_t wakeref;
4007 with_pps_lock(intel_dp, wakeref)
4008 intel_dp->active_pipe = INVALID_PIPE;
4013 intel_dp_extended_receiver_capabilities(struct intel_dp *intel_dp)
4018 * Prior to DP1.3 the bit represented by
4019 * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved.
4020 * if it is set DP_DPCD_REV at 0000h could be at a value less than
4021 * the true capability of the panel. The only way to check is to
4022 * then compare 0000h and 2200h.
4024 if (!(intel_dp->dpcd[DP_TRAINING_AUX_RD_INTERVAL] &
4025 DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT))
4028 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DP13_DPCD_REV,
4029 &dpcd_ext, sizeof(dpcd_ext)) != sizeof(dpcd_ext)) {
4030 DRM_ERROR("DPCD failed read at extended capabilities\n");
4034 if (intel_dp->dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) {
4035 DRM_DEBUG_KMS("DPCD extended DPCD rev less than base DPCD rev\n");
4039 if (!memcmp(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext)))
4042 DRM_DEBUG_KMS("Base DPCD: %*ph\n",
4043 (int)sizeof(intel_dp->dpcd), intel_dp->dpcd);
4045 memcpy(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext));
4049 intel_dp_read_dpcd(struct intel_dp *intel_dp)
4051 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
4052 sizeof(intel_dp->dpcd)) < 0)
4053 return false; /* aux transfer failed */
4055 intel_dp_extended_receiver_capabilities(intel_dp);
4057 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
4059 return intel_dp->dpcd[DP_DPCD_REV] != 0;
4062 static void intel_dp_get_dsc_sink_cap(struct intel_dp *intel_dp)
4065 * Clear the cached register set to avoid using stale values
4066 * for the sinks that do not support DSC.
4068 memset(intel_dp->dsc_dpcd, 0, sizeof(intel_dp->dsc_dpcd));
4070 /* Clear fec_capable to avoid using stale values */
4071 intel_dp->fec_capable = 0;
4073 /* Cache the DSC DPCD if eDP or DP rev >= 1.4 */
4074 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x14 ||
4075 intel_dp->edp_dpcd[0] >= DP_EDP_14) {
4076 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DSC_SUPPORT,
4078 sizeof(intel_dp->dsc_dpcd)) < 0)
4079 DRM_ERROR("Failed to read DPCD register 0x%x\n",
4082 DRM_DEBUG_KMS("DSC DPCD: %*ph\n",
4083 (int)sizeof(intel_dp->dsc_dpcd),
4084 intel_dp->dsc_dpcd);
4086 /* FEC is supported only on DP 1.4 */
4087 if (!intel_dp_is_edp(intel_dp) &&
4088 drm_dp_dpcd_readb(&intel_dp->aux, DP_FEC_CAPABILITY,
4089 &intel_dp->fec_capable) < 0)
4090 DRM_ERROR("Failed to read FEC DPCD register\n");
4092 DRM_DEBUG_KMS("FEC CAPABILITY: %x\n", intel_dp->fec_capable);
4097 intel_edp_init_dpcd(struct intel_dp *intel_dp)
4099 struct drm_i915_private *dev_priv =
4100 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
4102 /* this function is meant to be called only once */
4103 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
4105 if (!intel_dp_read_dpcd(intel_dp))
4108 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4109 drm_dp_is_branch(intel_dp->dpcd));
4111 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
4112 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
4113 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
4116 * Read the eDP display control registers.
4118 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
4119 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
4120 * set, but require eDP 1.4+ detection (e.g. for supported link rates
4121 * method). The display control registers should read zero if they're
4122 * not supported anyway.
4124 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
4125 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
4126 sizeof(intel_dp->edp_dpcd))
4127 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
4128 intel_dp->edp_dpcd);
4131 * This has to be called after intel_dp->edp_dpcd is filled, PSR checks
4132 * for SET_POWER_CAPABLE bit in intel_dp->edp_dpcd[1]
4134 intel_psr_init_dpcd(intel_dp);
4136 /* Read the eDP 1.4+ supported link rates. */
4137 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
4138 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
4141 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
4142 sink_rates, sizeof(sink_rates));
4144 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
4145 int val = le16_to_cpu(sink_rates[i]);
4150 /* Value read multiplied by 200kHz gives the per-lane
4151 * link rate in kHz. The source rates are, however,
4152 * stored in terms of LS_Clk kHz. The full conversion
4153 * back to symbols is
4154 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
4156 intel_dp->sink_rates[i] = (val * 200) / 10;
4158 intel_dp->num_sink_rates = i;
4162 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
4163 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
4165 if (intel_dp->num_sink_rates)
4166 intel_dp->use_rate_select = true;
4168 intel_dp_set_sink_rates(intel_dp);
4170 intel_dp_set_common_rates(intel_dp);
4172 /* Read the eDP DSC DPCD registers */
4173 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4174 intel_dp_get_dsc_sink_cap(intel_dp);
4181 intel_dp_get_dpcd(struct intel_dp *intel_dp)
4183 if (!intel_dp_read_dpcd(intel_dp))
4186 /* Don't clobber cached eDP rates. */
4187 if (!intel_dp_is_edp(intel_dp)) {
4188 intel_dp_set_sink_rates(intel_dp);
4189 intel_dp_set_common_rates(intel_dp);
4193 * Some eDP panels do not set a valid value for sink count, that is why
4194 * it don't care about read it here and in intel_edp_init_dpcd().
4196 if (!intel_dp_is_edp(intel_dp)) {
4200 r = drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &count);
4205 * Sink count can change between short pulse hpd hence
4206 * a member variable in intel_dp will track any changes
4207 * between short pulse interrupts.
4209 intel_dp->sink_count = DP_GET_SINK_COUNT(count);
4212 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
4213 * a dongle is present but no display. Unless we require to know
4214 * if a dongle is present or not, we don't need to update
4215 * downstream port information. So, an early return here saves
4216 * time from performing other operations which are not required.
4218 if (!intel_dp->sink_count)
4222 if (!drm_dp_is_branch(intel_dp->dpcd))
4223 return true; /* native DP sink */
4225 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
4226 return true; /* no per-port downstream info */
4228 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
4229 intel_dp->downstream_ports,
4230 DP_MAX_DOWNSTREAM_PORTS) < 0)
4231 return false; /* downstream port status fetch failed */
4237 intel_dp_sink_can_mst(struct intel_dp *intel_dp)
4241 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
4244 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
4247 return mstm_cap & DP_MST_CAP;
4251 intel_dp_can_mst(struct intel_dp *intel_dp)
4253 return i915_modparams.enable_dp_mst &&
4254 intel_dp->can_mst &&
4255 intel_dp_sink_can_mst(intel_dp);
4259 intel_dp_configure_mst(struct intel_dp *intel_dp)
4261 struct intel_encoder *encoder =
4262 &dp_to_dig_port(intel_dp)->base;
4263 bool sink_can_mst = intel_dp_sink_can_mst(intel_dp);
4265 DRM_DEBUG_KMS("MST support? port %c: %s, sink: %s, modparam: %s\n",
4266 port_name(encoder->port), yesno(intel_dp->can_mst),
4267 yesno(sink_can_mst), yesno(i915_modparams.enable_dp_mst));
4269 if (!intel_dp->can_mst)
4272 intel_dp->is_mst = sink_can_mst &&
4273 i915_modparams.enable_dp_mst;
4275 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4280 intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4282 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4283 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4287 u16 intel_dp_dsc_get_output_bpp(int link_clock, u8 lane_count,
4288 int mode_clock, int mode_hdisplay)
4290 u16 bits_per_pixel, max_bpp_small_joiner_ram;
4294 * Available Link Bandwidth(Kbits/sec) = (NumberOfLanes)*
4295 * (LinkSymbolClock)* 8 * ((100-FECOverhead)/100)*(TimeSlotsPerMTP)
4296 * FECOverhead = 2.4%, for SST -> TimeSlotsPerMTP is 1,
4297 * for MST -> TimeSlotsPerMTP has to be calculated
4299 bits_per_pixel = (link_clock * lane_count * 8 *
4300 DP_DSC_FEC_OVERHEAD_FACTOR) /
4303 /* Small Joiner Check: output bpp <= joiner RAM (bits) / Horiz. width */
4304 max_bpp_small_joiner_ram = DP_DSC_MAX_SMALL_JOINER_RAM_BUFFER /
4308 * Greatest allowed DSC BPP = MIN (output BPP from avaialble Link BW
4309 * check, output bpp from small joiner RAM check)
4311 bits_per_pixel = min(bits_per_pixel, max_bpp_small_joiner_ram);
4313 /* Error out if the max bpp is less than smallest allowed valid bpp */
4314 if (bits_per_pixel < valid_dsc_bpp[0]) {
4315 DRM_DEBUG_KMS("Unsupported BPP %d\n", bits_per_pixel);
4319 /* Find the nearest match in the array of known BPPs from VESA */
4320 for (i = 0; i < ARRAY_SIZE(valid_dsc_bpp) - 1; i++) {
4321 if (bits_per_pixel < valid_dsc_bpp[i + 1])
4324 bits_per_pixel = valid_dsc_bpp[i];
4327 * Compressed BPP in U6.4 format so multiply by 16, for Gen 11,
4328 * fractional part is 0
4330 return bits_per_pixel << 4;
4333 u8 intel_dp_dsc_get_slice_count(struct intel_dp *intel_dp,
4337 u8 min_slice_count, i;
4338 int max_slice_width;
4340 if (mode_clock <= DP_DSC_PEAK_PIXEL_RATE)
4341 min_slice_count = DIV_ROUND_UP(mode_clock,
4342 DP_DSC_MAX_ENC_THROUGHPUT_0);
4344 min_slice_count = DIV_ROUND_UP(mode_clock,
4345 DP_DSC_MAX_ENC_THROUGHPUT_1);
4347 max_slice_width = drm_dp_dsc_sink_max_slice_width(intel_dp->dsc_dpcd);
4348 if (max_slice_width < DP_DSC_MIN_SLICE_WIDTH_VALUE) {
4349 DRM_DEBUG_KMS("Unsupported slice width %d by DP DSC Sink device\n",
4353 /* Also take into account max slice width */
4354 min_slice_count = min_t(u8, min_slice_count,
4355 DIV_ROUND_UP(mode_hdisplay,
4358 /* Find the closest match to the valid slice count values */
4359 for (i = 0; i < ARRAY_SIZE(valid_dsc_slicecount); i++) {
4360 if (valid_dsc_slicecount[i] >
4361 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
4364 if (min_slice_count <= valid_dsc_slicecount[i])
4365 return valid_dsc_slicecount[i];
4368 DRM_DEBUG_KMS("Unsupported Slice Count %d\n", min_slice_count);
4372 static u8 intel_dp_autotest_link_training(struct intel_dp *intel_dp)
4376 u8 test_lane_count, test_link_bw;
4380 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4381 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4385 DRM_DEBUG_KMS("Lane count read failed\n");
4388 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
4390 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4393 DRM_DEBUG_KMS("Link Rate read failed\n");
4396 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
4398 /* Validate the requested link rate and lane count */
4399 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4403 intel_dp->compliance.test_lane_count = test_lane_count;
4404 intel_dp->compliance.test_link_rate = test_link_rate;
4409 static u8 intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4413 __be16 h_width, v_height;
4416 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
4417 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4420 DRM_DEBUG_KMS("Test pattern read failed\n");
4423 if (test_pattern != DP_COLOR_RAMP)
4426 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4429 DRM_DEBUG_KMS("H Width read failed\n");
4433 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4436 DRM_DEBUG_KMS("V Height read failed\n");
4440 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4443 DRM_DEBUG_KMS("TEST MISC read failed\n");
4446 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4448 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4450 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4451 case DP_TEST_BIT_DEPTH_6:
4452 intel_dp->compliance.test_data.bpc = 6;
4454 case DP_TEST_BIT_DEPTH_8:
4455 intel_dp->compliance.test_data.bpc = 8;
4461 intel_dp->compliance.test_data.video_pattern = test_pattern;
4462 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4463 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4464 /* Set test active flag here so userspace doesn't interrupt things */
4465 intel_dp->compliance.test_active = 1;
4470 static u8 intel_dp_autotest_edid(struct intel_dp *intel_dp)
4472 u8 test_result = DP_TEST_ACK;
4473 struct intel_connector *intel_connector = intel_dp->attached_connector;
4474 struct drm_connector *connector = &intel_connector->base;
4476 if (intel_connector->detect_edid == NULL ||
4477 connector->edid_corrupt ||
4478 intel_dp->aux.i2c_defer_count > 6) {
4479 /* Check EDID read for NACKs, DEFERs and corruption
4480 * (DP CTS 1.2 Core r1.1)
4481 * 4.2.2.4 : Failed EDID read, I2C_NAK
4482 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4483 * 4.2.2.6 : EDID corruption detected
4484 * Use failsafe mode for all cases
4486 if (intel_dp->aux.i2c_nack_count > 0 ||
4487 intel_dp->aux.i2c_defer_count > 0)
4488 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4489 intel_dp->aux.i2c_nack_count,
4490 intel_dp->aux.i2c_defer_count);
4491 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
4493 struct edid *block = intel_connector->detect_edid;
4495 /* We have to write the checksum
4496 * of the last block read
4498 block += intel_connector->detect_edid->extensions;
4500 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4501 block->checksum) <= 0)
4502 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4504 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
4505 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
4508 /* Set test active flag here so userspace doesn't interrupt things */
4509 intel_dp->compliance.test_active = 1;
4514 static u8 intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4516 u8 test_result = DP_TEST_NAK;
4520 static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4522 u8 response = DP_TEST_NAK;
4526 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
4528 DRM_DEBUG_KMS("Could not read test request from sink\n");
4533 case DP_TEST_LINK_TRAINING:
4534 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
4535 response = intel_dp_autotest_link_training(intel_dp);
4537 case DP_TEST_LINK_VIDEO_PATTERN:
4538 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
4539 response = intel_dp_autotest_video_pattern(intel_dp);
4541 case DP_TEST_LINK_EDID_READ:
4542 DRM_DEBUG_KMS("EDID test requested\n");
4543 response = intel_dp_autotest_edid(intel_dp);
4545 case DP_TEST_LINK_PHY_TEST_PATTERN:
4546 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
4547 response = intel_dp_autotest_phy_pattern(intel_dp);
4550 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
4554 if (response & DP_TEST_ACK)
4555 intel_dp->compliance.test_type = request;
4558 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
4560 DRM_DEBUG_KMS("Could not write test response to sink\n");
4564 intel_dp_check_mst_status(struct intel_dp *intel_dp)
4568 if (intel_dp->is_mst) {
4569 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
4574 WARN_ON_ONCE(intel_dp->active_mst_links < 0);
4575 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4579 /* check link status - esi[10] = 0x200c */
4580 if (intel_dp->active_mst_links > 0 &&
4581 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
4582 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4583 intel_dp_start_link_train(intel_dp);
4584 intel_dp_stop_link_train(intel_dp);
4587 DRM_DEBUG_KMS("got esi %3ph\n", esi);
4588 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4591 for (retry = 0; retry < 3; retry++) {
4593 wret = drm_dp_dpcd_write(&intel_dp->aux,
4594 DP_SINK_COUNT_ESI+1,
4601 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4603 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
4611 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4612 intel_dp->is_mst = false;
4613 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4621 intel_dp_needs_link_retrain(struct intel_dp *intel_dp)
4623 u8 link_status[DP_LINK_STATUS_SIZE];
4625 if (!intel_dp->link_trained)
4629 * While PSR source HW is enabled, it will control main-link sending
4630 * frames, enabling and disabling it so trying to do a retrain will fail
4631 * as the link would or not be on or it could mix training patterns
4632 * and frame data at the same time causing retrain to fail.
4633 * Also when exiting PSR, HW will retrain the link anyways fixing
4634 * any link status error.
4636 if (intel_psr_enabled(intel_dp))
4639 if (!intel_dp_get_link_status(intel_dp, link_status))
4643 * Validate the cached values of intel_dp->link_rate and
4644 * intel_dp->lane_count before attempting to retrain.
4646 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4647 intel_dp->lane_count))
4650 /* Retrain if Channel EQ or CR not ok */
4651 return !drm_dp_channel_eq_ok(link_status, intel_dp->lane_count);
4654 int intel_dp_retrain_link(struct intel_encoder *encoder,
4655 struct drm_modeset_acquire_ctx *ctx)
4657 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4658 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
4659 struct intel_connector *connector = intel_dp->attached_connector;
4660 struct drm_connector_state *conn_state;
4661 struct intel_crtc_state *crtc_state;
4662 struct intel_crtc *crtc;
4665 /* FIXME handle the MST connectors as well */
4667 if (!connector || connector->base.status != connector_status_connected)
4670 ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex,
4675 conn_state = connector->base.state;
4677 crtc = to_intel_crtc(conn_state->crtc);
4681 ret = drm_modeset_lock(&crtc->base.mutex, ctx);
4685 crtc_state = to_intel_crtc_state(crtc->base.state);
4687 WARN_ON(!intel_crtc_has_dp_encoder(crtc_state));
4689 if (!crtc_state->base.active)
4692 if (conn_state->commit &&
4693 !try_wait_for_completion(&conn_state->commit->hw_done))
4696 if (!intel_dp_needs_link_retrain(intel_dp))
4699 /* Suppress underruns caused by re-training */
4700 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4701 if (crtc_state->has_pch_encoder)
4702 intel_set_pch_fifo_underrun_reporting(dev_priv,
4703 intel_crtc_pch_transcoder(crtc), false);
4705 intel_dp_start_link_train(intel_dp);
4706 intel_dp_stop_link_train(intel_dp);
4708 /* Keep underrun reporting disabled until things are stable */
4709 intel_wait_for_vblank(dev_priv, crtc->pipe);
4711 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4712 if (crtc_state->has_pch_encoder)
4713 intel_set_pch_fifo_underrun_reporting(dev_priv,
4714 intel_crtc_pch_transcoder(crtc), true);
4720 * If display is now connected check links status,
4721 * there has been known issues of link loss triggering
4724 * Some sinks (eg. ASUS PB287Q) seem to perform some
4725 * weird HPD ping pong during modesets. So we can apparently
4726 * end up with HPD going low during a modeset, and then
4727 * going back up soon after. And once that happens we must
4728 * retrain the link to get a picture. That's in case no
4729 * userspace component reacted to intermittent HPD dip.
4731 static bool intel_dp_hotplug(struct intel_encoder *encoder,
4732 struct intel_connector *connector)
4734 struct drm_modeset_acquire_ctx ctx;
4738 changed = intel_encoder_hotplug(encoder, connector);
4740 drm_modeset_acquire_init(&ctx, 0);
4743 ret = intel_dp_retrain_link(encoder, &ctx);
4745 if (ret == -EDEADLK) {
4746 drm_modeset_backoff(&ctx);
4753 drm_modeset_drop_locks(&ctx);
4754 drm_modeset_acquire_fini(&ctx);
4755 WARN(ret, "Acquiring modeset locks failed with %i\n", ret);
4760 static void intel_dp_check_service_irq(struct intel_dp *intel_dp)
4764 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
4767 if (drm_dp_dpcd_readb(&intel_dp->aux,
4768 DP_DEVICE_SERVICE_IRQ_VECTOR, &val) != 1 || !val)
4771 drm_dp_dpcd_writeb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR, val);
4773 if (val & DP_AUTOMATED_TEST_REQUEST)
4774 intel_dp_handle_test_request(intel_dp);
4776 if (val & DP_CP_IRQ)
4777 intel_hdcp_handle_cp_irq(intel_dp->attached_connector);
4779 if (val & DP_SINK_SPECIFIC_IRQ)
4780 DRM_DEBUG_DRIVER("Sink specific irq unhandled\n");
4784 * According to DP spec
4787 * 2. Configure link according to Receiver Capabilities
4788 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4789 * 4. Check link status on receipt of hot-plug interrupt
4791 * intel_dp_short_pulse - handles short pulse interrupts
4792 * when full detection is not required.
4793 * Returns %true if short pulse is handled and full detection
4794 * is NOT required and %false otherwise.
4797 intel_dp_short_pulse(struct intel_dp *intel_dp)
4799 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
4800 u8 old_sink_count = intel_dp->sink_count;
4804 * Clearing compliance test variables to allow capturing
4805 * of values for next automated test request.
4807 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
4810 * Now read the DPCD to see if it's actually running
4811 * If the current value of sink count doesn't match with
4812 * the value that was stored earlier or dpcd read failed
4813 * we need to do full detection
4815 ret = intel_dp_get_dpcd(intel_dp);
4817 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4818 /* No need to proceed if we are going to do full detect */
4822 intel_dp_check_service_irq(intel_dp);
4824 /* Handle CEC interrupts, if any */
4825 drm_dp_cec_irq(&intel_dp->aux);
4827 /* defer to the hotplug work for link retraining if needed */
4828 if (intel_dp_needs_link_retrain(intel_dp))
4831 intel_psr_short_pulse(intel_dp);
4833 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4834 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4835 /* Send a Hotplug Uevent to userspace to start modeset */
4836 drm_kms_helper_hotplug_event(&dev_priv->drm);
4842 /* XXX this is probably wrong for multiple downstream ports */
4843 static enum drm_connector_status
4844 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
4846 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
4847 u8 *dpcd = intel_dp->dpcd;
4850 if (WARN_ON(intel_dp_is_edp(intel_dp)))
4851 return connector_status_connected;
4854 lspcon_resume(lspcon);
4856 if (!intel_dp_get_dpcd(intel_dp))
4857 return connector_status_disconnected;
4859 /* if there's no downstream port, we're done */
4860 if (!drm_dp_is_branch(dpcd))
4861 return connector_status_connected;
4863 /* If we're HPD-aware, SINK_COUNT changes dynamically */
4864 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4865 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
4867 return intel_dp->sink_count ?
4868 connector_status_connected : connector_status_disconnected;
4871 if (intel_dp_can_mst(intel_dp))
4872 return connector_status_connected;
4874 /* If no HPD, poke DDC gently */
4875 if (drm_probe_ddc(&intel_dp->aux.ddc))
4876 return connector_status_connected;
4878 /* Well we tried, say unknown for unreliable port types */
4879 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4880 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4881 if (type == DP_DS_PORT_TYPE_VGA ||
4882 type == DP_DS_PORT_TYPE_NON_EDID)
4883 return connector_status_unknown;
4885 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4886 DP_DWN_STRM_PORT_TYPE_MASK;
4887 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4888 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4889 return connector_status_unknown;
4892 /* Anything else is out of spec, warn and ignore */
4893 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
4894 return connector_status_disconnected;
4897 static enum drm_connector_status
4898 edp_detect(struct intel_dp *intel_dp)
4900 return connector_status_connected;
4903 static bool ibx_digital_port_connected(struct intel_encoder *encoder)
4905 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4908 switch (encoder->hpd_pin) {
4910 bit = SDE_PORTB_HOTPLUG;
4913 bit = SDE_PORTC_HOTPLUG;
4916 bit = SDE_PORTD_HOTPLUG;
4919 MISSING_CASE(encoder->hpd_pin);
4923 return I915_READ(SDEISR) & bit;
4926 static bool cpt_digital_port_connected(struct intel_encoder *encoder)
4928 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4931 switch (encoder->hpd_pin) {
4933 bit = SDE_PORTB_HOTPLUG_CPT;
4936 bit = SDE_PORTC_HOTPLUG_CPT;
4939 bit = SDE_PORTD_HOTPLUG_CPT;
4942 MISSING_CASE(encoder->hpd_pin);
4946 return I915_READ(SDEISR) & bit;
4949 static bool spt_digital_port_connected(struct intel_encoder *encoder)
4951 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4954 switch (encoder->hpd_pin) {
4956 bit = SDE_PORTA_HOTPLUG_SPT;
4959 bit = SDE_PORTE_HOTPLUG_SPT;
4962 return cpt_digital_port_connected(encoder);
4965 return I915_READ(SDEISR) & bit;
4968 static bool g4x_digital_port_connected(struct intel_encoder *encoder)
4970 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4973 switch (encoder->hpd_pin) {
4975 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4978 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4981 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4984 MISSING_CASE(encoder->hpd_pin);
4988 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4991 static bool gm45_digital_port_connected(struct intel_encoder *encoder)
4993 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4996 switch (encoder->hpd_pin) {
4998 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
5001 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
5004 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
5007 MISSING_CASE(encoder->hpd_pin);
5011 return I915_READ(PORT_HOTPLUG_STAT) & bit;
5014 static bool ilk_digital_port_connected(struct intel_encoder *encoder)
5016 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5018 if (encoder->hpd_pin == HPD_PORT_A)
5019 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
5021 return ibx_digital_port_connected(encoder);
5024 static bool snb_digital_port_connected(struct intel_encoder *encoder)
5026 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5028 if (encoder->hpd_pin == HPD_PORT_A)
5029 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
5031 return cpt_digital_port_connected(encoder);
5034 static bool ivb_digital_port_connected(struct intel_encoder *encoder)
5036 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5038 if (encoder->hpd_pin == HPD_PORT_A)
5039 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
5041 return cpt_digital_port_connected(encoder);
5044 static bool bdw_digital_port_connected(struct intel_encoder *encoder)
5046 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5048 if (encoder->hpd_pin == HPD_PORT_A)
5049 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
5051 return cpt_digital_port_connected(encoder);
5054 static bool bxt_digital_port_connected(struct intel_encoder *encoder)
5056 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5059 switch (encoder->hpd_pin) {
5061 bit = BXT_DE_PORT_HP_DDIA;
5064 bit = BXT_DE_PORT_HP_DDIB;
5067 bit = BXT_DE_PORT_HP_DDIC;
5070 MISSING_CASE(encoder->hpd_pin);
5074 return I915_READ(GEN8_DE_PORT_ISR) & bit;
5077 static bool icl_combo_port_connected(struct drm_i915_private *dev_priv,
5078 struct intel_digital_port *intel_dig_port)
5080 enum port port = intel_dig_port->base.port;
5082 return I915_READ(SDEISR) & SDE_DDI_HOTPLUG_ICP(port);
5085 static const char *tc_type_name(enum tc_port_type type)
5087 static const char * const names[] = {
5088 [TC_PORT_UNKNOWN] = "unknown",
5089 [TC_PORT_LEGACY] = "legacy",
5090 [TC_PORT_TYPEC] = "typec",
5091 [TC_PORT_TBT] = "tbt",
5094 if (WARN_ON(type >= ARRAY_SIZE(names)))
5095 type = TC_PORT_UNKNOWN;
5100 static void icl_update_tc_port_type(struct drm_i915_private *dev_priv,
5101 struct intel_digital_port *intel_dig_port,
5102 bool is_legacy, bool is_typec, bool is_tbt)
5104 enum port port = intel_dig_port->base.port;
5105 enum tc_port_type old_type = intel_dig_port->tc_type;
5107 WARN_ON(is_legacy + is_typec + is_tbt != 1);
5110 intel_dig_port->tc_type = TC_PORT_LEGACY;
5112 intel_dig_port->tc_type = TC_PORT_TYPEC;
5114 intel_dig_port->tc_type = TC_PORT_TBT;
5118 /* Types are not supposed to be changed at runtime. */
5119 WARN_ON(old_type != TC_PORT_UNKNOWN &&
5120 old_type != intel_dig_port->tc_type);
5122 if (old_type != intel_dig_port->tc_type)
5123 DRM_DEBUG_KMS("Port %c has TC type %s\n", port_name(port),
5124 tc_type_name(intel_dig_port->tc_type));
5128 * This function implements the first part of the Connect Flow described by our
5129 * specification, Gen11 TypeC Programming chapter. The rest of the flow (reading
5130 * lanes, EDID, etc) is done as needed in the typical places.
5132 * Unlike the other ports, type-C ports are not available to use as soon as we
5133 * get a hotplug. The type-C PHYs can be shared between multiple controllers:
5134 * display, USB, etc. As a result, handshaking through FIA is required around
5135 * connect and disconnect to cleanly transfer ownership with the controller and
5136 * set the type-C power state.
5138 * We could opt to only do the connect flow when we actually try to use the AUX
5139 * channels or do a modeset, then immediately run the disconnect flow after
5140 * usage, but there are some implications on this for a dynamic environment:
5141 * things may go away or change behind our backs. So for now our driver is
5142 * always trying to acquire ownership of the controller as soon as it gets an
5143 * interrupt (or polls state and sees a port is connected) and only gives it
5144 * back when it sees a disconnect. Implementation of a more fine-grained model
5145 * will require a lot of coordination with user space and thorough testing for
5146 * the extra possible cases.
5148 static bool icl_tc_phy_connect(struct drm_i915_private *dev_priv,
5149 struct intel_digital_port *dig_port)
5151 enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port);
5154 if (dig_port->tc_type != TC_PORT_LEGACY &&
5155 dig_port->tc_type != TC_PORT_TYPEC)
5158 val = I915_READ(PORT_TX_DFLEXDPPMS);
5159 if (!(val & DP_PHY_MODE_STATUS_COMPLETED(tc_port))) {
5160 DRM_DEBUG_KMS("DP PHY for TC port %d not ready\n", tc_port);
5161 WARN_ON(dig_port->tc_legacy_port);
5166 * This function may be called many times in a row without an HPD event
5167 * in between, so try to avoid the write when we can.
5169 val = I915_READ(PORT_TX_DFLEXDPCSSS);
5170 if (!(val & DP_PHY_MODE_STATUS_NOT_SAFE(tc_port))) {
5171 val |= DP_PHY_MODE_STATUS_NOT_SAFE(tc_port);
5172 I915_WRITE(PORT_TX_DFLEXDPCSSS, val);
5176 * Now we have to re-check the live state, in case the port recently
5177 * became disconnected. Not necessary for legacy mode.
5179 if (dig_port->tc_type == TC_PORT_TYPEC &&
5180 !(I915_READ(PORT_TX_DFLEXDPSP) & TC_LIVE_STATE_TC(tc_port))) {
5181 DRM_DEBUG_KMS("TC PHY %d sudden disconnect.\n", tc_port);
5182 icl_tc_phy_disconnect(dev_priv, dig_port);
5190 * See the comment at the connect function. This implements the Disconnect
5193 void icl_tc_phy_disconnect(struct drm_i915_private *dev_priv,
5194 struct intel_digital_port *dig_port)
5196 enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port);
5198 if (dig_port->tc_type == TC_PORT_UNKNOWN)
5202 * TBT disconnection flow is read the live status, what was done in
5205 if (dig_port->tc_type == TC_PORT_TYPEC ||
5206 dig_port->tc_type == TC_PORT_LEGACY) {
5209 val = I915_READ(PORT_TX_DFLEXDPCSSS);
5210 val &= ~DP_PHY_MODE_STATUS_NOT_SAFE(tc_port);
5211 I915_WRITE(PORT_TX_DFLEXDPCSSS, val);
5214 DRM_DEBUG_KMS("Port %c TC type %s disconnected\n",
5215 port_name(dig_port->base.port),
5216 tc_type_name(dig_port->tc_type));
5218 dig_port->tc_type = TC_PORT_UNKNOWN;
5222 * The type-C ports are different because even when they are connected, they may
5223 * not be available/usable by the graphics driver: see the comment on
5224 * icl_tc_phy_connect(). So in our driver instead of adding the additional
5225 * concept of "usable" and make everything check for "connected and usable" we
5226 * define a port as "connected" when it is not only connected, but also when it
5227 * is usable by the rest of the driver. That maintains the old assumption that
5228 * connected ports are usable, and avoids exposing to the users objects they
5231 static bool icl_tc_port_connected(struct drm_i915_private *dev_priv,
5232 struct intel_digital_port *intel_dig_port)
5234 enum port port = intel_dig_port->base.port;
5235 enum tc_port tc_port = intel_port_to_tc(dev_priv, port);
5236 bool is_legacy, is_typec, is_tbt;
5240 * Complain if we got a legacy port HPD, but VBT didn't mark the port as
5241 * legacy. Treat the port as legacy from now on.
5243 if (!intel_dig_port->tc_legacy_port &&
5244 I915_READ(SDEISR) & SDE_TC_HOTPLUG_ICP(tc_port)) {
5245 DRM_ERROR("VBT incorrectly claims port %c is not TypeC legacy\n",
5247 intel_dig_port->tc_legacy_port = true;
5249 is_legacy = intel_dig_port->tc_legacy_port;
5252 * The spec says we shouldn't be using the ISR bits for detecting
5253 * between TC and TBT. We should use DFLEXDPSP.
5255 dpsp = I915_READ(PORT_TX_DFLEXDPSP);
5256 is_typec = dpsp & TC_LIVE_STATE_TC(tc_port);
5257 is_tbt = dpsp & TC_LIVE_STATE_TBT(tc_port);
5259 if (!is_legacy && !is_typec && !is_tbt) {
5260 icl_tc_phy_disconnect(dev_priv, intel_dig_port);
5265 icl_update_tc_port_type(dev_priv, intel_dig_port, is_legacy, is_typec,
5268 if (!icl_tc_phy_connect(dev_priv, intel_dig_port))
5274 static bool icl_digital_port_connected(struct intel_encoder *encoder)
5276 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5277 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
5279 if (intel_port_is_combophy(dev_priv, encoder->port))
5280 return icl_combo_port_connected(dev_priv, dig_port);
5281 else if (intel_port_is_tc(dev_priv, encoder->port))
5282 return icl_tc_port_connected(dev_priv, dig_port);
5284 MISSING_CASE(encoder->hpd_pin);
5290 * intel_digital_port_connected - is the specified port connected?
5291 * @encoder: intel_encoder
5293 * In cases where there's a connector physically connected but it can't be used
5294 * by our hardware we also return false, since the rest of the driver should
5295 * pretty much treat the port as disconnected. This is relevant for type-C
5296 * (starting on ICL) where there's ownership involved.
5298 * Return %true if port is connected, %false otherwise.
5300 static bool __intel_digital_port_connected(struct intel_encoder *encoder)
5302 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5304 if (HAS_GMCH(dev_priv)) {
5305 if (IS_GM45(dev_priv))
5306 return gm45_digital_port_connected(encoder);
5308 return g4x_digital_port_connected(encoder);
5311 if (INTEL_GEN(dev_priv) >= 11)
5312 return icl_digital_port_connected(encoder);
5313 else if (IS_GEN(dev_priv, 10) || IS_GEN9_BC(dev_priv))
5314 return spt_digital_port_connected(encoder);
5315 else if (IS_GEN9_LP(dev_priv))
5316 return bxt_digital_port_connected(encoder);
5317 else if (IS_GEN(dev_priv, 8))
5318 return bdw_digital_port_connected(encoder);
5319 else if (IS_GEN(dev_priv, 7))
5320 return ivb_digital_port_connected(encoder);
5321 else if (IS_GEN(dev_priv, 6))
5322 return snb_digital_port_connected(encoder);
5323 else if (IS_GEN(dev_priv, 5))
5324 return ilk_digital_port_connected(encoder);
5326 MISSING_CASE(INTEL_GEN(dev_priv));
5330 bool intel_digital_port_connected(struct intel_encoder *encoder)
5332 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5333 bool is_connected = false;
5334 intel_wakeref_t wakeref;
5336 with_intel_display_power(dev_priv, POWER_DOMAIN_DISPLAY_CORE, wakeref)
5337 is_connected = __intel_digital_port_connected(encoder);
5339 return is_connected;
5342 static struct edid *
5343 intel_dp_get_edid(struct intel_dp *intel_dp)
5345 struct intel_connector *intel_connector = intel_dp->attached_connector;
5347 /* use cached edid if we have one */
5348 if (intel_connector->edid) {
5350 if (IS_ERR(intel_connector->edid))
5353 return drm_edid_duplicate(intel_connector->edid);
5355 return drm_get_edid(&intel_connector->base,
5356 &intel_dp->aux.ddc);
5360 intel_dp_set_edid(struct intel_dp *intel_dp)
5362 struct intel_connector *intel_connector = intel_dp->attached_connector;
5365 intel_dp_unset_edid(intel_dp);
5366 edid = intel_dp_get_edid(intel_dp);
5367 intel_connector->detect_edid = edid;
5369 intel_dp->has_audio = drm_detect_monitor_audio(edid);
5370 drm_dp_cec_set_edid(&intel_dp->aux, edid);
5374 intel_dp_unset_edid(struct intel_dp *intel_dp)
5376 struct intel_connector *intel_connector = intel_dp->attached_connector;
5378 drm_dp_cec_unset_edid(&intel_dp->aux);
5379 kfree(intel_connector->detect_edid);
5380 intel_connector->detect_edid = NULL;
5382 intel_dp->has_audio = false;
5386 intel_dp_detect(struct drm_connector *connector,
5387 struct drm_modeset_acquire_ctx *ctx,
5390 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5391 struct intel_dp *intel_dp = intel_attached_dp(connector);
5392 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
5393 struct intel_encoder *encoder = &dig_port->base;
5394 enum drm_connector_status status;
5396 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5397 connector->base.id, connector->name);
5398 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
5400 /* Can't disconnect eDP */
5401 if (intel_dp_is_edp(intel_dp))
5402 status = edp_detect(intel_dp);
5403 else if (intel_digital_port_connected(encoder))
5404 status = intel_dp_detect_dpcd(intel_dp);
5406 status = connector_status_disconnected;
5408 if (status == connector_status_disconnected) {
5409 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
5410 memset(intel_dp->dsc_dpcd, 0, sizeof(intel_dp->dsc_dpcd));
5412 if (intel_dp->is_mst) {
5413 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5415 intel_dp->mst_mgr.mst_state);
5416 intel_dp->is_mst = false;
5417 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5424 if (intel_dp->reset_link_params) {
5425 /* Initial max link lane count */
5426 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
5428 /* Initial max link rate */
5429 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
5431 intel_dp->reset_link_params = false;
5434 intel_dp_print_rates(intel_dp);
5436 /* Read DP Sink DSC Cap DPCD regs for DP v1.4 */
5437 if (INTEL_GEN(dev_priv) >= 11)
5438 intel_dp_get_dsc_sink_cap(intel_dp);
5440 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
5441 drm_dp_is_branch(intel_dp->dpcd));
5443 intel_dp_configure_mst(intel_dp);
5445 if (intel_dp->is_mst) {
5447 * If we are in MST mode then this connector
5448 * won't appear connected or have anything
5451 status = connector_status_disconnected;
5456 * Some external monitors do not signal loss of link synchronization
5457 * with an IRQ_HPD, so force a link status check.
5459 if (!intel_dp_is_edp(intel_dp)) {
5462 ret = intel_dp_retrain_link(encoder, ctx);
5468 * Clearing NACK and defer counts to get their exact values
5469 * while reading EDID which are required by Compliance tests
5470 * 4.2.2.4 and 4.2.2.5
5472 intel_dp->aux.i2c_nack_count = 0;
5473 intel_dp->aux.i2c_defer_count = 0;
5475 intel_dp_set_edid(intel_dp);
5476 if (intel_dp_is_edp(intel_dp) ||
5477 to_intel_connector(connector)->detect_edid)
5478 status = connector_status_connected;
5480 intel_dp_check_service_irq(intel_dp);
5483 if (status != connector_status_connected && !intel_dp->is_mst)
5484 intel_dp_unset_edid(intel_dp);
5490 intel_dp_force(struct drm_connector *connector)
5492 struct intel_dp *intel_dp = intel_attached_dp(connector);
5493 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
5494 struct intel_encoder *intel_encoder = &dig_port->base;
5495 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
5496 enum intel_display_power_domain aux_domain =
5497 intel_aux_power_domain(dig_port);
5498 intel_wakeref_t wakeref;
5500 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
5501 connector->base.id, connector->name);
5502 intel_dp_unset_edid(intel_dp);
5504 if (connector->status != connector_status_connected)
5507 wakeref = intel_display_power_get(dev_priv, aux_domain);
5509 intel_dp_set_edid(intel_dp);
5511 intel_display_power_put(dev_priv, aux_domain, wakeref);
5514 static int intel_dp_get_modes(struct drm_connector *connector)
5516 struct intel_connector *intel_connector = to_intel_connector(connector);
5519 edid = intel_connector->detect_edid;
5521 int ret = intel_connector_update_modes(connector, edid);
5526 /* if eDP has no EDID, fall back to fixed mode */
5527 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
5528 intel_connector->panel.fixed_mode) {
5529 struct drm_display_mode *mode;
5531 mode = drm_mode_duplicate(connector->dev,
5532 intel_connector->panel.fixed_mode);
5534 drm_mode_probed_add(connector, mode);
5543 intel_dp_connector_register(struct drm_connector *connector)
5545 struct intel_dp *intel_dp = intel_attached_dp(connector);
5546 struct drm_device *dev = connector->dev;
5549 ret = intel_connector_register(connector);
5553 i915_debugfs_connector_add(connector);
5555 DRM_DEBUG_KMS("registering %s bus for %s\n",
5556 intel_dp->aux.name, connector->kdev->kobj.name);
5558 intel_dp->aux.dev = connector->kdev;
5559 ret = drm_dp_aux_register(&intel_dp->aux);
5561 drm_dp_cec_register_connector(&intel_dp->aux,
5562 connector->name, dev->dev);
5567 intel_dp_connector_unregister(struct drm_connector *connector)
5569 struct intel_dp *intel_dp = intel_attached_dp(connector);
5571 drm_dp_cec_unregister_connector(&intel_dp->aux);
5572 drm_dp_aux_unregister(&intel_dp->aux);
5573 intel_connector_unregister(connector);
5576 void intel_dp_encoder_flush_work(struct drm_encoder *encoder)
5578 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
5579 struct intel_dp *intel_dp = &intel_dig_port->dp;
5581 intel_dp_mst_encoder_cleanup(intel_dig_port);
5582 if (intel_dp_is_edp(intel_dp)) {
5583 intel_wakeref_t wakeref;
5585 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5587 * vdd might still be enabled do to the delayed vdd off.
5588 * Make sure vdd is actually turned off here.
5590 with_pps_lock(intel_dp, wakeref)
5591 edp_panel_vdd_off_sync(intel_dp);
5593 if (intel_dp->edp_notifier.notifier_call) {
5594 unregister_reboot_notifier(&intel_dp->edp_notifier);
5595 intel_dp->edp_notifier.notifier_call = NULL;
5599 intel_dp_aux_fini(intel_dp);
5602 static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
5604 intel_dp_encoder_flush_work(encoder);
5606 drm_encoder_cleanup(encoder);
5607 kfree(enc_to_dig_port(encoder));
5610 void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
5612 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
5613 intel_wakeref_t wakeref;
5615 if (!intel_dp_is_edp(intel_dp))
5619 * vdd might still be enabled do to the delayed vdd off.
5620 * Make sure vdd is actually turned off here.
5622 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5623 with_pps_lock(intel_dp, wakeref)
5624 edp_panel_vdd_off_sync(intel_dp);
5627 static void intel_dp_hdcp_wait_for_cp_irq(struct intel_hdcp *hdcp, int timeout)
5631 #define C (hdcp->cp_irq_count_cached != atomic_read(&hdcp->cp_irq_count))
5632 ret = wait_event_interruptible_timeout(hdcp->cp_irq_queue, C,
5633 msecs_to_jiffies(timeout));
5636 DRM_DEBUG_KMS("Timedout at waiting for CP_IRQ\n");
5640 int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *intel_dig_port,
5643 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_dig_port->base.base);
5644 static const struct drm_dp_aux_msg msg = {
5645 .request = DP_AUX_NATIVE_WRITE,
5646 .address = DP_AUX_HDCP_AKSV,
5647 .size = DRM_HDCP_KSV_LEN,
5649 u8 txbuf[HEADER_SIZE + DRM_HDCP_KSV_LEN] = {}, rxbuf[2], reply = 0;
5653 /* Output An first, that's easy */
5654 dpcd_ret = drm_dp_dpcd_write(&intel_dig_port->dp.aux, DP_AUX_HDCP_AN,
5655 an, DRM_HDCP_AN_LEN);
5656 if (dpcd_ret != DRM_HDCP_AN_LEN) {
5657 DRM_DEBUG_KMS("Failed to write An over DP/AUX (%zd)\n",
5659 return dpcd_ret >= 0 ? -EIO : dpcd_ret;
5663 * Since Aksv is Oh-So-Secret, we can't access it in software. So in
5664 * order to get it on the wire, we need to create the AUX header as if
5665 * we were writing the data, and then tickle the hardware to output the
5666 * data once the header is sent out.
5668 intel_dp_aux_header(txbuf, &msg);
5670 ret = intel_dp_aux_xfer(intel_dp, txbuf, HEADER_SIZE + msg.size,
5671 rxbuf, sizeof(rxbuf),
5672 DP_AUX_CH_CTL_AUX_AKSV_SELECT);
5674 DRM_DEBUG_KMS("Write Aksv over DP/AUX failed (%d)\n", ret);
5676 } else if (ret == 0) {
5677 DRM_DEBUG_KMS("Aksv write over DP/AUX was empty\n");
5681 reply = (rxbuf[0] >> 4) & DP_AUX_NATIVE_REPLY_MASK;
5682 if (reply != DP_AUX_NATIVE_REPLY_ACK) {
5683 DRM_DEBUG_KMS("Aksv write: no DP_AUX_NATIVE_REPLY_ACK %x\n",
5690 static int intel_dp_hdcp_read_bksv(struct intel_digital_port *intel_dig_port,
5694 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BKSV, bksv,
5696 if (ret != DRM_HDCP_KSV_LEN) {
5697 DRM_DEBUG_KMS("Read Bksv from DP/AUX failed (%zd)\n", ret);
5698 return ret >= 0 ? -EIO : ret;
5703 static int intel_dp_hdcp_read_bstatus(struct intel_digital_port *intel_dig_port,
5708 * For some reason the HDMI and DP HDCP specs call this register
5709 * definition by different names. In the HDMI spec, it's called BSTATUS,
5710 * but in DP it's called BINFO.
5712 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BINFO,
5713 bstatus, DRM_HDCP_BSTATUS_LEN);
5714 if (ret != DRM_HDCP_BSTATUS_LEN) {
5715 DRM_DEBUG_KMS("Read bstatus from DP/AUX failed (%zd)\n", ret);
5716 return ret >= 0 ? -EIO : ret;
5722 int intel_dp_hdcp_read_bcaps(struct intel_digital_port *intel_dig_port,
5727 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BCAPS,
5730 DRM_DEBUG_KMS("Read bcaps from DP/AUX failed (%zd)\n", ret);
5731 return ret >= 0 ? -EIO : ret;
5738 int intel_dp_hdcp_repeater_present(struct intel_digital_port *intel_dig_port,
5739 bool *repeater_present)
5744 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
5748 *repeater_present = bcaps & DP_BCAPS_REPEATER_PRESENT;
5753 int intel_dp_hdcp_read_ri_prime(struct intel_digital_port *intel_dig_port,
5757 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_RI_PRIME,
5758 ri_prime, DRM_HDCP_RI_LEN);
5759 if (ret != DRM_HDCP_RI_LEN) {
5760 DRM_DEBUG_KMS("Read Ri' from DP/AUX failed (%zd)\n", ret);
5761 return ret >= 0 ? -EIO : ret;
5767 int intel_dp_hdcp_read_ksv_ready(struct intel_digital_port *intel_dig_port,
5772 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
5775 DRM_DEBUG_KMS("Read bstatus from DP/AUX failed (%zd)\n", ret);
5776 return ret >= 0 ? -EIO : ret;
5778 *ksv_ready = bstatus & DP_BSTATUS_READY;
5783 int intel_dp_hdcp_read_ksv_fifo(struct intel_digital_port *intel_dig_port,
5784 int num_downstream, u8 *ksv_fifo)
5789 /* KSV list is read via 15 byte window (3 entries @ 5 bytes each) */
5790 for (i = 0; i < num_downstream; i += 3) {
5791 size_t len = min(num_downstream - i, 3) * DRM_HDCP_KSV_LEN;
5792 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
5793 DP_AUX_HDCP_KSV_FIFO,
5794 ksv_fifo + i * DRM_HDCP_KSV_LEN,
5797 DRM_DEBUG_KMS("Read ksv[%d] from DP/AUX failed (%zd)\n",
5799 return ret >= 0 ? -EIO : ret;
5806 int intel_dp_hdcp_read_v_prime_part(struct intel_digital_port *intel_dig_port,
5811 if (i >= DRM_HDCP_V_PRIME_NUM_PARTS)
5814 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
5815 DP_AUX_HDCP_V_PRIME(i), part,
5816 DRM_HDCP_V_PRIME_PART_LEN);
5817 if (ret != DRM_HDCP_V_PRIME_PART_LEN) {
5818 DRM_DEBUG_KMS("Read v'[%d] from DP/AUX failed (%zd)\n", i, ret);
5819 return ret >= 0 ? -EIO : ret;
5825 int intel_dp_hdcp_toggle_signalling(struct intel_digital_port *intel_dig_port,
5828 /* Not used for single stream DisplayPort setups */
5833 bool intel_dp_hdcp_check_link(struct intel_digital_port *intel_dig_port)
5838 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
5841 DRM_DEBUG_KMS("Read bstatus from DP/AUX failed (%zd)\n", ret);
5845 return !(bstatus & (DP_BSTATUS_LINK_FAILURE | DP_BSTATUS_REAUTH_REQ));
5849 int intel_dp_hdcp_capable(struct intel_digital_port *intel_dig_port,
5855 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
5859 *hdcp_capable = bcaps & DP_BCAPS_HDCP_CAPABLE;
5863 struct hdcp2_dp_errata_stream_type {
5868 static struct hdcp2_dp_msg_data {
5871 bool msg_detectable;
5873 u32 timeout2; /* Added for non_paired situation */
5874 } hdcp2_msg_data[] = {
5875 {HDCP_2_2_AKE_INIT, DP_HDCP_2_2_AKE_INIT_OFFSET, false, 0, 0},
5876 {HDCP_2_2_AKE_SEND_CERT, DP_HDCP_2_2_AKE_SEND_CERT_OFFSET,
5877 false, HDCP_2_2_CERT_TIMEOUT_MS, 0},
5878 {HDCP_2_2_AKE_NO_STORED_KM, DP_HDCP_2_2_AKE_NO_STORED_KM_OFFSET,
5880 {HDCP_2_2_AKE_STORED_KM, DP_HDCP_2_2_AKE_STORED_KM_OFFSET,
5882 {HDCP_2_2_AKE_SEND_HPRIME, DP_HDCP_2_2_AKE_SEND_HPRIME_OFFSET,
5883 true, HDCP_2_2_HPRIME_PAIRED_TIMEOUT_MS,
5884 HDCP_2_2_HPRIME_NO_PAIRED_TIMEOUT_MS},
5885 {HDCP_2_2_AKE_SEND_PAIRING_INFO,
5886 DP_HDCP_2_2_AKE_SEND_PAIRING_INFO_OFFSET, true,
5887 HDCP_2_2_PAIRING_TIMEOUT_MS, 0},
5888 {HDCP_2_2_LC_INIT, DP_HDCP_2_2_LC_INIT_OFFSET, false, 0, 0},
5889 {HDCP_2_2_LC_SEND_LPRIME, DP_HDCP_2_2_LC_SEND_LPRIME_OFFSET,
5890 false, HDCP_2_2_DP_LPRIME_TIMEOUT_MS, 0},
5891 {HDCP_2_2_SKE_SEND_EKS, DP_HDCP_2_2_SKE_SEND_EKS_OFFSET, false,
5893 {HDCP_2_2_REP_SEND_RECVID_LIST,
5894 DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET, true,
5895 HDCP_2_2_RECVID_LIST_TIMEOUT_MS, 0},
5896 {HDCP_2_2_REP_SEND_ACK, DP_HDCP_2_2_REP_SEND_ACK_OFFSET, false,
5898 {HDCP_2_2_REP_STREAM_MANAGE,
5899 DP_HDCP_2_2_REP_STREAM_MANAGE_OFFSET, false,
5901 {HDCP_2_2_REP_STREAM_READY, DP_HDCP_2_2_REP_STREAM_READY_OFFSET,
5902 false, HDCP_2_2_STREAM_READY_TIMEOUT_MS, 0},
5903 /* local define to shovel this through the write_2_2 interface */
5904 #define HDCP_2_2_ERRATA_DP_STREAM_TYPE 50
5905 {HDCP_2_2_ERRATA_DP_STREAM_TYPE,
5906 DP_HDCP_2_2_REG_STREAM_TYPE_OFFSET, false,
5911 int intel_dp_hdcp2_read_rx_status(struct intel_digital_port *intel_dig_port,
5916 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
5917 DP_HDCP_2_2_REG_RXSTATUS_OFFSET, rx_status,
5918 HDCP_2_2_DP_RXSTATUS_LEN);
5919 if (ret != HDCP_2_2_DP_RXSTATUS_LEN) {
5920 DRM_DEBUG_KMS("Read bstatus from DP/AUX failed (%zd)\n", ret);
5921 return ret >= 0 ? -EIO : ret;
5928 int hdcp2_detect_msg_availability(struct intel_digital_port *intel_dig_port,
5929 u8 msg_id, bool *msg_ready)
5935 ret = intel_dp_hdcp2_read_rx_status(intel_dig_port, &rx_status);
5940 case HDCP_2_2_AKE_SEND_HPRIME:
5941 if (HDCP_2_2_DP_RXSTATUS_H_PRIME(rx_status))
5944 case HDCP_2_2_AKE_SEND_PAIRING_INFO:
5945 if (HDCP_2_2_DP_RXSTATUS_PAIRING(rx_status))
5948 case HDCP_2_2_REP_SEND_RECVID_LIST:
5949 if (HDCP_2_2_DP_RXSTATUS_READY(rx_status))
5953 DRM_ERROR("Unidentified msg_id: %d\n", msg_id);
5961 intel_dp_hdcp2_wait_for_msg(struct intel_digital_port *intel_dig_port,
5962 struct hdcp2_dp_msg_data *hdcp2_msg_data)
5964 struct intel_dp *dp = &intel_dig_port->dp;
5965 struct intel_hdcp *hdcp = &dp->attached_connector->hdcp;
5966 u8 msg_id = hdcp2_msg_data->msg_id;
5968 bool msg_ready = false;
5970 if (msg_id == HDCP_2_2_AKE_SEND_HPRIME && !hdcp->is_paired)
5971 timeout = hdcp2_msg_data->timeout2;
5973 timeout = hdcp2_msg_data->timeout;
5976 * There is no way to detect the CERT, LPRIME and STREAM_READY
5977 * availability. So Wait for timeout and read the msg.
5979 if (!hdcp2_msg_data->msg_detectable) {
5984 * As we want to check the msg availability at timeout, Ignoring
5985 * the timeout at wait for CP_IRQ.
5987 intel_dp_hdcp_wait_for_cp_irq(hdcp, timeout);
5988 ret = hdcp2_detect_msg_availability(intel_dig_port,
5989 msg_id, &msg_ready);
5995 DRM_DEBUG_KMS("msg_id %d, ret %d, timeout(mSec): %d\n",
5996 hdcp2_msg_data->msg_id, ret, timeout);
6001 static struct hdcp2_dp_msg_data *get_hdcp2_dp_msg_data(u8 msg_id)
6005 for (i = 0; i < ARRAY_SIZE(hdcp2_msg_data); i++)
6006 if (hdcp2_msg_data[i].msg_id == msg_id)
6007 return &hdcp2_msg_data[i];
6013 int intel_dp_hdcp2_write_msg(struct intel_digital_port *intel_dig_port,
6014 void *buf, size_t size)
6016 struct intel_dp *dp = &intel_dig_port->dp;
6017 struct intel_hdcp *hdcp = &dp->attached_connector->hdcp;
6018 unsigned int offset;
6020 ssize_t ret, bytes_to_write, len;
6021 struct hdcp2_dp_msg_data *hdcp2_msg_data;
6023 hdcp2_msg_data = get_hdcp2_dp_msg_data(*byte);
6024 if (!hdcp2_msg_data)
6027 offset = hdcp2_msg_data->offset;
6029 /* No msg_id in DP HDCP2.2 msgs */
6030 bytes_to_write = size - 1;
6033 hdcp->cp_irq_count_cached = atomic_read(&hdcp->cp_irq_count);
6035 while (bytes_to_write) {
6036 len = bytes_to_write > DP_AUX_MAX_PAYLOAD_BYTES ?
6037 DP_AUX_MAX_PAYLOAD_BYTES : bytes_to_write;
6039 ret = drm_dp_dpcd_write(&intel_dig_port->dp.aux,
6040 offset, (void *)byte, len);
6044 bytes_to_write -= ret;
6053 ssize_t get_receiver_id_list_size(struct intel_digital_port *intel_dig_port)
6055 u8 rx_info[HDCP_2_2_RXINFO_LEN];
6059 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
6060 DP_HDCP_2_2_REG_RXINFO_OFFSET,
6061 (void *)rx_info, HDCP_2_2_RXINFO_LEN);
6062 if (ret != HDCP_2_2_RXINFO_LEN)
6063 return ret >= 0 ? -EIO : ret;
6065 dev_cnt = (HDCP_2_2_DEV_COUNT_HI(rx_info[0]) << 4 |
6066 HDCP_2_2_DEV_COUNT_LO(rx_info[1]));
6068 if (dev_cnt > HDCP_2_2_MAX_DEVICE_COUNT)
6069 dev_cnt = HDCP_2_2_MAX_DEVICE_COUNT;
6071 ret = sizeof(struct hdcp2_rep_send_receiverid_list) -
6072 HDCP_2_2_RECEIVER_IDS_MAX_LEN +
6073 (dev_cnt * HDCP_2_2_RECEIVER_ID_LEN);
6079 int intel_dp_hdcp2_read_msg(struct intel_digital_port *intel_dig_port,
6080 u8 msg_id, void *buf, size_t size)
6082 unsigned int offset;
6084 ssize_t ret, bytes_to_recv, len;
6085 struct hdcp2_dp_msg_data *hdcp2_msg_data;
6087 hdcp2_msg_data = get_hdcp2_dp_msg_data(msg_id);
6088 if (!hdcp2_msg_data)
6090 offset = hdcp2_msg_data->offset;
6092 ret = intel_dp_hdcp2_wait_for_msg(intel_dig_port, hdcp2_msg_data);
6096 if (msg_id == HDCP_2_2_REP_SEND_RECVID_LIST) {
6097 ret = get_receiver_id_list_size(intel_dig_port);
6103 bytes_to_recv = size - 1;
6105 /* DP adaptation msgs has no msg_id */
6108 while (bytes_to_recv) {
6109 len = bytes_to_recv > DP_AUX_MAX_PAYLOAD_BYTES ?
6110 DP_AUX_MAX_PAYLOAD_BYTES : bytes_to_recv;
6112 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, offset,
6115 DRM_DEBUG_KMS("msg_id %d, ret %zd\n", msg_id, ret);
6119 bytes_to_recv -= ret;
6130 int intel_dp_hdcp2_config_stream_type(struct intel_digital_port *intel_dig_port,
6131 bool is_repeater, u8 content_type)
6133 struct hdcp2_dp_errata_stream_type stream_type_msg;
6139 * Errata for DP: As Stream type is used for encryption, Receiver
6140 * should be communicated with stream type for the decryption of the
6142 * Repeater will be communicated with stream type as a part of it's
6143 * auth later in time.
6145 stream_type_msg.msg_id = HDCP_2_2_ERRATA_DP_STREAM_TYPE;
6146 stream_type_msg.stream_type = content_type;
6148 return intel_dp_hdcp2_write_msg(intel_dig_port, &stream_type_msg,
6149 sizeof(stream_type_msg));
6153 int intel_dp_hdcp2_check_link(struct intel_digital_port *intel_dig_port)
6158 ret = intel_dp_hdcp2_read_rx_status(intel_dig_port, &rx_status);
6162 if (HDCP_2_2_DP_RXSTATUS_REAUTH_REQ(rx_status))
6163 ret = HDCP_REAUTH_REQUEST;
6164 else if (HDCP_2_2_DP_RXSTATUS_LINK_FAILED(rx_status))
6165 ret = HDCP_LINK_INTEGRITY_FAILURE;
6166 else if (HDCP_2_2_DP_RXSTATUS_READY(rx_status))
6167 ret = HDCP_TOPOLOGY_CHANGE;
6173 int intel_dp_hdcp2_capable(struct intel_digital_port *intel_dig_port,
6180 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
6181 DP_HDCP_2_2_REG_RX_CAPS_OFFSET,
6182 rx_caps, HDCP_2_2_RXCAPS_LEN);
6183 if (ret != HDCP_2_2_RXCAPS_LEN)
6184 return ret >= 0 ? -EIO : ret;
6186 if (rx_caps[0] == HDCP_2_2_RX_CAPS_VERSION_VAL &&
6187 HDCP_2_2_DP_HDCP_CAPABLE(rx_caps[2]))
6193 static const struct intel_hdcp_shim intel_dp_hdcp_shim = {
6194 .write_an_aksv = intel_dp_hdcp_write_an_aksv,
6195 .read_bksv = intel_dp_hdcp_read_bksv,
6196 .read_bstatus = intel_dp_hdcp_read_bstatus,
6197 .repeater_present = intel_dp_hdcp_repeater_present,
6198 .read_ri_prime = intel_dp_hdcp_read_ri_prime,
6199 .read_ksv_ready = intel_dp_hdcp_read_ksv_ready,
6200 .read_ksv_fifo = intel_dp_hdcp_read_ksv_fifo,
6201 .read_v_prime_part = intel_dp_hdcp_read_v_prime_part,
6202 .toggle_signalling = intel_dp_hdcp_toggle_signalling,
6203 .check_link = intel_dp_hdcp_check_link,
6204 .hdcp_capable = intel_dp_hdcp_capable,
6205 .write_2_2_msg = intel_dp_hdcp2_write_msg,
6206 .read_2_2_msg = intel_dp_hdcp2_read_msg,
6207 .config_stream_type = intel_dp_hdcp2_config_stream_type,
6208 .check_2_2_link = intel_dp_hdcp2_check_link,
6209 .hdcp_2_2_capable = intel_dp_hdcp2_capable,
6210 .protocol = HDCP_PROTOCOL_DP,
6213 static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
6215 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6216 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
6218 lockdep_assert_held(&dev_priv->pps_mutex);
6220 if (!edp_have_panel_vdd(intel_dp))
6224 * The VDD bit needs a power domain reference, so if the bit is
6225 * already enabled when we boot or resume, grab this reference and
6226 * schedule a vdd off, so we don't hold on to the reference
6229 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
6230 intel_display_power_get(dev_priv, intel_aux_power_domain(dig_port));
6232 edp_panel_vdd_schedule_off(intel_dp);
6235 static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
6237 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6238 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
6241 if (intel_dp_port_enabled(dev_priv, intel_dp->output_reg,
6242 encoder->port, &pipe))
6245 return INVALID_PIPE;
6248 void intel_dp_encoder_reset(struct drm_encoder *encoder)
6250 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
6251 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
6252 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
6253 intel_wakeref_t wakeref;
6255 if (!HAS_DDI(dev_priv))
6256 intel_dp->DP = I915_READ(intel_dp->output_reg);
6259 lspcon_resume(lspcon);
6261 intel_dp->reset_link_params = true;
6263 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
6264 !intel_dp_is_edp(intel_dp))
6267 with_pps_lock(intel_dp, wakeref) {
6268 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6269 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6271 if (intel_dp_is_edp(intel_dp)) {
6273 * Reinit the power sequencer, in case BIOS did
6274 * something nasty with it.
6276 intel_dp_pps_init(intel_dp);
6277 intel_edp_panel_vdd_sanitize(intel_dp);
6282 static const struct drm_connector_funcs intel_dp_connector_funcs = {
6283 .force = intel_dp_force,
6284 .fill_modes = drm_helper_probe_single_connector_modes,
6285 .atomic_get_property = intel_digital_connector_atomic_get_property,
6286 .atomic_set_property = intel_digital_connector_atomic_set_property,
6287 .late_register = intel_dp_connector_register,
6288 .early_unregister = intel_dp_connector_unregister,
6289 .destroy = intel_connector_destroy,
6290 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
6291 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
6294 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
6295 .detect_ctx = intel_dp_detect,
6296 .get_modes = intel_dp_get_modes,
6297 .mode_valid = intel_dp_mode_valid,
6298 .atomic_check = intel_digital_connector_atomic_check,
6301 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
6302 .reset = intel_dp_encoder_reset,
6303 .destroy = intel_dp_encoder_destroy,
6307 intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
6309 struct intel_dp *intel_dp = &intel_dig_port->dp;
6311 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
6313 * vdd off can generate a long pulse on eDP which
6314 * would require vdd on to handle it, and thus we
6315 * would end up in an endless cycle of
6316 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
6318 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
6319 port_name(intel_dig_port->base.port));
6323 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
6324 port_name(intel_dig_port->base.port),
6325 long_hpd ? "long" : "short");
6328 intel_dp->reset_link_params = true;
6332 if (intel_dp->is_mst) {
6333 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
6335 * If we were in MST mode, and device is not
6336 * there, get out of MST mode
6338 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
6339 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
6340 intel_dp->is_mst = false;
6341 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
6348 if (!intel_dp->is_mst) {
6351 handled = intel_dp_short_pulse(intel_dp);
6360 /* check the VBT to see whether the eDP is on another port */
6361 bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
6364 * eDP not supported on g4x. so bail out early just
6365 * for a bit extra safety in case the VBT is bonkers.
6367 if (INTEL_GEN(dev_priv) < 5)
6370 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
6373 return intel_bios_is_port_edp(dev_priv, port);
6377 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
6379 struct drm_i915_private *dev_priv = to_i915(connector->dev);
6380 enum port port = dp_to_dig_port(intel_dp)->base.port;
6382 if (!IS_G4X(dev_priv) && port != PORT_A)
6383 intel_attach_force_audio_property(connector);
6385 intel_attach_broadcast_rgb_property(connector);
6386 if (HAS_GMCH(dev_priv))
6387 drm_connector_attach_max_bpc_property(connector, 6, 10);
6388 else if (INTEL_GEN(dev_priv) >= 5)
6389 drm_connector_attach_max_bpc_property(connector, 6, 12);
6391 if (intel_dp_is_edp(intel_dp)) {
6392 u32 allowed_scalers;
6394 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
6395 if (!HAS_GMCH(dev_priv))
6396 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
6398 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
6400 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
6405 static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
6407 intel_dp->panel_power_off_time = ktime_get_boottime();
6408 intel_dp->last_power_on = jiffies;
6409 intel_dp->last_backlight_off = jiffies;
6413 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
6415 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6416 u32 pp_on, pp_off, pp_ctl;
6417 struct pps_registers regs;
6419 intel_pps_get_registers(intel_dp, ®s);
6421 pp_ctl = ironlake_get_pp_control(intel_dp);
6423 /* Ensure PPS is unlocked */
6424 if (!HAS_DDI(dev_priv))
6425 I915_WRITE(regs.pp_ctrl, pp_ctl);
6427 pp_on = I915_READ(regs.pp_on);
6428 pp_off = I915_READ(regs.pp_off);
6430 /* Pull timing values out of registers */
6431 seq->t1_t3 = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, pp_on);
6432 seq->t8 = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, pp_on);
6433 seq->t9 = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, pp_off);
6434 seq->t10 = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, pp_off);
6436 if (i915_mmio_reg_valid(regs.pp_div)) {
6439 pp_div = I915_READ(regs.pp_div);
6441 seq->t11_t12 = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, pp_div) * 1000;
6443 seq->t11_t12 = REG_FIELD_GET(BXT_POWER_CYCLE_DELAY_MASK, pp_ctl) * 1000;
6448 intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
6450 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
6452 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
6456 intel_pps_verify_state(struct intel_dp *intel_dp)
6458 struct edp_power_seq hw;
6459 struct edp_power_seq *sw = &intel_dp->pps_delays;
6461 intel_pps_readout_hw_state(intel_dp, &hw);
6463 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
6464 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
6465 DRM_ERROR("PPS state mismatch\n");
6466 intel_pps_dump_state("sw", sw);
6467 intel_pps_dump_state("hw", &hw);
6472 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp)
6474 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6475 struct edp_power_seq cur, vbt, spec,
6476 *final = &intel_dp->pps_delays;
6478 lockdep_assert_held(&dev_priv->pps_mutex);
6480 /* already initialized? */
6481 if (final->t11_t12 != 0)
6484 intel_pps_readout_hw_state(intel_dp, &cur);
6486 intel_pps_dump_state("cur", &cur);
6488 vbt = dev_priv->vbt.edp.pps;
6489 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
6490 * of 500ms appears to be too short. Ocassionally the panel
6491 * just fails to power back on. Increasing the delay to 800ms
6492 * seems sufficient to avoid this problem.
6494 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
6495 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
6496 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
6499 /* T11_T12 delay is special and actually in units of 100ms, but zero
6500 * based in the hw (so we need to add 100 ms). But the sw vbt
6501 * table multiplies it with 1000 to make it in units of 100usec,
6503 vbt.t11_t12 += 100 * 10;
6505 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
6506 * our hw here, which are all in 100usec. */
6507 spec.t1_t3 = 210 * 10;
6508 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
6509 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
6510 spec.t10 = 500 * 10;
6511 /* This one is special and actually in units of 100ms, but zero
6512 * based in the hw (so we need to add 100 ms). But the sw vbt
6513 * table multiplies it with 1000 to make it in units of 100usec,
6515 spec.t11_t12 = (510 + 100) * 10;
6517 intel_pps_dump_state("vbt", &vbt);
6519 /* Use the max of the register settings and vbt. If both are
6520 * unset, fall back to the spec limits. */
6521 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
6523 max(cur.field, vbt.field))
6524 assign_final(t1_t3);
6528 assign_final(t11_t12);
6531 #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
6532 intel_dp->panel_power_up_delay = get_delay(t1_t3);
6533 intel_dp->backlight_on_delay = get_delay(t8);
6534 intel_dp->backlight_off_delay = get_delay(t9);
6535 intel_dp->panel_power_down_delay = get_delay(t10);
6536 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
6539 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
6540 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
6541 intel_dp->panel_power_cycle_delay);
6543 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
6544 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
6547 * We override the HW backlight delays to 1 because we do manual waits
6548 * on them. For T8, even BSpec recommends doing it. For T9, if we
6549 * don't do this, we'll end up waiting for the backlight off delay
6550 * twice: once when we do the manual sleep, and once when we disable
6551 * the panel and wait for the PP_STATUS bit to become zero.
6557 * HW has only a 100msec granularity for t11_t12 so round it up
6560 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
6564 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
6565 bool force_disable_vdd)
6567 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6568 u32 pp_on, pp_off, port_sel = 0;
6569 int div = dev_priv->rawclk_freq / 1000;
6570 struct pps_registers regs;
6571 enum port port = dp_to_dig_port(intel_dp)->base.port;
6572 const struct edp_power_seq *seq = &intel_dp->pps_delays;
6574 lockdep_assert_held(&dev_priv->pps_mutex);
6576 intel_pps_get_registers(intel_dp, ®s);
6579 * On some VLV machines the BIOS can leave the VDD
6580 * enabled even on power sequencers which aren't
6581 * hooked up to any port. This would mess up the
6582 * power domain tracking the first time we pick
6583 * one of these power sequencers for use since
6584 * edp_panel_vdd_on() would notice that the VDD was
6585 * already on and therefore wouldn't grab the power
6586 * domain reference. Disable VDD first to avoid this.
6587 * This also avoids spuriously turning the VDD on as
6588 * soon as the new power sequencer gets initialized.
6590 if (force_disable_vdd) {
6591 u32 pp = ironlake_get_pp_control(intel_dp);
6593 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
6595 if (pp & EDP_FORCE_VDD)
6596 DRM_DEBUG_KMS("VDD already on, disabling first\n");
6598 pp &= ~EDP_FORCE_VDD;
6600 I915_WRITE(regs.pp_ctrl, pp);
6603 pp_on = REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, seq->t1_t3) |
6604 REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, seq->t8);
6605 pp_off = REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, seq->t9) |
6606 REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, seq->t10);
6608 /* Haswell doesn't have any port selection bits for the panel
6609 * power sequencer any more. */
6610 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
6611 port_sel = PANEL_PORT_SELECT_VLV(port);
6612 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
6615 port_sel = PANEL_PORT_SELECT_DPA;
6618 port_sel = PANEL_PORT_SELECT_DPC;
6621 port_sel = PANEL_PORT_SELECT_DPD;
6631 I915_WRITE(regs.pp_on, pp_on);
6632 I915_WRITE(regs.pp_off, pp_off);
6635 * Compute the divisor for the pp clock, simply match the Bspec formula.
6637 if (i915_mmio_reg_valid(regs.pp_div)) {
6638 I915_WRITE(regs.pp_div,
6639 REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, (100 * div) / 2 - 1) |
6640 REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000)));
6644 pp_ctl = I915_READ(regs.pp_ctrl);
6645 pp_ctl &= ~BXT_POWER_CYCLE_DELAY_MASK;
6646 pp_ctl |= REG_FIELD_PREP(BXT_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000));
6647 I915_WRITE(regs.pp_ctrl, pp_ctl);
6650 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
6651 I915_READ(regs.pp_on),
6652 I915_READ(regs.pp_off),
6653 i915_mmio_reg_valid(regs.pp_div) ?
6654 I915_READ(regs.pp_div) :
6655 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK));
6658 static void intel_dp_pps_init(struct intel_dp *intel_dp)
6660 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6662 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
6663 vlv_initial_power_sequencer_setup(intel_dp);
6665 intel_dp_init_panel_power_sequencer(intel_dp);
6666 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
6671 * intel_dp_set_drrs_state - program registers for RR switch to take effect
6672 * @dev_priv: i915 device
6673 * @crtc_state: a pointer to the active intel_crtc_state
6674 * @refresh_rate: RR to be programmed
6676 * This function gets called when refresh rate (RR) has to be changed from
6677 * one frequency to another. Switches can be between high and low RR
6678 * supported by the panel or to any other RR based on media playback (in
6679 * this case, RR value needs to be passed from user space).
6681 * The caller of this function needs to take a lock on dev_priv->drrs.
6683 static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
6684 const struct intel_crtc_state *crtc_state,
6687 struct intel_encoder *encoder;
6688 struct intel_digital_port *dig_port = NULL;
6689 struct intel_dp *intel_dp = dev_priv->drrs.dp;
6690 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
6691 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
6693 if (refresh_rate <= 0) {
6694 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
6698 if (intel_dp == NULL) {
6699 DRM_DEBUG_KMS("DRRS not supported.\n");
6703 dig_port = dp_to_dig_port(intel_dp);
6704 encoder = &dig_port->base;
6707 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
6711 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
6712 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
6716 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
6718 index = DRRS_LOW_RR;
6720 if (index == dev_priv->drrs.refresh_rate_type) {
6722 "DRRS requested for previously set RR...ignoring\n");
6726 if (!crtc_state->base.active) {
6727 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
6731 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
6734 intel_dp_set_m_n(crtc_state, M1_N1);
6737 intel_dp_set_m_n(crtc_state, M2_N2);
6741 DRM_ERROR("Unsupported refreshrate type\n");
6743 } else if (INTEL_GEN(dev_priv) > 6) {
6744 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
6747 val = I915_READ(reg);
6748 if (index > DRRS_HIGH_RR) {
6749 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6750 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
6752 val |= PIPECONF_EDP_RR_MODE_SWITCH;
6754 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6755 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
6757 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
6759 I915_WRITE(reg, val);
6762 dev_priv->drrs.refresh_rate_type = index;
6764 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
6768 * intel_edp_drrs_enable - init drrs struct if supported
6769 * @intel_dp: DP struct
6770 * @crtc_state: A pointer to the active crtc state.
6772 * Initializes frontbuffer_bits and drrs.dp
6774 void intel_edp_drrs_enable(struct intel_dp *intel_dp,
6775 const struct intel_crtc_state *crtc_state)
6777 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6779 if (!crtc_state->has_drrs) {
6780 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
6784 if (dev_priv->psr.enabled) {
6785 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
6789 mutex_lock(&dev_priv->drrs.mutex);
6790 if (dev_priv->drrs.dp) {
6791 DRM_DEBUG_KMS("DRRS already enabled\n");
6795 dev_priv->drrs.busy_frontbuffer_bits = 0;
6797 dev_priv->drrs.dp = intel_dp;
6800 mutex_unlock(&dev_priv->drrs.mutex);
6804 * intel_edp_drrs_disable - Disable DRRS
6805 * @intel_dp: DP struct
6806 * @old_crtc_state: Pointer to old crtc_state.
6809 void intel_edp_drrs_disable(struct intel_dp *intel_dp,
6810 const struct intel_crtc_state *old_crtc_state)
6812 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
6814 if (!old_crtc_state->has_drrs)
6817 mutex_lock(&dev_priv->drrs.mutex);
6818 if (!dev_priv->drrs.dp) {
6819 mutex_unlock(&dev_priv->drrs.mutex);
6823 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
6824 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
6825 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
6827 dev_priv->drrs.dp = NULL;
6828 mutex_unlock(&dev_priv->drrs.mutex);
6830 cancel_delayed_work_sync(&dev_priv->drrs.work);
6833 static void intel_edp_drrs_downclock_work(struct work_struct *work)
6835 struct drm_i915_private *dev_priv =
6836 container_of(work, typeof(*dev_priv), drrs.work.work);
6837 struct intel_dp *intel_dp;
6839 mutex_lock(&dev_priv->drrs.mutex);
6841 intel_dp = dev_priv->drrs.dp;
6847 * The delayed work can race with an invalidate hence we need to
6851 if (dev_priv->drrs.busy_frontbuffer_bits)
6854 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
6855 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
6857 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
6858 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
6862 mutex_unlock(&dev_priv->drrs.mutex);
6866 * intel_edp_drrs_invalidate - Disable Idleness DRRS
6867 * @dev_priv: i915 device
6868 * @frontbuffer_bits: frontbuffer plane tracking bits
6870 * This function gets called everytime rendering on the given planes start.
6871 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
6873 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
6875 void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
6876 unsigned int frontbuffer_bits)
6878 struct drm_crtc *crtc;
6881 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
6884 cancel_delayed_work(&dev_priv->drrs.work);
6886 mutex_lock(&dev_priv->drrs.mutex);
6887 if (!dev_priv->drrs.dp) {
6888 mutex_unlock(&dev_priv->drrs.mutex);
6892 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
6893 pipe = to_intel_crtc(crtc)->pipe;
6895 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
6896 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
6898 /* invalidate means busy screen hence upclock */
6899 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
6900 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
6901 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
6903 mutex_unlock(&dev_priv->drrs.mutex);
6907 * intel_edp_drrs_flush - Restart Idleness DRRS
6908 * @dev_priv: i915 device
6909 * @frontbuffer_bits: frontbuffer plane tracking bits
6911 * This function gets called every time rendering on the given planes has
6912 * completed or flip on a crtc is completed. So DRRS should be upclocked
6913 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
6914 * if no other planes are dirty.
6916 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
6918 void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
6919 unsigned int frontbuffer_bits)
6921 struct drm_crtc *crtc;
6924 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
6927 cancel_delayed_work(&dev_priv->drrs.work);
6929 mutex_lock(&dev_priv->drrs.mutex);
6930 if (!dev_priv->drrs.dp) {
6931 mutex_unlock(&dev_priv->drrs.mutex);
6935 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
6936 pipe = to_intel_crtc(crtc)->pipe;
6938 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
6939 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
6941 /* flush means busy screen hence upclock */
6942 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
6943 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
6944 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
6947 * flush also means no more activity hence schedule downclock, if all
6948 * other fbs are quiescent too
6950 if (!dev_priv->drrs.busy_frontbuffer_bits)
6951 schedule_delayed_work(&dev_priv->drrs.work,
6952 msecs_to_jiffies(1000));
6953 mutex_unlock(&dev_priv->drrs.mutex);
6957 * DOC: Display Refresh Rate Switching (DRRS)
6959 * Display Refresh Rate Switching (DRRS) is a power conservation feature
6960 * which enables swtching between low and high refresh rates,
6961 * dynamically, based on the usage scenario. This feature is applicable
6962 * for internal panels.
6964 * Indication that the panel supports DRRS is given by the panel EDID, which
6965 * would list multiple refresh rates for one resolution.
6967 * DRRS is of 2 types - static and seamless.
6968 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
6969 * (may appear as a blink on screen) and is used in dock-undock scenario.
6970 * Seamless DRRS involves changing RR without any visual effect to the user
6971 * and can be used during normal system usage. This is done by programming
6972 * certain registers.
6974 * Support for static/seamless DRRS may be indicated in the VBT based on
6975 * inputs from the panel spec.
6977 * DRRS saves power by switching to low RR based on usage scenarios.
6979 * The implementation is based on frontbuffer tracking implementation. When
6980 * there is a disturbance on the screen triggered by user activity or a periodic
6981 * system activity, DRRS is disabled (RR is changed to high RR). When there is
6982 * no movement on screen, after a timeout of 1 second, a switch to low RR is
6985 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
6986 * and intel_edp_drrs_flush() are called.
6988 * DRRS can be further extended to support other internal panels and also
6989 * the scenario of video playback wherein RR is set based on the rate
6990 * requested by userspace.
6994 * intel_dp_drrs_init - Init basic DRRS work and mutex.
6995 * @connector: eDP connector
6996 * @fixed_mode: preferred mode of panel
6998 * This function is called only once at driver load to initialize basic
7002 * Downclock mode if panel supports it, else return NULL.
7003 * DRRS support is determined by the presence of downclock mode (apart
7004 * from VBT setting).
7006 static struct drm_display_mode *
7007 intel_dp_drrs_init(struct intel_connector *connector,
7008 struct drm_display_mode *fixed_mode)
7010 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
7011 struct drm_display_mode *downclock_mode = NULL;
7013 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
7014 mutex_init(&dev_priv->drrs.mutex);
7016 if (INTEL_GEN(dev_priv) <= 6) {
7017 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
7021 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
7022 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
7026 downclock_mode = intel_panel_edid_downclock_mode(connector, fixed_mode);
7027 if (!downclock_mode) {
7028 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
7032 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
7034 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
7035 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
7036 return downclock_mode;
7039 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
7040 struct intel_connector *intel_connector)
7042 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7043 struct drm_device *dev = &dev_priv->drm;
7044 struct drm_connector *connector = &intel_connector->base;
7045 struct drm_display_mode *fixed_mode = NULL;
7046 struct drm_display_mode *downclock_mode = NULL;
7048 enum pipe pipe = INVALID_PIPE;
7049 intel_wakeref_t wakeref;
7052 if (!intel_dp_is_edp(intel_dp))
7055 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, edp_panel_vdd_work);
7058 * On IBX/CPT we may get here with LVDS already registered. Since the
7059 * driver uses the only internal power sequencer available for both
7060 * eDP and LVDS bail out early in this case to prevent interfering
7061 * with an already powered-on LVDS power sequencer.
7063 if (intel_get_lvds_encoder(dev_priv)) {
7064 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
7065 DRM_INFO("LVDS was detected, not registering eDP\n");
7070 with_pps_lock(intel_dp, wakeref) {
7071 intel_dp_init_panel_power_timestamps(intel_dp);
7072 intel_dp_pps_init(intel_dp);
7073 intel_edp_panel_vdd_sanitize(intel_dp);
7076 /* Cache DPCD and EDID for edp. */
7077 has_dpcd = intel_edp_init_dpcd(intel_dp);
7080 /* if this fails, presume the device is a ghost */
7081 DRM_INFO("failed to retrieve link info, disabling eDP\n");
7085 mutex_lock(&dev->mode_config.mutex);
7086 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
7088 if (drm_add_edid_modes(connector, edid)) {
7089 drm_connector_update_edid_property(connector,
7093 edid = ERR_PTR(-EINVAL);
7096 edid = ERR_PTR(-ENOENT);
7098 intel_connector->edid = edid;
7100 fixed_mode = intel_panel_edid_fixed_mode(intel_connector);
7102 downclock_mode = intel_dp_drrs_init(intel_connector, fixed_mode);
7104 /* fallback to VBT if available for eDP */
7106 fixed_mode = intel_panel_vbt_fixed_mode(intel_connector);
7107 mutex_unlock(&dev->mode_config.mutex);
7109 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7110 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
7111 register_reboot_notifier(&intel_dp->edp_notifier);
7114 * Figure out the current pipe for the initial backlight setup.
7115 * If the current pipe isn't valid, try the PPS pipe, and if that
7116 * fails just assume pipe A.
7118 pipe = vlv_active_pipe(intel_dp);
7120 if (pipe != PIPE_A && pipe != PIPE_B)
7121 pipe = intel_dp->pps_pipe;
7123 if (pipe != PIPE_A && pipe != PIPE_B)
7126 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
7130 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
7131 intel_connector->panel.backlight.power = intel_edp_backlight_power;
7132 intel_panel_setup_backlight(connector, pipe);
7135 drm_connector_init_panel_orientation_property(
7136 connector, fixed_mode->hdisplay, fixed_mode->vdisplay);
7141 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
7143 * vdd might still be enabled do to the delayed vdd off.
7144 * Make sure vdd is actually turned off here.
7146 with_pps_lock(intel_dp, wakeref)
7147 edp_panel_vdd_off_sync(intel_dp);
7152 static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
7154 struct intel_connector *intel_connector;
7155 struct drm_connector *connector;
7157 intel_connector = container_of(work, typeof(*intel_connector),
7158 modeset_retry_work);
7159 connector = &intel_connector->base;
7160 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
7163 /* Grab the locks before changing connector property*/
7164 mutex_lock(&connector->dev->mode_config.mutex);
7165 /* Set connector link status to BAD and send a Uevent to notify
7166 * userspace to do a modeset.
7168 drm_connector_set_link_status_property(connector,
7169 DRM_MODE_LINK_STATUS_BAD);
7170 mutex_unlock(&connector->dev->mode_config.mutex);
7171 /* Send Hotplug uevent so userspace can reprobe */
7172 drm_kms_helper_hotplug_event(connector->dev);
7176 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
7177 struct intel_connector *intel_connector)
7179 struct drm_connector *connector = &intel_connector->base;
7180 struct intel_dp *intel_dp = &intel_dig_port->dp;
7181 struct intel_encoder *intel_encoder = &intel_dig_port->base;
7182 struct drm_device *dev = intel_encoder->base.dev;
7183 struct drm_i915_private *dev_priv = to_i915(dev);
7184 enum port port = intel_encoder->port;
7187 /* Initialize the work for modeset in case of link train failure */
7188 INIT_WORK(&intel_connector->modeset_retry_work,
7189 intel_dp_modeset_retry_work_fn);
7191 if (WARN(intel_dig_port->max_lanes < 1,
7192 "Not enough lanes (%d) for DP on port %c\n",
7193 intel_dig_port->max_lanes, port_name(port)))
7196 intel_dp_set_source_rates(intel_dp);
7198 intel_dp->reset_link_params = true;
7199 intel_dp->pps_pipe = INVALID_PIPE;
7200 intel_dp->active_pipe = INVALID_PIPE;
7202 /* intel_dp vfuncs */
7203 if (HAS_DDI(dev_priv))
7204 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
7206 /* Preserve the current hw state. */
7207 intel_dp->DP = I915_READ(intel_dp->output_reg);
7208 intel_dp->attached_connector = intel_connector;
7210 if (intel_dp_is_port_edp(dev_priv, port)) {
7212 * Currently we don't support eDP on TypeC ports, although in
7213 * theory it could work on TypeC legacy ports.
7215 WARN_ON(intel_port_is_tc(dev_priv, port));
7216 type = DRM_MODE_CONNECTOR_eDP;
7218 type = DRM_MODE_CONNECTOR_DisplayPort;
7221 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
7222 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
7225 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
7226 * for DP the encoder type can be set by the caller to
7227 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
7229 if (type == DRM_MODE_CONNECTOR_eDP)
7230 intel_encoder->type = INTEL_OUTPUT_EDP;
7232 /* eDP only on port B and/or C on vlv/chv */
7233 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7234 intel_dp_is_edp(intel_dp) &&
7235 port != PORT_B && port != PORT_C))
7238 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
7239 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
7242 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
7243 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
7245 if (!HAS_GMCH(dev_priv))
7246 connector->interlace_allowed = true;
7247 connector->doublescan_allowed = 0;
7249 intel_encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port);
7251 intel_dp_aux_init(intel_dp);
7253 intel_connector_attach_encoder(intel_connector, intel_encoder);
7255 if (HAS_DDI(dev_priv))
7256 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
7258 intel_connector->get_hw_state = intel_connector_get_hw_state;
7260 /* init MST on ports that can support it */
7261 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
7262 (port == PORT_B || port == PORT_C ||
7263 port == PORT_D || port == PORT_F))
7264 intel_dp_mst_encoder_init(intel_dig_port,
7265 intel_connector->base.base.id);
7267 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
7268 intel_dp_aux_fini(intel_dp);
7269 intel_dp_mst_encoder_cleanup(intel_dig_port);
7273 intel_dp_add_properties(intel_dp, connector);
7275 if (is_hdcp_supported(dev_priv, port) && !intel_dp_is_edp(intel_dp)) {
7276 int ret = intel_hdcp_init(intel_connector, &intel_dp_hdcp_shim);
7278 DRM_DEBUG_KMS("HDCP init failed, skipping.\n");
7281 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
7282 * 0xd. Failure to do so will result in spurious interrupts being
7283 * generated on the port when a cable is not attached.
7285 if (IS_G45(dev_priv)) {
7286 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
7287 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
7293 drm_connector_cleanup(connector);
7298 bool intel_dp_init(struct drm_i915_private *dev_priv,
7299 i915_reg_t output_reg,
7302 struct intel_digital_port *intel_dig_port;
7303 struct intel_encoder *intel_encoder;
7304 struct drm_encoder *encoder;
7305 struct intel_connector *intel_connector;
7307 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
7308 if (!intel_dig_port)
7311 intel_connector = intel_connector_alloc();
7312 if (!intel_connector)
7313 goto err_connector_alloc;
7315 intel_encoder = &intel_dig_port->base;
7316 encoder = &intel_encoder->base;
7318 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
7319 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
7320 "DP %c", port_name(port)))
7321 goto err_encoder_init;
7323 intel_encoder->hotplug = intel_dp_hotplug;
7324 intel_encoder->compute_config = intel_dp_compute_config;
7325 intel_encoder->get_hw_state = intel_dp_get_hw_state;
7326 intel_encoder->get_config = intel_dp_get_config;
7327 intel_encoder->update_pipe = intel_panel_update_backlight;
7328 intel_encoder->suspend = intel_dp_encoder_suspend;
7329 if (IS_CHERRYVIEW(dev_priv)) {
7330 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
7331 intel_encoder->pre_enable = chv_pre_enable_dp;
7332 intel_encoder->enable = vlv_enable_dp;
7333 intel_encoder->disable = vlv_disable_dp;
7334 intel_encoder->post_disable = chv_post_disable_dp;
7335 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
7336 } else if (IS_VALLEYVIEW(dev_priv)) {
7337 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
7338 intel_encoder->pre_enable = vlv_pre_enable_dp;
7339 intel_encoder->enable = vlv_enable_dp;
7340 intel_encoder->disable = vlv_disable_dp;
7341 intel_encoder->post_disable = vlv_post_disable_dp;
7343 intel_encoder->pre_enable = g4x_pre_enable_dp;
7344 intel_encoder->enable = g4x_enable_dp;
7345 intel_encoder->disable = g4x_disable_dp;
7346 intel_encoder->post_disable = g4x_post_disable_dp;
7349 intel_dig_port->dp.output_reg = output_reg;
7350 intel_dig_port->max_lanes = 4;
7352 intel_encoder->type = INTEL_OUTPUT_DP;
7353 intel_encoder->power_domain = intel_port_to_power_domain(port);
7354 if (IS_CHERRYVIEW(dev_priv)) {
7356 intel_encoder->crtc_mask = 1 << 2;
7358 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
7360 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
7362 intel_encoder->cloneable = 0;
7363 intel_encoder->port = port;
7365 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
7368 intel_infoframe_init(intel_dig_port);
7370 intel_dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port);
7371 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
7372 goto err_init_connector;
7377 drm_encoder_cleanup(encoder);
7379 kfree(intel_connector);
7380 err_connector_alloc:
7381 kfree(intel_dig_port);
7385 void intel_dp_mst_suspend(struct drm_i915_private *dev_priv)
7387 struct intel_encoder *encoder;
7389 for_each_intel_encoder(&dev_priv->drm, encoder) {
7390 struct intel_dp *intel_dp;
7392 if (encoder->type != INTEL_OUTPUT_DDI)
7395 intel_dp = enc_to_intel_dp(&encoder->base);
7397 if (!intel_dp->can_mst)
7400 if (intel_dp->is_mst)
7401 drm_dp_mst_topology_mgr_suspend(&intel_dp->mst_mgr);
7405 void intel_dp_mst_resume(struct drm_i915_private *dev_priv)
7407 struct intel_encoder *encoder;
7409 for_each_intel_encoder(&dev_priv->drm, encoder) {
7410 struct intel_dp *intel_dp;
7413 if (encoder->type != INTEL_OUTPUT_DDI)
7416 intel_dp = enc_to_intel_dp(&encoder->base);
7418 if (!intel_dp->can_mst)
7421 ret = drm_dp_mst_topology_mgr_resume(&intel_dp->mst_mgr);
7423 intel_dp->is_mst = false;
7424 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,