2 * Copyright © 2012 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 * Eugeni Dodonov <eugeni.dodonov@intel.com>
28 #include <drm/drm_scdc_helper.h>
31 #include "intel_audio.h"
32 #include "intel_backlight.h"
33 #include "intel_combo_phy.h"
34 #include "intel_connector.h"
35 #include "intel_crtc.h"
36 #include "intel_ddi.h"
37 #include "intel_ddi_buf_trans.h"
39 #include "intel_display_types.h"
41 #include "intel_dp_link_training.h"
42 #include "intel_dp_mst.h"
43 #include "intel_dpio_phy.h"
44 #include "intel_drrs.h"
45 #include "intel_dsi.h"
46 #include "intel_fdi.h"
47 #include "intel_fifo_underrun.h"
48 #include "intel_gmbus.h"
49 #include "intel_hdcp.h"
50 #include "intel_hdmi.h"
51 #include "intel_hotplug.h"
52 #include "intel_lspcon.h"
53 #include "intel_pps.h"
54 #include "intel_psr.h"
55 #include "intel_snps_phy.h"
56 #include "intel_sprite.h"
58 #include "intel_vdsc.h"
59 #include "intel_vrr.h"
60 #include "skl_scaler.h"
61 #include "skl_universal_plane.h"
63 static const u8 index_to_dp_signal_levels[] = {
64 [0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0,
65 [1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1,
66 [2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2,
67 [3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3,
68 [4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0,
69 [5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1,
70 [6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2,
71 [7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0,
72 [8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1,
73 [9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0,
76 static int intel_ddi_hdmi_level(struct intel_encoder *encoder,
77 const struct intel_crtc_state *crtc_state)
79 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
80 int n_entries, level, default_entry;
82 n_entries = intel_ddi_hdmi_num_entries(encoder, crtc_state, &default_entry);
85 level = intel_bios_hdmi_level_shift(encoder);
87 level = default_entry;
89 if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
90 level = n_entries - 1;
96 * Starting with Haswell, DDI port buffers must be programmed with correct
97 * values in advance. This function programs the correct values for
98 * DP/eDP/FDI use cases.
100 void hsw_prepare_dp_ddi_buffers(struct intel_encoder *encoder,
101 const struct intel_crtc_state *crtc_state)
103 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
106 enum port port = encoder->port;
107 const struct intel_ddi_buf_trans *ddi_translations;
109 ddi_translations = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
110 if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
113 /* If we're boosting the current, set bit 31 of trans1 */
114 if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv) &&
115 intel_bios_encoder_dp_boost_level(encoder->devdata))
116 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
118 for (i = 0; i < n_entries; i++) {
119 intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, i),
120 ddi_translations->entries[i].hsw.trans1 | iboost_bit);
121 intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, i),
122 ddi_translations->entries[i].hsw.trans2);
127 * Starting with Haswell, DDI port buffers must be programmed with correct
128 * values in advance. This function programs the correct values for
129 * HDMI/DVI use cases.
131 static void hsw_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder,
132 const struct intel_crtc_state *crtc_state,
135 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
138 enum port port = encoder->port;
139 const struct intel_ddi_buf_trans *ddi_translations;
141 ddi_translations = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
142 if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
144 if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
145 level = n_entries - 1;
147 /* If we're boosting the current, set bit 31 of trans1 */
148 if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv) &&
149 intel_bios_encoder_hdmi_boost_level(encoder->devdata))
150 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
152 /* Entry 9 is for HDMI: */
153 intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, 9),
154 ddi_translations->entries[level].hsw.trans1 | iboost_bit);
155 intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, 9),
156 ddi_translations->entries[level].hsw.trans2);
159 void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
162 if (IS_BROXTON(dev_priv)) {
167 if (wait_for_us((intel_de_read(dev_priv, DDI_BUF_CTL(port)) &
168 DDI_BUF_IS_IDLE), 8))
169 drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get idle\n",
173 static void intel_wait_ddi_buf_active(struct drm_i915_private *dev_priv,
178 /* Wait > 518 usecs for DDI_BUF_CTL to be non idle */
179 if (DISPLAY_VER(dev_priv) < 10) {
180 usleep_range(518, 1000);
184 ret = _wait_for(!(intel_de_read(dev_priv, DDI_BUF_CTL(port)) &
185 DDI_BUF_IS_IDLE), IS_DG2(dev_priv) ? 1200 : 500, 10, 10);
188 drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get active\n",
192 static u32 hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll)
194 switch (pll->info->id) {
196 return PORT_CLK_SEL_WRPLL1;
198 return PORT_CLK_SEL_WRPLL2;
200 return PORT_CLK_SEL_SPLL;
201 case DPLL_ID_LCPLL_810:
202 return PORT_CLK_SEL_LCPLL_810;
203 case DPLL_ID_LCPLL_1350:
204 return PORT_CLK_SEL_LCPLL_1350;
205 case DPLL_ID_LCPLL_2700:
206 return PORT_CLK_SEL_LCPLL_2700;
208 MISSING_CASE(pll->info->id);
209 return PORT_CLK_SEL_NONE;
213 static u32 icl_pll_to_ddi_clk_sel(struct intel_encoder *encoder,
214 const struct intel_crtc_state *crtc_state)
216 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
217 int clock = crtc_state->port_clock;
218 const enum intel_dpll_id id = pll->info->id;
223 * DPLL_ID_ICL_DPLL0 and DPLL_ID_ICL_DPLL1 should not be used
224 * here, so do warn if this get passed in
227 return DDI_CLK_SEL_NONE;
228 case DPLL_ID_ICL_TBTPLL:
231 return DDI_CLK_SEL_TBT_162;
233 return DDI_CLK_SEL_TBT_270;
235 return DDI_CLK_SEL_TBT_540;
237 return DDI_CLK_SEL_TBT_810;
240 return DDI_CLK_SEL_NONE;
242 case DPLL_ID_ICL_MGPLL1:
243 case DPLL_ID_ICL_MGPLL2:
244 case DPLL_ID_ICL_MGPLL3:
245 case DPLL_ID_ICL_MGPLL4:
246 case DPLL_ID_TGL_MGPLL5:
247 case DPLL_ID_TGL_MGPLL6:
248 return DDI_CLK_SEL_MG;
252 static u32 ddi_buf_phy_link_rate(int port_clock)
254 switch (port_clock) {
256 return DDI_BUF_PHY_LINK_RATE(0);
258 return DDI_BUF_PHY_LINK_RATE(4);
260 return DDI_BUF_PHY_LINK_RATE(5);
262 return DDI_BUF_PHY_LINK_RATE(1);
264 return DDI_BUF_PHY_LINK_RATE(6);
266 return DDI_BUF_PHY_LINK_RATE(7);
268 return DDI_BUF_PHY_LINK_RATE(2);
270 return DDI_BUF_PHY_LINK_RATE(3);
272 MISSING_CASE(port_clock);
273 return DDI_BUF_PHY_LINK_RATE(0);
277 static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder,
278 const struct intel_crtc_state *crtc_state)
280 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
281 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
282 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
283 enum phy phy = intel_port_to_phy(i915, encoder->port);
285 intel_dp->DP = dig_port->saved_port_bits |
286 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
287 intel_dp->DP |= DDI_PORT_WIDTH(crtc_state->lane_count);
289 if (IS_ALDERLAKE_P(i915) && intel_phy_is_tc(i915, phy)) {
290 intel_dp->DP |= ddi_buf_phy_link_rate(crtc_state->port_clock);
291 if (dig_port->tc_mode != TC_PORT_TBT_ALT)
292 intel_dp->DP |= DDI_BUF_CTL_TC_PHY_OWNERSHIP;
296 static int icl_calc_tbt_pll_link(struct drm_i915_private *dev_priv,
299 u32 val = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
302 case DDI_CLK_SEL_NONE:
304 case DDI_CLK_SEL_TBT_162:
306 case DDI_CLK_SEL_TBT_270:
308 case DDI_CLK_SEL_TBT_540:
310 case DDI_CLK_SEL_TBT_810:
318 static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
322 if (pipe_config->has_pch_encoder)
323 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
324 &pipe_config->fdi_m_n);
325 else if (intel_crtc_has_dp_encoder(pipe_config))
326 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
327 &pipe_config->dp_m_n);
328 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
329 dotclock = pipe_config->port_clock * 24 / pipe_config->pipe_bpp;
331 dotclock = pipe_config->port_clock;
333 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
334 !intel_crtc_has_dp_encoder(pipe_config))
337 if (pipe_config->pixel_multiplier)
338 dotclock /= pipe_config->pixel_multiplier;
340 pipe_config->hw.adjusted_mode.crtc_clock = dotclock;
343 void intel_ddi_set_dp_msa(const struct intel_crtc_state *crtc_state,
344 const struct drm_connector_state *conn_state)
346 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
347 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
348 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
351 if (!intel_crtc_has_dp_encoder(crtc_state))
354 drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder));
356 temp = DP_MSA_MISC_SYNC_CLOCK;
358 switch (crtc_state->pipe_bpp) {
360 temp |= DP_MSA_MISC_6_BPC;
363 temp |= DP_MSA_MISC_8_BPC;
366 temp |= DP_MSA_MISC_10_BPC;
369 temp |= DP_MSA_MISC_12_BPC;
372 MISSING_CASE(crtc_state->pipe_bpp);
376 /* nonsense combination */
377 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
378 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
380 if (crtc_state->limited_color_range)
381 temp |= DP_MSA_MISC_COLOR_CEA_RGB;
384 * As per DP 1.2 spec section 2.3.4.3 while sending
385 * YCBCR 444 signals we should program MSA MISC1/0 fields with
386 * colorspace information.
388 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
389 temp |= DP_MSA_MISC_COLOR_YCBCR_444_BT709;
392 * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication
393 * of Color Encoding Format and Content Color Gamut] while sending
394 * YCBCR 420, HDR BT.2020 signals we should program MSA MISC1 fields
395 * which indicate VSC SDP for the Pixel Encoding/Colorimetry Format.
397 if (intel_dp_needs_vsc_sdp(crtc_state, conn_state))
398 temp |= DP_MSA_MISC_COLOR_VSC_SDP;
400 intel_de_write(dev_priv, TRANS_MSA_MISC(cpu_transcoder), temp);
403 static u32 bdw_trans_port_sync_master_select(enum transcoder master_transcoder)
405 if (master_transcoder == TRANSCODER_EDP)
408 return master_transcoder + 1;
412 intel_ddi_config_transcoder_dp2(struct intel_encoder *encoder,
413 const struct intel_crtc_state *crtc_state)
415 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
416 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
419 if (intel_dp_is_uhbr(crtc_state))
420 val = TRANS_DP2_128B132B_CHANNEL_CODING;
422 intel_de_write(i915, TRANS_DP2_CTL(cpu_transcoder), val);
426 * Returns the TRANS_DDI_FUNC_CTL value based on CRTC state.
428 * Only intended to be used by intel_ddi_enable_transcoder_func() and
429 * intel_ddi_config_transcoder_func().
432 intel_ddi_transcoder_func_reg_val_get(struct intel_encoder *encoder,
433 const struct intel_crtc_state *crtc_state)
435 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
436 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
437 enum pipe pipe = crtc->pipe;
438 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
439 enum port port = encoder->port;
442 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
443 temp = TRANS_DDI_FUNC_ENABLE;
444 if (DISPLAY_VER(dev_priv) >= 12)
445 temp |= TGL_TRANS_DDI_SELECT_PORT(port);
447 temp |= TRANS_DDI_SELECT_PORT(port);
449 switch (crtc_state->pipe_bpp) {
451 temp |= TRANS_DDI_BPC_6;
454 temp |= TRANS_DDI_BPC_8;
457 temp |= TRANS_DDI_BPC_10;
460 temp |= TRANS_DDI_BPC_12;
466 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
467 temp |= TRANS_DDI_PVSYNC;
468 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
469 temp |= TRANS_DDI_PHSYNC;
471 if (cpu_transcoder == TRANSCODER_EDP) {
474 /* On Haswell, can only use the always-on power well for
475 * eDP when not using the panel fitter, and when not
476 * using motion blur mitigation (which we don't
478 if (crtc_state->pch_pfit.force_thru)
479 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
481 temp |= TRANS_DDI_EDP_INPUT_A_ON;
484 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
487 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
495 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
496 if (crtc_state->has_hdmi_sink)
497 temp |= TRANS_DDI_MODE_SELECT_HDMI;
499 temp |= TRANS_DDI_MODE_SELECT_DVI;
501 if (crtc_state->hdmi_scrambling)
502 temp |= TRANS_DDI_HDMI_SCRAMBLING;
503 if (crtc_state->hdmi_high_tmds_clock_ratio)
504 temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
505 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
506 temp |= TRANS_DDI_MODE_SELECT_FDI_OR_128B132B;
507 temp |= (crtc_state->fdi_lanes - 1) << 1;
508 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
509 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
510 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
512 if (DISPLAY_VER(dev_priv) >= 12) {
513 enum transcoder master;
515 master = crtc_state->mst_master_transcoder;
516 drm_WARN_ON(&dev_priv->drm,
517 master == INVALID_TRANSCODER);
518 temp |= TRANS_DDI_MST_TRANSPORT_SELECT(master);
521 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
522 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
525 if (IS_DISPLAY_VER(dev_priv, 8, 10) &&
526 crtc_state->master_transcoder != INVALID_TRANSCODER) {
528 bdw_trans_port_sync_master_select(crtc_state->master_transcoder);
530 temp |= TRANS_DDI_PORT_SYNC_ENABLE |
531 TRANS_DDI_PORT_SYNC_MASTER_SELECT(master_select);
537 void intel_ddi_enable_transcoder_func(struct intel_encoder *encoder,
538 const struct intel_crtc_state *crtc_state)
540 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
541 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
542 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
544 if (DISPLAY_VER(dev_priv) >= 11) {
545 enum transcoder master_transcoder = crtc_state->master_transcoder;
548 if (master_transcoder != INVALID_TRANSCODER) {
550 bdw_trans_port_sync_master_select(master_transcoder);
552 ctl2 |= PORT_SYNC_MODE_ENABLE |
553 PORT_SYNC_MODE_MASTER_SELECT(master_select);
556 intel_de_write(dev_priv,
557 TRANS_DDI_FUNC_CTL2(cpu_transcoder), ctl2);
560 intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder),
561 intel_ddi_transcoder_func_reg_val_get(encoder,
566 * Same as intel_ddi_enable_transcoder_func(), but it does not set the enable
570 intel_ddi_config_transcoder_func(struct intel_encoder *encoder,
571 const struct intel_crtc_state *crtc_state)
573 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
574 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
575 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
578 ctl = intel_ddi_transcoder_func_reg_val_get(encoder, crtc_state);
579 ctl &= ~TRANS_DDI_FUNC_ENABLE;
580 intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl);
583 void intel_ddi_disable_transcoder_func(const struct intel_crtc_state *crtc_state)
585 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
586 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
587 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
590 if (DISPLAY_VER(dev_priv) >= 11)
591 intel_de_write(dev_priv,
592 TRANS_DDI_FUNC_CTL2(cpu_transcoder), 0);
594 ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
596 drm_WARN_ON(crtc->base.dev, ctl & TRANS_DDI_HDCP_SIGNALLING);
598 ctl &= ~TRANS_DDI_FUNC_ENABLE;
600 if (IS_DISPLAY_VER(dev_priv, 8, 10))
601 ctl &= ~(TRANS_DDI_PORT_SYNC_ENABLE |
602 TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK);
604 if (DISPLAY_VER(dev_priv) >= 12) {
605 if (!intel_dp_mst_is_master_trans(crtc_state)) {
606 ctl &= ~(TGL_TRANS_DDI_PORT_MASK |
607 TRANS_DDI_MODE_SELECT_MASK);
610 ctl &= ~(TRANS_DDI_PORT_MASK | TRANS_DDI_MODE_SELECT_MASK);
613 intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl);
615 if (dev_priv->quirks & QUIRK_INCREASE_DDI_DISABLED_TIME &&
616 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
617 drm_dbg_kms(&dev_priv->drm,
618 "Quirk Increase DDI disabled time\n");
619 /* Quirk time at 100ms for reliable operation */
624 int intel_ddi_toggle_hdcp_bits(struct intel_encoder *intel_encoder,
625 enum transcoder cpu_transcoder,
626 bool enable, u32 hdcp_mask)
628 struct drm_device *dev = intel_encoder->base.dev;
629 struct drm_i915_private *dev_priv = to_i915(dev);
630 intel_wakeref_t wakeref;
634 wakeref = intel_display_power_get_if_enabled(dev_priv,
635 intel_encoder->power_domain);
636 if (drm_WARN_ON(dev, !wakeref))
639 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
644 intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), tmp);
645 intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref);
649 bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
651 struct drm_device *dev = intel_connector->base.dev;
652 struct drm_i915_private *dev_priv = to_i915(dev);
653 struct intel_encoder *encoder = intel_attached_encoder(intel_connector);
654 int type = intel_connector->base.connector_type;
655 enum port port = encoder->port;
656 enum transcoder cpu_transcoder;
657 intel_wakeref_t wakeref;
662 wakeref = intel_display_power_get_if_enabled(dev_priv,
663 encoder->power_domain);
667 if (!encoder->get_hw_state(encoder, &pipe)) {
672 if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A)
673 cpu_transcoder = TRANSCODER_EDP;
675 cpu_transcoder = (enum transcoder) pipe;
677 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
679 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
680 case TRANS_DDI_MODE_SELECT_HDMI:
681 case TRANS_DDI_MODE_SELECT_DVI:
682 ret = type == DRM_MODE_CONNECTOR_HDMIA;
685 case TRANS_DDI_MODE_SELECT_DP_SST:
686 ret = type == DRM_MODE_CONNECTOR_eDP ||
687 type == DRM_MODE_CONNECTOR_DisplayPort;
690 case TRANS_DDI_MODE_SELECT_DP_MST:
691 /* if the transcoder is in MST state then
692 * connector isn't connected */
696 case TRANS_DDI_MODE_SELECT_FDI_OR_128B132B:
697 ret = type == DRM_MODE_CONNECTOR_VGA;
706 intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
711 static void intel_ddi_get_encoder_pipes(struct intel_encoder *encoder,
712 u8 *pipe_mask, bool *is_dp_mst)
714 struct drm_device *dev = encoder->base.dev;
715 struct drm_i915_private *dev_priv = to_i915(dev);
716 enum port port = encoder->port;
717 intel_wakeref_t wakeref;
725 wakeref = intel_display_power_get_if_enabled(dev_priv,
726 encoder->power_domain);
730 tmp = intel_de_read(dev_priv, DDI_BUF_CTL(port));
731 if (!(tmp & DDI_BUF_CTL_ENABLE))
734 if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) {
735 tmp = intel_de_read(dev_priv,
736 TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
738 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
740 MISSING_CASE(tmp & TRANS_DDI_EDP_INPUT_MASK);
742 case TRANS_DDI_EDP_INPUT_A_ON:
743 case TRANS_DDI_EDP_INPUT_A_ONOFF:
744 *pipe_mask = BIT(PIPE_A);
746 case TRANS_DDI_EDP_INPUT_B_ONOFF:
747 *pipe_mask = BIT(PIPE_B);
749 case TRANS_DDI_EDP_INPUT_C_ONOFF:
750 *pipe_mask = BIT(PIPE_C);
758 for_each_pipe(dev_priv, p) {
759 enum transcoder cpu_transcoder = (enum transcoder)p;
760 unsigned int port_mask, ddi_select;
761 intel_wakeref_t trans_wakeref;
763 trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
764 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
768 if (DISPLAY_VER(dev_priv) >= 12) {
769 port_mask = TGL_TRANS_DDI_PORT_MASK;
770 ddi_select = TGL_TRANS_DDI_SELECT_PORT(port);
772 port_mask = TRANS_DDI_PORT_MASK;
773 ddi_select = TRANS_DDI_SELECT_PORT(port);
776 tmp = intel_de_read(dev_priv,
777 TRANS_DDI_FUNC_CTL(cpu_transcoder));
778 intel_display_power_put(dev_priv, POWER_DOMAIN_TRANSCODER(cpu_transcoder),
781 if ((tmp & port_mask) != ddi_select)
784 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
785 TRANS_DDI_MODE_SELECT_DP_MST)
786 mst_pipe_mask |= BIT(p);
788 *pipe_mask |= BIT(p);
792 drm_dbg_kms(&dev_priv->drm,
793 "No pipe for [ENCODER:%d:%s] found\n",
794 encoder->base.base.id, encoder->base.name);
796 if (!mst_pipe_mask && hweight8(*pipe_mask) > 1) {
797 drm_dbg_kms(&dev_priv->drm,
798 "Multiple pipes for [ENCODER:%d:%s] (pipe_mask %02x)\n",
799 encoder->base.base.id, encoder->base.name,
801 *pipe_mask = BIT(ffs(*pipe_mask) - 1);
804 if (mst_pipe_mask && mst_pipe_mask != *pipe_mask)
805 drm_dbg_kms(&dev_priv->drm,
806 "Conflicting MST and non-MST state for [ENCODER:%d:%s] (pipe_mask %02x mst_pipe_mask %02x)\n",
807 encoder->base.base.id, encoder->base.name,
808 *pipe_mask, mst_pipe_mask);
810 *is_dp_mst = mst_pipe_mask;
813 if (*pipe_mask && (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))) {
814 tmp = intel_de_read(dev_priv, BXT_PHY_CTL(port));
815 if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK |
816 BXT_PHY_LANE_POWERDOWN_ACK |
817 BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
818 drm_err(&dev_priv->drm,
819 "[ENCODER:%d:%s] enabled but PHY powered down? (PHY_CTL %08x)\n",
820 encoder->base.base.id, encoder->base.name, tmp);
823 intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
826 bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
832 intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst);
834 if (is_mst || !pipe_mask)
837 *pipe = ffs(pipe_mask) - 1;
842 static enum intel_display_power_domain
843 intel_ddi_main_link_aux_domain(struct intel_digital_port *dig_port)
845 /* ICL+ HW requires corresponding AUX IOs to be powered up for PSR with
846 * DC states enabled at the same time, while for driver initiated AUX
847 * transfers we need the same AUX IOs to be powered but with DC states
848 * disabled. Accordingly use the AUX power domain here which leaves DC
850 * However, for non-A AUX ports the corresponding non-EDP transcoders
851 * would have already enabled power well 2 and DC_OFF. This means we can
852 * acquire a wider POWER_DOMAIN_AUX_{B,C,D,F} reference instead of a
853 * specific AUX_IO reference without powering up any extra wells.
854 * Note that PSR is enabled only on Port A even though this function
855 * returns the correct domain for other ports too.
857 return dig_port->aux_ch == AUX_CH_A ? POWER_DOMAIN_AUX_IO_A :
858 intel_aux_power_domain(dig_port);
861 static void intel_ddi_get_power_domains(struct intel_encoder *encoder,
862 struct intel_crtc_state *crtc_state)
864 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
865 struct intel_digital_port *dig_port;
866 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
869 * TODO: Add support for MST encoders. Atm, the following should never
870 * happen since fake-MST encoders don't set their get_power_domains()
873 if (drm_WARN_ON(&dev_priv->drm,
874 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)))
877 dig_port = enc_to_dig_port(encoder);
879 if (!intel_phy_is_tc(dev_priv, phy) ||
880 dig_port->tc_mode != TC_PORT_TBT_ALT) {
881 drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
882 dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
883 dig_port->ddi_io_power_domain);
887 * AUX power is only needed for (e)DP mode, and for HDMI mode on TC
890 if (intel_crtc_has_dp_encoder(crtc_state) ||
891 intel_phy_is_tc(dev_priv, phy)) {
892 drm_WARN_ON(&dev_priv->drm, dig_port->aux_wakeref);
893 dig_port->aux_wakeref =
894 intel_display_power_get(dev_priv,
895 intel_ddi_main_link_aux_domain(dig_port));
899 void intel_ddi_enable_pipe_clock(struct intel_encoder *encoder,
900 const struct intel_crtc_state *crtc_state)
902 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
903 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
904 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
905 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
908 if (cpu_transcoder != TRANSCODER_EDP) {
909 if (DISPLAY_VER(dev_priv) >= 13)
910 val = TGL_TRANS_CLK_SEL_PORT(phy);
911 else if (DISPLAY_VER(dev_priv) >= 12)
912 val = TGL_TRANS_CLK_SEL_PORT(encoder->port);
914 val = TRANS_CLK_SEL_PORT(encoder->port);
916 intel_de_write(dev_priv, TRANS_CLK_SEL(cpu_transcoder), val);
920 void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
922 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
923 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
925 if (cpu_transcoder != TRANSCODER_EDP) {
926 if (DISPLAY_VER(dev_priv) >= 12)
927 intel_de_write(dev_priv,
928 TRANS_CLK_SEL(cpu_transcoder),
929 TGL_TRANS_CLK_SEL_DISABLED);
931 intel_de_write(dev_priv,
932 TRANS_CLK_SEL(cpu_transcoder),
933 TRANS_CLK_SEL_DISABLED);
937 static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
938 enum port port, u8 iboost)
942 tmp = intel_de_read(dev_priv, DISPIO_CR_TX_BMU_CR0);
943 tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
945 tmp |= iboost << BALANCE_LEG_SHIFT(port);
947 tmp |= BALANCE_LEG_DISABLE(port);
948 intel_de_write(dev_priv, DISPIO_CR_TX_BMU_CR0, tmp);
951 static void skl_ddi_set_iboost(struct intel_encoder *encoder,
952 const struct intel_crtc_state *crtc_state,
955 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
956 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
959 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
960 iboost = intel_bios_encoder_hdmi_boost_level(encoder->devdata);
962 iboost = intel_bios_encoder_dp_boost_level(encoder->devdata);
965 const struct intel_ddi_buf_trans *ddi_translations;
968 ddi_translations = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
969 if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
971 if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
972 level = n_entries - 1;
974 iboost = ddi_translations->entries[level].hsw.i_boost;
977 /* Make sure that the requested I_boost is valid */
978 if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
979 drm_err(&dev_priv->drm, "Invalid I_boost value %u\n", iboost);
983 _skl_ddi_set_iboost(dev_priv, encoder->port, iboost);
985 if (encoder->port == PORT_A && dig_port->max_lanes == 4)
986 _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
989 static void bxt_ddi_vswing_sequence(struct intel_encoder *encoder,
990 const struct intel_crtc_state *crtc_state,
993 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
994 const struct intel_ddi_buf_trans *ddi_translations;
995 enum port port = encoder->port;
998 ddi_translations = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
999 if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
1001 if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1002 level = n_entries - 1;
1004 bxt_ddi_phy_set_signal_level(dev_priv, port,
1005 ddi_translations->entries[level].bxt.margin,
1006 ddi_translations->entries[level].bxt.scale,
1007 ddi_translations->entries[level].bxt.enable,
1008 ddi_translations->entries[level].bxt.deemphasis);
1011 static u8 intel_ddi_dp_voltage_max(struct intel_dp *intel_dp,
1012 const struct intel_crtc_state *crtc_state)
1014 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1015 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1018 encoder->get_buf_trans(encoder, crtc_state, &n_entries);
1020 if (drm_WARN_ON(&dev_priv->drm, n_entries < 1))
1022 if (drm_WARN_ON(&dev_priv->drm,
1023 n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
1024 n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
1026 return index_to_dp_signal_levels[n_entries - 1] &
1027 DP_TRAIN_VOLTAGE_SWING_MASK;
1031 * We assume that the full set of pre-emphasis values can be
1032 * used on all DDI platforms. Should that change we need to
1033 * rethink this code.
1035 static u8 intel_ddi_dp_preemph_max(struct intel_dp *intel_dp)
1037 return DP_TRAIN_PRE_EMPH_LEVEL_3;
1040 static void icl_ddi_combo_vswing_program(struct intel_encoder *encoder,
1041 const struct intel_crtc_state *crtc_state,
1044 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1045 const struct intel_ddi_buf_trans *ddi_translations;
1046 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1050 ddi_translations = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
1051 if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
1053 if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1054 level = n_entries - 1;
1056 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) {
1057 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1059 val = EDP4K2K_MODE_OVRD_EN | EDP4K2K_MODE_OVRD_OPTIMIZED;
1060 intel_dp->hobl_active = is_hobl_buf_trans(ddi_translations);
1061 intel_de_rmw(dev_priv, ICL_PORT_CL_DW10(phy), val,
1062 intel_dp->hobl_active ? val : 0);
1065 /* Set PORT_TX_DW5 */
1066 val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
1067 val &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK |
1068 TAP2_DISABLE | TAP3_DISABLE);
1069 val |= SCALING_MODE_SEL(0x2);
1070 val |= RTERM_SELECT(0x6);
1071 val |= TAP3_DISABLE;
1072 intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
1074 /* Program PORT_TX_DW2 */
1075 val = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN0(phy));
1076 val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
1078 val |= SWING_SEL_UPPER(ddi_translations->entries[level].icl.dw2_swing_sel);
1079 val |= SWING_SEL_LOWER(ddi_translations->entries[level].icl.dw2_swing_sel);
1080 /* Program Rcomp scalar for every table entry */
1081 val |= RCOMP_SCALAR(0x98);
1082 intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), val);
1084 /* Program PORT_TX_DW4 */
1085 /* We cannot write to GRP. It would overwrite individual loadgen. */
1086 for (ln = 0; ln <= 3; ln++) {
1087 val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy));
1088 val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
1090 val |= POST_CURSOR_1(ddi_translations->entries[level].icl.dw4_post_cursor_1);
1091 val |= POST_CURSOR_2(ddi_translations->entries[level].icl.dw4_post_cursor_2);
1092 val |= CURSOR_COEFF(ddi_translations->entries[level].icl.dw4_cursor_coeff);
1093 intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val);
1096 /* Program PORT_TX_DW7 */
1097 val = intel_de_read(dev_priv, ICL_PORT_TX_DW7_LN0(phy));
1098 val &= ~N_SCALAR_MASK;
1099 val |= N_SCALAR(ddi_translations->entries[level].icl.dw7_n_scalar);
1100 intel_de_write(dev_priv, ICL_PORT_TX_DW7_GRP(phy), val);
1103 static void icl_combo_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
1104 const struct intel_crtc_state *crtc_state,
1107 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1108 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1109 int width, rate, ln;
1112 width = crtc_state->lane_count;
1113 rate = crtc_state->port_clock;
1116 * 1. If port type is eDP or DP,
1117 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
1120 val = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN0(phy));
1121 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1122 val &= ~COMMON_KEEPER_EN;
1124 val |= COMMON_KEEPER_EN;
1125 intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), val);
1127 /* 2. Program loadgen select */
1129 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
1130 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
1131 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
1132 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
1134 for (ln = 0; ln <= 3; ln++) {
1135 val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy));
1136 val &= ~LOADGEN_SELECT;
1138 if ((rate <= 600000 && width == 4 && ln >= 1) ||
1139 (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
1140 val |= LOADGEN_SELECT;
1142 intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val);
1145 /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
1146 val = intel_de_read(dev_priv, ICL_PORT_CL_DW5(phy));
1147 val |= SUS_CLOCK_CONFIG;
1148 intel_de_write(dev_priv, ICL_PORT_CL_DW5(phy), val);
1150 /* 4. Clear training enable to change swing values */
1151 val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
1152 val &= ~TX_TRAINING_EN;
1153 intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
1155 /* 5. Program swing and de-emphasis */
1156 icl_ddi_combo_vswing_program(encoder, crtc_state, level);
1158 /* 6. Set training enable to trigger update */
1159 val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
1160 val |= TX_TRAINING_EN;
1161 intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
1164 static void icl_mg_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
1165 const struct intel_crtc_state *crtc_state,
1168 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1169 enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port);
1170 const struct intel_ddi_buf_trans *ddi_translations;
1174 if (enc_to_dig_port(encoder)->tc_mode == TC_PORT_TBT_ALT)
1177 ddi_translations = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
1178 if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
1180 if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1181 level = n_entries - 1;
1183 /* Set MG_TX_LINK_PARAMS cri_use_fs32 to 0. */
1184 for (ln = 0; ln < 2; ln++) {
1185 val = intel_de_read(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port));
1186 val &= ~CRI_USE_FS32;
1187 intel_de_write(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port), val);
1189 val = intel_de_read(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port));
1190 val &= ~CRI_USE_FS32;
1191 intel_de_write(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port), val);
1194 /* Program MG_TX_SWINGCTRL with values from vswing table */
1195 for (ln = 0; ln < 2; ln++) {
1196 val = intel_de_read(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port));
1197 val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK;
1198 val |= CRI_TXDEEMPH_OVERRIDE_17_12(
1199 ddi_translations->entries[level].mg.cri_txdeemph_override_17_12);
1200 intel_de_write(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port), val);
1202 val = intel_de_read(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port));
1203 val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK;
1204 val |= CRI_TXDEEMPH_OVERRIDE_17_12(
1205 ddi_translations->entries[level].mg.cri_txdeemph_override_17_12);
1206 intel_de_write(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port), val);
1209 /* Program MG_TX_DRVCTRL with values from vswing table */
1210 for (ln = 0; ln < 2; ln++) {
1211 val = intel_de_read(dev_priv, MG_TX1_DRVCTRL(ln, tc_port));
1212 val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK |
1213 CRI_TXDEEMPH_OVERRIDE_5_0_MASK);
1214 val |= CRI_TXDEEMPH_OVERRIDE_5_0(
1215 ddi_translations->entries[level].mg.cri_txdeemph_override_5_0) |
1216 CRI_TXDEEMPH_OVERRIDE_11_6(
1217 ddi_translations->entries[level].mg.cri_txdeemph_override_11_6) |
1218 CRI_TXDEEMPH_OVERRIDE_EN;
1219 intel_de_write(dev_priv, MG_TX1_DRVCTRL(ln, tc_port), val);
1221 val = intel_de_read(dev_priv, MG_TX2_DRVCTRL(ln, tc_port));
1222 val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK |
1223 CRI_TXDEEMPH_OVERRIDE_5_0_MASK);
1224 val |= CRI_TXDEEMPH_OVERRIDE_5_0(
1225 ddi_translations->entries[level].mg.cri_txdeemph_override_5_0) |
1226 CRI_TXDEEMPH_OVERRIDE_11_6(
1227 ddi_translations->entries[level].mg.cri_txdeemph_override_11_6) |
1228 CRI_TXDEEMPH_OVERRIDE_EN;
1229 intel_de_write(dev_priv, MG_TX2_DRVCTRL(ln, tc_port), val);
1231 /* FIXME: Program CRI_LOADGEN_SEL after the spec is updated */
1235 * Program MG_CLKHUB<LN, port being used> with value from frequency table
1236 * In case of Legacy mode on MG PHY, both TX1 and TX2 enabled so use the
1237 * values from table for which TX1 and TX2 enabled.
1239 for (ln = 0; ln < 2; ln++) {
1240 val = intel_de_read(dev_priv, MG_CLKHUB(ln, tc_port));
1241 if (crtc_state->port_clock < 300000)
1242 val |= CFG_LOW_RATE_LKREN_EN;
1244 val &= ~CFG_LOW_RATE_LKREN_EN;
1245 intel_de_write(dev_priv, MG_CLKHUB(ln, tc_port), val);
1248 /* Program the MG_TX_DCC<LN, port being used> based on the link frequency */
1249 for (ln = 0; ln < 2; ln++) {
1250 val = intel_de_read(dev_priv, MG_TX1_DCC(ln, tc_port));
1251 val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK;
1252 if (crtc_state->port_clock <= 500000) {
1253 val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN;
1255 val |= CFG_AMI_CK_DIV_OVERRIDE_EN |
1256 CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
1258 intel_de_write(dev_priv, MG_TX1_DCC(ln, tc_port), val);
1260 val = intel_de_read(dev_priv, MG_TX2_DCC(ln, tc_port));
1261 val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK;
1262 if (crtc_state->port_clock <= 500000) {
1263 val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN;
1265 val |= CFG_AMI_CK_DIV_OVERRIDE_EN |
1266 CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
1268 intel_de_write(dev_priv, MG_TX2_DCC(ln, tc_port), val);
1271 /* Program MG_TX_PISO_READLOAD with values from vswing table */
1272 for (ln = 0; ln < 2; ln++) {
1273 val = intel_de_read(dev_priv,
1274 MG_TX1_PISO_READLOAD(ln, tc_port));
1275 val |= CRI_CALCINIT;
1276 intel_de_write(dev_priv, MG_TX1_PISO_READLOAD(ln, tc_port),
1279 val = intel_de_read(dev_priv,
1280 MG_TX2_PISO_READLOAD(ln, tc_port));
1281 val |= CRI_CALCINIT;
1282 intel_de_write(dev_priv, MG_TX2_PISO_READLOAD(ln, tc_port),
1287 static void icl_ddi_vswing_sequence(struct intel_encoder *encoder,
1288 const struct intel_crtc_state *crtc_state,
1291 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1292 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1294 if (intel_phy_is_combo(dev_priv, phy))
1295 icl_combo_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1297 icl_mg_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1301 tgl_dkl_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
1302 const struct intel_crtc_state *crtc_state,
1305 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1306 enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port);
1307 const struct intel_ddi_buf_trans *ddi_translations;
1308 u32 val, dpcnt_mask, dpcnt_val;
1311 if (enc_to_dig_port(encoder)->tc_mode == TC_PORT_TBT_ALT)
1314 ddi_translations = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
1315 if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
1317 if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1318 level = n_entries - 1;
1320 dpcnt_mask = (DKL_TX_PRESHOOT_COEFF_MASK |
1321 DKL_TX_DE_EMPAHSIS_COEFF_MASK |
1322 DKL_TX_VSWING_CONTROL_MASK);
1323 dpcnt_val = DKL_TX_VSWING_CONTROL(ddi_translations->entries[level].dkl.dkl_vswing_control);
1324 dpcnt_val |= DKL_TX_DE_EMPHASIS_COEFF(ddi_translations->entries[level].dkl.dkl_de_emphasis_control);
1325 dpcnt_val |= DKL_TX_PRESHOOT_COEFF(ddi_translations->entries[level].dkl.dkl_preshoot_control);
1327 for (ln = 0; ln < 2; ln++) {
1328 intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
1329 HIP_INDEX_VAL(tc_port, ln));
1331 intel_de_write(dev_priv, DKL_TX_PMD_LANE_SUS(tc_port), 0);
1333 /* All the registers are RMW */
1334 val = intel_de_read(dev_priv, DKL_TX_DPCNTL0(tc_port));
1337 intel_de_write(dev_priv, DKL_TX_DPCNTL0(tc_port), val);
1339 val = intel_de_read(dev_priv, DKL_TX_DPCNTL1(tc_port));
1342 intel_de_write(dev_priv, DKL_TX_DPCNTL1(tc_port), val);
1344 val = intel_de_read(dev_priv, DKL_TX_DPCNTL2(tc_port));
1345 val &= ~DKL_TX_DP20BITMODE;
1346 intel_de_write(dev_priv, DKL_TX_DPCNTL2(tc_port), val);
1348 if ((intel_crtc_has_dp_encoder(crtc_state) &&
1349 crtc_state->port_clock == 162000) ||
1350 (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) &&
1351 crtc_state->port_clock == 594000))
1352 val |= DKL_TX_LOADGEN_SHARING_PMD_DISABLE;
1354 val &= ~DKL_TX_LOADGEN_SHARING_PMD_DISABLE;
1358 static void tgl_ddi_vswing_sequence(struct intel_encoder *encoder,
1359 const struct intel_crtc_state *crtc_state,
1362 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1363 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1365 if (intel_phy_is_combo(dev_priv, phy))
1366 icl_combo_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1368 tgl_dkl_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1371 static int translate_signal_level(struct intel_dp *intel_dp,
1374 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
1377 for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
1378 if (index_to_dp_signal_levels[i] == signal_levels)
1382 drm_WARN(&i915->drm, 1,
1383 "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
1389 static int intel_ddi_dp_level(struct intel_dp *intel_dp,
1390 const struct intel_crtc_state *crtc_state)
1392 u8 train_set = intel_dp->train_set[0];
1393 u8 signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1394 DP_TRAIN_PRE_EMPHASIS_MASK);
1396 return translate_signal_level(intel_dp, signal_levels);
1400 dg2_set_signal_levels(struct intel_dp *intel_dp,
1401 const struct intel_crtc_state *crtc_state)
1403 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1404 int level = intel_ddi_dp_level(intel_dp, crtc_state);
1406 intel_snps_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1410 tgl_set_signal_levels(struct intel_dp *intel_dp,
1411 const struct intel_crtc_state *crtc_state)
1413 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1414 int level = intel_ddi_dp_level(intel_dp, crtc_state);
1416 tgl_ddi_vswing_sequence(encoder, crtc_state, level);
1420 icl_set_signal_levels(struct intel_dp *intel_dp,
1421 const struct intel_crtc_state *crtc_state)
1423 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1424 int level = intel_ddi_dp_level(intel_dp, crtc_state);
1426 icl_ddi_vswing_sequence(encoder, crtc_state, level);
1430 bxt_set_signal_levels(struct intel_dp *intel_dp,
1431 const struct intel_crtc_state *crtc_state)
1433 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1434 int level = intel_ddi_dp_level(intel_dp, crtc_state);
1436 bxt_ddi_vswing_sequence(encoder, crtc_state, level);
1440 hsw_set_signal_levels(struct intel_dp *intel_dp,
1441 const struct intel_crtc_state *crtc_state)
1443 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1444 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1445 int level = intel_ddi_dp_level(intel_dp, crtc_state);
1446 enum port port = encoder->port;
1449 signal_levels = DDI_BUF_TRANS_SELECT(level);
1451 drm_dbg_kms(&dev_priv->drm, "Using signal levels %08x\n",
1454 intel_dp->DP &= ~DDI_BUF_EMP_MASK;
1455 intel_dp->DP |= signal_levels;
1457 if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv))
1458 skl_ddi_set_iboost(encoder, crtc_state, level);
1460 intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP);
1461 intel_de_posting_read(dev_priv, DDI_BUF_CTL(port));
1464 static void _icl_ddi_enable_clock(struct drm_i915_private *i915, i915_reg_t reg,
1465 u32 clk_sel_mask, u32 clk_sel, u32 clk_off)
1467 mutex_lock(&i915->dpll.lock);
1469 intel_de_rmw(i915, reg, clk_sel_mask, clk_sel);
1472 * "This step and the step before must be
1473 * done with separate register writes."
1475 intel_de_rmw(i915, reg, clk_off, 0);
1477 mutex_unlock(&i915->dpll.lock);
1480 static void _icl_ddi_disable_clock(struct drm_i915_private *i915, i915_reg_t reg,
1483 mutex_lock(&i915->dpll.lock);
1485 intel_de_rmw(i915, reg, 0, clk_off);
1487 mutex_unlock(&i915->dpll.lock);
1490 static bool _icl_ddi_is_clock_enabled(struct drm_i915_private *i915, i915_reg_t reg,
1493 return !(intel_de_read(i915, reg) & clk_off);
1496 static struct intel_shared_dpll *
1497 _icl_ddi_get_pll(struct drm_i915_private *i915, i915_reg_t reg,
1498 u32 clk_sel_mask, u32 clk_sel_shift)
1500 enum intel_dpll_id id;
1502 id = (intel_de_read(i915, reg) & clk_sel_mask) >> clk_sel_shift;
1504 return intel_get_shared_dpll_by_id(i915, id);
1507 static void adls_ddi_enable_clock(struct intel_encoder *encoder,
1508 const struct intel_crtc_state *crtc_state)
1510 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1511 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1512 enum phy phy = intel_port_to_phy(i915, encoder->port);
1514 if (drm_WARN_ON(&i915->drm, !pll))
1517 _icl_ddi_enable_clock(i915, ADLS_DPCLKA_CFGCR(phy),
1518 ADLS_DPCLKA_CFGCR_DDI_CLK_SEL_MASK(phy),
1519 pll->info->id << ADLS_DPCLKA_CFGCR_DDI_SHIFT(phy),
1520 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1523 static void adls_ddi_disable_clock(struct intel_encoder *encoder)
1525 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1526 enum phy phy = intel_port_to_phy(i915, encoder->port);
1528 _icl_ddi_disable_clock(i915, ADLS_DPCLKA_CFGCR(phy),
1529 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1532 static bool adls_ddi_is_clock_enabled(struct intel_encoder *encoder)
1534 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1535 enum phy phy = intel_port_to_phy(i915, encoder->port);
1537 return _icl_ddi_is_clock_enabled(i915, ADLS_DPCLKA_CFGCR(phy),
1538 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1541 static struct intel_shared_dpll *adls_ddi_get_pll(struct intel_encoder *encoder)
1543 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1544 enum phy phy = intel_port_to_phy(i915, encoder->port);
1546 return _icl_ddi_get_pll(i915, ADLS_DPCLKA_CFGCR(phy),
1547 ADLS_DPCLKA_CFGCR_DDI_CLK_SEL_MASK(phy),
1548 ADLS_DPCLKA_CFGCR_DDI_SHIFT(phy));
1551 static void rkl_ddi_enable_clock(struct intel_encoder *encoder,
1552 const struct intel_crtc_state *crtc_state)
1554 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1555 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1556 enum phy phy = intel_port_to_phy(i915, encoder->port);
1558 if (drm_WARN_ON(&i915->drm, !pll))
1561 _icl_ddi_enable_clock(i915, ICL_DPCLKA_CFGCR0,
1562 RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1563 RKL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy),
1564 RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1567 static void rkl_ddi_disable_clock(struct intel_encoder *encoder)
1569 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1570 enum phy phy = intel_port_to_phy(i915, encoder->port);
1572 _icl_ddi_disable_clock(i915, ICL_DPCLKA_CFGCR0,
1573 RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1576 static bool rkl_ddi_is_clock_enabled(struct intel_encoder *encoder)
1578 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1579 enum phy phy = intel_port_to_phy(i915, encoder->port);
1581 return _icl_ddi_is_clock_enabled(i915, ICL_DPCLKA_CFGCR0,
1582 RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1585 static struct intel_shared_dpll *rkl_ddi_get_pll(struct intel_encoder *encoder)
1587 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1588 enum phy phy = intel_port_to_phy(i915, encoder->port);
1590 return _icl_ddi_get_pll(i915, ICL_DPCLKA_CFGCR0,
1591 RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1592 RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy));
1595 static void dg1_ddi_enable_clock(struct intel_encoder *encoder,
1596 const struct intel_crtc_state *crtc_state)
1598 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1599 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1600 enum phy phy = intel_port_to_phy(i915, encoder->port);
1602 if (drm_WARN_ON(&i915->drm, !pll))
1606 * If we fail this, something went very wrong: first 2 PLLs should be
1607 * used by first 2 phys and last 2 PLLs by last phys
1609 if (drm_WARN_ON(&i915->drm,
1610 (pll->info->id < DPLL_ID_DG1_DPLL2 && phy >= PHY_C) ||
1611 (pll->info->id >= DPLL_ID_DG1_DPLL2 && phy < PHY_C)))
1614 _icl_ddi_enable_clock(i915, DG1_DPCLKA_CFGCR0(phy),
1615 DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1616 DG1_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy),
1617 DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1620 static void dg1_ddi_disable_clock(struct intel_encoder *encoder)
1622 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1623 enum phy phy = intel_port_to_phy(i915, encoder->port);
1625 _icl_ddi_disable_clock(i915, DG1_DPCLKA_CFGCR0(phy),
1626 DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1629 static bool dg1_ddi_is_clock_enabled(struct intel_encoder *encoder)
1631 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1632 enum phy phy = intel_port_to_phy(i915, encoder->port);
1634 return _icl_ddi_is_clock_enabled(i915, DG1_DPCLKA_CFGCR0(phy),
1635 DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1638 static struct intel_shared_dpll *dg1_ddi_get_pll(struct intel_encoder *encoder)
1640 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1641 enum phy phy = intel_port_to_phy(i915, encoder->port);
1642 enum intel_dpll_id id;
1645 val = intel_de_read(i915, DG1_DPCLKA_CFGCR0(phy));
1646 val &= DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
1647 val >>= DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
1651 * _DG1_DPCLKA0_CFGCR0 maps between DPLL 0 and 1 with one bit for phy A
1652 * and B while _DG1_DPCLKA1_CFGCR0 maps between DPLL 2 and 3 with one
1653 * bit for phy C and D.
1656 id += DPLL_ID_DG1_DPLL2;
1658 return intel_get_shared_dpll_by_id(i915, id);
1661 static void icl_ddi_combo_enable_clock(struct intel_encoder *encoder,
1662 const struct intel_crtc_state *crtc_state)
1664 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1665 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1666 enum phy phy = intel_port_to_phy(i915, encoder->port);
1668 if (drm_WARN_ON(&i915->drm, !pll))
1671 _icl_ddi_enable_clock(i915, ICL_DPCLKA_CFGCR0,
1672 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1673 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy),
1674 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1677 static void icl_ddi_combo_disable_clock(struct intel_encoder *encoder)
1679 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1680 enum phy phy = intel_port_to_phy(i915, encoder->port);
1682 _icl_ddi_disable_clock(i915, ICL_DPCLKA_CFGCR0,
1683 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1686 static bool icl_ddi_combo_is_clock_enabled(struct intel_encoder *encoder)
1688 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1689 enum phy phy = intel_port_to_phy(i915, encoder->port);
1691 return _icl_ddi_is_clock_enabled(i915, ICL_DPCLKA_CFGCR0,
1692 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1695 struct intel_shared_dpll *icl_ddi_combo_get_pll(struct intel_encoder *encoder)
1697 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1698 enum phy phy = intel_port_to_phy(i915, encoder->port);
1700 return _icl_ddi_get_pll(i915, ICL_DPCLKA_CFGCR0,
1701 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1702 ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy));
1705 static void jsl_ddi_tc_enable_clock(struct intel_encoder *encoder,
1706 const struct intel_crtc_state *crtc_state)
1708 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1709 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1710 enum port port = encoder->port;
1712 if (drm_WARN_ON(&i915->drm, !pll))
1716 * "For DDIC and DDID, program DDI_CLK_SEL to map the MG clock to the port.
1717 * MG does not exist, but the programming is required to ungate DDIC and DDID."
1719 intel_de_write(i915, DDI_CLK_SEL(port), DDI_CLK_SEL_MG);
1721 icl_ddi_combo_enable_clock(encoder, crtc_state);
1724 static void jsl_ddi_tc_disable_clock(struct intel_encoder *encoder)
1726 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1727 enum port port = encoder->port;
1729 icl_ddi_combo_disable_clock(encoder);
1731 intel_de_write(i915, DDI_CLK_SEL(port), DDI_CLK_SEL_NONE);
1734 static bool jsl_ddi_tc_is_clock_enabled(struct intel_encoder *encoder)
1736 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1737 enum port port = encoder->port;
1740 tmp = intel_de_read(i915, DDI_CLK_SEL(port));
1742 if ((tmp & DDI_CLK_SEL_MASK) == DDI_CLK_SEL_NONE)
1745 return icl_ddi_combo_is_clock_enabled(encoder);
1748 static void icl_ddi_tc_enable_clock(struct intel_encoder *encoder,
1749 const struct intel_crtc_state *crtc_state)
1751 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1752 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1753 enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
1754 enum port port = encoder->port;
1756 if (drm_WARN_ON(&i915->drm, !pll))
1759 intel_de_write(i915, DDI_CLK_SEL(port),
1760 icl_pll_to_ddi_clk_sel(encoder, crtc_state));
1762 mutex_lock(&i915->dpll.lock);
1764 intel_de_rmw(i915, ICL_DPCLKA_CFGCR0,
1765 ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port), 0);
1767 mutex_unlock(&i915->dpll.lock);
1770 static void icl_ddi_tc_disable_clock(struct intel_encoder *encoder)
1772 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1773 enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
1774 enum port port = encoder->port;
1776 mutex_lock(&i915->dpll.lock);
1778 intel_de_rmw(i915, ICL_DPCLKA_CFGCR0,
1779 0, ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port));
1781 mutex_unlock(&i915->dpll.lock);
1783 intel_de_write(i915, DDI_CLK_SEL(port), DDI_CLK_SEL_NONE);
1786 static bool icl_ddi_tc_is_clock_enabled(struct intel_encoder *encoder)
1788 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1789 enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
1790 enum port port = encoder->port;
1793 tmp = intel_de_read(i915, DDI_CLK_SEL(port));
1795 if ((tmp & DDI_CLK_SEL_MASK) == DDI_CLK_SEL_NONE)
1798 tmp = intel_de_read(i915, ICL_DPCLKA_CFGCR0);
1800 return !(tmp & ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port));
1803 static struct intel_shared_dpll *icl_ddi_tc_get_pll(struct intel_encoder *encoder)
1805 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1806 enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
1807 enum port port = encoder->port;
1808 enum intel_dpll_id id;
1811 tmp = intel_de_read(i915, DDI_CLK_SEL(port));
1813 switch (tmp & DDI_CLK_SEL_MASK) {
1814 case DDI_CLK_SEL_TBT_162:
1815 case DDI_CLK_SEL_TBT_270:
1816 case DDI_CLK_SEL_TBT_540:
1817 case DDI_CLK_SEL_TBT_810:
1818 id = DPLL_ID_ICL_TBTPLL;
1820 case DDI_CLK_SEL_MG:
1821 id = icl_tc_port_to_pll_id(tc_port);
1826 case DDI_CLK_SEL_NONE:
1830 return intel_get_shared_dpll_by_id(i915, id);
1833 static struct intel_shared_dpll *bxt_ddi_get_pll(struct intel_encoder *encoder)
1835 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1836 enum intel_dpll_id id;
1838 switch (encoder->port) {
1840 id = DPLL_ID_SKL_DPLL0;
1843 id = DPLL_ID_SKL_DPLL1;
1846 id = DPLL_ID_SKL_DPLL2;
1849 MISSING_CASE(encoder->port);
1853 return intel_get_shared_dpll_by_id(i915, id);
1856 static void skl_ddi_enable_clock(struct intel_encoder *encoder,
1857 const struct intel_crtc_state *crtc_state)
1859 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1860 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1861 enum port port = encoder->port;
1863 if (drm_WARN_ON(&i915->drm, !pll))
1866 mutex_lock(&i915->dpll.lock);
1868 intel_de_rmw(i915, DPLL_CTRL2,
1869 DPLL_CTRL2_DDI_CLK_OFF(port) |
1870 DPLL_CTRL2_DDI_CLK_SEL_MASK(port),
1871 DPLL_CTRL2_DDI_CLK_SEL(pll->info->id, port) |
1872 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
1874 mutex_unlock(&i915->dpll.lock);
1877 static void skl_ddi_disable_clock(struct intel_encoder *encoder)
1879 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1880 enum port port = encoder->port;
1882 mutex_lock(&i915->dpll.lock);
1884 intel_de_rmw(i915, DPLL_CTRL2,
1885 0, DPLL_CTRL2_DDI_CLK_OFF(port));
1887 mutex_unlock(&i915->dpll.lock);
1890 static bool skl_ddi_is_clock_enabled(struct intel_encoder *encoder)
1892 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1893 enum port port = encoder->port;
1896 * FIXME Not sure if the override affects both
1897 * the PLL selection and the CLK_OFF bit.
1899 return !(intel_de_read(i915, DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_OFF(port));
1902 static struct intel_shared_dpll *skl_ddi_get_pll(struct intel_encoder *encoder)
1904 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1905 enum port port = encoder->port;
1906 enum intel_dpll_id id;
1909 tmp = intel_de_read(i915, DPLL_CTRL2);
1912 * FIXME Not sure if the override affects both
1913 * the PLL selection and the CLK_OFF bit.
1915 if ((tmp & DPLL_CTRL2_DDI_SEL_OVERRIDE(port)) == 0)
1918 id = (tmp & DPLL_CTRL2_DDI_CLK_SEL_MASK(port)) >>
1919 DPLL_CTRL2_DDI_CLK_SEL_SHIFT(port);
1921 return intel_get_shared_dpll_by_id(i915, id);
1924 void hsw_ddi_enable_clock(struct intel_encoder *encoder,
1925 const struct intel_crtc_state *crtc_state)
1927 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1928 const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1929 enum port port = encoder->port;
1931 if (drm_WARN_ON(&i915->drm, !pll))
1934 intel_de_write(i915, PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
1937 void hsw_ddi_disable_clock(struct intel_encoder *encoder)
1939 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1940 enum port port = encoder->port;
1942 intel_de_write(i915, PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1945 bool hsw_ddi_is_clock_enabled(struct intel_encoder *encoder)
1947 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1948 enum port port = encoder->port;
1950 return intel_de_read(i915, PORT_CLK_SEL(port)) != PORT_CLK_SEL_NONE;
1953 static struct intel_shared_dpll *hsw_ddi_get_pll(struct intel_encoder *encoder)
1955 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1956 enum port port = encoder->port;
1957 enum intel_dpll_id id;
1960 tmp = intel_de_read(i915, PORT_CLK_SEL(port));
1962 switch (tmp & PORT_CLK_SEL_MASK) {
1963 case PORT_CLK_SEL_WRPLL1:
1964 id = DPLL_ID_WRPLL1;
1966 case PORT_CLK_SEL_WRPLL2:
1967 id = DPLL_ID_WRPLL2;
1969 case PORT_CLK_SEL_SPLL:
1972 case PORT_CLK_SEL_LCPLL_810:
1973 id = DPLL_ID_LCPLL_810;
1975 case PORT_CLK_SEL_LCPLL_1350:
1976 id = DPLL_ID_LCPLL_1350;
1978 case PORT_CLK_SEL_LCPLL_2700:
1979 id = DPLL_ID_LCPLL_2700;
1984 case PORT_CLK_SEL_NONE:
1988 return intel_get_shared_dpll_by_id(i915, id);
1991 void intel_ddi_enable_clock(struct intel_encoder *encoder,
1992 const struct intel_crtc_state *crtc_state)
1994 if (encoder->enable_clock)
1995 encoder->enable_clock(encoder, crtc_state);
1998 static void intel_ddi_disable_clock(struct intel_encoder *encoder)
2000 if (encoder->disable_clock)
2001 encoder->disable_clock(encoder);
2004 void intel_ddi_sanitize_encoder_pll_mapping(struct intel_encoder *encoder)
2006 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2008 bool ddi_clk_needed;
2011 * In case of DP MST, we sanitize the primary encoder only, not the
2014 if (encoder->type == INTEL_OUTPUT_DP_MST)
2017 if (!encoder->base.crtc && intel_encoder_is_dp(encoder)) {
2021 intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst);
2023 * In the unlikely case that BIOS enables DP in MST mode, just
2024 * warn since our MST HW readout is incomplete.
2026 if (drm_WARN_ON(&i915->drm, is_mst))
2030 port_mask = BIT(encoder->port);
2031 ddi_clk_needed = encoder->base.crtc;
2033 if (encoder->type == INTEL_OUTPUT_DSI) {
2034 struct intel_encoder *other_encoder;
2036 port_mask = intel_dsi_encoder_ports(encoder);
2038 * Sanity check that we haven't incorrectly registered another
2039 * encoder using any of the ports of this DSI encoder.
2041 for_each_intel_encoder(&i915->drm, other_encoder) {
2042 if (other_encoder == encoder)
2045 if (drm_WARN_ON(&i915->drm,
2046 port_mask & BIT(other_encoder->port)))
2050 * For DSI we keep the ddi clocks gated
2051 * except during enable/disable sequence.
2053 ddi_clk_needed = false;
2056 if (ddi_clk_needed || !encoder->is_clock_enabled ||
2057 !encoder->is_clock_enabled(encoder))
2060 drm_notice(&i915->drm,
2061 "[ENCODER:%d:%s] is disabled/in DSI mode with an ungated DDI clock, gate it\n",
2062 encoder->base.base.id, encoder->base.name);
2064 encoder->disable_clock(encoder);
2068 icl_program_mg_dp_mode(struct intel_digital_port *dig_port,
2069 const struct intel_crtc_state *crtc_state)
2071 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2072 enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port);
2073 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
2074 u32 ln0, ln1, pin_assignment;
2077 if (!intel_phy_is_tc(dev_priv, phy) ||
2078 dig_port->tc_mode == TC_PORT_TBT_ALT)
2081 if (DISPLAY_VER(dev_priv) >= 12) {
2082 intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2083 HIP_INDEX_VAL(tc_port, 0x0));
2084 ln0 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port));
2085 intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2086 HIP_INDEX_VAL(tc_port, 0x1));
2087 ln1 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port));
2089 ln0 = intel_de_read(dev_priv, MG_DP_MODE(0, tc_port));
2090 ln1 = intel_de_read(dev_priv, MG_DP_MODE(1, tc_port));
2093 ln0 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE);
2094 ln1 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE);
2097 pin_assignment = intel_tc_port_get_pin_assignment_mask(dig_port);
2098 width = crtc_state->lane_count;
2100 switch (pin_assignment) {
2102 drm_WARN_ON(&dev_priv->drm,
2103 dig_port->tc_mode != TC_PORT_LEGACY);
2105 ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
2107 ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
2108 ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
2113 ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
2114 ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
2119 ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
2120 ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
2126 ln0 |= MG_DP_MODE_CFG_DP_X1_MODE;
2127 ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
2129 ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
2130 ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
2136 ln0 |= MG_DP_MODE_CFG_DP_X1_MODE;
2137 ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
2139 ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
2140 ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
2144 MISSING_CASE(pin_assignment);
2147 if (DISPLAY_VER(dev_priv) >= 12) {
2148 intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2149 HIP_INDEX_VAL(tc_port, 0x0));
2150 intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln0);
2151 intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2152 HIP_INDEX_VAL(tc_port, 0x1));
2153 intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln1);
2155 intel_de_write(dev_priv, MG_DP_MODE(0, tc_port), ln0);
2156 intel_de_write(dev_priv, MG_DP_MODE(1, tc_port), ln1);
2160 static enum transcoder
2161 tgl_dp_tp_transcoder(const struct intel_crtc_state *crtc_state)
2163 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))
2164 return crtc_state->mst_master_transcoder;
2166 return crtc_state->cpu_transcoder;
2169 i915_reg_t dp_tp_ctl_reg(struct intel_encoder *encoder,
2170 const struct intel_crtc_state *crtc_state)
2172 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2174 if (DISPLAY_VER(dev_priv) >= 12)
2175 return TGL_DP_TP_CTL(tgl_dp_tp_transcoder(crtc_state));
2177 return DP_TP_CTL(encoder->port);
2180 i915_reg_t dp_tp_status_reg(struct intel_encoder *encoder,
2181 const struct intel_crtc_state *crtc_state)
2183 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2185 if (DISPLAY_VER(dev_priv) >= 12)
2186 return TGL_DP_TP_STATUS(tgl_dp_tp_transcoder(crtc_state));
2188 return DP_TP_STATUS(encoder->port);
2191 static void intel_dp_sink_set_msa_timing_par_ignore_state(struct intel_dp *intel_dp,
2192 const struct intel_crtc_state *crtc_state,
2195 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
2197 if (!crtc_state->vrr.enable)
2200 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_DOWNSPREAD_CTRL,
2201 enable ? DP_MSA_TIMING_PAR_IGNORE_EN : 0) <= 0)
2202 drm_dbg_kms(&i915->drm,
2203 "Failed to %s MSA_TIMING_PAR_IGNORE in the sink\n",
2204 enabledisable(enable));
2207 static void intel_dp_sink_set_fec_ready(struct intel_dp *intel_dp,
2208 const struct intel_crtc_state *crtc_state)
2210 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
2212 if (!crtc_state->fec_enable)
2215 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_FEC_CONFIGURATION, DP_FEC_READY) <= 0)
2216 drm_dbg_kms(&i915->drm,
2217 "Failed to set FEC_READY in the sink\n");
2220 static void intel_ddi_enable_fec(struct intel_encoder *encoder,
2221 const struct intel_crtc_state *crtc_state)
2223 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2224 struct intel_dp *intel_dp;
2227 if (!crtc_state->fec_enable)
2230 intel_dp = enc_to_intel_dp(encoder);
2231 val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2232 val |= DP_TP_CTL_FEC_ENABLE;
2233 intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
2236 static void intel_ddi_disable_fec_state(struct intel_encoder *encoder,
2237 const struct intel_crtc_state *crtc_state)
2239 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2240 struct intel_dp *intel_dp;
2243 if (!crtc_state->fec_enable)
2246 intel_dp = enc_to_intel_dp(encoder);
2247 val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2248 val &= ~DP_TP_CTL_FEC_ENABLE;
2249 intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
2250 intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2253 static void intel_ddi_power_up_lanes(struct intel_encoder *encoder,
2254 const struct intel_crtc_state *crtc_state)
2256 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2257 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2258 enum phy phy = intel_port_to_phy(i915, encoder->port);
2260 if (intel_phy_is_combo(i915, phy)) {
2261 bool lane_reversal =
2262 dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL;
2264 intel_combo_phy_power_up_lanes(i915, phy, false,
2265 crtc_state->lane_count,
2270 /* Splitter enable for eDP MSO is limited to certain pipes. */
2271 static u8 intel_ddi_splitter_pipe_mask(struct drm_i915_private *i915)
2273 if (IS_ALDERLAKE_P(i915))
2274 return BIT(PIPE_A) | BIT(PIPE_B);
2279 static void intel_ddi_mso_get_config(struct intel_encoder *encoder,
2280 struct intel_crtc_state *pipe_config)
2282 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
2283 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2284 enum pipe pipe = crtc->pipe;
2290 dss1 = intel_de_read(i915, ICL_PIPE_DSS_CTL1(pipe));
2292 pipe_config->splitter.enable = dss1 & SPLITTER_ENABLE;
2293 if (!pipe_config->splitter.enable)
2296 if (drm_WARN_ON(&i915->drm, !(intel_ddi_splitter_pipe_mask(i915) & BIT(pipe)))) {
2297 pipe_config->splitter.enable = false;
2301 switch (dss1 & SPLITTER_CONFIGURATION_MASK) {
2303 drm_WARN(&i915->drm, true,
2304 "Invalid splitter configuration, dss1=0x%08x\n", dss1);
2306 case SPLITTER_CONFIGURATION_2_SEGMENT:
2307 pipe_config->splitter.link_count = 2;
2309 case SPLITTER_CONFIGURATION_4_SEGMENT:
2310 pipe_config->splitter.link_count = 4;
2314 pipe_config->splitter.pixel_overlap = REG_FIELD_GET(OVERLAP_PIXELS_MASK, dss1);
2317 static void intel_ddi_mso_configure(const struct intel_crtc_state *crtc_state)
2319 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2320 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2321 enum pipe pipe = crtc->pipe;
2327 if (crtc_state->splitter.enable) {
2328 dss1 |= SPLITTER_ENABLE;
2329 dss1 |= OVERLAP_PIXELS(crtc_state->splitter.pixel_overlap);
2330 if (crtc_state->splitter.link_count == 2)
2331 dss1 |= SPLITTER_CONFIGURATION_2_SEGMENT;
2333 dss1 |= SPLITTER_CONFIGURATION_4_SEGMENT;
2336 intel_de_rmw(i915, ICL_PIPE_DSS_CTL1(pipe),
2337 SPLITTER_ENABLE | SPLITTER_CONFIGURATION_MASK |
2338 OVERLAP_PIXELS_MASK, dss1);
2341 static void dg2_ddi_pre_enable_dp(struct intel_atomic_state *state,
2342 struct intel_encoder *encoder,
2343 const struct intel_crtc_state *crtc_state,
2344 const struct drm_connector_state *conn_state)
2346 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2347 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2348 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2349 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2350 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
2351 int level = intel_ddi_dp_level(intel_dp, crtc_state);
2353 intel_dp_set_link_params(intel_dp, crtc_state->port_clock,
2354 crtc_state->lane_count);
2357 * 1. Enable Power Wells
2359 * This was handled at the beginning of intel_atomic_commit_tail(),
2360 * before we called down into this function.
2363 /* 2. Enable Panel Power if PPS is required */
2364 intel_pps_on(intel_dp);
2367 * 3. Enable the port PLL.
2369 intel_ddi_enable_clock(encoder, crtc_state);
2371 /* 4. Enable IO power */
2372 if (!intel_phy_is_tc(dev_priv, phy) ||
2373 dig_port->tc_mode != TC_PORT_TBT_ALT)
2374 dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
2375 dig_port->ddi_io_power_domain);
2378 * 5. The rest of the below are substeps under the bspec's "Enable and
2379 * Train Display Port" step. Note that steps that are specific to
2380 * MST will be handled by intel_mst_pre_enable_dp() before/after it
2381 * calls into this function. Also intel_mst_pre_enable_dp() only calls
2382 * us when active_mst_links==0, so any steps designated for "single
2383 * stream or multi-stream master transcoder" can just be performed
2384 * unconditionally here.
2388 * 5.a Configure Transcoder Clock Select to direct the Port clock to the
2391 intel_ddi_enable_pipe_clock(encoder, crtc_state);
2393 /* 5.b Configure transcoder for DP 2.0 128b/132b */
2394 intel_ddi_config_transcoder_dp2(encoder, crtc_state);
2397 * 5.c Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST
2400 intel_ddi_config_transcoder_func(encoder, crtc_state);
2403 * 5.d Configure & enable DP_TP_CTL with link training pattern 1
2406 * This will be handled by the intel_dp_start_link_train() farther
2407 * down this function.
2410 /* 5.e Configure voltage swing and related IO settings */
2411 intel_snps_phy_ddi_vswing_sequence(encoder, crtc_state, level);
2414 * 5.f Configure and enable DDI_BUF_CTL
2415 * 5.g Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout
2418 * We only configure what the register value will be here. Actual
2419 * enabling happens during link training farther down.
2421 intel_ddi_init_dp_buf_reg(encoder, crtc_state);
2424 intel_dp_set_power(intel_dp, DP_SET_POWER_D0);
2426 intel_dp_configure_protocol_converter(intel_dp, crtc_state);
2427 intel_dp_sink_set_decompression_state(intel_dp, crtc_state, true);
2429 * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit
2430 * in the FEC_CONFIGURATION register to 1 before initiating link
2433 intel_dp_sink_set_fec_ready(intel_dp, crtc_state);
2434 intel_dp_check_frl_training(intel_dp);
2435 intel_dp_pcon_dsc_configure(intel_dp, crtc_state);
2438 * 5.h Follow DisplayPort specification training sequence (see notes for
2440 * 5.i If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle
2441 * Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent)
2442 * (timeout after 800 us)
2444 intel_dp_start_link_train(intel_dp, crtc_state);
2446 /* 5.j Set DP_TP_CTL link training to Normal */
2447 if (!is_trans_port_sync_mode(crtc_state))
2448 intel_dp_stop_link_train(intel_dp, crtc_state);
2450 /* 5.k Configure and enable FEC if needed */
2451 intel_ddi_enable_fec(encoder, crtc_state);
2452 intel_dsc_enable(encoder, crtc_state);
2455 static void tgl_ddi_pre_enable_dp(struct intel_atomic_state *state,
2456 struct intel_encoder *encoder,
2457 const struct intel_crtc_state *crtc_state,
2458 const struct drm_connector_state *conn_state)
2460 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2461 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2462 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2463 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2464 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
2465 int level = intel_ddi_dp_level(intel_dp, crtc_state);
2467 intel_dp_set_link_params(intel_dp,
2468 crtc_state->port_clock,
2469 crtc_state->lane_count);
2472 * 1. Enable Power Wells
2474 * This was handled at the beginning of intel_atomic_commit_tail(),
2475 * before we called down into this function.
2478 /* 2. Enable Panel Power if PPS is required */
2479 intel_pps_on(intel_dp);
2482 * 3. For non-TBT Type-C ports, set FIA lane count
2483 * (DFLEXDPSP.DPX4TXLATC)
2485 * This was done before tgl_ddi_pre_enable_dp by
2486 * hsw_crtc_enable()->intel_encoders_pre_pll_enable().
2490 * 4. Enable the port PLL.
2492 * The PLL enabling itself was already done before this function by
2493 * hsw_crtc_enable()->intel_enable_shared_dpll(). We need only
2494 * configure the PLL to port mapping here.
2496 intel_ddi_enable_clock(encoder, crtc_state);
2498 /* 5. If IO power is controlled through PWR_WELL_CTL, Enable IO Power */
2499 if (!intel_phy_is_tc(dev_priv, phy) ||
2500 dig_port->tc_mode != TC_PORT_TBT_ALT) {
2501 drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
2502 dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
2503 dig_port->ddi_io_power_domain);
2506 /* 6. Program DP_MODE */
2507 icl_program_mg_dp_mode(dig_port, crtc_state);
2510 * 7. The rest of the below are substeps under the bspec's "Enable and
2511 * Train Display Port" step. Note that steps that are specific to
2512 * MST will be handled by intel_mst_pre_enable_dp() before/after it
2513 * calls into this function. Also intel_mst_pre_enable_dp() only calls
2514 * us when active_mst_links==0, so any steps designated for "single
2515 * stream or multi-stream master transcoder" can just be performed
2516 * unconditionally here.
2520 * 7.a Configure Transcoder Clock Select to direct the Port clock to the
2523 intel_ddi_enable_pipe_clock(encoder, crtc_state);
2526 * 7.b Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST
2529 intel_ddi_config_transcoder_func(encoder, crtc_state);
2532 * 7.c Configure & enable DP_TP_CTL with link training pattern 1
2535 * This will be handled by the intel_dp_start_link_train() farther
2536 * down this function.
2539 /* 7.e Configure voltage swing and related IO settings */
2540 tgl_ddi_vswing_sequence(encoder, crtc_state, level);
2543 * 7.f Combo PHY: Configure PORT_CL_DW10 Static Power Down to power up
2544 * the used lanes of the DDI.
2546 intel_ddi_power_up_lanes(encoder, crtc_state);
2549 * 7.g Program CoG/MSO configuration bits in DSS_CTL1 if selected.
2551 intel_ddi_mso_configure(crtc_state);
2554 * 7.g Configure and enable DDI_BUF_CTL
2555 * 7.h Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout
2558 * We only configure what the register value will be here. Actual
2559 * enabling happens during link training farther down.
2561 intel_ddi_init_dp_buf_reg(encoder, crtc_state);
2564 intel_dp_set_power(intel_dp, DP_SET_POWER_D0);
2566 intel_dp_configure_protocol_converter(intel_dp, crtc_state);
2567 intel_dp_sink_set_decompression_state(intel_dp, crtc_state, true);
2569 * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit
2570 * in the FEC_CONFIGURATION register to 1 before initiating link
2573 intel_dp_sink_set_fec_ready(intel_dp, crtc_state);
2575 intel_dp_check_frl_training(intel_dp);
2576 intel_dp_pcon_dsc_configure(intel_dp, crtc_state);
2579 * 7.i Follow DisplayPort specification training sequence (see notes for
2581 * 7.j If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle
2582 * Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent)
2583 * (timeout after 800 us)
2585 intel_dp_start_link_train(intel_dp, crtc_state);
2587 /* 7.k Set DP_TP_CTL link training to Normal */
2588 if (!is_trans_port_sync_mode(crtc_state))
2589 intel_dp_stop_link_train(intel_dp, crtc_state);
2591 /* 7.l Configure and enable FEC if needed */
2592 intel_ddi_enable_fec(encoder, crtc_state);
2593 if (!crtc_state->bigjoiner)
2594 intel_dsc_enable(encoder, crtc_state);
2597 static void hsw_ddi_pre_enable_dp(struct intel_atomic_state *state,
2598 struct intel_encoder *encoder,
2599 const struct intel_crtc_state *crtc_state,
2600 const struct drm_connector_state *conn_state)
2602 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2603 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2604 enum port port = encoder->port;
2605 enum phy phy = intel_port_to_phy(dev_priv, port);
2606 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2607 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
2608 int level = intel_ddi_dp_level(intel_dp, crtc_state);
2610 if (DISPLAY_VER(dev_priv) < 11)
2611 drm_WARN_ON(&dev_priv->drm,
2612 is_mst && (port == PORT_A || port == PORT_E));
2614 drm_WARN_ON(&dev_priv->drm, is_mst && port == PORT_A);
2616 intel_dp_set_link_params(intel_dp,
2617 crtc_state->port_clock,
2618 crtc_state->lane_count);
2620 intel_pps_on(intel_dp);
2622 intel_ddi_enable_clock(encoder, crtc_state);
2624 if (!intel_phy_is_tc(dev_priv, phy) ||
2625 dig_port->tc_mode != TC_PORT_TBT_ALT) {
2626 drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
2627 dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
2628 dig_port->ddi_io_power_domain);
2631 icl_program_mg_dp_mode(dig_port, crtc_state);
2633 if (DISPLAY_VER(dev_priv) >= 11)
2634 icl_ddi_vswing_sequence(encoder, crtc_state, level);
2635 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
2636 bxt_ddi_vswing_sequence(encoder, crtc_state, level);
2638 hsw_prepare_dp_ddi_buffers(encoder, crtc_state);
2640 intel_ddi_power_up_lanes(encoder, crtc_state);
2642 intel_ddi_init_dp_buf_reg(encoder, crtc_state);
2644 intel_dp_set_power(intel_dp, DP_SET_POWER_D0);
2645 intel_dp_configure_protocol_converter(intel_dp, crtc_state);
2646 intel_dp_sink_set_decompression_state(intel_dp, crtc_state,
2648 intel_dp_sink_set_fec_ready(intel_dp, crtc_state);
2649 intel_dp_start_link_train(intel_dp, crtc_state);
2650 if ((port != PORT_A || DISPLAY_VER(dev_priv) >= 9) &&
2651 !is_trans_port_sync_mode(crtc_state))
2652 intel_dp_stop_link_train(intel_dp, crtc_state);
2654 intel_ddi_enable_fec(encoder, crtc_state);
2657 intel_ddi_enable_pipe_clock(encoder, crtc_state);
2659 if (!crtc_state->bigjoiner)
2660 intel_dsc_enable(encoder, crtc_state);
2663 static void intel_ddi_pre_enable_dp(struct intel_atomic_state *state,
2664 struct intel_encoder *encoder,
2665 const struct intel_crtc_state *crtc_state,
2666 const struct drm_connector_state *conn_state)
2668 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2670 if (IS_DG2(dev_priv))
2671 dg2_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state);
2672 else if (DISPLAY_VER(dev_priv) >= 12)
2673 tgl_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state);
2675 hsw_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state);
2677 /* MST will call a setting of MSA after an allocating of Virtual Channel
2678 * from MST encoder pre_enable callback.
2680 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
2681 intel_ddi_set_dp_msa(crtc_state, conn_state);
2683 intel_dp_set_m_n(crtc_state, M1_N1);
2687 static void intel_ddi_pre_enable_hdmi(struct intel_atomic_state *state,
2688 struct intel_encoder *encoder,
2689 const struct intel_crtc_state *crtc_state,
2690 const struct drm_connector_state *conn_state)
2692 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2693 struct intel_hdmi *intel_hdmi = &dig_port->hdmi;
2694 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2696 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
2697 intel_ddi_enable_clock(encoder, crtc_state);
2699 drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
2700 dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
2701 dig_port->ddi_io_power_domain);
2703 icl_program_mg_dp_mode(dig_port, crtc_state);
2705 intel_ddi_enable_pipe_clock(encoder, crtc_state);
2707 dig_port->set_infoframes(encoder,
2708 crtc_state->has_infoframe,
2709 crtc_state, conn_state);
2712 static void intel_ddi_pre_enable(struct intel_atomic_state *state,
2713 struct intel_encoder *encoder,
2714 const struct intel_crtc_state *crtc_state,
2715 const struct drm_connector_state *conn_state)
2717 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2718 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2719 enum pipe pipe = crtc->pipe;
2722 * When called from DP MST code:
2723 * - conn_state will be NULL
2724 * - encoder will be the main encoder (ie. mst->primary)
2725 * - the main connector associated with this port
2726 * won't be active or linked to a crtc
2727 * - crtc_state will be the state of the first stream to
2728 * be activated on this port, and it may not be the same
2729 * stream that will be deactivated last, but each stream
2730 * should have a state that is identical when it comes to
2731 * the DP link parameteres
2734 drm_WARN_ON(&dev_priv->drm, crtc_state->has_pch_encoder);
2736 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2738 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
2739 intel_ddi_pre_enable_hdmi(state, encoder, crtc_state,
2742 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2744 intel_ddi_pre_enable_dp(state, encoder, crtc_state,
2747 /* FIXME precompute everything properly */
2748 /* FIXME how do we turn infoframes off again? */
2749 if (dig_port->lspcon.active && dig_port->dp.has_hdmi_sink)
2750 dig_port->set_infoframes(encoder,
2751 crtc_state->has_infoframe,
2752 crtc_state, conn_state);
2756 static void intel_disable_ddi_buf(struct intel_encoder *encoder,
2757 const struct intel_crtc_state *crtc_state)
2759 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2760 enum port port = encoder->port;
2764 val = intel_de_read(dev_priv, DDI_BUF_CTL(port));
2765 if (val & DDI_BUF_CTL_ENABLE) {
2766 val &= ~DDI_BUF_CTL_ENABLE;
2767 intel_de_write(dev_priv, DDI_BUF_CTL(port), val);
2771 if (intel_crtc_has_dp_encoder(crtc_state)) {
2772 val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2773 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2774 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2775 intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
2778 /* Disable FEC in DP Sink */
2779 intel_ddi_disable_fec_state(encoder, crtc_state);
2782 intel_wait_ddi_buf_idle(dev_priv, port);
2785 static void intel_ddi_post_disable_dp(struct intel_atomic_state *state,
2786 struct intel_encoder *encoder,
2787 const struct intel_crtc_state *old_crtc_state,
2788 const struct drm_connector_state *old_conn_state)
2790 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2791 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2792 struct intel_dp *intel_dp = &dig_port->dp;
2793 bool is_mst = intel_crtc_has_type(old_crtc_state,
2794 INTEL_OUTPUT_DP_MST);
2795 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2798 intel_dp_set_infoframes(encoder, false,
2799 old_crtc_state, old_conn_state);
2802 * Power down sink before disabling the port, otherwise we end
2803 * up getting interrupts from the sink on detecting link loss.
2805 intel_dp_set_power(intel_dp, DP_SET_POWER_D3);
2807 if (DISPLAY_VER(dev_priv) >= 12) {
2809 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
2812 val = intel_de_read(dev_priv,
2813 TRANS_DDI_FUNC_CTL(cpu_transcoder));
2814 val &= ~(TGL_TRANS_DDI_PORT_MASK |
2815 TRANS_DDI_MODE_SELECT_MASK);
2816 intel_de_write(dev_priv,
2817 TRANS_DDI_FUNC_CTL(cpu_transcoder),
2822 intel_ddi_disable_pipe_clock(old_crtc_state);
2825 intel_disable_ddi_buf(encoder, old_crtc_state);
2828 * From TGL spec: "If single stream or multi-stream master transcoder:
2829 * Configure Transcoder Clock select to direct no clock to the
2832 if (DISPLAY_VER(dev_priv) >= 12)
2833 intel_ddi_disable_pipe_clock(old_crtc_state);
2835 intel_pps_vdd_on(intel_dp);
2836 intel_pps_off(intel_dp);
2838 if (!intel_phy_is_tc(dev_priv, phy) ||
2839 dig_port->tc_mode != TC_PORT_TBT_ALT)
2840 intel_display_power_put(dev_priv,
2841 dig_port->ddi_io_power_domain,
2842 fetch_and_zero(&dig_port->ddi_io_wakeref));
2844 intel_ddi_disable_clock(encoder);
2847 static void intel_ddi_post_disable_hdmi(struct intel_atomic_state *state,
2848 struct intel_encoder *encoder,
2849 const struct intel_crtc_state *old_crtc_state,
2850 const struct drm_connector_state *old_conn_state)
2852 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2853 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2854 struct intel_hdmi *intel_hdmi = &dig_port->hdmi;
2856 dig_port->set_infoframes(encoder, false,
2857 old_crtc_state, old_conn_state);
2859 intel_ddi_disable_pipe_clock(old_crtc_state);
2861 intel_disable_ddi_buf(encoder, old_crtc_state);
2863 intel_display_power_put(dev_priv,
2864 dig_port->ddi_io_power_domain,
2865 fetch_and_zero(&dig_port->ddi_io_wakeref));
2867 intel_ddi_disable_clock(encoder);
2869 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
2872 static void intel_ddi_post_disable(struct intel_atomic_state *state,
2873 struct intel_encoder *encoder,
2874 const struct intel_crtc_state *old_crtc_state,
2875 const struct drm_connector_state *old_conn_state)
2877 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2878 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2879 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2880 bool is_tc_port = intel_phy_is_tc(dev_priv, phy);
2882 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) {
2883 intel_crtc_vblank_off(old_crtc_state);
2885 intel_disable_transcoder(old_crtc_state);
2887 intel_vrr_disable(old_crtc_state);
2889 intel_ddi_disable_transcoder_func(old_crtc_state);
2891 intel_dsc_disable(old_crtc_state);
2893 if (DISPLAY_VER(dev_priv) >= 9)
2894 skl_scaler_disable(old_crtc_state);
2896 ilk_pfit_disable(old_crtc_state);
2899 if (old_crtc_state->bigjoiner_linked_crtc) {
2900 struct intel_atomic_state *state =
2901 to_intel_atomic_state(old_crtc_state->uapi.state);
2902 struct intel_crtc *slave =
2903 old_crtc_state->bigjoiner_linked_crtc;
2904 const struct intel_crtc_state *old_slave_crtc_state =
2905 intel_atomic_get_old_crtc_state(state, slave);
2907 intel_crtc_vblank_off(old_slave_crtc_state);
2909 intel_dsc_disable(old_slave_crtc_state);
2910 skl_scaler_disable(old_slave_crtc_state);
2914 * When called from DP MST code:
2915 * - old_conn_state will be NULL
2916 * - encoder will be the main encoder (ie. mst->primary)
2917 * - the main connector associated with this port
2918 * won't be active or linked to a crtc
2919 * - old_crtc_state will be the state of the last stream to
2920 * be deactivated on this port, and it may not be the same
2921 * stream that was activated last, but each stream
2922 * should have a state that is identical when it comes to
2923 * the DP link parameteres
2926 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
2927 intel_ddi_post_disable_hdmi(state, encoder, old_crtc_state,
2930 intel_ddi_post_disable_dp(state, encoder, old_crtc_state,
2933 if (intel_crtc_has_dp_encoder(old_crtc_state) || is_tc_port)
2934 intel_display_power_put(dev_priv,
2935 intel_ddi_main_link_aux_domain(dig_port),
2936 fetch_and_zero(&dig_port->aux_wakeref));
2939 intel_tc_port_put_link(dig_port);
2942 void intel_ddi_fdi_post_disable(struct intel_atomic_state *state,
2943 struct intel_encoder *encoder,
2944 const struct intel_crtc_state *old_crtc_state,
2945 const struct drm_connector_state *old_conn_state)
2947 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2951 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
2952 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
2953 * step 13 is the correct place for it. Step 18 is where it was
2954 * originally before the BUN.
2956 val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
2957 val &= ~FDI_RX_ENABLE;
2958 intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
2960 intel_disable_ddi_buf(encoder, old_crtc_state);
2961 intel_ddi_disable_clock(encoder);
2963 val = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A));
2964 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
2965 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
2966 intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), val);
2968 val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
2970 intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
2972 val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
2973 val &= ~FDI_RX_PLL_ENABLE;
2974 intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
2977 static void trans_port_sync_stop_link_train(struct intel_atomic_state *state,
2978 struct intel_encoder *encoder,
2979 const struct intel_crtc_state *crtc_state)
2981 const struct drm_connector_state *conn_state;
2982 struct drm_connector *conn;
2985 if (!crtc_state->sync_mode_slaves_mask)
2988 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
2989 struct intel_encoder *slave_encoder =
2990 to_intel_encoder(conn_state->best_encoder);
2991 struct intel_crtc *slave_crtc = to_intel_crtc(conn_state->crtc);
2992 const struct intel_crtc_state *slave_crtc_state;
2998 intel_atomic_get_new_crtc_state(state, slave_crtc);
3000 if (slave_crtc_state->master_transcoder !=
3001 crtc_state->cpu_transcoder)
3004 intel_dp_stop_link_train(enc_to_intel_dp(slave_encoder),
3008 usleep_range(200, 400);
3010 intel_dp_stop_link_train(enc_to_intel_dp(encoder),
3014 static void intel_enable_ddi_dp(struct intel_atomic_state *state,
3015 struct intel_encoder *encoder,
3016 const struct intel_crtc_state *crtc_state,
3017 const struct drm_connector_state *conn_state)
3019 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3020 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3021 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3022 enum port port = encoder->port;
3024 if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
3025 intel_dp_stop_link_train(intel_dp, crtc_state);
3027 intel_edp_backlight_on(crtc_state, conn_state);
3028 intel_psr_enable(intel_dp, crtc_state, conn_state);
3030 if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
3031 intel_dp_set_infoframes(encoder, true, crtc_state, conn_state);
3033 intel_drrs_enable(intel_dp, crtc_state);
3035 if (crtc_state->has_audio)
3036 intel_audio_codec_enable(encoder, crtc_state, conn_state);
3038 trans_port_sync_stop_link_train(state, encoder, crtc_state);
3042 gen9_chicken_trans_reg_by_port(struct drm_i915_private *dev_priv,
3045 static const enum transcoder trans[] = {
3046 [PORT_A] = TRANSCODER_EDP,
3047 [PORT_B] = TRANSCODER_A,
3048 [PORT_C] = TRANSCODER_B,
3049 [PORT_D] = TRANSCODER_C,
3050 [PORT_E] = TRANSCODER_A,
3053 drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) < 9);
3055 if (drm_WARN_ON(&dev_priv->drm, port < PORT_A || port > PORT_E))
3058 return CHICKEN_TRANS(trans[port]);
3061 static void intel_enable_ddi_hdmi(struct intel_atomic_state *state,
3062 struct intel_encoder *encoder,
3063 const struct intel_crtc_state *crtc_state,
3064 const struct drm_connector_state *conn_state)
3066 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3067 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3068 struct drm_connector *connector = conn_state->connector;
3069 int level = intel_ddi_hdmi_level(encoder, crtc_state);
3070 enum port port = encoder->port;
3072 if (!intel_hdmi_handle_sink_scrambling(encoder, connector,
3073 crtc_state->hdmi_high_tmds_clock_ratio,
3074 crtc_state->hdmi_scrambling))
3075 drm_dbg_kms(&dev_priv->drm,
3076 "[CONNECTOR:%d:%s] Failed to configure sink scrambling/TMDS bit clock ratio\n",
3077 connector->base.id, connector->name);
3079 if (IS_DG2(dev_priv))
3080 intel_snps_phy_ddi_vswing_sequence(encoder, crtc_state, level);
3081 else if (DISPLAY_VER(dev_priv) >= 12)
3082 tgl_ddi_vswing_sequence(encoder, crtc_state, level);
3083 else if (DISPLAY_VER(dev_priv) == 11)
3084 icl_ddi_vswing_sequence(encoder, crtc_state, level);
3085 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3086 bxt_ddi_vswing_sequence(encoder, crtc_state, level);
3088 hsw_prepare_hdmi_ddi_buffers(encoder, crtc_state, level);
3090 if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv))
3091 skl_ddi_set_iboost(encoder, crtc_state, level);
3093 /* Display WA #1143: skl,kbl,cfl */
3094 if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv)) {
3096 * For some reason these chicken bits have been
3097 * stuffed into a transcoder register, event though
3098 * the bits affect a specific DDI port rather than
3099 * a specific transcoder.
3101 i915_reg_t reg = gen9_chicken_trans_reg_by_port(dev_priv, port);
3104 val = intel_de_read(dev_priv, reg);
3107 val |= DDIE_TRAINING_OVERRIDE_ENABLE |
3108 DDIE_TRAINING_OVERRIDE_VALUE;
3110 val |= DDI_TRAINING_OVERRIDE_ENABLE |
3111 DDI_TRAINING_OVERRIDE_VALUE;
3113 intel_de_write(dev_priv, reg, val);
3114 intel_de_posting_read(dev_priv, reg);
3119 val &= ~(DDIE_TRAINING_OVERRIDE_ENABLE |
3120 DDIE_TRAINING_OVERRIDE_VALUE);
3122 val &= ~(DDI_TRAINING_OVERRIDE_ENABLE |
3123 DDI_TRAINING_OVERRIDE_VALUE);
3125 intel_de_write(dev_priv, reg, val);
3128 intel_ddi_power_up_lanes(encoder, crtc_state);
3130 /* In HDMI/DVI mode, the port width, and swing/emphasis values
3131 * are ignored so nothing special needs to be done besides
3132 * enabling the port.
3134 * On ADL_P the PHY link rate and lane count must be programmed but
3135 * these are both 0 for HDMI.
3137 intel_de_write(dev_priv, DDI_BUF_CTL(port),
3138 dig_port->saved_port_bits | DDI_BUF_CTL_ENABLE);
3140 if (crtc_state->has_audio)
3141 intel_audio_codec_enable(encoder, crtc_state, conn_state);
3144 static void intel_enable_ddi(struct intel_atomic_state *state,
3145 struct intel_encoder *encoder,
3146 const struct intel_crtc_state *crtc_state,
3147 const struct drm_connector_state *conn_state)
3149 drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder);
3151 if (!crtc_state->bigjoiner_slave)
3152 intel_ddi_enable_transcoder_func(encoder, crtc_state);
3154 intel_vrr_enable(encoder, crtc_state);
3156 intel_enable_transcoder(crtc_state);
3158 intel_crtc_vblank_on(crtc_state);
3160 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
3161 intel_enable_ddi_hdmi(state, encoder, crtc_state, conn_state);
3163 intel_enable_ddi_dp(state, encoder, crtc_state, conn_state);
3165 /* Enable hdcp if it's desired */
3166 if (conn_state->content_protection ==
3167 DRM_MODE_CONTENT_PROTECTION_DESIRED)
3168 intel_hdcp_enable(to_intel_connector(conn_state->connector),
3170 (u8)conn_state->hdcp_content_type);
3173 static void intel_disable_ddi_dp(struct intel_atomic_state *state,
3174 struct intel_encoder *encoder,
3175 const struct intel_crtc_state *old_crtc_state,
3176 const struct drm_connector_state *old_conn_state)
3178 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3180 intel_dp->link_trained = false;
3182 intel_edp_backlight_off(old_conn_state);
3183 /* Disable the decompression in DP Sink */
3184 intel_dp_sink_set_decompression_state(intel_dp, old_crtc_state,
3186 /* Disable Ignore_MSA bit in DP Sink */
3187 intel_dp_sink_set_msa_timing_par_ignore_state(intel_dp, old_crtc_state,
3191 static void intel_disable_ddi_hdmi(struct intel_atomic_state *state,
3192 struct intel_encoder *encoder,
3193 const struct intel_crtc_state *old_crtc_state,
3194 const struct drm_connector_state *old_conn_state)
3196 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3197 struct drm_connector *connector = old_conn_state->connector;
3199 if (!intel_hdmi_handle_sink_scrambling(encoder, connector,
3201 drm_dbg_kms(&i915->drm,
3202 "[CONNECTOR:%d:%s] Failed to reset sink scrambling/TMDS bit clock ratio\n",
3203 connector->base.id, connector->name);
3206 static void intel_pre_disable_ddi(struct intel_atomic_state *state,
3207 struct intel_encoder *encoder,
3208 const struct intel_crtc_state *old_crtc_state,
3209 const struct drm_connector_state *old_conn_state)
3211 struct intel_dp *intel_dp;
3213 if (old_crtc_state->has_audio)
3214 intel_audio_codec_disable(encoder, old_crtc_state,
3217 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
3220 intel_dp = enc_to_intel_dp(encoder);
3221 intel_drrs_disable(intel_dp, old_crtc_state);
3222 intel_psr_disable(intel_dp, old_crtc_state);
3225 static void intel_disable_ddi(struct intel_atomic_state *state,
3226 struct intel_encoder *encoder,
3227 const struct intel_crtc_state *old_crtc_state,
3228 const struct drm_connector_state *old_conn_state)
3230 intel_hdcp_disable(to_intel_connector(old_conn_state->connector));
3232 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
3233 intel_disable_ddi_hdmi(state, encoder, old_crtc_state,
3236 intel_disable_ddi_dp(state, encoder, old_crtc_state,
3240 static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
3241 struct intel_encoder *encoder,
3242 const struct intel_crtc_state *crtc_state,
3243 const struct drm_connector_state *conn_state)
3245 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3247 intel_ddi_set_dp_msa(crtc_state, conn_state);
3249 intel_psr_update(intel_dp, crtc_state, conn_state);
3250 intel_dp_set_infoframes(encoder, true, crtc_state, conn_state);
3251 intel_drrs_update(intel_dp, crtc_state);
3253 intel_backlight_update(state, encoder, crtc_state, conn_state);
3256 void intel_ddi_update_pipe(struct intel_atomic_state *state,
3257 struct intel_encoder *encoder,
3258 const struct intel_crtc_state *crtc_state,
3259 const struct drm_connector_state *conn_state)
3262 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) &&
3263 !intel_encoder_is_mst(encoder))
3264 intel_ddi_update_pipe_dp(state, encoder, crtc_state,
3267 intel_hdcp_update_pipe(state, encoder, crtc_state, conn_state);
3271 intel_ddi_update_prepare(struct intel_atomic_state *state,
3272 struct intel_encoder *encoder,
3273 struct intel_crtc *crtc)
3275 struct intel_crtc_state *crtc_state =
3276 crtc ? intel_atomic_get_new_crtc_state(state, crtc) : NULL;
3277 int required_lanes = crtc_state ? crtc_state->lane_count : 1;
3279 drm_WARN_ON(state->base.dev, crtc && crtc->active);
3281 intel_tc_port_get_link(enc_to_dig_port(encoder),
3283 if (crtc_state && crtc_state->hw.active)
3284 intel_update_active_dpll(state, crtc, encoder);
3288 intel_ddi_update_complete(struct intel_atomic_state *state,
3289 struct intel_encoder *encoder,
3290 struct intel_crtc *crtc)
3292 intel_tc_port_put_link(enc_to_dig_port(encoder));
3296 intel_ddi_pre_pll_enable(struct intel_atomic_state *state,
3297 struct intel_encoder *encoder,
3298 const struct intel_crtc_state *crtc_state,
3299 const struct drm_connector_state *conn_state)
3301 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3302 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3303 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
3304 bool is_tc_port = intel_phy_is_tc(dev_priv, phy);
3307 intel_tc_port_get_link(dig_port, crtc_state->lane_count);
3309 if (intel_crtc_has_dp_encoder(crtc_state) || is_tc_port) {
3310 drm_WARN_ON(&dev_priv->drm, dig_port->aux_wakeref);
3311 dig_port->aux_wakeref =
3312 intel_display_power_get(dev_priv,
3313 intel_ddi_main_link_aux_domain(dig_port));
3316 if (is_tc_port && dig_port->tc_mode != TC_PORT_TBT_ALT)
3318 * Program the lane count for static/dynamic connections on
3319 * Type-C ports. Skip this step for TBT.
3321 intel_tc_port_set_fia_lane_count(dig_port, crtc_state->lane_count);
3322 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3323 bxt_ddi_phy_set_lane_optim_mask(encoder,
3324 crtc_state->lane_lat_optim_mask);
3327 static void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp,
3328 const struct intel_crtc_state *crtc_state)
3330 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3331 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3332 enum port port = encoder->port;
3333 u32 dp_tp_ctl, ddi_buf_ctl;
3336 dp_tp_ctl = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3338 if (dp_tp_ctl & DP_TP_CTL_ENABLE) {
3339 ddi_buf_ctl = intel_de_read(dev_priv, DDI_BUF_CTL(port));
3340 if (ddi_buf_ctl & DDI_BUF_CTL_ENABLE) {
3341 intel_de_write(dev_priv, DDI_BUF_CTL(port),
3342 ddi_buf_ctl & ~DDI_BUF_CTL_ENABLE);
3346 dp_tp_ctl &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
3347 dp_tp_ctl |= DP_TP_CTL_LINK_TRAIN_PAT1;
3348 intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), dp_tp_ctl);
3349 intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3352 intel_wait_ddi_buf_idle(dev_priv, port);
3355 dp_tp_ctl = DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_PAT1;
3356 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
3357 dp_tp_ctl |= DP_TP_CTL_MODE_MST;
3359 dp_tp_ctl |= DP_TP_CTL_MODE_SST;
3360 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
3361 dp_tp_ctl |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
3363 intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), dp_tp_ctl);
3364 intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3366 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
3367 intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP);
3368 intel_de_posting_read(dev_priv, DDI_BUF_CTL(port));
3370 intel_wait_ddi_buf_active(dev_priv, port);
3373 static void intel_ddi_set_link_train(struct intel_dp *intel_dp,
3374 const struct intel_crtc_state *crtc_state,
3377 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3378 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3381 temp = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3383 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3384 switch (intel_dp_training_pattern_symbol(dp_train_pat)) {
3385 case DP_TRAINING_PATTERN_DISABLE:
3386 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
3388 case DP_TRAINING_PATTERN_1:
3389 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
3391 case DP_TRAINING_PATTERN_2:
3392 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
3394 case DP_TRAINING_PATTERN_3:
3395 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
3397 case DP_TRAINING_PATTERN_4:
3398 temp |= DP_TP_CTL_LINK_TRAIN_PAT4;
3402 intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), temp);
3405 static void intel_ddi_set_idle_link_train(struct intel_dp *intel_dp,
3406 const struct intel_crtc_state *crtc_state)
3408 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3409 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3410 enum port port = encoder->port;
3413 val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3414 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3415 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3416 intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
3419 * Until TGL on PORT_A we can have only eDP in SST mode. There the only
3420 * reason we need to set idle transmission mode is to work around a HW
3421 * issue where we enable the pipe while not in idle link-training mode.
3422 * In this case there is requirement to wait for a minimum number of
3423 * idle patterns to be sent.
3425 if (port == PORT_A && DISPLAY_VER(dev_priv) < 12)
3428 if (intel_de_wait_for_set(dev_priv,
3429 dp_tp_status_reg(encoder, crtc_state),
3430 DP_TP_STATUS_IDLE_DONE, 1))
3431 drm_err(&dev_priv->drm,
3432 "Timed out waiting for DP idle patterns\n");
3435 static bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
3436 enum transcoder cpu_transcoder)
3438 if (cpu_transcoder == TRANSCODER_EDP)
3441 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO_MMIO))
3444 return intel_de_read(dev_priv, HSW_AUD_PIN_ELD_CP_VLD) &
3445 AUDIO_OUTPUT_ENABLE(cpu_transcoder);
3448 void intel_ddi_compute_min_voltage_level(struct drm_i915_private *dev_priv,
3449 struct intel_crtc_state *crtc_state)
3451 if (DISPLAY_VER(dev_priv) >= 12 && crtc_state->port_clock > 594000)
3452 crtc_state->min_voltage_level = 2;
3453 else if (IS_JSL_EHL(dev_priv) && crtc_state->port_clock > 594000)
3454 crtc_state->min_voltage_level = 3;
3455 else if (DISPLAY_VER(dev_priv) >= 11 && crtc_state->port_clock > 594000)
3456 crtc_state->min_voltage_level = 1;
3459 static enum transcoder bdw_transcoder_master_readout(struct drm_i915_private *dev_priv,
3460 enum transcoder cpu_transcoder)
3464 if (DISPLAY_VER(dev_priv) >= 11) {
3465 u32 ctl2 = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL2(cpu_transcoder));
3467 if ((ctl2 & PORT_SYNC_MODE_ENABLE) == 0)
3468 return INVALID_TRANSCODER;
3470 master_select = REG_FIELD_GET(PORT_SYNC_MODE_MASTER_SELECT_MASK, ctl2);
3472 u32 ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3474 if ((ctl & TRANS_DDI_PORT_SYNC_ENABLE) == 0)
3475 return INVALID_TRANSCODER;
3477 master_select = REG_FIELD_GET(TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK, ctl);
3480 if (master_select == 0)
3481 return TRANSCODER_EDP;
3483 return master_select - 1;
3486 static void bdw_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
3488 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3489 u32 transcoders = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
3490 BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
3491 enum transcoder cpu_transcoder;
3493 crtc_state->master_transcoder =
3494 bdw_transcoder_master_readout(dev_priv, crtc_state->cpu_transcoder);
3496 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) {
3497 enum intel_display_power_domain power_domain;
3498 intel_wakeref_t trans_wakeref;
3500 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3501 trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
3507 if (bdw_transcoder_master_readout(dev_priv, cpu_transcoder) ==
3508 crtc_state->cpu_transcoder)
3509 crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder);
3511 intel_display_power_put(dev_priv, power_domain, trans_wakeref);
3514 drm_WARN_ON(&dev_priv->drm,
3515 crtc_state->master_transcoder != INVALID_TRANSCODER &&
3516 crtc_state->sync_mode_slaves_mask);
3519 static void intel_ddi_read_func_ctl(struct intel_encoder *encoder,
3520 struct intel_crtc_state *pipe_config)
3522 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3523 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
3524 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
3525 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3526 u32 temp, flags = 0;
3528 temp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3529 if (temp & TRANS_DDI_PHSYNC)
3530 flags |= DRM_MODE_FLAG_PHSYNC;
3532 flags |= DRM_MODE_FLAG_NHSYNC;
3533 if (temp & TRANS_DDI_PVSYNC)
3534 flags |= DRM_MODE_FLAG_PVSYNC;
3536 flags |= DRM_MODE_FLAG_NVSYNC;
3538 pipe_config->hw.adjusted_mode.flags |= flags;
3540 switch (temp & TRANS_DDI_BPC_MASK) {
3541 case TRANS_DDI_BPC_6:
3542 pipe_config->pipe_bpp = 18;
3544 case TRANS_DDI_BPC_8:
3545 pipe_config->pipe_bpp = 24;
3547 case TRANS_DDI_BPC_10:
3548 pipe_config->pipe_bpp = 30;
3550 case TRANS_DDI_BPC_12:
3551 pipe_config->pipe_bpp = 36;
3557 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
3558 case TRANS_DDI_MODE_SELECT_HDMI:
3559 pipe_config->has_hdmi_sink = true;
3561 pipe_config->infoframes.enable |=
3562 intel_hdmi_infoframes_enabled(encoder, pipe_config);
3564 if (pipe_config->infoframes.enable)
3565 pipe_config->has_infoframe = true;
3567 if (temp & TRANS_DDI_HDMI_SCRAMBLING)
3568 pipe_config->hdmi_scrambling = true;
3569 if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
3570 pipe_config->hdmi_high_tmds_clock_ratio = true;
3572 case TRANS_DDI_MODE_SELECT_DVI:
3573 pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI);
3574 pipe_config->lane_count = 4;
3576 case TRANS_DDI_MODE_SELECT_FDI_OR_128B132B:
3577 pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG);
3579 case TRANS_DDI_MODE_SELECT_DP_SST:
3580 if (encoder->type == INTEL_OUTPUT_EDP)
3581 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
3583 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
3584 pipe_config->lane_count =
3585 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
3586 intel_dp_get_m_n(crtc, pipe_config);
3588 if (DISPLAY_VER(dev_priv) >= 11) {
3589 i915_reg_t dp_tp_ctl = dp_tp_ctl_reg(encoder, pipe_config);
3591 pipe_config->fec_enable =
3592 intel_de_read(dev_priv, dp_tp_ctl) & DP_TP_CTL_FEC_ENABLE;
3594 drm_dbg_kms(&dev_priv->drm,
3595 "[ENCODER:%d:%s] Fec status: %u\n",
3596 encoder->base.base.id, encoder->base.name,
3597 pipe_config->fec_enable);
3600 if (dig_port->lspcon.active && dig_port->dp.has_hdmi_sink)
3601 pipe_config->infoframes.enable |=
3602 intel_lspcon_infoframes_enabled(encoder, pipe_config);
3604 pipe_config->infoframes.enable |=
3605 intel_hdmi_infoframes_enabled(encoder, pipe_config);
3607 case TRANS_DDI_MODE_SELECT_DP_MST:
3608 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST);
3609 pipe_config->lane_count =
3610 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
3612 if (DISPLAY_VER(dev_priv) >= 12)
3613 pipe_config->mst_master_transcoder =
3614 REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK, temp);
3616 intel_dp_get_m_n(crtc, pipe_config);
3618 pipe_config->infoframes.enable |=
3619 intel_hdmi_infoframes_enabled(encoder, pipe_config);
3626 static void intel_ddi_get_config(struct intel_encoder *encoder,
3627 struct intel_crtc_state *pipe_config)
3629 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3630 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
3632 /* XXX: DSI transcoder paranoia */
3633 if (drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder)))
3636 if (pipe_config->bigjoiner_slave) {
3637 /* read out pipe settings from master */
3638 enum transcoder save = pipe_config->cpu_transcoder;
3640 /* Our own transcoder needs to be disabled when reading it in intel_ddi_read_func_ctl() */
3641 WARN_ON(pipe_config->output_types);
3642 pipe_config->cpu_transcoder = (enum transcoder)pipe_config->bigjoiner_linked_crtc->pipe;
3643 intel_ddi_read_func_ctl(encoder, pipe_config);
3644 pipe_config->cpu_transcoder = save;
3646 intel_ddi_read_func_ctl(encoder, pipe_config);
3649 intel_ddi_mso_get_config(encoder, pipe_config);
3651 pipe_config->has_audio =
3652 intel_ddi_is_audio_enabled(dev_priv, cpu_transcoder);
3654 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
3655 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
3657 * This is a big fat ugly hack.
3659 * Some machines in UEFI boot mode provide us a VBT that has 18
3660 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
3661 * unknown we fail to light up. Yet the same BIOS boots up with
3662 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
3663 * max, not what it tells us to use.
3665 * Note: This will still be broken if the eDP panel is not lit
3666 * up by the BIOS, and thus we can't get the mode at module
3669 drm_dbg_kms(&dev_priv->drm,
3670 "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
3671 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
3672 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
3675 if (!pipe_config->bigjoiner_slave)
3676 ddi_dotclock_get(pipe_config);
3678 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3679 pipe_config->lane_lat_optim_mask =
3680 bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
3682 intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
3684 intel_hdmi_read_gcp_infoframe(encoder, pipe_config);
3686 intel_read_infoframe(encoder, pipe_config,
3687 HDMI_INFOFRAME_TYPE_AVI,
3688 &pipe_config->infoframes.avi);
3689 intel_read_infoframe(encoder, pipe_config,
3690 HDMI_INFOFRAME_TYPE_SPD,
3691 &pipe_config->infoframes.spd);
3692 intel_read_infoframe(encoder, pipe_config,
3693 HDMI_INFOFRAME_TYPE_VENDOR,
3694 &pipe_config->infoframes.hdmi);
3695 intel_read_infoframe(encoder, pipe_config,
3696 HDMI_INFOFRAME_TYPE_DRM,
3697 &pipe_config->infoframes.drm);
3699 if (DISPLAY_VER(dev_priv) >= 8)
3700 bdw_get_trans_port_sync_config(pipe_config);
3702 intel_read_dp_sdp(encoder, pipe_config, HDMI_PACKET_TYPE_GAMUT_METADATA);
3703 intel_read_dp_sdp(encoder, pipe_config, DP_SDP_VSC);
3705 intel_psr_get_config(encoder, pipe_config);
3708 void intel_ddi_get_clock(struct intel_encoder *encoder,
3709 struct intel_crtc_state *crtc_state,
3710 struct intel_shared_dpll *pll)
3712 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3713 enum icl_port_dpll_id port_dpll_id = ICL_PORT_DPLL_DEFAULT;
3714 struct icl_port_dpll *port_dpll = &crtc_state->icl_port_dplls[port_dpll_id];
3717 if (drm_WARN_ON(&i915->drm, !pll))
3720 port_dpll->pll = pll;
3721 pll_active = intel_dpll_get_hw_state(i915, pll, &port_dpll->hw_state);
3722 drm_WARN_ON(&i915->drm, !pll_active);
3724 icl_set_active_port_dpll(crtc_state, port_dpll_id);
3726 crtc_state->port_clock = intel_dpll_get_freq(i915, crtc_state->shared_dpll,
3727 &crtc_state->dpll_hw_state);
3730 static void dg2_ddi_get_config(struct intel_encoder *encoder,
3731 struct intel_crtc_state *crtc_state)
3733 intel_mpllb_readout_hw_state(encoder, &crtc_state->mpllb_state);
3734 crtc_state->port_clock = intel_mpllb_calc_port_clock(encoder, &crtc_state->mpllb_state);
3736 intel_ddi_get_config(encoder, crtc_state);
3739 static void adls_ddi_get_config(struct intel_encoder *encoder,
3740 struct intel_crtc_state *crtc_state)
3742 intel_ddi_get_clock(encoder, crtc_state, adls_ddi_get_pll(encoder));
3743 intel_ddi_get_config(encoder, crtc_state);
3746 static void rkl_ddi_get_config(struct intel_encoder *encoder,
3747 struct intel_crtc_state *crtc_state)
3749 intel_ddi_get_clock(encoder, crtc_state, rkl_ddi_get_pll(encoder));
3750 intel_ddi_get_config(encoder, crtc_state);
3753 static void dg1_ddi_get_config(struct intel_encoder *encoder,
3754 struct intel_crtc_state *crtc_state)
3756 intel_ddi_get_clock(encoder, crtc_state, dg1_ddi_get_pll(encoder));
3757 intel_ddi_get_config(encoder, crtc_state);
3760 static void icl_ddi_combo_get_config(struct intel_encoder *encoder,
3761 struct intel_crtc_state *crtc_state)
3763 intel_ddi_get_clock(encoder, crtc_state, icl_ddi_combo_get_pll(encoder));
3764 intel_ddi_get_config(encoder, crtc_state);
3767 static void icl_ddi_tc_get_clock(struct intel_encoder *encoder,
3768 struct intel_crtc_state *crtc_state,
3769 struct intel_shared_dpll *pll)
3771 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3772 enum icl_port_dpll_id port_dpll_id;
3773 struct icl_port_dpll *port_dpll;
3776 if (drm_WARN_ON(&i915->drm, !pll))
3779 if (intel_get_shared_dpll_id(i915, pll) == DPLL_ID_ICL_TBTPLL)
3780 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
3782 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
3784 port_dpll = &crtc_state->icl_port_dplls[port_dpll_id];
3786 port_dpll->pll = pll;
3787 pll_active = intel_dpll_get_hw_state(i915, pll, &port_dpll->hw_state);
3788 drm_WARN_ON(&i915->drm, !pll_active);
3790 icl_set_active_port_dpll(crtc_state, port_dpll_id);
3792 if (intel_get_shared_dpll_id(i915, crtc_state->shared_dpll) == DPLL_ID_ICL_TBTPLL)
3793 crtc_state->port_clock = icl_calc_tbt_pll_link(i915, encoder->port);
3795 crtc_state->port_clock = intel_dpll_get_freq(i915, crtc_state->shared_dpll,
3796 &crtc_state->dpll_hw_state);
3799 static void icl_ddi_tc_get_config(struct intel_encoder *encoder,
3800 struct intel_crtc_state *crtc_state)
3802 icl_ddi_tc_get_clock(encoder, crtc_state, icl_ddi_tc_get_pll(encoder));
3803 intel_ddi_get_config(encoder, crtc_state);
3806 static void bxt_ddi_get_config(struct intel_encoder *encoder,
3807 struct intel_crtc_state *crtc_state)
3809 intel_ddi_get_clock(encoder, crtc_state, bxt_ddi_get_pll(encoder));
3810 intel_ddi_get_config(encoder, crtc_state);
3813 static void skl_ddi_get_config(struct intel_encoder *encoder,
3814 struct intel_crtc_state *crtc_state)
3816 intel_ddi_get_clock(encoder, crtc_state, skl_ddi_get_pll(encoder));
3817 intel_ddi_get_config(encoder, crtc_state);
3820 void hsw_ddi_get_config(struct intel_encoder *encoder,
3821 struct intel_crtc_state *crtc_state)
3823 intel_ddi_get_clock(encoder, crtc_state, hsw_ddi_get_pll(encoder));
3824 intel_ddi_get_config(encoder, crtc_state);
3827 static void intel_ddi_sync_state(struct intel_encoder *encoder,
3828 const struct intel_crtc_state *crtc_state)
3830 if (intel_crtc_has_dp_encoder(crtc_state))
3831 intel_dp_sync_state(encoder, crtc_state);
3834 static bool intel_ddi_initial_fastset_check(struct intel_encoder *encoder,
3835 struct intel_crtc_state *crtc_state)
3837 if (intel_crtc_has_dp_encoder(crtc_state))
3838 return intel_dp_initial_fastset_check(encoder, crtc_state);
3843 static enum intel_output_type
3844 intel_ddi_compute_output_type(struct intel_encoder *encoder,
3845 struct intel_crtc_state *crtc_state,
3846 struct drm_connector_state *conn_state)
3848 switch (conn_state->connector->connector_type) {
3849 case DRM_MODE_CONNECTOR_HDMIA:
3850 return INTEL_OUTPUT_HDMI;
3851 case DRM_MODE_CONNECTOR_eDP:
3852 return INTEL_OUTPUT_EDP;
3853 case DRM_MODE_CONNECTOR_DisplayPort:
3854 return INTEL_OUTPUT_DP;
3856 MISSING_CASE(conn_state->connector->connector_type);
3857 return INTEL_OUTPUT_UNUSED;
3861 static int intel_ddi_compute_config(struct intel_encoder *encoder,
3862 struct intel_crtc_state *pipe_config,
3863 struct drm_connector_state *conn_state)
3865 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
3866 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3867 enum port port = encoder->port;
3870 if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A)
3871 pipe_config->cpu_transcoder = TRANSCODER_EDP;
3873 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) {
3874 ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
3876 ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
3882 if (IS_HASWELL(dev_priv) && crtc->pipe == PIPE_A &&
3883 pipe_config->cpu_transcoder == TRANSCODER_EDP)
3884 pipe_config->pch_pfit.force_thru =
3885 pipe_config->pch_pfit.enabled ||
3886 pipe_config->crc_enabled;
3888 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3889 pipe_config->lane_lat_optim_mask =
3890 bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count);
3892 intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
3897 static bool mode_equal(const struct drm_display_mode *mode1,
3898 const struct drm_display_mode *mode2)
3900 return drm_mode_match(mode1, mode2,
3901 DRM_MODE_MATCH_TIMINGS |
3902 DRM_MODE_MATCH_FLAGS |
3903 DRM_MODE_MATCH_3D_FLAGS) &&
3904 mode1->clock == mode2->clock; /* we want an exact match */
3907 static bool m_n_equal(const struct intel_link_m_n *m_n_1,
3908 const struct intel_link_m_n *m_n_2)
3910 return m_n_1->tu == m_n_2->tu &&
3911 m_n_1->gmch_m == m_n_2->gmch_m &&
3912 m_n_1->gmch_n == m_n_2->gmch_n &&
3913 m_n_1->link_m == m_n_2->link_m &&
3914 m_n_1->link_n == m_n_2->link_n;
3917 static bool crtcs_port_sync_compatible(const struct intel_crtc_state *crtc_state1,
3918 const struct intel_crtc_state *crtc_state2)
3920 return crtc_state1->hw.active && crtc_state2->hw.active &&
3921 crtc_state1->output_types == crtc_state2->output_types &&
3922 crtc_state1->output_format == crtc_state2->output_format &&
3923 crtc_state1->lane_count == crtc_state2->lane_count &&
3924 crtc_state1->port_clock == crtc_state2->port_clock &&
3925 mode_equal(&crtc_state1->hw.adjusted_mode,
3926 &crtc_state2->hw.adjusted_mode) &&
3927 m_n_equal(&crtc_state1->dp_m_n, &crtc_state2->dp_m_n);
3931 intel_ddi_port_sync_transcoders(const struct intel_crtc_state *ref_crtc_state,
3934 struct drm_connector *connector;
3935 const struct drm_connector_state *conn_state;
3936 struct drm_i915_private *dev_priv = to_i915(ref_crtc_state->uapi.crtc->dev);
3937 struct intel_atomic_state *state =
3938 to_intel_atomic_state(ref_crtc_state->uapi.state);
3943 * We don't enable port sync on BDW due to missing w/as and
3944 * due to not having adjusted the modeset sequence appropriately.
3946 if (DISPLAY_VER(dev_priv) < 9)
3949 if (!intel_crtc_has_type(ref_crtc_state, INTEL_OUTPUT_DP))
3952 for_each_new_connector_in_state(&state->base, connector, conn_state, i) {
3953 struct intel_crtc *crtc = to_intel_crtc(conn_state->crtc);
3954 const struct intel_crtc_state *crtc_state;
3959 if (!connector->has_tile ||
3960 connector->tile_group->id !=
3963 crtc_state = intel_atomic_get_new_crtc_state(state,
3965 if (!crtcs_port_sync_compatible(ref_crtc_state,
3968 transcoders |= BIT(crtc_state->cpu_transcoder);
3974 static int intel_ddi_compute_config_late(struct intel_encoder *encoder,
3975 struct intel_crtc_state *crtc_state,
3976 struct drm_connector_state *conn_state)
3978 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3979 struct drm_connector *connector = conn_state->connector;
3980 u8 port_sync_transcoders = 0;
3982 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] [CRTC:%d:%s]",
3983 encoder->base.base.id, encoder->base.name,
3984 crtc_state->uapi.crtc->base.id, crtc_state->uapi.crtc->name);
3986 if (connector->has_tile)
3987 port_sync_transcoders = intel_ddi_port_sync_transcoders(crtc_state,
3988 connector->tile_group->id);
3991 * EDP Transcoders cannot be ensalved
3992 * make them a master always when present
3994 if (port_sync_transcoders & BIT(TRANSCODER_EDP))
3995 crtc_state->master_transcoder = TRANSCODER_EDP;
3997 crtc_state->master_transcoder = ffs(port_sync_transcoders) - 1;
3999 if (crtc_state->master_transcoder == crtc_state->cpu_transcoder) {
4000 crtc_state->master_transcoder = INVALID_TRANSCODER;
4001 crtc_state->sync_mode_slaves_mask =
4002 port_sync_transcoders & ~BIT(crtc_state->cpu_transcoder);
4008 static void intel_ddi_encoder_destroy(struct drm_encoder *encoder)
4010 struct drm_i915_private *i915 = to_i915(encoder->dev);
4011 struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder));
4013 intel_dp_encoder_flush_work(encoder);
4014 intel_display_power_flush_work(i915);
4016 drm_encoder_cleanup(encoder);
4018 kfree(dig_port->hdcp_port_data.streams);
4022 static void intel_ddi_encoder_reset(struct drm_encoder *encoder)
4024 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(encoder));
4026 intel_dp->reset_link_params = true;
4028 intel_pps_encoder_reset(intel_dp);
4031 static const struct drm_encoder_funcs intel_ddi_funcs = {
4032 .reset = intel_ddi_encoder_reset,
4033 .destroy = intel_ddi_encoder_destroy,
4036 static struct intel_connector *
4037 intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
4039 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
4040 struct intel_connector *connector;
4041 enum port port = dig_port->base.port;
4043 connector = intel_connector_alloc();
4047 dig_port->dp.output_reg = DDI_BUF_CTL(port);
4048 dig_port->dp.prepare_link_retrain = intel_ddi_prepare_link_retrain;
4049 dig_port->dp.set_link_train = intel_ddi_set_link_train;
4050 dig_port->dp.set_idle_link_train = intel_ddi_set_idle_link_train;
4052 if (IS_DG2(dev_priv))
4053 dig_port->dp.set_signal_levels = dg2_set_signal_levels;
4054 else if (DISPLAY_VER(dev_priv) >= 12)
4055 dig_port->dp.set_signal_levels = tgl_set_signal_levels;
4056 else if (DISPLAY_VER(dev_priv) >= 11)
4057 dig_port->dp.set_signal_levels = icl_set_signal_levels;
4058 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
4059 dig_port->dp.set_signal_levels = bxt_set_signal_levels;
4061 dig_port->dp.set_signal_levels = hsw_set_signal_levels;
4063 dig_port->dp.voltage_max = intel_ddi_dp_voltage_max;
4064 dig_port->dp.preemph_max = intel_ddi_dp_preemph_max;
4066 if (!intel_dp_init_connector(dig_port, connector)) {
4074 static int modeset_pipe(struct drm_crtc *crtc,
4075 struct drm_modeset_acquire_ctx *ctx)
4077 struct drm_atomic_state *state;
4078 struct drm_crtc_state *crtc_state;
4081 state = drm_atomic_state_alloc(crtc->dev);
4085 state->acquire_ctx = ctx;
4087 crtc_state = drm_atomic_get_crtc_state(state, crtc);
4088 if (IS_ERR(crtc_state)) {
4089 ret = PTR_ERR(crtc_state);
4093 crtc_state->connectors_changed = true;
4095 ret = drm_atomic_commit(state);
4097 drm_atomic_state_put(state);
4102 static int intel_hdmi_reset_link(struct intel_encoder *encoder,
4103 struct drm_modeset_acquire_ctx *ctx)
4105 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4106 struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder);
4107 struct intel_connector *connector = hdmi->attached_connector;
4108 struct i2c_adapter *adapter =
4109 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
4110 struct drm_connector_state *conn_state;
4111 struct intel_crtc_state *crtc_state;
4112 struct intel_crtc *crtc;
4116 if (!connector || connector->base.status != connector_status_connected)
4119 ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex,
4124 conn_state = connector->base.state;
4126 crtc = to_intel_crtc(conn_state->crtc);
4130 ret = drm_modeset_lock(&crtc->base.mutex, ctx);
4134 crtc_state = to_intel_crtc_state(crtc->base.state);
4136 drm_WARN_ON(&dev_priv->drm,
4137 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI));
4139 if (!crtc_state->hw.active)
4142 if (!crtc_state->hdmi_high_tmds_clock_ratio &&
4143 !crtc_state->hdmi_scrambling)
4146 if (conn_state->commit &&
4147 !try_wait_for_completion(&conn_state->commit->hw_done))
4150 ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config);
4152 drm_err(&dev_priv->drm, "Failed to read TMDS config: %d\n",
4157 if (!!(config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) ==
4158 crtc_state->hdmi_high_tmds_clock_ratio &&
4159 !!(config & SCDC_SCRAMBLING_ENABLE) ==
4160 crtc_state->hdmi_scrambling)
4164 * HDMI 2.0 says that one should not send scrambled data
4165 * prior to configuring the sink scrambling, and that
4166 * TMDS clock/data transmission should be suspended when
4167 * changing the TMDS clock rate in the sink. So let's
4168 * just do a full modeset here, even though some sinks
4169 * would be perfectly happy if were to just reconfigure
4170 * the SCDC settings on the fly.
4172 return modeset_pipe(&crtc->base, ctx);
4175 static enum intel_hotplug_state
4176 intel_ddi_hotplug(struct intel_encoder *encoder,
4177 struct intel_connector *connector)
4179 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
4180 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
4181 struct intel_dp *intel_dp = &dig_port->dp;
4182 enum phy phy = intel_port_to_phy(i915, encoder->port);
4183 bool is_tc = intel_phy_is_tc(i915, phy);
4184 struct drm_modeset_acquire_ctx ctx;
4185 enum intel_hotplug_state state;
4188 if (intel_dp->compliance.test_active &&
4189 intel_dp->compliance.test_type == DP_TEST_LINK_PHY_TEST_PATTERN) {
4190 intel_dp_phy_test(encoder);
4191 /* just do the PHY test and nothing else */
4192 return INTEL_HOTPLUG_UNCHANGED;
4195 state = intel_encoder_hotplug(encoder, connector);
4197 drm_modeset_acquire_init(&ctx, 0);
4200 if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA)
4201 ret = intel_hdmi_reset_link(encoder, &ctx);
4203 ret = intel_dp_retrain_link(encoder, &ctx);
4205 if (ret == -EDEADLK) {
4206 drm_modeset_backoff(&ctx);
4213 drm_modeset_drop_locks(&ctx);
4214 drm_modeset_acquire_fini(&ctx);
4215 drm_WARN(encoder->base.dev, ret,
4216 "Acquiring modeset locks failed with %i\n", ret);
4219 * Unpowered type-c dongles can take some time to boot and be
4220 * responsible, so here giving some time to those dongles to power up
4221 * and then retrying the probe.
4223 * On many platforms the HDMI live state signal is known to be
4224 * unreliable, so we can't use it to detect if a sink is connected or
4225 * not. Instead we detect if it's connected based on whether we can
4226 * read the EDID or not. That in turn has a problem during disconnect,
4227 * since the HPD interrupt may be raised before the DDC lines get
4228 * disconnected (due to how the required length of DDC vs. HPD
4229 * connector pins are specified) and so we'll still be able to get a
4230 * valid EDID. To solve this schedule another detection cycle if this
4231 * time around we didn't detect any change in the sink's connection
4234 * Type-c connectors which get their HPD signal deasserted then
4235 * reasserted, without unplugging/replugging the sink from the
4236 * connector, introduce a delay until the AUX channel communication
4237 * becomes functional. Retry the detection for 5 seconds on type-c
4238 * connectors to account for this delay.
4240 if (state == INTEL_HOTPLUG_UNCHANGED &&
4241 connector->hotplug_retries < (is_tc ? 5 : 1) &&
4242 !dig_port->dp.is_mst)
4243 state = INTEL_HOTPLUG_RETRY;
4248 static bool lpt_digital_port_connected(struct intel_encoder *encoder)
4250 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4251 u32 bit = dev_priv->hotplug.pch_hpd[encoder->hpd_pin];
4253 return intel_de_read(dev_priv, SDEISR) & bit;
4256 static bool hsw_digital_port_connected(struct intel_encoder *encoder)
4258 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4259 u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin];
4261 return intel_de_read(dev_priv, DEISR) & bit;
4264 static bool bdw_digital_port_connected(struct intel_encoder *encoder)
4266 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4267 u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin];
4269 return intel_de_read(dev_priv, GEN8_DE_PORT_ISR) & bit;
4272 static struct intel_connector *
4273 intel_ddi_init_hdmi_connector(struct intel_digital_port *dig_port)
4275 struct intel_connector *connector;
4276 enum port port = dig_port->base.port;
4278 connector = intel_connector_alloc();
4282 dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
4283 intel_hdmi_init_connector(dig_port, connector);
4288 static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dig_port)
4290 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
4292 if (dig_port->base.port != PORT_A)
4295 if (dig_port->saved_port_bits & DDI_A_4_LANES)
4298 /* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only
4299 * supported configuration
4301 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
4308 intel_ddi_max_lanes(struct intel_digital_port *dig_port)
4310 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
4311 enum port port = dig_port->base.port;
4314 if (DISPLAY_VER(dev_priv) >= 11)
4317 if (port == PORT_A || port == PORT_E) {
4318 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
4319 max_lanes = port == PORT_A ? 4 : 0;
4321 /* Both A and E share 2 lanes */
4326 * Some BIOS might fail to set this bit on port A if eDP
4327 * wasn't lit up at boot. Force this bit set when needed
4328 * so we use the proper lane count for our calculations.
4330 if (intel_ddi_a_force_4_lanes(dig_port)) {
4331 drm_dbg_kms(&dev_priv->drm,
4332 "Forcing DDI_A_4_LANES for port A\n");
4333 dig_port->saved_port_bits |= DDI_A_4_LANES;
4340 static bool hti_uses_phy(struct drm_i915_private *i915, enum phy phy)
4342 return i915->hti_state & HDPORT_ENABLED &&
4343 i915->hti_state & HDPORT_DDI_USED(phy);
4346 static enum hpd_pin xelpd_hpd_pin(struct drm_i915_private *dev_priv,
4349 if (port >= PORT_D_XELPD)
4350 return HPD_PORT_D + port - PORT_D_XELPD;
4351 else if (port >= PORT_TC1)
4352 return HPD_PORT_TC1 + port - PORT_TC1;
4354 return HPD_PORT_A + port - PORT_A;
4357 static enum hpd_pin dg1_hpd_pin(struct drm_i915_private *dev_priv,
4360 if (port >= PORT_TC1)
4361 return HPD_PORT_C + port - PORT_TC1;
4363 return HPD_PORT_A + port - PORT_A;
4366 static enum hpd_pin tgl_hpd_pin(struct drm_i915_private *dev_priv,
4369 if (port >= PORT_TC1)
4370 return HPD_PORT_TC1 + port - PORT_TC1;
4372 return HPD_PORT_A + port - PORT_A;
4375 static enum hpd_pin rkl_hpd_pin(struct drm_i915_private *dev_priv,
4378 if (HAS_PCH_TGP(dev_priv))
4379 return tgl_hpd_pin(dev_priv, port);
4381 if (port >= PORT_TC1)
4382 return HPD_PORT_C + port - PORT_TC1;
4384 return HPD_PORT_A + port - PORT_A;
4387 static enum hpd_pin icl_hpd_pin(struct drm_i915_private *dev_priv,
4391 return HPD_PORT_TC1 + port - PORT_C;
4393 return HPD_PORT_A + port - PORT_A;
4396 static enum hpd_pin ehl_hpd_pin(struct drm_i915_private *dev_priv,
4402 if (HAS_PCH_MCC(dev_priv))
4403 return icl_hpd_pin(dev_priv, port);
4405 return HPD_PORT_A + port - PORT_A;
4408 static enum hpd_pin skl_hpd_pin(struct drm_i915_private *dev_priv, enum port port)
4410 if (HAS_PCH_TGP(dev_priv))
4411 return icl_hpd_pin(dev_priv, port);
4413 return HPD_PORT_A + port - PORT_A;
4416 static bool intel_ddi_is_tc(struct drm_i915_private *i915, enum port port)
4418 if (DISPLAY_VER(i915) >= 12)
4419 return port >= PORT_TC1;
4420 else if (DISPLAY_VER(i915) >= 11)
4421 return port >= PORT_C;
4426 static void intel_ddi_encoder_suspend(struct intel_encoder *encoder)
4428 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4429 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
4430 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
4431 enum phy phy = intel_port_to_phy(i915, encoder->port);
4433 intel_dp_encoder_suspend(encoder);
4435 if (!intel_phy_is_tc(i915, phy))
4438 intel_tc_port_disconnect_phy(dig_port);
4441 static void intel_ddi_encoder_shutdown(struct intel_encoder *encoder)
4443 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4444 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
4445 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
4446 enum phy phy = intel_port_to_phy(i915, encoder->port);
4448 intel_dp_encoder_shutdown(encoder);
4450 if (!intel_phy_is_tc(i915, phy))
4453 intel_tc_port_disconnect_phy(dig_port);
4456 #define port_tc_name(port) ((port) - PORT_TC1 + '1')
4457 #define tc_port_name(tc_port) ((tc_port) - TC_PORT_1 + '1')
4459 void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
4461 struct intel_digital_port *dig_port;
4462 struct intel_encoder *encoder;
4463 const struct intel_bios_encoder_data *devdata;
4464 bool init_hdmi, init_dp;
4465 enum phy phy = intel_port_to_phy(dev_priv, port);
4468 * On platforms with HTI (aka HDPORT), if it's enabled at boot it may
4469 * have taken over some of the PHYs and made them unavailable to the
4470 * driver. In that case we should skip initializing the corresponding
4473 if (hti_uses_phy(dev_priv, phy)) {
4474 drm_dbg_kms(&dev_priv->drm, "PORT %c / PHY %c reserved by HTI\n",
4475 port_name(port), phy_name(phy));
4479 devdata = intel_bios_encoder_data_lookup(dev_priv, port);
4481 drm_dbg_kms(&dev_priv->drm,
4482 "VBT says port %c is not present\n",
4487 init_hdmi = intel_bios_encoder_supports_dvi(devdata) ||
4488 intel_bios_encoder_supports_hdmi(devdata);
4489 init_dp = intel_bios_encoder_supports_dp(devdata);
4491 if (intel_bios_is_lspcon_present(dev_priv, port)) {
4493 * Lspcon device needs to be driven with DP connector
4494 * with special detection sequence. So make sure DP
4495 * is initialized before lspcon.
4499 drm_dbg_kms(&dev_priv->drm, "VBT says port %c has lspcon\n",
4503 if (!init_dp && !init_hdmi) {
4504 drm_dbg_kms(&dev_priv->drm,
4505 "VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
4510 dig_port = kzalloc(sizeof(*dig_port), GFP_KERNEL);
4514 encoder = &dig_port->base;
4515 encoder->devdata = devdata;
4517 if (DISPLAY_VER(dev_priv) >= 13 && port >= PORT_D_XELPD) {
4518 drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
4519 DRM_MODE_ENCODER_TMDS,
4521 port_name(port - PORT_D_XELPD + PORT_D),
4523 } else if (DISPLAY_VER(dev_priv) >= 12) {
4524 enum tc_port tc_port = intel_port_to_tc(dev_priv, port);
4526 drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
4527 DRM_MODE_ENCODER_TMDS,
4528 "DDI %s%c/PHY %s%c",
4529 port >= PORT_TC1 ? "TC" : "",
4530 port >= PORT_TC1 ? port_tc_name(port) : port_name(port),
4531 tc_port != TC_PORT_NONE ? "TC" : "",
4532 tc_port != TC_PORT_NONE ? tc_port_name(tc_port) : phy_name(phy));
4533 } else if (DISPLAY_VER(dev_priv) >= 11) {
4534 enum tc_port tc_port = intel_port_to_tc(dev_priv, port);
4536 drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
4537 DRM_MODE_ENCODER_TMDS,
4538 "DDI %c%s/PHY %s%c",
4540 port >= PORT_C ? " (TC)" : "",
4541 tc_port != TC_PORT_NONE ? "TC" : "",
4542 tc_port != TC_PORT_NONE ? tc_port_name(tc_port) : phy_name(phy));
4544 drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
4545 DRM_MODE_ENCODER_TMDS,
4546 "DDI %c/PHY %c", port_name(port), phy_name(phy));
4549 mutex_init(&dig_port->hdcp_mutex);
4550 dig_port->num_hdcp_streams = 0;
4552 encoder->hotplug = intel_ddi_hotplug;
4553 encoder->compute_output_type = intel_ddi_compute_output_type;
4554 encoder->compute_config = intel_ddi_compute_config;
4555 encoder->compute_config_late = intel_ddi_compute_config_late;
4556 encoder->enable = intel_enable_ddi;
4557 encoder->pre_pll_enable = intel_ddi_pre_pll_enable;
4558 encoder->pre_enable = intel_ddi_pre_enable;
4559 encoder->pre_disable = intel_pre_disable_ddi;
4560 encoder->disable = intel_disable_ddi;
4561 encoder->post_disable = intel_ddi_post_disable;
4562 encoder->update_pipe = intel_ddi_update_pipe;
4563 encoder->get_hw_state = intel_ddi_get_hw_state;
4564 encoder->sync_state = intel_ddi_sync_state;
4565 encoder->initial_fastset_check = intel_ddi_initial_fastset_check;
4566 encoder->suspend = intel_ddi_encoder_suspend;
4567 encoder->shutdown = intel_ddi_encoder_shutdown;
4568 encoder->get_power_domains = intel_ddi_get_power_domains;
4570 encoder->type = INTEL_OUTPUT_DDI;
4571 encoder->power_domain = intel_port_to_power_domain(port);
4572 encoder->port = port;
4573 encoder->cloneable = 0;
4574 encoder->pipe_mask = ~0;
4576 if (IS_DG2(dev_priv)) {
4577 encoder->enable_clock = intel_mpllb_enable;
4578 encoder->disable_clock = intel_mpllb_disable;
4579 encoder->get_config = dg2_ddi_get_config;
4580 } else if (IS_ALDERLAKE_S(dev_priv)) {
4581 encoder->enable_clock = adls_ddi_enable_clock;
4582 encoder->disable_clock = adls_ddi_disable_clock;
4583 encoder->is_clock_enabled = adls_ddi_is_clock_enabled;
4584 encoder->get_config = adls_ddi_get_config;
4585 } else if (IS_ROCKETLAKE(dev_priv)) {
4586 encoder->enable_clock = rkl_ddi_enable_clock;
4587 encoder->disable_clock = rkl_ddi_disable_clock;
4588 encoder->is_clock_enabled = rkl_ddi_is_clock_enabled;
4589 encoder->get_config = rkl_ddi_get_config;
4590 } else if (IS_DG1(dev_priv)) {
4591 encoder->enable_clock = dg1_ddi_enable_clock;
4592 encoder->disable_clock = dg1_ddi_disable_clock;
4593 encoder->is_clock_enabled = dg1_ddi_is_clock_enabled;
4594 encoder->get_config = dg1_ddi_get_config;
4595 } else if (IS_JSL_EHL(dev_priv)) {
4596 if (intel_ddi_is_tc(dev_priv, port)) {
4597 encoder->enable_clock = jsl_ddi_tc_enable_clock;
4598 encoder->disable_clock = jsl_ddi_tc_disable_clock;
4599 encoder->is_clock_enabled = jsl_ddi_tc_is_clock_enabled;
4600 encoder->get_config = icl_ddi_combo_get_config;
4602 encoder->enable_clock = icl_ddi_combo_enable_clock;
4603 encoder->disable_clock = icl_ddi_combo_disable_clock;
4604 encoder->is_clock_enabled = icl_ddi_combo_is_clock_enabled;
4605 encoder->get_config = icl_ddi_combo_get_config;
4607 } else if (DISPLAY_VER(dev_priv) >= 11) {
4608 if (intel_ddi_is_tc(dev_priv, port)) {
4609 encoder->enable_clock = icl_ddi_tc_enable_clock;
4610 encoder->disable_clock = icl_ddi_tc_disable_clock;
4611 encoder->is_clock_enabled = icl_ddi_tc_is_clock_enabled;
4612 encoder->get_config = icl_ddi_tc_get_config;
4614 encoder->enable_clock = icl_ddi_combo_enable_clock;
4615 encoder->disable_clock = icl_ddi_combo_disable_clock;
4616 encoder->is_clock_enabled = icl_ddi_combo_is_clock_enabled;
4617 encoder->get_config = icl_ddi_combo_get_config;
4619 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
4620 /* BXT/GLK have fixed PLL->port mapping */
4621 encoder->get_config = bxt_ddi_get_config;
4622 } else if (DISPLAY_VER(dev_priv) == 9) {
4623 encoder->enable_clock = skl_ddi_enable_clock;
4624 encoder->disable_clock = skl_ddi_disable_clock;
4625 encoder->is_clock_enabled = skl_ddi_is_clock_enabled;
4626 encoder->get_config = skl_ddi_get_config;
4627 } else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4628 encoder->enable_clock = hsw_ddi_enable_clock;
4629 encoder->disable_clock = hsw_ddi_disable_clock;
4630 encoder->is_clock_enabled = hsw_ddi_is_clock_enabled;
4631 encoder->get_config = hsw_ddi_get_config;
4634 intel_ddi_buf_trans_init(encoder);
4636 if (DISPLAY_VER(dev_priv) >= 13)
4637 encoder->hpd_pin = xelpd_hpd_pin(dev_priv, port);
4638 else if (IS_DG1(dev_priv))
4639 encoder->hpd_pin = dg1_hpd_pin(dev_priv, port);
4640 else if (IS_ROCKETLAKE(dev_priv))
4641 encoder->hpd_pin = rkl_hpd_pin(dev_priv, port);
4642 else if (DISPLAY_VER(dev_priv) >= 12)
4643 encoder->hpd_pin = tgl_hpd_pin(dev_priv, port);
4644 else if (IS_JSL_EHL(dev_priv))
4645 encoder->hpd_pin = ehl_hpd_pin(dev_priv, port);
4646 else if (DISPLAY_VER(dev_priv) == 11)
4647 encoder->hpd_pin = icl_hpd_pin(dev_priv, port);
4648 else if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv))
4649 encoder->hpd_pin = skl_hpd_pin(dev_priv, port);
4651 encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port);
4653 if (DISPLAY_VER(dev_priv) >= 11)
4654 dig_port->saved_port_bits =
4655 intel_de_read(dev_priv, DDI_BUF_CTL(port))
4656 & DDI_BUF_PORT_REVERSAL;
4658 dig_port->saved_port_bits =
4659 intel_de_read(dev_priv, DDI_BUF_CTL(port))
4660 & (DDI_BUF_PORT_REVERSAL | DDI_A_4_LANES);
4662 if (intel_bios_is_lane_reversal_needed(dev_priv, port))
4663 dig_port->saved_port_bits |= DDI_BUF_PORT_REVERSAL;
4665 dig_port->dp.output_reg = INVALID_MMIO_REG;
4666 dig_port->max_lanes = intel_ddi_max_lanes(dig_port);
4667 dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port);
4669 if (intel_phy_is_tc(dev_priv, phy)) {
4671 !intel_bios_encoder_supports_typec_usb(devdata) &&
4672 !intel_bios_encoder_supports_tbt(devdata);
4674 intel_tc_port_init(dig_port, is_legacy);
4676 encoder->update_prepare = intel_ddi_update_prepare;
4677 encoder->update_complete = intel_ddi_update_complete;
4680 drm_WARN_ON(&dev_priv->drm, port > PORT_I);
4681 dig_port->ddi_io_power_domain = POWER_DOMAIN_PORT_DDI_A_IO +
4685 if (!intel_ddi_init_dp_connector(dig_port))
4688 dig_port->hpd_pulse = intel_dp_hpd_pulse;
4690 if (dig_port->dp.mso_link_count)
4691 encoder->pipe_mask = intel_ddi_splitter_pipe_mask(dev_priv);
4694 /* In theory we don't need the encoder->type check, but leave it just in
4695 * case we have some really bad VBTs... */
4696 if (encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
4697 if (!intel_ddi_init_hdmi_connector(dig_port))
4701 if (DISPLAY_VER(dev_priv) >= 11) {
4702 if (intel_phy_is_tc(dev_priv, phy))
4703 dig_port->connected = intel_tc_port_connected;
4705 dig_port->connected = lpt_digital_port_connected;
4706 } else if (DISPLAY_VER(dev_priv) >= 8) {
4707 if (port == PORT_A || IS_GEMINILAKE(dev_priv) ||
4708 IS_BROXTON(dev_priv))
4709 dig_port->connected = bdw_digital_port_connected;
4711 dig_port->connected = lpt_digital_port_connected;
4714 dig_port->connected = hsw_digital_port_connected;
4716 dig_port->connected = lpt_digital_port_connected;
4719 intel_infoframe_init(dig_port);
4724 drm_encoder_cleanup(&encoder->base);