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>
44 #include "i915_debugfs.h"
46 #include "i915_trace.h"
47 #include "intel_atomic.h"
48 #include "intel_audio.h"
49 #include "intel_connector.h"
50 #include "intel_ddi.h"
51 #include "intel_display_types.h"
53 #include "intel_dp_link_training.h"
54 #include "intel_dp_mst.h"
55 #include "intel_dpio_phy.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"
66 #include "intel_vdsc.h"
68 #define DP_DPRX_ESI_LEN 14
70 /* DP DSC throughput values used for slice count calculations KPixels/s */
71 #define DP_DSC_PEAK_PIXEL_RATE 2720000
72 #define DP_DSC_MAX_ENC_THROUGHPUT_0 340000
73 #define DP_DSC_MAX_ENC_THROUGHPUT_1 400000
75 /* DP DSC FEC Overhead factor = 1/(0.972261) */
76 #define DP_DSC_FEC_OVERHEAD_FACTOR 972261
78 /* Compliance test status bits */
79 #define INTEL_DP_RESOLUTION_SHIFT_MASK 0
80 #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
81 #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
82 #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
89 static const struct dp_link_dpll g4x_dpll[] = {
91 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
93 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
96 static const struct dp_link_dpll pch_dpll[] = {
98 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
100 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
103 static const struct dp_link_dpll vlv_dpll[] = {
105 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
107 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
111 * CHV supports eDP 1.4 that have more link rates.
112 * Below only provides the fixed rate but exclude variable rate.
114 static const struct dp_link_dpll chv_dpll[] = {
116 * CHV requires to program fractional division for m2.
117 * m2 is stored in fixed point format using formula below
118 * (m2_int << 22) | m2_fraction
120 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
121 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
122 { 270000, /* m2_int = 27, m2_fraction = 0 */
123 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
126 /* Constants for DP DSC configurations */
127 static const u8 valid_dsc_bpp[] = {6, 8, 10, 12, 15};
129 /* With Single pipe configuration, HW is capable of supporting maximum
130 * of 4 slices per line.
132 static const u8 valid_dsc_slicecount[] = {1, 2, 4};
135 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
136 * @intel_dp: DP struct
138 * If a CPU or PCH DP output is attached to an eDP panel, this function
139 * will return true, and false otherwise.
141 bool intel_dp_is_edp(struct intel_dp *intel_dp)
143 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
145 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
148 static void intel_dp_link_down(struct intel_encoder *encoder,
149 const struct intel_crtc_state *old_crtc_state);
150 static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
151 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
152 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
153 const struct intel_crtc_state *crtc_state);
154 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
156 static void intel_dp_unset_edid(struct intel_dp *intel_dp);
158 /* update sink rates from dpcd */
159 static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
161 static const int dp_rates[] = {
162 162000, 270000, 540000, 810000
166 if (drm_dp_has_quirk(&intel_dp->desc, 0,
167 DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS)) {
168 /* Needed, e.g., for Apple MBP 2017, 15 inch eDP Retina panel */
169 static const int quirk_rates[] = { 162000, 270000, 324000 };
171 memcpy(intel_dp->sink_rates, quirk_rates, sizeof(quirk_rates));
172 intel_dp->num_sink_rates = ARRAY_SIZE(quirk_rates);
177 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]);
179 for (i = 0; i < ARRAY_SIZE(dp_rates); i++) {
180 if (dp_rates[i] > max_rate)
182 intel_dp->sink_rates[i] = dp_rates[i];
185 intel_dp->num_sink_rates = i;
188 /* Get length of rates array potentially limited by max_rate. */
189 static int intel_dp_rate_limit_len(const int *rates, int len, int max_rate)
193 /* Limit results by potentially reduced max rate */
194 for (i = 0; i < len; i++) {
195 if (rates[len - i - 1] <= max_rate)
202 /* Get length of common rates array potentially limited by max_rate. */
203 static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp,
206 return intel_dp_rate_limit_len(intel_dp->common_rates,
207 intel_dp->num_common_rates, max_rate);
210 /* Theoretical max between source and sink */
211 static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
213 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
216 /* Theoretical max between source and sink */
217 static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
219 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
220 int source_max = intel_dig_port->max_lanes;
221 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
222 int fia_max = intel_tc_port_fia_max_lane_count(intel_dig_port);
224 return min3(source_max, sink_max, fia_max);
227 int intel_dp_max_lane_count(struct intel_dp *intel_dp)
229 return intel_dp->max_link_lane_count;
233 intel_dp_link_required(int pixel_clock, int bpp)
235 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
236 return DIV_ROUND_UP(pixel_clock * bpp, 8);
240 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
242 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
243 * link rate that is generally expressed in Gbps. Since, 8 bits of data
244 * is transmitted every LS_Clk per lane, there is no need to account for
245 * the channel encoding that is done in the PHY layer here.
248 return max_link_clock * max_lanes;
252 intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
254 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
255 struct intel_encoder *encoder = &intel_dig_port->base;
256 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
257 int max_dotclk = dev_priv->max_dotclk_freq;
260 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
262 if (type != DP_DS_PORT_TYPE_VGA)
265 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
266 intel_dp->downstream_ports);
268 if (ds_max_dotclk != 0)
269 max_dotclk = min(max_dotclk, ds_max_dotclk);
274 static int cnl_max_source_rate(struct intel_dp *intel_dp)
276 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
277 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
278 enum port port = dig_port->base.port;
280 u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
282 /* Low voltage SKUs are limited to max of 5.4G */
283 if (voltage == VOLTAGE_INFO_0_85V)
286 /* For this SKU 8.1G is supported in all ports */
287 if (IS_CNL_WITH_PORT_F(dev_priv))
290 /* For other SKUs, max rate on ports A and D is 5.4G */
291 if (port == PORT_A || port == PORT_D)
297 static int icl_max_source_rate(struct intel_dp *intel_dp)
299 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
300 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
301 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
303 if (intel_phy_is_combo(dev_priv, phy) &&
304 !IS_ELKHARTLAKE(dev_priv) &&
305 !intel_dp_is_edp(intel_dp))
312 intel_dp_set_source_rates(struct intel_dp *intel_dp)
314 /* The values must be in increasing order */
315 static const int cnl_rates[] = {
316 162000, 216000, 270000, 324000, 432000, 540000, 648000, 810000
318 static const int bxt_rates[] = {
319 162000, 216000, 243000, 270000, 324000, 432000, 540000
321 static const int skl_rates[] = {
322 162000, 216000, 270000, 324000, 432000, 540000
324 static const int hsw_rates[] = {
325 162000, 270000, 540000
327 static const int g4x_rates[] = {
330 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
331 struct intel_encoder *encoder = &dig_port->base;
332 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
333 const int *source_rates;
334 int size, max_rate = 0, vbt_max_rate;
336 /* This should only be done once */
337 drm_WARN_ON(&dev_priv->drm,
338 intel_dp->source_rates || intel_dp->num_source_rates);
340 if (INTEL_GEN(dev_priv) >= 10) {
341 source_rates = cnl_rates;
342 size = ARRAY_SIZE(cnl_rates);
343 if (IS_GEN(dev_priv, 10))
344 max_rate = cnl_max_source_rate(intel_dp);
346 max_rate = icl_max_source_rate(intel_dp);
347 } else if (IS_GEN9_LP(dev_priv)) {
348 source_rates = bxt_rates;
349 size = ARRAY_SIZE(bxt_rates);
350 } else if (IS_GEN9_BC(dev_priv)) {
351 source_rates = skl_rates;
352 size = ARRAY_SIZE(skl_rates);
353 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
354 IS_BROADWELL(dev_priv)) {
355 source_rates = hsw_rates;
356 size = ARRAY_SIZE(hsw_rates);
358 source_rates = g4x_rates;
359 size = ARRAY_SIZE(g4x_rates);
362 vbt_max_rate = intel_bios_dp_max_link_rate(encoder);
363 if (max_rate && vbt_max_rate)
364 max_rate = min(max_rate, vbt_max_rate);
365 else if (vbt_max_rate)
366 max_rate = vbt_max_rate;
369 size = intel_dp_rate_limit_len(source_rates, size, max_rate);
371 intel_dp->source_rates = source_rates;
372 intel_dp->num_source_rates = size;
375 static int intersect_rates(const int *source_rates, int source_len,
376 const int *sink_rates, int sink_len,
379 int i = 0, j = 0, k = 0;
381 while (i < source_len && j < sink_len) {
382 if (source_rates[i] == sink_rates[j]) {
383 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
385 common_rates[k] = source_rates[i];
389 } else if (source_rates[i] < sink_rates[j]) {
398 /* return index of rate in rates array, or -1 if not found */
399 static int intel_dp_rate_index(const int *rates, int len, int rate)
403 for (i = 0; i < len; i++)
404 if (rate == rates[i])
410 static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
412 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
414 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
415 intel_dp->num_source_rates,
416 intel_dp->sink_rates,
417 intel_dp->num_sink_rates,
418 intel_dp->common_rates);
420 /* Paranoia, there should always be something in common. */
421 if (WARN_ON(intel_dp->num_common_rates == 0)) {
422 intel_dp->common_rates[0] = 162000;
423 intel_dp->num_common_rates = 1;
427 static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
431 * FIXME: we need to synchronize the current link parameters with
432 * hardware readout. Currently fast link training doesn't work on
435 if (link_rate == 0 ||
436 link_rate > intel_dp->max_link_rate)
439 if (lane_count == 0 ||
440 lane_count > intel_dp_max_lane_count(intel_dp))
446 static bool intel_dp_can_link_train_fallback_for_edp(struct intel_dp *intel_dp,
450 const struct drm_display_mode *fixed_mode =
451 intel_dp->attached_connector->panel.fixed_mode;
452 int mode_rate, max_rate;
454 mode_rate = intel_dp_link_required(fixed_mode->clock, 18);
455 max_rate = intel_dp_max_data_rate(link_rate, lane_count);
456 if (mode_rate > max_rate)
462 int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
463 int link_rate, u8 lane_count)
465 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
468 index = intel_dp_rate_index(intel_dp->common_rates,
469 intel_dp->num_common_rates,
472 if (intel_dp_is_edp(intel_dp) &&
473 !intel_dp_can_link_train_fallback_for_edp(intel_dp,
474 intel_dp->common_rates[index - 1],
476 drm_dbg_kms(&i915->drm,
477 "Retrying Link training for eDP with same parameters\n");
480 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
481 intel_dp->max_link_lane_count = lane_count;
482 } else if (lane_count > 1) {
483 if (intel_dp_is_edp(intel_dp) &&
484 !intel_dp_can_link_train_fallback_for_edp(intel_dp,
485 intel_dp_max_common_rate(intel_dp),
487 drm_dbg_kms(&i915->drm,
488 "Retrying Link training for eDP with same parameters\n");
491 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
492 intel_dp->max_link_lane_count = lane_count >> 1;
494 drm_err(&i915->drm, "Link Training Unsuccessful\n");
501 u32 intel_dp_mode_to_fec_clock(u32 mode_clock)
503 return div_u64(mul_u32_u32(mode_clock, 1000000U),
504 DP_DSC_FEC_OVERHEAD_FACTOR);
508 small_joiner_ram_size_bits(struct drm_i915_private *i915)
510 if (INTEL_GEN(i915) >= 11)
516 static u16 intel_dp_dsc_get_output_bpp(struct drm_i915_private *i915,
517 u32 link_clock, u32 lane_count,
518 u32 mode_clock, u32 mode_hdisplay)
520 u32 bits_per_pixel, max_bpp_small_joiner_ram;
524 * Available Link Bandwidth(Kbits/sec) = (NumberOfLanes)*
525 * (LinkSymbolClock)* 8 * (TimeSlotsPerMTP)
526 * for SST -> TimeSlotsPerMTP is 1,
527 * for MST -> TimeSlotsPerMTP has to be calculated
529 bits_per_pixel = (link_clock * lane_count * 8) /
530 intel_dp_mode_to_fec_clock(mode_clock);
531 drm_dbg_kms(&i915->drm, "Max link bpp: %u\n", bits_per_pixel);
533 /* Small Joiner Check: output bpp <= joiner RAM (bits) / Horiz. width */
534 max_bpp_small_joiner_ram = small_joiner_ram_size_bits(i915) /
536 drm_dbg_kms(&i915->drm, "Max small joiner bpp: %u\n",
537 max_bpp_small_joiner_ram);
540 * Greatest allowed DSC BPP = MIN (output BPP from available Link BW
541 * check, output bpp from small joiner RAM check)
543 bits_per_pixel = min(bits_per_pixel, max_bpp_small_joiner_ram);
545 /* Error out if the max bpp is less than smallest allowed valid bpp */
546 if (bits_per_pixel < valid_dsc_bpp[0]) {
547 drm_dbg_kms(&i915->drm, "Unsupported BPP %u, min %u\n",
548 bits_per_pixel, valid_dsc_bpp[0]);
552 /* Find the nearest match in the array of known BPPs from VESA */
553 for (i = 0; i < ARRAY_SIZE(valid_dsc_bpp) - 1; i++) {
554 if (bits_per_pixel < valid_dsc_bpp[i + 1])
557 bits_per_pixel = valid_dsc_bpp[i];
560 * Compressed BPP in U6.4 format so multiply by 16, for Gen 11,
561 * fractional part is 0
563 return bits_per_pixel << 4;
566 static u8 intel_dp_dsc_get_slice_count(struct intel_dp *intel_dp,
567 int mode_clock, int mode_hdisplay)
569 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
570 u8 min_slice_count, i;
573 if (mode_clock <= DP_DSC_PEAK_PIXEL_RATE)
574 min_slice_count = DIV_ROUND_UP(mode_clock,
575 DP_DSC_MAX_ENC_THROUGHPUT_0);
577 min_slice_count = DIV_ROUND_UP(mode_clock,
578 DP_DSC_MAX_ENC_THROUGHPUT_1);
580 max_slice_width = drm_dp_dsc_sink_max_slice_width(intel_dp->dsc_dpcd);
581 if (max_slice_width < DP_DSC_MIN_SLICE_WIDTH_VALUE) {
582 drm_dbg_kms(&i915->drm,
583 "Unsupported slice width %d by DP DSC Sink device\n",
587 /* Also take into account max slice width */
588 min_slice_count = min_t(u8, min_slice_count,
589 DIV_ROUND_UP(mode_hdisplay,
592 /* Find the closest match to the valid slice count values */
593 for (i = 0; i < ARRAY_SIZE(valid_dsc_slicecount); i++) {
594 if (valid_dsc_slicecount[i] >
595 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
598 if (min_slice_count <= valid_dsc_slicecount[i])
599 return valid_dsc_slicecount[i];
602 drm_dbg_kms(&i915->drm, "Unsupported Slice Count %d\n",
607 static bool intel_dp_hdisplay_bad(struct drm_i915_private *dev_priv,
611 * Older platforms don't like hdisplay==4096 with DP.
613 * On ILK/SNB/IVB the pipe seems to be somewhat running (scanline
614 * and frame counter increment), but we don't get vblank interrupts,
615 * and the pipe underruns immediately. The link also doesn't seem
616 * to get trained properly.
618 * On CHV the vblank interrupts don't seem to disappear but
619 * otherwise the symptoms are similar.
621 * TODO: confirm the behaviour on HSW+
623 return hdisplay == 4096 && !HAS_DDI(dev_priv);
626 static enum drm_mode_status
627 intel_dp_mode_valid(struct drm_connector *connector,
628 struct drm_display_mode *mode)
630 struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector));
631 struct intel_connector *intel_connector = to_intel_connector(connector);
632 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
633 struct drm_i915_private *dev_priv = to_i915(connector->dev);
634 int target_clock = mode->clock;
635 int max_rate, mode_rate, max_lanes, max_link_clock;
637 u16 dsc_max_output_bpp = 0;
638 u8 dsc_slice_count = 0;
640 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
641 return MODE_NO_DBLESCAN;
643 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
645 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
646 if (mode->hdisplay > fixed_mode->hdisplay)
649 if (mode->vdisplay > fixed_mode->vdisplay)
652 target_clock = fixed_mode->clock;
655 max_link_clock = intel_dp_max_link_rate(intel_dp);
656 max_lanes = intel_dp_max_lane_count(intel_dp);
658 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
659 mode_rate = intel_dp_link_required(target_clock, 18);
661 if (intel_dp_hdisplay_bad(dev_priv, mode->hdisplay))
662 return MODE_H_ILLEGAL;
665 * Output bpp is stored in 6.4 format so right shift by 4 to get the
666 * integer value since we support only integer values of bpp.
668 if ((INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) &&
669 drm_dp_sink_supports_dsc(intel_dp->dsc_dpcd)) {
670 if (intel_dp_is_edp(intel_dp)) {
672 drm_edp_dsc_sink_output_bpp(intel_dp->dsc_dpcd) >> 4;
674 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
676 } else if (drm_dp_sink_supports_fec(intel_dp->fec_capable)) {
678 intel_dp_dsc_get_output_bpp(dev_priv,
682 mode->hdisplay) >> 4;
684 intel_dp_dsc_get_slice_count(intel_dp,
690 if ((mode_rate > max_rate && !(dsc_max_output_bpp && dsc_slice_count)) ||
691 target_clock > max_dotclk)
692 return MODE_CLOCK_HIGH;
694 if (mode->clock < 10000)
695 return MODE_CLOCK_LOW;
697 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
698 return MODE_H_ILLEGAL;
700 return intel_mode_valid_max_plane_size(dev_priv, mode);
703 u32 intel_dp_pack_aux(const u8 *src, int src_bytes)
710 for (i = 0; i < src_bytes; i++)
711 v |= ((u32)src[i]) << ((3 - i) * 8);
715 static void intel_dp_unpack_aux(u32 src, u8 *dst, int dst_bytes)
720 for (i = 0; i < dst_bytes; i++)
721 dst[i] = src >> ((3-i) * 8);
725 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp);
727 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
728 bool force_disable_vdd);
730 intel_dp_pps_init(struct intel_dp *intel_dp);
732 static intel_wakeref_t
733 pps_lock(struct intel_dp *intel_dp)
735 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
736 intel_wakeref_t wakeref;
739 * See intel_power_sequencer_reset() why we need
740 * a power domain reference here.
742 wakeref = intel_display_power_get(dev_priv,
743 intel_aux_power_domain(dp_to_dig_port(intel_dp)));
745 mutex_lock(&dev_priv->pps_mutex);
750 static intel_wakeref_t
751 pps_unlock(struct intel_dp *intel_dp, intel_wakeref_t wakeref)
753 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
755 mutex_unlock(&dev_priv->pps_mutex);
756 intel_display_power_put(dev_priv,
757 intel_aux_power_domain(dp_to_dig_port(intel_dp)),
762 #define with_pps_lock(dp, wf) \
763 for ((wf) = pps_lock(dp); (wf); (wf) = pps_unlock((dp), (wf)))
766 vlv_power_sequencer_kick(struct intel_dp *intel_dp)
768 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
769 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
770 enum pipe pipe = intel_dp->pps_pipe;
771 bool pll_enabled, release_cl_override = false;
772 enum dpio_phy phy = DPIO_PHY(pipe);
773 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
776 if (drm_WARN(&dev_priv->drm,
777 intel_de_read(dev_priv, intel_dp->output_reg) & DP_PORT_EN,
778 "skipping pipe %c power sequencer kick due to [ENCODER:%d:%s] being active\n",
779 pipe_name(pipe), intel_dig_port->base.base.base.id,
780 intel_dig_port->base.base.name))
783 drm_dbg_kms(&dev_priv->drm,
784 "kicking pipe %c power sequencer for [ENCODER:%d:%s]\n",
785 pipe_name(pipe), intel_dig_port->base.base.base.id,
786 intel_dig_port->base.base.name);
788 /* Preserve the BIOS-computed detected bit. This is
789 * supposed to be read-only.
791 DP = intel_de_read(dev_priv, intel_dp->output_reg) & DP_DETECTED;
792 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
793 DP |= DP_PORT_WIDTH(1);
794 DP |= DP_LINK_TRAIN_PAT_1;
796 if (IS_CHERRYVIEW(dev_priv))
797 DP |= DP_PIPE_SEL_CHV(pipe);
799 DP |= DP_PIPE_SEL(pipe);
801 pll_enabled = intel_de_read(dev_priv, DPLL(pipe)) & DPLL_VCO_ENABLE;
804 * The DPLL for the pipe must be enabled for this to work.
805 * So enable temporarily it if it's not already enabled.
808 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
809 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
811 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
812 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
813 drm_err(&dev_priv->drm,
814 "Failed to force on pll for pipe %c!\n",
821 * Similar magic as in intel_dp_enable_port().
822 * We _must_ do this port enable + disable trick
823 * to make this power sequencer lock onto the port.
824 * Otherwise even VDD force bit won't work.
826 intel_de_write(dev_priv, intel_dp->output_reg, DP);
827 intel_de_posting_read(dev_priv, intel_dp->output_reg);
829 intel_de_write(dev_priv, intel_dp->output_reg, DP | DP_PORT_EN);
830 intel_de_posting_read(dev_priv, intel_dp->output_reg);
832 intel_de_write(dev_priv, intel_dp->output_reg, DP & ~DP_PORT_EN);
833 intel_de_posting_read(dev_priv, intel_dp->output_reg);
836 vlv_force_pll_off(dev_priv, pipe);
838 if (release_cl_override)
839 chv_phy_powergate_ch(dev_priv, phy, ch, false);
843 static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
845 struct intel_encoder *encoder;
846 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
849 * We don't have power sequencer currently.
850 * Pick one that's not used by other ports.
852 for_each_intel_dp(&dev_priv->drm, encoder) {
853 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
855 if (encoder->type == INTEL_OUTPUT_EDP) {
856 drm_WARN_ON(&dev_priv->drm,
857 intel_dp->active_pipe != INVALID_PIPE &&
858 intel_dp->active_pipe !=
861 if (intel_dp->pps_pipe != INVALID_PIPE)
862 pipes &= ~(1 << intel_dp->pps_pipe);
864 drm_WARN_ON(&dev_priv->drm,
865 intel_dp->pps_pipe != INVALID_PIPE);
867 if (intel_dp->active_pipe != INVALID_PIPE)
868 pipes &= ~(1 << intel_dp->active_pipe);
875 return ffs(pipes) - 1;
879 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
881 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
882 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
885 lockdep_assert_held(&dev_priv->pps_mutex);
887 /* We should never land here with regular DP ports */
888 drm_WARN_ON(&dev_priv->drm, !intel_dp_is_edp(intel_dp));
890 drm_WARN_ON(&dev_priv->drm, intel_dp->active_pipe != INVALID_PIPE &&
891 intel_dp->active_pipe != intel_dp->pps_pipe);
893 if (intel_dp->pps_pipe != INVALID_PIPE)
894 return intel_dp->pps_pipe;
896 pipe = vlv_find_free_pps(dev_priv);
899 * Didn't find one. This should not happen since there
900 * are two power sequencers and up to two eDP ports.
902 if (drm_WARN_ON(&dev_priv->drm, pipe == INVALID_PIPE))
905 vlv_steal_power_sequencer(dev_priv, pipe);
906 intel_dp->pps_pipe = pipe;
908 drm_dbg_kms(&dev_priv->drm,
909 "picked pipe %c power sequencer for [ENCODER:%d:%s]\n",
910 pipe_name(intel_dp->pps_pipe),
911 intel_dig_port->base.base.base.id,
912 intel_dig_port->base.base.name);
914 /* init power sequencer on this pipe and port */
915 intel_dp_init_panel_power_sequencer(intel_dp);
916 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
919 * Even vdd force doesn't work until we've made
920 * the power sequencer lock in on the port.
922 vlv_power_sequencer_kick(intel_dp);
924 return intel_dp->pps_pipe;
928 bxt_power_sequencer_idx(struct intel_dp *intel_dp)
930 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
931 int backlight_controller = dev_priv->vbt.backlight.controller;
933 lockdep_assert_held(&dev_priv->pps_mutex);
935 /* We should never land here with regular DP ports */
936 drm_WARN_ON(&dev_priv->drm, !intel_dp_is_edp(intel_dp));
938 if (!intel_dp->pps_reset)
939 return backlight_controller;
941 intel_dp->pps_reset = false;
944 * Only the HW needs to be reprogrammed, the SW state is fixed and
945 * has been setup during connector init.
947 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
949 return backlight_controller;
952 typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
955 static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
958 return intel_de_read(dev_priv, PP_STATUS(pipe)) & PP_ON;
961 static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
964 return intel_de_read(dev_priv, PP_CONTROL(pipe)) & EDP_FORCE_VDD;
967 static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
974 vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
976 vlv_pipe_check pipe_check)
980 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
981 u32 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(pipe)) &
982 PANEL_PORT_SELECT_MASK;
984 if (port_sel != PANEL_PORT_SELECT_VLV(port))
987 if (!pipe_check(dev_priv, pipe))
997 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
999 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1000 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1001 enum port port = intel_dig_port->base.port;
1003 lockdep_assert_held(&dev_priv->pps_mutex);
1005 /* try to find a pipe with this port selected */
1006 /* first pick one where the panel is on */
1007 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
1008 vlv_pipe_has_pp_on);
1009 /* didn't find one? pick one where vdd is on */
1010 if (intel_dp->pps_pipe == INVALID_PIPE)
1011 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
1012 vlv_pipe_has_vdd_on);
1013 /* didn't find one? pick one with just the correct port */
1014 if (intel_dp->pps_pipe == INVALID_PIPE)
1015 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
1018 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
1019 if (intel_dp->pps_pipe == INVALID_PIPE) {
1020 drm_dbg_kms(&dev_priv->drm,
1021 "no initial power sequencer for [ENCODER:%d:%s]\n",
1022 intel_dig_port->base.base.base.id,
1023 intel_dig_port->base.base.name);
1027 drm_dbg_kms(&dev_priv->drm,
1028 "initial power sequencer for [ENCODER:%d:%s]: pipe %c\n",
1029 intel_dig_port->base.base.base.id,
1030 intel_dig_port->base.base.name,
1031 pipe_name(intel_dp->pps_pipe));
1033 intel_dp_init_panel_power_sequencer(intel_dp);
1034 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
1037 void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
1039 struct intel_encoder *encoder;
1041 if (drm_WARN_ON(&dev_priv->drm,
1042 !(IS_VALLEYVIEW(dev_priv) ||
1043 IS_CHERRYVIEW(dev_priv) ||
1044 IS_GEN9_LP(dev_priv))))
1048 * We can't grab pps_mutex here due to deadlock with power_domain
1049 * mutex when power_domain functions are called while holding pps_mutex.
1050 * That also means that in order to use pps_pipe the code needs to
1051 * hold both a power domain reference and pps_mutex, and the power domain
1052 * reference get/put must be done while _not_ holding pps_mutex.
1053 * pps_{lock,unlock}() do these steps in the correct order, so one
1054 * should use them always.
1057 for_each_intel_dp(&dev_priv->drm, encoder) {
1058 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1060 drm_WARN_ON(&dev_priv->drm,
1061 intel_dp->active_pipe != INVALID_PIPE);
1063 if (encoder->type != INTEL_OUTPUT_EDP)
1066 if (IS_GEN9_LP(dev_priv))
1067 intel_dp->pps_reset = true;
1069 intel_dp->pps_pipe = INVALID_PIPE;
1073 struct pps_registers {
1081 static void intel_pps_get_registers(struct intel_dp *intel_dp,
1082 struct pps_registers *regs)
1084 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1087 memset(regs, 0, sizeof(*regs));
1089 if (IS_GEN9_LP(dev_priv))
1090 pps_idx = bxt_power_sequencer_idx(intel_dp);
1091 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1092 pps_idx = vlv_power_sequencer_pipe(intel_dp);
1094 regs->pp_ctrl = PP_CONTROL(pps_idx);
1095 regs->pp_stat = PP_STATUS(pps_idx);
1096 regs->pp_on = PP_ON_DELAYS(pps_idx);
1097 regs->pp_off = PP_OFF_DELAYS(pps_idx);
1099 /* Cycle delay moved from PP_DIVISOR to PP_CONTROL */
1100 if (IS_GEN9_LP(dev_priv) || INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
1101 regs->pp_div = INVALID_MMIO_REG;
1103 regs->pp_div = PP_DIVISOR(pps_idx);
1107 _pp_ctrl_reg(struct intel_dp *intel_dp)
1109 struct pps_registers regs;
1111 intel_pps_get_registers(intel_dp, ®s);
1113 return regs.pp_ctrl;
1117 _pp_stat_reg(struct intel_dp *intel_dp)
1119 struct pps_registers regs;
1121 intel_pps_get_registers(intel_dp, ®s);
1123 return regs.pp_stat;
1126 /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
1127 This function only applicable when panel PM state is not to be tracked */
1128 static int edp_notify_handler(struct notifier_block *this, unsigned long code,
1131 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
1133 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1134 intel_wakeref_t wakeref;
1136 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
1139 with_pps_lock(intel_dp, wakeref) {
1140 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1141 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
1142 i915_reg_t pp_ctrl_reg, pp_div_reg;
1145 pp_ctrl_reg = PP_CONTROL(pipe);
1146 pp_div_reg = PP_DIVISOR(pipe);
1147 pp_div = intel_de_read(dev_priv, pp_div_reg);
1148 pp_div &= PP_REFERENCE_DIVIDER_MASK;
1150 /* 0x1F write to PP_DIV_REG sets max cycle delay */
1151 intel_de_write(dev_priv, pp_div_reg, pp_div | 0x1F);
1152 intel_de_write(dev_priv, pp_ctrl_reg,
1154 msleep(intel_dp->panel_power_cycle_delay);
1161 static bool edp_have_panel_power(struct intel_dp *intel_dp)
1163 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1165 lockdep_assert_held(&dev_priv->pps_mutex);
1167 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1168 intel_dp->pps_pipe == INVALID_PIPE)
1171 return (intel_de_read(dev_priv, _pp_stat_reg(intel_dp)) & PP_ON) != 0;
1174 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
1176 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1178 lockdep_assert_held(&dev_priv->pps_mutex);
1180 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1181 intel_dp->pps_pipe == INVALID_PIPE)
1184 return intel_de_read(dev_priv, _pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
1188 intel_dp_check_edp(struct intel_dp *intel_dp)
1190 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1192 if (!intel_dp_is_edp(intel_dp))
1195 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
1196 drm_WARN(&dev_priv->drm, 1,
1197 "eDP powered off while attempting aux channel communication.\n");
1198 drm_dbg_kms(&dev_priv->drm, "Status 0x%08x Control 0x%08x\n",
1199 intel_de_read(dev_priv, _pp_stat_reg(intel_dp)),
1200 intel_de_read(dev_priv, _pp_ctrl_reg(intel_dp)));
1205 intel_dp_aux_wait_done(struct intel_dp *intel_dp)
1207 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
1208 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
1209 const unsigned int timeout_ms = 10;
1213 #define C (((status = intel_uncore_read_notrace(&i915->uncore, ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1214 done = wait_event_timeout(i915->gmbus_wait_queue, C,
1215 msecs_to_jiffies_timeout(timeout_ms));
1217 /* just trace the final value */
1218 trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
1222 "%s: did not complete or timeout within %ums (status 0x%08x)\n",
1223 intel_dp->aux.name, timeout_ms, status);
1229 static u32 g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1231 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1237 * The clock divider is based off the hrawclk, and would like to run at
1238 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
1240 return DIV_ROUND_CLOSEST(RUNTIME_INFO(dev_priv)->rawclk_freq, 2000);
1243 static u32 ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1245 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1246 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1253 * The clock divider is based off the cdclk or PCH rawclk, and would
1254 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
1255 * divide by 2000 and use that
1257 if (dig_port->aux_ch == AUX_CH_A)
1258 freq = dev_priv->cdclk.hw.cdclk;
1260 freq = RUNTIME_INFO(dev_priv)->rawclk_freq;
1261 return DIV_ROUND_CLOSEST(freq, 2000);
1264 static u32 hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1266 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1267 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1269 if (dig_port->aux_ch != AUX_CH_A && HAS_PCH_LPT_H(dev_priv)) {
1270 /* Workaround for non-ULT HSW */
1278 return ilk_get_aux_clock_divider(intel_dp, index);
1281 static u32 skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
1284 * SKL doesn't need us to program the AUX clock divider (Hardware will
1285 * derive the clock from CDCLK automatically). We still implement the
1286 * get_aux_clock_divider vfunc to plug-in into the existing code.
1288 return index ? 0 : 1;
1291 static u32 g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1293 u32 aux_clock_divider)
1295 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1296 struct drm_i915_private *dev_priv =
1297 to_i915(intel_dig_port->base.base.dev);
1298 u32 precharge, timeout;
1300 if (IS_GEN(dev_priv, 6))
1305 if (IS_BROADWELL(dev_priv))
1306 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1308 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1310 return DP_AUX_CH_CTL_SEND_BUSY |
1311 DP_AUX_CH_CTL_DONE |
1312 DP_AUX_CH_CTL_INTERRUPT |
1313 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1315 DP_AUX_CH_CTL_RECEIVE_ERROR |
1316 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1317 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1318 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
1321 static u32 skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1325 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1326 struct drm_i915_private *i915 =
1327 to_i915(intel_dig_port->base.base.dev);
1328 enum phy phy = intel_port_to_phy(i915, intel_dig_port->base.port);
1331 ret = DP_AUX_CH_CTL_SEND_BUSY |
1332 DP_AUX_CH_CTL_DONE |
1333 DP_AUX_CH_CTL_INTERRUPT |
1334 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1335 DP_AUX_CH_CTL_TIME_OUT_MAX |
1336 DP_AUX_CH_CTL_RECEIVE_ERROR |
1337 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1338 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
1339 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1341 if (intel_phy_is_tc(i915, phy) &&
1342 intel_dig_port->tc_mode == TC_PORT_TBT_ALT)
1343 ret |= DP_AUX_CH_CTL_TBT_IO;
1349 intel_dp_aux_xfer(struct intel_dp *intel_dp,
1350 const u8 *send, int send_bytes,
1351 u8 *recv, int recv_size,
1352 u32 aux_send_ctl_flags)
1354 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1355 struct drm_i915_private *i915 =
1356 to_i915(intel_dig_port->base.base.dev);
1357 struct intel_uncore *uncore = &i915->uncore;
1358 enum phy phy = intel_port_to_phy(i915, intel_dig_port->base.port);
1359 bool is_tc_port = intel_phy_is_tc(i915, phy);
1360 i915_reg_t ch_ctl, ch_data[5];
1361 u32 aux_clock_divider;
1362 enum intel_display_power_domain aux_domain =
1363 intel_aux_power_domain(intel_dig_port);
1364 intel_wakeref_t aux_wakeref;
1365 intel_wakeref_t pps_wakeref;
1366 int i, ret, recv_bytes;
1371 ch_ctl = intel_dp->aux_ch_ctl_reg(intel_dp);
1372 for (i = 0; i < ARRAY_SIZE(ch_data); i++)
1373 ch_data[i] = intel_dp->aux_ch_data_reg(intel_dp, i);
1376 intel_tc_port_lock(intel_dig_port);
1378 aux_wakeref = intel_display_power_get(i915, aux_domain);
1379 pps_wakeref = pps_lock(intel_dp);
1382 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1383 * In such cases we want to leave VDD enabled and it's up to upper layers
1384 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1387 vdd = edp_panel_vdd_on(intel_dp);
1389 /* dp aux is extremely sensitive to irq latency, hence request the
1390 * lowest possible wakeup latency and so prevent the cpu from going into
1391 * deep sleep states.
1393 cpu_latency_qos_update_request(&i915->pm_qos, 0);
1395 intel_dp_check_edp(intel_dp);
1397 /* Try to wait for any previous AUX channel activity */
1398 for (try = 0; try < 3; try++) {
1399 status = intel_uncore_read_notrace(uncore, ch_ctl);
1400 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1404 /* just trace the final value */
1405 trace_i915_reg_rw(false, ch_ctl, status, sizeof(status), true);
1408 const u32 status = intel_uncore_read(uncore, ch_ctl);
1410 if (status != intel_dp->aux_busy_last_status) {
1411 drm_WARN(&i915->drm, 1,
1412 "%s: not started (status 0x%08x)\n",
1413 intel_dp->aux.name, status);
1414 intel_dp->aux_busy_last_status = status;
1421 /* Only 5 data registers! */
1422 if (drm_WARN_ON(&i915->drm, send_bytes > 20 || recv_size > 20)) {
1427 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
1428 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1432 send_ctl |= aux_send_ctl_flags;
1434 /* Must try at least 3 times according to DP spec */
1435 for (try = 0; try < 5; try++) {
1436 /* Load the send data into the aux channel data registers */
1437 for (i = 0; i < send_bytes; i += 4)
1438 intel_uncore_write(uncore,
1440 intel_dp_pack_aux(send + i,
1443 /* Send the command and wait for it to complete */
1444 intel_uncore_write(uncore, ch_ctl, send_ctl);
1446 status = intel_dp_aux_wait_done(intel_dp);
1448 /* Clear done status and any errors */
1449 intel_uncore_write(uncore,
1452 DP_AUX_CH_CTL_DONE |
1453 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1454 DP_AUX_CH_CTL_RECEIVE_ERROR);
1456 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1457 * 400us delay required for errors and timeouts
1458 * Timeout errors from the HW already meet this
1459 * requirement so skip to next iteration
1461 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
1464 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1465 usleep_range(400, 500);
1468 if (status & DP_AUX_CH_CTL_DONE)
1473 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
1474 drm_err(&i915->drm, "%s: not done (status 0x%08x)\n",
1475 intel_dp->aux.name, status);
1481 /* Check for timeout or receive error.
1482 * Timeouts occur when the sink is not connected
1484 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1485 drm_err(&i915->drm, "%s: receive error (status 0x%08x)\n",
1486 intel_dp->aux.name, status);
1491 /* Timeouts occur when the device isn't connected, so they're
1492 * "normal" -- don't fill the kernel log with these */
1493 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
1494 drm_dbg_kms(&i915->drm, "%s: timeout (status 0x%08x)\n",
1495 intel_dp->aux.name, status);
1500 /* Unload any bytes sent back from the other side */
1501 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1502 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
1505 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1506 * We have no idea of what happened so we return -EBUSY so
1507 * drm layer takes care for the necessary retries.
1509 if (recv_bytes == 0 || recv_bytes > 20) {
1510 drm_dbg_kms(&i915->drm,
1511 "%s: Forbidden recv_bytes = %d on aux transaction\n",
1512 intel_dp->aux.name, recv_bytes);
1517 if (recv_bytes > recv_size)
1518 recv_bytes = recv_size;
1520 for (i = 0; i < recv_bytes; i += 4)
1521 intel_dp_unpack_aux(intel_uncore_read(uncore, ch_data[i >> 2]),
1522 recv + i, recv_bytes - i);
1526 cpu_latency_qos_update_request(&i915->pm_qos, PM_QOS_DEFAULT_VALUE);
1529 edp_panel_vdd_off(intel_dp, false);
1531 pps_unlock(intel_dp, pps_wakeref);
1532 intel_display_power_put_async(i915, aux_domain, aux_wakeref);
1535 intel_tc_port_unlock(intel_dig_port);
1540 #define BARE_ADDRESS_SIZE 3
1541 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
1544 intel_dp_aux_header(u8 txbuf[HEADER_SIZE],
1545 const struct drm_dp_aux_msg *msg)
1547 txbuf[0] = (msg->request << 4) | ((msg->address >> 16) & 0xf);
1548 txbuf[1] = (msg->address >> 8) & 0xff;
1549 txbuf[2] = msg->address & 0xff;
1550 txbuf[3] = msg->size - 1;
1554 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
1556 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1557 u8 txbuf[20], rxbuf[20];
1558 size_t txsize, rxsize;
1561 intel_dp_aux_header(txbuf, msg);
1563 switch (msg->request & ~DP_AUX_I2C_MOT) {
1564 case DP_AUX_NATIVE_WRITE:
1565 case DP_AUX_I2C_WRITE:
1566 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
1567 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
1568 rxsize = 2; /* 0 or 1 data bytes */
1570 if (WARN_ON(txsize > 20))
1573 WARN_ON(!msg->buffer != !msg->size);
1576 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
1578 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
1581 msg->reply = rxbuf[0] >> 4;
1584 /* Number of bytes written in a short write. */
1585 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1587 /* Return payload size. */
1593 case DP_AUX_NATIVE_READ:
1594 case DP_AUX_I2C_READ:
1595 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
1596 rxsize = msg->size + 1;
1598 if (WARN_ON(rxsize > 20))
1601 ret = intel_dp_aux_xfer(intel_dp, txbuf, txsize,
1604 msg->reply = rxbuf[0] >> 4;
1606 * Assume happy day, and copy the data. The caller is
1607 * expected to check msg->reply before touching it.
1609 * Return payload size.
1612 memcpy(msg->buffer, rxbuf + 1, ret);
1625 static i915_reg_t g4x_aux_ctl_reg(struct intel_dp *intel_dp)
1627 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1628 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1629 enum aux_ch aux_ch = dig_port->aux_ch;
1635 return DP_AUX_CH_CTL(aux_ch);
1637 MISSING_CASE(aux_ch);
1638 return DP_AUX_CH_CTL(AUX_CH_B);
1642 static i915_reg_t g4x_aux_data_reg(struct intel_dp *intel_dp, int index)
1644 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1645 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1646 enum aux_ch aux_ch = dig_port->aux_ch;
1652 return DP_AUX_CH_DATA(aux_ch, index);
1654 MISSING_CASE(aux_ch);
1655 return DP_AUX_CH_DATA(AUX_CH_B, index);
1659 static i915_reg_t ilk_aux_ctl_reg(struct intel_dp *intel_dp)
1661 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1662 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1663 enum aux_ch aux_ch = dig_port->aux_ch;
1667 return DP_AUX_CH_CTL(aux_ch);
1671 return PCH_DP_AUX_CH_CTL(aux_ch);
1673 MISSING_CASE(aux_ch);
1674 return DP_AUX_CH_CTL(AUX_CH_A);
1678 static i915_reg_t ilk_aux_data_reg(struct intel_dp *intel_dp, int index)
1680 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1681 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1682 enum aux_ch aux_ch = dig_port->aux_ch;
1686 return DP_AUX_CH_DATA(aux_ch, index);
1690 return PCH_DP_AUX_CH_DATA(aux_ch, index);
1692 MISSING_CASE(aux_ch);
1693 return DP_AUX_CH_DATA(AUX_CH_A, index);
1697 static i915_reg_t skl_aux_ctl_reg(struct intel_dp *intel_dp)
1699 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1700 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1701 enum aux_ch aux_ch = dig_port->aux_ch;
1711 return DP_AUX_CH_CTL(aux_ch);
1713 MISSING_CASE(aux_ch);
1714 return DP_AUX_CH_CTL(AUX_CH_A);
1718 static i915_reg_t skl_aux_data_reg(struct intel_dp *intel_dp, int index)
1720 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1721 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1722 enum aux_ch aux_ch = dig_port->aux_ch;
1732 return DP_AUX_CH_DATA(aux_ch, index);
1734 MISSING_CASE(aux_ch);
1735 return DP_AUX_CH_DATA(AUX_CH_A, index);
1740 intel_dp_aux_fini(struct intel_dp *intel_dp)
1742 kfree(intel_dp->aux.name);
1746 intel_dp_aux_init(struct intel_dp *intel_dp)
1748 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1749 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1750 struct intel_encoder *encoder = &dig_port->base;
1752 if (INTEL_GEN(dev_priv) >= 9) {
1753 intel_dp->aux_ch_ctl_reg = skl_aux_ctl_reg;
1754 intel_dp->aux_ch_data_reg = skl_aux_data_reg;
1755 } else if (HAS_PCH_SPLIT(dev_priv)) {
1756 intel_dp->aux_ch_ctl_reg = ilk_aux_ctl_reg;
1757 intel_dp->aux_ch_data_reg = ilk_aux_data_reg;
1759 intel_dp->aux_ch_ctl_reg = g4x_aux_ctl_reg;
1760 intel_dp->aux_ch_data_reg = g4x_aux_data_reg;
1763 if (INTEL_GEN(dev_priv) >= 9)
1764 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
1765 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
1766 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
1767 else if (HAS_PCH_SPLIT(dev_priv))
1768 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
1770 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
1772 if (INTEL_GEN(dev_priv) >= 9)
1773 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
1775 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
1777 drm_dp_aux_init(&intel_dp->aux);
1779 /* Failure to allocate our preferred name is not critical */
1780 intel_dp->aux.name = kasprintf(GFP_KERNEL, "AUX %c/port %c",
1781 aux_ch_name(dig_port->aux_ch),
1782 port_name(encoder->port));
1783 intel_dp->aux.transfer = intel_dp_aux_transfer;
1786 bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
1788 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
1790 return max_rate >= 540000;
1793 bool intel_dp_source_supports_hbr3(struct intel_dp *intel_dp)
1795 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
1797 return max_rate >= 810000;
1801 intel_dp_set_clock(struct intel_encoder *encoder,
1802 struct intel_crtc_state *pipe_config)
1804 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1805 const struct dp_link_dpll *divisor = NULL;
1808 if (IS_G4X(dev_priv)) {
1810 count = ARRAY_SIZE(g4x_dpll);
1811 } else if (HAS_PCH_SPLIT(dev_priv)) {
1813 count = ARRAY_SIZE(pch_dpll);
1814 } else if (IS_CHERRYVIEW(dev_priv)) {
1816 count = ARRAY_SIZE(chv_dpll);
1817 } else if (IS_VALLEYVIEW(dev_priv)) {
1819 count = ARRAY_SIZE(vlv_dpll);
1822 if (divisor && count) {
1823 for (i = 0; i < count; i++) {
1824 if (pipe_config->port_clock == divisor[i].clock) {
1825 pipe_config->dpll = divisor[i].dpll;
1826 pipe_config->clock_set = true;
1833 static void snprintf_int_array(char *str, size_t len,
1834 const int *array, int nelem)
1840 for (i = 0; i < nelem; i++) {
1841 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
1849 static void intel_dp_print_rates(struct intel_dp *intel_dp)
1851 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
1852 char str[128]; /* FIXME: too big for stack? */
1854 if (!drm_debug_enabled(DRM_UT_KMS))
1857 snprintf_int_array(str, sizeof(str),
1858 intel_dp->source_rates, intel_dp->num_source_rates);
1859 drm_dbg_kms(&i915->drm, "source rates: %s\n", str);
1861 snprintf_int_array(str, sizeof(str),
1862 intel_dp->sink_rates, intel_dp->num_sink_rates);
1863 drm_dbg_kms(&i915->drm, "sink rates: %s\n", str);
1865 snprintf_int_array(str, sizeof(str),
1866 intel_dp->common_rates, intel_dp->num_common_rates);
1867 drm_dbg_kms(&i915->drm, "common rates: %s\n", str);
1871 intel_dp_max_link_rate(struct intel_dp *intel_dp)
1875 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
1876 if (WARN_ON(len <= 0))
1879 return intel_dp->common_rates[len - 1];
1882 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1884 int i = intel_dp_rate_index(intel_dp->sink_rates,
1885 intel_dp->num_sink_rates, rate);
1893 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1894 u8 *link_bw, u8 *rate_select)
1896 /* eDP 1.4 rate select method. */
1897 if (intel_dp->use_rate_select) {
1900 intel_dp_rate_select(intel_dp, port_clock);
1902 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1907 static bool intel_dp_source_supports_fec(struct intel_dp *intel_dp,
1908 const struct intel_crtc_state *pipe_config)
1910 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1912 /* On TGL, FEC is supported on all Pipes */
1913 if (INTEL_GEN(dev_priv) >= 12)
1916 if (IS_GEN(dev_priv, 11) && pipe_config->cpu_transcoder != TRANSCODER_A)
1922 static bool intel_dp_supports_fec(struct intel_dp *intel_dp,
1923 const struct intel_crtc_state *pipe_config)
1925 return intel_dp_source_supports_fec(intel_dp, pipe_config) &&
1926 drm_dp_sink_supports_fec(intel_dp->fec_capable);
1929 static bool intel_dp_supports_dsc(struct intel_dp *intel_dp,
1930 const struct intel_crtc_state *crtc_state)
1932 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1934 if (!intel_dp_is_edp(intel_dp) && !crtc_state->fec_enable)
1937 return intel_dsc_source_support(encoder, crtc_state) &&
1938 drm_dp_sink_supports_dsc(intel_dp->dsc_dpcd);
1941 static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1942 struct intel_crtc_state *pipe_config)
1944 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1945 struct intel_connector *intel_connector = intel_dp->attached_connector;
1948 bpp = pipe_config->pipe_bpp;
1949 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1952 bpp = min(bpp, 3*bpc);
1954 if (intel_dp_is_edp(intel_dp)) {
1955 /* Get bpp from vbt only for panels that dont have bpp in edid */
1956 if (intel_connector->base.display_info.bpc == 0 &&
1957 dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp) {
1958 drm_dbg_kms(&dev_priv->drm,
1959 "clamping bpp for eDP panel to BIOS-provided %i\n",
1960 dev_priv->vbt.edp.bpp);
1961 bpp = dev_priv->vbt.edp.bpp;
1968 /* Adjust link config limits based on compliance test requests. */
1970 intel_dp_adjust_compliance_config(struct intel_dp *intel_dp,
1971 struct intel_crtc_state *pipe_config,
1972 struct link_config_limits *limits)
1974 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
1976 /* For DP Compliance we override the computed bpp for the pipe */
1977 if (intel_dp->compliance.test_data.bpc != 0) {
1978 int bpp = 3 * intel_dp->compliance.test_data.bpc;
1980 limits->min_bpp = limits->max_bpp = bpp;
1981 pipe_config->dither_force_disable = bpp == 6 * 3;
1983 drm_dbg_kms(&i915->drm, "Setting pipe_bpp to %d\n", bpp);
1986 /* Use values requested by Compliance Test Request */
1987 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1990 /* Validate the compliance test data since max values
1991 * might have changed due to link train fallback.
1993 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1994 intel_dp->compliance.test_lane_count)) {
1995 index = intel_dp_rate_index(intel_dp->common_rates,
1996 intel_dp->num_common_rates,
1997 intel_dp->compliance.test_link_rate);
1999 limits->min_clock = limits->max_clock = index;
2000 limits->min_lane_count = limits->max_lane_count =
2001 intel_dp->compliance.test_lane_count;
2006 static int intel_dp_output_bpp(const struct intel_crtc_state *crtc_state, int bpp)
2009 * bpp value was assumed to RGB format. And YCbCr 4:2:0 output
2010 * format of the number of bytes per pixel will be half the number
2011 * of bytes of RGB pixel.
2013 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
2019 /* Optimize link config in order: max bpp, min clock, min lanes */
2021 intel_dp_compute_link_config_wide(struct intel_dp *intel_dp,
2022 struct intel_crtc_state *pipe_config,
2023 const struct link_config_limits *limits)
2025 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2026 int bpp, clock, lane_count;
2027 int mode_rate, link_clock, link_avail;
2029 for (bpp = limits->max_bpp; bpp >= limits->min_bpp; bpp -= 2 * 3) {
2030 int output_bpp = intel_dp_output_bpp(pipe_config, bpp);
2032 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
2035 for (clock = limits->min_clock; clock <= limits->max_clock; clock++) {
2036 for (lane_count = limits->min_lane_count;
2037 lane_count <= limits->max_lane_count;
2039 link_clock = intel_dp->common_rates[clock];
2040 link_avail = intel_dp_max_data_rate(link_clock,
2043 if (mode_rate <= link_avail) {
2044 pipe_config->lane_count = lane_count;
2045 pipe_config->pipe_bpp = bpp;
2046 pipe_config->port_clock = link_clock;
2057 static int intel_dp_dsc_compute_bpp(struct intel_dp *intel_dp, u8 dsc_max_bpc)
2060 u8 dsc_bpc[3] = {0};
2062 num_bpc = drm_dp_dsc_sink_supported_input_bpcs(intel_dp->dsc_dpcd,
2064 for (i = 0; i < num_bpc; i++) {
2065 if (dsc_max_bpc >= dsc_bpc[i])
2066 return dsc_bpc[i] * 3;
2072 #define DSC_SUPPORTED_VERSION_MIN 1
2074 static int intel_dp_dsc_compute_params(struct intel_encoder *encoder,
2075 struct intel_crtc_state *crtc_state)
2077 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2078 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2079 struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config;
2083 ret = intel_dsc_compute_params(encoder, crtc_state);
2088 * Slice Height of 8 works for all currently available panels. So start
2089 * with that if pic_height is an integral multiple of 8. Eventually add
2090 * logic to try multiple slice heights.
2092 if (vdsc_cfg->pic_height % 8 == 0)
2093 vdsc_cfg->slice_height = 8;
2094 else if (vdsc_cfg->pic_height % 4 == 0)
2095 vdsc_cfg->slice_height = 4;
2097 vdsc_cfg->slice_height = 2;
2099 vdsc_cfg->dsc_version_major =
2100 (intel_dp->dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] &
2101 DP_DSC_MAJOR_MASK) >> DP_DSC_MAJOR_SHIFT;
2102 vdsc_cfg->dsc_version_minor =
2103 min(DSC_SUPPORTED_VERSION_MIN,
2104 (intel_dp->dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] &
2105 DP_DSC_MINOR_MASK) >> DP_DSC_MINOR_SHIFT);
2107 vdsc_cfg->convert_rgb = intel_dp->dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] &
2110 line_buf_depth = drm_dp_dsc_sink_line_buf_depth(intel_dp->dsc_dpcd);
2111 if (!line_buf_depth) {
2112 drm_dbg_kms(&i915->drm,
2113 "DSC Sink Line Buffer Depth invalid\n");
2117 if (vdsc_cfg->dsc_version_minor == 2)
2118 vdsc_cfg->line_buf_depth = (line_buf_depth == DSC_1_2_MAX_LINEBUF_DEPTH_BITS) ?
2119 DSC_1_2_MAX_LINEBUF_DEPTH_VAL : line_buf_depth;
2121 vdsc_cfg->line_buf_depth = (line_buf_depth > DSC_1_1_MAX_LINEBUF_DEPTH_BITS) ?
2122 DSC_1_1_MAX_LINEBUF_DEPTH_BITS : line_buf_depth;
2124 vdsc_cfg->block_pred_enable =
2125 intel_dp->dsc_dpcd[DP_DSC_BLK_PREDICTION_SUPPORT - DP_DSC_SUPPORT] &
2126 DP_DSC_BLK_PREDICTION_IS_SUPPORTED;
2128 return drm_dsc_compute_rc_parameters(vdsc_cfg);
2131 static int intel_dp_dsc_compute_config(struct intel_dp *intel_dp,
2132 struct intel_crtc_state *pipe_config,
2133 struct drm_connector_state *conn_state,
2134 struct link_config_limits *limits)
2136 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2137 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2138 const struct drm_display_mode *adjusted_mode =
2139 &pipe_config->hw.adjusted_mode;
2144 pipe_config->fec_enable = !intel_dp_is_edp(intel_dp) &&
2145 intel_dp_supports_fec(intel_dp, pipe_config);
2147 if (!intel_dp_supports_dsc(intel_dp, pipe_config))
2150 /* Max DSC Input BPC for ICL is 10 and for TGL+ is 12 */
2151 if (INTEL_GEN(dev_priv) >= 12)
2152 dsc_max_bpc = min_t(u8, 12, conn_state->max_requested_bpc);
2154 dsc_max_bpc = min_t(u8, 10,
2155 conn_state->max_requested_bpc);
2157 pipe_bpp = intel_dp_dsc_compute_bpp(intel_dp, dsc_max_bpc);
2159 /* Min Input BPC for ICL+ is 8 */
2160 if (pipe_bpp < 8 * 3) {
2161 drm_dbg_kms(&dev_priv->drm,
2162 "No DSC support for less than 8bpc\n");
2167 * For now enable DSC for max bpp, max link rate, max lane count.
2168 * Optimize this later for the minimum possible link rate/lane count
2169 * with DSC enabled for the requested mode.
2171 pipe_config->pipe_bpp = pipe_bpp;
2172 pipe_config->port_clock = intel_dp->common_rates[limits->max_clock];
2173 pipe_config->lane_count = limits->max_lane_count;
2175 if (intel_dp_is_edp(intel_dp)) {
2176 pipe_config->dsc.compressed_bpp =
2177 min_t(u16, drm_edp_dsc_sink_output_bpp(intel_dp->dsc_dpcd) >> 4,
2178 pipe_config->pipe_bpp);
2179 pipe_config->dsc.slice_count =
2180 drm_dp_dsc_sink_max_slice_count(intel_dp->dsc_dpcd,
2183 u16 dsc_max_output_bpp;
2184 u8 dsc_dp_slice_count;
2186 dsc_max_output_bpp =
2187 intel_dp_dsc_get_output_bpp(dev_priv,
2188 pipe_config->port_clock,
2189 pipe_config->lane_count,
2190 adjusted_mode->crtc_clock,
2191 adjusted_mode->crtc_hdisplay);
2192 dsc_dp_slice_count =
2193 intel_dp_dsc_get_slice_count(intel_dp,
2194 adjusted_mode->crtc_clock,
2195 adjusted_mode->crtc_hdisplay);
2196 if (!dsc_max_output_bpp || !dsc_dp_slice_count) {
2197 drm_dbg_kms(&dev_priv->drm,
2198 "Compressed BPP/Slice Count not supported\n");
2201 pipe_config->dsc.compressed_bpp = min_t(u16,
2202 dsc_max_output_bpp >> 4,
2203 pipe_config->pipe_bpp);
2204 pipe_config->dsc.slice_count = dsc_dp_slice_count;
2207 * VDSC engine operates at 1 Pixel per clock, so if peak pixel rate
2208 * is greater than the maximum Cdclock and if slice count is even
2209 * then we need to use 2 VDSC instances.
2211 if (adjusted_mode->crtc_clock > dev_priv->max_cdclk_freq) {
2212 if (pipe_config->dsc.slice_count > 1) {
2213 pipe_config->dsc.dsc_split = true;
2215 drm_dbg_kms(&dev_priv->drm,
2216 "Cannot split stream to use 2 VDSC instances\n");
2221 ret = intel_dp_dsc_compute_params(&dig_port->base, pipe_config);
2223 drm_dbg_kms(&dev_priv->drm,
2224 "Cannot compute valid DSC parameters for Input Bpp = %d "
2225 "Compressed BPP = %d\n",
2226 pipe_config->pipe_bpp,
2227 pipe_config->dsc.compressed_bpp);
2231 pipe_config->dsc.compression_enable = true;
2232 drm_dbg_kms(&dev_priv->drm, "DP DSC computed with Input Bpp = %d "
2233 "Compressed Bpp = %d Slice Count = %d\n",
2234 pipe_config->pipe_bpp,
2235 pipe_config->dsc.compressed_bpp,
2236 pipe_config->dsc.slice_count);
2241 int intel_dp_min_bpp(const struct intel_crtc_state *crtc_state)
2243 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_RGB)
2250 intel_dp_compute_link_config(struct intel_encoder *encoder,
2251 struct intel_crtc_state *pipe_config,
2252 struct drm_connector_state *conn_state)
2254 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2255 const struct drm_display_mode *adjusted_mode =
2256 &pipe_config->hw.adjusted_mode;
2257 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2258 struct link_config_limits limits;
2262 common_len = intel_dp_common_len_rate_limit(intel_dp,
2263 intel_dp->max_link_rate);
2265 /* No common link rates between source and sink */
2266 drm_WARN_ON(encoder->base.dev, common_len <= 0);
2268 limits.min_clock = 0;
2269 limits.max_clock = common_len - 1;
2271 limits.min_lane_count = 1;
2272 limits.max_lane_count = intel_dp_max_lane_count(intel_dp);
2274 limits.min_bpp = intel_dp_min_bpp(pipe_config);
2275 limits.max_bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
2277 if (intel_dp_is_edp(intel_dp)) {
2279 * Use the maximum clock and number of lanes the eDP panel
2280 * advertizes being capable of. The panels are generally
2281 * designed to support only a single clock and lane
2282 * configuration, and typically these values correspond to the
2283 * native resolution of the panel.
2285 limits.min_lane_count = limits.max_lane_count;
2286 limits.min_clock = limits.max_clock;
2289 intel_dp_adjust_compliance_config(intel_dp, pipe_config, &limits);
2291 drm_dbg_kms(&i915->drm, "DP link computation with max lane count %i "
2292 "max rate %d max bpp %d pixel clock %iKHz\n",
2293 limits.max_lane_count,
2294 intel_dp->common_rates[limits.max_clock],
2295 limits.max_bpp, adjusted_mode->crtc_clock);
2298 * Optimize for slow and wide. This is the place to add alternative
2299 * optimization policy.
2301 ret = intel_dp_compute_link_config_wide(intel_dp, pipe_config, &limits);
2303 /* enable compression if the mode doesn't fit available BW */
2304 drm_dbg_kms(&i915->drm, "Force DSC en = %d\n", intel_dp->force_dsc_en);
2305 if (ret || intel_dp->force_dsc_en) {
2306 ret = intel_dp_dsc_compute_config(intel_dp, pipe_config,
2307 conn_state, &limits);
2312 if (pipe_config->dsc.compression_enable) {
2313 drm_dbg_kms(&i915->drm,
2314 "DP lane count %d clock %d Input bpp %d Compressed bpp %d\n",
2315 pipe_config->lane_count, pipe_config->port_clock,
2316 pipe_config->pipe_bpp,
2317 pipe_config->dsc.compressed_bpp);
2319 drm_dbg_kms(&i915->drm,
2320 "DP link rate required %i available %i\n",
2321 intel_dp_link_required(adjusted_mode->crtc_clock,
2322 pipe_config->dsc.compressed_bpp),
2323 intel_dp_max_data_rate(pipe_config->port_clock,
2324 pipe_config->lane_count));
2326 drm_dbg_kms(&i915->drm, "DP lane count %d clock %d bpp %d\n",
2327 pipe_config->lane_count, pipe_config->port_clock,
2328 pipe_config->pipe_bpp);
2330 drm_dbg_kms(&i915->drm,
2331 "DP link rate required %i available %i\n",
2332 intel_dp_link_required(adjusted_mode->crtc_clock,
2333 pipe_config->pipe_bpp),
2334 intel_dp_max_data_rate(pipe_config->port_clock,
2335 pipe_config->lane_count));
2341 intel_dp_ycbcr420_config(struct intel_dp *intel_dp,
2342 struct drm_connector *connector,
2343 struct intel_crtc_state *crtc_state)
2345 const struct drm_display_info *info = &connector->display_info;
2346 const struct drm_display_mode *adjusted_mode =
2347 &crtc_state->hw.adjusted_mode;
2348 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2350 if (!drm_mode_is_420_only(info, adjusted_mode) ||
2351 !intel_dp_get_colorimetry_status(intel_dp) ||
2352 !connector->ycbcr_420_allowed)
2355 crtc_state->output_format = INTEL_OUTPUT_FORMAT_YCBCR420;
2357 intel_pch_panel_fitting(crtc, crtc_state, DRM_MODE_SCALE_FULLSCREEN);
2362 bool intel_dp_limited_color_range(const struct intel_crtc_state *crtc_state,
2363 const struct drm_connector_state *conn_state)
2365 const struct intel_digital_connector_state *intel_conn_state =
2366 to_intel_digital_connector_state(conn_state);
2367 const struct drm_display_mode *adjusted_mode =
2368 &crtc_state->hw.adjusted_mode;
2371 * Our YCbCr output is always limited range.
2372 * crtc_state->limited_color_range only applies to RGB,
2373 * and it must never be set for YCbCr or we risk setting
2374 * some conflicting bits in PIPECONF which will mess up
2375 * the colors on the monitor.
2377 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
2380 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
2383 * CEA-861-E - 5.1 Default Encoding Parameters
2384 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
2386 return crtc_state->pipe_bpp != 18 &&
2387 drm_default_rgb_quant_range(adjusted_mode) ==
2388 HDMI_QUANTIZATION_RANGE_LIMITED;
2390 return intel_conn_state->broadcast_rgb ==
2391 INTEL_BROADCAST_RGB_LIMITED;
2395 static bool intel_dp_port_has_audio(struct drm_i915_private *dev_priv,
2398 if (IS_G4X(dev_priv))
2400 if (INTEL_GEN(dev_priv) < 12 && port == PORT_A)
2406 static void intel_dp_compute_vsc_colorimetry(const struct intel_crtc_state *crtc_state,
2407 const struct drm_connector_state *conn_state,
2408 struct drm_dp_vsc_sdp *vsc)
2410 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2411 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2414 * Prepare VSC Header for SU as per DP 1.4 spec, Table 2-118
2415 * VSC SDP supporting 3D stereo, PSR2, and Pixel Encoding/
2416 * Colorimetry Format indication.
2418 vsc->revision = 0x5;
2421 /* DP 1.4a spec, Table 2-120 */
2422 switch (crtc_state->output_format) {
2423 case INTEL_OUTPUT_FORMAT_YCBCR444:
2424 vsc->pixelformat = DP_PIXELFORMAT_YUV444;
2426 case INTEL_OUTPUT_FORMAT_YCBCR420:
2427 vsc->pixelformat = DP_PIXELFORMAT_YUV420;
2429 case INTEL_OUTPUT_FORMAT_RGB:
2431 vsc->pixelformat = DP_PIXELFORMAT_RGB;
2434 switch (conn_state->colorspace) {
2435 case DRM_MODE_COLORIMETRY_BT709_YCC:
2436 vsc->colorimetry = DP_COLORIMETRY_BT709_YCC;
2438 case DRM_MODE_COLORIMETRY_XVYCC_601:
2439 vsc->colorimetry = DP_COLORIMETRY_XVYCC_601;
2441 case DRM_MODE_COLORIMETRY_XVYCC_709:
2442 vsc->colorimetry = DP_COLORIMETRY_XVYCC_709;
2444 case DRM_MODE_COLORIMETRY_SYCC_601:
2445 vsc->colorimetry = DP_COLORIMETRY_SYCC_601;
2447 case DRM_MODE_COLORIMETRY_OPYCC_601:
2448 vsc->colorimetry = DP_COLORIMETRY_OPYCC_601;
2450 case DRM_MODE_COLORIMETRY_BT2020_CYCC:
2451 vsc->colorimetry = DP_COLORIMETRY_BT2020_CYCC;
2453 case DRM_MODE_COLORIMETRY_BT2020_RGB:
2454 vsc->colorimetry = DP_COLORIMETRY_BT2020_RGB;
2456 case DRM_MODE_COLORIMETRY_BT2020_YCC:
2457 vsc->colorimetry = DP_COLORIMETRY_BT2020_YCC;
2459 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65:
2460 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER:
2461 vsc->colorimetry = DP_COLORIMETRY_DCI_P3_RGB;
2465 * RGB->YCBCR color conversion uses the BT.709
2468 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
2469 vsc->colorimetry = DP_COLORIMETRY_BT709_YCC;
2471 vsc->colorimetry = DP_COLORIMETRY_DEFAULT;
2475 vsc->bpc = crtc_state->pipe_bpp / 3;
2477 /* only RGB pixelformat supports 6 bpc */
2478 drm_WARN_ON(&dev_priv->drm,
2479 vsc->bpc == 6 && vsc->pixelformat != DP_PIXELFORMAT_RGB);
2481 /* all YCbCr are always limited range */
2482 vsc->dynamic_range = DP_DYNAMIC_RANGE_CTA;
2483 vsc->content_type = DP_CONTENT_TYPE_NOT_DEFINED;
2486 static void intel_dp_compute_vsc_sdp(struct intel_dp *intel_dp,
2487 struct intel_crtc_state *crtc_state,
2488 const struct drm_connector_state *conn_state)
2490 struct drm_dp_vsc_sdp *vsc = &crtc_state->infoframes.vsc;
2492 /* When PSR is enabled, VSC SDP is handled by PSR routine */
2493 if (intel_psr_enabled(intel_dp))
2496 if (!intel_dp_needs_vsc_sdp(crtc_state, conn_state))
2499 crtc_state->infoframes.enable |= intel_hdmi_infoframe_enable(DP_SDP_VSC);
2500 vsc->sdp_type = DP_SDP_VSC;
2501 intel_dp_compute_vsc_colorimetry(crtc_state, conn_state,
2502 &crtc_state->infoframes.vsc);
2506 intel_dp_compute_hdr_metadata_infoframe_sdp(struct intel_dp *intel_dp,
2507 struct intel_crtc_state *crtc_state,
2508 const struct drm_connector_state *conn_state)
2511 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2512 struct hdmi_drm_infoframe *drm_infoframe = &crtc_state->infoframes.drm.drm;
2514 if (!conn_state->hdr_output_metadata)
2517 ret = drm_hdmi_infoframe_set_hdr_metadata(drm_infoframe, conn_state);
2520 drm_dbg_kms(&dev_priv->drm, "couldn't set HDR metadata in infoframe\n");
2524 crtc_state->infoframes.enable |=
2525 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA);
2529 intel_dp_compute_config(struct intel_encoder *encoder,
2530 struct intel_crtc_state *pipe_config,
2531 struct drm_connector_state *conn_state)
2533 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2534 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2535 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2536 struct intel_lspcon *lspcon = enc_to_intel_lspcon(encoder);
2537 enum port port = encoder->port;
2538 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
2539 struct intel_connector *intel_connector = intel_dp->attached_connector;
2540 struct intel_digital_connector_state *intel_conn_state =
2541 to_intel_digital_connector_state(conn_state);
2542 bool constant_n = drm_dp_has_quirk(&intel_dp->desc, 0,
2543 DP_DPCD_QUIRK_CONSTANT_N);
2544 int ret = 0, output_bpp;
2546 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
2547 pipe_config->has_pch_encoder = true;
2549 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
2552 lspcon_ycbcr420_config(&intel_connector->base, pipe_config);
2554 ret = intel_dp_ycbcr420_config(intel_dp, &intel_connector->base,
2559 pipe_config->has_drrs = false;
2560 if (!intel_dp_port_has_audio(dev_priv, port))
2561 pipe_config->has_audio = false;
2562 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
2563 pipe_config->has_audio = intel_dp->has_audio;
2565 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
2567 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
2568 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
2571 if (HAS_GMCH(dev_priv))
2572 intel_gmch_panel_fitting(intel_crtc, pipe_config,
2573 conn_state->scaling_mode);
2575 intel_pch_panel_fitting(intel_crtc, pipe_config,
2576 conn_state->scaling_mode);
2579 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
2582 if (HAS_GMCH(dev_priv) &&
2583 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
2586 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
2589 if (intel_dp_hdisplay_bad(dev_priv, adjusted_mode->crtc_hdisplay))
2592 ret = intel_dp_compute_link_config(encoder, pipe_config, conn_state);
2596 pipe_config->limited_color_range =
2597 intel_dp_limited_color_range(pipe_config, conn_state);
2599 if (pipe_config->dsc.compression_enable)
2600 output_bpp = pipe_config->dsc.compressed_bpp;
2602 output_bpp = intel_dp_output_bpp(pipe_config, pipe_config->pipe_bpp);
2604 intel_link_compute_m_n(output_bpp,
2605 pipe_config->lane_count,
2606 adjusted_mode->crtc_clock,
2607 pipe_config->port_clock,
2608 &pipe_config->dp_m_n,
2609 constant_n, pipe_config->fec_enable);
2611 if (intel_connector->panel.downclock_mode != NULL &&
2612 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
2613 pipe_config->has_drrs = true;
2614 intel_link_compute_m_n(output_bpp,
2615 pipe_config->lane_count,
2616 intel_connector->panel.downclock_mode->clock,
2617 pipe_config->port_clock,
2618 &pipe_config->dp_m2_n2,
2619 constant_n, pipe_config->fec_enable);
2622 if (!HAS_DDI(dev_priv))
2623 intel_dp_set_clock(encoder, pipe_config);
2625 intel_psr_compute_config(intel_dp, pipe_config);
2626 intel_dp_compute_vsc_sdp(intel_dp, pipe_config, conn_state);
2627 intel_dp_compute_hdr_metadata_infoframe_sdp(intel_dp, pipe_config, conn_state);
2632 void intel_dp_set_link_params(struct intel_dp *intel_dp,
2633 int link_rate, u8 lane_count,
2636 intel_dp->link_trained = false;
2637 intel_dp->link_rate = link_rate;
2638 intel_dp->lane_count = lane_count;
2639 intel_dp->link_mst = link_mst;
2642 static void intel_dp_prepare(struct intel_encoder *encoder,
2643 const struct intel_crtc_state *pipe_config)
2645 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2646 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2647 enum port port = encoder->port;
2648 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
2649 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2651 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
2652 pipe_config->lane_count,
2653 intel_crtc_has_type(pipe_config,
2654 INTEL_OUTPUT_DP_MST));
2657 * There are four kinds of DP registers:
2664 * IBX PCH and CPU are the same for almost everything,
2665 * except that the CPU DP PLL is configured in this
2668 * CPT PCH is quite different, having many bits moved
2669 * to the TRANS_DP_CTL register instead. That
2670 * configuration happens (oddly) in ilk_pch_enable
2673 /* Preserve the BIOS-computed detected bit. This is
2674 * supposed to be read-only.
2676 intel_dp->DP = intel_de_read(dev_priv, intel_dp->output_reg) & DP_DETECTED;
2678 /* Handle DP bits in common between all three register formats */
2679 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
2680 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
2682 /* Split out the IBX/CPU vs CPT settings */
2684 if (IS_IVYBRIDGE(dev_priv) && port == PORT_A) {
2685 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2686 intel_dp->DP |= DP_SYNC_HS_HIGH;
2687 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2688 intel_dp->DP |= DP_SYNC_VS_HIGH;
2689 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
2691 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2692 intel_dp->DP |= DP_ENHANCED_FRAMING;
2694 intel_dp->DP |= DP_PIPE_SEL_IVB(crtc->pipe);
2695 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2698 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
2700 trans_dp = intel_de_read(dev_priv, TRANS_DP_CTL(crtc->pipe));
2701 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2702 trans_dp |= TRANS_DP_ENH_FRAMING;
2704 trans_dp &= ~TRANS_DP_ENH_FRAMING;
2705 intel_de_write(dev_priv, TRANS_DP_CTL(crtc->pipe), trans_dp);
2707 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
2708 intel_dp->DP |= DP_COLOR_RANGE_16_235;
2710 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2711 intel_dp->DP |= DP_SYNC_HS_HIGH;
2712 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2713 intel_dp->DP |= DP_SYNC_VS_HIGH;
2714 intel_dp->DP |= DP_LINK_TRAIN_OFF;
2716 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2717 intel_dp->DP |= DP_ENHANCED_FRAMING;
2719 if (IS_CHERRYVIEW(dev_priv))
2720 intel_dp->DP |= DP_PIPE_SEL_CHV(crtc->pipe);
2722 intel_dp->DP |= DP_PIPE_SEL(crtc->pipe);
2726 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
2727 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
2729 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
2730 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
2732 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
2733 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
2735 static void intel_pps_verify_state(struct intel_dp *intel_dp);
2737 static void wait_panel_status(struct intel_dp *intel_dp,
2741 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2742 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2744 lockdep_assert_held(&dev_priv->pps_mutex);
2746 intel_pps_verify_state(intel_dp);
2748 pp_stat_reg = _pp_stat_reg(intel_dp);
2749 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2751 drm_dbg_kms(&dev_priv->drm,
2752 "mask %08x value %08x status %08x control %08x\n",
2754 intel_de_read(dev_priv, pp_stat_reg),
2755 intel_de_read(dev_priv, pp_ctrl_reg));
2757 if (intel_de_wait_for_register(dev_priv, pp_stat_reg,
2759 drm_err(&dev_priv->drm,
2760 "Panel status timeout: status %08x control %08x\n",
2761 intel_de_read(dev_priv, pp_stat_reg),
2762 intel_de_read(dev_priv, pp_ctrl_reg));
2764 drm_dbg_kms(&dev_priv->drm, "Wait complete\n");
2767 static void wait_panel_on(struct intel_dp *intel_dp)
2769 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
2771 drm_dbg_kms(&i915->drm, "Wait for panel power on\n");
2772 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
2775 static void wait_panel_off(struct intel_dp *intel_dp)
2777 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
2779 drm_dbg_kms(&i915->drm, "Wait for panel power off time\n");
2780 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
2783 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
2785 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
2786 ktime_t panel_power_on_time;
2787 s64 panel_power_off_duration;
2789 drm_dbg_kms(&i915->drm, "Wait for panel power cycle\n");
2791 /* take the difference of currrent time and panel power off time
2792 * and then make panel wait for t11_t12 if needed. */
2793 panel_power_on_time = ktime_get_boottime();
2794 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2796 /* When we disable the VDD override bit last we have to do the manual
2798 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2799 wait_remaining_ms_from_jiffies(jiffies,
2800 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
2802 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
2805 static void wait_backlight_on(struct intel_dp *intel_dp)
2807 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2808 intel_dp->backlight_on_delay);
2811 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
2813 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2814 intel_dp->backlight_off_delay);
2817 /* Read the current pp_control value, unlocking the register if it
2821 static u32 ilk_get_pp_control(struct intel_dp *intel_dp)
2823 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2826 lockdep_assert_held(&dev_priv->pps_mutex);
2828 control = intel_de_read(dev_priv, _pp_ctrl_reg(intel_dp));
2829 if (drm_WARN_ON(&dev_priv->drm, !HAS_DDI(dev_priv) &&
2830 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
2831 control &= ~PANEL_UNLOCK_MASK;
2832 control |= PANEL_UNLOCK_REGS;
2838 * Must be paired with edp_panel_vdd_off().
2839 * Must hold pps_mutex around the whole on/off sequence.
2840 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2842 static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
2844 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2845 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2847 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2848 bool need_to_disable = !intel_dp->want_panel_vdd;
2850 lockdep_assert_held(&dev_priv->pps_mutex);
2852 if (!intel_dp_is_edp(intel_dp))
2855 cancel_delayed_work(&intel_dp->panel_vdd_work);
2856 intel_dp->want_panel_vdd = true;
2858 if (edp_have_panel_vdd(intel_dp))
2859 return need_to_disable;
2861 intel_display_power_get(dev_priv,
2862 intel_aux_power_domain(intel_dig_port));
2864 drm_dbg_kms(&dev_priv->drm, "Turning [ENCODER:%d:%s] VDD on\n",
2865 intel_dig_port->base.base.base.id,
2866 intel_dig_port->base.base.name);
2868 if (!edp_have_panel_power(intel_dp))
2869 wait_panel_power_cycle(intel_dp);
2871 pp = ilk_get_pp_control(intel_dp);
2872 pp |= EDP_FORCE_VDD;
2874 pp_stat_reg = _pp_stat_reg(intel_dp);
2875 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2877 intel_de_write(dev_priv, pp_ctrl_reg, pp);
2878 intel_de_posting_read(dev_priv, pp_ctrl_reg);
2879 drm_dbg_kms(&dev_priv->drm, "PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2880 intel_de_read(dev_priv, pp_stat_reg),
2881 intel_de_read(dev_priv, pp_ctrl_reg));
2883 * If the panel wasn't on, delay before accessing aux channel
2885 if (!edp_have_panel_power(intel_dp)) {
2886 drm_dbg_kms(&dev_priv->drm,
2887 "[ENCODER:%d:%s] panel power wasn't enabled\n",
2888 intel_dig_port->base.base.base.id,
2889 intel_dig_port->base.base.name);
2890 msleep(intel_dp->panel_power_up_delay);
2893 return need_to_disable;
2897 * Must be paired with intel_edp_panel_vdd_off() or
2898 * intel_edp_panel_off().
2899 * Nested calls to these functions are not allowed since
2900 * we drop the lock. Caller must use some higher level
2901 * locking to prevent nested calls from other threads.
2903 void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
2905 intel_wakeref_t wakeref;
2908 if (!intel_dp_is_edp(intel_dp))
2912 with_pps_lock(intel_dp, wakeref)
2913 vdd = edp_panel_vdd_on(intel_dp);
2914 I915_STATE_WARN(!vdd, "[ENCODER:%d:%s] VDD already requested on\n",
2915 dp_to_dig_port(intel_dp)->base.base.base.id,
2916 dp_to_dig_port(intel_dp)->base.base.name);
2919 static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
2921 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2922 struct intel_digital_port *intel_dig_port =
2923 dp_to_dig_port(intel_dp);
2925 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2927 lockdep_assert_held(&dev_priv->pps_mutex);
2929 drm_WARN_ON(&dev_priv->drm, intel_dp->want_panel_vdd);
2931 if (!edp_have_panel_vdd(intel_dp))
2934 drm_dbg_kms(&dev_priv->drm, "Turning [ENCODER:%d:%s] VDD off\n",
2935 intel_dig_port->base.base.base.id,
2936 intel_dig_port->base.base.name);
2938 pp = ilk_get_pp_control(intel_dp);
2939 pp &= ~EDP_FORCE_VDD;
2941 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2942 pp_stat_reg = _pp_stat_reg(intel_dp);
2944 intel_de_write(dev_priv, pp_ctrl_reg, pp);
2945 intel_de_posting_read(dev_priv, pp_ctrl_reg);
2947 /* Make sure sequencer is idle before allowing subsequent activity */
2948 drm_dbg_kms(&dev_priv->drm, "PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2949 intel_de_read(dev_priv, pp_stat_reg),
2950 intel_de_read(dev_priv, pp_ctrl_reg));
2952 if ((pp & PANEL_POWER_ON) == 0)
2953 intel_dp->panel_power_off_time = ktime_get_boottime();
2955 intel_display_power_put_unchecked(dev_priv,
2956 intel_aux_power_domain(intel_dig_port));
2959 static void edp_panel_vdd_work(struct work_struct *__work)
2961 struct intel_dp *intel_dp =
2962 container_of(to_delayed_work(__work),
2963 struct intel_dp, panel_vdd_work);
2964 intel_wakeref_t wakeref;
2966 with_pps_lock(intel_dp, wakeref) {
2967 if (!intel_dp->want_panel_vdd)
2968 edp_panel_vdd_off_sync(intel_dp);
2972 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2974 unsigned long delay;
2977 * Queue the timer to fire a long time from now (relative to the power
2978 * down delay) to keep the panel power up across a sequence of
2981 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2982 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2986 * Must be paired with edp_panel_vdd_on().
2987 * Must hold pps_mutex around the whole on/off sequence.
2988 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2990 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
2992 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
2994 lockdep_assert_held(&dev_priv->pps_mutex);
2996 if (!intel_dp_is_edp(intel_dp))
2999 I915_STATE_WARN(!intel_dp->want_panel_vdd, "[ENCODER:%d:%s] VDD not forced on",
3000 dp_to_dig_port(intel_dp)->base.base.base.id,
3001 dp_to_dig_port(intel_dp)->base.base.name);
3003 intel_dp->want_panel_vdd = false;
3006 edp_panel_vdd_off_sync(intel_dp);
3008 edp_panel_vdd_schedule_off(intel_dp);
3011 static void edp_panel_on(struct intel_dp *intel_dp)
3013 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3015 i915_reg_t pp_ctrl_reg;
3017 lockdep_assert_held(&dev_priv->pps_mutex);
3019 if (!intel_dp_is_edp(intel_dp))
3022 drm_dbg_kms(&dev_priv->drm, "Turn [ENCODER:%d:%s] panel power on\n",
3023 dp_to_dig_port(intel_dp)->base.base.base.id,
3024 dp_to_dig_port(intel_dp)->base.base.name);
3026 if (drm_WARN(&dev_priv->drm, edp_have_panel_power(intel_dp),
3027 "[ENCODER:%d:%s] panel power already on\n",
3028 dp_to_dig_port(intel_dp)->base.base.base.id,
3029 dp_to_dig_port(intel_dp)->base.base.name))
3032 wait_panel_power_cycle(intel_dp);
3034 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
3035 pp = ilk_get_pp_control(intel_dp);
3036 if (IS_GEN(dev_priv, 5)) {
3037 /* ILK workaround: disable reset around power sequence */
3038 pp &= ~PANEL_POWER_RESET;
3039 intel_de_write(dev_priv, pp_ctrl_reg, pp);
3040 intel_de_posting_read(dev_priv, pp_ctrl_reg);
3043 pp |= PANEL_POWER_ON;
3044 if (!IS_GEN(dev_priv, 5))
3045 pp |= PANEL_POWER_RESET;
3047 intel_de_write(dev_priv, pp_ctrl_reg, pp);
3048 intel_de_posting_read(dev_priv, pp_ctrl_reg);
3050 wait_panel_on(intel_dp);
3051 intel_dp->last_power_on = jiffies;
3053 if (IS_GEN(dev_priv, 5)) {
3054 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
3055 intel_de_write(dev_priv, pp_ctrl_reg, pp);
3056 intel_de_posting_read(dev_priv, pp_ctrl_reg);
3060 void intel_edp_panel_on(struct intel_dp *intel_dp)
3062 intel_wakeref_t wakeref;
3064 if (!intel_dp_is_edp(intel_dp))
3067 with_pps_lock(intel_dp, wakeref)
3068 edp_panel_on(intel_dp);
3072 static void edp_panel_off(struct intel_dp *intel_dp)
3074 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3075 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3077 i915_reg_t pp_ctrl_reg;
3079 lockdep_assert_held(&dev_priv->pps_mutex);
3081 if (!intel_dp_is_edp(intel_dp))
3084 drm_dbg_kms(&dev_priv->drm, "Turn [ENCODER:%d:%s] panel power off\n",
3085 dig_port->base.base.base.id, dig_port->base.base.name);
3087 drm_WARN(&dev_priv->drm, !intel_dp->want_panel_vdd,
3088 "Need [ENCODER:%d:%s] VDD to turn off panel\n",
3089 dig_port->base.base.base.id, dig_port->base.base.name);
3091 pp = ilk_get_pp_control(intel_dp);
3092 /* We need to switch off panel power _and_ force vdd, for otherwise some
3093 * panels get very unhappy and cease to work. */
3094 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
3097 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
3099 intel_dp->want_panel_vdd = false;
3101 intel_de_write(dev_priv, pp_ctrl_reg, pp);
3102 intel_de_posting_read(dev_priv, pp_ctrl_reg);
3104 wait_panel_off(intel_dp);
3105 intel_dp->panel_power_off_time = ktime_get_boottime();
3107 /* We got a reference when we enabled the VDD. */
3108 intel_display_power_put_unchecked(dev_priv, intel_aux_power_domain(dig_port));
3111 void intel_edp_panel_off(struct intel_dp *intel_dp)
3113 intel_wakeref_t wakeref;
3115 if (!intel_dp_is_edp(intel_dp))
3118 with_pps_lock(intel_dp, wakeref)
3119 edp_panel_off(intel_dp);
3122 /* Enable backlight in the panel power control. */
3123 static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
3125 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3126 intel_wakeref_t wakeref;
3129 * If we enable the backlight right away following a panel power
3130 * on, we may see slight flicker as the panel syncs with the eDP
3131 * link. So delay a bit to make sure the image is solid before
3132 * allowing it to appear.
3134 wait_backlight_on(intel_dp);
3136 with_pps_lock(intel_dp, wakeref) {
3137 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
3140 pp = ilk_get_pp_control(intel_dp);
3141 pp |= EDP_BLC_ENABLE;
3143 intel_de_write(dev_priv, pp_ctrl_reg, pp);
3144 intel_de_posting_read(dev_priv, pp_ctrl_reg);
3148 /* Enable backlight PWM and backlight PP control. */
3149 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
3150 const struct drm_connector_state *conn_state)
3152 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(conn_state->best_encoder));
3153 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
3155 if (!intel_dp_is_edp(intel_dp))
3158 drm_dbg_kms(&i915->drm, "\n");
3160 intel_panel_enable_backlight(crtc_state, conn_state);
3161 _intel_edp_backlight_on(intel_dp);
3164 /* Disable backlight in the panel power control. */
3165 static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
3167 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3168 intel_wakeref_t wakeref;
3170 if (!intel_dp_is_edp(intel_dp))
3173 with_pps_lock(intel_dp, wakeref) {
3174 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
3177 pp = ilk_get_pp_control(intel_dp);
3178 pp &= ~EDP_BLC_ENABLE;
3180 intel_de_write(dev_priv, pp_ctrl_reg, pp);
3181 intel_de_posting_read(dev_priv, pp_ctrl_reg);
3184 intel_dp->last_backlight_off = jiffies;
3185 edp_wait_backlight_off(intel_dp);
3188 /* Disable backlight PP control and backlight PWM. */
3189 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
3191 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(old_conn_state->best_encoder));
3192 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
3194 if (!intel_dp_is_edp(intel_dp))
3197 drm_dbg_kms(&i915->drm, "\n");
3199 _intel_edp_backlight_off(intel_dp);
3200 intel_panel_disable_backlight(old_conn_state);
3204 * Hook for controlling the panel power control backlight through the bl_power
3205 * sysfs attribute. Take care to handle multiple calls.
3207 static void intel_edp_backlight_power(struct intel_connector *connector,
3210 struct drm_i915_private *i915 = to_i915(connector->base.dev);
3211 struct intel_dp *intel_dp = intel_attached_dp(connector);
3212 intel_wakeref_t wakeref;
3216 with_pps_lock(intel_dp, wakeref)
3217 is_enabled = ilk_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
3218 if (is_enabled == enable)
3221 drm_dbg_kms(&i915->drm, "panel power control backlight %s\n",
3222 enable ? "enable" : "disable");
3225 _intel_edp_backlight_on(intel_dp);
3227 _intel_edp_backlight_off(intel_dp);
3230 static void assert_dp_port(struct intel_dp *intel_dp, bool state)
3232 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3233 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3234 bool cur_state = intel_de_read(dev_priv, intel_dp->output_reg) & DP_PORT_EN;
3236 I915_STATE_WARN(cur_state != state,
3237 "[ENCODER:%d:%s] state assertion failure (expected %s, current %s)\n",
3238 dig_port->base.base.base.id, dig_port->base.base.name,
3239 onoff(state), onoff(cur_state));
3241 #define assert_dp_port_disabled(d) assert_dp_port((d), false)
3243 static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
3245 bool cur_state = intel_de_read(dev_priv, DP_A) & DP_PLL_ENABLE;
3247 I915_STATE_WARN(cur_state != state,
3248 "eDP PLL state assertion failure (expected %s, current %s)\n",
3249 onoff(state), onoff(cur_state));
3251 #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
3252 #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
3254 static void ilk_edp_pll_on(struct intel_dp *intel_dp,
3255 const struct intel_crtc_state *pipe_config)
3257 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
3258 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3260 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
3261 assert_dp_port_disabled(intel_dp);
3262 assert_edp_pll_disabled(dev_priv);
3264 drm_dbg_kms(&dev_priv->drm, "enabling eDP PLL for clock %d\n",
3265 pipe_config->port_clock);
3267 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
3269 if (pipe_config->port_clock == 162000)
3270 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
3272 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
3274 intel_de_write(dev_priv, DP_A, intel_dp->DP);
3275 intel_de_posting_read(dev_priv, DP_A);
3279 * [DevILK] Work around required when enabling DP PLL
3280 * while a pipe is enabled going to FDI:
3281 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
3282 * 2. Program DP PLL enable
3284 if (IS_GEN(dev_priv, 5))
3285 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
3287 intel_dp->DP |= DP_PLL_ENABLE;
3289 intel_de_write(dev_priv, DP_A, intel_dp->DP);
3290 intel_de_posting_read(dev_priv, DP_A);
3294 static void ilk_edp_pll_off(struct intel_dp *intel_dp,
3295 const struct intel_crtc_state *old_crtc_state)
3297 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
3298 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3300 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
3301 assert_dp_port_disabled(intel_dp);
3302 assert_edp_pll_enabled(dev_priv);
3304 drm_dbg_kms(&dev_priv->drm, "disabling eDP PLL\n");
3306 intel_dp->DP &= ~DP_PLL_ENABLE;
3308 intel_de_write(dev_priv, DP_A, intel_dp->DP);
3309 intel_de_posting_read(dev_priv, DP_A);
3313 static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
3316 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
3317 * be capable of signalling downstream hpd with a long pulse.
3318 * Whether or not that means D3 is safe to use is not clear,
3319 * but let's assume so until proven otherwise.
3321 * FIXME should really check all downstream ports...
3323 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
3324 drm_dp_is_branch(intel_dp->dpcd) &&
3325 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
3328 void intel_dp_sink_set_decompression_state(struct intel_dp *intel_dp,
3329 const struct intel_crtc_state *crtc_state,
3332 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
3335 if (!crtc_state->dsc.compression_enable)
3338 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_DSC_ENABLE,
3339 enable ? DP_DECOMPRESSION_EN : 0);
3341 drm_dbg_kms(&i915->drm,
3342 "Failed to %s sink decompression state\n",
3343 enable ? "enable" : "disable");
3346 /* If the sink supports it, try to set the power state appropriately */
3347 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
3349 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
3352 /* Should have a valid DPCD by this point */
3353 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
3356 if (mode != DRM_MODE_DPMS_ON) {
3357 if (downstream_hpd_needs_d0(intel_dp))
3360 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
3363 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
3366 * When turning on, we need to retry for 1ms to give the sink
3369 for (i = 0; i < 3; i++) {
3370 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
3377 if (ret == 1 && lspcon->active)
3378 lspcon_wait_pcon_mode(lspcon);
3382 drm_dbg_kms(&i915->drm, "failed to %s sink power state\n",
3383 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
3386 static bool cpt_dp_port_selected(struct drm_i915_private *dev_priv,
3387 enum port port, enum pipe *pipe)
3391 for_each_pipe(dev_priv, p) {
3392 u32 val = intel_de_read(dev_priv, TRANS_DP_CTL(p));
3394 if ((val & TRANS_DP_PORT_SEL_MASK) == TRANS_DP_PORT_SEL(port)) {
3400 drm_dbg_kms(&dev_priv->drm, "No pipe for DP port %c found\n",
3403 /* must initialize pipe to something for the asserts */
3409 bool intel_dp_port_enabled(struct drm_i915_private *dev_priv,
3410 i915_reg_t dp_reg, enum port port,
3416 val = intel_de_read(dev_priv, dp_reg);
3418 ret = val & DP_PORT_EN;
3420 /* asserts want to know the pipe even if the port is disabled */
3421 if (IS_IVYBRIDGE(dev_priv) && port == PORT_A)
3422 *pipe = (val & DP_PIPE_SEL_MASK_IVB) >> DP_PIPE_SEL_SHIFT_IVB;
3423 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
3424 ret &= cpt_dp_port_selected(dev_priv, port, pipe);
3425 else if (IS_CHERRYVIEW(dev_priv))
3426 *pipe = (val & DP_PIPE_SEL_MASK_CHV) >> DP_PIPE_SEL_SHIFT_CHV;
3428 *pipe = (val & DP_PIPE_SEL_MASK) >> DP_PIPE_SEL_SHIFT;
3433 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
3436 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3437 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3438 intel_wakeref_t wakeref;
3441 wakeref = intel_display_power_get_if_enabled(dev_priv,
3442 encoder->power_domain);
3446 ret = intel_dp_port_enabled(dev_priv, intel_dp->output_reg,
3447 encoder->port, pipe);
3449 intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
3454 static void intel_dp_get_config(struct intel_encoder *encoder,
3455 struct intel_crtc_state *pipe_config)
3457 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3458 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3460 enum port port = encoder->port;
3461 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
3463 if (encoder->type == INTEL_OUTPUT_EDP)
3464 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
3466 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
3468 tmp = intel_de_read(dev_priv, intel_dp->output_reg);
3470 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
3472 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
3473 u32 trans_dp = intel_de_read(dev_priv,
3474 TRANS_DP_CTL(crtc->pipe));
3476 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
3477 flags |= DRM_MODE_FLAG_PHSYNC;
3479 flags |= DRM_MODE_FLAG_NHSYNC;
3481 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
3482 flags |= DRM_MODE_FLAG_PVSYNC;
3484 flags |= DRM_MODE_FLAG_NVSYNC;
3486 if (tmp & DP_SYNC_HS_HIGH)
3487 flags |= DRM_MODE_FLAG_PHSYNC;
3489 flags |= DRM_MODE_FLAG_NHSYNC;
3491 if (tmp & DP_SYNC_VS_HIGH)
3492 flags |= DRM_MODE_FLAG_PVSYNC;
3494 flags |= DRM_MODE_FLAG_NVSYNC;
3497 pipe_config->hw.adjusted_mode.flags |= flags;
3499 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
3500 pipe_config->limited_color_range = true;
3502 pipe_config->lane_count =
3503 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
3505 intel_dp_get_m_n(crtc, pipe_config);
3507 if (port == PORT_A) {
3508 if ((intel_de_read(dev_priv, DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
3509 pipe_config->port_clock = 162000;
3511 pipe_config->port_clock = 270000;
3514 pipe_config->hw.adjusted_mode.crtc_clock =
3515 intel_dotclock_calculate(pipe_config->port_clock,
3516 &pipe_config->dp_m_n);
3518 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
3519 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
3521 * This is a big fat ugly hack.
3523 * Some machines in UEFI boot mode provide us a VBT that has 18
3524 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
3525 * unknown we fail to light up. Yet the same BIOS boots up with
3526 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
3527 * max, not what it tells us to use.
3529 * Note: This will still be broken if the eDP panel is not lit
3530 * up by the BIOS, and thus we can't get the mode at module
3533 drm_dbg_kms(&dev_priv->drm,
3534 "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
3535 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
3536 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
3540 static void intel_disable_dp(struct intel_atomic_state *state,
3541 struct intel_encoder *encoder,
3542 const struct intel_crtc_state *old_crtc_state,
3543 const struct drm_connector_state *old_conn_state)
3545 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3547 intel_dp->link_trained = false;
3549 if (old_crtc_state->has_audio)
3550 intel_audio_codec_disable(encoder,
3551 old_crtc_state, old_conn_state);
3553 /* Make sure the panel is off before trying to change the mode. But also
3554 * ensure that we have vdd while we switch off the panel. */
3555 intel_edp_panel_vdd_on(intel_dp);
3556 intel_edp_backlight_off(old_conn_state);
3557 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
3558 intel_edp_panel_off(intel_dp);
3561 static void g4x_disable_dp(struct intel_atomic_state *state,
3562 struct intel_encoder *encoder,
3563 const struct intel_crtc_state *old_crtc_state,
3564 const struct drm_connector_state *old_conn_state)
3566 intel_disable_dp(state, encoder, old_crtc_state, old_conn_state);
3569 static void vlv_disable_dp(struct intel_atomic_state *state,
3570 struct intel_encoder *encoder,
3571 const struct intel_crtc_state *old_crtc_state,
3572 const struct drm_connector_state *old_conn_state)
3574 intel_disable_dp(state, encoder, old_crtc_state, old_conn_state);
3577 static void g4x_post_disable_dp(struct intel_atomic_state *state,
3578 struct intel_encoder *encoder,
3579 const struct intel_crtc_state *old_crtc_state,
3580 const struct drm_connector_state *old_conn_state)
3582 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3583 enum port port = encoder->port;
3586 * Bspec does not list a specific disable sequence for g4x DP.
3587 * Follow the ilk+ sequence (disable pipe before the port) for
3588 * g4x DP as it does not suffer from underruns like the normal
3589 * g4x modeset sequence (disable pipe after the port).
3591 intel_dp_link_down(encoder, old_crtc_state);
3593 /* Only ilk+ has port A */
3595 ilk_edp_pll_off(intel_dp, old_crtc_state);
3598 static void vlv_post_disable_dp(struct intel_atomic_state *state,
3599 struct intel_encoder *encoder,
3600 const struct intel_crtc_state *old_crtc_state,
3601 const struct drm_connector_state *old_conn_state)
3603 intel_dp_link_down(encoder, old_crtc_state);
3606 static void chv_post_disable_dp(struct intel_atomic_state *state,
3607 struct intel_encoder *encoder,
3608 const struct intel_crtc_state *old_crtc_state,
3609 const struct drm_connector_state *old_conn_state)
3611 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3613 intel_dp_link_down(encoder, old_crtc_state);
3615 vlv_dpio_get(dev_priv);
3617 /* Assert data lane reset */
3618 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
3620 vlv_dpio_put(dev_priv);
3624 _intel_dp_set_link_train(struct intel_dp *intel_dp,
3628 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3629 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3630 enum port port = intel_dig_port->base.port;
3631 u8 train_pat_mask = drm_dp_training_pattern_mask(intel_dp->dpcd);
3633 if (dp_train_pat & train_pat_mask)
3634 drm_dbg_kms(&dev_priv->drm,
3635 "Using DP training pattern TPS%d\n",
3636 dp_train_pat & train_pat_mask);
3638 if (HAS_DDI(dev_priv)) {
3639 u32 temp = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl);
3641 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
3642 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
3644 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
3646 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3647 switch (dp_train_pat & train_pat_mask) {
3648 case DP_TRAINING_PATTERN_DISABLE:
3649 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
3652 case DP_TRAINING_PATTERN_1:
3653 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
3655 case DP_TRAINING_PATTERN_2:
3656 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
3658 case DP_TRAINING_PATTERN_3:
3659 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
3661 case DP_TRAINING_PATTERN_4:
3662 temp |= DP_TP_CTL_LINK_TRAIN_PAT4;
3665 intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, temp);
3667 } else if ((IS_IVYBRIDGE(dev_priv) && port == PORT_A) ||
3668 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
3669 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
3671 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
3672 case DP_TRAINING_PATTERN_DISABLE:
3673 *DP |= DP_LINK_TRAIN_OFF_CPT;
3675 case DP_TRAINING_PATTERN_1:
3676 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
3678 case DP_TRAINING_PATTERN_2:
3679 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
3681 case DP_TRAINING_PATTERN_3:
3682 drm_dbg_kms(&dev_priv->drm,
3683 "TPS3 not supported, using TPS2 instead\n");
3684 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
3689 *DP &= ~DP_LINK_TRAIN_MASK;
3691 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
3692 case DP_TRAINING_PATTERN_DISABLE:
3693 *DP |= DP_LINK_TRAIN_OFF;
3695 case DP_TRAINING_PATTERN_1:
3696 *DP |= DP_LINK_TRAIN_PAT_1;
3698 case DP_TRAINING_PATTERN_2:
3699 *DP |= DP_LINK_TRAIN_PAT_2;
3701 case DP_TRAINING_PATTERN_3:
3702 drm_dbg_kms(&dev_priv->drm,
3703 "TPS3 not supported, using TPS2 instead\n");
3704 *DP |= DP_LINK_TRAIN_PAT_2;
3710 static void intel_dp_enable_port(struct intel_dp *intel_dp,
3711 const struct intel_crtc_state *old_crtc_state)
3713 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3715 /* enable with pattern 1 (as per spec) */
3717 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
3720 * Magic for VLV/CHV. We _must_ first set up the register
3721 * without actually enabling the port, and then do another
3722 * write to enable the port. Otherwise link training will
3723 * fail when the power sequencer is freshly used for this port.
3725 intel_dp->DP |= DP_PORT_EN;
3726 if (old_crtc_state->has_audio)
3727 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
3729 intel_de_write(dev_priv, intel_dp->output_reg, intel_dp->DP);
3730 intel_de_posting_read(dev_priv, intel_dp->output_reg);
3733 static void intel_enable_dp(struct intel_atomic_state *state,
3734 struct intel_encoder *encoder,
3735 const struct intel_crtc_state *pipe_config,
3736 const struct drm_connector_state *conn_state)
3738 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3739 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3740 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
3741 u32 dp_reg = intel_de_read(dev_priv, intel_dp->output_reg);
3742 enum pipe pipe = crtc->pipe;
3743 intel_wakeref_t wakeref;
3745 if (drm_WARN_ON(&dev_priv->drm, dp_reg & DP_PORT_EN))
3748 with_pps_lock(intel_dp, wakeref) {
3749 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3750 vlv_init_panel_power_sequencer(encoder, pipe_config);
3752 intel_dp_enable_port(intel_dp, pipe_config);
3754 edp_panel_vdd_on(intel_dp);
3755 edp_panel_on(intel_dp);
3756 edp_panel_vdd_off(intel_dp, true);
3759 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3760 unsigned int lane_mask = 0x0;
3762 if (IS_CHERRYVIEW(dev_priv))
3763 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
3765 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
3769 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
3770 intel_dp_start_link_train(intel_dp);
3771 intel_dp_stop_link_train(intel_dp);
3773 if (pipe_config->has_audio) {
3774 drm_dbg(&dev_priv->drm, "Enabling DP audio on pipe %c\n",
3776 intel_audio_codec_enable(encoder, pipe_config, conn_state);
3780 static void g4x_enable_dp(struct intel_atomic_state *state,
3781 struct intel_encoder *encoder,
3782 const struct intel_crtc_state *pipe_config,
3783 const struct drm_connector_state *conn_state)
3785 intel_enable_dp(state, encoder, pipe_config, conn_state);
3786 intel_edp_backlight_on(pipe_config, conn_state);
3789 static void vlv_enable_dp(struct intel_atomic_state *state,
3790 struct intel_encoder *encoder,
3791 const struct intel_crtc_state *pipe_config,
3792 const struct drm_connector_state *conn_state)
3794 intel_edp_backlight_on(pipe_config, conn_state);
3797 static void g4x_pre_enable_dp(struct intel_atomic_state *state,
3798 struct intel_encoder *encoder,
3799 const struct intel_crtc_state *pipe_config,
3800 const struct drm_connector_state *conn_state)
3802 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3803 enum port port = encoder->port;
3805 intel_dp_prepare(encoder, pipe_config);
3807 /* Only ilk+ has port A */
3809 ilk_edp_pll_on(intel_dp, pipe_config);
3812 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
3814 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3815 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
3816 enum pipe pipe = intel_dp->pps_pipe;
3817 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
3819 drm_WARN_ON(&dev_priv->drm, intel_dp->active_pipe != INVALID_PIPE);
3821 if (drm_WARN_ON(&dev_priv->drm, pipe != PIPE_A && pipe != PIPE_B))
3824 edp_panel_vdd_off_sync(intel_dp);
3827 * VLV seems to get confused when multiple power sequencers
3828 * have the same port selected (even if only one has power/vdd
3829 * enabled). The failure manifests as vlv_wait_port_ready() failing
3830 * CHV on the other hand doesn't seem to mind having the same port
3831 * selected in multiple power sequencers, but let's clear the
3832 * port select always when logically disconnecting a power sequencer
3835 drm_dbg_kms(&dev_priv->drm,
3836 "detaching pipe %c power sequencer from [ENCODER:%d:%s]\n",
3837 pipe_name(pipe), intel_dig_port->base.base.base.id,
3838 intel_dig_port->base.base.name);
3839 intel_de_write(dev_priv, pp_on_reg, 0);
3840 intel_de_posting_read(dev_priv, pp_on_reg);
3842 intel_dp->pps_pipe = INVALID_PIPE;
3845 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
3848 struct intel_encoder *encoder;
3850 lockdep_assert_held(&dev_priv->pps_mutex);
3852 for_each_intel_dp(&dev_priv->drm, encoder) {
3853 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3855 drm_WARN(&dev_priv->drm, intel_dp->active_pipe == pipe,
3856 "stealing pipe %c power sequencer from active [ENCODER:%d:%s]\n",
3857 pipe_name(pipe), encoder->base.base.id,
3858 encoder->base.name);
3860 if (intel_dp->pps_pipe != pipe)
3863 drm_dbg_kms(&dev_priv->drm,
3864 "stealing pipe %c power sequencer from [ENCODER:%d:%s]\n",
3865 pipe_name(pipe), encoder->base.base.id,
3866 encoder->base.name);
3868 /* make sure vdd is off before we steal it */
3869 vlv_detach_power_sequencer(intel_dp);
3873 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
3874 const struct intel_crtc_state *crtc_state)
3876 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3877 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3878 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3880 lockdep_assert_held(&dev_priv->pps_mutex);
3882 drm_WARN_ON(&dev_priv->drm, intel_dp->active_pipe != INVALID_PIPE);
3884 if (intel_dp->pps_pipe != INVALID_PIPE &&
3885 intel_dp->pps_pipe != crtc->pipe) {
3887 * If another power sequencer was being used on this
3888 * port previously make sure to turn off vdd there while
3889 * we still have control of it.
3891 vlv_detach_power_sequencer(intel_dp);
3895 * We may be stealing the power
3896 * sequencer from another port.
3898 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
3900 intel_dp->active_pipe = crtc->pipe;
3902 if (!intel_dp_is_edp(intel_dp))
3905 /* now it's all ours */
3906 intel_dp->pps_pipe = crtc->pipe;
3908 drm_dbg_kms(&dev_priv->drm,
3909 "initializing pipe %c power sequencer for [ENCODER:%d:%s]\n",
3910 pipe_name(intel_dp->pps_pipe), encoder->base.base.id,
3911 encoder->base.name);
3913 /* init power sequencer on this pipe and port */
3914 intel_dp_init_panel_power_sequencer(intel_dp);
3915 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
3918 static void vlv_pre_enable_dp(struct intel_atomic_state *state,
3919 struct intel_encoder *encoder,
3920 const struct intel_crtc_state *pipe_config,
3921 const struct drm_connector_state *conn_state)
3923 vlv_phy_pre_encoder_enable(encoder, pipe_config);
3925 intel_enable_dp(state, encoder, pipe_config, conn_state);
3928 static void vlv_dp_pre_pll_enable(struct intel_atomic_state *state,
3929 struct intel_encoder *encoder,
3930 const struct intel_crtc_state *pipe_config,
3931 const struct drm_connector_state *conn_state)
3933 intel_dp_prepare(encoder, pipe_config);
3935 vlv_phy_pre_pll_enable(encoder, pipe_config);
3938 static void chv_pre_enable_dp(struct intel_atomic_state *state,
3939 struct intel_encoder *encoder,
3940 const struct intel_crtc_state *pipe_config,
3941 const struct drm_connector_state *conn_state)
3943 chv_phy_pre_encoder_enable(encoder, pipe_config);
3945 intel_enable_dp(state, encoder, pipe_config, conn_state);
3947 /* Second common lane will stay alive on its own now */
3948 chv_phy_release_cl2_override(encoder);
3951 static void chv_dp_pre_pll_enable(struct intel_atomic_state *state,
3952 struct intel_encoder *encoder,
3953 const struct intel_crtc_state *pipe_config,
3954 const struct drm_connector_state *conn_state)
3956 intel_dp_prepare(encoder, pipe_config);
3958 chv_phy_pre_pll_enable(encoder, pipe_config);
3961 static void chv_dp_post_pll_disable(struct intel_atomic_state *state,
3962 struct intel_encoder *encoder,
3963 const struct intel_crtc_state *old_crtc_state,
3964 const struct drm_connector_state *old_conn_state)
3966 chv_phy_post_pll_disable(encoder, old_crtc_state);
3970 * Fetch AUX CH registers 0x202 - 0x207 which contain
3971 * link status information
3974 intel_dp_get_link_status(struct intel_dp *intel_dp, u8 link_status[DP_LINK_STATUS_SIZE])
3976 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3977 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
3980 /* These are source-specific values. */
3982 intel_dp_voltage_max(struct intel_dp *intel_dp)
3984 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
3985 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3986 enum port port = encoder->port;
3988 if (HAS_DDI(dev_priv))
3989 return intel_ddi_dp_voltage_max(encoder);
3990 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3991 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3992 else if (IS_IVYBRIDGE(dev_priv) && port == PORT_A)
3993 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3994 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
3995 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3997 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
4001 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, u8 voltage_swing)
4003 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
4004 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4005 enum port port = encoder->port;
4007 if (HAS_DDI(dev_priv)) {
4008 return intel_ddi_dp_pre_emphasis_max(encoder, voltage_swing);
4009 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
4010 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
4011 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4012 return DP_TRAIN_PRE_EMPH_LEVEL_3;
4013 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4014 return DP_TRAIN_PRE_EMPH_LEVEL_2;
4015 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4016 return DP_TRAIN_PRE_EMPH_LEVEL_1;
4017 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
4019 return DP_TRAIN_PRE_EMPH_LEVEL_0;
4021 } else if (IS_IVYBRIDGE(dev_priv) && port == PORT_A) {
4022 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
4023 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4024 return DP_TRAIN_PRE_EMPH_LEVEL_2;
4025 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4026 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4027 return DP_TRAIN_PRE_EMPH_LEVEL_1;
4029 return DP_TRAIN_PRE_EMPH_LEVEL_0;
4032 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
4033 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4034 return DP_TRAIN_PRE_EMPH_LEVEL_2;
4035 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4036 return DP_TRAIN_PRE_EMPH_LEVEL_2;
4037 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4038 return DP_TRAIN_PRE_EMPH_LEVEL_1;
4039 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
4041 return DP_TRAIN_PRE_EMPH_LEVEL_0;
4046 static u32 vlv_signal_levels(struct intel_dp *intel_dp)
4048 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4049 unsigned long demph_reg_value, preemph_reg_value,
4050 uniqtranscale_reg_value;
4051 u8 train_set = intel_dp->train_set[0];
4053 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
4054 case DP_TRAIN_PRE_EMPH_LEVEL_0:
4055 preemph_reg_value = 0x0004000;
4056 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4057 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4058 demph_reg_value = 0x2B405555;
4059 uniqtranscale_reg_value = 0x552AB83A;
4061 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4062 demph_reg_value = 0x2B404040;
4063 uniqtranscale_reg_value = 0x5548B83A;
4065 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4066 demph_reg_value = 0x2B245555;
4067 uniqtranscale_reg_value = 0x5560B83A;
4069 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
4070 demph_reg_value = 0x2B405555;
4071 uniqtranscale_reg_value = 0x5598DA3A;
4077 case DP_TRAIN_PRE_EMPH_LEVEL_1:
4078 preemph_reg_value = 0x0002000;
4079 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4080 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4081 demph_reg_value = 0x2B404040;
4082 uniqtranscale_reg_value = 0x5552B83A;
4084 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4085 demph_reg_value = 0x2B404848;
4086 uniqtranscale_reg_value = 0x5580B83A;
4088 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4089 demph_reg_value = 0x2B404040;
4090 uniqtranscale_reg_value = 0x55ADDA3A;
4096 case DP_TRAIN_PRE_EMPH_LEVEL_2:
4097 preemph_reg_value = 0x0000000;
4098 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4099 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4100 demph_reg_value = 0x2B305555;
4101 uniqtranscale_reg_value = 0x5570B83A;
4103 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4104 demph_reg_value = 0x2B2B4040;
4105 uniqtranscale_reg_value = 0x55ADDA3A;
4111 case DP_TRAIN_PRE_EMPH_LEVEL_3:
4112 preemph_reg_value = 0x0006000;
4113 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4114 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4115 demph_reg_value = 0x1B405555;
4116 uniqtranscale_reg_value = 0x55ADDA3A;
4126 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
4127 uniqtranscale_reg_value, 0);
4132 static u32 chv_signal_levels(struct intel_dp *intel_dp)
4134 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4135 u32 deemph_reg_value, margin_reg_value;
4136 bool uniq_trans_scale = false;
4137 u8 train_set = intel_dp->train_set[0];
4139 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
4140 case DP_TRAIN_PRE_EMPH_LEVEL_0:
4141 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4142 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4143 deemph_reg_value = 128;
4144 margin_reg_value = 52;
4146 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4147 deemph_reg_value = 128;
4148 margin_reg_value = 77;
4150 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4151 deemph_reg_value = 128;
4152 margin_reg_value = 102;
4154 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
4155 deemph_reg_value = 128;
4156 margin_reg_value = 154;
4157 uniq_trans_scale = true;
4163 case DP_TRAIN_PRE_EMPH_LEVEL_1:
4164 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4165 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4166 deemph_reg_value = 85;
4167 margin_reg_value = 78;
4169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4170 deemph_reg_value = 85;
4171 margin_reg_value = 116;
4173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4174 deemph_reg_value = 85;
4175 margin_reg_value = 154;
4181 case DP_TRAIN_PRE_EMPH_LEVEL_2:
4182 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4183 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4184 deemph_reg_value = 64;
4185 margin_reg_value = 104;
4187 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4188 deemph_reg_value = 64;
4189 margin_reg_value = 154;
4195 case DP_TRAIN_PRE_EMPH_LEVEL_3:
4196 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4197 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4198 deemph_reg_value = 43;
4199 margin_reg_value = 154;
4209 chv_set_phy_signal_level(encoder, deemph_reg_value,
4210 margin_reg_value, uniq_trans_scale);
4216 g4x_signal_levels(u8 train_set)
4218 u32 signal_levels = 0;
4220 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
4221 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
4223 signal_levels |= DP_VOLTAGE_0_4;
4225 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
4226 signal_levels |= DP_VOLTAGE_0_6;
4228 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
4229 signal_levels |= DP_VOLTAGE_0_8;
4231 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
4232 signal_levels |= DP_VOLTAGE_1_2;
4235 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
4236 case DP_TRAIN_PRE_EMPH_LEVEL_0:
4238 signal_levels |= DP_PRE_EMPHASIS_0;
4240 case DP_TRAIN_PRE_EMPH_LEVEL_1:
4241 signal_levels |= DP_PRE_EMPHASIS_3_5;
4243 case DP_TRAIN_PRE_EMPH_LEVEL_2:
4244 signal_levels |= DP_PRE_EMPHASIS_6;
4246 case DP_TRAIN_PRE_EMPH_LEVEL_3:
4247 signal_levels |= DP_PRE_EMPHASIS_9_5;
4250 return signal_levels;
4253 /* SNB CPU eDP voltage swing and pre-emphasis control */
4255 snb_cpu_edp_signal_levels(u8 train_set)
4257 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
4258 DP_TRAIN_PRE_EMPHASIS_MASK);
4259 switch (signal_levels) {
4260 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
4261 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
4262 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
4263 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
4264 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
4265 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
4266 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
4267 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
4268 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
4269 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
4270 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
4271 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
4272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
4273 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
4275 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
4276 "0x%x\n", signal_levels);
4277 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
4281 /* IVB CPU eDP voltage swing and pre-emphasis control */
4283 ivb_cpu_edp_signal_levels(u8 train_set)
4285 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
4286 DP_TRAIN_PRE_EMPHASIS_MASK);
4287 switch (signal_levels) {
4288 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
4289 return EDP_LINK_TRAIN_400MV_0DB_IVB;
4290 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
4291 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
4292 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
4293 return EDP_LINK_TRAIN_400MV_6DB_IVB;
4295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
4296 return EDP_LINK_TRAIN_600MV_0DB_IVB;
4297 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
4298 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
4300 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
4301 return EDP_LINK_TRAIN_800MV_0DB_IVB;
4302 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
4303 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
4306 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
4307 "0x%x\n", signal_levels);
4308 return EDP_LINK_TRAIN_500MV_0DB_IVB;
4313 intel_dp_set_signal_levels(struct intel_dp *intel_dp)
4315 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
4316 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4317 enum port port = intel_dig_port->base.port;
4318 u32 signal_levels, mask = 0;
4319 u8 train_set = intel_dp->train_set[0];
4321 if (IS_GEN9_LP(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
4322 signal_levels = bxt_signal_levels(intel_dp);
4323 } else if (HAS_DDI(dev_priv)) {
4324 signal_levels = ddi_signal_levels(intel_dp);
4325 mask = DDI_BUF_EMP_MASK;
4326 } else if (IS_CHERRYVIEW(dev_priv)) {
4327 signal_levels = chv_signal_levels(intel_dp);
4328 } else if (IS_VALLEYVIEW(dev_priv)) {
4329 signal_levels = vlv_signal_levels(intel_dp);
4330 } else if (IS_IVYBRIDGE(dev_priv) && port == PORT_A) {
4331 signal_levels = ivb_cpu_edp_signal_levels(train_set);
4332 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
4333 } else if (IS_GEN(dev_priv, 6) && port == PORT_A) {
4334 signal_levels = snb_cpu_edp_signal_levels(train_set);
4335 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
4337 signal_levels = g4x_signal_levels(train_set);
4338 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
4342 drm_dbg_kms(&dev_priv->drm, "Using signal levels %08x\n",
4345 drm_dbg_kms(&dev_priv->drm, "Using vswing level %d%s\n",
4346 train_set & DP_TRAIN_VOLTAGE_SWING_MASK,
4347 train_set & DP_TRAIN_MAX_SWING_REACHED ? " (max)" : "");
4348 drm_dbg_kms(&dev_priv->drm, "Using pre-emphasis level %d%s\n",
4349 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
4350 DP_TRAIN_PRE_EMPHASIS_SHIFT,
4351 train_set & DP_TRAIN_MAX_PRE_EMPHASIS_REACHED ?
4354 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
4356 intel_de_write(dev_priv, intel_dp->output_reg, intel_dp->DP);
4357 intel_de_posting_read(dev_priv, intel_dp->output_reg);
4361 intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
4364 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4365 struct drm_i915_private *dev_priv =
4366 to_i915(intel_dig_port->base.base.dev);
4368 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
4370 intel_de_write(dev_priv, intel_dp->output_reg, intel_dp->DP);
4371 intel_de_posting_read(dev_priv, intel_dp->output_reg);
4374 void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
4376 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
4377 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4378 enum port port = intel_dig_port->base.port;
4381 if (!HAS_DDI(dev_priv))
4384 val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl);
4385 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
4386 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
4387 intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val);
4390 * Until TGL on PORT_A we can have only eDP in SST mode. There the only
4391 * reason we need to set idle transmission mode is to work around a HW
4392 * issue where we enable the pipe while not in idle link-training mode.
4393 * In this case there is requirement to wait for a minimum number of
4394 * idle patterns to be sent.
4396 if (port == PORT_A && INTEL_GEN(dev_priv) < 12)
4399 if (intel_de_wait_for_set(dev_priv, intel_dp->regs.dp_tp_status,
4400 DP_TP_STATUS_IDLE_DONE, 1))
4401 drm_err(&dev_priv->drm,
4402 "Timed out waiting for DP idle patterns\n");
4406 intel_dp_link_down(struct intel_encoder *encoder,
4407 const struct intel_crtc_state *old_crtc_state)
4409 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4410 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4411 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
4412 enum port port = encoder->port;
4413 u32 DP = intel_dp->DP;
4415 if (drm_WARN_ON(&dev_priv->drm,
4416 (intel_de_read(dev_priv, intel_dp->output_reg) &
4420 drm_dbg_kms(&dev_priv->drm, "\n");
4422 if ((IS_IVYBRIDGE(dev_priv) && port == PORT_A) ||
4423 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
4424 DP &= ~DP_LINK_TRAIN_MASK_CPT;
4425 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
4427 DP &= ~DP_LINK_TRAIN_MASK;
4428 DP |= DP_LINK_TRAIN_PAT_IDLE;
4430 intel_de_write(dev_priv, intel_dp->output_reg, DP);
4431 intel_de_posting_read(dev_priv, intel_dp->output_reg);
4433 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
4434 intel_de_write(dev_priv, intel_dp->output_reg, DP);
4435 intel_de_posting_read(dev_priv, intel_dp->output_reg);
4438 * HW workaround for IBX, we need to move the port
4439 * to transcoder A after disabling it to allow the
4440 * matching HDMI port to be enabled on transcoder A.
4442 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
4444 * We get CPU/PCH FIFO underruns on the other pipe when
4445 * doing the workaround. Sweep them under the rug.
4447 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
4448 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
4450 /* always enable with pattern 1 (as per spec) */
4451 DP &= ~(DP_PIPE_SEL_MASK | DP_LINK_TRAIN_MASK);
4452 DP |= DP_PORT_EN | DP_PIPE_SEL(PIPE_A) |
4453 DP_LINK_TRAIN_PAT_1;
4454 intel_de_write(dev_priv, intel_dp->output_reg, DP);
4455 intel_de_posting_read(dev_priv, intel_dp->output_reg);
4458 intel_de_write(dev_priv, intel_dp->output_reg, DP);
4459 intel_de_posting_read(dev_priv, intel_dp->output_reg);
4461 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
4462 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
4463 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
4466 msleep(intel_dp->panel_power_down_delay);
4470 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
4471 intel_wakeref_t wakeref;
4473 with_pps_lock(intel_dp, wakeref)
4474 intel_dp->active_pipe = INVALID_PIPE;
4479 intel_dp_extended_receiver_capabilities(struct intel_dp *intel_dp)
4481 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
4485 * Prior to DP1.3 the bit represented by
4486 * DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT was reserved.
4487 * if it is set DP_DPCD_REV at 0000h could be at a value less than
4488 * the true capability of the panel. The only way to check is to
4489 * then compare 0000h and 2200h.
4491 if (!(intel_dp->dpcd[DP_TRAINING_AUX_RD_INTERVAL] &
4492 DP_EXTENDED_RECEIVER_CAP_FIELD_PRESENT))
4495 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DP13_DPCD_REV,
4496 &dpcd_ext, sizeof(dpcd_ext)) != sizeof(dpcd_ext)) {
4498 "DPCD failed read at extended capabilities\n");
4502 if (intel_dp->dpcd[DP_DPCD_REV] > dpcd_ext[DP_DPCD_REV]) {
4503 drm_dbg_kms(&i915->drm,
4504 "DPCD extended DPCD rev less than base DPCD rev\n");
4508 if (!memcmp(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext)))
4511 drm_dbg_kms(&i915->drm, "Base DPCD: %*ph\n",
4512 (int)sizeof(intel_dp->dpcd), intel_dp->dpcd);
4514 memcpy(intel_dp->dpcd, dpcd_ext, sizeof(dpcd_ext));
4518 intel_dp_read_dpcd(struct intel_dp *intel_dp)
4520 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
4522 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
4523 sizeof(intel_dp->dpcd)) < 0)
4524 return false; /* aux transfer failed */
4526 intel_dp_extended_receiver_capabilities(intel_dp);
4528 drm_dbg_kms(&i915->drm, "DPCD: %*ph\n", (int)sizeof(intel_dp->dpcd),
4531 return intel_dp->dpcd[DP_DPCD_REV] != 0;
4534 bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
4538 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
4541 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
4544 static void intel_dp_get_dsc_sink_cap(struct intel_dp *intel_dp)
4546 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
4549 * Clear the cached register set to avoid using stale values
4550 * for the sinks that do not support DSC.
4552 memset(intel_dp->dsc_dpcd, 0, sizeof(intel_dp->dsc_dpcd));
4554 /* Clear fec_capable to avoid using stale values */
4555 intel_dp->fec_capable = 0;
4557 /* Cache the DSC DPCD if eDP or DP rev >= 1.4 */
4558 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x14 ||
4559 intel_dp->edp_dpcd[0] >= DP_EDP_14) {
4560 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DSC_SUPPORT,
4562 sizeof(intel_dp->dsc_dpcd)) < 0)
4564 "Failed to read DPCD register 0x%x\n",
4567 drm_dbg_kms(&i915->drm, "DSC DPCD: %*ph\n",
4568 (int)sizeof(intel_dp->dsc_dpcd),
4569 intel_dp->dsc_dpcd);
4571 /* FEC is supported only on DP 1.4 */
4572 if (!intel_dp_is_edp(intel_dp) &&
4573 drm_dp_dpcd_readb(&intel_dp->aux, DP_FEC_CAPABILITY,
4574 &intel_dp->fec_capable) < 0)
4576 "Failed to read FEC DPCD register\n");
4578 drm_dbg_kms(&i915->drm, "FEC CAPABILITY: %x\n",
4579 intel_dp->fec_capable);
4584 intel_edp_init_dpcd(struct intel_dp *intel_dp)
4586 struct drm_i915_private *dev_priv =
4587 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
4589 /* this function is meant to be called only once */
4590 drm_WARN_ON(&dev_priv->drm, intel_dp->dpcd[DP_DPCD_REV] != 0);
4592 if (!intel_dp_read_dpcd(intel_dp))
4595 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4596 drm_dp_is_branch(intel_dp->dpcd));
4599 * Read the eDP display control registers.
4601 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
4602 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
4603 * set, but require eDP 1.4+ detection (e.g. for supported link rates
4604 * method). The display control registers should read zero if they're
4605 * not supported anyway.
4607 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
4608 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
4609 sizeof(intel_dp->edp_dpcd))
4610 drm_dbg_kms(&dev_priv->drm, "eDP DPCD: %*ph\n",
4611 (int)sizeof(intel_dp->edp_dpcd),
4612 intel_dp->edp_dpcd);
4615 * This has to be called after intel_dp->edp_dpcd is filled, PSR checks
4616 * for SET_POWER_CAPABLE bit in intel_dp->edp_dpcd[1]
4618 intel_psr_init_dpcd(intel_dp);
4620 /* Read the eDP 1.4+ supported link rates. */
4621 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
4622 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
4625 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
4626 sink_rates, sizeof(sink_rates));
4628 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
4629 int val = le16_to_cpu(sink_rates[i]);
4634 /* Value read multiplied by 200kHz gives the per-lane
4635 * link rate in kHz. The source rates are, however,
4636 * stored in terms of LS_Clk kHz. The full conversion
4637 * back to symbols is
4638 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
4640 intel_dp->sink_rates[i] = (val * 200) / 10;
4642 intel_dp->num_sink_rates = i;
4646 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
4647 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
4649 if (intel_dp->num_sink_rates)
4650 intel_dp->use_rate_select = true;
4652 intel_dp_set_sink_rates(intel_dp);
4654 intel_dp_set_common_rates(intel_dp);
4656 /* Read the eDP DSC DPCD registers */
4657 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4658 intel_dp_get_dsc_sink_cap(intel_dp);
4665 intel_dp_get_dpcd(struct intel_dp *intel_dp)
4667 if (!intel_dp_read_dpcd(intel_dp))
4671 * Don't clobber cached eDP rates. Also skip re-reading
4672 * the OUI/ID since we know it won't change.
4674 if (!intel_dp_is_edp(intel_dp)) {
4675 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4676 drm_dp_is_branch(intel_dp->dpcd));
4678 intel_dp_set_sink_rates(intel_dp);
4679 intel_dp_set_common_rates(intel_dp);
4683 * Some eDP panels do not set a valid value for sink count, that is why
4684 * it don't care about read it here and in intel_edp_init_dpcd().
4686 if (!intel_dp_is_edp(intel_dp) &&
4687 !drm_dp_has_quirk(&intel_dp->desc, 0,
4688 DP_DPCD_QUIRK_NO_SINK_COUNT)) {
4692 r = drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &count);
4697 * Sink count can change between short pulse hpd hence
4698 * a member variable in intel_dp will track any changes
4699 * between short pulse interrupts.
4701 intel_dp->sink_count = DP_GET_SINK_COUNT(count);
4704 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
4705 * a dongle is present but no display. Unless we require to know
4706 * if a dongle is present or not, we don't need to update
4707 * downstream port information. So, an early return here saves
4708 * time from performing other operations which are not required.
4710 if (!intel_dp->sink_count)
4714 if (!drm_dp_is_branch(intel_dp->dpcd))
4715 return true; /* native DP sink */
4717 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
4718 return true; /* no per-port downstream info */
4720 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
4721 intel_dp->downstream_ports,
4722 DP_MAX_DOWNSTREAM_PORTS) < 0)
4723 return false; /* downstream port status fetch failed */
4729 intel_dp_sink_can_mst(struct intel_dp *intel_dp)
4733 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
4736 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
4739 return mstm_cap & DP_MST_CAP;
4743 intel_dp_can_mst(struct intel_dp *intel_dp)
4745 return i915_modparams.enable_dp_mst &&
4746 intel_dp->can_mst &&
4747 intel_dp_sink_can_mst(intel_dp);
4751 intel_dp_configure_mst(struct intel_dp *intel_dp)
4753 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
4754 struct intel_encoder *encoder =
4755 &dp_to_dig_port(intel_dp)->base;
4756 bool sink_can_mst = intel_dp_sink_can_mst(intel_dp);
4758 drm_dbg_kms(&i915->drm,
4759 "[ENCODER:%d:%s] MST support: port: %s, sink: %s, modparam: %s\n",
4760 encoder->base.base.id, encoder->base.name,
4761 yesno(intel_dp->can_mst), yesno(sink_can_mst),
4762 yesno(i915_modparams.enable_dp_mst));
4764 if (!intel_dp->can_mst)
4767 intel_dp->is_mst = sink_can_mst &&
4768 i915_modparams.enable_dp_mst;
4770 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4775 intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4777 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4778 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4783 intel_dp_needs_vsc_sdp(const struct intel_crtc_state *crtc_state,
4784 const struct drm_connector_state *conn_state)
4787 * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication
4788 * of Color Encoding Format and Content Color Gamut], in order to
4789 * sending YCBCR 420 or HDR BT.2020 signals we should use DP VSC SDP.
4791 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
4794 switch (conn_state->colorspace) {
4795 case DRM_MODE_COLORIMETRY_SYCC_601:
4796 case DRM_MODE_COLORIMETRY_OPYCC_601:
4797 case DRM_MODE_COLORIMETRY_BT2020_YCC:
4798 case DRM_MODE_COLORIMETRY_BT2020_RGB:
4799 case DRM_MODE_COLORIMETRY_BT2020_CYCC:
4808 static ssize_t intel_dp_vsc_sdp_pack(const struct drm_dp_vsc_sdp *vsc,
4809 struct dp_sdp *sdp, size_t size)
4811 size_t length = sizeof(struct dp_sdp);
4816 memset(sdp, 0, size);
4819 * Prepare VSC Header for SU as per DP 1.4a spec, Table 2-119
4820 * VSC SDP Header Bytes
4822 sdp->sdp_header.HB0 = 0; /* Secondary-Data Packet ID = 0 */
4823 sdp->sdp_header.HB1 = vsc->sdp_type; /* Secondary-data Packet Type */
4824 sdp->sdp_header.HB2 = vsc->revision; /* Revision Number */
4825 sdp->sdp_header.HB3 = vsc->length; /* Number of Valid Data Bytes */
4827 /* VSC SDP Payload for DB16 through DB18 */
4828 /* Pixel Encoding and Colorimetry Formats */
4829 sdp->db[16] = (vsc->pixelformat & 0xf) << 4; /* DB16[7:4] */
4830 sdp->db[16] |= vsc->colorimetry & 0xf; /* DB16[3:0] */
4837 sdp->db[17] = 0x1; /* DB17[3:0] */
4849 MISSING_CASE(vsc->bpc);
4852 /* Dynamic Range and Component Bit Depth */
4853 if (vsc->dynamic_range == DP_DYNAMIC_RANGE_CTA)
4854 sdp->db[17] |= 0x80; /* DB17[7] */
4857 sdp->db[18] = vsc->content_type & 0x7;
4863 intel_dp_hdr_metadata_infoframe_sdp_pack(const struct hdmi_drm_infoframe *drm_infoframe,
4867 size_t length = sizeof(struct dp_sdp);
4868 const int infoframe_size = HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE;
4869 unsigned char buf[HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE];
4875 memset(sdp, 0, size);
4877 len = hdmi_drm_infoframe_pack_only(drm_infoframe, buf, sizeof(buf));
4879 DRM_DEBUG_KMS("buffer size is smaller than hdr metadata infoframe\n");
4883 if (len != infoframe_size) {
4884 DRM_DEBUG_KMS("wrong static hdr metadata size\n");
4889 * Set up the infoframe sdp packet for HDR static metadata.
4890 * Prepare VSC Header for SU as per DP 1.4a spec,
4891 * Table 2-100 and Table 2-101
4894 /* Secondary-Data Packet ID, 00h for non-Audio INFOFRAME */
4895 sdp->sdp_header.HB0 = 0;
4897 * Packet Type 80h + Non-audio INFOFRAME Type value
4898 * HDMI_INFOFRAME_TYPE_DRM: 0x87
4899 * - 80h + Non-audio INFOFRAME Type value
4900 * - InfoFrame Type: 0x07
4901 * [CTA-861-G Table-42 Dynamic Range and Mastering InfoFrame]
4903 sdp->sdp_header.HB1 = drm_infoframe->type;
4905 * Least Significant Eight Bits of (Data Byte Count – 1)
4906 * infoframe_size - 1
4908 sdp->sdp_header.HB2 = 0x1D;
4909 /* INFOFRAME SDP Version Number */
4910 sdp->sdp_header.HB3 = (0x13 << 2);
4911 /* CTA Header Byte 2 (INFOFRAME Version Number) */
4912 sdp->db[0] = drm_infoframe->version;
4913 /* CTA Header Byte 3 (Length of INFOFRAME): HDMI_DRM_INFOFRAME_SIZE */
4914 sdp->db[1] = drm_infoframe->length;
4916 * Copy HDMI_DRM_INFOFRAME_SIZE size from a buffer after
4917 * HDMI_INFOFRAME_HEADER_SIZE
4919 BUILD_BUG_ON(sizeof(sdp->db) < HDMI_DRM_INFOFRAME_SIZE + 2);
4920 memcpy(&sdp->db[2], &buf[HDMI_INFOFRAME_HEADER_SIZE],
4921 HDMI_DRM_INFOFRAME_SIZE);
4924 * Size of DP infoframe sdp packet for HDR static metadata consists of
4925 * - DP SDP Header(struct dp_sdp_header): 4 bytes
4926 * - Two Data Blocks: 2 bytes
4927 * CTA Header Byte2 (INFOFRAME Version Number)
4928 * CTA Header Byte3 (Length of INFOFRAME)
4929 * - HDMI_DRM_INFOFRAME_SIZE: 26 bytes
4931 * Prior to GEN11's GMP register size is identical to DP HDR static metadata
4932 * infoframe size. But GEN11+ has larger than that size, write_infoframe
4933 * will pad rest of the size.
4935 return sizeof(struct dp_sdp_header) + 2 + HDMI_DRM_INFOFRAME_SIZE;
4938 static void intel_write_dp_sdp(struct intel_encoder *encoder,
4939 const struct intel_crtc_state *crtc_state,
4942 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4943 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4944 struct dp_sdp sdp = {};
4947 if ((crtc_state->infoframes.enable &
4948 intel_hdmi_infoframe_enable(type)) == 0)
4953 len = intel_dp_vsc_sdp_pack(&crtc_state->infoframes.vsc, &sdp,
4956 case HDMI_PACKET_TYPE_GAMUT_METADATA:
4957 len = intel_dp_hdr_metadata_infoframe_sdp_pack(&crtc_state->infoframes.drm.drm,
4965 if (drm_WARN_ON(&dev_priv->drm, len < 0))
4968 intel_dig_port->write_infoframe(encoder, crtc_state, type, &sdp, len);
4971 void intel_dp_set_infoframes(struct intel_encoder *encoder,
4973 const struct intel_crtc_state *crtc_state,
4974 const struct drm_connector_state *conn_state)
4976 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4977 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4978 i915_reg_t reg = HSW_TVIDEO_DIP_CTL(crtc_state->cpu_transcoder);
4979 u32 dip_enable = VIDEO_DIP_ENABLE_AVI_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
4980 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW |
4981 VIDEO_DIP_ENABLE_SPD_HSW | VIDEO_DIP_ENABLE_DRM_GLK;
4982 u32 val = intel_de_read(dev_priv, reg);
4984 /* TODO: Add DSC case (DIP_ENABLE_PPS) */
4985 /* When PSR is enabled, this routine doesn't disable VSC DIP */
4986 if (intel_psr_enabled(intel_dp))
4989 val &= ~(dip_enable | VIDEO_DIP_ENABLE_VSC_HSW);
4992 intel_de_write(dev_priv, reg, val);
4993 intel_de_posting_read(dev_priv, reg);
4997 intel_de_write(dev_priv, reg, val);
4998 intel_de_posting_read(dev_priv, reg);
5000 /* When PSR is enabled, VSC SDP is handled by PSR routine */
5001 if (!intel_psr_enabled(intel_dp))
5002 intel_write_dp_sdp(encoder, crtc_state, DP_SDP_VSC);
5004 intel_write_dp_sdp(encoder, crtc_state, HDMI_PACKET_TYPE_GAMUT_METADATA);
5008 intel_dp_setup_vsc_sdp(struct intel_dp *intel_dp,
5009 const struct intel_crtc_state *crtc_state,
5010 const struct drm_connector_state *conn_state)
5012 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5013 struct dp_sdp vsc_sdp = {};
5015 /* Prepare VSC Header for SU as per DP 1.4a spec, Table 2-119 */
5016 vsc_sdp.sdp_header.HB0 = 0;
5017 vsc_sdp.sdp_header.HB1 = 0x7;
5020 * VSC SDP supporting 3D stereo, PSR2, and Pixel Encoding/
5021 * Colorimetry Format indication.
5023 vsc_sdp.sdp_header.HB2 = 0x5;
5026 * VSC SDP supporting 3D stereo, + PSR2, + Pixel Encoding/
5027 * Colorimetry Format indication (HB2 = 05h).
5029 vsc_sdp.sdp_header.HB3 = 0x13;
5031 /* DP 1.4a spec, Table 2-120 */
5032 switch (crtc_state->output_format) {
5033 case INTEL_OUTPUT_FORMAT_YCBCR444:
5034 vsc_sdp.db[16] = 0x1 << 4; /* YCbCr 444 : DB16[7:4] = 1h */
5036 case INTEL_OUTPUT_FORMAT_YCBCR420:
5037 vsc_sdp.db[16] = 0x3 << 4; /* YCbCr 420 : DB16[7:4] = 3h */
5039 case INTEL_OUTPUT_FORMAT_RGB:
5041 /* RGB: DB16[7:4] = 0h */
5045 switch (conn_state->colorspace) {
5046 case DRM_MODE_COLORIMETRY_BT709_YCC:
5047 vsc_sdp.db[16] |= 0x1;
5049 case DRM_MODE_COLORIMETRY_XVYCC_601:
5050 vsc_sdp.db[16] |= 0x2;
5052 case DRM_MODE_COLORIMETRY_XVYCC_709:
5053 vsc_sdp.db[16] |= 0x3;
5055 case DRM_MODE_COLORIMETRY_SYCC_601:
5056 vsc_sdp.db[16] |= 0x4;
5058 case DRM_MODE_COLORIMETRY_OPYCC_601:
5059 vsc_sdp.db[16] |= 0x5;
5061 case DRM_MODE_COLORIMETRY_BT2020_CYCC:
5062 case DRM_MODE_COLORIMETRY_BT2020_RGB:
5063 vsc_sdp.db[16] |= 0x6;
5065 case DRM_MODE_COLORIMETRY_BT2020_YCC:
5066 vsc_sdp.db[16] |= 0x7;
5068 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65:
5069 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER:
5070 vsc_sdp.db[16] |= 0x4; /* DCI-P3 (SMPTE RP 431-2) */
5073 /* sRGB (IEC 61966-2-1) / ITU-R BT.601: DB16[0:3] = 0h */
5075 /* RGB->YCBCR color conversion uses the BT.709 color space. */
5076 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5077 vsc_sdp.db[16] |= 0x1; /* 0x1, ITU-R BT.709 */
5082 * For pixel encoding formats YCbCr444, YCbCr422, YCbCr420, and Y Only,
5083 * the following Component Bit Depth values are defined:
5089 switch (crtc_state->pipe_bpp) {
5091 vsc_sdp.db[17] = 0x1;
5093 case 30: /* 10bpc */
5094 vsc_sdp.db[17] = 0x2;
5096 case 36: /* 12bpc */
5097 vsc_sdp.db[17] = 0x3;
5099 case 48: /* 16bpc */
5100 vsc_sdp.db[17] = 0x4;
5103 MISSING_CASE(crtc_state->pipe_bpp);
5108 * Dynamic Range (Bit 7)
5109 * 0 = VESA range, 1 = CTA range.
5110 * all YCbCr are always limited range
5112 vsc_sdp.db[17] |= 0x80;
5115 * Content Type (Bits 2:0)
5116 * 000b = Not defined.
5121 * All other values are RESERVED.
5122 * Note: See CTA-861-G for the definition and expected
5123 * processing by a stream sink for the above contect types.
5127 intel_dig_port->write_infoframe(&intel_dig_port->base,
5128 crtc_state, DP_SDP_VSC, &vsc_sdp, sizeof(vsc_sdp));
5132 intel_dp_setup_hdr_metadata_infoframe_sdp(struct intel_dp *intel_dp,
5133 const struct intel_crtc_state *crtc_state,
5134 const struct drm_connector_state *conn_state)
5136 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5137 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5138 struct dp_sdp infoframe_sdp = {};
5139 struct hdmi_drm_infoframe drm_infoframe = {};
5140 const int infoframe_size = HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE;
5141 unsigned char buf[HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE];
5145 ret = drm_hdmi_infoframe_set_hdr_metadata(&drm_infoframe, conn_state);
5147 drm_dbg_kms(&i915->drm,
5148 "couldn't set HDR metadata in infoframe\n");
5152 len = hdmi_drm_infoframe_pack_only(&drm_infoframe, buf, sizeof(buf));
5154 drm_dbg_kms(&i915->drm,
5155 "buffer size is smaller than hdr metadata infoframe\n");
5159 if (len != infoframe_size) {
5160 drm_dbg_kms(&i915->drm, "wrong static hdr metadata size\n");
5165 * Set up the infoframe sdp packet for HDR static metadata.
5166 * Prepare VSC Header for SU as per DP 1.4a spec,
5167 * Table 2-100 and Table 2-101
5170 /* Packet ID, 00h for non-Audio INFOFRAME */
5171 infoframe_sdp.sdp_header.HB0 = 0;
5173 * Packet Type 80h + Non-audio INFOFRAME Type value
5174 * HDMI_INFOFRAME_TYPE_DRM: 0x87,
5176 infoframe_sdp.sdp_header.HB1 = drm_infoframe.type;
5178 * Least Significant Eight Bits of (Data Byte Count – 1)
5179 * infoframe_size - 1,
5181 infoframe_sdp.sdp_header.HB2 = 0x1D;
5182 /* INFOFRAME SDP Version Number */
5183 infoframe_sdp.sdp_header.HB3 = (0x13 << 2);
5184 /* CTA Header Byte 2 (INFOFRAME Version Number) */
5185 infoframe_sdp.db[0] = drm_infoframe.version;
5186 /* CTA Header Byte 3 (Length of INFOFRAME): HDMI_DRM_INFOFRAME_SIZE */
5187 infoframe_sdp.db[1] = drm_infoframe.length;
5189 * Copy HDMI_DRM_INFOFRAME_SIZE size from a buffer after
5190 * HDMI_INFOFRAME_HEADER_SIZE
5192 BUILD_BUG_ON(sizeof(infoframe_sdp.db) < HDMI_DRM_INFOFRAME_SIZE + 2);
5193 memcpy(&infoframe_sdp.db[2], &buf[HDMI_INFOFRAME_HEADER_SIZE],
5194 HDMI_DRM_INFOFRAME_SIZE);
5197 * Size of DP infoframe sdp packet for HDR static metadata is consist of
5198 * - DP SDP Header(struct dp_sdp_header): 4 bytes
5199 * - Two Data Blocks: 2 bytes
5200 * CTA Header Byte2 (INFOFRAME Version Number)
5201 * CTA Header Byte3 (Length of INFOFRAME)
5202 * - HDMI_DRM_INFOFRAME_SIZE: 26 bytes
5204 * Prior to GEN11's GMP register size is identical to DP HDR static metadata
5205 * infoframe size. But GEN11+ has larger than that size, write_infoframe
5206 * will pad rest of the size.
5208 intel_dig_port->write_infoframe(&intel_dig_port->base, crtc_state,
5209 HDMI_PACKET_TYPE_GAMUT_METADATA,
5211 sizeof(struct dp_sdp_header) + 2 + HDMI_DRM_INFOFRAME_SIZE);
5214 void intel_dp_vsc_enable(struct intel_dp *intel_dp,
5215 const struct intel_crtc_state *crtc_state,
5216 const struct drm_connector_state *conn_state)
5218 if (!intel_dp_needs_vsc_sdp(crtc_state, conn_state))
5221 intel_dp_setup_vsc_sdp(intel_dp, crtc_state, conn_state);
5224 void intel_dp_hdr_metadata_enable(struct intel_dp *intel_dp,
5225 const struct intel_crtc_state *crtc_state,
5226 const struct drm_connector_state *conn_state)
5228 if (!conn_state->hdr_output_metadata)
5231 intel_dp_setup_hdr_metadata_infoframe_sdp(intel_dp,
5236 static u8 intel_dp_autotest_link_training(struct intel_dp *intel_dp)
5238 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5241 u8 test_lane_count, test_link_bw;
5245 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
5246 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
5250 drm_dbg_kms(&i915->drm, "Lane count read failed\n");
5253 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
5255 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
5258 drm_dbg_kms(&i915->drm, "Link Rate read failed\n");
5261 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
5263 /* Validate the requested link rate and lane count */
5264 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
5268 intel_dp->compliance.test_lane_count = test_lane_count;
5269 intel_dp->compliance.test_link_rate = test_link_rate;
5274 static u8 intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
5276 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5279 __be16 h_width, v_height;
5282 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
5283 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
5286 drm_dbg_kms(&i915->drm, "Test pattern read failed\n");
5289 if (test_pattern != DP_COLOR_RAMP)
5292 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
5295 drm_dbg_kms(&i915->drm, "H Width read failed\n");
5299 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
5302 drm_dbg_kms(&i915->drm, "V Height read failed\n");
5306 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
5309 drm_dbg_kms(&i915->drm, "TEST MISC read failed\n");
5312 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
5314 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
5316 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
5317 case DP_TEST_BIT_DEPTH_6:
5318 intel_dp->compliance.test_data.bpc = 6;
5320 case DP_TEST_BIT_DEPTH_8:
5321 intel_dp->compliance.test_data.bpc = 8;
5327 intel_dp->compliance.test_data.video_pattern = test_pattern;
5328 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
5329 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
5330 /* Set test active flag here so userspace doesn't interrupt things */
5331 intel_dp->compliance.test_active = true;
5336 static u8 intel_dp_autotest_edid(struct intel_dp *intel_dp)
5338 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5339 u8 test_result = DP_TEST_ACK;
5340 struct intel_connector *intel_connector = intel_dp->attached_connector;
5341 struct drm_connector *connector = &intel_connector->base;
5343 if (intel_connector->detect_edid == NULL ||
5344 connector->edid_corrupt ||
5345 intel_dp->aux.i2c_defer_count > 6) {
5346 /* Check EDID read for NACKs, DEFERs and corruption
5347 * (DP CTS 1.2 Core r1.1)
5348 * 4.2.2.4 : Failed EDID read, I2C_NAK
5349 * 4.2.2.5 : Failed EDID read, I2C_DEFER
5350 * 4.2.2.6 : EDID corruption detected
5351 * Use failsafe mode for all cases
5353 if (intel_dp->aux.i2c_nack_count > 0 ||
5354 intel_dp->aux.i2c_defer_count > 0)
5355 drm_dbg_kms(&i915->drm,
5356 "EDID read had %d NACKs, %d DEFERs\n",
5357 intel_dp->aux.i2c_nack_count,
5358 intel_dp->aux.i2c_defer_count);
5359 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
5361 struct edid *block = intel_connector->detect_edid;
5363 /* We have to write the checksum
5364 * of the last block read
5366 block += intel_connector->detect_edid->extensions;
5368 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
5369 block->checksum) <= 0)
5370 drm_dbg_kms(&i915->drm,
5371 "Failed to write EDID checksum\n");
5373 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
5374 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
5377 /* Set test active flag here so userspace doesn't interrupt things */
5378 intel_dp->compliance.test_active = true;
5383 static u8 intel_dp_prepare_phytest(struct intel_dp *intel_dp)
5385 struct drm_dp_phy_test_params *data =
5386 &intel_dp->compliance.test_data.phytest;
5388 if (drm_dp_get_phy_test_pattern(&intel_dp->aux, data)) {
5389 DRM_DEBUG_KMS("DP Phy Test pattern AUX read failure\n");
5394 * link_mst is set to false to avoid executing mst related code
5395 * during compliance testing.
5397 intel_dp->link_mst = false;
5402 static void intel_dp_phy_pattern_update(struct intel_dp *intel_dp)
5404 struct drm_i915_private *dev_priv =
5405 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
5406 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5407 struct drm_dp_phy_test_params *data =
5408 &intel_dp->compliance.test_data.phytest;
5409 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
5410 enum pipe pipe = crtc->pipe;
5413 switch (data->phy_pattern) {
5414 case DP_PHY_TEST_PATTERN_NONE:
5415 DRM_DEBUG_KMS("Disable Phy Test Pattern\n");
5416 intel_de_write(dev_priv, DDI_DP_COMP_CTL(pipe), 0x0);
5418 case DP_PHY_TEST_PATTERN_D10_2:
5419 DRM_DEBUG_KMS("Set D10.2 Phy Test Pattern\n");
5420 intel_de_write(dev_priv, DDI_DP_COMP_CTL(pipe),
5421 DDI_DP_COMP_CTL_ENABLE | DDI_DP_COMP_CTL_D10_2);
5423 case DP_PHY_TEST_PATTERN_ERROR_COUNT:
5424 DRM_DEBUG_KMS("Set Error Count Phy Test Pattern\n");
5425 intel_de_write(dev_priv, DDI_DP_COMP_CTL(pipe),
5426 DDI_DP_COMP_CTL_ENABLE |
5427 DDI_DP_COMP_CTL_SCRAMBLED_0);
5429 case DP_PHY_TEST_PATTERN_PRBS7:
5430 DRM_DEBUG_KMS("Set PRBS7 Phy Test Pattern\n");
5431 intel_de_write(dev_priv, DDI_DP_COMP_CTL(pipe),
5432 DDI_DP_COMP_CTL_ENABLE | DDI_DP_COMP_CTL_PRBS7);
5434 case DP_PHY_TEST_PATTERN_80BIT_CUSTOM:
5436 * FIXME: Ideally pattern should come from DPCD 0x250. As
5437 * current firmware of DPR-100 could not set it, so hardcoding
5438 * now for complaince test.
5440 DRM_DEBUG_KMS("Set 80Bit Custom Phy Test Pattern 0x3e0f83e0 0x0f83e0f8 0x0000f83e\n");
5441 pattern_val = 0x3e0f83e0;
5442 intel_de_write(dev_priv, DDI_DP_COMP_PAT(pipe, 0), pattern_val);
5443 pattern_val = 0x0f83e0f8;
5444 intel_de_write(dev_priv, DDI_DP_COMP_PAT(pipe, 1), pattern_val);
5445 pattern_val = 0x0000f83e;
5446 intel_de_write(dev_priv, DDI_DP_COMP_PAT(pipe, 2), pattern_val);
5447 intel_de_write(dev_priv, DDI_DP_COMP_CTL(pipe),
5448 DDI_DP_COMP_CTL_ENABLE |
5449 DDI_DP_COMP_CTL_CUSTOM80);
5451 case DP_PHY_TEST_PATTERN_CP2520:
5453 * FIXME: Ideally pattern should come from DPCD 0x24A. As
5454 * current firmware of DPR-100 could not set it, so hardcoding
5455 * now for complaince test.
5457 DRM_DEBUG_KMS("Set HBR2 compliance Phy Test Pattern\n");
5459 intel_de_write(dev_priv, DDI_DP_COMP_CTL(pipe),
5460 DDI_DP_COMP_CTL_ENABLE | DDI_DP_COMP_CTL_HBR2 |
5464 WARN(1, "Invalid Phy Test Pattern\n");
5469 intel_dp_autotest_phy_ddi_disable(struct intel_dp *intel_dp)
5471 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5472 struct drm_device *dev = intel_dig_port->base.base.dev;
5473 struct drm_i915_private *dev_priv = to_i915(dev);
5474 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
5475 enum pipe pipe = crtc->pipe;
5476 u32 trans_ddi_func_ctl_value, trans_conf_value, dp_tp_ctl_value;
5478 trans_ddi_func_ctl_value = intel_de_read(dev_priv,
5479 TRANS_DDI_FUNC_CTL(pipe));
5480 trans_conf_value = intel_de_read(dev_priv, PIPECONF(pipe));
5481 dp_tp_ctl_value = intel_de_read(dev_priv, TGL_DP_TP_CTL(pipe));
5483 trans_ddi_func_ctl_value &= ~(TRANS_DDI_FUNC_ENABLE |
5484 TGL_TRANS_DDI_PORT_MASK);
5485 trans_conf_value &= ~PIPECONF_ENABLE;
5486 dp_tp_ctl_value &= ~DP_TP_CTL_ENABLE;
5488 intel_de_write(dev_priv, PIPECONF(pipe), trans_conf_value);
5489 intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(pipe),
5490 trans_ddi_func_ctl_value);
5491 intel_de_write(dev_priv, TGL_DP_TP_CTL(pipe), dp_tp_ctl_value);
5495 intel_dp_autotest_phy_ddi_enable(struct intel_dp *intel_dp, uint8_t lane_cnt)
5497 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
5498 struct drm_device *dev = intel_dig_port->base.base.dev;
5499 struct drm_i915_private *dev_priv = to_i915(dev);
5500 enum port port = intel_dig_port->base.port;
5501 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
5502 enum pipe pipe = crtc->pipe;
5503 u32 trans_ddi_func_ctl_value, trans_conf_value, dp_tp_ctl_value;
5505 trans_ddi_func_ctl_value = intel_de_read(dev_priv,
5506 TRANS_DDI_FUNC_CTL(pipe));
5507 trans_conf_value = intel_de_read(dev_priv, PIPECONF(pipe));
5508 dp_tp_ctl_value = intel_de_read(dev_priv, TGL_DP_TP_CTL(pipe));
5510 trans_ddi_func_ctl_value |= TRANS_DDI_FUNC_ENABLE |
5511 TGL_TRANS_DDI_SELECT_PORT(port);
5512 trans_conf_value |= PIPECONF_ENABLE;
5513 dp_tp_ctl_value |= DP_TP_CTL_ENABLE;
5515 intel_de_write(dev_priv, PIPECONF(pipe), trans_conf_value);
5516 intel_de_write(dev_priv, TGL_DP_TP_CTL(pipe), dp_tp_ctl_value);
5517 intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(pipe),
5518 trans_ddi_func_ctl_value);
5521 void intel_dp_process_phy_request(struct intel_dp *intel_dp)
5523 struct drm_dp_phy_test_params *data =
5524 &intel_dp->compliance.test_data.phytest;
5525 u8 link_status[DP_LINK_STATUS_SIZE];
5527 if (!intel_dp_get_link_status(intel_dp, link_status)) {
5528 DRM_DEBUG_KMS("failed to get link status\n");
5532 /* retrieve vswing & pre-emphasis setting */
5533 intel_dp_get_adjust_train(intel_dp, link_status);
5535 intel_dp_autotest_phy_ddi_disable(intel_dp);
5537 intel_dp_set_signal_levels(intel_dp);
5539 intel_dp_phy_pattern_update(intel_dp);
5541 intel_dp_autotest_phy_ddi_enable(intel_dp, data->num_lanes);
5543 drm_dp_set_phy_test_pattern(&intel_dp->aux, data,
5544 link_status[DP_DPCD_REV]);
5547 static u8 intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
5551 test_result = intel_dp_prepare_phytest(intel_dp);
5552 if (test_result != DP_TEST_ACK)
5553 DRM_ERROR("Phy test preparation failed\n");
5555 intel_dp_process_phy_request(intel_dp);
5560 static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
5562 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5563 u8 response = DP_TEST_NAK;
5567 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
5569 drm_dbg_kms(&i915->drm,
5570 "Could not read test request from sink\n");
5575 case DP_TEST_LINK_TRAINING:
5576 drm_dbg_kms(&i915->drm, "LINK_TRAINING test requested\n");
5577 response = intel_dp_autotest_link_training(intel_dp);
5579 case DP_TEST_LINK_VIDEO_PATTERN:
5580 drm_dbg_kms(&i915->drm, "TEST_PATTERN test requested\n");
5581 response = intel_dp_autotest_video_pattern(intel_dp);
5583 case DP_TEST_LINK_EDID_READ:
5584 drm_dbg_kms(&i915->drm, "EDID test requested\n");
5585 response = intel_dp_autotest_edid(intel_dp);
5587 case DP_TEST_LINK_PHY_TEST_PATTERN:
5588 drm_dbg_kms(&i915->drm, "PHY_PATTERN test requested\n");
5589 response = intel_dp_autotest_phy_pattern(intel_dp);
5592 drm_dbg_kms(&i915->drm, "Invalid test request '%02x'\n",
5597 if (response & DP_TEST_ACK)
5598 intel_dp->compliance.test_type = request;
5601 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
5603 drm_dbg_kms(&i915->drm,
5604 "Could not write test response to sink\n");
5608 intel_dp_check_mst_status(struct intel_dp *intel_dp)
5610 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5611 bool need_retrain = false;
5613 if (!intel_dp->is_mst)
5616 WARN_ON_ONCE(intel_dp->active_mst_links < 0);
5619 u8 esi[DP_DPRX_ESI_LEN] = {};
5623 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
5625 drm_dbg_kms(&i915->drm,
5626 "failed to get ESI - device may have failed\n");
5630 /* check link status - esi[10] = 0x200c */
5631 if (intel_dp->active_mst_links > 0 && !need_retrain &&
5632 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
5633 drm_dbg_kms(&i915->drm,
5634 "channel EQ not ok, retraining\n");
5635 need_retrain = true;
5638 drm_dbg_kms(&i915->drm, "got esi %3ph\n", esi);
5640 drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
5644 for (retry = 0; retry < 3; retry++) {
5647 wret = drm_dp_dpcd_write(&intel_dp->aux,
5648 DP_SINK_COUNT_ESI+1,
5655 return need_retrain;
5659 intel_dp_needs_link_retrain(struct intel_dp *intel_dp)
5661 u8 link_status[DP_LINK_STATUS_SIZE];
5663 if (!intel_dp->link_trained)
5667 * While PSR source HW is enabled, it will control main-link sending
5668 * frames, enabling and disabling it so trying to do a retrain will fail
5669 * as the link would or not be on or it could mix training patterns
5670 * and frame data at the same time causing retrain to fail.
5671 * Also when exiting PSR, HW will retrain the link anyways fixing
5672 * any link status error.
5674 if (intel_psr_enabled(intel_dp))
5677 if (!intel_dp_get_link_status(intel_dp, link_status))
5681 * Validate the cached values of intel_dp->link_rate and
5682 * intel_dp->lane_count before attempting to retrain.
5684 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
5685 intel_dp->lane_count))
5688 /* Retrain if Channel EQ or CR not ok */
5689 return !drm_dp_channel_eq_ok(link_status, intel_dp->lane_count);
5692 static bool intel_dp_has_connector(struct intel_dp *intel_dp,
5693 const struct drm_connector_state *conn_state)
5695 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5696 struct intel_encoder *encoder;
5699 if (!conn_state->best_encoder)
5703 encoder = &dp_to_dig_port(intel_dp)->base;
5704 if (conn_state->best_encoder == &encoder->base)
5708 for_each_pipe(i915, pipe) {
5709 encoder = &intel_dp->mst_encoders[pipe]->base;
5710 if (conn_state->best_encoder == &encoder->base)
5717 static int intel_dp_prep_link_retrain(struct intel_dp *intel_dp,
5718 struct drm_modeset_acquire_ctx *ctx,
5721 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5722 struct drm_connector_list_iter conn_iter;
5723 struct intel_connector *connector;
5728 if (!intel_dp_needs_link_retrain(intel_dp))
5731 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
5732 for_each_intel_connector_iter(connector, &conn_iter) {
5733 struct drm_connector_state *conn_state =
5734 connector->base.state;
5735 struct intel_crtc_state *crtc_state;
5736 struct intel_crtc *crtc;
5738 if (!intel_dp_has_connector(intel_dp, conn_state))
5741 crtc = to_intel_crtc(conn_state->crtc);
5745 ret = drm_modeset_lock(&crtc->base.mutex, ctx);
5749 crtc_state = to_intel_crtc_state(crtc->base.state);
5751 drm_WARN_ON(&i915->drm, !intel_crtc_has_dp_encoder(crtc_state));
5753 if (!crtc_state->hw.active)
5756 if (conn_state->commit &&
5757 !try_wait_for_completion(&conn_state->commit->hw_done))
5760 *crtc_mask |= drm_crtc_mask(&crtc->base);
5762 drm_connector_list_iter_end(&conn_iter);
5764 if (!intel_dp_needs_link_retrain(intel_dp))
5770 static bool intel_dp_is_connected(struct intel_dp *intel_dp)
5772 struct intel_connector *connector = intel_dp->attached_connector;
5774 return connector->base.status == connector_status_connected ||
5778 int intel_dp_retrain_link(struct intel_encoder *encoder,
5779 struct drm_modeset_acquire_ctx *ctx)
5781 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5782 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5783 struct intel_crtc *crtc;
5787 if (!intel_dp_is_connected(intel_dp))
5790 ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex,
5795 ret = intel_dp_prep_link_retrain(intel_dp, ctx, &crtc_mask);
5802 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s] retraining link\n",
5803 encoder->base.base.id, encoder->base.name);
5805 for_each_intel_crtc_mask(&dev_priv->drm, crtc, crtc_mask) {
5806 const struct intel_crtc_state *crtc_state =
5807 to_intel_crtc_state(crtc->base.state);
5809 /* Suppress underruns caused by re-training */
5810 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
5811 if (crtc_state->has_pch_encoder)
5812 intel_set_pch_fifo_underrun_reporting(dev_priv,
5813 intel_crtc_pch_transcoder(crtc), false);
5816 intel_dp_start_link_train(intel_dp);
5817 intel_dp_stop_link_train(intel_dp);
5819 for_each_intel_crtc_mask(&dev_priv->drm, crtc, crtc_mask) {
5820 const struct intel_crtc_state *crtc_state =
5821 to_intel_crtc_state(crtc->base.state);
5823 /* Keep underrun reporting disabled until things are stable */
5824 intel_wait_for_vblank(dev_priv, crtc->pipe);
5826 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
5827 if (crtc_state->has_pch_encoder)
5828 intel_set_pch_fifo_underrun_reporting(dev_priv,
5829 intel_crtc_pch_transcoder(crtc), true);
5836 * If display is now connected check links status,
5837 * there has been known issues of link loss triggering
5840 * Some sinks (eg. ASUS PB287Q) seem to perform some
5841 * weird HPD ping pong during modesets. So we can apparently
5842 * end up with HPD going low during a modeset, and then
5843 * going back up soon after. And once that happens we must
5844 * retrain the link to get a picture. That's in case no
5845 * userspace component reacted to intermittent HPD dip.
5847 static enum intel_hotplug_state
5848 intel_dp_hotplug(struct intel_encoder *encoder,
5849 struct intel_connector *connector)
5851 struct drm_modeset_acquire_ctx ctx;
5852 enum intel_hotplug_state state;
5855 state = intel_encoder_hotplug(encoder, connector);
5857 drm_modeset_acquire_init(&ctx, 0);
5860 ret = intel_dp_retrain_link(encoder, &ctx);
5862 if (ret == -EDEADLK) {
5863 drm_modeset_backoff(&ctx);
5870 drm_modeset_drop_locks(&ctx);
5871 drm_modeset_acquire_fini(&ctx);
5872 drm_WARN(encoder->base.dev, ret,
5873 "Acquiring modeset locks failed with %i\n", ret);
5876 * Keeping it consistent with intel_ddi_hotplug() and
5877 * intel_hdmi_hotplug().
5879 if (state == INTEL_HOTPLUG_UNCHANGED && !connector->hotplug_retries)
5880 state = INTEL_HOTPLUG_RETRY;
5885 static void intel_dp_check_service_irq(struct intel_dp *intel_dp)
5887 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5890 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
5893 if (drm_dp_dpcd_readb(&intel_dp->aux,
5894 DP_DEVICE_SERVICE_IRQ_VECTOR, &val) != 1 || !val)
5897 drm_dp_dpcd_writeb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR, val);
5899 if (val & DP_AUTOMATED_TEST_REQUEST)
5900 intel_dp_handle_test_request(intel_dp);
5902 if (val & DP_CP_IRQ)
5903 intel_hdcp_handle_cp_irq(intel_dp->attached_connector);
5905 if (val & DP_SINK_SPECIFIC_IRQ)
5906 drm_dbg_kms(&i915->drm, "Sink specific irq unhandled\n");
5910 * According to DP spec
5913 * 2. Configure link according to Receiver Capabilities
5914 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
5915 * 4. Check link status on receipt of hot-plug interrupt
5917 * intel_dp_short_pulse - handles short pulse interrupts
5918 * when full detection is not required.
5919 * Returns %true if short pulse is handled and full detection
5920 * is NOT required and %false otherwise.
5923 intel_dp_short_pulse(struct intel_dp *intel_dp)
5925 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
5926 u8 old_sink_count = intel_dp->sink_count;
5930 * Clearing compliance test variables to allow capturing
5931 * of values for next automated test request.
5933 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
5936 * Now read the DPCD to see if it's actually running
5937 * If the current value of sink count doesn't match with
5938 * the value that was stored earlier or dpcd read failed
5939 * we need to do full detection
5941 ret = intel_dp_get_dpcd(intel_dp);
5943 if ((old_sink_count != intel_dp->sink_count) || !ret) {
5944 /* No need to proceed if we are going to do full detect */
5948 intel_dp_check_service_irq(intel_dp);
5950 /* Handle CEC interrupts, if any */
5951 drm_dp_cec_irq(&intel_dp->aux);
5953 /* defer to the hotplug work for link retraining if needed */
5954 if (intel_dp_needs_link_retrain(intel_dp))
5957 intel_psr_short_pulse(intel_dp);
5959 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
5960 drm_dbg_kms(&dev_priv->drm,
5961 "Link Training Compliance Test requested\n");
5962 /* Send a Hotplug Uevent to userspace to start modeset */
5963 drm_kms_helper_hotplug_event(&dev_priv->drm);
5969 /* XXX this is probably wrong for multiple downstream ports */
5970 static enum drm_connector_status
5971 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
5973 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
5974 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
5975 u8 *dpcd = intel_dp->dpcd;
5978 if (WARN_ON(intel_dp_is_edp(intel_dp)))
5979 return connector_status_connected;
5982 lspcon_resume(lspcon);
5984 if (!intel_dp_get_dpcd(intel_dp))
5985 return connector_status_disconnected;
5987 /* if there's no downstream port, we're done */
5988 if (!drm_dp_is_branch(dpcd))
5989 return connector_status_connected;
5991 /* If we're HPD-aware, SINK_COUNT changes dynamically */
5992 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
5993 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
5995 return intel_dp->sink_count ?
5996 connector_status_connected : connector_status_disconnected;
5999 if (intel_dp_can_mst(intel_dp))
6000 return connector_status_connected;
6002 /* If no HPD, poke DDC gently */
6003 if (drm_probe_ddc(&intel_dp->aux.ddc))
6004 return connector_status_connected;
6006 /* Well we tried, say unknown for unreliable port types */
6007 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
6008 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
6009 if (type == DP_DS_PORT_TYPE_VGA ||
6010 type == DP_DS_PORT_TYPE_NON_EDID)
6011 return connector_status_unknown;
6013 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
6014 DP_DWN_STRM_PORT_TYPE_MASK;
6015 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
6016 type == DP_DWN_STRM_PORT_TYPE_OTHER)
6017 return connector_status_unknown;
6020 /* Anything else is out of spec, warn and ignore */
6021 drm_dbg_kms(&i915->drm, "Broken DP branch device, ignoring\n");
6022 return connector_status_disconnected;
6025 static enum drm_connector_status
6026 edp_detect(struct intel_dp *intel_dp)
6028 return connector_status_connected;
6031 static bool ibx_digital_port_connected(struct intel_encoder *encoder)
6033 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6036 switch (encoder->hpd_pin) {
6038 bit = SDE_PORTB_HOTPLUG;
6041 bit = SDE_PORTC_HOTPLUG;
6044 bit = SDE_PORTD_HOTPLUG;
6047 MISSING_CASE(encoder->hpd_pin);
6051 return intel_de_read(dev_priv, SDEISR) & bit;
6054 static bool cpt_digital_port_connected(struct intel_encoder *encoder)
6056 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6059 switch (encoder->hpd_pin) {
6061 bit = SDE_PORTB_HOTPLUG_CPT;
6064 bit = SDE_PORTC_HOTPLUG_CPT;
6067 bit = SDE_PORTD_HOTPLUG_CPT;
6070 MISSING_CASE(encoder->hpd_pin);
6074 return intel_de_read(dev_priv, SDEISR) & bit;
6077 static bool spt_digital_port_connected(struct intel_encoder *encoder)
6079 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6082 switch (encoder->hpd_pin) {
6084 bit = SDE_PORTA_HOTPLUG_SPT;
6087 bit = SDE_PORTE_HOTPLUG_SPT;
6090 return cpt_digital_port_connected(encoder);
6093 return intel_de_read(dev_priv, SDEISR) & bit;
6096 static bool g4x_digital_port_connected(struct intel_encoder *encoder)
6098 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6101 switch (encoder->hpd_pin) {
6103 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
6106 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
6109 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
6112 MISSING_CASE(encoder->hpd_pin);
6116 return intel_de_read(dev_priv, PORT_HOTPLUG_STAT) & bit;
6119 static bool gm45_digital_port_connected(struct intel_encoder *encoder)
6121 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6124 switch (encoder->hpd_pin) {
6126 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
6129 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
6132 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
6135 MISSING_CASE(encoder->hpd_pin);
6139 return intel_de_read(dev_priv, PORT_HOTPLUG_STAT) & bit;
6142 static bool ilk_digital_port_connected(struct intel_encoder *encoder)
6144 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6146 if (encoder->hpd_pin == HPD_PORT_A)
6147 return intel_de_read(dev_priv, DEISR) & DE_DP_A_HOTPLUG;
6149 return ibx_digital_port_connected(encoder);
6152 static bool snb_digital_port_connected(struct intel_encoder *encoder)
6154 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6156 if (encoder->hpd_pin == HPD_PORT_A)
6157 return intel_de_read(dev_priv, DEISR) & DE_DP_A_HOTPLUG;
6159 return cpt_digital_port_connected(encoder);
6162 static bool ivb_digital_port_connected(struct intel_encoder *encoder)
6164 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6166 if (encoder->hpd_pin == HPD_PORT_A)
6167 return intel_de_read(dev_priv, DEISR) & DE_DP_A_HOTPLUG_IVB;
6169 return cpt_digital_port_connected(encoder);
6172 static bool bdw_digital_port_connected(struct intel_encoder *encoder)
6174 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6176 if (encoder->hpd_pin == HPD_PORT_A)
6177 return intel_de_read(dev_priv, GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
6179 return cpt_digital_port_connected(encoder);
6182 static bool bxt_digital_port_connected(struct intel_encoder *encoder)
6184 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6187 switch (encoder->hpd_pin) {
6189 bit = BXT_DE_PORT_HP_DDIA;
6192 bit = BXT_DE_PORT_HP_DDIB;
6195 bit = BXT_DE_PORT_HP_DDIC;
6198 MISSING_CASE(encoder->hpd_pin);
6202 return intel_de_read(dev_priv, GEN8_DE_PORT_ISR) & bit;
6205 static bool intel_combo_phy_connected(struct drm_i915_private *dev_priv,
6208 if (HAS_PCH_MCC(dev_priv) && phy == PHY_C)
6209 return intel_de_read(dev_priv, SDEISR) & SDE_TC_HOTPLUG_ICP(PORT_TC1);
6211 return intel_de_read(dev_priv, SDEISR) & SDE_DDI_HOTPLUG_ICP(phy);
6214 static bool icp_digital_port_connected(struct intel_encoder *encoder)
6216 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6217 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
6218 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
6220 if (intel_phy_is_combo(dev_priv, phy))
6221 return intel_combo_phy_connected(dev_priv, phy);
6222 else if (intel_phy_is_tc(dev_priv, phy))
6223 return intel_tc_port_connected(dig_port);
6225 MISSING_CASE(encoder->hpd_pin);
6231 * intel_digital_port_connected - is the specified port connected?
6232 * @encoder: intel_encoder
6234 * In cases where there's a connector physically connected but it can't be used
6235 * by our hardware we also return false, since the rest of the driver should
6236 * pretty much treat the port as disconnected. This is relevant for type-C
6237 * (starting on ICL) where there's ownership involved.
6239 * Return %true if port is connected, %false otherwise.
6241 static bool __intel_digital_port_connected(struct intel_encoder *encoder)
6243 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6245 if (HAS_GMCH(dev_priv)) {
6246 if (IS_GM45(dev_priv))
6247 return gm45_digital_port_connected(encoder);
6249 return g4x_digital_port_connected(encoder);
6252 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
6253 return icp_digital_port_connected(encoder);
6254 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
6255 return spt_digital_port_connected(encoder);
6256 else if (IS_GEN9_LP(dev_priv))
6257 return bxt_digital_port_connected(encoder);
6258 else if (IS_GEN(dev_priv, 8))
6259 return bdw_digital_port_connected(encoder);
6260 else if (IS_GEN(dev_priv, 7))
6261 return ivb_digital_port_connected(encoder);
6262 else if (IS_GEN(dev_priv, 6))
6263 return snb_digital_port_connected(encoder);
6264 else if (IS_GEN(dev_priv, 5))
6265 return ilk_digital_port_connected(encoder);
6267 MISSING_CASE(INTEL_GEN(dev_priv));
6271 bool intel_digital_port_connected(struct intel_encoder *encoder)
6273 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6274 bool is_connected = false;
6275 intel_wakeref_t wakeref;
6277 with_intel_display_power(dev_priv, POWER_DOMAIN_DISPLAY_CORE, wakeref)
6278 is_connected = __intel_digital_port_connected(encoder);
6280 return is_connected;
6283 static struct edid *
6284 intel_dp_get_edid(struct intel_dp *intel_dp)
6286 struct intel_connector *intel_connector = intel_dp->attached_connector;
6288 /* use cached edid if we have one */
6289 if (intel_connector->edid) {
6291 if (IS_ERR(intel_connector->edid))
6294 return drm_edid_duplicate(intel_connector->edid);
6296 return drm_get_edid(&intel_connector->base,
6297 &intel_dp->aux.ddc);
6301 intel_dp_set_edid(struct intel_dp *intel_dp)
6303 struct intel_connector *intel_connector = intel_dp->attached_connector;
6306 intel_dp_unset_edid(intel_dp);
6307 edid = intel_dp_get_edid(intel_dp);
6308 intel_connector->detect_edid = edid;
6310 intel_dp->has_audio = drm_detect_monitor_audio(edid);
6311 drm_dp_cec_set_edid(&intel_dp->aux, edid);
6312 intel_dp->edid_quirks = drm_dp_get_edid_quirks(edid);
6316 intel_dp_unset_edid(struct intel_dp *intel_dp)
6318 struct intel_connector *intel_connector = intel_dp->attached_connector;
6320 drm_dp_cec_unset_edid(&intel_dp->aux);
6321 kfree(intel_connector->detect_edid);
6322 intel_connector->detect_edid = NULL;
6324 intel_dp->has_audio = false;
6325 intel_dp->edid_quirks = 0;
6329 intel_dp_detect(struct drm_connector *connector,
6330 struct drm_modeset_acquire_ctx *ctx,
6333 struct drm_i915_private *dev_priv = to_i915(connector->dev);
6334 struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector));
6335 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
6336 struct intel_encoder *encoder = &dig_port->base;
6337 enum drm_connector_status status;
6339 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s]\n",
6340 connector->base.id, connector->name);
6341 drm_WARN_ON(&dev_priv->drm,
6342 !drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
6344 /* Can't disconnect eDP */
6345 if (intel_dp_is_edp(intel_dp))
6346 status = edp_detect(intel_dp);
6347 else if (intel_digital_port_connected(encoder))
6348 status = intel_dp_detect_dpcd(intel_dp);
6350 status = connector_status_disconnected;
6352 if (status == connector_status_disconnected) {
6353 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
6354 memset(intel_dp->dsc_dpcd, 0, sizeof(intel_dp->dsc_dpcd));
6356 if (intel_dp->is_mst) {
6357 drm_dbg_kms(&dev_priv->drm,
6358 "MST device may have disappeared %d vs %d\n",
6360 intel_dp->mst_mgr.mst_state);
6361 intel_dp->is_mst = false;
6362 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
6369 if (intel_dp->reset_link_params) {
6370 /* Initial max link lane count */
6371 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
6373 /* Initial max link rate */
6374 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
6376 intel_dp->reset_link_params = false;
6379 intel_dp_print_rates(intel_dp);
6381 /* Read DP Sink DSC Cap DPCD regs for DP v1.4 */
6382 if (INTEL_GEN(dev_priv) >= 11)
6383 intel_dp_get_dsc_sink_cap(intel_dp);
6385 intel_dp_configure_mst(intel_dp);
6387 if (intel_dp->is_mst) {
6389 * If we are in MST mode then this connector
6390 * won't appear connected or have anything
6393 status = connector_status_disconnected;
6398 * Some external monitors do not signal loss of link synchronization
6399 * with an IRQ_HPD, so force a link status check.
6401 if (!intel_dp_is_edp(intel_dp)) {
6404 ret = intel_dp_retrain_link(encoder, ctx);
6410 * Clearing NACK and defer counts to get their exact values
6411 * while reading EDID which are required by Compliance tests
6412 * 4.2.2.4 and 4.2.2.5
6414 intel_dp->aux.i2c_nack_count = 0;
6415 intel_dp->aux.i2c_defer_count = 0;
6417 intel_dp_set_edid(intel_dp);
6418 if (intel_dp_is_edp(intel_dp) ||
6419 to_intel_connector(connector)->detect_edid)
6420 status = connector_status_connected;
6422 intel_dp_check_service_irq(intel_dp);
6425 if (status != connector_status_connected && !intel_dp->is_mst)
6426 intel_dp_unset_edid(intel_dp);
6429 * Make sure the refs for power wells enabled during detect are
6430 * dropped to avoid a new detect cycle triggered by HPD polling.
6432 intel_display_power_flush_work(dev_priv);
6438 intel_dp_force(struct drm_connector *connector)
6440 struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector));
6441 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
6442 struct intel_encoder *intel_encoder = &dig_port->base;
6443 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
6444 enum intel_display_power_domain aux_domain =
6445 intel_aux_power_domain(dig_port);
6446 intel_wakeref_t wakeref;
6448 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s]\n",
6449 connector->base.id, connector->name);
6450 intel_dp_unset_edid(intel_dp);
6452 if (connector->status != connector_status_connected)
6455 wakeref = intel_display_power_get(dev_priv, aux_domain);
6457 intel_dp_set_edid(intel_dp);
6459 intel_display_power_put(dev_priv, aux_domain, wakeref);
6462 static int intel_dp_get_modes(struct drm_connector *connector)
6464 struct intel_connector *intel_connector = to_intel_connector(connector);
6467 edid = intel_connector->detect_edid;
6469 int ret = intel_connector_update_modes(connector, edid);
6474 /* if eDP has no EDID, fall back to fixed mode */
6475 if (intel_dp_is_edp(intel_attached_dp(to_intel_connector(connector))) &&
6476 intel_connector->panel.fixed_mode) {
6477 struct drm_display_mode *mode;
6479 mode = drm_mode_duplicate(connector->dev,
6480 intel_connector->panel.fixed_mode);
6482 drm_mode_probed_add(connector, mode);
6491 intel_dp_connector_register(struct drm_connector *connector)
6493 struct drm_i915_private *i915 = to_i915(connector->dev);
6494 struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector));
6497 ret = intel_connector_register(connector);
6501 drm_dbg_kms(&i915->drm, "registering %s bus for %s\n",
6502 intel_dp->aux.name, connector->kdev->kobj.name);
6504 intel_dp->aux.dev = connector->kdev;
6505 ret = drm_dp_aux_register(&intel_dp->aux);
6507 drm_dp_cec_register_connector(&intel_dp->aux, connector);
6512 intel_dp_connector_unregister(struct drm_connector *connector)
6514 struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector));
6516 drm_dp_cec_unregister_connector(&intel_dp->aux);
6517 drm_dp_aux_unregister(&intel_dp->aux);
6518 intel_connector_unregister(connector);
6521 void intel_dp_encoder_flush_work(struct drm_encoder *encoder)
6523 struct intel_digital_port *intel_dig_port = enc_to_dig_port(to_intel_encoder(encoder));
6524 struct intel_dp *intel_dp = &intel_dig_port->dp;
6526 intel_dp_mst_encoder_cleanup(intel_dig_port);
6527 if (intel_dp_is_edp(intel_dp)) {
6528 intel_wakeref_t wakeref;
6530 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
6532 * vdd might still be enabled do to the delayed vdd off.
6533 * Make sure vdd is actually turned off here.
6535 with_pps_lock(intel_dp, wakeref)
6536 edp_panel_vdd_off_sync(intel_dp);
6538 if (intel_dp->edp_notifier.notifier_call) {
6539 unregister_reboot_notifier(&intel_dp->edp_notifier);
6540 intel_dp->edp_notifier.notifier_call = NULL;
6544 intel_dp_aux_fini(intel_dp);
6547 static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
6549 intel_dp_encoder_flush_work(encoder);
6551 drm_encoder_cleanup(encoder);
6552 kfree(enc_to_dig_port(to_intel_encoder(encoder)));
6555 void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
6557 struct intel_dp *intel_dp = enc_to_intel_dp(intel_encoder);
6558 intel_wakeref_t wakeref;
6560 if (!intel_dp_is_edp(intel_dp))
6564 * vdd might still be enabled do to the delayed vdd off.
6565 * Make sure vdd is actually turned off here.
6567 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
6568 with_pps_lock(intel_dp, wakeref)
6569 edp_panel_vdd_off_sync(intel_dp);
6572 static void intel_dp_hdcp_wait_for_cp_irq(struct intel_hdcp *hdcp, int timeout)
6576 #define C (hdcp->cp_irq_count_cached != atomic_read(&hdcp->cp_irq_count))
6577 ret = wait_event_interruptible_timeout(hdcp->cp_irq_queue, C,
6578 msecs_to_jiffies(timeout));
6581 DRM_DEBUG_KMS("Timedout at waiting for CP_IRQ\n");
6585 int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *intel_dig_port,
6588 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6589 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(&intel_dig_port->base.base));
6590 static const struct drm_dp_aux_msg msg = {
6591 .request = DP_AUX_NATIVE_WRITE,
6592 .address = DP_AUX_HDCP_AKSV,
6593 .size = DRM_HDCP_KSV_LEN,
6595 u8 txbuf[HEADER_SIZE + DRM_HDCP_KSV_LEN] = {}, rxbuf[2], reply = 0;
6599 /* Output An first, that's easy */
6600 dpcd_ret = drm_dp_dpcd_write(&intel_dig_port->dp.aux, DP_AUX_HDCP_AN,
6601 an, DRM_HDCP_AN_LEN);
6602 if (dpcd_ret != DRM_HDCP_AN_LEN) {
6603 drm_dbg_kms(&i915->drm,
6604 "Failed to write An over DP/AUX (%zd)\n",
6606 return dpcd_ret >= 0 ? -EIO : dpcd_ret;
6610 * Since Aksv is Oh-So-Secret, we can't access it in software. So in
6611 * order to get it on the wire, we need to create the AUX header as if
6612 * we were writing the data, and then tickle the hardware to output the
6613 * data once the header is sent out.
6615 intel_dp_aux_header(txbuf, &msg);
6617 ret = intel_dp_aux_xfer(intel_dp, txbuf, HEADER_SIZE + msg.size,
6618 rxbuf, sizeof(rxbuf),
6619 DP_AUX_CH_CTL_AUX_AKSV_SELECT);
6621 drm_dbg_kms(&i915->drm,
6622 "Write Aksv over DP/AUX failed (%d)\n", ret);
6624 } else if (ret == 0) {
6625 drm_dbg_kms(&i915->drm, "Aksv write over DP/AUX was empty\n");
6629 reply = (rxbuf[0] >> 4) & DP_AUX_NATIVE_REPLY_MASK;
6630 if (reply != DP_AUX_NATIVE_REPLY_ACK) {
6631 drm_dbg_kms(&i915->drm,
6632 "Aksv write: no DP_AUX_NATIVE_REPLY_ACK %x\n",
6639 static int intel_dp_hdcp_read_bksv(struct intel_digital_port *intel_dig_port,
6642 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6645 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BKSV, bksv,
6647 if (ret != DRM_HDCP_KSV_LEN) {
6648 drm_dbg_kms(&i915->drm,
6649 "Read Bksv from DP/AUX failed (%zd)\n", ret);
6650 return ret >= 0 ? -EIO : ret;
6655 static int intel_dp_hdcp_read_bstatus(struct intel_digital_port *intel_dig_port,
6658 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6662 * For some reason the HDMI and DP HDCP specs call this register
6663 * definition by different names. In the HDMI spec, it's called BSTATUS,
6664 * but in DP it's called BINFO.
6666 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BINFO,
6667 bstatus, DRM_HDCP_BSTATUS_LEN);
6668 if (ret != DRM_HDCP_BSTATUS_LEN) {
6669 drm_dbg_kms(&i915->drm,
6670 "Read bstatus from DP/AUX failed (%zd)\n", ret);
6671 return ret >= 0 ? -EIO : ret;
6677 int intel_dp_hdcp_read_bcaps(struct intel_digital_port *intel_dig_port,
6680 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6683 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BCAPS,
6686 drm_dbg_kms(&i915->drm,
6687 "Read bcaps from DP/AUX failed (%zd)\n", ret);
6688 return ret >= 0 ? -EIO : ret;
6695 int intel_dp_hdcp_repeater_present(struct intel_digital_port *intel_dig_port,
6696 bool *repeater_present)
6701 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
6705 *repeater_present = bcaps & DP_BCAPS_REPEATER_PRESENT;
6710 int intel_dp_hdcp_read_ri_prime(struct intel_digital_port *intel_dig_port,
6713 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6716 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_RI_PRIME,
6717 ri_prime, DRM_HDCP_RI_LEN);
6718 if (ret != DRM_HDCP_RI_LEN) {
6719 drm_dbg_kms(&i915->drm, "Read Ri' from DP/AUX failed (%zd)\n",
6721 return ret >= 0 ? -EIO : ret;
6727 int intel_dp_hdcp_read_ksv_ready(struct intel_digital_port *intel_dig_port,
6730 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6734 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
6737 drm_dbg_kms(&i915->drm,
6738 "Read bstatus from DP/AUX failed (%zd)\n", ret);
6739 return ret >= 0 ? -EIO : ret;
6741 *ksv_ready = bstatus & DP_BSTATUS_READY;
6746 int intel_dp_hdcp_read_ksv_fifo(struct intel_digital_port *intel_dig_port,
6747 int num_downstream, u8 *ksv_fifo)
6749 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6753 /* KSV list is read via 15 byte window (3 entries @ 5 bytes each) */
6754 for (i = 0; i < num_downstream; i += 3) {
6755 size_t len = min(num_downstream - i, 3) * DRM_HDCP_KSV_LEN;
6756 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
6757 DP_AUX_HDCP_KSV_FIFO,
6758 ksv_fifo + i * DRM_HDCP_KSV_LEN,
6761 drm_dbg_kms(&i915->drm,
6762 "Read ksv[%d] from DP/AUX failed (%zd)\n",
6764 return ret >= 0 ? -EIO : ret;
6771 int intel_dp_hdcp_read_v_prime_part(struct intel_digital_port *intel_dig_port,
6774 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6777 if (i >= DRM_HDCP_V_PRIME_NUM_PARTS)
6780 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
6781 DP_AUX_HDCP_V_PRIME(i), part,
6782 DRM_HDCP_V_PRIME_PART_LEN);
6783 if (ret != DRM_HDCP_V_PRIME_PART_LEN) {
6784 drm_dbg_kms(&i915->drm,
6785 "Read v'[%d] from DP/AUX failed (%zd)\n", i, ret);
6786 return ret >= 0 ? -EIO : ret;
6792 int intel_dp_hdcp_toggle_signalling(struct intel_digital_port *intel_dig_port,
6795 /* Not used for single stream DisplayPort setups */
6800 bool intel_dp_hdcp_check_link(struct intel_digital_port *intel_dig_port)
6802 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6806 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, DP_AUX_HDCP_BSTATUS,
6809 drm_dbg_kms(&i915->drm,
6810 "Read bstatus from DP/AUX failed (%zd)\n", ret);
6814 return !(bstatus & (DP_BSTATUS_LINK_FAILURE | DP_BSTATUS_REAUTH_REQ));
6818 int intel_dp_hdcp_capable(struct intel_digital_port *intel_dig_port,
6824 ret = intel_dp_hdcp_read_bcaps(intel_dig_port, &bcaps);
6828 *hdcp_capable = bcaps & DP_BCAPS_HDCP_CAPABLE;
6832 struct hdcp2_dp_errata_stream_type {
6837 struct hdcp2_dp_msg_data {
6840 bool msg_detectable;
6842 u32 timeout2; /* Added for non_paired situation */
6845 static const struct hdcp2_dp_msg_data hdcp2_dp_msg_data[] = {
6846 { HDCP_2_2_AKE_INIT, DP_HDCP_2_2_AKE_INIT_OFFSET, false, 0, 0 },
6847 { HDCP_2_2_AKE_SEND_CERT, DP_HDCP_2_2_AKE_SEND_CERT_OFFSET,
6848 false, HDCP_2_2_CERT_TIMEOUT_MS, 0 },
6849 { HDCP_2_2_AKE_NO_STORED_KM, DP_HDCP_2_2_AKE_NO_STORED_KM_OFFSET,
6851 { HDCP_2_2_AKE_STORED_KM, DP_HDCP_2_2_AKE_STORED_KM_OFFSET,
6853 { HDCP_2_2_AKE_SEND_HPRIME, DP_HDCP_2_2_AKE_SEND_HPRIME_OFFSET,
6854 true, HDCP_2_2_HPRIME_PAIRED_TIMEOUT_MS,
6855 HDCP_2_2_HPRIME_NO_PAIRED_TIMEOUT_MS },
6856 { HDCP_2_2_AKE_SEND_PAIRING_INFO,
6857 DP_HDCP_2_2_AKE_SEND_PAIRING_INFO_OFFSET, true,
6858 HDCP_2_2_PAIRING_TIMEOUT_MS, 0 },
6859 { HDCP_2_2_LC_INIT, DP_HDCP_2_2_LC_INIT_OFFSET, false, 0, 0 },
6860 { HDCP_2_2_LC_SEND_LPRIME, DP_HDCP_2_2_LC_SEND_LPRIME_OFFSET,
6861 false, HDCP_2_2_DP_LPRIME_TIMEOUT_MS, 0 },
6862 { HDCP_2_2_SKE_SEND_EKS, DP_HDCP_2_2_SKE_SEND_EKS_OFFSET, false,
6864 { HDCP_2_2_REP_SEND_RECVID_LIST,
6865 DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET, true,
6866 HDCP_2_2_RECVID_LIST_TIMEOUT_MS, 0 },
6867 { HDCP_2_2_REP_SEND_ACK, DP_HDCP_2_2_REP_SEND_ACK_OFFSET, false,
6869 { HDCP_2_2_REP_STREAM_MANAGE,
6870 DP_HDCP_2_2_REP_STREAM_MANAGE_OFFSET, false,
6872 { HDCP_2_2_REP_STREAM_READY, DP_HDCP_2_2_REP_STREAM_READY_OFFSET,
6873 false, HDCP_2_2_STREAM_READY_TIMEOUT_MS, 0 },
6874 /* local define to shovel this through the write_2_2 interface */
6875 #define HDCP_2_2_ERRATA_DP_STREAM_TYPE 50
6876 { HDCP_2_2_ERRATA_DP_STREAM_TYPE,
6877 DP_HDCP_2_2_REG_STREAM_TYPE_OFFSET, false,
6882 intel_dp_hdcp2_read_rx_status(struct intel_digital_port *intel_dig_port,
6885 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6888 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
6889 DP_HDCP_2_2_REG_RXSTATUS_OFFSET, rx_status,
6890 HDCP_2_2_DP_RXSTATUS_LEN);
6891 if (ret != HDCP_2_2_DP_RXSTATUS_LEN) {
6892 drm_dbg_kms(&i915->drm,
6893 "Read bstatus from DP/AUX failed (%zd)\n", ret);
6894 return ret >= 0 ? -EIO : ret;
6901 int hdcp2_detect_msg_availability(struct intel_digital_port *intel_dig_port,
6902 u8 msg_id, bool *msg_ready)
6908 ret = intel_dp_hdcp2_read_rx_status(intel_dig_port, &rx_status);
6913 case HDCP_2_2_AKE_SEND_HPRIME:
6914 if (HDCP_2_2_DP_RXSTATUS_H_PRIME(rx_status))
6917 case HDCP_2_2_AKE_SEND_PAIRING_INFO:
6918 if (HDCP_2_2_DP_RXSTATUS_PAIRING(rx_status))
6921 case HDCP_2_2_REP_SEND_RECVID_LIST:
6922 if (HDCP_2_2_DP_RXSTATUS_READY(rx_status))
6926 DRM_ERROR("Unidentified msg_id: %d\n", msg_id);
6934 intel_dp_hdcp2_wait_for_msg(struct intel_digital_port *intel_dig_port,
6935 const struct hdcp2_dp_msg_data *hdcp2_msg_data)
6937 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
6938 struct intel_dp *dp = &intel_dig_port->dp;
6939 struct intel_hdcp *hdcp = &dp->attached_connector->hdcp;
6940 u8 msg_id = hdcp2_msg_data->msg_id;
6942 bool msg_ready = false;
6944 if (msg_id == HDCP_2_2_AKE_SEND_HPRIME && !hdcp->is_paired)
6945 timeout = hdcp2_msg_data->timeout2;
6947 timeout = hdcp2_msg_data->timeout;
6950 * There is no way to detect the CERT, LPRIME and STREAM_READY
6951 * availability. So Wait for timeout and read the msg.
6953 if (!hdcp2_msg_data->msg_detectable) {
6958 * As we want to check the msg availability at timeout, Ignoring
6959 * the timeout at wait for CP_IRQ.
6961 intel_dp_hdcp_wait_for_cp_irq(hdcp, timeout);
6962 ret = hdcp2_detect_msg_availability(intel_dig_port,
6963 msg_id, &msg_ready);
6969 drm_dbg_kms(&i915->drm,
6970 "msg_id %d, ret %d, timeout(mSec): %d\n",
6971 hdcp2_msg_data->msg_id, ret, timeout);
6976 static const struct hdcp2_dp_msg_data *get_hdcp2_dp_msg_data(u8 msg_id)
6980 for (i = 0; i < ARRAY_SIZE(hdcp2_dp_msg_data); i++)
6981 if (hdcp2_dp_msg_data[i].msg_id == msg_id)
6982 return &hdcp2_dp_msg_data[i];
6988 int intel_dp_hdcp2_write_msg(struct intel_digital_port *intel_dig_port,
6989 void *buf, size_t size)
6991 struct intel_dp *dp = &intel_dig_port->dp;
6992 struct intel_hdcp *hdcp = &dp->attached_connector->hdcp;
6993 unsigned int offset;
6995 ssize_t ret, bytes_to_write, len;
6996 const struct hdcp2_dp_msg_data *hdcp2_msg_data;
6998 hdcp2_msg_data = get_hdcp2_dp_msg_data(*byte);
6999 if (!hdcp2_msg_data)
7002 offset = hdcp2_msg_data->offset;
7004 /* No msg_id in DP HDCP2.2 msgs */
7005 bytes_to_write = size - 1;
7008 hdcp->cp_irq_count_cached = atomic_read(&hdcp->cp_irq_count);
7010 while (bytes_to_write) {
7011 len = bytes_to_write > DP_AUX_MAX_PAYLOAD_BYTES ?
7012 DP_AUX_MAX_PAYLOAD_BYTES : bytes_to_write;
7014 ret = drm_dp_dpcd_write(&intel_dig_port->dp.aux,
7015 offset, (void *)byte, len);
7019 bytes_to_write -= ret;
7028 ssize_t get_receiver_id_list_size(struct intel_digital_port *intel_dig_port)
7030 u8 rx_info[HDCP_2_2_RXINFO_LEN];
7034 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
7035 DP_HDCP_2_2_REG_RXINFO_OFFSET,
7036 (void *)rx_info, HDCP_2_2_RXINFO_LEN);
7037 if (ret != HDCP_2_2_RXINFO_LEN)
7038 return ret >= 0 ? -EIO : ret;
7040 dev_cnt = (HDCP_2_2_DEV_COUNT_HI(rx_info[0]) << 4 |
7041 HDCP_2_2_DEV_COUNT_LO(rx_info[1]));
7043 if (dev_cnt > HDCP_2_2_MAX_DEVICE_COUNT)
7044 dev_cnt = HDCP_2_2_MAX_DEVICE_COUNT;
7046 ret = sizeof(struct hdcp2_rep_send_receiverid_list) -
7047 HDCP_2_2_RECEIVER_IDS_MAX_LEN +
7048 (dev_cnt * HDCP_2_2_RECEIVER_ID_LEN);
7054 int intel_dp_hdcp2_read_msg(struct intel_digital_port *intel_dig_port,
7055 u8 msg_id, void *buf, size_t size)
7057 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
7058 unsigned int offset;
7060 ssize_t ret, bytes_to_recv, len;
7061 const struct hdcp2_dp_msg_data *hdcp2_msg_data;
7063 hdcp2_msg_data = get_hdcp2_dp_msg_data(msg_id);
7064 if (!hdcp2_msg_data)
7066 offset = hdcp2_msg_data->offset;
7068 ret = intel_dp_hdcp2_wait_for_msg(intel_dig_port, hdcp2_msg_data);
7072 if (msg_id == HDCP_2_2_REP_SEND_RECVID_LIST) {
7073 ret = get_receiver_id_list_size(intel_dig_port);
7079 bytes_to_recv = size - 1;
7081 /* DP adaptation msgs has no msg_id */
7084 while (bytes_to_recv) {
7085 len = bytes_to_recv > DP_AUX_MAX_PAYLOAD_BYTES ?
7086 DP_AUX_MAX_PAYLOAD_BYTES : bytes_to_recv;
7088 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux, offset,
7091 drm_dbg_kms(&i915->drm, "msg_id %d, ret %zd\n",
7096 bytes_to_recv -= ret;
7107 int intel_dp_hdcp2_config_stream_type(struct intel_digital_port *intel_dig_port,
7108 bool is_repeater, u8 content_type)
7111 struct hdcp2_dp_errata_stream_type stream_type_msg;
7117 * Errata for DP: As Stream type is used for encryption, Receiver
7118 * should be communicated with stream type for the decryption of the
7120 * Repeater will be communicated with stream type as a part of it's
7121 * auth later in time.
7123 stream_type_msg.msg_id = HDCP_2_2_ERRATA_DP_STREAM_TYPE;
7124 stream_type_msg.stream_type = content_type;
7126 ret = intel_dp_hdcp2_write_msg(intel_dig_port, &stream_type_msg,
7127 sizeof(stream_type_msg));
7129 return ret < 0 ? ret : 0;
7134 int intel_dp_hdcp2_check_link(struct intel_digital_port *intel_dig_port)
7139 ret = intel_dp_hdcp2_read_rx_status(intel_dig_port, &rx_status);
7143 if (HDCP_2_2_DP_RXSTATUS_REAUTH_REQ(rx_status))
7144 ret = HDCP_REAUTH_REQUEST;
7145 else if (HDCP_2_2_DP_RXSTATUS_LINK_FAILED(rx_status))
7146 ret = HDCP_LINK_INTEGRITY_FAILURE;
7147 else if (HDCP_2_2_DP_RXSTATUS_READY(rx_status))
7148 ret = HDCP_TOPOLOGY_CHANGE;
7154 int intel_dp_hdcp2_capable(struct intel_digital_port *intel_dig_port,
7161 ret = drm_dp_dpcd_read(&intel_dig_port->dp.aux,
7162 DP_HDCP_2_2_REG_RX_CAPS_OFFSET,
7163 rx_caps, HDCP_2_2_RXCAPS_LEN);
7164 if (ret != HDCP_2_2_RXCAPS_LEN)
7165 return ret >= 0 ? -EIO : ret;
7167 if (rx_caps[0] == HDCP_2_2_RX_CAPS_VERSION_VAL &&
7168 HDCP_2_2_DP_HDCP_CAPABLE(rx_caps[2]))
7174 static const struct intel_hdcp_shim intel_dp_hdcp_shim = {
7175 .write_an_aksv = intel_dp_hdcp_write_an_aksv,
7176 .read_bksv = intel_dp_hdcp_read_bksv,
7177 .read_bstatus = intel_dp_hdcp_read_bstatus,
7178 .repeater_present = intel_dp_hdcp_repeater_present,
7179 .read_ri_prime = intel_dp_hdcp_read_ri_prime,
7180 .read_ksv_ready = intel_dp_hdcp_read_ksv_ready,
7181 .read_ksv_fifo = intel_dp_hdcp_read_ksv_fifo,
7182 .read_v_prime_part = intel_dp_hdcp_read_v_prime_part,
7183 .toggle_signalling = intel_dp_hdcp_toggle_signalling,
7184 .check_link = intel_dp_hdcp_check_link,
7185 .hdcp_capable = intel_dp_hdcp_capable,
7186 .write_2_2_msg = intel_dp_hdcp2_write_msg,
7187 .read_2_2_msg = intel_dp_hdcp2_read_msg,
7188 .config_stream_type = intel_dp_hdcp2_config_stream_type,
7189 .check_2_2_link = intel_dp_hdcp2_check_link,
7190 .hdcp_2_2_capable = intel_dp_hdcp2_capable,
7191 .protocol = HDCP_PROTOCOL_DP,
7194 static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
7196 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7197 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
7199 lockdep_assert_held(&dev_priv->pps_mutex);
7201 if (!edp_have_panel_vdd(intel_dp))
7205 * The VDD bit needs a power domain reference, so if the bit is
7206 * already enabled when we boot or resume, grab this reference and
7207 * schedule a vdd off, so we don't hold on to the reference
7210 drm_dbg_kms(&dev_priv->drm,
7211 "VDD left on by BIOS, adjusting state tracking\n");
7212 intel_display_power_get(dev_priv, intel_aux_power_domain(dig_port));
7214 edp_panel_vdd_schedule_off(intel_dp);
7217 static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
7219 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7220 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
7223 if (intel_dp_port_enabled(dev_priv, intel_dp->output_reg,
7224 encoder->port, &pipe))
7227 return INVALID_PIPE;
7230 void intel_dp_encoder_reset(struct drm_encoder *encoder)
7232 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
7233 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(encoder));
7234 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
7235 intel_wakeref_t wakeref;
7237 if (!HAS_DDI(dev_priv))
7238 intel_dp->DP = intel_de_read(dev_priv, intel_dp->output_reg);
7241 lspcon_resume(lspcon);
7243 intel_dp->reset_link_params = true;
7245 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
7246 !intel_dp_is_edp(intel_dp))
7249 with_pps_lock(intel_dp, wakeref) {
7250 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
7251 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
7253 if (intel_dp_is_edp(intel_dp)) {
7255 * Reinit the power sequencer, in case BIOS did
7256 * something nasty with it.
7258 intel_dp_pps_init(intel_dp);
7259 intel_edp_panel_vdd_sanitize(intel_dp);
7264 static int intel_modeset_tile_group(struct intel_atomic_state *state,
7267 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7268 struct drm_connector_list_iter conn_iter;
7269 struct drm_connector *connector;
7272 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
7273 drm_for_each_connector_iter(connector, &conn_iter) {
7274 struct drm_connector_state *conn_state;
7275 struct intel_crtc_state *crtc_state;
7276 struct intel_crtc *crtc;
7278 if (!connector->has_tile ||
7279 connector->tile_group->id != tile_group_id)
7282 conn_state = drm_atomic_get_connector_state(&state->base,
7284 if (IS_ERR(conn_state)) {
7285 ret = PTR_ERR(conn_state);
7289 crtc = to_intel_crtc(conn_state->crtc);
7294 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
7295 crtc_state->uapi.mode_changed = true;
7297 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base);
7301 drm_connector_list_iter_end(&conn_iter);
7306 static int intel_modeset_affected_transcoders(struct intel_atomic_state *state, u8 transcoders)
7308 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7309 struct intel_crtc *crtc;
7311 if (transcoders == 0)
7314 for_each_intel_crtc(&dev_priv->drm, crtc) {
7315 struct intel_crtc_state *crtc_state;
7318 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
7319 if (IS_ERR(crtc_state))
7320 return PTR_ERR(crtc_state);
7322 if (!crtc_state->hw.enable)
7325 if (!(transcoders & BIT(crtc_state->cpu_transcoder)))
7328 crtc_state->uapi.mode_changed = true;
7330 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
7334 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base);
7338 transcoders &= ~BIT(crtc_state->cpu_transcoder);
7341 drm_WARN_ON(&dev_priv->drm, transcoders != 0);
7346 static int intel_modeset_synced_crtcs(struct intel_atomic_state *state,
7347 struct drm_connector *connector)
7349 const struct drm_connector_state *old_conn_state =
7350 drm_atomic_get_old_connector_state(&state->base, connector);
7351 const struct intel_crtc_state *old_crtc_state;
7352 struct intel_crtc *crtc;
7355 crtc = to_intel_crtc(old_conn_state->crtc);
7359 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
7361 if (!old_crtc_state->hw.active)
7364 transcoders = old_crtc_state->sync_mode_slaves_mask;
7365 if (old_crtc_state->master_transcoder != INVALID_TRANSCODER)
7366 transcoders |= BIT(old_crtc_state->master_transcoder);
7368 return intel_modeset_affected_transcoders(state,
7372 static int intel_dp_connector_atomic_check(struct drm_connector *conn,
7373 struct drm_atomic_state *_state)
7375 struct drm_i915_private *dev_priv = to_i915(conn->dev);
7376 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7379 ret = intel_digital_connector_atomic_check(conn, &state->base);
7384 * We don't enable port sync on BDW due to missing w/as and
7385 * due to not having adjusted the modeset sequence appropriately.
7387 if (INTEL_GEN(dev_priv) < 9)
7390 if (!intel_connector_needs_modeset(state, conn))
7393 if (conn->has_tile) {
7394 ret = intel_modeset_tile_group(state, conn->tile_group->id);
7399 return intel_modeset_synced_crtcs(state, conn);
7402 static const struct drm_connector_funcs intel_dp_connector_funcs = {
7403 .force = intel_dp_force,
7404 .fill_modes = drm_helper_probe_single_connector_modes,
7405 .atomic_get_property = intel_digital_connector_atomic_get_property,
7406 .atomic_set_property = intel_digital_connector_atomic_set_property,
7407 .late_register = intel_dp_connector_register,
7408 .early_unregister = intel_dp_connector_unregister,
7409 .destroy = intel_connector_destroy,
7410 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
7411 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
7414 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
7415 .detect_ctx = intel_dp_detect,
7416 .get_modes = intel_dp_get_modes,
7417 .mode_valid = intel_dp_mode_valid,
7418 .atomic_check = intel_dp_connector_atomic_check,
7421 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
7422 .reset = intel_dp_encoder_reset,
7423 .destroy = intel_dp_encoder_destroy,
7426 static bool intel_edp_have_power(struct intel_dp *intel_dp)
7428 intel_wakeref_t wakeref;
7429 bool have_power = false;
7431 with_pps_lock(intel_dp, wakeref) {
7432 have_power = edp_have_panel_power(intel_dp) &&
7433 edp_have_panel_vdd(intel_dp);
7440 intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
7442 struct drm_i915_private *i915 = to_i915(intel_dig_port->base.base.dev);
7443 struct intel_dp *intel_dp = &intel_dig_port->dp;
7445 if (intel_dig_port->base.type == INTEL_OUTPUT_EDP &&
7446 (long_hpd || !intel_edp_have_power(intel_dp))) {
7448 * vdd off can generate a long/short pulse on eDP which
7449 * would require vdd on to handle it, and thus we
7450 * would end up in an endless cycle of
7451 * "vdd off -> long/short hpd -> vdd on -> detect -> vdd off -> ..."
7453 drm_dbg_kms(&i915->drm,
7454 "ignoring %s hpd on eDP [ENCODER:%d:%s]\n",
7455 long_hpd ? "long" : "short",
7456 intel_dig_port->base.base.base.id,
7457 intel_dig_port->base.base.name);
7461 drm_dbg_kms(&i915->drm, "got hpd irq on [ENCODER:%d:%s] - %s\n",
7462 intel_dig_port->base.base.base.id,
7463 intel_dig_port->base.base.name,
7464 long_hpd ? "long" : "short");
7467 intel_dp->reset_link_params = true;
7471 if (intel_dp->is_mst) {
7472 switch (intel_dp_check_mst_status(intel_dp)) {
7475 * If we were in MST mode, and device is not
7476 * there, get out of MST mode
7478 drm_dbg_kms(&i915->drm,
7479 "MST device may have disappeared %d vs %d\n",
7481 intel_dp->mst_mgr.mst_state);
7482 intel_dp->is_mst = false;
7483 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
7494 if (!intel_dp->is_mst) {
7497 handled = intel_dp_short_pulse(intel_dp);
7506 /* check the VBT to see whether the eDP is on another port */
7507 bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
7510 * eDP not supported on g4x. so bail out early just
7511 * for a bit extra safety in case the VBT is bonkers.
7513 if (INTEL_GEN(dev_priv) < 5)
7516 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
7519 return intel_bios_is_port_edp(dev_priv, port);
7523 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
7525 struct drm_i915_private *dev_priv = to_i915(connector->dev);
7526 enum port port = dp_to_dig_port(intel_dp)->base.port;
7528 if (!IS_G4X(dev_priv) && port != PORT_A)
7529 intel_attach_force_audio_property(connector);
7531 intel_attach_broadcast_rgb_property(connector);
7532 if (HAS_GMCH(dev_priv))
7533 drm_connector_attach_max_bpc_property(connector, 6, 10);
7534 else if (INTEL_GEN(dev_priv) >= 5)
7535 drm_connector_attach_max_bpc_property(connector, 6, 12);
7537 intel_attach_colorspace_property(connector);
7539 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 11)
7540 drm_object_attach_property(&connector->base,
7541 connector->dev->mode_config.hdr_output_metadata_property,
7544 if (intel_dp_is_edp(intel_dp)) {
7545 u32 allowed_scalers;
7547 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
7548 if (!HAS_GMCH(dev_priv))
7549 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
7551 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
7553 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
7558 static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
7560 intel_dp->panel_power_off_time = ktime_get_boottime();
7561 intel_dp->last_power_on = jiffies;
7562 intel_dp->last_backlight_off = jiffies;
7566 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
7568 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7569 u32 pp_on, pp_off, pp_ctl;
7570 struct pps_registers regs;
7572 intel_pps_get_registers(intel_dp, ®s);
7574 pp_ctl = ilk_get_pp_control(intel_dp);
7576 /* Ensure PPS is unlocked */
7577 if (!HAS_DDI(dev_priv))
7578 intel_de_write(dev_priv, regs.pp_ctrl, pp_ctl);
7580 pp_on = intel_de_read(dev_priv, regs.pp_on);
7581 pp_off = intel_de_read(dev_priv, regs.pp_off);
7583 /* Pull timing values out of registers */
7584 seq->t1_t3 = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, pp_on);
7585 seq->t8 = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, pp_on);
7586 seq->t9 = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, pp_off);
7587 seq->t10 = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, pp_off);
7589 if (i915_mmio_reg_valid(regs.pp_div)) {
7592 pp_div = intel_de_read(dev_priv, regs.pp_div);
7594 seq->t11_t12 = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, pp_div) * 1000;
7596 seq->t11_t12 = REG_FIELD_GET(BXT_POWER_CYCLE_DELAY_MASK, pp_ctl) * 1000;
7601 intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
7603 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
7605 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
7609 intel_pps_verify_state(struct intel_dp *intel_dp)
7611 struct edp_power_seq hw;
7612 struct edp_power_seq *sw = &intel_dp->pps_delays;
7614 intel_pps_readout_hw_state(intel_dp, &hw);
7616 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
7617 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
7618 DRM_ERROR("PPS state mismatch\n");
7619 intel_pps_dump_state("sw", sw);
7620 intel_pps_dump_state("hw", &hw);
7625 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp)
7627 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7628 struct edp_power_seq cur, vbt, spec,
7629 *final = &intel_dp->pps_delays;
7631 lockdep_assert_held(&dev_priv->pps_mutex);
7633 /* already initialized? */
7634 if (final->t11_t12 != 0)
7637 intel_pps_readout_hw_state(intel_dp, &cur);
7639 intel_pps_dump_state("cur", &cur);
7641 vbt = dev_priv->vbt.edp.pps;
7642 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
7643 * of 500ms appears to be too short. Ocassionally the panel
7644 * just fails to power back on. Increasing the delay to 800ms
7645 * seems sufficient to avoid this problem.
7647 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
7648 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
7649 drm_dbg_kms(&dev_priv->drm,
7650 "Increasing T12 panel delay as per the quirk to %d\n",
7653 /* T11_T12 delay is special and actually in units of 100ms, but zero
7654 * based in the hw (so we need to add 100 ms). But the sw vbt
7655 * table multiplies it with 1000 to make it in units of 100usec,
7657 vbt.t11_t12 += 100 * 10;
7659 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
7660 * our hw here, which are all in 100usec. */
7661 spec.t1_t3 = 210 * 10;
7662 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
7663 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
7664 spec.t10 = 500 * 10;
7665 /* This one is special and actually in units of 100ms, but zero
7666 * based in the hw (so we need to add 100 ms). But the sw vbt
7667 * table multiplies it with 1000 to make it in units of 100usec,
7669 spec.t11_t12 = (510 + 100) * 10;
7671 intel_pps_dump_state("vbt", &vbt);
7673 /* Use the max of the register settings and vbt. If both are
7674 * unset, fall back to the spec limits. */
7675 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
7677 max(cur.field, vbt.field))
7678 assign_final(t1_t3);
7682 assign_final(t11_t12);
7685 #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
7686 intel_dp->panel_power_up_delay = get_delay(t1_t3);
7687 intel_dp->backlight_on_delay = get_delay(t8);
7688 intel_dp->backlight_off_delay = get_delay(t9);
7689 intel_dp->panel_power_down_delay = get_delay(t10);
7690 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
7693 drm_dbg_kms(&dev_priv->drm,
7694 "panel power up delay %d, power down delay %d, power cycle delay %d\n",
7695 intel_dp->panel_power_up_delay,
7696 intel_dp->panel_power_down_delay,
7697 intel_dp->panel_power_cycle_delay);
7699 drm_dbg_kms(&dev_priv->drm, "backlight on delay %d, off delay %d\n",
7700 intel_dp->backlight_on_delay,
7701 intel_dp->backlight_off_delay);
7704 * We override the HW backlight delays to 1 because we do manual waits
7705 * on them. For T8, even BSpec recommends doing it. For T9, if we
7706 * don't do this, we'll end up waiting for the backlight off delay
7707 * twice: once when we do the manual sleep, and once when we disable
7708 * the panel and wait for the PP_STATUS bit to become zero.
7714 * HW has only a 100msec granularity for t11_t12 so round it up
7717 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
7721 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
7722 bool force_disable_vdd)
7724 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7725 u32 pp_on, pp_off, port_sel = 0;
7726 int div = RUNTIME_INFO(dev_priv)->rawclk_freq / 1000;
7727 struct pps_registers regs;
7728 enum port port = dp_to_dig_port(intel_dp)->base.port;
7729 const struct edp_power_seq *seq = &intel_dp->pps_delays;
7731 lockdep_assert_held(&dev_priv->pps_mutex);
7733 intel_pps_get_registers(intel_dp, ®s);
7736 * On some VLV machines the BIOS can leave the VDD
7737 * enabled even on power sequencers which aren't
7738 * hooked up to any port. This would mess up the
7739 * power domain tracking the first time we pick
7740 * one of these power sequencers for use since
7741 * edp_panel_vdd_on() would notice that the VDD was
7742 * already on and therefore wouldn't grab the power
7743 * domain reference. Disable VDD first to avoid this.
7744 * This also avoids spuriously turning the VDD on as
7745 * soon as the new power sequencer gets initialized.
7747 if (force_disable_vdd) {
7748 u32 pp = ilk_get_pp_control(intel_dp);
7750 drm_WARN(&dev_priv->drm, pp & PANEL_POWER_ON,
7751 "Panel power already on\n");
7753 if (pp & EDP_FORCE_VDD)
7754 drm_dbg_kms(&dev_priv->drm,
7755 "VDD already on, disabling first\n");
7757 pp &= ~EDP_FORCE_VDD;
7759 intel_de_write(dev_priv, regs.pp_ctrl, pp);
7762 pp_on = REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, seq->t1_t3) |
7763 REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, seq->t8);
7764 pp_off = REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, seq->t9) |
7765 REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, seq->t10);
7767 /* Haswell doesn't have any port selection bits for the panel
7768 * power sequencer any more. */
7769 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7770 port_sel = PANEL_PORT_SELECT_VLV(port);
7771 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
7774 port_sel = PANEL_PORT_SELECT_DPA;
7777 port_sel = PANEL_PORT_SELECT_DPC;
7780 port_sel = PANEL_PORT_SELECT_DPD;
7790 intel_de_write(dev_priv, regs.pp_on, pp_on);
7791 intel_de_write(dev_priv, regs.pp_off, pp_off);
7794 * Compute the divisor for the pp clock, simply match the Bspec formula.
7796 if (i915_mmio_reg_valid(regs.pp_div)) {
7797 intel_de_write(dev_priv, regs.pp_div,
7798 REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, (100 * div) / 2 - 1) | REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000)));
7802 pp_ctl = intel_de_read(dev_priv, regs.pp_ctrl);
7803 pp_ctl &= ~BXT_POWER_CYCLE_DELAY_MASK;
7804 pp_ctl |= REG_FIELD_PREP(BXT_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000));
7805 intel_de_write(dev_priv, regs.pp_ctrl, pp_ctl);
7808 drm_dbg_kms(&dev_priv->drm,
7809 "panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
7810 intel_de_read(dev_priv, regs.pp_on),
7811 intel_de_read(dev_priv, regs.pp_off),
7812 i915_mmio_reg_valid(regs.pp_div) ?
7813 intel_de_read(dev_priv, regs.pp_div) :
7814 (intel_de_read(dev_priv, regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK));
7817 static void intel_dp_pps_init(struct intel_dp *intel_dp)
7819 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7821 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7822 vlv_initial_power_sequencer_setup(intel_dp);
7824 intel_dp_init_panel_power_sequencer(intel_dp);
7825 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
7830 * intel_dp_set_drrs_state - program registers for RR switch to take effect
7831 * @dev_priv: i915 device
7832 * @crtc_state: a pointer to the active intel_crtc_state
7833 * @refresh_rate: RR to be programmed
7835 * This function gets called when refresh rate (RR) has to be changed from
7836 * one frequency to another. Switches can be between high and low RR
7837 * supported by the panel or to any other RR based on media playback (in
7838 * this case, RR value needs to be passed from user space).
7840 * The caller of this function needs to take a lock on dev_priv->drrs.
7842 static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
7843 const struct intel_crtc_state *crtc_state,
7846 struct intel_dp *intel_dp = dev_priv->drrs.dp;
7847 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
7848 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
7850 if (refresh_rate <= 0) {
7851 drm_dbg_kms(&dev_priv->drm,
7852 "Refresh rate should be positive non-zero.\n");
7856 if (intel_dp == NULL) {
7857 drm_dbg_kms(&dev_priv->drm, "DRRS not supported.\n");
7862 drm_dbg_kms(&dev_priv->drm,
7863 "DRRS: intel_crtc not initialized\n");
7867 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
7868 drm_dbg_kms(&dev_priv->drm, "Only Seamless DRRS supported.\n");
7872 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
7874 index = DRRS_LOW_RR;
7876 if (index == dev_priv->drrs.refresh_rate_type) {
7877 drm_dbg_kms(&dev_priv->drm,
7878 "DRRS requested for previously set RR...ignoring\n");
7882 if (!crtc_state->hw.active) {
7883 drm_dbg_kms(&dev_priv->drm,
7884 "eDP encoder disabled. CRTC not Active\n");
7888 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
7891 intel_dp_set_m_n(crtc_state, M1_N1);
7894 intel_dp_set_m_n(crtc_state, M2_N2);
7898 drm_err(&dev_priv->drm,
7899 "Unsupported refreshrate type\n");
7901 } else if (INTEL_GEN(dev_priv) > 6) {
7902 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
7905 val = intel_de_read(dev_priv, reg);
7906 if (index > DRRS_HIGH_RR) {
7907 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
7908 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
7910 val |= PIPECONF_EDP_RR_MODE_SWITCH;
7912 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
7913 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
7915 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
7917 intel_de_write(dev_priv, reg, val);
7920 dev_priv->drrs.refresh_rate_type = index;
7922 drm_dbg_kms(&dev_priv->drm, "eDP Refresh Rate set to : %dHz\n",
7927 * intel_edp_drrs_enable - init drrs struct if supported
7928 * @intel_dp: DP struct
7929 * @crtc_state: A pointer to the active crtc state.
7931 * Initializes frontbuffer_bits and drrs.dp
7933 void intel_edp_drrs_enable(struct intel_dp *intel_dp,
7934 const struct intel_crtc_state *crtc_state)
7936 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7938 if (!crtc_state->has_drrs) {
7939 drm_dbg_kms(&dev_priv->drm, "Panel doesn't support DRRS\n");
7943 if (dev_priv->psr.enabled) {
7944 drm_dbg_kms(&dev_priv->drm,
7945 "PSR enabled. Not enabling DRRS.\n");
7949 mutex_lock(&dev_priv->drrs.mutex);
7950 if (dev_priv->drrs.dp) {
7951 drm_dbg_kms(&dev_priv->drm, "DRRS already enabled\n");
7955 dev_priv->drrs.busy_frontbuffer_bits = 0;
7957 dev_priv->drrs.dp = intel_dp;
7960 mutex_unlock(&dev_priv->drrs.mutex);
7964 * intel_edp_drrs_disable - Disable DRRS
7965 * @intel_dp: DP struct
7966 * @old_crtc_state: Pointer to old crtc_state.
7969 void intel_edp_drrs_disable(struct intel_dp *intel_dp,
7970 const struct intel_crtc_state *old_crtc_state)
7972 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
7974 if (!old_crtc_state->has_drrs)
7977 mutex_lock(&dev_priv->drrs.mutex);
7978 if (!dev_priv->drrs.dp) {
7979 mutex_unlock(&dev_priv->drrs.mutex);
7983 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
7984 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
7985 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
7987 dev_priv->drrs.dp = NULL;
7988 mutex_unlock(&dev_priv->drrs.mutex);
7990 cancel_delayed_work_sync(&dev_priv->drrs.work);
7993 static void intel_edp_drrs_downclock_work(struct work_struct *work)
7995 struct drm_i915_private *dev_priv =
7996 container_of(work, typeof(*dev_priv), drrs.work.work);
7997 struct intel_dp *intel_dp;
7999 mutex_lock(&dev_priv->drrs.mutex);
8001 intel_dp = dev_priv->drrs.dp;
8007 * The delayed work can race with an invalidate hence we need to
8011 if (dev_priv->drrs.busy_frontbuffer_bits)
8014 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
8015 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
8017 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
8018 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
8022 mutex_unlock(&dev_priv->drrs.mutex);
8026 * intel_edp_drrs_invalidate - Disable Idleness DRRS
8027 * @dev_priv: i915 device
8028 * @frontbuffer_bits: frontbuffer plane tracking bits
8030 * This function gets called everytime rendering on the given planes start.
8031 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
8033 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
8035 void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
8036 unsigned int frontbuffer_bits)
8038 struct drm_crtc *crtc;
8041 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
8044 cancel_delayed_work(&dev_priv->drrs.work);
8046 mutex_lock(&dev_priv->drrs.mutex);
8047 if (!dev_priv->drrs.dp) {
8048 mutex_unlock(&dev_priv->drrs.mutex);
8052 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
8053 pipe = to_intel_crtc(crtc)->pipe;
8055 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
8056 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
8058 /* invalidate means busy screen hence upclock */
8059 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
8060 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
8061 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
8063 mutex_unlock(&dev_priv->drrs.mutex);
8067 * intel_edp_drrs_flush - Restart Idleness DRRS
8068 * @dev_priv: i915 device
8069 * @frontbuffer_bits: frontbuffer plane tracking bits
8071 * This function gets called every time rendering on the given planes has
8072 * completed or flip on a crtc is completed. So DRRS should be upclocked
8073 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
8074 * if no other planes are dirty.
8076 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
8078 void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
8079 unsigned int frontbuffer_bits)
8081 struct drm_crtc *crtc;
8084 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
8087 cancel_delayed_work(&dev_priv->drrs.work);
8089 mutex_lock(&dev_priv->drrs.mutex);
8090 if (!dev_priv->drrs.dp) {
8091 mutex_unlock(&dev_priv->drrs.mutex);
8095 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
8096 pipe = to_intel_crtc(crtc)->pipe;
8098 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
8099 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
8101 /* flush means busy screen hence upclock */
8102 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
8103 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
8104 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
8107 * flush also means no more activity hence schedule downclock, if all
8108 * other fbs are quiescent too
8110 if (!dev_priv->drrs.busy_frontbuffer_bits)
8111 schedule_delayed_work(&dev_priv->drrs.work,
8112 msecs_to_jiffies(1000));
8113 mutex_unlock(&dev_priv->drrs.mutex);
8117 * DOC: Display Refresh Rate Switching (DRRS)
8119 * Display Refresh Rate Switching (DRRS) is a power conservation feature
8120 * which enables swtching between low and high refresh rates,
8121 * dynamically, based on the usage scenario. This feature is applicable
8122 * for internal panels.
8124 * Indication that the panel supports DRRS is given by the panel EDID, which
8125 * would list multiple refresh rates for one resolution.
8127 * DRRS is of 2 types - static and seamless.
8128 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
8129 * (may appear as a blink on screen) and is used in dock-undock scenario.
8130 * Seamless DRRS involves changing RR without any visual effect to the user
8131 * and can be used during normal system usage. This is done by programming
8132 * certain registers.
8134 * Support for static/seamless DRRS may be indicated in the VBT based on
8135 * inputs from the panel spec.
8137 * DRRS saves power by switching to low RR based on usage scenarios.
8139 * The implementation is based on frontbuffer tracking implementation. When
8140 * there is a disturbance on the screen triggered by user activity or a periodic
8141 * system activity, DRRS is disabled (RR is changed to high RR). When there is
8142 * no movement on screen, after a timeout of 1 second, a switch to low RR is
8145 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
8146 * and intel_edp_drrs_flush() are called.
8148 * DRRS can be further extended to support other internal panels and also
8149 * the scenario of video playback wherein RR is set based on the rate
8150 * requested by userspace.
8154 * intel_dp_drrs_init - Init basic DRRS work and mutex.
8155 * @connector: eDP connector
8156 * @fixed_mode: preferred mode of panel
8158 * This function is called only once at driver load to initialize basic
8162 * Downclock mode if panel supports it, else return NULL.
8163 * DRRS support is determined by the presence of downclock mode (apart
8164 * from VBT setting).
8166 static struct drm_display_mode *
8167 intel_dp_drrs_init(struct intel_connector *connector,
8168 struct drm_display_mode *fixed_mode)
8170 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
8171 struct drm_display_mode *downclock_mode = NULL;
8173 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
8174 mutex_init(&dev_priv->drrs.mutex);
8176 if (INTEL_GEN(dev_priv) <= 6) {
8177 drm_dbg_kms(&dev_priv->drm,
8178 "DRRS supported for Gen7 and above\n");
8182 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
8183 drm_dbg_kms(&dev_priv->drm, "VBT doesn't support DRRS\n");
8187 downclock_mode = intel_panel_edid_downclock_mode(connector, fixed_mode);
8188 if (!downclock_mode) {
8189 drm_dbg_kms(&dev_priv->drm,
8190 "Downclock mode is not found. DRRS not supported\n");
8194 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
8196 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
8197 drm_dbg_kms(&dev_priv->drm,
8198 "seamless DRRS supported for eDP panel.\n");
8199 return downclock_mode;
8202 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
8203 struct intel_connector *intel_connector)
8205 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
8206 struct drm_device *dev = &dev_priv->drm;
8207 struct drm_connector *connector = &intel_connector->base;
8208 struct drm_display_mode *fixed_mode = NULL;
8209 struct drm_display_mode *downclock_mode = NULL;
8211 enum pipe pipe = INVALID_PIPE;
8212 intel_wakeref_t wakeref;
8215 if (!intel_dp_is_edp(intel_dp))
8218 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, edp_panel_vdd_work);
8221 * On IBX/CPT we may get here with LVDS already registered. Since the
8222 * driver uses the only internal power sequencer available for both
8223 * eDP and LVDS bail out early in this case to prevent interfering
8224 * with an already powered-on LVDS power sequencer.
8226 if (intel_get_lvds_encoder(dev_priv)) {
8228 !(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
8229 drm_info(&dev_priv->drm,
8230 "LVDS was detected, not registering eDP\n");
8235 with_pps_lock(intel_dp, wakeref) {
8236 intel_dp_init_panel_power_timestamps(intel_dp);
8237 intel_dp_pps_init(intel_dp);
8238 intel_edp_panel_vdd_sanitize(intel_dp);
8241 /* Cache DPCD and EDID for edp. */
8242 has_dpcd = intel_edp_init_dpcd(intel_dp);
8245 /* if this fails, presume the device is a ghost */
8246 drm_info(&dev_priv->drm,
8247 "failed to retrieve link info, disabling eDP\n");
8251 mutex_lock(&dev->mode_config.mutex);
8252 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
8254 if (drm_add_edid_modes(connector, edid)) {
8255 drm_connector_update_edid_property(connector, edid);
8256 intel_dp->edid_quirks = drm_dp_get_edid_quirks(edid);
8259 edid = ERR_PTR(-EINVAL);
8262 edid = ERR_PTR(-ENOENT);
8264 intel_connector->edid = edid;
8266 fixed_mode = intel_panel_edid_fixed_mode(intel_connector);
8268 downclock_mode = intel_dp_drrs_init(intel_connector, fixed_mode);
8270 /* fallback to VBT if available for eDP */
8272 fixed_mode = intel_panel_vbt_fixed_mode(intel_connector);
8273 mutex_unlock(&dev->mode_config.mutex);
8275 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
8276 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
8277 register_reboot_notifier(&intel_dp->edp_notifier);
8280 * Figure out the current pipe for the initial backlight setup.
8281 * If the current pipe isn't valid, try the PPS pipe, and if that
8282 * fails just assume pipe A.
8284 pipe = vlv_active_pipe(intel_dp);
8286 if (pipe != PIPE_A && pipe != PIPE_B)
8287 pipe = intel_dp->pps_pipe;
8289 if (pipe != PIPE_A && pipe != PIPE_B)
8292 drm_dbg_kms(&dev_priv->drm,
8293 "using pipe %c for initial backlight setup\n",
8297 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
8298 intel_connector->panel.backlight.power = intel_edp_backlight_power;
8299 intel_panel_setup_backlight(connector, pipe);
8302 drm_connector_set_panel_orientation_with_quirk(connector,
8303 dev_priv->vbt.orientation,
8304 fixed_mode->hdisplay, fixed_mode->vdisplay);
8310 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
8312 * vdd might still be enabled do to the delayed vdd off.
8313 * Make sure vdd is actually turned off here.
8315 with_pps_lock(intel_dp, wakeref)
8316 edp_panel_vdd_off_sync(intel_dp);
8321 static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
8323 struct intel_connector *intel_connector;
8324 struct drm_connector *connector;
8326 intel_connector = container_of(work, typeof(*intel_connector),
8327 modeset_retry_work);
8328 connector = &intel_connector->base;
8329 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
8332 /* Grab the locks before changing connector property*/
8333 mutex_lock(&connector->dev->mode_config.mutex);
8334 /* Set connector link status to BAD and send a Uevent to notify
8335 * userspace to do a modeset.
8337 drm_connector_set_link_status_property(connector,
8338 DRM_MODE_LINK_STATUS_BAD);
8339 mutex_unlock(&connector->dev->mode_config.mutex);
8340 /* Send Hotplug uevent so userspace can reprobe */
8341 drm_kms_helper_hotplug_event(connector->dev);
8345 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
8346 struct intel_connector *intel_connector)
8348 struct drm_connector *connector = &intel_connector->base;
8349 struct intel_dp *intel_dp = &intel_dig_port->dp;
8350 struct intel_encoder *intel_encoder = &intel_dig_port->base;
8351 struct drm_device *dev = intel_encoder->base.dev;
8352 struct drm_i915_private *dev_priv = to_i915(dev);
8353 enum port port = intel_encoder->port;
8354 enum phy phy = intel_port_to_phy(dev_priv, port);
8357 /* Initialize the work for modeset in case of link train failure */
8358 INIT_WORK(&intel_connector->modeset_retry_work,
8359 intel_dp_modeset_retry_work_fn);
8361 if (drm_WARN(dev, intel_dig_port->max_lanes < 1,
8362 "Not enough lanes (%d) for DP on [ENCODER:%d:%s]\n",
8363 intel_dig_port->max_lanes, intel_encoder->base.base.id,
8364 intel_encoder->base.name))
8367 intel_dp_set_source_rates(intel_dp);
8369 intel_dp->reset_link_params = true;
8370 intel_dp->pps_pipe = INVALID_PIPE;
8371 intel_dp->active_pipe = INVALID_PIPE;
8373 /* Preserve the current hw state. */
8374 intel_dp->DP = intel_de_read(dev_priv, intel_dp->output_reg);
8375 intel_dp->attached_connector = intel_connector;
8377 if (intel_dp_is_port_edp(dev_priv, port)) {
8379 * Currently we don't support eDP on TypeC ports, although in
8380 * theory it could work on TypeC legacy ports.
8382 drm_WARN_ON(dev, intel_phy_is_tc(dev_priv, phy));
8383 type = DRM_MODE_CONNECTOR_eDP;
8385 type = DRM_MODE_CONNECTOR_DisplayPort;
8388 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
8389 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
8392 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
8393 * for DP the encoder type can be set by the caller to
8394 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
8396 if (type == DRM_MODE_CONNECTOR_eDP)
8397 intel_encoder->type = INTEL_OUTPUT_EDP;
8399 /* eDP only on port B and/or C on vlv/chv */
8400 if (drm_WARN_ON(dev, (IS_VALLEYVIEW(dev_priv) ||
8401 IS_CHERRYVIEW(dev_priv)) &&
8402 intel_dp_is_edp(intel_dp) &&
8403 port != PORT_B && port != PORT_C))
8406 drm_dbg_kms(&dev_priv->drm,
8407 "Adding %s connector on [ENCODER:%d:%s]\n",
8408 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
8409 intel_encoder->base.base.id, intel_encoder->base.name);
8411 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
8412 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
8414 if (!HAS_GMCH(dev_priv))
8415 connector->interlace_allowed = true;
8416 connector->doublescan_allowed = 0;
8418 if (INTEL_GEN(dev_priv) >= 11)
8419 connector->ycbcr_420_allowed = true;
8421 intel_encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port);
8422 intel_connector->polled = DRM_CONNECTOR_POLL_HPD;
8424 intel_dp_aux_init(intel_dp);
8426 intel_connector_attach_encoder(intel_connector, intel_encoder);
8428 if (HAS_DDI(dev_priv))
8429 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
8431 intel_connector->get_hw_state = intel_connector_get_hw_state;
8433 /* init MST on ports that can support it */
8434 intel_dp_mst_encoder_init(intel_dig_port,
8435 intel_connector->base.base.id);
8437 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
8438 intel_dp_aux_fini(intel_dp);
8439 intel_dp_mst_encoder_cleanup(intel_dig_port);
8443 intel_dp_add_properties(intel_dp, connector);
8445 if (is_hdcp_supported(dev_priv, port) && !intel_dp_is_edp(intel_dp)) {
8446 int ret = intel_hdcp_init(intel_connector, &intel_dp_hdcp_shim);
8448 drm_dbg_kms(&dev_priv->drm,
8449 "HDCP init failed, skipping.\n");
8452 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
8453 * 0xd. Failure to do so will result in spurious interrupts being
8454 * generated on the port when a cable is not attached.
8456 if (IS_G45(dev_priv)) {
8457 u32 temp = intel_de_read(dev_priv, PEG_BAND_GAP_DATA);
8458 intel_de_write(dev_priv, PEG_BAND_GAP_DATA,
8459 (temp & ~0xf) | 0xd);
8465 drm_connector_cleanup(connector);
8470 bool intel_dp_init(struct drm_i915_private *dev_priv,
8471 i915_reg_t output_reg,
8474 struct intel_digital_port *intel_dig_port;
8475 struct intel_encoder *intel_encoder;
8476 struct drm_encoder *encoder;
8477 struct intel_connector *intel_connector;
8479 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
8480 if (!intel_dig_port)
8483 intel_connector = intel_connector_alloc();
8484 if (!intel_connector)
8485 goto err_connector_alloc;
8487 intel_encoder = &intel_dig_port->base;
8488 encoder = &intel_encoder->base;
8490 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
8491 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
8492 "DP %c", port_name(port)))
8493 goto err_encoder_init;
8495 intel_encoder->hotplug = intel_dp_hotplug;
8496 intel_encoder->compute_config = intel_dp_compute_config;
8497 intel_encoder->get_hw_state = intel_dp_get_hw_state;
8498 intel_encoder->get_config = intel_dp_get_config;
8499 intel_encoder->update_pipe = intel_panel_update_backlight;
8500 intel_encoder->suspend = intel_dp_encoder_suspend;
8501 if (IS_CHERRYVIEW(dev_priv)) {
8502 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
8503 intel_encoder->pre_enable = chv_pre_enable_dp;
8504 intel_encoder->enable = vlv_enable_dp;
8505 intel_encoder->disable = vlv_disable_dp;
8506 intel_encoder->post_disable = chv_post_disable_dp;
8507 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
8508 } else if (IS_VALLEYVIEW(dev_priv)) {
8509 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
8510 intel_encoder->pre_enable = vlv_pre_enable_dp;
8511 intel_encoder->enable = vlv_enable_dp;
8512 intel_encoder->disable = vlv_disable_dp;
8513 intel_encoder->post_disable = vlv_post_disable_dp;
8515 intel_encoder->pre_enable = g4x_pre_enable_dp;
8516 intel_encoder->enable = g4x_enable_dp;
8517 intel_encoder->disable = g4x_disable_dp;
8518 intel_encoder->post_disable = g4x_post_disable_dp;
8521 intel_dig_port->dp.output_reg = output_reg;
8522 intel_dig_port->max_lanes = 4;
8523 intel_dig_port->dp.regs.dp_tp_ctl = DP_TP_CTL(port);
8524 intel_dig_port->dp.regs.dp_tp_status = DP_TP_STATUS(port);
8526 intel_encoder->type = INTEL_OUTPUT_DP;
8527 intel_encoder->power_domain = intel_port_to_power_domain(port);
8528 if (IS_CHERRYVIEW(dev_priv)) {
8530 intel_encoder->pipe_mask = BIT(PIPE_C);
8532 intel_encoder->pipe_mask = BIT(PIPE_A) | BIT(PIPE_B);
8534 intel_encoder->pipe_mask = ~0;
8536 intel_encoder->cloneable = 0;
8537 intel_encoder->port = port;
8539 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
8542 intel_infoframe_init(intel_dig_port);
8544 intel_dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port);
8545 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
8546 goto err_init_connector;
8551 drm_encoder_cleanup(encoder);
8553 kfree(intel_connector);
8554 err_connector_alloc:
8555 kfree(intel_dig_port);
8559 void intel_dp_mst_suspend(struct drm_i915_private *dev_priv)
8561 struct intel_encoder *encoder;
8563 for_each_intel_encoder(&dev_priv->drm, encoder) {
8564 struct intel_dp *intel_dp;
8566 if (encoder->type != INTEL_OUTPUT_DDI)
8569 intel_dp = enc_to_intel_dp(encoder);
8571 if (!intel_dp->can_mst)
8574 if (intel_dp->is_mst)
8575 drm_dp_mst_topology_mgr_suspend(&intel_dp->mst_mgr);
8579 void intel_dp_mst_resume(struct drm_i915_private *dev_priv)
8581 struct intel_encoder *encoder;
8583 for_each_intel_encoder(&dev_priv->drm, encoder) {
8584 struct intel_dp *intel_dp;
8587 if (encoder->type != INTEL_OUTPUT_DDI)
8590 intel_dp = enc_to_intel_dp(encoder);
8592 if (!intel_dp->can_mst)
8595 ret = drm_dp_mst_topology_mgr_resume(&intel_dp->mst_mgr,
8598 intel_dp->is_mst = false;
8599 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,