xref: /linux/drivers/gpu/drm/i915/display/intel_ddi.c (revision 93e7e61eb448318e5793c4b20b21a8fd92d4f949)
1379bc100SJani Nikula /*
2379bc100SJani Nikula  * Copyright © 2012 Intel Corporation
3379bc100SJani Nikula  *
4379bc100SJani Nikula  * Permission is hereby granted, free of charge, to any person obtaining a
5379bc100SJani Nikula  * copy of this software and associated documentation files (the "Software"),
6379bc100SJani Nikula  * to deal in the Software without restriction, including without limitation
7379bc100SJani Nikula  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8379bc100SJani Nikula  * and/or sell copies of the Software, and to permit persons to whom the
9379bc100SJani Nikula  * Software is furnished to do so, subject to the following conditions:
10379bc100SJani Nikula  *
11379bc100SJani Nikula  * The above copyright notice and this permission notice (including the next
12379bc100SJani Nikula  * paragraph) shall be included in all copies or substantial portions of the
13379bc100SJani Nikula  * Software.
14379bc100SJani Nikula  *
15379bc100SJani Nikula  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16379bc100SJani Nikula  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17379bc100SJani Nikula  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18379bc100SJani Nikula  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19379bc100SJani Nikula  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20379bc100SJani Nikula  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21379bc100SJani Nikula  * IN THE SOFTWARE.
22379bc100SJani Nikula  *
23379bc100SJani Nikula  * Authors:
24379bc100SJani Nikula  *    Eugeni Dodonov <eugeni.dodonov@intel.com>
25379bc100SJani Nikula  *
26379bc100SJani Nikula  */
27379bc100SJani Nikula 
28379bc100SJani Nikula #include <drm/drm_scdc_helper.h>
29379bc100SJani Nikula 
30379bc100SJani Nikula #include "i915_drv.h"
31379bc100SJani Nikula #include "intel_audio.h"
32379bc100SJani Nikula #include "intel_combo_phy.h"
33379bc100SJani Nikula #include "intel_connector.h"
34379bc100SJani Nikula #include "intel_ddi.h"
3599092a97SDave Airlie #include "intel_ddi_buf_trans.h"
361d455f8dSJani Nikula #include "intel_display_types.h"
37379bc100SJani Nikula #include "intel_dp.h"
38379bc100SJani Nikula #include "intel_dp_link_training.h"
39dcb38f79SDave Airlie #include "intel_dp_mst.h"
40379bc100SJani Nikula #include "intel_dpio_phy.h"
41379bc100SJani Nikula #include "intel_dsi.h"
42dcb38f79SDave Airlie #include "intel_fdi.h"
43379bc100SJani Nikula #include "intel_fifo_underrun.h"
44379bc100SJani Nikula #include "intel_gmbus.h"
45379bc100SJani Nikula #include "intel_hdcp.h"
46379bc100SJani Nikula #include "intel_hdmi.h"
47379bc100SJani Nikula #include "intel_hotplug.h"
48379bc100SJani Nikula #include "intel_lspcon.h"
49379bc100SJani Nikula #include "intel_panel.h"
50abad6805SJani Nikula #include "intel_pps.h"
51379bc100SJani Nikula #include "intel_psr.h"
52bdacf087SAnshuman Gupta #include "intel_sprite.h"
53bc85328fSImre Deak #include "intel_tc.h"
54379bc100SJani Nikula #include "intel_vdsc.h"
55aa52b39dSManasi Navare #include "intel_vrr.h"
56714b1cdbSDave Airlie #include "skl_scaler.h"
5746d12f91SDave Airlie #include "skl_universal_plane.h"
58379bc100SJani Nikula 
59379bc100SJani Nikula static const u8 index_to_dp_signal_levels[] = {
60379bc100SJani Nikula 	[0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0,
61379bc100SJani Nikula 	[1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1,
62379bc100SJani Nikula 	[2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2,
63379bc100SJani Nikula 	[3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3,
64379bc100SJani Nikula 	[4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0,
65379bc100SJani Nikula 	[5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1,
66379bc100SJani Nikula 	[6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2,
67379bc100SJani Nikula 	[7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0,
68379bc100SJani Nikula 	[8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1,
69379bc100SJani Nikula 	[9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0,
70379bc100SJani Nikula };
71379bc100SJani Nikula 
72a621860aSVille Syrjälä static int intel_ddi_hdmi_level(struct intel_encoder *encoder,
73a621860aSVille Syrjälä 				const struct intel_crtc_state *crtc_state)
74379bc100SJani Nikula {
750aed3bdeSJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
76379bc100SJani Nikula 	int n_entries, level, default_entry;
77379bc100SJani Nikula 
7899092a97SDave Airlie 	n_entries = intel_ddi_hdmi_num_entries(encoder, crtc_state, &default_entry);
7999092a97SDave Airlie 	if (n_entries == 0)
80379bc100SJani Nikula 		return 0;
810aed3bdeSJani Nikula 	level = intel_bios_hdmi_level_shift(encoder);
820aed3bdeSJani Nikula 	if (level < 0)
837a0073d6SJani Nikula 		level = default_entry;
847a0073d6SJani Nikula 
851de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
86379bc100SJani Nikula 		level = n_entries - 1;
87379bc100SJani Nikula 
88379bc100SJani Nikula 	return level;
89379bc100SJani Nikula }
90379bc100SJani Nikula 
91379bc100SJani Nikula /*
92379bc100SJani Nikula  * Starting with Haswell, DDI port buffers must be programmed with correct
93379bc100SJani Nikula  * values in advance. This function programs the correct values for
94379bc100SJani Nikula  * DP/eDP/FDI use cases.
95379bc100SJani Nikula  */
96dcb38f79SDave Airlie void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder,
97379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state)
98379bc100SJani Nikula {
99379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
100379bc100SJani Nikula 	u32 iboost_bit = 0;
101379bc100SJani Nikula 	int i, n_entries;
102379bc100SJani Nikula 	enum port port = encoder->port;
103379bc100SJani Nikula 	const struct ddi_buf_trans *ddi_translations;
104379bc100SJani Nikula 
105379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
106379bc100SJani Nikula 		ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
107379bc100SJani Nikula 							       &n_entries);
108379bc100SJani Nikula 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
109f0e86e05SJosé Roberto de Souza 		ddi_translations = intel_ddi_get_buf_trans_edp(encoder,
110379bc100SJani Nikula 							       &n_entries);
111379bc100SJani Nikula 	else
112f0e86e05SJosé Roberto de Souza 		ddi_translations = intel_ddi_get_buf_trans_dp(encoder,
113379bc100SJani Nikula 							      &n_entries);
114379bc100SJani Nikula 
115379bc100SJani Nikula 	/* If we're boosting the current, set bit 31 of trans1 */
116*93e7e61eSLucas De Marchi 	if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv) &&
1172446e1d6SMatt Roper 	    intel_bios_encoder_dp_boost_level(encoder->devdata))
118379bc100SJani Nikula 		iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
119379bc100SJani Nikula 
120379bc100SJani Nikula 	for (i = 0; i < n_entries; i++) {
121f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, i),
122379bc100SJani Nikula 			       ddi_translations[i].trans1 | iboost_bit);
123f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, i),
124379bc100SJani Nikula 			       ddi_translations[i].trans2);
125379bc100SJani Nikula 	}
126379bc100SJani Nikula }
127379bc100SJani Nikula 
128379bc100SJani Nikula /*
129379bc100SJani Nikula  * Starting with Haswell, DDI port buffers must be programmed with correct
130379bc100SJani Nikula  * values in advance. This function programs the correct values for
131379bc100SJani Nikula  * HDMI/DVI use cases.
132379bc100SJani Nikula  */
133379bc100SJani Nikula static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder,
134379bc100SJani Nikula 					   int level)
135379bc100SJani Nikula {
136379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
137379bc100SJani Nikula 	u32 iboost_bit = 0;
138379bc100SJani Nikula 	int n_entries;
139379bc100SJani Nikula 	enum port port = encoder->port;
140379bc100SJani Nikula 	const struct ddi_buf_trans *ddi_translations;
141379bc100SJani Nikula 
142a8143150SJosé Roberto de Souza 	ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries);
143379bc100SJani Nikula 
1441de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
145379bc100SJani Nikula 		return;
1461de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
147379bc100SJani Nikula 		level = n_entries - 1;
148379bc100SJani Nikula 
149379bc100SJani Nikula 	/* If we're boosting the current, set bit 31 of trans1 */
150*93e7e61eSLucas De Marchi 	if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv) &&
1512446e1d6SMatt Roper 	    intel_bios_encoder_hdmi_boost_level(encoder->devdata))
152379bc100SJani Nikula 		iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
153379bc100SJani Nikula 
154379bc100SJani Nikula 	/* Entry 9 is for HDMI: */
155f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, 9),
156379bc100SJani Nikula 		       ddi_translations[level].trans1 | iboost_bit);
157f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, 9),
158379bc100SJani Nikula 		       ddi_translations[level].trans2);
159379bc100SJani Nikula }
160379bc100SJani Nikula 
161dcb38f79SDave Airlie void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
162379bc100SJani Nikula 			     enum port port)
163379bc100SJani Nikula {
1645a2ad99bSManasi Navare 	if (IS_BROXTON(dev_priv)) {
1655a2ad99bSManasi Navare 		udelay(16);
166379bc100SJani Nikula 		return;
167379bc100SJani Nikula 	}
1685a2ad99bSManasi Navare 
1695a2ad99bSManasi Navare 	if (wait_for_us((intel_de_read(dev_priv, DDI_BUF_CTL(port)) &
1705a2ad99bSManasi Navare 			 DDI_BUF_IS_IDLE), 8))
1715a2ad99bSManasi Navare 		drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get idle\n",
17247bdb1caSJani Nikula 			port_name(port));
173379bc100SJani Nikula }
174379bc100SJani Nikula 
175e828da30SManasi Navare static void intel_wait_ddi_buf_active(struct drm_i915_private *dev_priv,
176e828da30SManasi Navare 				      enum port port)
177e828da30SManasi Navare {
178e828da30SManasi Navare 	/* Wait > 518 usecs for DDI_BUF_CTL to be non idle */
179ad314fecSVille Syrjälä 	if (DISPLAY_VER(dev_priv) < 10) {
180e828da30SManasi Navare 		usleep_range(518, 1000);
181e828da30SManasi Navare 		return;
182e828da30SManasi Navare 	}
183e828da30SManasi Navare 
184e828da30SManasi Navare 	if (wait_for_us(!(intel_de_read(dev_priv, DDI_BUF_CTL(port)) &
185e828da30SManasi Navare 			  DDI_BUF_IS_IDLE), 500))
186e828da30SManasi Navare 		drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get active\n",
187e828da30SManasi Navare 			port_name(port));
188e828da30SManasi Navare }
189e828da30SManasi Navare 
190ad952982SVille Syrjälä static u32 hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll)
191379bc100SJani Nikula {
192379bc100SJani Nikula 	switch (pll->info->id) {
193379bc100SJani Nikula 	case DPLL_ID_WRPLL1:
194379bc100SJani Nikula 		return PORT_CLK_SEL_WRPLL1;
195379bc100SJani Nikula 	case DPLL_ID_WRPLL2:
196379bc100SJani Nikula 		return PORT_CLK_SEL_WRPLL2;
197379bc100SJani Nikula 	case DPLL_ID_SPLL:
198379bc100SJani Nikula 		return PORT_CLK_SEL_SPLL;
199379bc100SJani Nikula 	case DPLL_ID_LCPLL_810:
200379bc100SJani Nikula 		return PORT_CLK_SEL_LCPLL_810;
201379bc100SJani Nikula 	case DPLL_ID_LCPLL_1350:
202379bc100SJani Nikula 		return PORT_CLK_SEL_LCPLL_1350;
203379bc100SJani Nikula 	case DPLL_ID_LCPLL_2700:
204379bc100SJani Nikula 		return PORT_CLK_SEL_LCPLL_2700;
205379bc100SJani Nikula 	default:
206379bc100SJani Nikula 		MISSING_CASE(pll->info->id);
207379bc100SJani Nikula 		return PORT_CLK_SEL_NONE;
208379bc100SJani Nikula 	}
209379bc100SJani Nikula }
210379bc100SJani Nikula 
211379bc100SJani Nikula static u32 icl_pll_to_ddi_clk_sel(struct intel_encoder *encoder,
212379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state)
213379bc100SJani Nikula {
214379bc100SJani Nikula 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
215379bc100SJani Nikula 	int clock = crtc_state->port_clock;
216379bc100SJani Nikula 	const enum intel_dpll_id id = pll->info->id;
217379bc100SJani Nikula 
218379bc100SJani Nikula 	switch (id) {
219379bc100SJani Nikula 	default:
220379bc100SJani Nikula 		/*
221379bc100SJani Nikula 		 * DPLL_ID_ICL_DPLL0 and DPLL_ID_ICL_DPLL1 should not be used
222379bc100SJani Nikula 		 * here, so do warn if this get passed in
223379bc100SJani Nikula 		 */
224379bc100SJani Nikula 		MISSING_CASE(id);
225379bc100SJani Nikula 		return DDI_CLK_SEL_NONE;
226379bc100SJani Nikula 	case DPLL_ID_ICL_TBTPLL:
227379bc100SJani Nikula 		switch (clock) {
228379bc100SJani Nikula 		case 162000:
229379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_162;
230379bc100SJani Nikula 		case 270000:
231379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_270;
232379bc100SJani Nikula 		case 540000:
233379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_540;
234379bc100SJani Nikula 		case 810000:
235379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_810;
236379bc100SJani Nikula 		default:
237379bc100SJani Nikula 			MISSING_CASE(clock);
238379bc100SJani Nikula 			return DDI_CLK_SEL_NONE;
239379bc100SJani Nikula 		}
240379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL1:
241379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL2:
242379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL3:
243379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL4:
2446677c3b1SJosé Roberto de Souza 	case DPLL_ID_TGL_MGPLL5:
2456677c3b1SJosé Roberto de Souza 	case DPLL_ID_TGL_MGPLL6:
246379bc100SJani Nikula 		return DDI_CLK_SEL_MG;
247379bc100SJani Nikula 	}
248379bc100SJani Nikula }
249379bc100SJani Nikula 
250a621860aSVille Syrjälä static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder,
251a621860aSVille Syrjälä 				      const struct intel_crtc_state *crtc_state)
252379bc100SJani Nikula {
253b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2547801f3b7SLucas De Marchi 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
255379bc100SJani Nikula 
2567801f3b7SLucas De Marchi 	intel_dp->DP = dig_port->saved_port_bits |
257379bc100SJani Nikula 		DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
258a621860aSVille Syrjälä 	intel_dp->DP |= DDI_PORT_WIDTH(crtc_state->lane_count);
259379bc100SJani Nikula }
260379bc100SJani Nikula 
261379bc100SJani Nikula static int icl_calc_tbt_pll_link(struct drm_i915_private *dev_priv,
262379bc100SJani Nikula 				 enum port port)
263379bc100SJani Nikula {
264f7960e7fSJani Nikula 	u32 val = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
265379bc100SJani Nikula 
266379bc100SJani Nikula 	switch (val) {
267379bc100SJani Nikula 	case DDI_CLK_SEL_NONE:
268379bc100SJani Nikula 		return 0;
269379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_162:
270379bc100SJani Nikula 		return 162000;
271379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_270:
272379bc100SJani Nikula 		return 270000;
273379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_540:
274379bc100SJani Nikula 		return 540000;
275379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_810:
276379bc100SJani Nikula 		return 810000;
277379bc100SJani Nikula 	default:
278379bc100SJani Nikula 		MISSING_CASE(val);
279379bc100SJani Nikula 		return 0;
280379bc100SJani Nikula 	}
281379bc100SJani Nikula }
282379bc100SJani Nikula 
283379bc100SJani Nikula static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
284379bc100SJani Nikula {
285379bc100SJani Nikula 	int dotclock;
286379bc100SJani Nikula 
287379bc100SJani Nikula 	if (pipe_config->has_pch_encoder)
288379bc100SJani Nikula 		dotclock = intel_dotclock_calculate(pipe_config->port_clock,
289379bc100SJani Nikula 						    &pipe_config->fdi_m_n);
290379bc100SJani Nikula 	else if (intel_crtc_has_dp_encoder(pipe_config))
291379bc100SJani Nikula 		dotclock = intel_dotclock_calculate(pipe_config->port_clock,
292379bc100SJani Nikula 						    &pipe_config->dp_m_n);
2932969a78aSImre Deak 	else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
2942969a78aSImre Deak 		dotclock = pipe_config->port_clock * 24 / pipe_config->pipe_bpp;
295379bc100SJani Nikula 	else
296379bc100SJani Nikula 		dotclock = pipe_config->port_clock;
297379bc100SJani Nikula 
298379bc100SJani Nikula 	if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
299379bc100SJani Nikula 	    !intel_crtc_has_dp_encoder(pipe_config))
300379bc100SJani Nikula 		dotclock *= 2;
301379bc100SJani Nikula 
302379bc100SJani Nikula 	if (pipe_config->pixel_multiplier)
303379bc100SJani Nikula 		dotclock /= pipe_config->pixel_multiplier;
304379bc100SJani Nikula 
3051326a92cSMaarten Lankhorst 	pipe_config->hw.adjusted_mode.crtc_clock = dotclock;
306379bc100SJani Nikula }
307379bc100SJani Nikula 
3080c06fa15SGwan-gyeong Mun void intel_ddi_set_dp_msa(const struct intel_crtc_state *crtc_state,
3090c06fa15SGwan-gyeong Mun 			  const struct drm_connector_state *conn_state)
310379bc100SJani Nikula {
3112225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
312379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
313379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
314379bc100SJani Nikula 	u32 temp;
315379bc100SJani Nikula 
316379bc100SJani Nikula 	if (!intel_crtc_has_dp_encoder(crtc_state))
317379bc100SJani Nikula 		return;
318379bc100SJani Nikula 
3191de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder));
320379bc100SJani Nikula 
3213e706dffSVille Syrjälä 	temp = DP_MSA_MISC_SYNC_CLOCK;
322379bc100SJani Nikula 
323379bc100SJani Nikula 	switch (crtc_state->pipe_bpp) {
324379bc100SJani Nikula 	case 18:
3253e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_6_BPC;
326379bc100SJani Nikula 		break;
327379bc100SJani Nikula 	case 24:
3283e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_8_BPC;
329379bc100SJani Nikula 		break;
330379bc100SJani Nikula 	case 30:
3313e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_10_BPC;
332379bc100SJani Nikula 		break;
333379bc100SJani Nikula 	case 36:
3343e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_12_BPC;
335379bc100SJani Nikula 		break;
336379bc100SJani Nikula 	default:
337379bc100SJani Nikula 		MISSING_CASE(crtc_state->pipe_bpp);
338379bc100SJani Nikula 		break;
339379bc100SJani Nikula 	}
340379bc100SJani Nikula 
341cae154fcSVille Syrjälä 	/* nonsense combination */
3421de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
343cae154fcSVille Syrjälä 		    crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
344cae154fcSVille Syrjälä 
345cae154fcSVille Syrjälä 	if (crtc_state->limited_color_range)
3463e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_COLOR_CEA_RGB;
347cae154fcSVille Syrjälä 
348379bc100SJani Nikula 	/*
349379bc100SJani Nikula 	 * As per DP 1.2 spec section 2.3.4.3 while sending
350379bc100SJani Nikula 	 * YCBCR 444 signals we should program MSA MISC1/0 fields with
351646d3dc8SVille Syrjälä 	 * colorspace information.
352379bc100SJani Nikula 	 */
353379bc100SJani Nikula 	if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3543e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_COLOR_YCBCR_444_BT709;
355646d3dc8SVille Syrjälä 
356379bc100SJani Nikula 	/*
357379bc100SJani Nikula 	 * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication
358379bc100SJani Nikula 	 * of Color Encoding Format and Content Color Gamut] while sending
3590c06fa15SGwan-gyeong Mun 	 * YCBCR 420, HDR BT.2020 signals we should program MSA MISC1 fields
3600c06fa15SGwan-gyeong Mun 	 * which indicate VSC SDP for the Pixel Encoding/Colorimetry Format.
361379bc100SJani Nikula 	 */
362bd8c9ccaSGwan-gyeong Mun 	if (intel_dp_needs_vsc_sdp(crtc_state, conn_state))
3633e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_COLOR_VSC_SDP;
3640c06fa15SGwan-gyeong Mun 
365f7960e7fSJani Nikula 	intel_de_write(dev_priv, TRANS_MSA_MISC(cpu_transcoder), temp);
366379bc100SJani Nikula }
367379bc100SJani Nikula 
368dc5b8ed5SVille Syrjälä static u32 bdw_trans_port_sync_master_select(enum transcoder master_transcoder)
369dc5b8ed5SVille Syrjälä {
370dc5b8ed5SVille Syrjälä 	if (master_transcoder == TRANSCODER_EDP)
371dc5b8ed5SVille Syrjälä 		return 0;
372dc5b8ed5SVille Syrjälä 	else
373dc5b8ed5SVille Syrjälä 		return master_transcoder + 1;
374dc5b8ed5SVille Syrjälä }
375dc5b8ed5SVille Syrjälä 
37699389390SJosé Roberto de Souza /*
37799389390SJosé Roberto de Souza  * Returns the TRANS_DDI_FUNC_CTL value based on CRTC state.
37899389390SJosé Roberto de Souza  *
37999389390SJosé Roberto de Souza  * Only intended to be used by intel_ddi_enable_transcoder_func() and
38099389390SJosé Roberto de Souza  * intel_ddi_config_transcoder_func().
38199389390SJosé Roberto de Souza  */
38299389390SJosé Roberto de Souza static u32
383eed22a46SVille Syrjälä intel_ddi_transcoder_func_reg_val_get(struct intel_encoder *encoder,
384eed22a46SVille Syrjälä 				      const struct intel_crtc_state *crtc_state)
385379bc100SJani Nikula {
3862225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
387379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
388379bc100SJani Nikula 	enum pipe pipe = crtc->pipe;
389379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
390379bc100SJani Nikula 	enum port port = encoder->port;
391379bc100SJani Nikula 	u32 temp;
392379bc100SJani Nikula 
393379bc100SJani Nikula 	/* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
394379bc100SJani Nikula 	temp = TRANS_DDI_FUNC_ENABLE;
395005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
396df16b636SMahesh Kumar 		temp |= TGL_TRANS_DDI_SELECT_PORT(port);
397df16b636SMahesh Kumar 	else
398379bc100SJani Nikula 		temp |= TRANS_DDI_SELECT_PORT(port);
399379bc100SJani Nikula 
400379bc100SJani Nikula 	switch (crtc_state->pipe_bpp) {
401379bc100SJani Nikula 	case 18:
402379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_6;
403379bc100SJani Nikula 		break;
404379bc100SJani Nikula 	case 24:
405379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_8;
406379bc100SJani Nikula 		break;
407379bc100SJani Nikula 	case 30:
408379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_10;
409379bc100SJani Nikula 		break;
410379bc100SJani Nikula 	case 36:
411379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_12;
412379bc100SJani Nikula 		break;
413379bc100SJani Nikula 	default:
414379bc100SJani Nikula 		BUG();
415379bc100SJani Nikula 	}
416379bc100SJani Nikula 
4171326a92cSMaarten Lankhorst 	if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
418379bc100SJani Nikula 		temp |= TRANS_DDI_PVSYNC;
4191326a92cSMaarten Lankhorst 	if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
420379bc100SJani Nikula 		temp |= TRANS_DDI_PHSYNC;
421379bc100SJani Nikula 
422379bc100SJani Nikula 	if (cpu_transcoder == TRANSCODER_EDP) {
423379bc100SJani Nikula 		switch (pipe) {
424379bc100SJani Nikula 		case PIPE_A:
425379bc100SJani Nikula 			/* On Haswell, can only use the always-on power well for
426379bc100SJani Nikula 			 * eDP when not using the panel fitter, and when not
427379bc100SJani Nikula 			 * using motion blur mitigation (which we don't
428379bc100SJani Nikula 			 * support). */
429379bc100SJani Nikula 			if (crtc_state->pch_pfit.force_thru)
430379bc100SJani Nikula 				temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
431379bc100SJani Nikula 			else
432379bc100SJani Nikula 				temp |= TRANS_DDI_EDP_INPUT_A_ON;
433379bc100SJani Nikula 			break;
434379bc100SJani Nikula 		case PIPE_B:
435379bc100SJani Nikula 			temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
436379bc100SJani Nikula 			break;
437379bc100SJani Nikula 		case PIPE_C:
438379bc100SJani Nikula 			temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
439379bc100SJani Nikula 			break;
440379bc100SJani Nikula 		default:
441379bc100SJani Nikula 			BUG();
442379bc100SJani Nikula 			break;
443379bc100SJani Nikula 		}
444379bc100SJani Nikula 	}
445379bc100SJani Nikula 
446379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
447379bc100SJani Nikula 		if (crtc_state->has_hdmi_sink)
448379bc100SJani Nikula 			temp |= TRANS_DDI_MODE_SELECT_HDMI;
449379bc100SJani Nikula 		else
450379bc100SJani Nikula 			temp |= TRANS_DDI_MODE_SELECT_DVI;
451379bc100SJani Nikula 
452379bc100SJani Nikula 		if (crtc_state->hdmi_scrambling)
453379bc100SJani Nikula 			temp |= TRANS_DDI_HDMI_SCRAMBLING;
454379bc100SJani Nikula 		if (crtc_state->hdmi_high_tmds_clock_ratio)
455379bc100SJani Nikula 			temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
456379bc100SJani Nikula 	} else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
457379bc100SJani Nikula 		temp |= TRANS_DDI_MODE_SELECT_FDI;
458379bc100SJani Nikula 		temp |= (crtc_state->fdi_lanes - 1) << 1;
459379bc100SJani Nikula 	} else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
460379bc100SJani Nikula 		temp |= TRANS_DDI_MODE_SELECT_DP_MST;
461379bc100SJani Nikula 		temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
462b3545e08SLucas De Marchi 
463005e9537SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 12) {
4646671c367SJosé Roberto de Souza 			enum transcoder master;
4656671c367SJosé Roberto de Souza 
4666671c367SJosé Roberto de Souza 			master = crtc_state->mst_master_transcoder;
4671de143ccSPankaj Bharadiya 			drm_WARN_ON(&dev_priv->drm,
4681de143ccSPankaj Bharadiya 				    master == INVALID_TRANSCODER);
4696671c367SJosé Roberto de Souza 			temp |= TRANS_DDI_MST_TRANSPORT_SELECT(master);
4706671c367SJosé Roberto de Souza 		}
471379bc100SJani Nikula 	} else {
472379bc100SJani Nikula 		temp |= TRANS_DDI_MODE_SELECT_DP_SST;
473379bc100SJani Nikula 		temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
474379bc100SJani Nikula 	}
475379bc100SJani Nikula 
476*93e7e61eSLucas De Marchi 	if (IS_DISPLAY_VER(dev_priv, 8, 10) &&
477dc5b8ed5SVille Syrjälä 	    crtc_state->master_transcoder != INVALID_TRANSCODER) {
478dc5b8ed5SVille Syrjälä 		u8 master_select =
479dc5b8ed5SVille Syrjälä 			bdw_trans_port_sync_master_select(crtc_state->master_transcoder);
480dc5b8ed5SVille Syrjälä 
481dc5b8ed5SVille Syrjälä 		temp |= TRANS_DDI_PORT_SYNC_ENABLE |
482dc5b8ed5SVille Syrjälä 			TRANS_DDI_PORT_SYNC_MASTER_SELECT(master_select);
483dc5b8ed5SVille Syrjälä 	}
484dc5b8ed5SVille Syrjälä 
48599389390SJosé Roberto de Souza 	return temp;
48699389390SJosé Roberto de Souza }
48799389390SJosé Roberto de Souza 
488eed22a46SVille Syrjälä void intel_ddi_enable_transcoder_func(struct intel_encoder *encoder,
489eed22a46SVille Syrjälä 				      const struct intel_crtc_state *crtc_state)
49099389390SJosé Roberto de Souza {
4912225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
49299389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
49399389390SJosé Roberto de Souza 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
49499389390SJosé Roberto de Souza 
495005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11) {
496589a4cd6SVille Syrjälä 		enum transcoder master_transcoder = crtc_state->master_transcoder;
497589a4cd6SVille Syrjälä 		u32 ctl2 = 0;
498589a4cd6SVille Syrjälä 
499589a4cd6SVille Syrjälä 		if (master_transcoder != INVALID_TRANSCODER) {
500dc5b8ed5SVille Syrjälä 			u8 master_select =
501dc5b8ed5SVille Syrjälä 				bdw_trans_port_sync_master_select(master_transcoder);
502589a4cd6SVille Syrjälä 
503589a4cd6SVille Syrjälä 			ctl2 |= PORT_SYNC_MODE_ENABLE |
504d4d7d9caSVille Syrjälä 				PORT_SYNC_MODE_MASTER_SELECT(master_select);
505589a4cd6SVille Syrjälä 		}
506589a4cd6SVille Syrjälä 
507589a4cd6SVille Syrjälä 		intel_de_write(dev_priv,
508589a4cd6SVille Syrjälä 			       TRANS_DDI_FUNC_CTL2(cpu_transcoder), ctl2);
509589a4cd6SVille Syrjälä 	}
510589a4cd6SVille Syrjälä 
511580fbdc5SImre Deak 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder),
512580fbdc5SImre Deak 		       intel_ddi_transcoder_func_reg_val_get(encoder,
513580fbdc5SImre Deak 							     crtc_state));
51499389390SJosé Roberto de Souza }
51599389390SJosé Roberto de Souza 
51699389390SJosé Roberto de Souza /*
51799389390SJosé Roberto de Souza  * Same as intel_ddi_enable_transcoder_func(), but it does not set the enable
51899389390SJosé Roberto de Souza  * bit.
51999389390SJosé Roberto de Souza  */
52099389390SJosé Roberto de Souza static void
521eed22a46SVille Syrjälä intel_ddi_config_transcoder_func(struct intel_encoder *encoder,
522eed22a46SVille Syrjälä 				 const struct intel_crtc_state *crtc_state)
52399389390SJosé Roberto de Souza {
5242225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
52599389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
52699389390SJosé Roberto de Souza 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
527589a4cd6SVille Syrjälä 	u32 ctl;
52899389390SJosé Roberto de Souza 
529eed22a46SVille Syrjälä 	ctl = intel_ddi_transcoder_func_reg_val_get(encoder, crtc_state);
530589a4cd6SVille Syrjälä 	ctl &= ~TRANS_DDI_FUNC_ENABLE;
531589a4cd6SVille Syrjälä 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl);
532379bc100SJani Nikula }
533379bc100SJani Nikula 
534379bc100SJani Nikula void intel_ddi_disable_transcoder_func(const struct intel_crtc_state *crtc_state)
535379bc100SJani Nikula {
5362225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
537379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
538379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
539589a4cd6SVille Syrjälä 	u32 ctl;
540c59053dcSJosé Roberto de Souza 
541005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11)
542589a4cd6SVille Syrjälä 		intel_de_write(dev_priv,
543589a4cd6SVille Syrjälä 			       TRANS_DDI_FUNC_CTL2(cpu_transcoder), 0);
544589a4cd6SVille Syrjälä 
545589a4cd6SVille Syrjälä 	ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
546dc5b8ed5SVille Syrjälä 
5471cfcdbf3SSean Paul 	drm_WARN_ON(crtc->base.dev, ctl & TRANS_DDI_HDCP_SIGNALLING);
5481cfcdbf3SSean Paul 
549589a4cd6SVille Syrjälä 	ctl &= ~TRANS_DDI_FUNC_ENABLE;
550379bc100SJani Nikula 
551*93e7e61eSLucas De Marchi 	if (IS_DISPLAY_VER(dev_priv, 8, 10))
552dc5b8ed5SVille Syrjälä 		ctl &= ~(TRANS_DDI_PORT_SYNC_ENABLE |
553dc5b8ed5SVille Syrjälä 			 TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK);
554dc5b8ed5SVille Syrjälä 
555005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
556919e4f07SJosé Roberto de Souza 		if (!intel_dp_mst_is_master_trans(crtc_state)) {
557589a4cd6SVille Syrjälä 			ctl &= ~(TGL_TRANS_DDI_PORT_MASK |
558919e4f07SJosé Roberto de Souza 				 TRANS_DDI_MODE_SELECT_MASK);
559919e4f07SJosé Roberto de Souza 		}
560df16b636SMahesh Kumar 	} else {
561589a4cd6SVille Syrjälä 		ctl &= ~(TRANS_DDI_PORT_MASK | TRANS_DDI_MODE_SELECT_MASK);
562df16b636SMahesh Kumar 	}
563dc5b8ed5SVille Syrjälä 
564589a4cd6SVille Syrjälä 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl);
565379bc100SJani Nikula 
566379bc100SJani Nikula 	if (dev_priv->quirks & QUIRK_INCREASE_DDI_DISABLED_TIME &&
567379bc100SJani Nikula 	    intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
56847bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
56947bdb1caSJani Nikula 			    "Quirk Increase DDI disabled time\n");
570379bc100SJani Nikula 		/* Quirk time at 100ms for reliable operation */
571379bc100SJani Nikula 		msleep(100);
572379bc100SJani Nikula 	}
573379bc100SJani Nikula }
574379bc100SJani Nikula 
5751a67a168SAnshuman Gupta int intel_ddi_toggle_hdcp_bits(struct intel_encoder *intel_encoder,
5760b9c9290SSean Paul 			       enum transcoder cpu_transcoder,
5771a67a168SAnshuman Gupta 			       bool enable, u32 hdcp_mask)
578379bc100SJani Nikula {
579379bc100SJani Nikula 	struct drm_device *dev = intel_encoder->base.dev;
580379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
581379bc100SJani Nikula 	intel_wakeref_t wakeref;
582379bc100SJani Nikula 	int ret = 0;
583379bc100SJani Nikula 	u32 tmp;
584379bc100SJani Nikula 
585379bc100SJani Nikula 	wakeref = intel_display_power_get_if_enabled(dev_priv,
586379bc100SJani Nikula 						     intel_encoder->power_domain);
5871de143ccSPankaj Bharadiya 	if (drm_WARN_ON(dev, !wakeref))
588379bc100SJani Nikula 		return -ENXIO;
589379bc100SJani Nikula 
5900b9c9290SSean Paul 	tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
591379bc100SJani Nikula 	if (enable)
5921a67a168SAnshuman Gupta 		tmp |= hdcp_mask;
593379bc100SJani Nikula 	else
5941a67a168SAnshuman Gupta 		tmp &= ~hdcp_mask;
5950b9c9290SSean Paul 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), tmp);
596379bc100SJani Nikula 	intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref);
597379bc100SJani Nikula 	return ret;
598379bc100SJani Nikula }
599379bc100SJani Nikula 
600379bc100SJani Nikula bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
601379bc100SJani Nikula {
602379bc100SJani Nikula 	struct drm_device *dev = intel_connector->base.dev;
603379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
604fa7edcd2SVille Syrjälä 	struct intel_encoder *encoder = intel_attached_encoder(intel_connector);
605379bc100SJani Nikula 	int type = intel_connector->base.connector_type;
606379bc100SJani Nikula 	enum port port = encoder->port;
607379bc100SJani Nikula 	enum transcoder cpu_transcoder;
608379bc100SJani Nikula 	intel_wakeref_t wakeref;
609379bc100SJani Nikula 	enum pipe pipe = 0;
610379bc100SJani Nikula 	u32 tmp;
611379bc100SJani Nikula 	bool ret;
612379bc100SJani Nikula 
613379bc100SJani Nikula 	wakeref = intel_display_power_get_if_enabled(dev_priv,
614379bc100SJani Nikula 						     encoder->power_domain);
615379bc100SJani Nikula 	if (!wakeref)
616379bc100SJani Nikula 		return false;
617379bc100SJani Nikula 
618379bc100SJani Nikula 	if (!encoder->get_hw_state(encoder, &pipe)) {
619379bc100SJani Nikula 		ret = false;
620379bc100SJani Nikula 		goto out;
621379bc100SJani Nikula 	}
622379bc100SJani Nikula 
62310cf8e75SVille Syrjälä 	if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A)
624379bc100SJani Nikula 		cpu_transcoder = TRANSCODER_EDP;
625379bc100SJani Nikula 	else
626379bc100SJani Nikula 		cpu_transcoder = (enum transcoder) pipe;
627379bc100SJani Nikula 
628f7960e7fSJani Nikula 	tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
629379bc100SJani Nikula 
630379bc100SJani Nikula 	switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
631379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_HDMI:
632379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DVI:
633379bc100SJani Nikula 		ret = type == DRM_MODE_CONNECTOR_HDMIA;
634379bc100SJani Nikula 		break;
635379bc100SJani Nikula 
636379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_SST:
637379bc100SJani Nikula 		ret = type == DRM_MODE_CONNECTOR_eDP ||
638379bc100SJani Nikula 		      type == DRM_MODE_CONNECTOR_DisplayPort;
639379bc100SJani Nikula 		break;
640379bc100SJani Nikula 
641379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_MST:
642379bc100SJani Nikula 		/* if the transcoder is in MST state then
643379bc100SJani Nikula 		 * connector isn't connected */
644379bc100SJani Nikula 		ret = false;
645379bc100SJani Nikula 		break;
646379bc100SJani Nikula 
647379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_FDI:
648379bc100SJani Nikula 		ret = type == DRM_MODE_CONNECTOR_VGA;
649379bc100SJani Nikula 		break;
650379bc100SJani Nikula 
651379bc100SJani Nikula 	default:
652379bc100SJani Nikula 		ret = false;
653379bc100SJani Nikula 		break;
654379bc100SJani Nikula 	}
655379bc100SJani Nikula 
656379bc100SJani Nikula out:
657379bc100SJani Nikula 	intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
658379bc100SJani Nikula 
659379bc100SJani Nikula 	return ret;
660379bc100SJani Nikula }
661379bc100SJani Nikula 
662379bc100SJani Nikula static void intel_ddi_get_encoder_pipes(struct intel_encoder *encoder,
663379bc100SJani Nikula 					u8 *pipe_mask, bool *is_dp_mst)
664379bc100SJani Nikula {
665379bc100SJani Nikula 	struct drm_device *dev = encoder->base.dev;
666379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
667379bc100SJani Nikula 	enum port port = encoder->port;
668379bc100SJani Nikula 	intel_wakeref_t wakeref;
669379bc100SJani Nikula 	enum pipe p;
670379bc100SJani Nikula 	u32 tmp;
671379bc100SJani Nikula 	u8 mst_pipe_mask;
672379bc100SJani Nikula 
673379bc100SJani Nikula 	*pipe_mask = 0;
674379bc100SJani Nikula 	*is_dp_mst = false;
675379bc100SJani Nikula 
676379bc100SJani Nikula 	wakeref = intel_display_power_get_if_enabled(dev_priv,
677379bc100SJani Nikula 						     encoder->power_domain);
678379bc100SJani Nikula 	if (!wakeref)
679379bc100SJani Nikula 		return;
680379bc100SJani Nikula 
681f7960e7fSJani Nikula 	tmp = intel_de_read(dev_priv, DDI_BUF_CTL(port));
682379bc100SJani Nikula 	if (!(tmp & DDI_BUF_CTL_ENABLE))
683379bc100SJani Nikula 		goto out;
684379bc100SJani Nikula 
68510cf8e75SVille Syrjälä 	if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) {
686f7960e7fSJani Nikula 		tmp = intel_de_read(dev_priv,
687f7960e7fSJani Nikula 				    TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
688379bc100SJani Nikula 
689379bc100SJani Nikula 		switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
690379bc100SJani Nikula 		default:
691379bc100SJani Nikula 			MISSING_CASE(tmp & TRANS_DDI_EDP_INPUT_MASK);
692df561f66SGustavo A. R. Silva 			fallthrough;
693379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_A_ON:
694379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_A_ONOFF:
695379bc100SJani Nikula 			*pipe_mask = BIT(PIPE_A);
696379bc100SJani Nikula 			break;
697379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_B_ONOFF:
698379bc100SJani Nikula 			*pipe_mask = BIT(PIPE_B);
699379bc100SJani Nikula 			break;
700379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_C_ONOFF:
701379bc100SJani Nikula 			*pipe_mask = BIT(PIPE_C);
702379bc100SJani Nikula 			break;
703379bc100SJani Nikula 		}
704379bc100SJani Nikula 
705379bc100SJani Nikula 		goto out;
706379bc100SJani Nikula 	}
707379bc100SJani Nikula 
708379bc100SJani Nikula 	mst_pipe_mask = 0;
709379bc100SJani Nikula 	for_each_pipe(dev_priv, p) {
710379bc100SJani Nikula 		enum transcoder cpu_transcoder = (enum transcoder)p;
711df16b636SMahesh Kumar 		unsigned int port_mask, ddi_select;
7126aa3bef1SJosé Roberto de Souza 		intel_wakeref_t trans_wakeref;
7136aa3bef1SJosé Roberto de Souza 
7146aa3bef1SJosé Roberto de Souza 		trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
7156aa3bef1SJosé Roberto de Souza 								   POWER_DOMAIN_TRANSCODER(cpu_transcoder));
7166aa3bef1SJosé Roberto de Souza 		if (!trans_wakeref)
7176aa3bef1SJosé Roberto de Souza 			continue;
718df16b636SMahesh Kumar 
719005e9537SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 12) {
720df16b636SMahesh Kumar 			port_mask = TGL_TRANS_DDI_PORT_MASK;
721df16b636SMahesh Kumar 			ddi_select = TGL_TRANS_DDI_SELECT_PORT(port);
722df16b636SMahesh Kumar 		} else {
723df16b636SMahesh Kumar 			port_mask = TRANS_DDI_PORT_MASK;
724df16b636SMahesh Kumar 			ddi_select = TRANS_DDI_SELECT_PORT(port);
725df16b636SMahesh Kumar 		}
726379bc100SJani Nikula 
727f7960e7fSJani Nikula 		tmp = intel_de_read(dev_priv,
728f7960e7fSJani Nikula 				    TRANS_DDI_FUNC_CTL(cpu_transcoder));
7296aa3bef1SJosé Roberto de Souza 		intel_display_power_put(dev_priv, POWER_DOMAIN_TRANSCODER(cpu_transcoder),
7306aa3bef1SJosé Roberto de Souza 					trans_wakeref);
731379bc100SJani Nikula 
732df16b636SMahesh Kumar 		if ((tmp & port_mask) != ddi_select)
733379bc100SJani Nikula 			continue;
734379bc100SJani Nikula 
735379bc100SJani Nikula 		if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
736379bc100SJani Nikula 		    TRANS_DDI_MODE_SELECT_DP_MST)
737379bc100SJani Nikula 			mst_pipe_mask |= BIT(p);
738379bc100SJani Nikula 
739379bc100SJani Nikula 		*pipe_mask |= BIT(p);
740379bc100SJani Nikula 	}
741379bc100SJani Nikula 
742379bc100SJani Nikula 	if (!*pipe_mask)
74347bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
74447bdb1caSJani Nikula 			    "No pipe for [ENCODER:%d:%s] found\n",
74566a990ddSVille Syrjälä 			    encoder->base.base.id, encoder->base.name);
746379bc100SJani Nikula 
747379bc100SJani Nikula 	if (!mst_pipe_mask && hweight8(*pipe_mask) > 1) {
74847bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
74947bdb1caSJani Nikula 			    "Multiple pipes for [ENCODER:%d:%s] (pipe_mask %02x)\n",
75066a990ddSVille Syrjälä 			    encoder->base.base.id, encoder->base.name,
75166a990ddSVille Syrjälä 			    *pipe_mask);
752379bc100SJani Nikula 		*pipe_mask = BIT(ffs(*pipe_mask) - 1);
753379bc100SJani Nikula 	}
754379bc100SJani Nikula 
755379bc100SJani Nikula 	if (mst_pipe_mask && mst_pipe_mask != *pipe_mask)
75647bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
75747bdb1caSJani Nikula 			    "Conflicting MST and non-MST state for [ENCODER:%d:%s] (pipe_mask %02x mst_pipe_mask %02x)\n",
75866a990ddSVille Syrjälä 			    encoder->base.base.id, encoder->base.name,
75966a990ddSVille Syrjälä 			    *pipe_mask, mst_pipe_mask);
760379bc100SJani Nikula 	else
761379bc100SJani Nikula 		*is_dp_mst = mst_pipe_mask;
762379bc100SJani Nikula 
763379bc100SJani Nikula out:
7642446e1d6SMatt Roper 	if (*pipe_mask && (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))) {
765f7960e7fSJani Nikula 		tmp = intel_de_read(dev_priv, BXT_PHY_CTL(port));
766379bc100SJani Nikula 		if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK |
767379bc100SJani Nikula 			    BXT_PHY_LANE_POWERDOWN_ACK |
768379bc100SJani Nikula 			    BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
76947bdb1caSJani Nikula 			drm_err(&dev_priv->drm,
77047bdb1caSJani Nikula 				"[ENCODER:%d:%s] enabled but PHY powered down? (PHY_CTL %08x)\n",
77147bdb1caSJani Nikula 				encoder->base.base.id, encoder->base.name, tmp);
772379bc100SJani Nikula 	}
773379bc100SJani Nikula 
774379bc100SJani Nikula 	intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
775379bc100SJani Nikula }
776379bc100SJani Nikula 
777379bc100SJani Nikula bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
778379bc100SJani Nikula 			    enum pipe *pipe)
779379bc100SJani Nikula {
780379bc100SJani Nikula 	u8 pipe_mask;
781379bc100SJani Nikula 	bool is_mst;
782379bc100SJani Nikula 
783379bc100SJani Nikula 	intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst);
784379bc100SJani Nikula 
785379bc100SJani Nikula 	if (is_mst || !pipe_mask)
786379bc100SJani Nikula 		return false;
787379bc100SJani Nikula 
788379bc100SJani Nikula 	*pipe = ffs(pipe_mask) - 1;
789379bc100SJani Nikula 
790379bc100SJani Nikula 	return true;
791379bc100SJani Nikula }
792379bc100SJani Nikula 
79381b55ef1SJani Nikula static enum intel_display_power_domain
794379bc100SJani Nikula intel_ddi_main_link_aux_domain(struct intel_digital_port *dig_port)
795379bc100SJani Nikula {
796379bc100SJani Nikula 	/* CNL+ HW requires corresponding AUX IOs to be powered up for PSR with
797379bc100SJani Nikula 	 * DC states enabled at the same time, while for driver initiated AUX
798379bc100SJani Nikula 	 * transfers we need the same AUX IOs to be powered but with DC states
799379bc100SJani Nikula 	 * disabled. Accordingly use the AUX power domain here which leaves DC
800379bc100SJani Nikula 	 * states enabled.
801379bc100SJani Nikula 	 * However, for non-A AUX ports the corresponding non-EDP transcoders
802379bc100SJani Nikula 	 * would have already enabled power well 2 and DC_OFF. This means we can
803379bc100SJani Nikula 	 * acquire a wider POWER_DOMAIN_AUX_{B,C,D,F} reference instead of a
804379bc100SJani Nikula 	 * specific AUX_IO reference without powering up any extra wells.
805379bc100SJani Nikula 	 * Note that PSR is enabled only on Port A even though this function
806379bc100SJani Nikula 	 * returns the correct domain for other ports too.
807379bc100SJani Nikula 	 */
808379bc100SJani Nikula 	return dig_port->aux_ch == AUX_CH_A ? POWER_DOMAIN_AUX_IO_A :
809379bc100SJani Nikula 					      intel_aux_power_domain(dig_port);
810379bc100SJani Nikula }
811379bc100SJani Nikula 
812379bc100SJani Nikula static void intel_ddi_get_power_domains(struct intel_encoder *encoder,
813379bc100SJani Nikula 					struct intel_crtc_state *crtc_state)
814379bc100SJani Nikula {
815379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
816379bc100SJani Nikula 	struct intel_digital_port *dig_port;
817d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
818379bc100SJani Nikula 
819379bc100SJani Nikula 	/*
820379bc100SJani Nikula 	 * TODO: Add support for MST encoders. Atm, the following should never
821379bc100SJani Nikula 	 * happen since fake-MST encoders don't set their get_power_domains()
822379bc100SJani Nikula 	 * hook.
823379bc100SJani Nikula 	 */
8241de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm,
8251de143ccSPankaj Bharadiya 			intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)))
826379bc100SJani Nikula 		return;
827379bc100SJani Nikula 
828b7d02c3aSVille Syrjälä 	dig_port = enc_to_dig_port(encoder);
829f77a2db2SImre Deak 
830f77a2db2SImre Deak 	if (!intel_phy_is_tc(dev_priv, phy) ||
831a4550977SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT) {
832a4550977SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
833a4550977SImre Deak 		dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
834f77a2db2SImre Deak 								   dig_port->ddi_io_power_domain);
835a4550977SImre Deak 	}
836379bc100SJani Nikula 
837379bc100SJani Nikula 	/*
838379bc100SJani Nikula 	 * AUX power is only needed for (e)DP mode, and for HDMI mode on TC
839379bc100SJani Nikula 	 * ports.
840379bc100SJani Nikula 	 */
841379bc100SJani Nikula 	if (intel_crtc_has_dp_encoder(crtc_state) ||
842162e68e1SImre Deak 	    intel_phy_is_tc(dev_priv, phy)) {
843162e68e1SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->aux_wakeref);
844162e68e1SImre Deak 		dig_port->aux_wakeref =
845379bc100SJani Nikula 			intel_display_power_get(dev_priv,
846379bc100SJani Nikula 						intel_ddi_main_link_aux_domain(dig_port));
847379bc100SJani Nikula 	}
848162e68e1SImre Deak }
849379bc100SJani Nikula 
85002a715c3SVille Syrjälä void intel_ddi_enable_pipe_clock(struct intel_encoder *encoder,
85102a715c3SVille Syrjälä 				 const struct intel_crtc_state *crtc_state)
852379bc100SJani Nikula {
8532225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
854379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
855379bc100SJani Nikula 	enum port port = encoder->port;
856379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
857379bc100SJani Nikula 
858df16b636SMahesh Kumar 	if (cpu_transcoder != TRANSCODER_EDP) {
859005e9537SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 12)
860f7960e7fSJani Nikula 			intel_de_write(dev_priv,
861f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
862df16b636SMahesh Kumar 				       TGL_TRANS_CLK_SEL_PORT(port));
863df16b636SMahesh Kumar 		else
864f7960e7fSJani Nikula 			intel_de_write(dev_priv,
865f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
866379bc100SJani Nikula 				       TRANS_CLK_SEL_PORT(port));
867379bc100SJani Nikula 	}
868df16b636SMahesh Kumar }
869379bc100SJani Nikula 
870379bc100SJani Nikula void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
871379bc100SJani Nikula {
8722225f3c6SMaarten Lankhorst 	struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
873379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
874379bc100SJani Nikula 
875df16b636SMahesh Kumar 	if (cpu_transcoder != TRANSCODER_EDP) {
876005e9537SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 12)
877f7960e7fSJani Nikula 			intel_de_write(dev_priv,
878f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
879df16b636SMahesh Kumar 				       TGL_TRANS_CLK_SEL_DISABLED);
880df16b636SMahesh Kumar 		else
881f7960e7fSJani Nikula 			intel_de_write(dev_priv,
882f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
883379bc100SJani Nikula 				       TRANS_CLK_SEL_DISABLED);
884379bc100SJani Nikula 	}
885df16b636SMahesh Kumar }
886379bc100SJani Nikula 
887379bc100SJani Nikula static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
888379bc100SJani Nikula 				enum port port, u8 iboost)
889379bc100SJani Nikula {
890379bc100SJani Nikula 	u32 tmp;
891379bc100SJani Nikula 
892f7960e7fSJani Nikula 	tmp = intel_de_read(dev_priv, DISPIO_CR_TX_BMU_CR0);
893379bc100SJani Nikula 	tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
894379bc100SJani Nikula 	if (iboost)
895379bc100SJani Nikula 		tmp |= iboost << BALANCE_LEG_SHIFT(port);
896379bc100SJani Nikula 	else
897379bc100SJani Nikula 		tmp |= BALANCE_LEG_DISABLE(port);
898f7960e7fSJani Nikula 	intel_de_write(dev_priv, DISPIO_CR_TX_BMU_CR0, tmp);
899379bc100SJani Nikula }
900379bc100SJani Nikula 
901379bc100SJani Nikula static void skl_ddi_set_iboost(struct intel_encoder *encoder,
902a621860aSVille Syrjälä 			       const struct intel_crtc_state *crtc_state,
903a621860aSVille Syrjälä 			       int level)
904379bc100SJani Nikula {
9057801f3b7SLucas De Marchi 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
906379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
907379bc100SJani Nikula 	u8 iboost;
908379bc100SJani Nikula 
909a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
910c0a950d1SJani Nikula 		iboost = intel_bios_encoder_hdmi_boost_level(encoder->devdata);
911379bc100SJani Nikula 	else
912c0a950d1SJani Nikula 		iboost = intel_bios_encoder_dp_boost_level(encoder->devdata);
913379bc100SJani Nikula 
914379bc100SJani Nikula 	if (iboost == 0) {
915379bc100SJani Nikula 		const struct ddi_buf_trans *ddi_translations;
916379bc100SJani Nikula 		int n_entries;
917379bc100SJani Nikula 
918a621860aSVille Syrjälä 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
919a8143150SJosé Roberto de Souza 			ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries);
920a621860aSVille Syrjälä 		else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
921a621860aSVille Syrjälä 			ddi_translations = intel_ddi_get_buf_trans_edp(encoder, &n_entries);
922379bc100SJani Nikula 		else
923a621860aSVille Syrjälä 			ddi_translations = intel_ddi_get_buf_trans_dp(encoder, &n_entries);
924379bc100SJani Nikula 
9251de143ccSPankaj Bharadiya 		if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
926379bc100SJani Nikula 			return;
9271de143ccSPankaj Bharadiya 		if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
928379bc100SJani Nikula 			level = n_entries - 1;
929379bc100SJani Nikula 
930379bc100SJani Nikula 		iboost = ddi_translations[level].i_boost;
931379bc100SJani Nikula 	}
932379bc100SJani Nikula 
933379bc100SJani Nikula 	/* Make sure that the requested I_boost is valid */
934379bc100SJani Nikula 	if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
93547bdb1caSJani Nikula 		drm_err(&dev_priv->drm, "Invalid I_boost value %u\n", iboost);
936379bc100SJani Nikula 		return;
937379bc100SJani Nikula 	}
938379bc100SJani Nikula 
939f0e86e05SJosé Roberto de Souza 	_skl_ddi_set_iboost(dev_priv, encoder->port, iboost);
940379bc100SJani Nikula 
941f0e86e05SJosé Roberto de Souza 	if (encoder->port == PORT_A && dig_port->max_lanes == 4)
942379bc100SJani Nikula 		_skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
943379bc100SJani Nikula }
944379bc100SJani Nikula 
945379bc100SJani Nikula static void bxt_ddi_vswing_sequence(struct intel_encoder *encoder,
946a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
947a621860aSVille Syrjälä 				    int level)
948379bc100SJani Nikula {
949379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
950379bc100SJani Nikula 	const struct bxt_ddi_buf_trans *ddi_translations;
951379bc100SJani Nikula 	enum port port = encoder->port;
952379bc100SJani Nikula 	int n_entries;
953379bc100SJani Nikula 
95499092a97SDave Airlie 	ddi_translations = bxt_get_buf_trans(encoder, crtc_state, &n_entries);
9551de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
956379bc100SJani Nikula 		return;
9571de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
958379bc100SJani Nikula 		level = n_entries - 1;
959379bc100SJani Nikula 
960379bc100SJani Nikula 	bxt_ddi_phy_set_signal_level(dev_priv, port,
961379bc100SJani Nikula 				     ddi_translations[level].margin,
962379bc100SJani Nikula 				     ddi_translations[level].scale,
963379bc100SJani Nikula 				     ddi_translations[level].enable,
964379bc100SJani Nikula 				     ddi_translations[level].deemphasis);
965379bc100SJani Nikula }
966379bc100SJani Nikula 
967a621860aSVille Syrjälä static u8 intel_ddi_dp_voltage_max(struct intel_dp *intel_dp,
968a621860aSVille Syrjälä 				   const struct intel_crtc_state *crtc_state)
969379bc100SJani Nikula {
97053de0a20SVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
971379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
972379bc100SJani Nikula 	enum port port = encoder->port;
973d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
974379bc100SJani Nikula 	int n_entries;
975379bc100SJani Nikula 
976005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
977978c3e53SClinton A Taylor 		if (intel_phy_is_combo(dev_priv, phy))
978a621860aSVille Syrjälä 			tgl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
979978c3e53SClinton A Taylor 		else
980a621860aSVille Syrjälä 			tgl_get_dkl_buf_trans(encoder, crtc_state, &n_entries);
981*93e7e61eSLucas De Marchi 	} else if (DISPLAY_VER(dev_priv) == 11) {
9821ba1014dSTejas Upadhyay 		if (IS_PLATFORM(dev_priv, INTEL_JASPERLAKE))
9831ba1014dSTejas Upadhyay 			jsl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
9841ba1014dSTejas Upadhyay 		else if (IS_PLATFORM(dev_priv, INTEL_ELKHARTLAKE))
985a621860aSVille Syrjälä 			ehl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
986b42d5a67SJosé Roberto de Souza 		else if (intel_phy_is_combo(dev_priv, phy))
987a621860aSVille Syrjälä 			icl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
988379bc100SJani Nikula 		else
989a621860aSVille Syrjälä 			icl_get_mg_buf_trans(encoder, crtc_state, &n_entries);
990379bc100SJani Nikula 	} else if (IS_CANNONLAKE(dev_priv)) {
99199092a97SDave Airlie 		cnl_get_buf_trans(encoder, crtc_state, &n_entries);
9922446e1d6SMatt Roper 	} else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
99399092a97SDave Airlie 		bxt_get_buf_trans(encoder, crtc_state, &n_entries);
994379bc100SJani Nikula 	} else {
995a621860aSVille Syrjälä 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
996f0e86e05SJosé Roberto de Souza 			intel_ddi_get_buf_trans_edp(encoder, &n_entries);
997379bc100SJani Nikula 		else
998f0e86e05SJosé Roberto de Souza 			intel_ddi_get_buf_trans_dp(encoder, &n_entries);
999379bc100SJani Nikula 	}
1000379bc100SJani Nikula 
10011de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, n_entries < 1))
1002379bc100SJani Nikula 		n_entries = 1;
10031de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm,
10041de143ccSPankaj Bharadiya 			n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
1005379bc100SJani Nikula 		n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
1006379bc100SJani Nikula 
1007379bc100SJani Nikula 	return index_to_dp_signal_levels[n_entries - 1] &
1008379bc100SJani Nikula 		DP_TRAIN_VOLTAGE_SWING_MASK;
1009379bc100SJani Nikula }
1010379bc100SJani Nikula 
1011379bc100SJani Nikula /*
1012379bc100SJani Nikula  * We assume that the full set of pre-emphasis values can be
1013379bc100SJani Nikula  * used on all DDI platforms. Should that change we need to
1014379bc100SJani Nikula  * rethink this code.
1015379bc100SJani Nikula  */
101653de0a20SVille Syrjälä static u8 intel_ddi_dp_preemph_max(struct intel_dp *intel_dp)
1017379bc100SJani Nikula {
1018379bc100SJani Nikula 	return DP_TRAIN_PRE_EMPH_LEVEL_3;
1019379bc100SJani Nikula }
1020379bc100SJani Nikula 
1021379bc100SJani Nikula static void cnl_ddi_vswing_program(struct intel_encoder *encoder,
1022a621860aSVille Syrjälä 				   const struct intel_crtc_state *crtc_state,
1023a621860aSVille Syrjälä 				   int level)
1024379bc100SJani Nikula {
1025379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1026379bc100SJani Nikula 	const struct cnl_ddi_buf_trans *ddi_translations;
1027379bc100SJani Nikula 	enum port port = encoder->port;
1028379bc100SJani Nikula 	int n_entries, ln;
1029379bc100SJani Nikula 	u32 val;
1030379bc100SJani Nikula 
103199092a97SDave Airlie 	ddi_translations = cnl_get_buf_trans(encoder, crtc_state, &n_entries);
1032379bc100SJani Nikula 
10331de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
1034379bc100SJani Nikula 		return;
10351de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1036379bc100SJani Nikula 		level = n_entries - 1;
1037379bc100SJani Nikula 
1038379bc100SJani Nikula 	/* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */
1039f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
1040379bc100SJani Nikula 	val &= ~SCALING_MODE_SEL_MASK;
1041379bc100SJani Nikula 	val |= SCALING_MODE_SEL(2);
1042f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
1043379bc100SJani Nikula 
1044379bc100SJani Nikula 	/* Program PORT_TX_DW2 */
1045f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW2_LN0(port));
1046379bc100SJani Nikula 	val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
1047379bc100SJani Nikula 		 RCOMP_SCALAR_MASK);
1048379bc100SJani Nikula 	val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
1049379bc100SJani Nikula 	val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
1050379bc100SJani Nikula 	/* Rcomp scalar is fixed as 0x98 for every table entry */
1051379bc100SJani Nikula 	val |= RCOMP_SCALAR(0x98);
1052f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW2_GRP(port), val);
1053379bc100SJani Nikula 
1054379bc100SJani Nikula 	/* Program PORT_TX_DW4 */
1055379bc100SJani Nikula 	/* We cannot write to GRP. It would overrite individual loadgen */
1056379bc100SJani Nikula 	for (ln = 0; ln < 4; ln++) {
1057f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port));
1058379bc100SJani Nikula 		val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
1059379bc100SJani Nikula 			 CURSOR_COEFF_MASK);
1060379bc100SJani Nikula 		val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
1061379bc100SJani Nikula 		val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
1062379bc100SJani Nikula 		val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
1063f7960e7fSJani Nikula 		intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val);
1064379bc100SJani Nikula 	}
1065379bc100SJani Nikula 
1066379bc100SJani Nikula 	/* Program PORT_TX_DW5 */
1067379bc100SJani Nikula 	/* All DW5 values are fixed for every table entry */
1068f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
1069379bc100SJani Nikula 	val &= ~RTERM_SELECT_MASK;
1070379bc100SJani Nikula 	val |= RTERM_SELECT(6);
1071379bc100SJani Nikula 	val |= TAP3_DISABLE;
1072f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
1073379bc100SJani Nikula 
1074379bc100SJani Nikula 	/* Program PORT_TX_DW7 */
1075f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW7_LN0(port));
1076379bc100SJani Nikula 	val &= ~N_SCALAR_MASK;
1077379bc100SJani Nikula 	val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
1078f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW7_GRP(port), val);
1079379bc100SJani Nikula }
1080379bc100SJani Nikula 
1081379bc100SJani Nikula static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder,
1082a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
1083a621860aSVille Syrjälä 				    int level)
1084379bc100SJani Nikula {
1085379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1086379bc100SJani Nikula 	enum port port = encoder->port;
1087379bc100SJani Nikula 	int width, rate, ln;
1088379bc100SJani Nikula 	u32 val;
1089379bc100SJani Nikula 
1090a621860aSVille Syrjälä 	width = crtc_state->lane_count;
1091a621860aSVille Syrjälä 	rate = crtc_state->port_clock;
1092379bc100SJani Nikula 
1093379bc100SJani Nikula 	/*
1094379bc100SJani Nikula 	 * 1. If port type is eDP or DP,
1095379bc100SJani Nikula 	 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
1096379bc100SJani Nikula 	 * else clear to 0b.
1097379bc100SJani Nikula 	 */
1098f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_PCS_DW1_LN0(port));
1099a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1100379bc100SJani Nikula 		val &= ~COMMON_KEEPER_EN;
1101a621860aSVille Syrjälä 	else
1102a621860aSVille Syrjälä 		val |= COMMON_KEEPER_EN;
1103f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_PCS_DW1_GRP(port), val);
1104379bc100SJani Nikula 
1105379bc100SJani Nikula 	/* 2. Program loadgen select */
1106379bc100SJani Nikula 	/*
1107379bc100SJani Nikula 	 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
1108379bc100SJani Nikula 	 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
1109379bc100SJani Nikula 	 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
1110379bc100SJani Nikula 	 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
1111379bc100SJani Nikula 	 */
1112379bc100SJani Nikula 	for (ln = 0; ln <= 3; ln++) {
1113f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port));
1114379bc100SJani Nikula 		val &= ~LOADGEN_SELECT;
1115379bc100SJani Nikula 
1116379bc100SJani Nikula 		if ((rate <= 600000 && width == 4 && ln >= 1)  ||
1117379bc100SJani Nikula 		    (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
1118379bc100SJani Nikula 			val |= LOADGEN_SELECT;
1119379bc100SJani Nikula 		}
1120f7960e7fSJani Nikula 		intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val);
1121379bc100SJani Nikula 	}
1122379bc100SJani Nikula 
1123379bc100SJani Nikula 	/* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
1124f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_CL1CM_DW5);
1125379bc100SJani Nikula 	val |= SUS_CLOCK_CONFIG;
1126f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_CL1CM_DW5, val);
1127379bc100SJani Nikula 
1128379bc100SJani Nikula 	/* 4. Clear training enable to change swing values */
1129f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
1130379bc100SJani Nikula 	val &= ~TX_TRAINING_EN;
1131f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
1132379bc100SJani Nikula 
1133379bc100SJani Nikula 	/* 5. Program swing and de-emphasis */
1134a621860aSVille Syrjälä 	cnl_ddi_vswing_program(encoder, crtc_state, level);
1135379bc100SJani Nikula 
1136379bc100SJani Nikula 	/* 6. Set training enable to trigger update */
1137f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
1138379bc100SJani Nikula 	val |= TX_TRAINING_EN;
1139f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
1140379bc100SJani Nikula }
1141379bc100SJani Nikula 
1142a8143150SJosé Roberto de Souza static void icl_ddi_combo_vswing_program(struct intel_encoder *encoder,
1143a621860aSVille Syrjälä 					 const struct intel_crtc_state *crtc_state,
1144a621860aSVille Syrjälä 					 int level)
1145379bc100SJani Nikula {
1146a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1147a621860aSVille Syrjälä 	const struct cnl_ddi_buf_trans *ddi_translations;
1148f0e86e05SJosé Roberto de Souza 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1149a621860aSVille Syrjälä 	int n_entries, ln;
1150a621860aSVille Syrjälä 	u32 val;
1151379bc100SJani Nikula 
1152005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
1153a621860aSVille Syrjälä 		ddi_translations = tgl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
11541ba1014dSTejas Upadhyay 	else if (IS_PLATFORM(dev_priv, INTEL_JASPERLAKE))
11551ba1014dSTejas Upadhyay 		ddi_translations = jsl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
11561ba1014dSTejas Upadhyay 	else if (IS_PLATFORM(dev_priv, INTEL_ELKHARTLAKE))
1157a621860aSVille Syrjälä 		ddi_translations = ehl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
1158bd3cf6f7SJosé Roberto de Souza 	else
1159a621860aSVille Syrjälä 		ddi_translations = icl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
1160379bc100SJani Nikula 
116185da0292SVille Syrjälä 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
116285da0292SVille Syrjälä 		return;
116385da0292SVille Syrjälä 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1164379bc100SJani Nikula 		level = n_entries - 1;
1165379bc100SJani Nikula 
1166a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) {
116781619f4aSJosé Roberto de Souza 		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
116881619f4aSJosé Roberto de Souza 
116981619f4aSJosé Roberto de Souza 		val = EDP4K2K_MODE_OVRD_EN | EDP4K2K_MODE_OVRD_OPTIMIZED;
117081619f4aSJosé Roberto de Souza 		intel_dp->hobl_active = is_hobl_buf_trans(ddi_translations);
117181619f4aSJosé Roberto de Souza 		intel_de_rmw(dev_priv, ICL_PORT_CL_DW10(phy), val,
117281619f4aSJosé Roberto de Souza 			     intel_dp->hobl_active ? val : 0);
117381619f4aSJosé Roberto de Souza 	}
117481619f4aSJosé Roberto de Souza 
1175379bc100SJani Nikula 	/* Set PORT_TX_DW5 */
1176f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
1177379bc100SJani Nikula 	val &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK |
1178379bc100SJani Nikula 		  TAP2_DISABLE | TAP3_DISABLE);
1179379bc100SJani Nikula 	val |= SCALING_MODE_SEL(0x2);
1180379bc100SJani Nikula 	val |= RTERM_SELECT(0x6);
1181379bc100SJani Nikula 	val |= TAP3_DISABLE;
1182f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
1183379bc100SJani Nikula 
1184379bc100SJani Nikula 	/* Program PORT_TX_DW2 */
1185f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN0(phy));
1186379bc100SJani Nikula 	val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
1187379bc100SJani Nikula 		 RCOMP_SCALAR_MASK);
1188379bc100SJani Nikula 	val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
1189379bc100SJani Nikula 	val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
1190379bc100SJani Nikula 	/* Program Rcomp scalar for every table entry */
1191379bc100SJani Nikula 	val |= RCOMP_SCALAR(0x98);
1192f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), val);
1193379bc100SJani Nikula 
1194379bc100SJani Nikula 	/* Program PORT_TX_DW4 */
1195379bc100SJani Nikula 	/* We cannot write to GRP. It would overwrite individual loadgen. */
1196379bc100SJani Nikula 	for (ln = 0; ln <= 3; ln++) {
1197f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy));
1198379bc100SJani Nikula 		val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
1199379bc100SJani Nikula 			 CURSOR_COEFF_MASK);
1200379bc100SJani Nikula 		val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
1201379bc100SJani Nikula 		val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
1202379bc100SJani Nikula 		val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
1203f7960e7fSJani Nikula 		intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val);
1204379bc100SJani Nikula 	}
1205379bc100SJani Nikula 
1206379bc100SJani Nikula 	/* Program PORT_TX_DW7 */
1207f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW7_LN0(phy));
1208379bc100SJani Nikula 	val &= ~N_SCALAR_MASK;
1209379bc100SJani Nikula 	val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
1210f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW7_GRP(phy), val);
1211379bc100SJani Nikula }
1212379bc100SJani Nikula 
1213379bc100SJani Nikula static void icl_combo_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
1214a621860aSVille Syrjälä 					      const struct intel_crtc_state *crtc_state,
1215a621860aSVille Syrjälä 					      int level)
1216379bc100SJani Nikula {
1217379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1218dc867bc7SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1219a621860aSVille Syrjälä 	int width, rate, ln;
1220379bc100SJani Nikula 	u32 val;
1221379bc100SJani Nikula 
1222a621860aSVille Syrjälä 	width = crtc_state->lane_count;
1223a621860aSVille Syrjälä 	rate = crtc_state->port_clock;
1224379bc100SJani Nikula 
1225379bc100SJani Nikula 	/*
1226379bc100SJani Nikula 	 * 1. If port type is eDP or DP,
1227379bc100SJani Nikula 	 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
1228379bc100SJani Nikula 	 * else clear to 0b.
1229379bc100SJani Nikula 	 */
1230f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN0(phy));
1231a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1232379bc100SJani Nikula 		val &= ~COMMON_KEEPER_EN;
1233379bc100SJani Nikula 	else
1234379bc100SJani Nikula 		val |= COMMON_KEEPER_EN;
1235f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), val);
1236379bc100SJani Nikula 
1237379bc100SJani Nikula 	/* 2. Program loadgen select */
1238379bc100SJani Nikula 	/*
1239379bc100SJani Nikula 	 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
1240379bc100SJani Nikula 	 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
1241379bc100SJani Nikula 	 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
1242379bc100SJani Nikula 	 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
1243379bc100SJani Nikula 	 */
1244379bc100SJani Nikula 	for (ln = 0; ln <= 3; ln++) {
1245f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy));
1246379bc100SJani Nikula 		val &= ~LOADGEN_SELECT;
1247379bc100SJani Nikula 
1248379bc100SJani Nikula 		if ((rate <= 600000 && width == 4 && ln >= 1) ||
1249379bc100SJani Nikula 		    (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
1250379bc100SJani Nikula 			val |= LOADGEN_SELECT;
1251379bc100SJani Nikula 		}
1252f7960e7fSJani Nikula 		intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val);
1253379bc100SJani Nikula 	}
1254379bc100SJani Nikula 
1255379bc100SJani Nikula 	/* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
1256f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_CL_DW5(phy));
1257379bc100SJani Nikula 	val |= SUS_CLOCK_CONFIG;
1258f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_CL_DW5(phy), val);
1259379bc100SJani Nikula 
1260379bc100SJani Nikula 	/* 4. Clear training enable to change swing values */
1261f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
1262379bc100SJani Nikula 	val &= ~TX_TRAINING_EN;
1263f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
1264379bc100SJani Nikula 
1265379bc100SJani Nikula 	/* 5. Program swing and de-emphasis */
1266a621860aSVille Syrjälä 	icl_ddi_combo_vswing_program(encoder, crtc_state, level);
1267379bc100SJani Nikula 
1268379bc100SJani Nikula 	/* 6. Set training enable to trigger update */
1269f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
1270379bc100SJani Nikula 	val |= TX_TRAINING_EN;
1271f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
1272379bc100SJani Nikula }
1273379bc100SJani Nikula 
1274379bc100SJani Nikula static void icl_mg_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
1275a621860aSVille Syrjälä 					   const struct intel_crtc_state *crtc_state,
1276a621860aSVille Syrjälä 					   int level)
1277379bc100SJani Nikula {
1278379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1279f21e8b80SJosé Roberto de Souza 	enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port);
1280379bc100SJani Nikula 	const struct icl_mg_phy_ddi_buf_trans *ddi_translations;
1281a621860aSVille Syrjälä 	int n_entries, ln;
1282a621860aSVille Syrjälä 	u32 val;
1283379bc100SJani Nikula 
1284f8c6b615SVille Syrjälä 	if (enc_to_dig_port(encoder)->tc_mode == TC_PORT_TBT_ALT)
1285f8c6b615SVille Syrjälä 		return;
1286f8c6b615SVille Syrjälä 
1287a621860aSVille Syrjälä 	ddi_translations = icl_get_mg_buf_trans(encoder, crtc_state, &n_entries);
128885da0292SVille Syrjälä 
128985da0292SVille Syrjälä 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
129085da0292SVille Syrjälä 		return;
129185da0292SVille Syrjälä 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
12925ec34647SVille Syrjälä 		level = n_entries - 1;
1293379bc100SJani Nikula 
1294379bc100SJani Nikula 	/* Set MG_TX_LINK_PARAMS cri_use_fs32 to 0. */
1295379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
1296f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port));
1297379bc100SJani Nikula 		val &= ~CRI_USE_FS32;
1298f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port), val);
1299379bc100SJani Nikula 
1300f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port));
1301379bc100SJani Nikula 		val &= ~CRI_USE_FS32;
1302f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port), val);
1303379bc100SJani Nikula 	}
1304379bc100SJani Nikula 
1305379bc100SJani Nikula 	/* Program MG_TX_SWINGCTRL with values from vswing table */
1306379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
1307f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port));
1308379bc100SJani Nikula 		val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK;
1309379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_17_12(
1310379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_17_12);
1311f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port), val);
1312379bc100SJani Nikula 
1313f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port));
1314379bc100SJani Nikula 		val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK;
1315379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_17_12(
1316379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_17_12);
1317f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port), val);
1318379bc100SJani Nikula 	}
1319379bc100SJani Nikula 
1320379bc100SJani Nikula 	/* Program MG_TX_DRVCTRL with values from vswing table */
1321379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
1322f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_DRVCTRL(ln, tc_port));
1323379bc100SJani Nikula 		val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK |
1324379bc100SJani Nikula 			 CRI_TXDEEMPH_OVERRIDE_5_0_MASK);
1325379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_5_0(
1326379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_5_0) |
1327379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_11_6(
1328379bc100SJani Nikula 				ddi_translations[level].cri_txdeemph_override_11_6) |
1329379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_EN;
1330f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_DRVCTRL(ln, tc_port), val);
1331379bc100SJani Nikula 
1332f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_DRVCTRL(ln, tc_port));
1333379bc100SJani Nikula 		val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK |
1334379bc100SJani Nikula 			 CRI_TXDEEMPH_OVERRIDE_5_0_MASK);
1335379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_5_0(
1336379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_5_0) |
1337379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_11_6(
1338379bc100SJani Nikula 				ddi_translations[level].cri_txdeemph_override_11_6) |
1339379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_EN;
1340f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_DRVCTRL(ln, tc_port), val);
1341379bc100SJani Nikula 
1342379bc100SJani Nikula 		/* FIXME: Program CRI_LOADGEN_SEL after the spec is updated */
1343379bc100SJani Nikula 	}
1344379bc100SJani Nikula 
1345379bc100SJani Nikula 	/*
1346379bc100SJani Nikula 	 * Program MG_CLKHUB<LN, port being used> with value from frequency table
1347379bc100SJani Nikula 	 * In case of Legacy mode on MG PHY, both TX1 and TX2 enabled so use the
1348379bc100SJani Nikula 	 * values from table for which TX1 and TX2 enabled.
1349379bc100SJani Nikula 	 */
1350379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
1351f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_CLKHUB(ln, tc_port));
1352a621860aSVille Syrjälä 		if (crtc_state->port_clock < 300000)
1353379bc100SJani Nikula 			val |= CFG_LOW_RATE_LKREN_EN;
1354379bc100SJani Nikula 		else
1355379bc100SJani Nikula 			val &= ~CFG_LOW_RATE_LKREN_EN;
1356f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_CLKHUB(ln, tc_port), val);
1357379bc100SJani Nikula 	}
1358379bc100SJani Nikula 
1359379bc100SJani Nikula 	/* Program the MG_TX_DCC<LN, port being used> based on the link frequency */
1360379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
1361f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_DCC(ln, tc_port));
1362379bc100SJani Nikula 		val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK;
1363a621860aSVille Syrjälä 		if (crtc_state->port_clock <= 500000) {
1364379bc100SJani Nikula 			val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN;
1365379bc100SJani Nikula 		} else {
1366379bc100SJani Nikula 			val |= CFG_AMI_CK_DIV_OVERRIDE_EN |
1367379bc100SJani Nikula 				CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
1368379bc100SJani Nikula 		}
1369f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_DCC(ln, tc_port), val);
1370379bc100SJani Nikula 
1371f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_DCC(ln, tc_port));
1372379bc100SJani Nikula 		val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK;
1373a621860aSVille Syrjälä 		if (crtc_state->port_clock <= 500000) {
1374379bc100SJani Nikula 			val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN;
1375379bc100SJani Nikula 		} else {
1376379bc100SJani Nikula 			val |= CFG_AMI_CK_DIV_OVERRIDE_EN |
1377379bc100SJani Nikula 				CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
1378379bc100SJani Nikula 		}
1379f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_DCC(ln, tc_port), val);
1380379bc100SJani Nikula 	}
1381379bc100SJani Nikula 
1382379bc100SJani Nikula 	/* Program MG_TX_PISO_READLOAD with values from vswing table */
1383379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
1384f7960e7fSJani Nikula 		val = intel_de_read(dev_priv,
1385f7960e7fSJani Nikula 				    MG_TX1_PISO_READLOAD(ln, tc_port));
1386379bc100SJani Nikula 		val |= CRI_CALCINIT;
1387f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_PISO_READLOAD(ln, tc_port),
1388f7960e7fSJani Nikula 			       val);
1389379bc100SJani Nikula 
1390f7960e7fSJani Nikula 		val = intel_de_read(dev_priv,
1391f7960e7fSJani Nikula 				    MG_TX2_PISO_READLOAD(ln, tc_port));
1392379bc100SJani Nikula 		val |= CRI_CALCINIT;
1393f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_PISO_READLOAD(ln, tc_port),
1394f7960e7fSJani Nikula 			       val);
1395379bc100SJani Nikula 	}
1396379bc100SJani Nikula }
1397379bc100SJani Nikula 
1398379bc100SJani Nikula static void icl_ddi_vswing_sequence(struct intel_encoder *encoder,
1399a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
1400a621860aSVille Syrjälä 				    int level)
1401379bc100SJani Nikula {
1402379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1403d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1404379bc100SJani Nikula 
1405d8fe2ab6SMatt Roper 	if (intel_phy_is_combo(dev_priv, phy))
1406a621860aSVille Syrjälä 		icl_combo_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1407379bc100SJani Nikula 	else
1408a621860aSVille Syrjälä 		icl_mg_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1409379bc100SJani Nikula }
1410379bc100SJani Nikula 
1411978c3e53SClinton A Taylor static void
1412a621860aSVille Syrjälä tgl_dkl_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
1413a621860aSVille Syrjälä 				const struct intel_crtc_state *crtc_state,
1414a621860aSVille Syrjälä 				int level)
1415978c3e53SClinton A Taylor {
1416978c3e53SClinton A Taylor 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1417978c3e53SClinton A Taylor 	enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port);
1418978c3e53SClinton A Taylor 	const struct tgl_dkl_phy_ddi_buf_trans *ddi_translations;
1419a621860aSVille Syrjälä 	u32 val, dpcnt_mask, dpcnt_val;
1420a621860aSVille Syrjälä 	int n_entries, ln;
1421978c3e53SClinton A Taylor 
1422f8c6b615SVille Syrjälä 	if (enc_to_dig_port(encoder)->tc_mode == TC_PORT_TBT_ALT)
1423f8c6b615SVille Syrjälä 		return;
1424f8c6b615SVille Syrjälä 
1425a621860aSVille Syrjälä 	ddi_translations = tgl_get_dkl_buf_trans(encoder, crtc_state, &n_entries);
14269fa67699SJosé Roberto de Souza 
142785da0292SVille Syrjälä 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
142885da0292SVille Syrjälä 		return;
142985da0292SVille Syrjälä 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1430978c3e53SClinton A Taylor 		level = n_entries - 1;
1431978c3e53SClinton A Taylor 
1432978c3e53SClinton A Taylor 	dpcnt_mask = (DKL_TX_PRESHOOT_COEFF_MASK |
1433978c3e53SClinton A Taylor 		      DKL_TX_DE_EMPAHSIS_COEFF_MASK |
1434978c3e53SClinton A Taylor 		      DKL_TX_VSWING_CONTROL_MASK);
1435978c3e53SClinton A Taylor 	dpcnt_val = DKL_TX_VSWING_CONTROL(ddi_translations[level].dkl_vswing_control);
1436978c3e53SClinton A Taylor 	dpcnt_val |= DKL_TX_DE_EMPHASIS_COEFF(ddi_translations[level].dkl_de_emphasis_control);
1437978c3e53SClinton A Taylor 	dpcnt_val |= DKL_TX_PRESHOOT_COEFF(ddi_translations[level].dkl_preshoot_control);
1438978c3e53SClinton A Taylor 
1439978c3e53SClinton A Taylor 	for (ln = 0; ln < 2; ln++) {
1440f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
1441f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, ln));
1442978c3e53SClinton A Taylor 
1443f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_PMD_LANE_SUS(tc_port), 0);
14442d69c42eSJosé Roberto de Souza 
1445978c3e53SClinton A Taylor 		/* All the registers are RMW */
1446f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DKL_TX_DPCNTL0(tc_port));
1447978c3e53SClinton A Taylor 		val &= ~dpcnt_mask;
1448978c3e53SClinton A Taylor 		val |= dpcnt_val;
1449f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_DPCNTL0(tc_port), val);
1450978c3e53SClinton A Taylor 
1451f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DKL_TX_DPCNTL1(tc_port));
1452978c3e53SClinton A Taylor 		val &= ~dpcnt_mask;
1453978c3e53SClinton A Taylor 		val |= dpcnt_val;
1454f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_DPCNTL1(tc_port), val);
1455978c3e53SClinton A Taylor 
1456f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DKL_TX_DPCNTL2(tc_port));
1457978c3e53SClinton A Taylor 		val &= ~DKL_TX_DP20BITMODE;
1458f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_DPCNTL2(tc_port), val);
1459978c3e53SClinton A Taylor 	}
1460978c3e53SClinton A Taylor }
1461978c3e53SClinton A Taylor 
1462978c3e53SClinton A Taylor static void tgl_ddi_vswing_sequence(struct intel_encoder *encoder,
1463a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
1464a621860aSVille Syrjälä 				    int level)
1465978c3e53SClinton A Taylor {
1466978c3e53SClinton A Taylor 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1467978c3e53SClinton A Taylor 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1468978c3e53SClinton A Taylor 
1469978c3e53SClinton A Taylor 	if (intel_phy_is_combo(dev_priv, phy))
1470a621860aSVille Syrjälä 		icl_combo_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1471978c3e53SClinton A Taylor 	else
1472a621860aSVille Syrjälä 		tgl_dkl_phy_ddi_vswing_sequence(encoder, crtc_state, level);
1473978c3e53SClinton A Taylor }
1474978c3e53SClinton A Taylor 
1475a621860aSVille Syrjälä static int translate_signal_level(struct intel_dp *intel_dp,
1476a621860aSVille Syrjälä 				  u8 signal_levels)
1477379bc100SJani Nikula {
14788b4f2137SPankaj Bharadiya 	struct drm_i915_private *i915 = dp_to_i915(intel_dp);
1479379bc100SJani Nikula 	int i;
1480379bc100SJani Nikula 
1481379bc100SJani Nikula 	for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
1482379bc100SJani Nikula 		if (index_to_dp_signal_levels[i] == signal_levels)
1483379bc100SJani Nikula 			return i;
1484379bc100SJani Nikula 	}
1485379bc100SJani Nikula 
14868b4f2137SPankaj Bharadiya 	drm_WARN(&i915->drm, 1,
14878b4f2137SPankaj Bharadiya 		 "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
1488379bc100SJani Nikula 		 signal_levels);
1489379bc100SJani Nikula 
1490379bc100SJani Nikula 	return 0;
1491379bc100SJani Nikula }
1492379bc100SJani Nikula 
1493a621860aSVille Syrjälä static int intel_ddi_dp_level(struct intel_dp *intel_dp)
1494379bc100SJani Nikula {
1495379bc100SJani Nikula 	u8 train_set = intel_dp->train_set[0];
1496a621860aSVille Syrjälä 	u8 signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1497379bc100SJani Nikula 					DP_TRAIN_PRE_EMPHASIS_MASK);
1498379bc100SJani Nikula 
14998b4f2137SPankaj Bharadiya 	return translate_signal_level(intel_dp, signal_levels);
1500379bc100SJani Nikula }
1501379bc100SJani Nikula 
1502fb83f72cSVille Syrjälä static void
1503a621860aSVille Syrjälä tgl_set_signal_levels(struct intel_dp *intel_dp,
1504a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
1505379bc100SJani Nikula {
1506fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1507379bc100SJani Nikula 	int level = intel_ddi_dp_level(intel_dp);
1508379bc100SJani Nikula 
1509a621860aSVille Syrjälä 	tgl_ddi_vswing_sequence(encoder, crtc_state, level);
1510379bc100SJani Nikula }
1511379bc100SJani Nikula 
1512fb83f72cSVille Syrjälä static void
1513a621860aSVille Syrjälä icl_set_signal_levels(struct intel_dp *intel_dp,
1514a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
1515379bc100SJani Nikula {
1516fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1517379bc100SJani Nikula 	int level = intel_ddi_dp_level(intel_dp);
1518379bc100SJani Nikula 
1519a621860aSVille Syrjälä 	icl_ddi_vswing_sequence(encoder, crtc_state, level);
1520fb83f72cSVille Syrjälä }
1521fb83f72cSVille Syrjälä 
1522fb83f72cSVille Syrjälä static void
1523a621860aSVille Syrjälä cnl_set_signal_levels(struct intel_dp *intel_dp,
1524a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
1525fb83f72cSVille Syrjälä {
1526fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1527fb83f72cSVille Syrjälä 	int level = intel_ddi_dp_level(intel_dp);
1528fb83f72cSVille Syrjälä 
1529a621860aSVille Syrjälä 	cnl_ddi_vswing_sequence(encoder, crtc_state, level);
1530fb83f72cSVille Syrjälä }
1531fb83f72cSVille Syrjälä 
1532fb83f72cSVille Syrjälä static void
1533a621860aSVille Syrjälä bxt_set_signal_levels(struct intel_dp *intel_dp,
1534a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
1535fb83f72cSVille Syrjälä {
1536fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1537fb83f72cSVille Syrjälä 	int level = intel_ddi_dp_level(intel_dp);
1538fb83f72cSVille Syrjälä 
1539a621860aSVille Syrjälä 	bxt_ddi_vswing_sequence(encoder, crtc_state, level);
1540fb83f72cSVille Syrjälä }
1541fb83f72cSVille Syrjälä 
1542fb83f72cSVille Syrjälä static void
1543a621860aSVille Syrjälä hsw_set_signal_levels(struct intel_dp *intel_dp,
1544a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
1545fb83f72cSVille Syrjälä {
1546fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1547fb83f72cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1548fb83f72cSVille Syrjälä 	int level = intel_ddi_dp_level(intel_dp);
1549fb83f72cSVille Syrjälä 	enum port port = encoder->port;
1550fb83f72cSVille Syrjälä 	u32 signal_levels;
1551fb83f72cSVille Syrjälä 
1552fb83f72cSVille Syrjälä 	signal_levels = DDI_BUF_TRANS_SELECT(level);
1553fb83f72cSVille Syrjälä 
1554fb83f72cSVille Syrjälä 	drm_dbg_kms(&dev_priv->drm, "Using signal levels %08x\n",
1555fb83f72cSVille Syrjälä 		    signal_levels);
1556fb83f72cSVille Syrjälä 
1557fb83f72cSVille Syrjälä 	intel_dp->DP &= ~DDI_BUF_EMP_MASK;
1558fb83f72cSVille Syrjälä 	intel_dp->DP |= signal_levels;
1559fb83f72cSVille Syrjälä 
1560*93e7e61eSLucas De Marchi 	if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv))
1561a621860aSVille Syrjälä 		skl_ddi_set_iboost(encoder, crtc_state, level);
1562379bc100SJani Nikula 
1563fb83f72cSVille Syrjälä 	intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP);
1564fb83f72cSVille Syrjälä 	intel_de_posting_read(dev_priv, DDI_BUF_CTL(port));
1565379bc100SJani Nikula }
1566379bc100SJani Nikula 
15679c6a5c35SVille Syrjälä static void _cnl_ddi_enable_clock(struct drm_i915_private *i915, i915_reg_t reg,
15689c6a5c35SVille Syrjälä 				  u32 clk_sel_mask, u32 clk_sel, u32 clk_off)
15699c6a5c35SVille Syrjälä {
15709c6a5c35SVille Syrjälä 	mutex_lock(&i915->dpll.lock);
15719c6a5c35SVille Syrjälä 
15729c6a5c35SVille Syrjälä 	intel_de_rmw(i915, reg, clk_sel_mask, clk_sel);
15739c6a5c35SVille Syrjälä 
15749c6a5c35SVille Syrjälä 	/*
15759c6a5c35SVille Syrjälä 	 * "This step and the step before must be
15769c6a5c35SVille Syrjälä 	 *  done with separate register writes."
15779c6a5c35SVille Syrjälä 	 */
15789c6a5c35SVille Syrjälä 	intel_de_rmw(i915, reg, clk_off, 0);
15799c6a5c35SVille Syrjälä 
15809c6a5c35SVille Syrjälä 	mutex_unlock(&i915->dpll.lock);
15819c6a5c35SVille Syrjälä }
15829c6a5c35SVille Syrjälä 
15839c6a5c35SVille Syrjälä static void _cnl_ddi_disable_clock(struct drm_i915_private *i915, i915_reg_t reg,
15849c6a5c35SVille Syrjälä 				   u32 clk_off)
15859c6a5c35SVille Syrjälä {
15869c6a5c35SVille Syrjälä 	mutex_lock(&i915->dpll.lock);
15879c6a5c35SVille Syrjälä 
15889c6a5c35SVille Syrjälä 	intel_de_rmw(i915, reg, 0, clk_off);
15899c6a5c35SVille Syrjälä 
15909c6a5c35SVille Syrjälä 	mutex_unlock(&i915->dpll.lock);
15919c6a5c35SVille Syrjälä }
15929c6a5c35SVille Syrjälä 
15930fbd8694SVille Syrjälä static bool _cnl_ddi_is_clock_enabled(struct drm_i915_private *i915, i915_reg_t reg,
15940fbd8694SVille Syrjälä 				      u32 clk_off)
15950fbd8694SVille Syrjälä {
15960fbd8694SVille Syrjälä 	return !(intel_de_read(i915, reg) & clk_off);
15970fbd8694SVille Syrjälä }
15980fbd8694SVille Syrjälä 
1599351221ffSVille Syrjälä static struct intel_shared_dpll *
1600351221ffSVille Syrjälä _cnl_ddi_get_pll(struct drm_i915_private *i915, i915_reg_t reg,
1601351221ffSVille Syrjälä 		 u32 clk_sel_mask, u32 clk_sel_shift)
1602351221ffSVille Syrjälä {
1603351221ffSVille Syrjälä 	enum intel_dpll_id id;
1604351221ffSVille Syrjälä 
1605351221ffSVille Syrjälä 	id = (intel_de_read(i915, reg) & clk_sel_mask) >> clk_sel_shift;
1606351221ffSVille Syrjälä 
1607351221ffSVille Syrjälä 	return intel_get_shared_dpll_by_id(i915, id);
1608351221ffSVille Syrjälä }
1609351221ffSVille Syrjälä 
161040b316d4SVille Syrjälä static void adls_ddi_enable_clock(struct intel_encoder *encoder,
161140b316d4SVille Syrjälä 				  const struct intel_crtc_state *crtc_state)
161240b316d4SVille Syrjälä {
161340b316d4SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
161440b316d4SVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
161540b316d4SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
161640b316d4SVille Syrjälä 
161740b316d4SVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
161840b316d4SVille Syrjälä 		return;
161940b316d4SVille Syrjälä 
162040b316d4SVille Syrjälä 	_cnl_ddi_enable_clock(i915, ADLS_DPCLKA_CFGCR(phy),
162140b316d4SVille Syrjälä 			      ADLS_DPCLKA_CFGCR_DDI_CLK_SEL_MASK(phy),
162240b316d4SVille Syrjälä 			      pll->info->id << ADLS_DPCLKA_CFGCR_DDI_SHIFT(phy),
162340b316d4SVille Syrjälä 			      ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
162440b316d4SVille Syrjälä }
162540b316d4SVille Syrjälä 
162640b316d4SVille Syrjälä static void adls_ddi_disable_clock(struct intel_encoder *encoder)
162740b316d4SVille Syrjälä {
162840b316d4SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
162940b316d4SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
163040b316d4SVille Syrjälä 
163140b316d4SVille Syrjälä 	_cnl_ddi_disable_clock(i915, ADLS_DPCLKA_CFGCR(phy),
163240b316d4SVille Syrjälä 			       ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
163340b316d4SVille Syrjälä }
163440b316d4SVille Syrjälä 
16350fbd8694SVille Syrjälä static bool adls_ddi_is_clock_enabled(struct intel_encoder *encoder)
16360fbd8694SVille Syrjälä {
16370fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
16380fbd8694SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
16390fbd8694SVille Syrjälä 
16400fbd8694SVille Syrjälä 	return _cnl_ddi_is_clock_enabled(i915, ADLS_DPCLKA_CFGCR(phy),
16410fbd8694SVille Syrjälä 					 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
16420fbd8694SVille Syrjälä }
16430fbd8694SVille Syrjälä 
1644351221ffSVille Syrjälä static struct intel_shared_dpll *adls_ddi_get_pll(struct intel_encoder *encoder)
1645351221ffSVille Syrjälä {
1646351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1647351221ffSVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
1648351221ffSVille Syrjälä 
1649351221ffSVille Syrjälä 	return _cnl_ddi_get_pll(i915, ADLS_DPCLKA_CFGCR(phy),
1650351221ffSVille Syrjälä 				ADLS_DPCLKA_CFGCR_DDI_CLK_SEL_MASK(phy),
1651351221ffSVille Syrjälä 				ADLS_DPCLKA_CFGCR_DDI_SHIFT(phy));
1652351221ffSVille Syrjälä }
1653351221ffSVille Syrjälä 
165440b316d4SVille Syrjälä static void rkl_ddi_enable_clock(struct intel_encoder *encoder,
165540b316d4SVille Syrjälä 				 const struct intel_crtc_state *crtc_state)
165640b316d4SVille Syrjälä {
165740b316d4SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
165840b316d4SVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
165940b316d4SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
166040b316d4SVille Syrjälä 
166140b316d4SVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
166240b316d4SVille Syrjälä 		return;
166340b316d4SVille Syrjälä 
166440b316d4SVille Syrjälä 	_cnl_ddi_enable_clock(i915, ICL_DPCLKA_CFGCR0,
166540b316d4SVille Syrjälä 			      RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
166640b316d4SVille Syrjälä 			      RKL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy),
166740b316d4SVille Syrjälä 			      RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
166840b316d4SVille Syrjälä }
166940b316d4SVille Syrjälä 
167040b316d4SVille Syrjälä static void rkl_ddi_disable_clock(struct intel_encoder *encoder)
167140b316d4SVille Syrjälä {
167240b316d4SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
167340b316d4SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
167440b316d4SVille Syrjälä 
167540b316d4SVille Syrjälä 	_cnl_ddi_disable_clock(i915, ICL_DPCLKA_CFGCR0,
167640b316d4SVille Syrjälä 			       RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
167740b316d4SVille Syrjälä }
167840b316d4SVille Syrjälä 
16790fbd8694SVille Syrjälä static bool rkl_ddi_is_clock_enabled(struct intel_encoder *encoder)
16800fbd8694SVille Syrjälä {
16810fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
16820fbd8694SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
16830fbd8694SVille Syrjälä 
16840fbd8694SVille Syrjälä 	return _cnl_ddi_is_clock_enabled(i915, ICL_DPCLKA_CFGCR0,
16850fbd8694SVille Syrjälä 					 RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
16860fbd8694SVille Syrjälä }
16870fbd8694SVille Syrjälä 
1688351221ffSVille Syrjälä static struct intel_shared_dpll *rkl_ddi_get_pll(struct intel_encoder *encoder)
1689351221ffSVille Syrjälä {
1690351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1691351221ffSVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
1692351221ffSVille Syrjälä 
1693351221ffSVille Syrjälä 	return _cnl_ddi_get_pll(i915, ICL_DPCLKA_CFGCR0,
1694351221ffSVille Syrjälä 				RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1695351221ffSVille Syrjälä 				RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy));
1696351221ffSVille Syrjälä }
1697351221ffSVille Syrjälä 
169835bb6b1aSVille Syrjälä static void dg1_ddi_enable_clock(struct intel_encoder *encoder,
169911ffe972SLucas De Marchi 				 const struct intel_crtc_state *crtc_state)
170011ffe972SLucas De Marchi {
170197a24a70SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
17029c6a5c35SVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
170397a24a70SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
170411ffe972SLucas De Marchi 
170597a24a70SVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
1706f67a008eSVille Syrjälä 		return;
1707f67a008eSVille Syrjälä 
170811ffe972SLucas De Marchi 	/*
170911ffe972SLucas De Marchi 	 * If we fail this, something went very wrong: first 2 PLLs should be
171011ffe972SLucas De Marchi 	 * used by first 2 phys and last 2 PLLs by last phys
171111ffe972SLucas De Marchi 	 */
171297a24a70SVille Syrjälä 	if (drm_WARN_ON(&i915->drm,
171311ffe972SLucas De Marchi 			(pll->info->id < DPLL_ID_DG1_DPLL2 && phy >= PHY_C) ||
171411ffe972SLucas De Marchi 			(pll->info->id >= DPLL_ID_DG1_DPLL2 && phy < PHY_C)))
171511ffe972SLucas De Marchi 		return;
171611ffe972SLucas De Marchi 
171797a24a70SVille Syrjälä 	_cnl_ddi_enable_clock(i915, DG1_DPCLKA_CFGCR0(phy),
17187815ed88SVille Syrjälä 			      DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
17199c6a5c35SVille Syrjälä 			      DG1_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy),
17209c6a5c35SVille Syrjälä 			      DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
172111ffe972SLucas De Marchi }
172211ffe972SLucas De Marchi 
172335bb6b1aSVille Syrjälä static void dg1_ddi_disable_clock(struct intel_encoder *encoder)
172435bb6b1aSVille Syrjälä {
172597a24a70SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
172697a24a70SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
172735bb6b1aSVille Syrjälä 
172897a24a70SVille Syrjälä 	_cnl_ddi_disable_clock(i915, DG1_DPCLKA_CFGCR0(phy),
17299c6a5c35SVille Syrjälä 			       DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
173035bb6b1aSVille Syrjälä }
173135bb6b1aSVille Syrjälä 
17320fbd8694SVille Syrjälä static bool dg1_ddi_is_clock_enabled(struct intel_encoder *encoder)
17330fbd8694SVille Syrjälä {
17340fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
17350fbd8694SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
17360fbd8694SVille Syrjälä 
17370fbd8694SVille Syrjälä 	return _cnl_ddi_is_clock_enabled(i915, DG1_DPCLKA_CFGCR0(phy),
17380fbd8694SVille Syrjälä 					 DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
17390fbd8694SVille Syrjälä }
17400fbd8694SVille Syrjälä 
1741351221ffSVille Syrjälä static struct intel_shared_dpll *dg1_ddi_get_pll(struct intel_encoder *encoder)
1742351221ffSVille Syrjälä {
1743351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1744351221ffSVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
1745351221ffSVille Syrjälä 
1746351221ffSVille Syrjälä 	return _cnl_ddi_get_pll(i915, DG1_DPCLKA_CFGCR0(phy),
1747351221ffSVille Syrjälä 				DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1748351221ffSVille Syrjälä 				DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy));
1749351221ffSVille Syrjälä }
1750351221ffSVille Syrjälä 
175136ecb0ecSVille Syrjälä static void icl_ddi_combo_enable_clock(struct intel_encoder *encoder,
1752379bc100SJani Nikula 				       const struct intel_crtc_state *crtc_state)
1753379bc100SJani Nikula {
175497a24a70SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
17559c6a5c35SVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
175697a24a70SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
1757cd803bb4SMatt Roper 
175897a24a70SVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
1759f67a008eSVille Syrjälä 		return;
1760f67a008eSVille Syrjälä 
176197a24a70SVille Syrjälä 	_cnl_ddi_enable_clock(i915, ICL_DPCLKA_CFGCR0,
176240b316d4SVille Syrjälä 			      ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
176340b316d4SVille Syrjälä 			      ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy),
176440b316d4SVille Syrjälä 			      ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1765379bc100SJani Nikula }
1766379bc100SJani Nikula 
176736ecb0ecSVille Syrjälä static void icl_ddi_combo_disable_clock(struct intel_encoder *encoder)
1768379bc100SJani Nikula {
176997a24a70SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
177097a24a70SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
1771379bc100SJani Nikula 
177297a24a70SVille Syrjälä 	_cnl_ddi_disable_clock(i915, ICL_DPCLKA_CFGCR0,
177340b316d4SVille Syrjälä 			       ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
1774379bc100SJani Nikula }
1775379bc100SJani Nikula 
17760fbd8694SVille Syrjälä static bool icl_ddi_combo_is_clock_enabled(struct intel_encoder *encoder)
17770fbd8694SVille Syrjälä {
17780fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
17790fbd8694SVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
17800fbd8694SVille Syrjälä 
17810fbd8694SVille Syrjälä 	return _cnl_ddi_is_clock_enabled(i915, ICL_DPCLKA_CFGCR0,
17820fbd8694SVille Syrjälä 					 ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
17830fbd8694SVille Syrjälä }
17840fbd8694SVille Syrjälä 
1785351221ffSVille Syrjälä struct intel_shared_dpll *icl_ddi_combo_get_pll(struct intel_encoder *encoder)
1786351221ffSVille Syrjälä {
1787351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1788351221ffSVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
1789351221ffSVille Syrjälä 
1790351221ffSVille Syrjälä 	return _cnl_ddi_get_pll(i915, ICL_DPCLKA_CFGCR0,
1791351221ffSVille Syrjälä 				ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy),
1792351221ffSVille Syrjälä 				ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy));
1793351221ffSVille Syrjälä }
1794351221ffSVille Syrjälä 
179536ecb0ecSVille Syrjälä static void jsl_ddi_tc_enable_clock(struct intel_encoder *encoder,
1796379bc100SJani Nikula 				    const struct intel_crtc_state *crtc_state)
1797379bc100SJani Nikula {
179836ecb0ecSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1799379bc100SJani Nikula 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
180036ecb0ecSVille Syrjälä 	enum port port = encoder->port;
1801379bc100SJani Nikula 
180236ecb0ecSVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
1803379bc100SJani Nikula 		return;
1804379bc100SJani Nikula 
1805c2052d6eSJosé Roberto de Souza 	/*
180636ecb0ecSVille Syrjälä 	 * "For DDIC and DDID, program DDI_CLK_SEL to map the MG clock to the port.
180736ecb0ecSVille Syrjälä 	 *  MG does not exist, but the programming is required to ungate DDIC and DDID."
1808c2052d6eSJosé Roberto de Souza 	 */
180936ecb0ecSVille Syrjälä 	intel_de_write(i915, DDI_CLK_SEL(port), DDI_CLK_SEL_MG);
181036ecb0ecSVille Syrjälä 
181136ecb0ecSVille Syrjälä 	icl_ddi_combo_enable_clock(encoder, crtc_state);
1812379bc100SJani Nikula }
1813379bc100SJani Nikula 
181436ecb0ecSVille Syrjälä static void jsl_ddi_tc_disable_clock(struct intel_encoder *encoder)
1815379bc100SJani Nikula {
181636ecb0ecSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1817379bc100SJani Nikula 	enum port port = encoder->port;
1818379bc100SJani Nikula 
181936ecb0ecSVille Syrjälä 	icl_ddi_combo_disable_clock(encoder);
182036ecb0ecSVille Syrjälä 
182136ecb0ecSVille Syrjälä 	intel_de_write(i915, DDI_CLK_SEL(port), DDI_CLK_SEL_NONE);
1822379bc100SJani Nikula }
182336ecb0ecSVille Syrjälä 
18240fbd8694SVille Syrjälä static bool jsl_ddi_tc_is_clock_enabled(struct intel_encoder *encoder)
18250fbd8694SVille Syrjälä {
18260fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
18270fbd8694SVille Syrjälä 	enum port port = encoder->port;
18280fbd8694SVille Syrjälä 	u32 tmp;
18290fbd8694SVille Syrjälä 
18300fbd8694SVille Syrjälä 	tmp = intel_de_read(i915, DDI_CLK_SEL(port));
18310fbd8694SVille Syrjälä 
18320fbd8694SVille Syrjälä 	if ((tmp & DDI_CLK_SEL_MASK) == DDI_CLK_SEL_NONE)
18330fbd8694SVille Syrjälä 		return false;
18340fbd8694SVille Syrjälä 
18350fbd8694SVille Syrjälä 	return icl_ddi_combo_is_clock_enabled(encoder);
18360fbd8694SVille Syrjälä }
18370fbd8694SVille Syrjälä 
183836ecb0ecSVille Syrjälä static void icl_ddi_tc_enable_clock(struct intel_encoder *encoder,
183936ecb0ecSVille Syrjälä 				    const struct intel_crtc_state *crtc_state)
184036ecb0ecSVille Syrjälä {
184136ecb0ecSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
184236ecb0ecSVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
184336ecb0ecSVille Syrjälä 	enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
184436ecb0ecSVille Syrjälä 	enum port port = encoder->port;
184536ecb0ecSVille Syrjälä 
184636ecb0ecSVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
184736ecb0ecSVille Syrjälä 		return;
184836ecb0ecSVille Syrjälä 
184936ecb0ecSVille Syrjälä 	intel_de_write(i915, DDI_CLK_SEL(port),
185036ecb0ecSVille Syrjälä 		       icl_pll_to_ddi_clk_sel(encoder, crtc_state));
185136ecb0ecSVille Syrjälä 
185236ecb0ecSVille Syrjälä 	mutex_lock(&i915->dpll.lock);
185336ecb0ecSVille Syrjälä 
185436ecb0ecSVille Syrjälä 	intel_de_rmw(i915, ICL_DPCLKA_CFGCR0,
185536ecb0ecSVille Syrjälä 		     ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port), 0);
185636ecb0ecSVille Syrjälä 
185736ecb0ecSVille Syrjälä 	mutex_unlock(&i915->dpll.lock);
185836ecb0ecSVille Syrjälä }
185936ecb0ecSVille Syrjälä 
186036ecb0ecSVille Syrjälä static void icl_ddi_tc_disable_clock(struct intel_encoder *encoder)
186136ecb0ecSVille Syrjälä {
186236ecb0ecSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
186336ecb0ecSVille Syrjälä 	enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
186436ecb0ecSVille Syrjälä 	enum port port = encoder->port;
186536ecb0ecSVille Syrjälä 
186636ecb0ecSVille Syrjälä 	mutex_lock(&i915->dpll.lock);
186736ecb0ecSVille Syrjälä 
186836ecb0ecSVille Syrjälä 	intel_de_rmw(i915, ICL_DPCLKA_CFGCR0,
186936ecb0ecSVille Syrjälä 		     0, ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port));
187036ecb0ecSVille Syrjälä 
187136ecb0ecSVille Syrjälä 	mutex_unlock(&i915->dpll.lock);
187236ecb0ecSVille Syrjälä 
187336ecb0ecSVille Syrjälä 	intel_de_write(i915, DDI_CLK_SEL(port), DDI_CLK_SEL_NONE);
1874379bc100SJani Nikula }
1875379bc100SJani Nikula 
18760fbd8694SVille Syrjälä static bool icl_ddi_tc_is_clock_enabled(struct intel_encoder *encoder)
18770fbd8694SVille Syrjälä {
18780fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
18790fbd8694SVille Syrjälä 	enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
18800fbd8694SVille Syrjälä 	enum port port = encoder->port;
18810fbd8694SVille Syrjälä 	u32 tmp;
18820fbd8694SVille Syrjälä 
18830fbd8694SVille Syrjälä 	tmp = intel_de_read(i915, DDI_CLK_SEL(port));
18840fbd8694SVille Syrjälä 
18850fbd8694SVille Syrjälä 	if ((tmp & DDI_CLK_SEL_MASK) == DDI_CLK_SEL_NONE)
18860fbd8694SVille Syrjälä 		return false;
18870fbd8694SVille Syrjälä 
18880fbd8694SVille Syrjälä 	tmp = intel_de_read(i915, ICL_DPCLKA_CFGCR0);
18890fbd8694SVille Syrjälä 
18900fbd8694SVille Syrjälä 	return !(tmp & ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port));
18910fbd8694SVille Syrjälä }
18920fbd8694SVille Syrjälä 
1893351221ffSVille Syrjälä static struct intel_shared_dpll *icl_ddi_tc_get_pll(struct intel_encoder *encoder)
1894351221ffSVille Syrjälä {
1895351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1896351221ffSVille Syrjälä 	enum tc_port tc_port = intel_port_to_tc(i915, encoder->port);
1897351221ffSVille Syrjälä 	enum port port = encoder->port;
1898351221ffSVille Syrjälä 	enum intel_dpll_id id;
1899351221ffSVille Syrjälä 	u32 tmp;
1900351221ffSVille Syrjälä 
1901351221ffSVille Syrjälä 	tmp = intel_de_read(i915, DDI_CLK_SEL(port));
1902351221ffSVille Syrjälä 
1903351221ffSVille Syrjälä 	switch (tmp & DDI_CLK_SEL_MASK) {
1904351221ffSVille Syrjälä 	case DDI_CLK_SEL_TBT_162:
1905351221ffSVille Syrjälä 	case DDI_CLK_SEL_TBT_270:
1906351221ffSVille Syrjälä 	case DDI_CLK_SEL_TBT_540:
1907351221ffSVille Syrjälä 	case DDI_CLK_SEL_TBT_810:
1908351221ffSVille Syrjälä 		id = DPLL_ID_ICL_TBTPLL;
1909351221ffSVille Syrjälä 		break;
1910351221ffSVille Syrjälä 	case DDI_CLK_SEL_MG:
1911351221ffSVille Syrjälä 		id = icl_tc_port_to_pll_id(tc_port);
1912351221ffSVille Syrjälä 		break;
1913351221ffSVille Syrjälä 	default:
1914351221ffSVille Syrjälä 		MISSING_CASE(tmp);
1915351221ffSVille Syrjälä 		fallthrough;
1916351221ffSVille Syrjälä 	case DDI_CLK_SEL_NONE:
1917351221ffSVille Syrjälä 		return NULL;
1918351221ffSVille Syrjälä 	}
1919351221ffSVille Syrjälä 
1920351221ffSVille Syrjälä 	return intel_get_shared_dpll_by_id(i915, id);
1921351221ffSVille Syrjälä }
1922351221ffSVille Syrjälä 
19232c7b1d34SVille Syrjälä static void cnl_ddi_enable_clock(struct intel_encoder *encoder,
19242c7b1d34SVille Syrjälä 				 const struct intel_crtc_state *crtc_state)
19252c7b1d34SVille Syrjälä {
19262c7b1d34SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
19272c7b1d34SVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
19282c7b1d34SVille Syrjälä 	enum port port = encoder->port;
19292c7b1d34SVille Syrjälä 
19302c7b1d34SVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
19312c7b1d34SVille Syrjälä 		return;
19322c7b1d34SVille Syrjälä 
19339c6a5c35SVille Syrjälä 	_cnl_ddi_enable_clock(i915, DPCLKA_CFGCR0,
19347815ed88SVille Syrjälä 			      DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port),
19359c6a5c35SVille Syrjälä 			      DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, port),
19369c6a5c35SVille Syrjälä 			      DPCLKA_CFGCR0_DDI_CLK_OFF(port));
19372c7b1d34SVille Syrjälä }
19382c7b1d34SVille Syrjälä 
19392c7b1d34SVille Syrjälä static void cnl_ddi_disable_clock(struct intel_encoder *encoder)
19402c7b1d34SVille Syrjälä {
19412c7b1d34SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
19422c7b1d34SVille Syrjälä 	enum port port = encoder->port;
19432c7b1d34SVille Syrjälä 
19449c6a5c35SVille Syrjälä 	_cnl_ddi_disable_clock(i915, DPCLKA_CFGCR0,
19459c6a5c35SVille Syrjälä 			       DPCLKA_CFGCR0_DDI_CLK_OFF(port));
19462c7b1d34SVille Syrjälä }
19472c7b1d34SVille Syrjälä 
19480fbd8694SVille Syrjälä static bool cnl_ddi_is_clock_enabled(struct intel_encoder *encoder)
19490fbd8694SVille Syrjälä {
19500fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
19510fbd8694SVille Syrjälä 	enum port port = encoder->port;
19520fbd8694SVille Syrjälä 
19530fbd8694SVille Syrjälä 	return _cnl_ddi_is_clock_enabled(i915, DPCLKA_CFGCR0,
19540fbd8694SVille Syrjälä 					 DPCLKA_CFGCR0_DDI_CLK_OFF(port));
19550fbd8694SVille Syrjälä }
19560fbd8694SVille Syrjälä 
1957351221ffSVille Syrjälä static struct intel_shared_dpll *cnl_ddi_get_pll(struct intel_encoder *encoder)
1958351221ffSVille Syrjälä {
1959351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1960351221ffSVille Syrjälä 	enum port port = encoder->port;
1961351221ffSVille Syrjälä 
1962351221ffSVille Syrjälä 	return _cnl_ddi_get_pll(i915, DPCLKA_CFGCR0,
1963351221ffSVille Syrjälä 				DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port),
1964351221ffSVille Syrjälä 				DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port));
1965351221ffSVille Syrjälä }
1966351221ffSVille Syrjälä 
1967351221ffSVille Syrjälä static struct intel_shared_dpll *bxt_ddi_get_pll(struct intel_encoder *encoder)
1968351221ffSVille Syrjälä {
1969351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
1970351221ffSVille Syrjälä 	enum intel_dpll_id id;
1971351221ffSVille Syrjälä 
1972351221ffSVille Syrjälä 	switch (encoder->port) {
1973351221ffSVille Syrjälä 	case PORT_A:
1974351221ffSVille Syrjälä 		id = DPLL_ID_SKL_DPLL0;
1975351221ffSVille Syrjälä 		break;
1976351221ffSVille Syrjälä 	case PORT_B:
1977351221ffSVille Syrjälä 		id = DPLL_ID_SKL_DPLL1;
1978351221ffSVille Syrjälä 		break;
1979351221ffSVille Syrjälä 	case PORT_C:
1980351221ffSVille Syrjälä 		id = DPLL_ID_SKL_DPLL2;
1981351221ffSVille Syrjälä 		break;
1982351221ffSVille Syrjälä 	default:
1983351221ffSVille Syrjälä 		MISSING_CASE(encoder->port);
1984351221ffSVille Syrjälä 		return NULL;
1985351221ffSVille Syrjälä 	}
1986351221ffSVille Syrjälä 
1987351221ffSVille Syrjälä 	return intel_get_shared_dpll_by_id(i915, id);
1988351221ffSVille Syrjälä }
1989351221ffSVille Syrjälä 
199038e31f1aSVille Syrjälä static void skl_ddi_enable_clock(struct intel_encoder *encoder,
199138e31f1aSVille Syrjälä 				 const struct intel_crtc_state *crtc_state)
199238e31f1aSVille Syrjälä {
199338e31f1aSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
199438e31f1aSVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
199538e31f1aSVille Syrjälä 	enum port port = encoder->port;
199638e31f1aSVille Syrjälä 
199738e31f1aSVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
199838e31f1aSVille Syrjälä 		return;
199938e31f1aSVille Syrjälä 
200038e31f1aSVille Syrjälä 	mutex_lock(&i915->dpll.lock);
200138e31f1aSVille Syrjälä 
20027815ed88SVille Syrjälä 	intel_de_rmw(i915, DPLL_CTRL2,
20037815ed88SVille Syrjälä 		     DPLL_CTRL2_DDI_CLK_OFF(port) |
20047815ed88SVille Syrjälä 		     DPLL_CTRL2_DDI_CLK_SEL_MASK(port),
20057815ed88SVille Syrjälä 		     DPLL_CTRL2_DDI_CLK_SEL(pll->info->id, port) |
200638e31f1aSVille Syrjälä 		     DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
200738e31f1aSVille Syrjälä 
200838e31f1aSVille Syrjälä 	mutex_unlock(&i915->dpll.lock);
200938e31f1aSVille Syrjälä }
201038e31f1aSVille Syrjälä 
201138e31f1aSVille Syrjälä static void skl_ddi_disable_clock(struct intel_encoder *encoder)
201238e31f1aSVille Syrjälä {
201338e31f1aSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
201438e31f1aSVille Syrjälä 	enum port port = encoder->port;
201538e31f1aSVille Syrjälä 
2016be317ca0SVille Syrjälä 	mutex_lock(&i915->dpll.lock);
2017be317ca0SVille Syrjälä 
20187815ed88SVille Syrjälä 	intel_de_rmw(i915, DPLL_CTRL2,
20197815ed88SVille Syrjälä 		     0, DPLL_CTRL2_DDI_CLK_OFF(port));
2020be317ca0SVille Syrjälä 
2021be317ca0SVille Syrjälä 	mutex_unlock(&i915->dpll.lock);
202238e31f1aSVille Syrjälä }
202338e31f1aSVille Syrjälä 
20240fbd8694SVille Syrjälä static bool skl_ddi_is_clock_enabled(struct intel_encoder *encoder)
20250fbd8694SVille Syrjälä {
20260fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
20270fbd8694SVille Syrjälä 	enum port port = encoder->port;
20280fbd8694SVille Syrjälä 
20290fbd8694SVille Syrjälä 	/*
20300fbd8694SVille Syrjälä 	 * FIXME Not sure if the override affects both
20310fbd8694SVille Syrjälä 	 * the PLL selection and the CLK_OFF bit.
20320fbd8694SVille Syrjälä 	 */
20330fbd8694SVille Syrjälä 	return !(intel_de_read(i915, DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_OFF(port));
20340fbd8694SVille Syrjälä }
20350fbd8694SVille Syrjälä 
2036351221ffSVille Syrjälä static struct intel_shared_dpll *skl_ddi_get_pll(struct intel_encoder *encoder)
2037351221ffSVille Syrjälä {
2038351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2039351221ffSVille Syrjälä 	enum port port = encoder->port;
2040351221ffSVille Syrjälä 	enum intel_dpll_id id;
2041351221ffSVille Syrjälä 	u32 tmp;
2042351221ffSVille Syrjälä 
2043351221ffSVille Syrjälä 	tmp = intel_de_read(i915, DPLL_CTRL2);
2044351221ffSVille Syrjälä 
2045351221ffSVille Syrjälä 	/*
2046351221ffSVille Syrjälä 	 * FIXME Not sure if the override affects both
2047351221ffSVille Syrjälä 	 * the PLL selection and the CLK_OFF bit.
2048351221ffSVille Syrjälä 	 */
2049351221ffSVille Syrjälä 	if ((tmp & DPLL_CTRL2_DDI_SEL_OVERRIDE(port)) == 0)
2050351221ffSVille Syrjälä 		return NULL;
2051351221ffSVille Syrjälä 
2052351221ffSVille Syrjälä 	id = (tmp & DPLL_CTRL2_DDI_CLK_SEL_MASK(port)) >>
2053351221ffSVille Syrjälä 		DPLL_CTRL2_DDI_CLK_SEL_SHIFT(port);
2054351221ffSVille Syrjälä 
2055351221ffSVille Syrjälä 	return intel_get_shared_dpll_by_id(i915, id);
2056351221ffSVille Syrjälä }
2057351221ffSVille Syrjälä 
2058d135368dSVille Syrjälä void hsw_ddi_enable_clock(struct intel_encoder *encoder,
2059d135368dSVille Syrjälä 			  const struct intel_crtc_state *crtc_state)
2060d135368dSVille Syrjälä {
2061d135368dSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2062d135368dSVille Syrjälä 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
2063d135368dSVille Syrjälä 	enum port port = encoder->port;
2064d135368dSVille Syrjälä 
2065d135368dSVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
2066d135368dSVille Syrjälä 		return;
2067d135368dSVille Syrjälä 
2068d135368dSVille Syrjälä 	intel_de_write(i915, PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
2069d135368dSVille Syrjälä }
2070d135368dSVille Syrjälä 
2071d135368dSVille Syrjälä void hsw_ddi_disable_clock(struct intel_encoder *encoder)
2072d135368dSVille Syrjälä {
2073d135368dSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2074d135368dSVille Syrjälä 	enum port port = encoder->port;
2075d135368dSVille Syrjälä 
2076d135368dSVille Syrjälä 	intel_de_write(i915, PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
2077d135368dSVille Syrjälä }
2078d135368dSVille Syrjälä 
20790fbd8694SVille Syrjälä bool hsw_ddi_is_clock_enabled(struct intel_encoder *encoder)
20800fbd8694SVille Syrjälä {
20810fbd8694SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
20820fbd8694SVille Syrjälä 	enum port port = encoder->port;
20830fbd8694SVille Syrjälä 
20840fbd8694SVille Syrjälä 	return intel_de_read(i915, PORT_CLK_SEL(port)) != PORT_CLK_SEL_NONE;
20850fbd8694SVille Syrjälä }
20860fbd8694SVille Syrjälä 
2087351221ffSVille Syrjälä static struct intel_shared_dpll *hsw_ddi_get_pll(struct intel_encoder *encoder)
2088351221ffSVille Syrjälä {
2089351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2090351221ffSVille Syrjälä 	enum port port = encoder->port;
2091351221ffSVille Syrjälä 	enum intel_dpll_id id;
2092351221ffSVille Syrjälä 	u32 tmp;
2093351221ffSVille Syrjälä 
2094351221ffSVille Syrjälä 	tmp = intel_de_read(i915, PORT_CLK_SEL(port));
2095351221ffSVille Syrjälä 
2096351221ffSVille Syrjälä 	switch (tmp & PORT_CLK_SEL_MASK) {
2097351221ffSVille Syrjälä 	case PORT_CLK_SEL_WRPLL1:
2098351221ffSVille Syrjälä 		id = DPLL_ID_WRPLL1;
2099351221ffSVille Syrjälä 		break;
2100351221ffSVille Syrjälä 	case PORT_CLK_SEL_WRPLL2:
2101351221ffSVille Syrjälä 		id = DPLL_ID_WRPLL2;
2102351221ffSVille Syrjälä 		break;
2103351221ffSVille Syrjälä 	case PORT_CLK_SEL_SPLL:
2104351221ffSVille Syrjälä 		id = DPLL_ID_SPLL;
2105351221ffSVille Syrjälä 		break;
2106351221ffSVille Syrjälä 	case PORT_CLK_SEL_LCPLL_810:
2107351221ffSVille Syrjälä 		id = DPLL_ID_LCPLL_810;
2108351221ffSVille Syrjälä 		break;
2109351221ffSVille Syrjälä 	case PORT_CLK_SEL_LCPLL_1350:
2110351221ffSVille Syrjälä 		id = DPLL_ID_LCPLL_1350;
2111351221ffSVille Syrjälä 		break;
2112351221ffSVille Syrjälä 	case PORT_CLK_SEL_LCPLL_2700:
2113351221ffSVille Syrjälä 		id = DPLL_ID_LCPLL_2700;
2114351221ffSVille Syrjälä 		break;
2115351221ffSVille Syrjälä 	default:
2116351221ffSVille Syrjälä 		MISSING_CASE(tmp);
2117351221ffSVille Syrjälä 		fallthrough;
2118351221ffSVille Syrjälä 	case PORT_CLK_SEL_NONE:
2119351221ffSVille Syrjälä 		return NULL;
2120351221ffSVille Syrjälä 	}
2121351221ffSVille Syrjälä 
2122351221ffSVille Syrjälä 	return intel_get_shared_dpll_by_id(i915, id);
2123351221ffSVille Syrjälä }
2124351221ffSVille Syrjälä 
2125c133df69SVille Syrjälä void intel_ddi_enable_clock(struct intel_encoder *encoder,
2126c133df69SVille Syrjälä 			    const struct intel_crtc_state *crtc_state)
2127c133df69SVille Syrjälä {
2128c133df69SVille Syrjälä 	if (encoder->enable_clock)
2129c133df69SVille Syrjälä 		encoder->enable_clock(encoder, crtc_state);
2130c133df69SVille Syrjälä }
2131c133df69SVille Syrjälä 
2132c133df69SVille Syrjälä static void intel_ddi_disable_clock(struct intel_encoder *encoder)
2133c133df69SVille Syrjälä {
2134c133df69SVille Syrjälä 	if (encoder->disable_clock)
2135c133df69SVille Syrjälä 		encoder->disable_clock(encoder);
2136c133df69SVille Syrjälä }
2137c133df69SVille Syrjälä 
2138aaca50efSVille Syrjälä void intel_ddi_sanitize_encoder_pll_mapping(struct intel_encoder *encoder)
2139dc1ddac6SVille Syrjälä {
214097a24a70SVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2141dc1ddac6SVille Syrjälä 	u32 port_mask;
2142dc1ddac6SVille Syrjälä 	bool ddi_clk_needed;
2143dc1ddac6SVille Syrjälä 
2144dc1ddac6SVille Syrjälä 	/*
2145dc1ddac6SVille Syrjälä 	 * In case of DP MST, we sanitize the primary encoder only, not the
2146dc1ddac6SVille Syrjälä 	 * virtual ones.
2147dc1ddac6SVille Syrjälä 	 */
2148dc1ddac6SVille Syrjälä 	if (encoder->type == INTEL_OUTPUT_DP_MST)
2149dc1ddac6SVille Syrjälä 		return;
2150dc1ddac6SVille Syrjälä 
2151dc1ddac6SVille Syrjälä 	if (!encoder->base.crtc && intel_encoder_is_dp(encoder)) {
2152dc1ddac6SVille Syrjälä 		u8 pipe_mask;
2153dc1ddac6SVille Syrjälä 		bool is_mst;
2154dc1ddac6SVille Syrjälä 
2155dc1ddac6SVille Syrjälä 		intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst);
2156dc1ddac6SVille Syrjälä 		/*
2157dc1ddac6SVille Syrjälä 		 * In the unlikely case that BIOS enables DP in MST mode, just
2158dc1ddac6SVille Syrjälä 		 * warn since our MST HW readout is incomplete.
2159dc1ddac6SVille Syrjälä 		 */
216097a24a70SVille Syrjälä 		if (drm_WARN_ON(&i915->drm, is_mst))
2161dc1ddac6SVille Syrjälä 			return;
2162dc1ddac6SVille Syrjälä 	}
2163dc1ddac6SVille Syrjälä 
2164dc1ddac6SVille Syrjälä 	port_mask = BIT(encoder->port);
2165dc1ddac6SVille Syrjälä 	ddi_clk_needed = encoder->base.crtc;
2166dc1ddac6SVille Syrjälä 
2167dc1ddac6SVille Syrjälä 	if (encoder->type == INTEL_OUTPUT_DSI) {
2168dc1ddac6SVille Syrjälä 		struct intel_encoder *other_encoder;
2169dc1ddac6SVille Syrjälä 
2170dc1ddac6SVille Syrjälä 		port_mask = intel_dsi_encoder_ports(encoder);
2171dc1ddac6SVille Syrjälä 		/*
2172dc1ddac6SVille Syrjälä 		 * Sanity check that we haven't incorrectly registered another
2173dc1ddac6SVille Syrjälä 		 * encoder using any of the ports of this DSI encoder.
2174dc1ddac6SVille Syrjälä 		 */
217597a24a70SVille Syrjälä 		for_each_intel_encoder(&i915->drm, other_encoder) {
2176dc1ddac6SVille Syrjälä 			if (other_encoder == encoder)
2177dc1ddac6SVille Syrjälä 				continue;
2178dc1ddac6SVille Syrjälä 
217997a24a70SVille Syrjälä 			if (drm_WARN_ON(&i915->drm,
2180dc1ddac6SVille Syrjälä 					port_mask & BIT(other_encoder->port)))
2181dc1ddac6SVille Syrjälä 				return;
2182dc1ddac6SVille Syrjälä 		}
2183dc1ddac6SVille Syrjälä 		/*
2184dc1ddac6SVille Syrjälä 		 * For DSI we keep the ddi clocks gated
2185dc1ddac6SVille Syrjälä 		 * except during enable/disable sequence.
2186dc1ddac6SVille Syrjälä 		 */
2187dc1ddac6SVille Syrjälä 		ddi_clk_needed = false;
2188dc1ddac6SVille Syrjälä 	}
2189dc1ddac6SVille Syrjälä 
21900fbd8694SVille Syrjälä 	if (ddi_clk_needed || !encoder->disable_clock ||
21910fbd8694SVille Syrjälä 	    !encoder->is_clock_enabled(encoder))
21920fbd8694SVille Syrjälä 		return;
21930fbd8694SVille Syrjälä 
21940fbd8694SVille Syrjälä 	drm_notice(&i915->drm,
21950fbd8694SVille Syrjälä 		   "[ENCODER:%d:%s] is disabled/in DSI mode with an ungated DDI clock, gate it\n",
21960fbd8694SVille Syrjälä 		   encoder->base.base.id, encoder->base.name);
21970fbd8694SVille Syrjälä 
2198dc1ddac6SVille Syrjälä 	encoder->disable_clock(encoder);
2199dc1ddac6SVille Syrjälä }
2200dc1ddac6SVille Syrjälä 
22018aaf5cbdSJosé Roberto de Souza static void
22027801f3b7SLucas De Marchi icl_program_mg_dp_mode(struct intel_digital_port *dig_port,
22033b51be4eSClinton A Taylor 		       const struct intel_crtc_state *crtc_state)
2204379bc100SJani Nikula {
22057801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
22067801f3b7SLucas De Marchi 	enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port);
22075b6a9ba9SVille Syrjälä 	enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
22083b51be4eSClinton A Taylor 	u32 ln0, ln1, pin_assignment;
22093b51be4eSClinton A Taylor 	u8 width;
2210379bc100SJani Nikula 
22115b6a9ba9SVille Syrjälä 	if (!intel_phy_is_tc(dev_priv, phy) ||
22125b6a9ba9SVille Syrjälä 	    dig_port->tc_mode == TC_PORT_TBT_ALT)
2213379bc100SJani Nikula 		return;
2214379bc100SJani Nikula 
2215005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
2216f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2217f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x0));
2218f7960e7fSJani Nikula 		ln0 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port));
2219f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2220f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x1));
2221f7960e7fSJani Nikula 		ln1 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port));
2222978c3e53SClinton A Taylor 	} else {
2223f7960e7fSJani Nikula 		ln0 = intel_de_read(dev_priv, MG_DP_MODE(0, tc_port));
2224f7960e7fSJani Nikula 		ln1 = intel_de_read(dev_priv, MG_DP_MODE(1, tc_port));
2225978c3e53SClinton A Taylor 	}
2226379bc100SJani Nikula 
22274f72a8eeSKhaled Almahallawy 	ln0 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE);
2228379bc100SJani Nikula 	ln1 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE);
2229379bc100SJani Nikula 
22303b51be4eSClinton A Taylor 	/* DPPATC */
22317801f3b7SLucas De Marchi 	pin_assignment = intel_tc_port_get_pin_assignment_mask(dig_port);
22323b51be4eSClinton A Taylor 	width = crtc_state->lane_count;
2233379bc100SJani Nikula 
22343b51be4eSClinton A Taylor 	switch (pin_assignment) {
22353b51be4eSClinton A Taylor 	case 0x0:
22361de143ccSPankaj Bharadiya 		drm_WARN_ON(&dev_priv->drm,
22377801f3b7SLucas De Marchi 			    dig_port->tc_mode != TC_PORT_LEGACY);
22383b51be4eSClinton A Taylor 		if (width == 1) {
2239379bc100SJani Nikula 			ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
22403b51be4eSClinton A Taylor 		} else {
22413b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
22423b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
2243379bc100SJani Nikula 		}
2244379bc100SJani Nikula 		break;
22453b51be4eSClinton A Taylor 	case 0x1:
22463b51be4eSClinton A Taylor 		if (width == 4) {
22473b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
22483b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
22493b51be4eSClinton A Taylor 		}
2250379bc100SJani Nikula 		break;
22513b51be4eSClinton A Taylor 	case 0x2:
22523b51be4eSClinton A Taylor 		if (width == 2) {
22533b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
22543b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
22553b51be4eSClinton A Taylor 		}
22563b51be4eSClinton A Taylor 		break;
22573b51be4eSClinton A Taylor 	case 0x3:
22583b51be4eSClinton A Taylor 	case 0x5:
22593b51be4eSClinton A Taylor 		if (width == 1) {
22603b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X1_MODE;
22613b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
22623b51be4eSClinton A Taylor 		} else {
22633b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
22643b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
22653b51be4eSClinton A Taylor 		}
22663b51be4eSClinton A Taylor 		break;
22673b51be4eSClinton A Taylor 	case 0x4:
22683b51be4eSClinton A Taylor 	case 0x6:
22693b51be4eSClinton A Taylor 		if (width == 1) {
22703b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X1_MODE;
22713b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
22723b51be4eSClinton A Taylor 		} else {
22733b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
22743b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
22753b51be4eSClinton A Taylor 		}
22763b51be4eSClinton A Taylor 		break;
2277379bc100SJani Nikula 	default:
22783b51be4eSClinton A Taylor 		MISSING_CASE(pin_assignment);
2279379bc100SJani Nikula 	}
2280379bc100SJani Nikula 
2281005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
2282f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2283f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x0));
2284f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln0);
2285f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2286f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x1));
2287f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln1);
2288978c3e53SClinton A Taylor 	} else {
2289f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_DP_MODE(0, tc_port), ln0);
2290f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_DP_MODE(1, tc_port), ln1);
2291379bc100SJani Nikula 	}
2292978c3e53SClinton A Taylor }
2293379bc100SJani Nikula 
2294ef79fafeSVille Syrjälä static enum transcoder
2295ef79fafeSVille Syrjälä tgl_dp_tp_transcoder(const struct intel_crtc_state *crtc_state)
2296ef79fafeSVille Syrjälä {
2297ef79fafeSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))
2298ef79fafeSVille Syrjälä 		return crtc_state->mst_master_transcoder;
2299ef79fafeSVille Syrjälä 	else
2300ef79fafeSVille Syrjälä 		return crtc_state->cpu_transcoder;
2301ef79fafeSVille Syrjälä }
2302ef79fafeSVille Syrjälä 
2303ef79fafeSVille Syrjälä i915_reg_t dp_tp_ctl_reg(struct intel_encoder *encoder,
2304ef79fafeSVille Syrjälä 			 const struct intel_crtc_state *crtc_state)
2305ef79fafeSVille Syrjälä {
2306ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2307ef79fafeSVille Syrjälä 
2308005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
2309ef79fafeSVille Syrjälä 		return TGL_DP_TP_CTL(tgl_dp_tp_transcoder(crtc_state));
2310ef79fafeSVille Syrjälä 	else
2311ef79fafeSVille Syrjälä 		return DP_TP_CTL(encoder->port);
2312ef79fafeSVille Syrjälä }
2313ef79fafeSVille Syrjälä 
2314ef79fafeSVille Syrjälä i915_reg_t dp_tp_status_reg(struct intel_encoder *encoder,
2315ef79fafeSVille Syrjälä 			    const struct intel_crtc_state *crtc_state)
2316ef79fafeSVille Syrjälä {
2317ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2318ef79fafeSVille Syrjälä 
2319005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
2320ef79fafeSVille Syrjälä 		return TGL_DP_TP_STATUS(tgl_dp_tp_transcoder(crtc_state));
2321ef79fafeSVille Syrjälä 	else
2322ef79fafeSVille Syrjälä 		return DP_TP_STATUS(encoder->port);
2323ef79fafeSVille Syrjälä }
2324ef79fafeSVille Syrjälä 
23251639406aSManasi Navare static void intel_dp_sink_set_msa_timing_par_ignore_state(struct intel_dp *intel_dp,
23261639406aSManasi Navare 							  const struct intel_crtc_state *crtc_state,
23271639406aSManasi Navare 							  bool enable)
23281639406aSManasi Navare {
23291639406aSManasi Navare 	struct drm_i915_private *i915 = dp_to_i915(intel_dp);
23301639406aSManasi Navare 
23311639406aSManasi Navare 	if (!crtc_state->vrr.enable)
23321639406aSManasi Navare 		return;
23331639406aSManasi Navare 
23341639406aSManasi Navare 	if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_DOWNSPREAD_CTRL,
23351639406aSManasi Navare 			       enable ? DP_MSA_TIMING_PAR_IGNORE_EN : 0) <= 0)
23361639406aSManasi Navare 		drm_dbg_kms(&i915->drm,
23371639406aSManasi Navare 			    "Failed to set MSA_TIMING_PAR_IGNORE %s in the sink\n",
23381639406aSManasi Navare 			    enable ? "enable" : "disable");
23391639406aSManasi Navare }
23401639406aSManasi Navare 
2341379bc100SJani Nikula static void intel_dp_sink_set_fec_ready(struct intel_dp *intel_dp,
2342379bc100SJani Nikula 					const struct intel_crtc_state *crtc_state)
2343379bc100SJani Nikula {
234447bdb1caSJani Nikula 	struct drm_i915_private *i915 = dp_to_i915(intel_dp);
234547bdb1caSJani Nikula 
2346379bc100SJani Nikula 	if (!crtc_state->fec_enable)
2347379bc100SJani Nikula 		return;
2348379bc100SJani Nikula 
2349379bc100SJani Nikula 	if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_FEC_CONFIGURATION, DP_FEC_READY) <= 0)
235047bdb1caSJani Nikula 		drm_dbg_kms(&i915->drm,
235147bdb1caSJani Nikula 			    "Failed to set FEC_READY in the sink\n");
2352379bc100SJani Nikula }
2353379bc100SJani Nikula 
2354379bc100SJani Nikula static void intel_ddi_enable_fec(struct intel_encoder *encoder,
2355379bc100SJani Nikula 				 const struct intel_crtc_state *crtc_state)
2356379bc100SJani Nikula {
2357379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
23584444df6eSLucas De Marchi 	struct intel_dp *intel_dp;
2359379bc100SJani Nikula 	u32 val;
2360379bc100SJani Nikula 
2361379bc100SJani Nikula 	if (!crtc_state->fec_enable)
2362379bc100SJani Nikula 		return;
2363379bc100SJani Nikula 
2364b7d02c3aSVille Syrjälä 	intel_dp = enc_to_intel_dp(encoder);
2365ef79fafeSVille Syrjälä 	val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2366379bc100SJani Nikula 	val |= DP_TP_CTL_FEC_ENABLE;
2367ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
2368379bc100SJani Nikula }
2369379bc100SJani Nikula 
2370379bc100SJani Nikula static void intel_ddi_disable_fec_state(struct intel_encoder *encoder,
2371379bc100SJani Nikula 					const struct intel_crtc_state *crtc_state)
2372379bc100SJani Nikula {
2373379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
23744444df6eSLucas De Marchi 	struct intel_dp *intel_dp;
2375379bc100SJani Nikula 	u32 val;
2376379bc100SJani Nikula 
2377379bc100SJani Nikula 	if (!crtc_state->fec_enable)
2378379bc100SJani Nikula 		return;
2379379bc100SJani Nikula 
2380b7d02c3aSVille Syrjälä 	intel_dp = enc_to_intel_dp(encoder);
2381ef79fafeSVille Syrjälä 	val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2382379bc100SJani Nikula 	val &= ~DP_TP_CTL_FEC_ENABLE;
2383ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
2384ef79fafeSVille Syrjälä 	intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2385379bc100SJani Nikula }
2386379bc100SJani Nikula 
23875cdf706fSVille Syrjälä static void intel_ddi_power_up_lanes(struct intel_encoder *encoder,
23885cdf706fSVille Syrjälä 				     const struct intel_crtc_state *crtc_state)
23895cdf706fSVille Syrjälä {
23905cdf706fSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
23915cdf706fSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
23925cdf706fSVille Syrjälä 	enum phy phy = intel_port_to_phy(i915, encoder->port);
23935cdf706fSVille Syrjälä 
23945cdf706fSVille Syrjälä 	if (intel_phy_is_combo(i915, phy)) {
23955cdf706fSVille Syrjälä 		bool lane_reversal =
23965cdf706fSVille Syrjälä 			dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL;
23975cdf706fSVille Syrjälä 
23985cdf706fSVille Syrjälä 		intel_combo_phy_power_up_lanes(i915, phy, false,
23995cdf706fSVille Syrjälä 					       crtc_state->lane_count,
24005cdf706fSVille Syrjälä 					       lane_reversal);
24015cdf706fSVille Syrjälä 	}
24025cdf706fSVille Syrjälä }
24035cdf706fSVille Syrjälä 
24045b616a29SJani Nikula static void intel_ddi_mso_get_config(struct intel_encoder *encoder,
24055b616a29SJani Nikula 				     struct intel_crtc_state *pipe_config)
24065b616a29SJani Nikula {
24075b616a29SJani Nikula 	struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
24085b616a29SJani Nikula 	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
24095b616a29SJani Nikula 	enum pipe pipe = crtc->pipe;
24105b616a29SJani Nikula 	u32 dss1;
24115b616a29SJani Nikula 
24125b616a29SJani Nikula 	if (!HAS_MSO(i915))
24135b616a29SJani Nikula 		return;
24145b616a29SJani Nikula 
24155b616a29SJani Nikula 	dss1 = intel_de_read(i915, ICL_PIPE_DSS_CTL1(pipe));
24165b616a29SJani Nikula 
24175b616a29SJani Nikula 	pipe_config->splitter.enable = dss1 & SPLITTER_ENABLE;
24185b616a29SJani Nikula 	if (!pipe_config->splitter.enable)
24195b616a29SJani Nikula 		return;
24205b616a29SJani Nikula 
24215b616a29SJani Nikula 	/* Splitter enable is supported for pipe A only. */
24225b616a29SJani Nikula 	if (drm_WARN_ON(&i915->drm, pipe != PIPE_A)) {
24235b616a29SJani Nikula 		pipe_config->splitter.enable = false;
24245b616a29SJani Nikula 		return;
24255b616a29SJani Nikula 	}
24265b616a29SJani Nikula 
24275b616a29SJani Nikula 	switch (dss1 & SPLITTER_CONFIGURATION_MASK) {
24285b616a29SJani Nikula 	default:
24295b616a29SJani Nikula 		drm_WARN(&i915->drm, true,
24305b616a29SJani Nikula 			 "Invalid splitter configuration, dss1=0x%08x\n", dss1);
24315b616a29SJani Nikula 		fallthrough;
24325b616a29SJani Nikula 	case SPLITTER_CONFIGURATION_2_SEGMENT:
24335b616a29SJani Nikula 		pipe_config->splitter.link_count = 2;
24345b616a29SJani Nikula 		break;
24355b616a29SJani Nikula 	case SPLITTER_CONFIGURATION_4_SEGMENT:
24365b616a29SJani Nikula 		pipe_config->splitter.link_count = 4;
24375b616a29SJani Nikula 		break;
24385b616a29SJani Nikula 	}
24395b616a29SJani Nikula 
24405b616a29SJani Nikula 	pipe_config->splitter.pixel_overlap = REG_FIELD_GET(OVERLAP_PIXELS_MASK, dss1);
24415b616a29SJani Nikula }
24425b616a29SJani Nikula 
2443bc71194eSJani Nikula static void intel_ddi_mso_configure(const struct intel_crtc_state *crtc_state)
2444bc71194eSJani Nikula {
2445bc71194eSJani Nikula 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2446bc71194eSJani Nikula 	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2447bc71194eSJani Nikula 	enum pipe pipe = crtc->pipe;
2448bc71194eSJani Nikula 	u32 dss1 = 0;
2449bc71194eSJani Nikula 
2450bc71194eSJani Nikula 	if (!HAS_MSO(i915))
2451bc71194eSJani Nikula 		return;
2452bc71194eSJani Nikula 
2453bc71194eSJani Nikula 	if (crtc_state->splitter.enable) {
2454bc71194eSJani Nikula 		/* Splitter enable is supported for pipe A only. */
2455bc71194eSJani Nikula 		if (drm_WARN_ON(&i915->drm, pipe != PIPE_A))
2456bc71194eSJani Nikula 			return;
2457bc71194eSJani Nikula 
2458bc71194eSJani Nikula 		dss1 |= SPLITTER_ENABLE;
2459bc71194eSJani Nikula 		dss1 |= OVERLAP_PIXELS(crtc_state->splitter.pixel_overlap);
2460bc71194eSJani Nikula 		if (crtc_state->splitter.link_count == 2)
2461bc71194eSJani Nikula 			dss1 |= SPLITTER_CONFIGURATION_2_SEGMENT;
2462bc71194eSJani Nikula 		else
2463bc71194eSJani Nikula 			dss1 |= SPLITTER_CONFIGURATION_4_SEGMENT;
2464bc71194eSJani Nikula 	}
2465bc71194eSJani Nikula 
2466bc71194eSJani Nikula 	intel_de_rmw(i915, ICL_PIPE_DSS_CTL1(pipe),
2467bc71194eSJani Nikula 		     SPLITTER_ENABLE | SPLITTER_CONFIGURATION_MASK |
2468bc71194eSJani Nikula 		     OVERLAP_PIXELS_MASK, dss1);
2469bc71194eSJani Nikula }
2470bc71194eSJani Nikula 
2471ede9771dSVille Syrjälä static void tgl_ddi_pre_enable_dp(struct intel_atomic_state *state,
2472ede9771dSVille Syrjälä 				  struct intel_encoder *encoder,
247399389390SJosé Roberto de Souza 				  const struct intel_crtc_state *crtc_state,
247499389390SJosé Roberto de Souza 				  const struct drm_connector_state *conn_state)
247599389390SJosé Roberto de Souza {
2476b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
247799389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
247899389390SJosé Roberto de Souza 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2479b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
248099389390SJosé Roberto de Souza 	bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
248199389390SJosé Roberto de Souza 	int level = intel_ddi_dp_level(intel_dp);
248299389390SJosé Roberto de Souza 
2483a621860aSVille Syrjälä 	intel_dp_set_link_params(intel_dp,
2484a621860aSVille Syrjälä 				 crtc_state->port_clock,
2485a621860aSVille Syrjälä 				 crtc_state->lane_count);
248699389390SJosé Roberto de Souza 
24875e19c0b0SMatt Roper 	/*
24885e19c0b0SMatt Roper 	 * 1. Enable Power Wells
24895e19c0b0SMatt Roper 	 *
24905e19c0b0SMatt Roper 	 * This was handled at the beginning of intel_atomic_commit_tail(),
24915e19c0b0SMatt Roper 	 * before we called down into this function.
24925e19c0b0SMatt Roper 	 */
249399389390SJosé Roberto de Souza 
24945e19c0b0SMatt Roper 	/* 2. Enable Panel Power if PPS is required */
2495eb46f498SJani Nikula 	intel_pps_on(intel_dp);
249699389390SJosé Roberto de Souza 
249799389390SJosé Roberto de Souza 	/*
24985e19c0b0SMatt Roper 	 * 3. For non-TBT Type-C ports, set FIA lane count
24995e19c0b0SMatt Roper 	 * (DFLEXDPSP.DPX4TXLATC)
25005e19c0b0SMatt Roper 	 *
25015e19c0b0SMatt Roper 	 * This was done before tgl_ddi_pre_enable_dp by
25021e98f88cSLucas De Marchi 	 * hsw_crtc_enable()->intel_encoders_pre_pll_enable().
250399389390SJosé Roberto de Souza 	 */
250499389390SJosé Roberto de Souza 
25055e19c0b0SMatt Roper 	/*
25065e19c0b0SMatt Roper 	 * 4. Enable the port PLL.
25075e19c0b0SMatt Roper 	 *
25085e19c0b0SMatt Roper 	 * The PLL enabling itself was already done before this function by
25091e98f88cSLucas De Marchi 	 * hsw_crtc_enable()->intel_enable_shared_dpll().  We need only
25105e19c0b0SMatt Roper 	 * configure the PLL to port mapping here.
25115e19c0b0SMatt Roper 	 */
2512c133df69SVille Syrjälä 	intel_ddi_enable_clock(encoder, crtc_state);
25136171e58bSClinton A Taylor 
25145e19c0b0SMatt Roper 	/* 5. If IO power is controlled through PWR_WELL_CTL, Enable IO Power */
251599389390SJosé Roberto de Souza 	if (!intel_phy_is_tc(dev_priv, phy) ||
2516a4550977SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT) {
2517a4550977SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
2518a4550977SImre Deak 		dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
251999389390SJosé Roberto de Souza 								   dig_port->ddi_io_power_domain);
2520a4550977SImre Deak 	}
252199389390SJosé Roberto de Souza 
25225e19c0b0SMatt Roper 	/* 6. Program DP_MODE */
25233b51be4eSClinton A Taylor 	icl_program_mg_dp_mode(dig_port, crtc_state);
252499389390SJosé Roberto de Souza 
252599389390SJosé Roberto de Souza 	/*
25265e19c0b0SMatt Roper 	 * 7. The rest of the below are substeps under the bspec's "Enable and
25275e19c0b0SMatt Roper 	 * Train Display Port" step.  Note that steps that are specific to
25285e19c0b0SMatt Roper 	 * MST will be handled by intel_mst_pre_enable_dp() before/after it
25295e19c0b0SMatt Roper 	 * calls into this function.  Also intel_mst_pre_enable_dp() only calls
25305e19c0b0SMatt Roper 	 * us when active_mst_links==0, so any steps designated for "single
25315e19c0b0SMatt Roper 	 * stream or multi-stream master transcoder" can just be performed
25325e19c0b0SMatt Roper 	 * unconditionally here.
25335e19c0b0SMatt Roper 	 */
25345e19c0b0SMatt Roper 
25355e19c0b0SMatt Roper 	/*
25365e19c0b0SMatt Roper 	 * 7.a Configure Transcoder Clock Select to direct the Port clock to the
25375e19c0b0SMatt Roper 	 * Transcoder.
253899389390SJosé Roberto de Souza 	 */
253902a715c3SVille Syrjälä 	intel_ddi_enable_pipe_clock(encoder, crtc_state);
254099389390SJosé Roberto de Souza 
25415e19c0b0SMatt Roper 	/*
25425e19c0b0SMatt Roper 	 * 7.b Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST
25435e19c0b0SMatt Roper 	 * Transport Select
25445e19c0b0SMatt Roper 	 */
2545eed22a46SVille Syrjälä 	intel_ddi_config_transcoder_func(encoder, crtc_state);
254699389390SJosé Roberto de Souza 
25475e19c0b0SMatt Roper 	/*
25485e19c0b0SMatt Roper 	 * 7.c Configure & enable DP_TP_CTL with link training pattern 1
25495e19c0b0SMatt Roper 	 * selected
25505e19c0b0SMatt Roper 	 *
25515e19c0b0SMatt Roper 	 * This will be handled by the intel_dp_start_link_train() farther
25525e19c0b0SMatt Roper 	 * down this function.
25535e19c0b0SMatt Roper 	 */
25545e19c0b0SMatt Roper 
25555e19c0b0SMatt Roper 	/* 7.e Configure voltage swing and related IO settings */
2556a621860aSVille Syrjälä 	tgl_ddi_vswing_sequence(encoder, crtc_state, level);
255799389390SJosé Roberto de Souza 
25585e19c0b0SMatt Roper 	/*
25595e19c0b0SMatt Roper 	 * 7.f Combo PHY: Configure PORT_CL_DW10 Static Power Down to power up
25605e19c0b0SMatt Roper 	 * the used lanes of the DDI.
25615e19c0b0SMatt Roper 	 */
25625cdf706fSVille Syrjälä 	intel_ddi_power_up_lanes(encoder, crtc_state);
256399389390SJosé Roberto de Souza 
25645e19c0b0SMatt Roper 	/*
2565bc71194eSJani Nikula 	 * 7.g Program CoG/MSO configuration bits in DSS_CTL1 if selected.
2566bc71194eSJani Nikula 	 */
2567bc71194eSJani Nikula 	intel_ddi_mso_configure(crtc_state);
2568bc71194eSJani Nikula 
2569bc71194eSJani Nikula 	/*
25705e19c0b0SMatt Roper 	 * 7.g Configure and enable DDI_BUF_CTL
25715e19c0b0SMatt Roper 	 * 7.h Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout
25725e19c0b0SMatt Roper 	 *     after 500 us.
25735e19c0b0SMatt Roper 	 *
25745e19c0b0SMatt Roper 	 * We only configure what the register value will be here.  Actual
25755e19c0b0SMatt Roper 	 * enabling happens during link training farther down.
25765e19c0b0SMatt Roper 	 */
2577a621860aSVille Syrjälä 	intel_ddi_init_dp_buf_reg(encoder, crtc_state);
257899389390SJosé Roberto de Souza 
257999389390SJosé Roberto de Souza 	if (!is_mst)
25800e634efdSVille Syrjälä 		intel_dp_set_power(intel_dp, DP_SET_POWER_D0);
258199389390SJosé Roberto de Souza 
2582522508b6SAnkit Nautiyal 	intel_dp_configure_protocol_converter(intel_dp, crtc_state);
258399389390SJosé Roberto de Souza 	intel_dp_sink_set_decompression_state(intel_dp, crtc_state, true);
258499389390SJosé Roberto de Souza 	/*
258599389390SJosé Roberto de Souza 	 * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit
258699389390SJosé Roberto de Souza 	 * in the FEC_CONFIGURATION register to 1 before initiating link
258799389390SJosé Roberto de Souza 	 * training
258899389390SJosé Roberto de Souza 	 */
258999389390SJosé Roberto de Souza 	intel_dp_sink_set_fec_ready(intel_dp, crtc_state);
25905e19c0b0SMatt Roper 
25914f3dd47aSAnkit Nautiyal 	intel_dp_check_frl_training(intel_dp);
259210fec80bSAnkit Nautiyal 	intel_dp_pcon_dsc_configure(intel_dp, crtc_state);
25934f3dd47aSAnkit Nautiyal 
25945e19c0b0SMatt Roper 	/*
25955e19c0b0SMatt Roper 	 * 7.i Follow DisplayPort specification training sequence (see notes for
25965e19c0b0SMatt Roper 	 *     failure handling)
25975e19c0b0SMatt Roper 	 * 7.j If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle
25985e19c0b0SMatt Roper 	 *     Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent)
25995e19c0b0SMatt Roper 	 *     (timeout after 800 us)
26005e19c0b0SMatt Roper 	 */
2601a621860aSVille Syrjälä 	intel_dp_start_link_train(intel_dp, crtc_state);
260299389390SJosé Roberto de Souza 
26035e19c0b0SMatt Roper 	/* 7.k Set DP_TP_CTL link training to Normal */
2604eadf6f91SManasi Navare 	if (!is_trans_port_sync_mode(crtc_state))
2605a621860aSVille Syrjälä 		intel_dp_stop_link_train(intel_dp, crtc_state);
260699389390SJosé Roberto de Souza 
26075e19c0b0SMatt Roper 	/* 7.l Configure and enable FEC if needed */
260899389390SJosé Roberto de Souza 	intel_ddi_enable_fec(encoder, crtc_state);
26094e3cdb45SManasi Navare 	if (!crtc_state->bigjoiner)
261099389390SJosé Roberto de Souza 		intel_dsc_enable(encoder, crtc_state);
261199389390SJosé Roberto de Souza }
261299389390SJosé Roberto de Souza 
2613ede9771dSVille Syrjälä static void hsw_ddi_pre_enable_dp(struct intel_atomic_state *state,
2614ede9771dSVille Syrjälä 				  struct intel_encoder *encoder,
2615379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state,
2616379bc100SJani Nikula 				  const struct drm_connector_state *conn_state)
2617379bc100SJani Nikula {
2618b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2619379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2620379bc100SJani Nikula 	enum port port = encoder->port;
2621dc867bc7SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
2622b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2623379bc100SJani Nikula 	bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
2624379bc100SJani Nikula 	int level = intel_ddi_dp_level(intel_dp);
2625379bc100SJani Nikula 
2626005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) < 11)
26271de143ccSPankaj Bharadiya 		drm_WARN_ON(&dev_priv->drm,
26281de143ccSPankaj Bharadiya 			    is_mst && (port == PORT_A || port == PORT_E));
2629542dfab5SJosé Roberto de Souza 	else
26301de143ccSPankaj Bharadiya 		drm_WARN_ON(&dev_priv->drm, is_mst && port == PORT_A);
2631379bc100SJani Nikula 
2632a621860aSVille Syrjälä 	intel_dp_set_link_params(intel_dp,
2633a621860aSVille Syrjälä 				 crtc_state->port_clock,
2634a621860aSVille Syrjälä 				 crtc_state->lane_count);
2635379bc100SJani Nikula 
2636eb46f498SJani Nikula 	intel_pps_on(intel_dp);
2637379bc100SJani Nikula 
2638c133df69SVille Syrjälä 	intel_ddi_enable_clock(encoder, crtc_state);
2639379bc100SJani Nikula 
2640d8fe2ab6SMatt Roper 	if (!intel_phy_is_tc(dev_priv, phy) ||
2641a4550977SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT) {
2642a4550977SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
2643a4550977SImre Deak 		dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
26443b2ed431SImre Deak 								   dig_port->ddi_io_power_domain);
2645a4550977SImre Deak 	}
2646379bc100SJani Nikula 
26473b51be4eSClinton A Taylor 	icl_program_mg_dp_mode(dig_port, crtc_state);
2648379bc100SJani Nikula 
2649005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11)
2650a621860aSVille Syrjälä 		icl_ddi_vswing_sequence(encoder, crtc_state, level);
2651379bc100SJani Nikula 	else if (IS_CANNONLAKE(dev_priv))
2652a621860aSVille Syrjälä 		cnl_ddi_vswing_sequence(encoder, crtc_state, level);
26532446e1d6SMatt Roper 	else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
2654a621860aSVille Syrjälä 		bxt_ddi_vswing_sequence(encoder, crtc_state, level);
2655379bc100SJani Nikula 	else
2656379bc100SJani Nikula 		intel_prepare_dp_ddi_buffers(encoder, crtc_state);
2657379bc100SJani Nikula 
26585cdf706fSVille Syrjälä 	intel_ddi_power_up_lanes(encoder, crtc_state);
2659379bc100SJani Nikula 
2660a621860aSVille Syrjälä 	intel_ddi_init_dp_buf_reg(encoder, crtc_state);
2661379bc100SJani Nikula 	if (!is_mst)
26620e634efdSVille Syrjälä 		intel_dp_set_power(intel_dp, DP_SET_POWER_D0);
2663522508b6SAnkit Nautiyal 	intel_dp_configure_protocol_converter(intel_dp, crtc_state);
2664379bc100SJani Nikula 	intel_dp_sink_set_decompression_state(intel_dp, crtc_state,
2665379bc100SJani Nikula 					      true);
2666379bc100SJani Nikula 	intel_dp_sink_set_fec_ready(intel_dp, crtc_state);
2667a621860aSVille Syrjälä 	intel_dp_start_link_train(intel_dp, crtc_state);
2668005e9537SMatt Roper 	if ((port != PORT_A || DISPLAY_VER(dev_priv) >= 9) &&
2669eadf6f91SManasi Navare 	    !is_trans_port_sync_mode(crtc_state))
2670a621860aSVille Syrjälä 		intel_dp_stop_link_train(intel_dp, crtc_state);
2671379bc100SJani Nikula 
2672379bc100SJani Nikula 	intel_ddi_enable_fec(encoder, crtc_state);
2673379bc100SJani Nikula 
2674379bc100SJani Nikula 	if (!is_mst)
267502a715c3SVille Syrjälä 		intel_ddi_enable_pipe_clock(encoder, crtc_state);
2676379bc100SJani Nikula 
26774e3cdb45SManasi Navare 	if (!crtc_state->bigjoiner)
2678379bc100SJani Nikula 		intel_dsc_enable(encoder, crtc_state);
2679379bc100SJani Nikula }
2680379bc100SJani Nikula 
2681ede9771dSVille Syrjälä static void intel_ddi_pre_enable_dp(struct intel_atomic_state *state,
2682ede9771dSVille Syrjälä 				    struct intel_encoder *encoder,
268399389390SJosé Roberto de Souza 				    const struct intel_crtc_state *crtc_state,
268499389390SJosé Roberto de Souza 				    const struct drm_connector_state *conn_state)
268599389390SJosé Roberto de Souza {
268699389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
268799389390SJosé Roberto de Souza 
2688005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
2689ede9771dSVille Syrjälä 		tgl_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state);
269099389390SJosé Roberto de Souza 	else
2691ede9771dSVille Syrjälä 		hsw_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state);
26920c06fa15SGwan-gyeong Mun 
2693bd8c9ccaSGwan-gyeong Mun 	/* MST will call a setting of MSA after an allocating of Virtual Channel
2694bd8c9ccaSGwan-gyeong Mun 	 * from MST encoder pre_enable callback.
2695bd8c9ccaSGwan-gyeong Mun 	 */
26961fc1e8d4SJosé Roberto de Souza 	if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
26970c06fa15SGwan-gyeong Mun 		intel_ddi_set_dp_msa(crtc_state, conn_state);
26981c9d2eb2SJani Nikula 
26991c9d2eb2SJani Nikula 		intel_dp_set_m_n(crtc_state, M1_N1);
270099389390SJosé Roberto de Souza 	}
27011fc1e8d4SJosé Roberto de Souza }
270299389390SJosé Roberto de Souza 
2703ede9771dSVille Syrjälä static void intel_ddi_pre_enable_hdmi(struct intel_atomic_state *state,
2704ede9771dSVille Syrjälä 				      struct intel_encoder *encoder,
2705379bc100SJani Nikula 				      const struct intel_crtc_state *crtc_state,
2706379bc100SJani Nikula 				      const struct drm_connector_state *conn_state)
2707379bc100SJani Nikula {
27080ba7ffeaSLucas De Marchi 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
27090ba7ffeaSLucas De Marchi 	struct intel_hdmi *intel_hdmi = &dig_port->hdmi;
2710379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2711379bc100SJani Nikula 
2712379bc100SJani Nikula 	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
2713c133df69SVille Syrjälä 	intel_ddi_enable_clock(encoder, crtc_state);
2714379bc100SJani Nikula 
2715a4550977SImre Deak 	drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
2716a4550977SImre Deak 	dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
2717a4550977SImre Deak 							   dig_port->ddi_io_power_domain);
2718379bc100SJani Nikula 
27193b51be4eSClinton A Taylor 	icl_program_mg_dp_mode(dig_port, crtc_state);
2720379bc100SJani Nikula 
272102a715c3SVille Syrjälä 	intel_ddi_enable_pipe_clock(encoder, crtc_state);
2722379bc100SJani Nikula 
27230ba7ffeaSLucas De Marchi 	dig_port->set_infoframes(encoder,
2724379bc100SJani Nikula 				 crtc_state->has_infoframe,
2725379bc100SJani Nikula 				 crtc_state, conn_state);
2726379bc100SJani Nikula }
2727379bc100SJani Nikula 
2728ede9771dSVille Syrjälä static void intel_ddi_pre_enable(struct intel_atomic_state *state,
2729ede9771dSVille Syrjälä 				 struct intel_encoder *encoder,
2730379bc100SJani Nikula 				 const struct intel_crtc_state *crtc_state,
2731379bc100SJani Nikula 				 const struct drm_connector_state *conn_state)
2732379bc100SJani Nikula {
27332225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2734379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2735379bc100SJani Nikula 	enum pipe pipe = crtc->pipe;
2736379bc100SJani Nikula 
2737379bc100SJani Nikula 	/*
2738379bc100SJani Nikula 	 * When called from DP MST code:
2739379bc100SJani Nikula 	 * - conn_state will be NULL
2740379bc100SJani Nikula 	 * - encoder will be the main encoder (ie. mst->primary)
2741379bc100SJani Nikula 	 * - the main connector associated with this port
2742379bc100SJani Nikula 	 *   won't be active or linked to a crtc
2743379bc100SJani Nikula 	 * - crtc_state will be the state of the first stream to
2744379bc100SJani Nikula 	 *   be activated on this port, and it may not be the same
2745379bc100SJani Nikula 	 *   stream that will be deactivated last, but each stream
2746379bc100SJani Nikula 	 *   should have a state that is identical when it comes to
2747379bc100SJani Nikula 	 *   the DP link parameteres
2748379bc100SJani Nikula 	 */
2749379bc100SJani Nikula 
27501de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, crtc_state->has_pch_encoder);
2751379bc100SJani Nikula 
2752379bc100SJani Nikula 	intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2753379bc100SJani Nikula 
2754379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
2755ede9771dSVille Syrjälä 		intel_ddi_pre_enable_hdmi(state, encoder, crtc_state,
2756ede9771dSVille Syrjälä 					  conn_state);
2757379bc100SJani Nikula 	} else {
2758f7af425dSVille Syrjälä 		struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2759379bc100SJani Nikula 
2760ede9771dSVille Syrjälä 		intel_ddi_pre_enable_dp(state, encoder, crtc_state,
2761ede9771dSVille Syrjälä 					conn_state);
2762379bc100SJani Nikula 
2763f7af425dSVille Syrjälä 		/* FIXME precompute everything properly */
2764f7af425dSVille Syrjälä 		/* FIXME how do we turn infoframes off again? */
2765f7af425dSVille Syrjälä 		if (dig_port->lspcon.active && dig_port->dp.has_hdmi_sink)
2766379bc100SJani Nikula 			dig_port->set_infoframes(encoder,
2767379bc100SJani Nikula 						 crtc_state->has_infoframe,
2768379bc100SJani Nikula 						 crtc_state, conn_state);
2769379bc100SJani Nikula 	}
2770379bc100SJani Nikula }
2771379bc100SJani Nikula 
2772379bc100SJani Nikula static void intel_disable_ddi_buf(struct intel_encoder *encoder,
2773379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state)
2774379bc100SJani Nikula {
2775379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2776379bc100SJani Nikula 	enum port port = encoder->port;
2777379bc100SJani Nikula 	bool wait = false;
2778379bc100SJani Nikula 	u32 val;
2779379bc100SJani Nikula 
2780f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, DDI_BUF_CTL(port));
2781379bc100SJani Nikula 	if (val & DDI_BUF_CTL_ENABLE) {
2782379bc100SJani Nikula 		val &= ~DDI_BUF_CTL_ENABLE;
2783f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_CTL(port), val);
2784379bc100SJani Nikula 		wait = true;
2785379bc100SJani Nikula 	}
2786379bc100SJani Nikula 
2787e468ff06SLucas De Marchi 	if (intel_crtc_has_dp_encoder(crtc_state)) {
2788ef79fafeSVille Syrjälä 		val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
2789379bc100SJani Nikula 		val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2790379bc100SJani Nikula 		val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2791ef79fafeSVille Syrjälä 		intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
2792e468ff06SLucas De Marchi 	}
2793379bc100SJani Nikula 
2794379bc100SJani Nikula 	/* Disable FEC in DP Sink */
2795379bc100SJani Nikula 	intel_ddi_disable_fec_state(encoder, crtc_state);
2796379bc100SJani Nikula 
2797379bc100SJani Nikula 	if (wait)
2798379bc100SJani Nikula 		intel_wait_ddi_buf_idle(dev_priv, port);
2799379bc100SJani Nikula }
2800379bc100SJani Nikula 
2801ede9771dSVille Syrjälä static void intel_ddi_post_disable_dp(struct intel_atomic_state *state,
2802ede9771dSVille Syrjälä 				      struct intel_encoder *encoder,
2803379bc100SJani Nikula 				      const struct intel_crtc_state *old_crtc_state,
2804379bc100SJani Nikula 				      const struct drm_connector_state *old_conn_state)
2805379bc100SJani Nikula {
2806379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2807b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2808379bc100SJani Nikula 	struct intel_dp *intel_dp = &dig_port->dp;
2809379bc100SJani Nikula 	bool is_mst = intel_crtc_has_type(old_crtc_state,
2810379bc100SJani Nikula 					  INTEL_OUTPUT_DP_MST);
2811d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2812379bc100SJani Nikula 
2813c980216dSImre Deak 	if (!is_mst)
2814c980216dSImre Deak 		intel_dp_set_infoframes(encoder, false,
2815c980216dSImre Deak 					old_crtc_state, old_conn_state);
2816fa37a213SGwan-gyeong Mun 
2817379bc100SJani Nikula 	/*
2818379bc100SJani Nikula 	 * Power down sink before disabling the port, otherwise we end
2819379bc100SJani Nikula 	 * up getting interrupts from the sink on detecting link loss.
2820379bc100SJani Nikula 	 */
28210e634efdSVille Syrjälä 	intel_dp_set_power(intel_dp, DP_SET_POWER_D3);
282278eaaba3SJosé Roberto de Souza 
2823005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
2824c59053dcSJosé Roberto de Souza 		if (is_mst) {
2825c59053dcSJosé Roberto de Souza 			enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
2826c59053dcSJosé Roberto de Souza 			u32 val;
2827c59053dcSJosé Roberto de Souza 
2828f7960e7fSJani Nikula 			val = intel_de_read(dev_priv,
2829f7960e7fSJani Nikula 					    TRANS_DDI_FUNC_CTL(cpu_transcoder));
2830919e4f07SJosé Roberto de Souza 			val &= ~(TGL_TRANS_DDI_PORT_MASK |
2831919e4f07SJosé Roberto de Souza 				 TRANS_DDI_MODE_SELECT_MASK);
2832f7960e7fSJani Nikula 			intel_de_write(dev_priv,
2833f7960e7fSJani Nikula 				       TRANS_DDI_FUNC_CTL(cpu_transcoder),
2834f7960e7fSJani Nikula 				       val);
2835c59053dcSJosé Roberto de Souza 		}
2836c59053dcSJosé Roberto de Souza 	} else {
2837c59053dcSJosé Roberto de Souza 		if (!is_mst)
283850a7efb2SJosé Roberto de Souza 			intel_ddi_disable_pipe_clock(old_crtc_state);
2839c59053dcSJosé Roberto de Souza 	}
2840379bc100SJani Nikula 
2841379bc100SJani Nikula 	intel_disable_ddi_buf(encoder, old_crtc_state);
2842379bc100SJani Nikula 
28433ca8f191SJosé Roberto de Souza 	/*
28443ca8f191SJosé Roberto de Souza 	 * From TGL spec: "If single stream or multi-stream master transcoder:
28453ca8f191SJosé Roberto de Souza 	 * Configure Transcoder Clock select to direct no clock to the
28463ca8f191SJosé Roberto de Souza 	 * transcoder"
28473ca8f191SJosé Roberto de Souza 	 */
2848005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
28493ca8f191SJosé Roberto de Souza 		intel_ddi_disable_pipe_clock(old_crtc_state);
28503ca8f191SJosé Roberto de Souza 
2851eb46f498SJani Nikula 	intel_pps_vdd_on(intel_dp);
2852eb46f498SJani Nikula 	intel_pps_off(intel_dp);
2853379bc100SJani Nikula 
2854d8fe2ab6SMatt Roper 	if (!intel_phy_is_tc(dev_priv, phy) ||
28553b2ed431SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT)
2856a4550977SImre Deak 		intel_display_power_put(dev_priv,
2857a4550977SImre Deak 					dig_port->ddi_io_power_domain,
2858a4550977SImre Deak 					fetch_and_zero(&dig_port->ddi_io_wakeref));
2859379bc100SJani Nikula 
2860c133df69SVille Syrjälä 	intel_ddi_disable_clock(encoder);
2861379bc100SJani Nikula }
2862379bc100SJani Nikula 
2863ede9771dSVille Syrjälä static void intel_ddi_post_disable_hdmi(struct intel_atomic_state *state,
2864ede9771dSVille Syrjälä 					struct intel_encoder *encoder,
2865379bc100SJani Nikula 					const struct intel_crtc_state *old_crtc_state,
2866379bc100SJani Nikula 					const struct drm_connector_state *old_conn_state)
2867379bc100SJani Nikula {
2868379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2869b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2870379bc100SJani Nikula 	struct intel_hdmi *intel_hdmi = &dig_port->hdmi;
2871379bc100SJani Nikula 
2872379bc100SJani Nikula 	dig_port->set_infoframes(encoder, false,
2873379bc100SJani Nikula 				 old_crtc_state, old_conn_state);
2874379bc100SJani Nikula 
2875379bc100SJani Nikula 	intel_ddi_disable_pipe_clock(old_crtc_state);
2876379bc100SJani Nikula 
2877379bc100SJani Nikula 	intel_disable_ddi_buf(encoder, old_crtc_state);
2878379bc100SJani Nikula 
2879a4550977SImre Deak 	intel_display_power_put(dev_priv,
2880a4550977SImre Deak 				dig_port->ddi_io_power_domain,
2881a4550977SImre Deak 				fetch_and_zero(&dig_port->ddi_io_wakeref));
2882379bc100SJani Nikula 
2883c133df69SVille Syrjälä 	intel_ddi_disable_clock(encoder);
2884379bc100SJani Nikula 
2885379bc100SJani Nikula 	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
2886379bc100SJani Nikula }
2887379bc100SJani Nikula 
2888ede9771dSVille Syrjälä static void intel_ddi_post_disable(struct intel_atomic_state *state,
2889ede9771dSVille Syrjälä 				   struct intel_encoder *encoder,
2890379bc100SJani Nikula 				   const struct intel_crtc_state *old_crtc_state,
2891379bc100SJani Nikula 				   const struct drm_connector_state *old_conn_state)
2892379bc100SJani Nikula {
2893379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2894b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
289517bef9baSVille Syrjälä 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
289617bef9baSVille Syrjälä 	bool is_tc_port = intel_phy_is_tc(dev_priv, phy);
2897379bc100SJani Nikula 
28987829c92bSVille Syrjälä 	if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) {
2899773b4b54SVille Syrjälä 		intel_crtc_vblank_off(old_crtc_state);
2900773b4b54SVille Syrjälä 
2901773b4b54SVille Syrjälä 		intel_disable_pipe(old_crtc_state);
2902773b4b54SVille Syrjälä 
2903f0651232SManasi Navare 		intel_vrr_disable(old_crtc_state);
2904f0651232SManasi Navare 
2905773b4b54SVille Syrjälä 		intel_ddi_disable_transcoder_func(old_crtc_state);
2906773b4b54SVille Syrjälä 
2907773b4b54SVille Syrjälä 		intel_dsc_disable(old_crtc_state);
2908773b4b54SVille Syrjälä 
2909005e9537SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 9)
2910f6df4d46SLucas De Marchi 			skl_scaler_disable(old_crtc_state);
2911773b4b54SVille Syrjälä 		else
29129eae5e27SLucas De Marchi 			ilk_pfit_disable(old_crtc_state);
29137829c92bSVille Syrjälä 	}
2914773b4b54SVille Syrjälä 
29154e3cdb45SManasi Navare 	if (old_crtc_state->bigjoiner_linked_crtc) {
29164e3cdb45SManasi Navare 		struct intel_atomic_state *state =
29174e3cdb45SManasi Navare 			to_intel_atomic_state(old_crtc_state->uapi.state);
29184e3cdb45SManasi Navare 		struct intel_crtc *slave =
29194e3cdb45SManasi Navare 			old_crtc_state->bigjoiner_linked_crtc;
29204e3cdb45SManasi Navare 		const struct intel_crtc_state *old_slave_crtc_state =
29214e3cdb45SManasi Navare 			intel_atomic_get_old_crtc_state(state, slave);
29224e3cdb45SManasi Navare 
29234e3cdb45SManasi Navare 		intel_crtc_vblank_off(old_slave_crtc_state);
29244e3cdb45SManasi Navare 
29254e3cdb45SManasi Navare 		intel_dsc_disable(old_slave_crtc_state);
29264e3cdb45SManasi Navare 		skl_scaler_disable(old_slave_crtc_state);
29274e3cdb45SManasi Navare 	}
29284e3cdb45SManasi Navare 
2929379bc100SJani Nikula 	/*
2930379bc100SJani Nikula 	 * When called from DP MST code:
2931379bc100SJani Nikula 	 * - old_conn_state will be NULL
2932379bc100SJani Nikula 	 * - encoder will be the main encoder (ie. mst->primary)
2933379bc100SJani Nikula 	 * - the main connector associated with this port
2934379bc100SJani Nikula 	 *   won't be active or linked to a crtc
2935379bc100SJani Nikula 	 * - old_crtc_state will be the state of the last stream to
2936379bc100SJani Nikula 	 *   be deactivated on this port, and it may not be the same
2937379bc100SJani Nikula 	 *   stream that was activated last, but each stream
2938379bc100SJani Nikula 	 *   should have a state that is identical when it comes to
2939379bc100SJani Nikula 	 *   the DP link parameteres
2940379bc100SJani Nikula 	 */
2941379bc100SJani Nikula 
2942379bc100SJani Nikula 	if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
2943ede9771dSVille Syrjälä 		intel_ddi_post_disable_hdmi(state, encoder, old_crtc_state,
2944ede9771dSVille Syrjälä 					    old_conn_state);
2945379bc100SJani Nikula 	else
2946ede9771dSVille Syrjälä 		intel_ddi_post_disable_dp(state, encoder, old_crtc_state,
2947ede9771dSVille Syrjälä 					  old_conn_state);
2948379bc100SJani Nikula 
294917bef9baSVille Syrjälä 	if (intel_crtc_has_dp_encoder(old_crtc_state) || is_tc_port)
2950162e68e1SImre Deak 		intel_display_power_put(dev_priv,
2951162e68e1SImre Deak 					intel_ddi_main_link_aux_domain(dig_port),
2952162e68e1SImre Deak 					fetch_and_zero(&dig_port->aux_wakeref));
295317bef9baSVille Syrjälä 
295417bef9baSVille Syrjälä 	if (is_tc_port)
295517bef9baSVille Syrjälä 		intel_tc_port_put_link(dig_port);
2956379bc100SJani Nikula }
2957379bc100SJani Nikula 
2958ede9771dSVille Syrjälä void intel_ddi_fdi_post_disable(struct intel_atomic_state *state,
2959ede9771dSVille Syrjälä 				struct intel_encoder *encoder,
2960379bc100SJani Nikula 				const struct intel_crtc_state *old_crtc_state,
2961379bc100SJani Nikula 				const struct drm_connector_state *old_conn_state)
2962379bc100SJani Nikula {
2963379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2964379bc100SJani Nikula 	u32 val;
2965379bc100SJani Nikula 
2966379bc100SJani Nikula 	/*
2967379bc100SJani Nikula 	 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
2968379bc100SJani Nikula 	 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
2969379bc100SJani Nikula 	 * step 13 is the correct place for it. Step 18 is where it was
2970379bc100SJani Nikula 	 * originally before the BUN.
2971379bc100SJani Nikula 	 */
2972f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
2973379bc100SJani Nikula 	val &= ~FDI_RX_ENABLE;
2974f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
2975379bc100SJani Nikula 
2976379bc100SJani Nikula 	intel_disable_ddi_buf(encoder, old_crtc_state);
2977c133df69SVille Syrjälä 	intel_ddi_disable_clock(encoder);
2978379bc100SJani Nikula 
2979f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A));
2980379bc100SJani Nikula 	val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
2981379bc100SJani Nikula 	val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
2982f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), val);
2983379bc100SJani Nikula 
2984f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
2985379bc100SJani Nikula 	val &= ~FDI_PCDCLK;
2986f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
2987379bc100SJani Nikula 
2988f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
2989379bc100SJani Nikula 	val &= ~FDI_RX_PLL_ENABLE;
2990f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
2991379bc100SJani Nikula }
2992379bc100SJani Nikula 
2993d82a855aSVille Syrjälä static void trans_port_sync_stop_link_train(struct intel_atomic_state *state,
2994d82a855aSVille Syrjälä 					    struct intel_encoder *encoder,
2995d82a855aSVille Syrjälä 					    const struct intel_crtc_state *crtc_state)
2996d82a855aSVille Syrjälä {
2997d82a855aSVille Syrjälä 	const struct drm_connector_state *conn_state;
2998d82a855aSVille Syrjälä 	struct drm_connector *conn;
2999d82a855aSVille Syrjälä 	int i;
3000d82a855aSVille Syrjälä 
3001d82a855aSVille Syrjälä 	if (!crtc_state->sync_mode_slaves_mask)
3002d82a855aSVille Syrjälä 		return;
3003d82a855aSVille Syrjälä 
3004d82a855aSVille Syrjälä 	for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
3005d82a855aSVille Syrjälä 		struct intel_encoder *slave_encoder =
3006d82a855aSVille Syrjälä 			to_intel_encoder(conn_state->best_encoder);
3007d82a855aSVille Syrjälä 		struct intel_crtc *slave_crtc = to_intel_crtc(conn_state->crtc);
3008d82a855aSVille Syrjälä 		const struct intel_crtc_state *slave_crtc_state;
3009d82a855aSVille Syrjälä 
3010d82a855aSVille Syrjälä 		if (!slave_crtc)
3011d82a855aSVille Syrjälä 			continue;
3012d82a855aSVille Syrjälä 
3013d82a855aSVille Syrjälä 		slave_crtc_state =
3014d82a855aSVille Syrjälä 			intel_atomic_get_new_crtc_state(state, slave_crtc);
3015d82a855aSVille Syrjälä 
3016d82a855aSVille Syrjälä 		if (slave_crtc_state->master_transcoder !=
3017d82a855aSVille Syrjälä 		    crtc_state->cpu_transcoder)
3018d82a855aSVille Syrjälä 			continue;
3019d82a855aSVille Syrjälä 
3020a621860aSVille Syrjälä 		intel_dp_stop_link_train(enc_to_intel_dp(slave_encoder),
3021a621860aSVille Syrjälä 					 slave_crtc_state);
3022d82a855aSVille Syrjälä 	}
3023d82a855aSVille Syrjälä 
3024d82a855aSVille Syrjälä 	usleep_range(200, 400);
3025d82a855aSVille Syrjälä 
3026a621860aSVille Syrjälä 	intel_dp_stop_link_train(enc_to_intel_dp(encoder),
3027a621860aSVille Syrjälä 				 crtc_state);
3028d82a855aSVille Syrjälä }
3029d82a855aSVille Syrjälä 
3030ede9771dSVille Syrjälä static void intel_enable_ddi_dp(struct intel_atomic_state *state,
3031ede9771dSVille Syrjälä 				struct intel_encoder *encoder,
3032379bc100SJani Nikula 				const struct intel_crtc_state *crtc_state,
3033379bc100SJani Nikula 				const struct drm_connector_state *conn_state)
3034379bc100SJani Nikula {
3035379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3036b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3037998cc864SUma Shankar 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3038379bc100SJani Nikula 	enum port port = encoder->port;
3039379bc100SJani Nikula 
3040005e9537SMatt Roper 	if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
3041a621860aSVille Syrjälä 		intel_dp_stop_link_train(intel_dp, crtc_state);
3042379bc100SJani Nikula 
3043379bc100SJani Nikula 	intel_edp_backlight_on(crtc_state, conn_state);
30447a00e68bSGwan-gyeong Mun 	intel_psr_enable(intel_dp, crtc_state, conn_state);
3045998cc864SUma Shankar 
3046998cc864SUma Shankar 	if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
30471bf3657cSGwan-gyeong Mun 		intel_dp_set_infoframes(encoder, true, crtc_state, conn_state);
3048998cc864SUma Shankar 
3049379bc100SJani Nikula 	intel_edp_drrs_enable(intel_dp, crtc_state);
3050379bc100SJani Nikula 
3051379bc100SJani Nikula 	if (crtc_state->has_audio)
3052379bc100SJani Nikula 		intel_audio_codec_enable(encoder, crtc_state, conn_state);
3053d82a855aSVille Syrjälä 
3054d82a855aSVille Syrjälä 	trans_port_sync_stop_link_train(state, encoder, crtc_state);
3055379bc100SJani Nikula }
3056379bc100SJani Nikula 
3057379bc100SJani Nikula static i915_reg_t
3058379bc100SJani Nikula gen9_chicken_trans_reg_by_port(struct drm_i915_private *dev_priv,
3059379bc100SJani Nikula 			       enum port port)
3060379bc100SJani Nikula {
306112c4d4c1SVille Syrjälä 	static const enum transcoder trans[] = {
306212c4d4c1SVille Syrjälä 		[PORT_A] = TRANSCODER_EDP,
306312c4d4c1SVille Syrjälä 		[PORT_B] = TRANSCODER_A,
306412c4d4c1SVille Syrjälä 		[PORT_C] = TRANSCODER_B,
306512c4d4c1SVille Syrjälä 		[PORT_D] = TRANSCODER_C,
306612c4d4c1SVille Syrjälä 		[PORT_E] = TRANSCODER_A,
3067379bc100SJani Nikula 	};
3068379bc100SJani Nikula 
3069005e9537SMatt Roper 	drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) < 9);
3070379bc100SJani Nikula 
30711de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, port < PORT_A || port > PORT_E))
3072379bc100SJani Nikula 		port = PORT_A;
3073379bc100SJani Nikula 
307412c4d4c1SVille Syrjälä 	return CHICKEN_TRANS(trans[port]);
3075379bc100SJani Nikula }
3076379bc100SJani Nikula 
3077ede9771dSVille Syrjälä static void intel_enable_ddi_hdmi(struct intel_atomic_state *state,
3078ede9771dSVille Syrjälä 				  struct intel_encoder *encoder,
3079379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state,
3080379bc100SJani Nikula 				  const struct drm_connector_state *conn_state)
3081379bc100SJani Nikula {
3082379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3083b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3084379bc100SJani Nikula 	struct drm_connector *connector = conn_state->connector;
3085c9b69041SVille Syrjälä 	int level = intel_ddi_hdmi_level(encoder, crtc_state);
3086379bc100SJani Nikula 	enum port port = encoder->port;
3087379bc100SJani Nikula 
3088379bc100SJani Nikula 	if (!intel_hdmi_handle_sink_scrambling(encoder, connector,
3089379bc100SJani Nikula 					       crtc_state->hdmi_high_tmds_clock_ratio,
3090379bc100SJani Nikula 					       crtc_state->hdmi_scrambling))
309147bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
309247bdb1caSJani Nikula 			    "[CONNECTOR:%d:%s] Failed to configure sink scrambling/TMDS bit clock ratio\n",
3093379bc100SJani Nikula 			    connector->base.id, connector->name);
3094379bc100SJani Nikula 
3095005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
3096c9b69041SVille Syrjälä 		tgl_ddi_vswing_sequence(encoder, crtc_state, level);
3097*93e7e61eSLucas De Marchi 	else if (DISPLAY_VER(dev_priv) == 11)
3098c9b69041SVille Syrjälä 		icl_ddi_vswing_sequence(encoder, crtc_state, level);
3099c9b69041SVille Syrjälä 	else if (IS_CANNONLAKE(dev_priv))
3100c9b69041SVille Syrjälä 		cnl_ddi_vswing_sequence(encoder, crtc_state, level);
31012446e1d6SMatt Roper 	else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3102c9b69041SVille Syrjälä 		bxt_ddi_vswing_sequence(encoder, crtc_state, level);
3103c9b69041SVille Syrjälä 	else
3104c9b69041SVille Syrjälä 		intel_prepare_hdmi_ddi_buffers(encoder, level);
3105c9b69041SVille Syrjälä 
3106*93e7e61eSLucas De Marchi 	if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv))
3107c9b69041SVille Syrjälä 		skl_ddi_set_iboost(encoder, crtc_state, level);
3108c9b69041SVille Syrjälä 
3109379bc100SJani Nikula 	/* Display WA #1143: skl,kbl,cfl */
3110*93e7e61eSLucas De Marchi 	if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv)) {
3111379bc100SJani Nikula 		/*
3112379bc100SJani Nikula 		 * For some reason these chicken bits have been
3113379bc100SJani Nikula 		 * stuffed into a transcoder register, event though
3114379bc100SJani Nikula 		 * the bits affect a specific DDI port rather than
3115379bc100SJani Nikula 		 * a specific transcoder.
3116379bc100SJani Nikula 		 */
3117379bc100SJani Nikula 		i915_reg_t reg = gen9_chicken_trans_reg_by_port(dev_priv, port);
3118379bc100SJani Nikula 		u32 val;
3119379bc100SJani Nikula 
3120f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, reg);
3121379bc100SJani Nikula 
3122379bc100SJani Nikula 		if (port == PORT_E)
3123379bc100SJani Nikula 			val |= DDIE_TRAINING_OVERRIDE_ENABLE |
3124379bc100SJani Nikula 				DDIE_TRAINING_OVERRIDE_VALUE;
3125379bc100SJani Nikula 		else
3126379bc100SJani Nikula 			val |= DDI_TRAINING_OVERRIDE_ENABLE |
3127379bc100SJani Nikula 				DDI_TRAINING_OVERRIDE_VALUE;
3128379bc100SJani Nikula 
3129f7960e7fSJani Nikula 		intel_de_write(dev_priv, reg, val);
3130f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, reg);
3131379bc100SJani Nikula 
3132379bc100SJani Nikula 		udelay(1);
3133379bc100SJani Nikula 
3134379bc100SJani Nikula 		if (port == PORT_E)
3135379bc100SJani Nikula 			val &= ~(DDIE_TRAINING_OVERRIDE_ENABLE |
3136379bc100SJani Nikula 				 DDIE_TRAINING_OVERRIDE_VALUE);
3137379bc100SJani Nikula 		else
3138379bc100SJani Nikula 			val &= ~(DDI_TRAINING_OVERRIDE_ENABLE |
3139379bc100SJani Nikula 				 DDI_TRAINING_OVERRIDE_VALUE);
3140379bc100SJani Nikula 
3141f7960e7fSJani Nikula 		intel_de_write(dev_priv, reg, val);
3142379bc100SJani Nikula 	}
3143379bc100SJani Nikula 
31441e0cb7beSVille Syrjälä 	intel_ddi_power_up_lanes(encoder, crtc_state);
31451e0cb7beSVille Syrjälä 
3146379bc100SJani Nikula 	/* In HDMI/DVI mode, the port width, and swing/emphasis values
3147379bc100SJani Nikula 	 * are ignored so nothing special needs to be done besides
3148379bc100SJani Nikula 	 * enabling the port.
3149379bc100SJani Nikula 	 */
3150f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_CTL(port),
3151379bc100SJani Nikula 		       dig_port->saved_port_bits | DDI_BUF_CTL_ENABLE);
3152379bc100SJani Nikula 
3153379bc100SJani Nikula 	if (crtc_state->has_audio)
3154379bc100SJani Nikula 		intel_audio_codec_enable(encoder, crtc_state, conn_state);
3155379bc100SJani Nikula }
3156379bc100SJani Nikula 
3157ede9771dSVille Syrjälä static void intel_enable_ddi(struct intel_atomic_state *state,
3158ede9771dSVille Syrjälä 			     struct intel_encoder *encoder,
3159379bc100SJani Nikula 			     const struct intel_crtc_state *crtc_state,
3160379bc100SJani Nikula 			     const struct drm_connector_state *conn_state)
3161379bc100SJani Nikula {
31628b4f2137SPankaj Bharadiya 	drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder);
316321fd23acSJani Nikula 
31644e3cdb45SManasi Navare 	if (!crtc_state->bigjoiner_slave)
3165eed22a46SVille Syrjälä 		intel_ddi_enable_transcoder_func(encoder, crtc_state);
31667c2fedd7SVille Syrjälä 
3167aa52b39dSManasi Navare 	intel_vrr_enable(encoder, crtc_state);
3168aa52b39dSManasi Navare 
316921fd23acSJani Nikula 	intel_enable_pipe(crtc_state);
317021fd23acSJani Nikula 
317121fd23acSJani Nikula 	intel_crtc_vblank_on(crtc_state);
317221fd23acSJani Nikula 
3173379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
3174ede9771dSVille Syrjälä 		intel_enable_ddi_hdmi(state, encoder, crtc_state, conn_state);
3175379bc100SJani Nikula 	else
3176ede9771dSVille Syrjälä 		intel_enable_ddi_dp(state, encoder, crtc_state, conn_state);
3177379bc100SJani Nikula 
3178379bc100SJani Nikula 	/* Enable hdcp if it's desired */
3179379bc100SJani Nikula 	if (conn_state->content_protection ==
3180379bc100SJani Nikula 	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
3181d456512cSRamalingam C 		intel_hdcp_enable(to_intel_connector(conn_state->connector),
3182fc6097d4SAnshuman Gupta 				  crtc_state,
3183d456512cSRamalingam C 				  (u8)conn_state->hdcp_content_type);
3184379bc100SJani Nikula }
3185379bc100SJani Nikula 
3186ede9771dSVille Syrjälä static void intel_disable_ddi_dp(struct intel_atomic_state *state,
3187ede9771dSVille Syrjälä 				 struct intel_encoder *encoder,
3188379bc100SJani Nikula 				 const struct intel_crtc_state *old_crtc_state,
3189379bc100SJani Nikula 				 const struct drm_connector_state *old_conn_state)
3190379bc100SJani Nikula {
3191b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3192379bc100SJani Nikula 
3193379bc100SJani Nikula 	intel_dp->link_trained = false;
3194379bc100SJani Nikula 
3195379bc100SJani Nikula 	if (old_crtc_state->has_audio)
3196379bc100SJani Nikula 		intel_audio_codec_disable(encoder,
3197379bc100SJani Nikula 					  old_crtc_state, old_conn_state);
3198379bc100SJani Nikula 
3199379bc100SJani Nikula 	intel_edp_drrs_disable(intel_dp, old_crtc_state);
3200379bc100SJani Nikula 	intel_psr_disable(intel_dp, old_crtc_state);
3201379bc100SJani Nikula 	intel_edp_backlight_off(old_conn_state);
3202379bc100SJani Nikula 	/* Disable the decompression in DP Sink */
3203379bc100SJani Nikula 	intel_dp_sink_set_decompression_state(intel_dp, old_crtc_state,
3204379bc100SJani Nikula 					      false);
32051639406aSManasi Navare 	/* Disable Ignore_MSA bit in DP Sink */
32061639406aSManasi Navare 	intel_dp_sink_set_msa_timing_par_ignore_state(intel_dp, old_crtc_state,
32071639406aSManasi Navare 						      false);
3208379bc100SJani Nikula }
3209379bc100SJani Nikula 
3210ede9771dSVille Syrjälä static void intel_disable_ddi_hdmi(struct intel_atomic_state *state,
3211ede9771dSVille Syrjälä 				   struct intel_encoder *encoder,
3212379bc100SJani Nikula 				   const struct intel_crtc_state *old_crtc_state,
3213379bc100SJani Nikula 				   const struct drm_connector_state *old_conn_state)
3214379bc100SJani Nikula {
321547bdb1caSJani Nikula 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3216379bc100SJani Nikula 	struct drm_connector *connector = old_conn_state->connector;
3217379bc100SJani Nikula 
3218379bc100SJani Nikula 	if (old_crtc_state->has_audio)
3219379bc100SJani Nikula 		intel_audio_codec_disable(encoder,
3220379bc100SJani Nikula 					  old_crtc_state, old_conn_state);
3221379bc100SJani Nikula 
3222379bc100SJani Nikula 	if (!intel_hdmi_handle_sink_scrambling(encoder, connector,
3223379bc100SJani Nikula 					       false, false))
322447bdb1caSJani Nikula 		drm_dbg_kms(&i915->drm,
322547bdb1caSJani Nikula 			    "[CONNECTOR:%d:%s] Failed to reset sink scrambling/TMDS bit clock ratio\n",
3226379bc100SJani Nikula 			    connector->base.id, connector->name);
3227379bc100SJani Nikula }
3228379bc100SJani Nikula 
3229ede9771dSVille Syrjälä static void intel_disable_ddi(struct intel_atomic_state *state,
3230ede9771dSVille Syrjälä 			      struct intel_encoder *encoder,
3231379bc100SJani Nikula 			      const struct intel_crtc_state *old_crtc_state,
3232379bc100SJani Nikula 			      const struct drm_connector_state *old_conn_state)
3233379bc100SJani Nikula {
3234379bc100SJani Nikula 	intel_hdcp_disable(to_intel_connector(old_conn_state->connector));
3235379bc100SJani Nikula 
3236379bc100SJani Nikula 	if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
3237ede9771dSVille Syrjälä 		intel_disable_ddi_hdmi(state, encoder, old_crtc_state,
3238ede9771dSVille Syrjälä 				       old_conn_state);
3239379bc100SJani Nikula 	else
3240ede9771dSVille Syrjälä 		intel_disable_ddi_dp(state, encoder, old_crtc_state,
3241ede9771dSVille Syrjälä 				     old_conn_state);
3242379bc100SJani Nikula }
3243379bc100SJani Nikula 
3244ede9771dSVille Syrjälä static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
3245ede9771dSVille Syrjälä 				     struct intel_encoder *encoder,
3246379bc100SJani Nikula 				     const struct intel_crtc_state *crtc_state,
3247379bc100SJani Nikula 				     const struct drm_connector_state *conn_state)
3248379bc100SJani Nikula {
3249b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3250379bc100SJani Nikula 
32510c06fa15SGwan-gyeong Mun 	intel_ddi_set_dp_msa(crtc_state, conn_state);
3252379bc100SJani Nikula 
32537a00e68bSGwan-gyeong Mun 	intel_psr_update(intel_dp, crtc_state, conn_state);
325476d45d06SGwan-gyeong Mun 	intel_dp_set_infoframes(encoder, true, crtc_state, conn_state);
32558040fefaSJosé Roberto de Souza 	intel_edp_drrs_update(intel_dp, crtc_state);
3256379bc100SJani Nikula 
3257ede9771dSVille Syrjälä 	intel_panel_update_backlight(state, encoder, crtc_state, conn_state);
3258379bc100SJani Nikula }
3259379bc100SJani Nikula 
3260f1c7a36bSSean Paul void intel_ddi_update_pipe(struct intel_atomic_state *state,
3261ede9771dSVille Syrjälä 			   struct intel_encoder *encoder,
3262379bc100SJani Nikula 			   const struct intel_crtc_state *crtc_state,
3263379bc100SJani Nikula 			   const struct drm_connector_state *conn_state)
3264379bc100SJani Nikula {
3265d456512cSRamalingam C 
3266f1c7a36bSSean Paul 	if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) &&
3267f1c7a36bSSean Paul 	    !intel_encoder_is_mst(encoder))
3268ede9771dSVille Syrjälä 		intel_ddi_update_pipe_dp(state, encoder, crtc_state,
3269ede9771dSVille Syrjälä 					 conn_state);
3270379bc100SJani Nikula 
3271ede9771dSVille Syrjälä 	intel_hdcp_update_pipe(state, encoder, crtc_state, conn_state);
3272379bc100SJani Nikula }
3273379bc100SJani Nikula 
3274379bc100SJani Nikula static void
327524a7bfe0SImre Deak intel_ddi_update_prepare(struct intel_atomic_state *state,
327624a7bfe0SImre Deak 			 struct intel_encoder *encoder,
327724a7bfe0SImre Deak 			 struct intel_crtc *crtc)
327824a7bfe0SImre Deak {
327924a7bfe0SImre Deak 	struct intel_crtc_state *crtc_state =
328024a7bfe0SImre Deak 		crtc ? intel_atomic_get_new_crtc_state(state, crtc) : NULL;
328124a7bfe0SImre Deak 	int required_lanes = crtc_state ? crtc_state->lane_count : 1;
328224a7bfe0SImre Deak 
32838b4f2137SPankaj Bharadiya 	drm_WARN_ON(state->base.dev, crtc && crtc->active);
328424a7bfe0SImre Deak 
3285b7d02c3aSVille Syrjälä 	intel_tc_port_get_link(enc_to_dig_port(encoder),
3286b7d02c3aSVille Syrjälä 		               required_lanes);
32871326a92cSMaarten Lankhorst 	if (crtc_state && crtc_state->hw.active)
328824a7bfe0SImre Deak 		intel_update_active_dpll(state, crtc, encoder);
328924a7bfe0SImre Deak }
329024a7bfe0SImre Deak 
329124a7bfe0SImre Deak static void
329224a7bfe0SImre Deak intel_ddi_update_complete(struct intel_atomic_state *state,
329324a7bfe0SImre Deak 			  struct intel_encoder *encoder,
329424a7bfe0SImre Deak 			  struct intel_crtc *crtc)
329524a7bfe0SImre Deak {
3296b7d02c3aSVille Syrjälä 	intel_tc_port_put_link(enc_to_dig_port(encoder));
329724a7bfe0SImre Deak }
329824a7bfe0SImre Deak 
329924a7bfe0SImre Deak static void
3300ede9771dSVille Syrjälä intel_ddi_pre_pll_enable(struct intel_atomic_state *state,
3301ede9771dSVille Syrjälä 			 struct intel_encoder *encoder,
3302379bc100SJani Nikula 			 const struct intel_crtc_state *crtc_state,
3303379bc100SJani Nikula 			 const struct drm_connector_state *conn_state)
3304379bc100SJani Nikula {
3305379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3306b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3307d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
3308d8fe2ab6SMatt Roper 	bool is_tc_port = intel_phy_is_tc(dev_priv, phy);
3309379bc100SJani Nikula 
331024a7bfe0SImre Deak 	if (is_tc_port)
331124a7bfe0SImre Deak 		intel_tc_port_get_link(dig_port, crtc_state->lane_count);
331224a7bfe0SImre Deak 
3313162e68e1SImre Deak 	if (intel_crtc_has_dp_encoder(crtc_state) || is_tc_port) {
3314162e68e1SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->aux_wakeref);
3315162e68e1SImre Deak 		dig_port->aux_wakeref =
3316379bc100SJani Nikula 			intel_display_power_get(dev_priv,
3317379bc100SJani Nikula 						intel_ddi_main_link_aux_domain(dig_port));
3318162e68e1SImre Deak 	}
3319379bc100SJani Nikula 
33209d44dcb9SLucas De Marchi 	if (is_tc_port && dig_port->tc_mode != TC_PORT_TBT_ALT)
33219d44dcb9SLucas De Marchi 		/*
33229d44dcb9SLucas De Marchi 		 * Program the lane count for static/dynamic connections on
33239d44dcb9SLucas De Marchi 		 * Type-C ports.  Skip this step for TBT.
33249d44dcb9SLucas De Marchi 		 */
33259d44dcb9SLucas De Marchi 		intel_tc_port_set_fia_lane_count(dig_port, crtc_state->lane_count);
33262446e1d6SMatt Roper 	else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3327379bc100SJani Nikula 		bxt_ddi_phy_set_lane_optim_mask(encoder,
3328379bc100SJani Nikula 						crtc_state->lane_lat_optim_mask);
3329379bc100SJani Nikula }
3330379bc100SJani Nikula 
3331a621860aSVille Syrjälä static void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp,
3332a621860aSVille Syrjälä 					   const struct intel_crtc_state *crtc_state)
3333379bc100SJani Nikula {
3334ef79fafeSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3335ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3336ef79fafeSVille Syrjälä 	enum port port = encoder->port;
333735ac28a8SLucas De Marchi 	u32 dp_tp_ctl, ddi_buf_ctl;
3338379bc100SJani Nikula 	bool wait = false;
3339379bc100SJani Nikula 
3340ef79fafeSVille Syrjälä 	dp_tp_ctl = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
334135ac28a8SLucas De Marchi 
334235ac28a8SLucas De Marchi 	if (dp_tp_ctl & DP_TP_CTL_ENABLE) {
3343f7960e7fSJani Nikula 		ddi_buf_ctl = intel_de_read(dev_priv, DDI_BUF_CTL(port));
334435ac28a8SLucas De Marchi 		if (ddi_buf_ctl & DDI_BUF_CTL_ENABLE) {
3345f7960e7fSJani Nikula 			intel_de_write(dev_priv, DDI_BUF_CTL(port),
334635ac28a8SLucas De Marchi 				       ddi_buf_ctl & ~DDI_BUF_CTL_ENABLE);
3347379bc100SJani Nikula 			wait = true;
3348379bc100SJani Nikula 		}
3349379bc100SJani Nikula 
335035ac28a8SLucas De Marchi 		dp_tp_ctl &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
335135ac28a8SLucas De Marchi 		dp_tp_ctl |= DP_TP_CTL_LINK_TRAIN_PAT1;
3352ef79fafeSVille Syrjälä 		intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), dp_tp_ctl);
3353ef79fafeSVille Syrjälä 		intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3354379bc100SJani Nikula 
3355379bc100SJani Nikula 		if (wait)
3356379bc100SJani Nikula 			intel_wait_ddi_buf_idle(dev_priv, port);
3357379bc100SJani Nikula 	}
3358379bc100SJani Nikula 
3359963501bdSImre Deak 	dp_tp_ctl = DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_PAT1;
3360a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
336135ac28a8SLucas De Marchi 		dp_tp_ctl |= DP_TP_CTL_MODE_MST;
3362a621860aSVille Syrjälä 	} else {
336335ac28a8SLucas De Marchi 		dp_tp_ctl |= DP_TP_CTL_MODE_SST;
3364379bc100SJani Nikula 		if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
336535ac28a8SLucas De Marchi 			dp_tp_ctl |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
3366379bc100SJani Nikula 	}
3367ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), dp_tp_ctl);
3368ef79fafeSVille Syrjälä 	intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3369379bc100SJani Nikula 
3370379bc100SJani Nikula 	intel_dp->DP |= DDI_BUF_CTL_ENABLE;
3371f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP);
3372f7960e7fSJani Nikula 	intel_de_posting_read(dev_priv, DDI_BUF_CTL(port));
3373379bc100SJani Nikula 
3374e828da30SManasi Navare 	intel_wait_ddi_buf_active(dev_priv, port);
3375379bc100SJani Nikula }
3376379bc100SJani Nikula 
3377eee3f911SVille Syrjälä static void intel_ddi_set_link_train(struct intel_dp *intel_dp,
3378a621860aSVille Syrjälä 				     const struct intel_crtc_state *crtc_state,
3379eee3f911SVille Syrjälä 				     u8 dp_train_pat)
3380eee3f911SVille Syrjälä {
3381ef79fafeSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3382ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3383eee3f911SVille Syrjälä 	u32 temp;
3384eee3f911SVille Syrjälä 
3385ef79fafeSVille Syrjälä 	temp = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3386eee3f911SVille Syrjälä 
3387eee3f911SVille Syrjälä 	temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
33886777a855SImre Deak 	switch (intel_dp_training_pattern_symbol(dp_train_pat)) {
3389eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_DISABLE:
3390eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
3391eee3f911SVille Syrjälä 		break;
3392eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_1:
3393eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
3394eee3f911SVille Syrjälä 		break;
3395eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_2:
3396eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
3397eee3f911SVille Syrjälä 		break;
3398eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_3:
3399eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
3400eee3f911SVille Syrjälä 		break;
3401eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_4:
3402eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT4;
3403eee3f911SVille Syrjälä 		break;
3404eee3f911SVille Syrjälä 	}
3405eee3f911SVille Syrjälä 
3406ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), temp);
3407eee3f911SVille Syrjälä }
3408eee3f911SVille Syrjälä 
3409a621860aSVille Syrjälä static void intel_ddi_set_idle_link_train(struct intel_dp *intel_dp,
3410a621860aSVille Syrjälä 					  const struct intel_crtc_state *crtc_state)
34118fdda385SVille Syrjälä {
34128fdda385SVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
34138fdda385SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
34148fdda385SVille Syrjälä 	enum port port = encoder->port;
34158fdda385SVille Syrjälä 	u32 val;
34168fdda385SVille Syrjälä 
3417ef79fafeSVille Syrjälä 	val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
34188fdda385SVille Syrjälä 	val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
34198fdda385SVille Syrjälä 	val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3420ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
34218fdda385SVille Syrjälä 
34228fdda385SVille Syrjälä 	/*
34238fdda385SVille Syrjälä 	 * Until TGL on PORT_A we can have only eDP in SST mode. There the only
34248fdda385SVille Syrjälä 	 * reason we need to set idle transmission mode is to work around a HW
34258fdda385SVille Syrjälä 	 * issue where we enable the pipe while not in idle link-training mode.
34268fdda385SVille Syrjälä 	 * In this case there is requirement to wait for a minimum number of
34278fdda385SVille Syrjälä 	 * idle patterns to be sent.
34288fdda385SVille Syrjälä 	 */
3429005e9537SMatt Roper 	if (port == PORT_A && DISPLAY_VER(dev_priv) < 12)
34308fdda385SVille Syrjälä 		return;
34318fdda385SVille Syrjälä 
3432ef79fafeSVille Syrjälä 	if (intel_de_wait_for_set(dev_priv,
3433ef79fafeSVille Syrjälä 				  dp_tp_status_reg(encoder, crtc_state),
34348fdda385SVille Syrjälä 				  DP_TP_STATUS_IDLE_DONE, 1))
34358fdda385SVille Syrjälä 		drm_err(&dev_priv->drm,
34368fdda385SVille Syrjälä 			"Timed out waiting for DP idle patterns\n");
34378fdda385SVille Syrjälä }
34388fdda385SVille Syrjälä 
3439379bc100SJani Nikula static bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
3440379bc100SJani Nikula 				       enum transcoder cpu_transcoder)
3441379bc100SJani Nikula {
3442379bc100SJani Nikula 	if (cpu_transcoder == TRANSCODER_EDP)
3443379bc100SJani Nikula 		return false;
3444379bc100SJani Nikula 
3445379bc100SJani Nikula 	if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO))
3446379bc100SJani Nikula 		return false;
3447379bc100SJani Nikula 
3448f7960e7fSJani Nikula 	return intel_de_read(dev_priv, HSW_AUD_PIN_ELD_CP_VLD) &
3449379bc100SJani Nikula 		AUDIO_OUTPUT_ENABLE(cpu_transcoder);
3450379bc100SJani Nikula }
3451379bc100SJani Nikula 
3452379bc100SJani Nikula void intel_ddi_compute_min_voltage_level(struct drm_i915_private *dev_priv,
3453379bc100SJani Nikula 					 struct intel_crtc_state *crtc_state)
3454379bc100SJani Nikula {
3455005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12 && crtc_state->port_clock > 594000)
34560fde0b1dSMatt Roper 		crtc_state->min_voltage_level = 2;
345724ea098bSTejas Upadhyay 	else if (IS_JSL_EHL(dev_priv) && crtc_state->port_clock > 594000)
34589d5fd37eSMatt Roper 		crtc_state->min_voltage_level = 3;
3459005e9537SMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 11 && crtc_state->port_clock > 594000)
3460379bc100SJani Nikula 		crtc_state->min_voltage_level = 1;
3461379bc100SJani Nikula 	else if (IS_CANNONLAKE(dev_priv) && crtc_state->port_clock > 594000)
3462379bc100SJani Nikula 		crtc_state->min_voltage_level = 2;
3463379bc100SJani Nikula }
3464379bc100SJani Nikula 
3465dc5b8ed5SVille Syrjälä static enum transcoder bdw_transcoder_master_readout(struct drm_i915_private *dev_priv,
346602d8ea47SVille Syrjälä 						     enum transcoder cpu_transcoder)
346702d8ea47SVille Syrjälä {
3468dc5b8ed5SVille Syrjälä 	u32 master_select;
346902d8ea47SVille Syrjälä 
3470005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11) {
3471dc5b8ed5SVille Syrjälä 		u32 ctl2 = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL2(cpu_transcoder));
347202d8ea47SVille Syrjälä 
347302d8ea47SVille Syrjälä 		if ((ctl2 & PORT_SYNC_MODE_ENABLE) == 0)
347402d8ea47SVille Syrjälä 			return INVALID_TRANSCODER;
347502d8ea47SVille Syrjälä 
3476d4d7d9caSVille Syrjälä 		master_select = REG_FIELD_GET(PORT_SYNC_MODE_MASTER_SELECT_MASK, ctl2);
3477dc5b8ed5SVille Syrjälä 	} else {
3478dc5b8ed5SVille Syrjälä 		u32 ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3479dc5b8ed5SVille Syrjälä 
3480dc5b8ed5SVille Syrjälä 		if ((ctl & TRANS_DDI_PORT_SYNC_ENABLE) == 0)
3481dc5b8ed5SVille Syrjälä 			return INVALID_TRANSCODER;
3482dc5b8ed5SVille Syrjälä 
3483dc5b8ed5SVille Syrjälä 		master_select = REG_FIELD_GET(TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK, ctl);
3484dc5b8ed5SVille Syrjälä 	}
348502d8ea47SVille Syrjälä 
348602d8ea47SVille Syrjälä 	if (master_select == 0)
348702d8ea47SVille Syrjälä 		return TRANSCODER_EDP;
348802d8ea47SVille Syrjälä 	else
348902d8ea47SVille Syrjälä 		return master_select - 1;
349002d8ea47SVille Syrjälä }
349102d8ea47SVille Syrjälä 
3492dc5b8ed5SVille Syrjälä static void bdw_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
349302d8ea47SVille Syrjälä {
349402d8ea47SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
349502d8ea47SVille Syrjälä 	u32 transcoders = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
349602d8ea47SVille Syrjälä 		BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
349702d8ea47SVille Syrjälä 	enum transcoder cpu_transcoder;
349802d8ea47SVille Syrjälä 
349902d8ea47SVille Syrjälä 	crtc_state->master_transcoder =
3500dc5b8ed5SVille Syrjälä 		bdw_transcoder_master_readout(dev_priv, crtc_state->cpu_transcoder);
350102d8ea47SVille Syrjälä 
350202d8ea47SVille Syrjälä 	for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) {
350302d8ea47SVille Syrjälä 		enum intel_display_power_domain power_domain;
350402d8ea47SVille Syrjälä 		intel_wakeref_t trans_wakeref;
350502d8ea47SVille Syrjälä 
350602d8ea47SVille Syrjälä 		power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
350702d8ea47SVille Syrjälä 		trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
350802d8ea47SVille Syrjälä 								   power_domain);
350902d8ea47SVille Syrjälä 
351002d8ea47SVille Syrjälä 		if (!trans_wakeref)
351102d8ea47SVille Syrjälä 			continue;
351202d8ea47SVille Syrjälä 
3513dc5b8ed5SVille Syrjälä 		if (bdw_transcoder_master_readout(dev_priv, cpu_transcoder) ==
351402d8ea47SVille Syrjälä 		    crtc_state->cpu_transcoder)
351502d8ea47SVille Syrjälä 			crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder);
351602d8ea47SVille Syrjälä 
351702d8ea47SVille Syrjälä 		intel_display_power_put(dev_priv, power_domain, trans_wakeref);
351802d8ea47SVille Syrjälä 	}
351902d8ea47SVille Syrjälä 
352002d8ea47SVille Syrjälä 	drm_WARN_ON(&dev_priv->drm,
352102d8ea47SVille Syrjälä 		    crtc_state->master_transcoder != INVALID_TRANSCODER &&
352202d8ea47SVille Syrjälä 		    crtc_state->sync_mode_slaves_mask);
352302d8ea47SVille Syrjälä }
352402d8ea47SVille Syrjälä 
35250385eceaSManasi Navare static void intel_ddi_read_func_ctl(struct intel_encoder *encoder,
3526379bc100SJani Nikula 				    struct intel_crtc_state *pipe_config)
3527379bc100SJani Nikula {
3528379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
35292225f3c6SMaarten Lankhorst 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
3530379bc100SJani Nikula 	enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
3531a44289b9SUma Shankar 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3532379bc100SJani Nikula 	u32 temp, flags = 0;
3533379bc100SJani Nikula 
3534f7960e7fSJani Nikula 	temp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3535379bc100SJani Nikula 	if (temp & TRANS_DDI_PHSYNC)
3536379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_PHSYNC;
3537379bc100SJani Nikula 	else
3538379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_NHSYNC;
3539379bc100SJani Nikula 	if (temp & TRANS_DDI_PVSYNC)
3540379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_PVSYNC;
3541379bc100SJani Nikula 	else
3542379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_NVSYNC;
3543379bc100SJani Nikula 
35441326a92cSMaarten Lankhorst 	pipe_config->hw.adjusted_mode.flags |= flags;
3545379bc100SJani Nikula 
3546379bc100SJani Nikula 	switch (temp & TRANS_DDI_BPC_MASK) {
3547379bc100SJani Nikula 	case TRANS_DDI_BPC_6:
3548379bc100SJani Nikula 		pipe_config->pipe_bpp = 18;
3549379bc100SJani Nikula 		break;
3550379bc100SJani Nikula 	case TRANS_DDI_BPC_8:
3551379bc100SJani Nikula 		pipe_config->pipe_bpp = 24;
3552379bc100SJani Nikula 		break;
3553379bc100SJani Nikula 	case TRANS_DDI_BPC_10:
3554379bc100SJani Nikula 		pipe_config->pipe_bpp = 30;
3555379bc100SJani Nikula 		break;
3556379bc100SJani Nikula 	case TRANS_DDI_BPC_12:
3557379bc100SJani Nikula 		pipe_config->pipe_bpp = 36;
3558379bc100SJani Nikula 		break;
3559379bc100SJani Nikula 	default:
3560379bc100SJani Nikula 		break;
3561379bc100SJani Nikula 	}
3562379bc100SJani Nikula 
3563379bc100SJani Nikula 	switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
3564379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_HDMI:
3565379bc100SJani Nikula 		pipe_config->has_hdmi_sink = true;
3566379bc100SJani Nikula 
3567379bc100SJani Nikula 		pipe_config->infoframes.enable |=
3568379bc100SJani Nikula 			intel_hdmi_infoframes_enabled(encoder, pipe_config);
3569379bc100SJani Nikula 
3570379bc100SJani Nikula 		if (pipe_config->infoframes.enable)
3571379bc100SJani Nikula 			pipe_config->has_infoframe = true;
3572379bc100SJani Nikula 
3573379bc100SJani Nikula 		if (temp & TRANS_DDI_HDMI_SCRAMBLING)
3574379bc100SJani Nikula 			pipe_config->hdmi_scrambling = true;
3575379bc100SJani Nikula 		if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
3576379bc100SJani Nikula 			pipe_config->hdmi_high_tmds_clock_ratio = true;
3577df561f66SGustavo A. R. Silva 		fallthrough;
3578379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DVI:
3579379bc100SJani Nikula 		pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI);
3580379bc100SJani Nikula 		pipe_config->lane_count = 4;
3581379bc100SJani Nikula 		break;
3582379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_FDI:
3583379bc100SJani Nikula 		pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG);
3584379bc100SJani Nikula 		break;
3585379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_SST:
3586379bc100SJani Nikula 		if (encoder->type == INTEL_OUTPUT_EDP)
3587379bc100SJani Nikula 			pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
3588379bc100SJani Nikula 		else
3589379bc100SJani Nikula 			pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
3590379bc100SJani Nikula 		pipe_config->lane_count =
3591379bc100SJani Nikula 			((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
3592379bc100SJani Nikula 		intel_dp_get_m_n(intel_crtc, pipe_config);
35938aa940c8SMaarten Lankhorst 
3594005e9537SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 11) {
3595ef79fafeSVille Syrjälä 			i915_reg_t dp_tp_ctl = dp_tp_ctl_reg(encoder, pipe_config);
35968aa940c8SMaarten Lankhorst 
35978aa940c8SMaarten Lankhorst 			pipe_config->fec_enable =
3598f7960e7fSJani Nikula 				intel_de_read(dev_priv, dp_tp_ctl) & DP_TP_CTL_FEC_ENABLE;
35998aa940c8SMaarten Lankhorst 
360047bdb1caSJani Nikula 			drm_dbg_kms(&dev_priv->drm,
360147bdb1caSJani Nikula 				    "[ENCODER:%d:%s] Fec status: %u\n",
36028aa940c8SMaarten Lankhorst 				    encoder->base.base.id, encoder->base.name,
36038aa940c8SMaarten Lankhorst 				    pipe_config->fec_enable);
36048aa940c8SMaarten Lankhorst 		}
36058aa940c8SMaarten Lankhorst 
3606a44289b9SUma Shankar 		if (dig_port->lspcon.active && dig_port->dp.has_hdmi_sink)
3607a44289b9SUma Shankar 			pipe_config->infoframes.enable |=
3608a44289b9SUma Shankar 				intel_lspcon_infoframes_enabled(encoder, pipe_config);
3609a44289b9SUma Shankar 		else
3610dee66f3eSGwan-gyeong Mun 			pipe_config->infoframes.enable |=
3611dee66f3eSGwan-gyeong Mun 				intel_hdmi_infoframes_enabled(encoder, pipe_config);
3612379bc100SJani Nikula 		break;
3613379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_MST:
3614379bc100SJani Nikula 		pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST);
3615379bc100SJani Nikula 		pipe_config->lane_count =
3616379bc100SJani Nikula 			((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
36176671c367SJosé Roberto de Souza 
3618005e9537SMatt Roper 		if (DISPLAY_VER(dev_priv) >= 12)
36196671c367SJosé Roberto de Souza 			pipe_config->mst_master_transcoder =
36206671c367SJosé Roberto de Souza 					REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK, temp);
36216671c367SJosé Roberto de Souza 
3622379bc100SJani Nikula 		intel_dp_get_m_n(intel_crtc, pipe_config);
3623dee66f3eSGwan-gyeong Mun 
3624dee66f3eSGwan-gyeong Mun 		pipe_config->infoframes.enable |=
3625dee66f3eSGwan-gyeong Mun 			intel_hdmi_infoframes_enabled(encoder, pipe_config);
3626379bc100SJani Nikula 		break;
3627379bc100SJani Nikula 	default:
3628379bc100SJani Nikula 		break;
3629379bc100SJani Nikula 	}
36300385eceaSManasi Navare }
36310385eceaSManasi Navare 
3632351221ffSVille Syrjälä static void intel_ddi_get_config(struct intel_encoder *encoder,
36330385eceaSManasi Navare 				 struct intel_crtc_state *pipe_config)
36340385eceaSManasi Navare {
36350385eceaSManasi Navare 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
36360385eceaSManasi Navare 	enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
36370385eceaSManasi Navare 
36380385eceaSManasi Navare 	/* XXX: DSI transcoder paranoia */
36390385eceaSManasi Navare 	if (drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder)))
36400385eceaSManasi Navare 		return;
36410385eceaSManasi Navare 
36420385eceaSManasi Navare 	if (pipe_config->bigjoiner_slave) {
36430385eceaSManasi Navare 		/* read out pipe settings from master */
36440385eceaSManasi Navare 		enum transcoder save = pipe_config->cpu_transcoder;
36450385eceaSManasi Navare 
36460385eceaSManasi Navare 		/* Our own transcoder needs to be disabled when reading it in intel_ddi_read_func_ctl() */
36470385eceaSManasi Navare 		WARN_ON(pipe_config->output_types);
36480385eceaSManasi Navare 		pipe_config->cpu_transcoder = (enum transcoder)pipe_config->bigjoiner_linked_crtc->pipe;
36490385eceaSManasi Navare 		intel_ddi_read_func_ctl(encoder, pipe_config);
36500385eceaSManasi Navare 		pipe_config->cpu_transcoder = save;
36510385eceaSManasi Navare 	} else {
36520385eceaSManasi Navare 		intel_ddi_read_func_ctl(encoder, pipe_config);
36530385eceaSManasi Navare 	}
3654379bc100SJani Nikula 
36555b616a29SJani Nikula 	intel_ddi_mso_get_config(encoder, pipe_config);
36565b616a29SJani Nikula 
3657379bc100SJani Nikula 	pipe_config->has_audio =
3658379bc100SJani Nikula 		intel_ddi_is_audio_enabled(dev_priv, cpu_transcoder);
3659379bc100SJani Nikula 
3660379bc100SJani Nikula 	if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
3661379bc100SJani Nikula 	    pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
3662379bc100SJani Nikula 		/*
3663379bc100SJani Nikula 		 * This is a big fat ugly hack.
3664379bc100SJani Nikula 		 *
3665379bc100SJani Nikula 		 * Some machines in UEFI boot mode provide us a VBT that has 18
3666379bc100SJani Nikula 		 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
3667379bc100SJani Nikula 		 * unknown we fail to light up. Yet the same BIOS boots up with
3668379bc100SJani Nikula 		 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
3669379bc100SJani Nikula 		 * max, not what it tells us to use.
3670379bc100SJani Nikula 		 *
3671379bc100SJani Nikula 		 * Note: This will still be broken if the eDP panel is not lit
3672379bc100SJani Nikula 		 * up by the BIOS, and thus we can't get the mode at module
3673379bc100SJani Nikula 		 * load.
3674379bc100SJani Nikula 		 */
367547bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
367647bdb1caSJani Nikula 			    "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
3677379bc100SJani Nikula 			    pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
3678379bc100SJani Nikula 		dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
3679379bc100SJani Nikula 	}
3680379bc100SJani Nikula 
36810385eceaSManasi Navare 	if (!pipe_config->bigjoiner_slave)
3682351221ffSVille Syrjälä 		ddi_dotclock_get(pipe_config);
3683379bc100SJani Nikula 
36842446e1d6SMatt Roper 	if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3685379bc100SJani Nikula 		pipe_config->lane_lat_optim_mask =
3686379bc100SJani Nikula 			bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
3687379bc100SJani Nikula 
3688379bc100SJani Nikula 	intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
3689379bc100SJani Nikula 
3690379bc100SJani Nikula 	intel_hdmi_read_gcp_infoframe(encoder, pipe_config);
3691379bc100SJani Nikula 
3692379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
3693379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_AVI,
3694379bc100SJani Nikula 			     &pipe_config->infoframes.avi);
3695379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
3696379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_SPD,
3697379bc100SJani Nikula 			     &pipe_config->infoframes.spd);
3698379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
3699379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_VENDOR,
3700379bc100SJani Nikula 			     &pipe_config->infoframes.hdmi);
3701379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
3702379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_DRM,
3703379bc100SJani Nikula 			     &pipe_config->infoframes.drm);
370402d8ea47SVille Syrjälä 
3705005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 8)
3706dc5b8ed5SVille Syrjälä 		bdw_get_trans_port_sync_config(pipe_config);
3707dee66f3eSGwan-gyeong Mun 
3708dee66f3eSGwan-gyeong Mun 	intel_read_dp_sdp(encoder, pipe_config, HDMI_PACKET_TYPE_GAMUT_METADATA);
37092c3928e4SGwan-gyeong Mun 	intel_read_dp_sdp(encoder, pipe_config, DP_SDP_VSC);
3710379bc100SJani Nikula }
3711379bc100SJani Nikula 
3712351221ffSVille Syrjälä void intel_ddi_get_clock(struct intel_encoder *encoder,
3713351221ffSVille Syrjälä 			 struct intel_crtc_state *crtc_state,
3714351221ffSVille Syrjälä 			 struct intel_shared_dpll *pll)
3715351221ffSVille Syrjälä {
3716351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3717351221ffSVille Syrjälä 	enum icl_port_dpll_id port_dpll_id = ICL_PORT_DPLL_DEFAULT;
3718351221ffSVille Syrjälä 	struct icl_port_dpll *port_dpll = &crtc_state->icl_port_dplls[port_dpll_id];
3719351221ffSVille Syrjälä 	bool pll_active;
3720351221ffSVille Syrjälä 
3721086877a1SVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
3722086877a1SVille Syrjälä 		return;
3723086877a1SVille Syrjälä 
3724351221ffSVille Syrjälä 	port_dpll->pll = pll;
3725351221ffSVille Syrjälä 	pll_active = intel_dpll_get_hw_state(i915, pll, &port_dpll->hw_state);
3726351221ffSVille Syrjälä 	drm_WARN_ON(&i915->drm, !pll_active);
3727351221ffSVille Syrjälä 
3728351221ffSVille Syrjälä 	icl_set_active_port_dpll(crtc_state, port_dpll_id);
3729351221ffSVille Syrjälä 
3730351221ffSVille Syrjälä 	crtc_state->port_clock = intel_dpll_get_freq(i915, crtc_state->shared_dpll,
3731351221ffSVille Syrjälä 						     &crtc_state->dpll_hw_state);
3732351221ffSVille Syrjälä }
3733351221ffSVille Syrjälä 
3734351221ffSVille Syrjälä static void adls_ddi_get_config(struct intel_encoder *encoder,
3735351221ffSVille Syrjälä 				struct intel_crtc_state *crtc_state)
3736351221ffSVille Syrjälä {
3737351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, adls_ddi_get_pll(encoder));
3738351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3739351221ffSVille Syrjälä }
3740351221ffSVille Syrjälä 
3741351221ffSVille Syrjälä static void rkl_ddi_get_config(struct intel_encoder *encoder,
3742351221ffSVille Syrjälä 			       struct intel_crtc_state *crtc_state)
3743351221ffSVille Syrjälä {
3744351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, rkl_ddi_get_pll(encoder));
3745351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3746351221ffSVille Syrjälä }
3747351221ffSVille Syrjälä 
3748351221ffSVille Syrjälä static void dg1_ddi_get_config(struct intel_encoder *encoder,
3749351221ffSVille Syrjälä 			       struct intel_crtc_state *crtc_state)
3750351221ffSVille Syrjälä {
3751351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, dg1_ddi_get_pll(encoder));
3752351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3753351221ffSVille Syrjälä }
3754351221ffSVille Syrjälä 
3755351221ffSVille Syrjälä static void icl_ddi_combo_get_config(struct intel_encoder *encoder,
3756351221ffSVille Syrjälä 				     struct intel_crtc_state *crtc_state)
3757351221ffSVille Syrjälä {
3758351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, icl_ddi_combo_get_pll(encoder));
3759351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3760351221ffSVille Syrjälä }
3761351221ffSVille Syrjälä 
3762086877a1SVille Syrjälä static void icl_ddi_tc_get_clock(struct intel_encoder *encoder,
3763086877a1SVille Syrjälä 				 struct intel_crtc_state *crtc_state,
3764086877a1SVille Syrjälä 				 struct intel_shared_dpll *pll)
3765351221ffSVille Syrjälä {
3766351221ffSVille Syrjälä 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3767351221ffSVille Syrjälä 	enum icl_port_dpll_id port_dpll_id;
3768351221ffSVille Syrjälä 	struct icl_port_dpll *port_dpll;
3769351221ffSVille Syrjälä 	bool pll_active;
3770351221ffSVille Syrjälä 
3771086877a1SVille Syrjälä 	if (drm_WARN_ON(&i915->drm, !pll))
3772086877a1SVille Syrjälä 		return;
3773351221ffSVille Syrjälä 
3774351221ffSVille Syrjälä 	if (intel_get_shared_dpll_id(i915, pll) == DPLL_ID_ICL_TBTPLL)
3775351221ffSVille Syrjälä 		port_dpll_id = ICL_PORT_DPLL_DEFAULT;
3776351221ffSVille Syrjälä 	else
3777351221ffSVille Syrjälä 		port_dpll_id = ICL_PORT_DPLL_MG_PHY;
3778351221ffSVille Syrjälä 
3779351221ffSVille Syrjälä 	port_dpll = &crtc_state->icl_port_dplls[port_dpll_id];
3780351221ffSVille Syrjälä 
3781351221ffSVille Syrjälä 	port_dpll->pll = pll;
3782351221ffSVille Syrjälä 	pll_active = intel_dpll_get_hw_state(i915, pll, &port_dpll->hw_state);
3783351221ffSVille Syrjälä 	drm_WARN_ON(&i915->drm, !pll_active);
3784351221ffSVille Syrjälä 
3785351221ffSVille Syrjälä 	icl_set_active_port_dpll(crtc_state, port_dpll_id);
3786351221ffSVille Syrjälä 
3787351221ffSVille Syrjälä 	if (intel_get_shared_dpll_id(i915, crtc_state->shared_dpll) == DPLL_ID_ICL_TBTPLL)
3788351221ffSVille Syrjälä 		crtc_state->port_clock = icl_calc_tbt_pll_link(i915, encoder->port);
3789351221ffSVille Syrjälä 	else
3790351221ffSVille Syrjälä 		crtc_state->port_clock = intel_dpll_get_freq(i915, crtc_state->shared_dpll,
3791351221ffSVille Syrjälä 							     &crtc_state->dpll_hw_state);
3792086877a1SVille Syrjälä }
3793351221ffSVille Syrjälä 
3794086877a1SVille Syrjälä static void icl_ddi_tc_get_config(struct intel_encoder *encoder,
3795086877a1SVille Syrjälä 				  struct intel_crtc_state *crtc_state)
3796086877a1SVille Syrjälä {
3797086877a1SVille Syrjälä 	icl_ddi_tc_get_clock(encoder, crtc_state, icl_ddi_tc_get_pll(encoder));
3798351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3799351221ffSVille Syrjälä }
3800351221ffSVille Syrjälä 
3801351221ffSVille Syrjälä static void cnl_ddi_get_config(struct intel_encoder *encoder,
3802351221ffSVille Syrjälä 			       struct intel_crtc_state *crtc_state)
3803351221ffSVille Syrjälä {
3804351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, cnl_ddi_get_pll(encoder));
3805351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3806351221ffSVille Syrjälä }
3807351221ffSVille Syrjälä 
3808351221ffSVille Syrjälä static void bxt_ddi_get_config(struct intel_encoder *encoder,
3809351221ffSVille Syrjälä 			       struct intel_crtc_state *crtc_state)
3810351221ffSVille Syrjälä {
3811351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, bxt_ddi_get_pll(encoder));
3812351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3813351221ffSVille Syrjälä }
3814351221ffSVille Syrjälä 
3815351221ffSVille Syrjälä static void skl_ddi_get_config(struct intel_encoder *encoder,
3816351221ffSVille Syrjälä 			       struct intel_crtc_state *crtc_state)
3817351221ffSVille Syrjälä {
3818351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, skl_ddi_get_pll(encoder));
3819351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3820351221ffSVille Syrjälä }
3821351221ffSVille Syrjälä 
3822351221ffSVille Syrjälä void hsw_ddi_get_config(struct intel_encoder *encoder,
3823351221ffSVille Syrjälä 			struct intel_crtc_state *crtc_state)
3824351221ffSVille Syrjälä {
3825351221ffSVille Syrjälä 	intel_ddi_get_clock(encoder, crtc_state, hsw_ddi_get_pll(encoder));
3826351221ffSVille Syrjälä 	intel_ddi_get_config(encoder, crtc_state);
3827351221ffSVille Syrjälä }
3828351221ffSVille Syrjälä 
3829f9e76a6eSImre Deak static void intel_ddi_sync_state(struct intel_encoder *encoder,
3830f9e76a6eSImre Deak 				 const struct intel_crtc_state *crtc_state)
3831f9e76a6eSImre Deak {
3832f9e76a6eSImre Deak 	if (intel_crtc_has_dp_encoder(crtc_state))
3833f9e76a6eSImre Deak 		intel_dp_sync_state(encoder, crtc_state);
3834f9e76a6eSImre Deak }
3835f9e76a6eSImre Deak 
3836b671d6efSImre Deak static bool intel_ddi_initial_fastset_check(struct intel_encoder *encoder,
3837b671d6efSImre Deak 					    struct intel_crtc_state *crtc_state)
3838b671d6efSImre Deak {
3839b671d6efSImre Deak 	if (intel_crtc_has_dp_encoder(crtc_state))
3840b671d6efSImre Deak 		return intel_dp_initial_fastset_check(encoder, crtc_state);
3841b671d6efSImre Deak 
3842b671d6efSImre Deak 	return true;
3843b671d6efSImre Deak }
3844b671d6efSImre Deak 
3845379bc100SJani Nikula static enum intel_output_type
3846379bc100SJani Nikula intel_ddi_compute_output_type(struct intel_encoder *encoder,
3847379bc100SJani Nikula 			      struct intel_crtc_state *crtc_state,
3848379bc100SJani Nikula 			      struct drm_connector_state *conn_state)
3849379bc100SJani Nikula {
3850379bc100SJani Nikula 	switch (conn_state->connector->connector_type) {
3851379bc100SJani Nikula 	case DRM_MODE_CONNECTOR_HDMIA:
3852379bc100SJani Nikula 		return INTEL_OUTPUT_HDMI;
3853379bc100SJani Nikula 	case DRM_MODE_CONNECTOR_eDP:
3854379bc100SJani Nikula 		return INTEL_OUTPUT_EDP;
3855379bc100SJani Nikula 	case DRM_MODE_CONNECTOR_DisplayPort:
3856379bc100SJani Nikula 		return INTEL_OUTPUT_DP;
3857379bc100SJani Nikula 	default:
3858379bc100SJani Nikula 		MISSING_CASE(conn_state->connector->connector_type);
3859379bc100SJani Nikula 		return INTEL_OUTPUT_UNUSED;
3860379bc100SJani Nikula 	}
3861379bc100SJani Nikula }
3862379bc100SJani Nikula 
3863379bc100SJani Nikula static int intel_ddi_compute_config(struct intel_encoder *encoder,
3864379bc100SJani Nikula 				    struct intel_crtc_state *pipe_config,
3865379bc100SJani Nikula 				    struct drm_connector_state *conn_state)
3866379bc100SJani Nikula {
38672225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
3868379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3869379bc100SJani Nikula 	enum port port = encoder->port;
3870379bc100SJani Nikula 	int ret;
3871379bc100SJani Nikula 
387210cf8e75SVille Syrjälä 	if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A)
3873379bc100SJani Nikula 		pipe_config->cpu_transcoder = TRANSCODER_EDP;
3874379bc100SJani Nikula 
3875bdacf087SAnshuman Gupta 	if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) {
3876379bc100SJani Nikula 		ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
3877bdacf087SAnshuman Gupta 	} else {
3878379bc100SJani Nikula 		ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
3879bdacf087SAnshuman Gupta 	}
3880bdacf087SAnshuman Gupta 
3881379bc100SJani Nikula 	if (ret)
3882379bc100SJani Nikula 		return ret;
3883379bc100SJani Nikula 
3884379bc100SJani Nikula 	if (IS_HASWELL(dev_priv) && crtc->pipe == PIPE_A &&
3885379bc100SJani Nikula 	    pipe_config->cpu_transcoder == TRANSCODER_EDP)
3886379bc100SJani Nikula 		pipe_config->pch_pfit.force_thru =
3887379bc100SJani Nikula 			pipe_config->pch_pfit.enabled ||
3888379bc100SJani Nikula 			pipe_config->crc_enabled;
3889379bc100SJani Nikula 
38902446e1d6SMatt Roper 	if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
3891379bc100SJani Nikula 		pipe_config->lane_lat_optim_mask =
3892379bc100SJani Nikula 			bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count);
3893379bc100SJani Nikula 
3894379bc100SJani Nikula 	intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
3895379bc100SJani Nikula 
3896379bc100SJani Nikula 	return 0;
3897379bc100SJani Nikula }
3898379bc100SJani Nikula 
3899b50a1aa6SManasi Navare static bool mode_equal(const struct drm_display_mode *mode1,
3900b50a1aa6SManasi Navare 		       const struct drm_display_mode *mode2)
3901b50a1aa6SManasi Navare {
3902b50a1aa6SManasi Navare 	return drm_mode_match(mode1, mode2,
3903b50a1aa6SManasi Navare 			      DRM_MODE_MATCH_TIMINGS |
3904b50a1aa6SManasi Navare 			      DRM_MODE_MATCH_FLAGS |
3905b50a1aa6SManasi Navare 			      DRM_MODE_MATCH_3D_FLAGS) &&
3906b50a1aa6SManasi Navare 		mode1->clock == mode2->clock; /* we want an exact match */
3907b50a1aa6SManasi Navare }
3908b50a1aa6SManasi Navare 
3909b50a1aa6SManasi Navare static bool m_n_equal(const struct intel_link_m_n *m_n_1,
3910b50a1aa6SManasi Navare 		      const struct intel_link_m_n *m_n_2)
3911b50a1aa6SManasi Navare {
3912b50a1aa6SManasi Navare 	return m_n_1->tu == m_n_2->tu &&
3913b50a1aa6SManasi Navare 		m_n_1->gmch_m == m_n_2->gmch_m &&
3914b50a1aa6SManasi Navare 		m_n_1->gmch_n == m_n_2->gmch_n &&
3915b50a1aa6SManasi Navare 		m_n_1->link_m == m_n_2->link_m &&
3916b50a1aa6SManasi Navare 		m_n_1->link_n == m_n_2->link_n;
3917b50a1aa6SManasi Navare }
3918b50a1aa6SManasi Navare 
3919b50a1aa6SManasi Navare static bool crtcs_port_sync_compatible(const struct intel_crtc_state *crtc_state1,
3920b50a1aa6SManasi Navare 				       const struct intel_crtc_state *crtc_state2)
3921b50a1aa6SManasi Navare {
3922b50a1aa6SManasi Navare 	return crtc_state1->hw.active && crtc_state2->hw.active &&
3923b50a1aa6SManasi Navare 		crtc_state1->output_types == crtc_state2->output_types &&
3924b50a1aa6SManasi Navare 		crtc_state1->output_format == crtc_state2->output_format &&
3925b50a1aa6SManasi Navare 		crtc_state1->lane_count == crtc_state2->lane_count &&
3926b50a1aa6SManasi Navare 		crtc_state1->port_clock == crtc_state2->port_clock &&
3927b50a1aa6SManasi Navare 		mode_equal(&crtc_state1->hw.adjusted_mode,
3928b50a1aa6SManasi Navare 			   &crtc_state2->hw.adjusted_mode) &&
3929b50a1aa6SManasi Navare 		m_n_equal(&crtc_state1->dp_m_n, &crtc_state2->dp_m_n);
3930b50a1aa6SManasi Navare }
3931b50a1aa6SManasi Navare 
3932b50a1aa6SManasi Navare static u8
3933b50a1aa6SManasi Navare intel_ddi_port_sync_transcoders(const struct intel_crtc_state *ref_crtc_state,
3934b50a1aa6SManasi Navare 				int tile_group_id)
3935b50a1aa6SManasi Navare {
3936b50a1aa6SManasi Navare 	struct drm_connector *connector;
3937b50a1aa6SManasi Navare 	const struct drm_connector_state *conn_state;
3938b50a1aa6SManasi Navare 	struct drm_i915_private *dev_priv = to_i915(ref_crtc_state->uapi.crtc->dev);
3939b50a1aa6SManasi Navare 	struct intel_atomic_state *state =
3940b50a1aa6SManasi Navare 		to_intel_atomic_state(ref_crtc_state->uapi.state);
3941b50a1aa6SManasi Navare 	u8 transcoders = 0;
3942b50a1aa6SManasi Navare 	int i;
3943b50a1aa6SManasi Navare 
3944dc5b8ed5SVille Syrjälä 	/*
3945dc5b8ed5SVille Syrjälä 	 * We don't enable port sync on BDW due to missing w/as and
3946dc5b8ed5SVille Syrjälä 	 * due to not having adjusted the modeset sequence appropriately.
3947dc5b8ed5SVille Syrjälä 	 */
3948005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) < 9)
3949b50a1aa6SManasi Navare 		return 0;
3950b50a1aa6SManasi Navare 
3951b50a1aa6SManasi Navare 	if (!intel_crtc_has_type(ref_crtc_state, INTEL_OUTPUT_DP))
3952b50a1aa6SManasi Navare 		return 0;
3953b50a1aa6SManasi Navare 
3954b50a1aa6SManasi Navare 	for_each_new_connector_in_state(&state->base, connector, conn_state, i) {
3955b50a1aa6SManasi Navare 		struct intel_crtc *crtc = to_intel_crtc(conn_state->crtc);
3956b50a1aa6SManasi Navare 		const struct intel_crtc_state *crtc_state;
3957b50a1aa6SManasi Navare 
3958b50a1aa6SManasi Navare 		if (!crtc)
3959b50a1aa6SManasi Navare 			continue;
3960b50a1aa6SManasi Navare 
3961b50a1aa6SManasi Navare 		if (!connector->has_tile ||
3962b50a1aa6SManasi Navare 		    connector->tile_group->id !=
3963b50a1aa6SManasi Navare 		    tile_group_id)
3964b50a1aa6SManasi Navare 			continue;
3965b50a1aa6SManasi Navare 		crtc_state = intel_atomic_get_new_crtc_state(state,
3966b50a1aa6SManasi Navare 							     crtc);
3967b50a1aa6SManasi Navare 		if (!crtcs_port_sync_compatible(ref_crtc_state,
3968b50a1aa6SManasi Navare 						crtc_state))
3969b50a1aa6SManasi Navare 			continue;
3970b50a1aa6SManasi Navare 		transcoders |= BIT(crtc_state->cpu_transcoder);
3971b50a1aa6SManasi Navare 	}
3972b50a1aa6SManasi Navare 
3973b50a1aa6SManasi Navare 	return transcoders;
3974b50a1aa6SManasi Navare }
3975b50a1aa6SManasi Navare 
3976b50a1aa6SManasi Navare static int intel_ddi_compute_config_late(struct intel_encoder *encoder,
3977b50a1aa6SManasi Navare 					 struct intel_crtc_state *crtc_state,
3978b50a1aa6SManasi Navare 					 struct drm_connector_state *conn_state)
3979b50a1aa6SManasi Navare {
398047bdb1caSJani Nikula 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3981b50a1aa6SManasi Navare 	struct drm_connector *connector = conn_state->connector;
3982b50a1aa6SManasi Navare 	u8 port_sync_transcoders = 0;
3983b50a1aa6SManasi Navare 
398447bdb1caSJani Nikula 	drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] [CRTC:%d:%s]",
3985b50a1aa6SManasi Navare 		    encoder->base.base.id, encoder->base.name,
3986b50a1aa6SManasi Navare 		    crtc_state->uapi.crtc->base.id, crtc_state->uapi.crtc->name);
3987b50a1aa6SManasi Navare 
3988b50a1aa6SManasi Navare 	if (connector->has_tile)
3989b50a1aa6SManasi Navare 		port_sync_transcoders = intel_ddi_port_sync_transcoders(crtc_state,
3990b50a1aa6SManasi Navare 									connector->tile_group->id);
3991b50a1aa6SManasi Navare 
3992b50a1aa6SManasi Navare 	/*
3993b50a1aa6SManasi Navare 	 * EDP Transcoders cannot be ensalved
3994b50a1aa6SManasi Navare 	 * make them a master always when present
3995b50a1aa6SManasi Navare 	 */
3996b50a1aa6SManasi Navare 	if (port_sync_transcoders & BIT(TRANSCODER_EDP))
3997b50a1aa6SManasi Navare 		crtc_state->master_transcoder = TRANSCODER_EDP;
3998b50a1aa6SManasi Navare 	else
3999b50a1aa6SManasi Navare 		crtc_state->master_transcoder = ffs(port_sync_transcoders) - 1;
4000b50a1aa6SManasi Navare 
4001b50a1aa6SManasi Navare 	if (crtc_state->master_transcoder == crtc_state->cpu_transcoder) {
4002b50a1aa6SManasi Navare 		crtc_state->master_transcoder = INVALID_TRANSCODER;
4003b50a1aa6SManasi Navare 		crtc_state->sync_mode_slaves_mask =
4004b50a1aa6SManasi Navare 			port_sync_transcoders & ~BIT(crtc_state->cpu_transcoder);
4005b50a1aa6SManasi Navare 	}
4006b50a1aa6SManasi Navare 
4007b50a1aa6SManasi Navare 	return 0;
4008b50a1aa6SManasi Navare }
4009b50a1aa6SManasi Navare 
4010379bc100SJani Nikula static void intel_ddi_encoder_destroy(struct drm_encoder *encoder)
4011379bc100SJani Nikula {
4012b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder));
4013379bc100SJani Nikula 
4014379bc100SJani Nikula 	intel_dp_encoder_flush_work(encoder);
4015379bc100SJani Nikula 
4016379bc100SJani Nikula 	drm_encoder_cleanup(encoder);
4017a6c6eac9SAnshuman Gupta 	if (dig_port)
4018a6c6eac9SAnshuman Gupta 		kfree(dig_port->hdcp_port_data.streams);
4019379bc100SJani Nikula 	kfree(dig_port);
4020379bc100SJani Nikula }
4021379bc100SJani Nikula 
4022764f6729SVille Syrjälä static void intel_ddi_encoder_reset(struct drm_encoder *encoder)
4023764f6729SVille Syrjälä {
4024764f6729SVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(encoder));
4025764f6729SVille Syrjälä 
4026764f6729SVille Syrjälä 	intel_dp->reset_link_params = true;
4027764f6729SVille Syrjälä 
4028764f6729SVille Syrjälä 	intel_pps_encoder_reset(intel_dp);
4029764f6729SVille Syrjälä }
4030764f6729SVille Syrjälä 
4031379bc100SJani Nikula static const struct drm_encoder_funcs intel_ddi_funcs = {
4032764f6729SVille Syrjälä 	.reset = intel_ddi_encoder_reset,
4033379bc100SJani Nikula 	.destroy = intel_ddi_encoder_destroy,
4034379bc100SJani Nikula };
4035379bc100SJani Nikula 
4036379bc100SJani Nikula static struct intel_connector *
40377801f3b7SLucas De Marchi intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
4038379bc100SJani Nikula {
40397801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
4040379bc100SJani Nikula 	struct intel_connector *connector;
40417801f3b7SLucas De Marchi 	enum port port = dig_port->base.port;
4042379bc100SJani Nikula 
4043379bc100SJani Nikula 	connector = intel_connector_alloc();
4044379bc100SJani Nikula 	if (!connector)
4045379bc100SJani Nikula 		return NULL;
4046379bc100SJani Nikula 
40477801f3b7SLucas De Marchi 	dig_port->dp.output_reg = DDI_BUF_CTL(port);
40487801f3b7SLucas De Marchi 	dig_port->dp.prepare_link_retrain = intel_ddi_prepare_link_retrain;
40497801f3b7SLucas De Marchi 	dig_port->dp.set_link_train = intel_ddi_set_link_train;
40507801f3b7SLucas De Marchi 	dig_port->dp.set_idle_link_train = intel_ddi_set_idle_link_train;
4051eee3f911SVille Syrjälä 
4052005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12)
40537801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = tgl_set_signal_levels;
4054005e9537SMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 11)
40557801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = icl_set_signal_levels;
4056fb83f72cSVille Syrjälä 	else if (IS_CANNONLAKE(dev_priv))
40577801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = cnl_set_signal_levels;
40582446e1d6SMatt Roper 	else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
40597801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = bxt_set_signal_levels;
4060fb83f72cSVille Syrjälä 	else
40617801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = hsw_set_signal_levels;
4062fb83f72cSVille Syrjälä 
40637801f3b7SLucas De Marchi 	dig_port->dp.voltage_max = intel_ddi_dp_voltage_max;
40647801f3b7SLucas De Marchi 	dig_port->dp.preemph_max = intel_ddi_dp_preemph_max;
406553de0a20SVille Syrjälä 
40667801f3b7SLucas De Marchi 	if (!intel_dp_init_connector(dig_port, connector)) {
4067379bc100SJani Nikula 		kfree(connector);
4068379bc100SJani Nikula 		return NULL;
4069379bc100SJani Nikula 	}
4070379bc100SJani Nikula 
4071379bc100SJani Nikula 	return connector;
4072379bc100SJani Nikula }
4073379bc100SJani Nikula 
4074379bc100SJani Nikula static int modeset_pipe(struct drm_crtc *crtc,
4075379bc100SJani Nikula 			struct drm_modeset_acquire_ctx *ctx)
4076379bc100SJani Nikula {
4077379bc100SJani Nikula 	struct drm_atomic_state *state;
4078379bc100SJani Nikula 	struct drm_crtc_state *crtc_state;
4079379bc100SJani Nikula 	int ret;
4080379bc100SJani Nikula 
4081379bc100SJani Nikula 	state = drm_atomic_state_alloc(crtc->dev);
4082379bc100SJani Nikula 	if (!state)
4083379bc100SJani Nikula 		return -ENOMEM;
4084379bc100SJani Nikula 
4085379bc100SJani Nikula 	state->acquire_ctx = ctx;
4086379bc100SJani Nikula 
4087379bc100SJani Nikula 	crtc_state = drm_atomic_get_crtc_state(state, crtc);
4088379bc100SJani Nikula 	if (IS_ERR(crtc_state)) {
4089379bc100SJani Nikula 		ret = PTR_ERR(crtc_state);
4090379bc100SJani Nikula 		goto out;
4091379bc100SJani Nikula 	}
4092379bc100SJani Nikula 
4093379bc100SJani Nikula 	crtc_state->connectors_changed = true;
4094379bc100SJani Nikula 
4095379bc100SJani Nikula 	ret = drm_atomic_commit(state);
4096379bc100SJani Nikula out:
4097379bc100SJani Nikula 	drm_atomic_state_put(state);
4098379bc100SJani Nikula 
4099379bc100SJani Nikula 	return ret;
4100379bc100SJani Nikula }
4101379bc100SJani Nikula 
4102379bc100SJani Nikula static int intel_hdmi_reset_link(struct intel_encoder *encoder,
4103379bc100SJani Nikula 				 struct drm_modeset_acquire_ctx *ctx)
4104379bc100SJani Nikula {
4105379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4106b7d02c3aSVille Syrjälä 	struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder);
4107379bc100SJani Nikula 	struct intel_connector *connector = hdmi->attached_connector;
4108379bc100SJani Nikula 	struct i2c_adapter *adapter =
4109379bc100SJani Nikula 		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
4110379bc100SJani Nikula 	struct drm_connector_state *conn_state;
4111379bc100SJani Nikula 	struct intel_crtc_state *crtc_state;
4112379bc100SJani Nikula 	struct intel_crtc *crtc;
4113379bc100SJani Nikula 	u8 config;
4114379bc100SJani Nikula 	int ret;
4115379bc100SJani Nikula 
4116379bc100SJani Nikula 	if (!connector || connector->base.status != connector_status_connected)
4117379bc100SJani Nikula 		return 0;
4118379bc100SJani Nikula 
4119379bc100SJani Nikula 	ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex,
4120379bc100SJani Nikula 			       ctx);
4121379bc100SJani Nikula 	if (ret)
4122379bc100SJani Nikula 		return ret;
4123379bc100SJani Nikula 
4124379bc100SJani Nikula 	conn_state = connector->base.state;
4125379bc100SJani Nikula 
4126379bc100SJani Nikula 	crtc = to_intel_crtc(conn_state->crtc);
4127379bc100SJani Nikula 	if (!crtc)
4128379bc100SJani Nikula 		return 0;
4129379bc100SJani Nikula 
4130379bc100SJani Nikula 	ret = drm_modeset_lock(&crtc->base.mutex, ctx);
4131379bc100SJani Nikula 	if (ret)
4132379bc100SJani Nikula 		return ret;
4133379bc100SJani Nikula 
4134379bc100SJani Nikula 	crtc_state = to_intel_crtc_state(crtc->base.state);
4135379bc100SJani Nikula 
41361de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm,
41371de143ccSPankaj Bharadiya 		    !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI));
4138379bc100SJani Nikula 
41391326a92cSMaarten Lankhorst 	if (!crtc_state->hw.active)
4140379bc100SJani Nikula 		return 0;
4141379bc100SJani Nikula 
4142379bc100SJani Nikula 	if (!crtc_state->hdmi_high_tmds_clock_ratio &&
4143379bc100SJani Nikula 	    !crtc_state->hdmi_scrambling)
4144379bc100SJani Nikula 		return 0;
4145379bc100SJani Nikula 
4146379bc100SJani Nikula 	if (conn_state->commit &&
4147379bc100SJani Nikula 	    !try_wait_for_completion(&conn_state->commit->hw_done))
4148379bc100SJani Nikula 		return 0;
4149379bc100SJani Nikula 
4150379bc100SJani Nikula 	ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config);
4151379bc100SJani Nikula 	if (ret < 0) {
415247bdb1caSJani Nikula 		drm_err(&dev_priv->drm, "Failed to read TMDS config: %d\n",
415347bdb1caSJani Nikula 			ret);
4154379bc100SJani Nikula 		return 0;
4155379bc100SJani Nikula 	}
4156379bc100SJani Nikula 
4157379bc100SJani Nikula 	if (!!(config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) ==
4158379bc100SJani Nikula 	    crtc_state->hdmi_high_tmds_clock_ratio &&
4159379bc100SJani Nikula 	    !!(config & SCDC_SCRAMBLING_ENABLE) ==
4160379bc100SJani Nikula 	    crtc_state->hdmi_scrambling)
4161379bc100SJani Nikula 		return 0;
4162379bc100SJani Nikula 
4163379bc100SJani Nikula 	/*
4164379bc100SJani Nikula 	 * HDMI 2.0 says that one should not send scrambled data
4165379bc100SJani Nikula 	 * prior to configuring the sink scrambling, and that
4166379bc100SJani Nikula 	 * TMDS clock/data transmission should be suspended when
4167379bc100SJani Nikula 	 * changing the TMDS clock rate in the sink. So let's
4168379bc100SJani Nikula 	 * just do a full modeset here, even though some sinks
4169379bc100SJani Nikula 	 * would be perfectly happy if were to just reconfigure
4170379bc100SJani Nikula 	 * the SCDC settings on the fly.
4171379bc100SJani Nikula 	 */
4172379bc100SJani Nikula 	return modeset_pipe(&crtc->base, ctx);
4173379bc100SJani Nikula }
4174379bc100SJani Nikula 
41753944709dSImre Deak static enum intel_hotplug_state
41763944709dSImre Deak intel_ddi_hotplug(struct intel_encoder *encoder,
41778c8919c7SImre Deak 		  struct intel_connector *connector)
4178379bc100SJani Nikula {
4179b4df5405SImre Deak 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
4180b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
4181699390f7SVille Syrjälä 	struct intel_dp *intel_dp = &dig_port->dp;
4182b4df5405SImre Deak 	enum phy phy = intel_port_to_phy(i915, encoder->port);
4183b4df5405SImre Deak 	bool is_tc = intel_phy_is_tc(i915, phy);
4184379bc100SJani Nikula 	struct drm_modeset_acquire_ctx ctx;
41853944709dSImre Deak 	enum intel_hotplug_state state;
4186379bc100SJani Nikula 	int ret;
4187379bc100SJani Nikula 
4188699390f7SVille Syrjälä 	if (intel_dp->compliance.test_active &&
4189699390f7SVille Syrjälä 	    intel_dp->compliance.test_type == DP_TEST_LINK_PHY_TEST_PATTERN) {
4190699390f7SVille Syrjälä 		intel_dp_phy_test(encoder);
4191699390f7SVille Syrjälä 		/* just do the PHY test and nothing else */
4192699390f7SVille Syrjälä 		return INTEL_HOTPLUG_UNCHANGED;
4193699390f7SVille Syrjälä 	}
4194699390f7SVille Syrjälä 
41958c8919c7SImre Deak 	state = intel_encoder_hotplug(encoder, connector);
4196379bc100SJani Nikula 
4197379bc100SJani Nikula 	drm_modeset_acquire_init(&ctx, 0);
4198379bc100SJani Nikula 
4199379bc100SJani Nikula 	for (;;) {
4200379bc100SJani Nikula 		if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA)
4201379bc100SJani Nikula 			ret = intel_hdmi_reset_link(encoder, &ctx);
4202379bc100SJani Nikula 		else
4203379bc100SJani Nikula 			ret = intel_dp_retrain_link(encoder, &ctx);
4204379bc100SJani Nikula 
4205379bc100SJani Nikula 		if (ret == -EDEADLK) {
4206379bc100SJani Nikula 			drm_modeset_backoff(&ctx);
4207379bc100SJani Nikula 			continue;
4208379bc100SJani Nikula 		}
4209379bc100SJani Nikula 
4210379bc100SJani Nikula 		break;
4211379bc100SJani Nikula 	}
4212379bc100SJani Nikula 
4213379bc100SJani Nikula 	drm_modeset_drop_locks(&ctx);
4214379bc100SJani Nikula 	drm_modeset_acquire_fini(&ctx);
42153a47ae20SPankaj Bharadiya 	drm_WARN(encoder->base.dev, ret,
42163a47ae20SPankaj Bharadiya 		 "Acquiring modeset locks failed with %i\n", ret);
4217379bc100SJani Nikula 
4218bb80c925SJosé Roberto de Souza 	/*
4219bb80c925SJosé Roberto de Souza 	 * Unpowered type-c dongles can take some time to boot and be
4220bb80c925SJosé Roberto de Souza 	 * responsible, so here giving some time to those dongles to power up
4221bb80c925SJosé Roberto de Souza 	 * and then retrying the probe.
4222bb80c925SJosé Roberto de Souza 	 *
4223bb80c925SJosé Roberto de Souza 	 * On many platforms the HDMI live state signal is known to be
4224bb80c925SJosé Roberto de Souza 	 * unreliable, so we can't use it to detect if a sink is connected or
4225bb80c925SJosé Roberto de Souza 	 * not. Instead we detect if it's connected based on whether we can
4226bb80c925SJosé Roberto de Souza 	 * read the EDID or not. That in turn has a problem during disconnect,
4227bb80c925SJosé Roberto de Souza 	 * since the HPD interrupt may be raised before the DDC lines get
4228bb80c925SJosé Roberto de Souza 	 * disconnected (due to how the required length of DDC vs. HPD
4229bb80c925SJosé Roberto de Souza 	 * connector pins are specified) and so we'll still be able to get a
4230bb80c925SJosé Roberto de Souza 	 * valid EDID. To solve this schedule another detection cycle if this
4231bb80c925SJosé Roberto de Souza 	 * time around we didn't detect any change in the sink's connection
4232bb80c925SJosé Roberto de Souza 	 * status.
4233b4df5405SImre Deak 	 *
4234b4df5405SImre Deak 	 * Type-c connectors which get their HPD signal deasserted then
4235b4df5405SImre Deak 	 * reasserted, without unplugging/replugging the sink from the
4236b4df5405SImre Deak 	 * connector, introduce a delay until the AUX channel communication
4237b4df5405SImre Deak 	 * becomes functional. Retry the detection for 5 seconds on type-c
4238b4df5405SImre Deak 	 * connectors to account for this delay.
4239bb80c925SJosé Roberto de Souza 	 */
4240b4df5405SImre Deak 	if (state == INTEL_HOTPLUG_UNCHANGED &&
4241b4df5405SImre Deak 	    connector->hotplug_retries < (is_tc ? 5 : 1) &&
4242bb80c925SJosé Roberto de Souza 	    !dig_port->dp.is_mst)
4243bb80c925SJosé Roberto de Souza 		state = INTEL_HOTPLUG_RETRY;
4244bb80c925SJosé Roberto de Souza 
42453944709dSImre Deak 	return state;
4246379bc100SJani Nikula }
4247379bc100SJani Nikula 
4248edc0e09cSVille Syrjälä static bool lpt_digital_port_connected(struct intel_encoder *encoder)
4249edc0e09cSVille Syrjälä {
4250edc0e09cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4251c7e8a3d6SVille Syrjälä 	u32 bit = dev_priv->hotplug.pch_hpd[encoder->hpd_pin];
4252edc0e09cSVille Syrjälä 
4253edc0e09cSVille Syrjälä 	return intel_de_read(dev_priv, SDEISR) & bit;
4254edc0e09cSVille Syrjälä }
4255edc0e09cSVille Syrjälä 
4256edc0e09cSVille Syrjälä static bool hsw_digital_port_connected(struct intel_encoder *encoder)
4257edc0e09cSVille Syrjälä {
4258edc0e09cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4259c7e8a3d6SVille Syrjälä 	u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin];
4260edc0e09cSVille Syrjälä 
4261c7e8a3d6SVille Syrjälä 	return intel_de_read(dev_priv, DEISR) & bit;
4262edc0e09cSVille Syrjälä }
4263edc0e09cSVille Syrjälä 
4264edc0e09cSVille Syrjälä static bool bdw_digital_port_connected(struct intel_encoder *encoder)
4265edc0e09cSVille Syrjälä {
4266edc0e09cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4267c7e8a3d6SVille Syrjälä 	u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin];
4268edc0e09cSVille Syrjälä 
4269edc0e09cSVille Syrjälä 	return intel_de_read(dev_priv, GEN8_DE_PORT_ISR) & bit;
4270edc0e09cSVille Syrjälä }
4271edc0e09cSVille Syrjälä 
4272379bc100SJani Nikula static struct intel_connector *
42737801f3b7SLucas De Marchi intel_ddi_init_hdmi_connector(struct intel_digital_port *dig_port)
4274379bc100SJani Nikula {
4275379bc100SJani Nikula 	struct intel_connector *connector;
42767801f3b7SLucas De Marchi 	enum port port = dig_port->base.port;
4277379bc100SJani Nikula 
4278379bc100SJani Nikula 	connector = intel_connector_alloc();
4279379bc100SJani Nikula 	if (!connector)
4280379bc100SJani Nikula 		return NULL;
4281379bc100SJani Nikula 
42827801f3b7SLucas De Marchi 	dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
42837801f3b7SLucas De Marchi 	intel_hdmi_init_connector(dig_port, connector);
4284379bc100SJani Nikula 
4285379bc100SJani Nikula 	return connector;
4286379bc100SJani Nikula }
4287379bc100SJani Nikula 
42887801f3b7SLucas De Marchi static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dig_port)
4289379bc100SJani Nikula {
42907801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
4291379bc100SJani Nikula 
42927801f3b7SLucas De Marchi 	if (dig_port->base.port != PORT_A)
4293379bc100SJani Nikula 		return false;
4294379bc100SJani Nikula 
42957801f3b7SLucas De Marchi 	if (dig_port->saved_port_bits & DDI_A_4_LANES)
4296379bc100SJani Nikula 		return false;
4297379bc100SJani Nikula 
4298379bc100SJani Nikula 	/* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only
4299379bc100SJani Nikula 	 *                     supported configuration
4300379bc100SJani Nikula 	 */
43012446e1d6SMatt Roper 	if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
4302379bc100SJani Nikula 		return true;
4303379bc100SJani Nikula 
4304379bc100SJani Nikula 	/* Cannonlake: Most of SKUs don't support DDI_E, and the only
4305379bc100SJani Nikula 	 *             one who does also have a full A/E split called
4306379bc100SJani Nikula 	 *             DDI_F what makes DDI_E useless. However for this
4307379bc100SJani Nikula 	 *             case let's trust VBT info.
4308379bc100SJani Nikula 	 */
4309379bc100SJani Nikula 	if (IS_CANNONLAKE(dev_priv) &&
4310379bc100SJani Nikula 	    !intel_bios_is_port_present(dev_priv, PORT_E))
4311379bc100SJani Nikula 		return true;
4312379bc100SJani Nikula 
4313379bc100SJani Nikula 	return false;
4314379bc100SJani Nikula }
4315379bc100SJani Nikula 
4316379bc100SJani Nikula static int
43177801f3b7SLucas De Marchi intel_ddi_max_lanes(struct intel_digital_port *dig_port)
4318379bc100SJani Nikula {
43197801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
43207801f3b7SLucas De Marchi 	enum port port = dig_port->base.port;
4321379bc100SJani Nikula 	int max_lanes = 4;
4322379bc100SJani Nikula 
4323005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11)
4324379bc100SJani Nikula 		return max_lanes;
4325379bc100SJani Nikula 
4326379bc100SJani Nikula 	if (port == PORT_A || port == PORT_E) {
4327f7960e7fSJani Nikula 		if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
4328379bc100SJani Nikula 			max_lanes = port == PORT_A ? 4 : 0;
4329379bc100SJani Nikula 		else
4330379bc100SJani Nikula 			/* Both A and E share 2 lanes */
4331379bc100SJani Nikula 			max_lanes = 2;
4332379bc100SJani Nikula 	}
4333379bc100SJani Nikula 
4334379bc100SJani Nikula 	/*
4335379bc100SJani Nikula 	 * Some BIOS might fail to set this bit on port A if eDP
4336379bc100SJani Nikula 	 * wasn't lit up at boot.  Force this bit set when needed
4337379bc100SJani Nikula 	 * so we use the proper lane count for our calculations.
4338379bc100SJani Nikula 	 */
43397801f3b7SLucas De Marchi 	if (intel_ddi_a_force_4_lanes(dig_port)) {
434047bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
434147bdb1caSJani Nikula 			    "Forcing DDI_A_4_LANES for port A\n");
43427801f3b7SLucas De Marchi 		dig_port->saved_port_bits |= DDI_A_4_LANES;
4343379bc100SJani Nikula 		max_lanes = 4;
4344379bc100SJani Nikula 	}
4345379bc100SJani Nikula 
4346379bc100SJani Nikula 	return max_lanes;
4347379bc100SJani Nikula }
4348379bc100SJani Nikula 
4349ddff9a60SMatt Roper static bool hti_uses_phy(struct drm_i915_private *i915, enum phy phy)
4350ddff9a60SMatt Roper {
4351ddff9a60SMatt Roper 	return i915->hti_state & HDPORT_ENABLED &&
4352ff7fb44dSJosé Roberto de Souza 	       i915->hti_state & HDPORT_DDI_USED(phy);
4353ddff9a60SMatt Roper }
4354ddff9a60SMatt Roper 
4355229f31e2SLucas De Marchi static enum hpd_pin dg1_hpd_pin(struct drm_i915_private *dev_priv,
4356229f31e2SLucas De Marchi 				enum port port)
4357229f31e2SLucas De Marchi {
43581d8ca002SVille Syrjälä 	if (port >= PORT_TC1)
43591d8ca002SVille Syrjälä 		return HPD_PORT_C + port - PORT_TC1;
4360229f31e2SLucas De Marchi 	else
4361229f31e2SLucas De Marchi 		return HPD_PORT_A + port - PORT_A;
4362229f31e2SLucas De Marchi }
4363229f31e2SLucas De Marchi 
4364da51e4baSVille Syrjälä static enum hpd_pin tgl_hpd_pin(struct drm_i915_private *dev_priv,
4365da51e4baSVille Syrjälä 				enum port port)
4366da51e4baSVille Syrjälä {
43671d8ca002SVille Syrjälä 	if (port >= PORT_TC1)
43681d8ca002SVille Syrjälä 		return HPD_PORT_TC1 + port - PORT_TC1;
4369da51e4baSVille Syrjälä 	else
4370da51e4baSVille Syrjälä 		return HPD_PORT_A + port - PORT_A;
4371da51e4baSVille Syrjälä }
4372da51e4baSVille Syrjälä 
4373da51e4baSVille Syrjälä static enum hpd_pin rkl_hpd_pin(struct drm_i915_private *dev_priv,
4374da51e4baSVille Syrjälä 				enum port port)
4375da51e4baSVille Syrjälä {
4376da51e4baSVille Syrjälä 	if (HAS_PCH_TGP(dev_priv))
4377da51e4baSVille Syrjälä 		return tgl_hpd_pin(dev_priv, port);
4378da51e4baSVille Syrjälä 
43791d8ca002SVille Syrjälä 	if (port >= PORT_TC1)
43801d8ca002SVille Syrjälä 		return HPD_PORT_C + port - PORT_TC1;
4381da51e4baSVille Syrjälä 	else
4382da51e4baSVille Syrjälä 		return HPD_PORT_A + port - PORT_A;
4383da51e4baSVille Syrjälä }
4384da51e4baSVille Syrjälä 
4385da51e4baSVille Syrjälä static enum hpd_pin icl_hpd_pin(struct drm_i915_private *dev_priv,
4386da51e4baSVille Syrjälä 				enum port port)
4387da51e4baSVille Syrjälä {
4388da51e4baSVille Syrjälä 	if (port >= PORT_C)
4389da51e4baSVille Syrjälä 		return HPD_PORT_TC1 + port - PORT_C;
4390da51e4baSVille Syrjälä 	else
4391da51e4baSVille Syrjälä 		return HPD_PORT_A + port - PORT_A;
4392da51e4baSVille Syrjälä }
4393da51e4baSVille Syrjälä 
4394da51e4baSVille Syrjälä static enum hpd_pin ehl_hpd_pin(struct drm_i915_private *dev_priv,
4395da51e4baSVille Syrjälä 				enum port port)
4396da51e4baSVille Syrjälä {
4397da51e4baSVille Syrjälä 	if (port == PORT_D)
4398da51e4baSVille Syrjälä 		return HPD_PORT_A;
4399da51e4baSVille Syrjälä 
4400da51e4baSVille Syrjälä 	if (HAS_PCH_MCC(dev_priv))
4401da51e4baSVille Syrjälä 		return icl_hpd_pin(dev_priv, port);
4402da51e4baSVille Syrjälä 
4403da51e4baSVille Syrjälä 	return HPD_PORT_A + port - PORT_A;
4404da51e4baSVille Syrjälä }
4405da51e4baSVille Syrjälä 
4406da51e4baSVille Syrjälä static enum hpd_pin cnl_hpd_pin(struct drm_i915_private *dev_priv,
4407da51e4baSVille Syrjälä 				enum port port)
4408da51e4baSVille Syrjälä {
4409da51e4baSVille Syrjälä 	if (port == PORT_F)
4410da51e4baSVille Syrjälä 		return HPD_PORT_E;
4411da51e4baSVille Syrjälä 
4412da51e4baSVille Syrjälä 	return HPD_PORT_A + port - PORT_A;
4413da51e4baSVille Syrjälä }
4414da51e4baSVille Syrjälä 
4415c8455098SLyude Paul static enum hpd_pin skl_hpd_pin(struct drm_i915_private *dev_priv, enum port port)
4416c8455098SLyude Paul {
4417c8455098SLyude Paul 	if (HAS_PCH_TGP(dev_priv))
4418c8455098SLyude Paul 		return icl_hpd_pin(dev_priv, port);
4419c8455098SLyude Paul 
4420c8455098SLyude Paul 	return HPD_PORT_A + port - PORT_A;
4421c8455098SLyude Paul }
4422c8455098SLyude Paul 
442336ecb0ecSVille Syrjälä static bool intel_ddi_is_tc(struct drm_i915_private *i915, enum port port)
442436ecb0ecSVille Syrjälä {
4425005e9537SMatt Roper 	if (DISPLAY_VER(i915) >= 12)
442636ecb0ecSVille Syrjälä 		return port >= PORT_TC1;
4427005e9537SMatt Roper 	else if (DISPLAY_VER(i915) >= 11)
442836ecb0ecSVille Syrjälä 		return port >= PORT_C;
442936ecb0ecSVille Syrjälä 	else
443036ecb0ecSVille Syrjälä 		return false;
443136ecb0ecSVille Syrjälä }
443236ecb0ecSVille Syrjälä 
443383566d13SVille Syrjälä #define port_tc_name(port) ((port) - PORT_TC1 + '1')
443483566d13SVille Syrjälä #define tc_port_name(tc_port) ((tc_port) - TC_PORT_1 + '1')
443583566d13SVille Syrjälä 
4436379bc100SJani Nikula void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
4437379bc100SJani Nikula {
44387801f3b7SLucas De Marchi 	struct intel_digital_port *dig_port;
443970dfbc29SLucas De Marchi 	struct intel_encoder *encoder;
444045c0673aSJani Nikula 	const struct intel_bios_encoder_data *devdata;
4441f542d671SKai-Heng Feng 	bool init_hdmi, init_dp;
4442d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
4443379bc100SJani Nikula 
4444ddff9a60SMatt Roper 	/*
4445ddff9a60SMatt Roper 	 * On platforms with HTI (aka HDPORT), if it's enabled at boot it may
4446ddff9a60SMatt Roper 	 * have taken over some of the PHYs and made them unavailable to the
4447ddff9a60SMatt Roper 	 * driver.  In that case we should skip initializing the corresponding
4448ddff9a60SMatt Roper 	 * outputs.
4449ddff9a60SMatt Roper 	 */
4450ddff9a60SMatt Roper 	if (hti_uses_phy(dev_priv, phy)) {
4451ddff9a60SMatt Roper 		drm_dbg_kms(&dev_priv->drm, "PORT %c / PHY %c reserved by HTI\n",
4452ddff9a60SMatt Roper 			    port_name(port), phy_name(phy));
4453ddff9a60SMatt Roper 		return;
4454ddff9a60SMatt Roper 	}
4455ddff9a60SMatt Roper 
445645c0673aSJani Nikula 	devdata = intel_bios_encoder_data_lookup(dev_priv, port);
445745c0673aSJani Nikula 	if (!devdata) {
445845c0673aSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
445945c0673aSJani Nikula 			    "VBT says port %c is not present\n",
446045c0673aSJani Nikula 			    port_name(port));
446145c0673aSJani Nikula 		return;
446245c0673aSJani Nikula 	}
446345c0673aSJani Nikula 
446445c0673aSJani Nikula 	init_hdmi = intel_bios_encoder_supports_dvi(devdata) ||
446545c0673aSJani Nikula 		intel_bios_encoder_supports_hdmi(devdata);
446645c0673aSJani Nikula 	init_dp = intel_bios_encoder_supports_dp(devdata);
4467379bc100SJani Nikula 
4468379bc100SJani Nikula 	if (intel_bios_is_lspcon_present(dev_priv, port)) {
4469379bc100SJani Nikula 		/*
4470379bc100SJani Nikula 		 * Lspcon device needs to be driven with DP connector
4471379bc100SJani Nikula 		 * with special detection sequence. So make sure DP
4472379bc100SJani Nikula 		 * is initialized before lspcon.
4473379bc100SJani Nikula 		 */
4474379bc100SJani Nikula 		init_dp = true;
4475379bc100SJani Nikula 		init_hdmi = false;
447647bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm, "VBT says port %c has lspcon\n",
447747bdb1caSJani Nikula 			    port_name(port));
4478379bc100SJani Nikula 	}
4479379bc100SJani Nikula 
4480379bc100SJani Nikula 	if (!init_dp && !init_hdmi) {
448147bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
448247bdb1caSJani Nikula 			    "VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
4483379bc100SJani Nikula 			    port_name(port));
4484379bc100SJani Nikula 		return;
4485379bc100SJani Nikula 	}
4486379bc100SJani Nikula 
44877801f3b7SLucas De Marchi 	dig_port = kzalloc(sizeof(*dig_port), GFP_KERNEL);
44887801f3b7SLucas De Marchi 	if (!dig_port)
4489379bc100SJani Nikula 		return;
4490379bc100SJani Nikula 
44917801f3b7SLucas De Marchi 	encoder = &dig_port->base;
4492c0a950d1SJani Nikula 	encoder->devdata = devdata;
4493379bc100SJani Nikula 
4494005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 12) {
44952d709a5aSVille Syrjälä 		enum tc_port tc_port = intel_port_to_tc(dev_priv, port);
44962d709a5aSVille Syrjälä 
449770dfbc29SLucas De Marchi 		drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
44982d709a5aSVille Syrjälä 				 DRM_MODE_ENCODER_TMDS,
44992d709a5aSVille Syrjälä 				 "DDI %s%c/PHY %s%c",
45002d709a5aSVille Syrjälä 				 port >= PORT_TC1 ? "TC" : "",
450183566d13SVille Syrjälä 				 port >= PORT_TC1 ? port_tc_name(port) : port_name(port),
45022d709a5aSVille Syrjälä 				 tc_port != TC_PORT_NONE ? "TC" : "",
450383566d13SVille Syrjälä 				 tc_port != TC_PORT_NONE ? tc_port_name(tc_port) : phy_name(phy));
4504005e9537SMatt Roper 	} else if (DISPLAY_VER(dev_priv) >= 11) {
45052d709a5aSVille Syrjälä 		enum tc_port tc_port = intel_port_to_tc(dev_priv, port);
45062d709a5aSVille Syrjälä 
45072d709a5aSVille Syrjälä 		drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
45082d709a5aSVille Syrjälä 				 DRM_MODE_ENCODER_TMDS,
45092d709a5aSVille Syrjälä 				 "DDI %c%s/PHY %s%c",
45102d709a5aSVille Syrjälä 				 port_name(port),
45112d709a5aSVille Syrjälä 				 port >= PORT_C ? " (TC)" : "",
45122d709a5aSVille Syrjälä 				 tc_port != TC_PORT_NONE ? "TC" : "",
451383566d13SVille Syrjälä 				 tc_port != TC_PORT_NONE ? tc_port_name(tc_port) : phy_name(phy));
45142d709a5aSVille Syrjälä 	} else {
45152d709a5aSVille Syrjälä 		drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
45162d709a5aSVille Syrjälä 				 DRM_MODE_ENCODER_TMDS,
45172d709a5aSVille Syrjälä 				 "DDI %c/PHY %c", port_name(port),  phy_name(phy));
45182d709a5aSVille Syrjälä 	}
4519379bc100SJani Nikula 
452036e5e704SSean Paul 	mutex_init(&dig_port->hdcp_mutex);
452136e5e704SSean Paul 	dig_port->num_hdcp_streams = 0;
452236e5e704SSean Paul 
452370dfbc29SLucas De Marchi 	encoder->hotplug = intel_ddi_hotplug;
452470dfbc29SLucas De Marchi 	encoder->compute_output_type = intel_ddi_compute_output_type;
452570dfbc29SLucas De Marchi 	encoder->compute_config = intel_ddi_compute_config;
4526b50a1aa6SManasi Navare 	encoder->compute_config_late = intel_ddi_compute_config_late;
452770dfbc29SLucas De Marchi 	encoder->enable = intel_enable_ddi;
452870dfbc29SLucas De Marchi 	encoder->pre_pll_enable = intel_ddi_pre_pll_enable;
452970dfbc29SLucas De Marchi 	encoder->pre_enable = intel_ddi_pre_enable;
453070dfbc29SLucas De Marchi 	encoder->disable = intel_disable_ddi;
453170dfbc29SLucas De Marchi 	encoder->post_disable = intel_ddi_post_disable;
453270dfbc29SLucas De Marchi 	encoder->update_pipe = intel_ddi_update_pipe;
453370dfbc29SLucas De Marchi 	encoder->get_hw_state = intel_ddi_get_hw_state;
4534f9e76a6eSImre Deak 	encoder->sync_state = intel_ddi_sync_state;
4535b671d6efSImre Deak 	encoder->initial_fastset_check = intel_ddi_initial_fastset_check;
453670dfbc29SLucas De Marchi 	encoder->suspend = intel_dp_encoder_suspend;
4537e219ef91SVille Syrjälä 	encoder->shutdown = intel_dp_encoder_shutdown;
453870dfbc29SLucas De Marchi 	encoder->get_power_domains = intel_ddi_get_power_domains;
453970dfbc29SLucas De Marchi 
454070dfbc29SLucas De Marchi 	encoder->type = INTEL_OUTPUT_DDI;
454170dfbc29SLucas De Marchi 	encoder->power_domain = intel_port_to_power_domain(port);
454270dfbc29SLucas De Marchi 	encoder->port = port;
454370dfbc29SLucas De Marchi 	encoder->cloneable = 0;
454470dfbc29SLucas De Marchi 	encoder->pipe_mask = ~0;
4545da51e4baSVille Syrjälä 
454640b316d4SVille Syrjälä 	if (IS_ALDERLAKE_S(dev_priv)) {
454740b316d4SVille Syrjälä 		encoder->enable_clock = adls_ddi_enable_clock;
454840b316d4SVille Syrjälä 		encoder->disable_clock = adls_ddi_disable_clock;
45490fbd8694SVille Syrjälä 		encoder->is_clock_enabled = adls_ddi_is_clock_enabled;
4550351221ffSVille Syrjälä 		encoder->get_config = adls_ddi_get_config;
455140b316d4SVille Syrjälä 	} else if (IS_ROCKETLAKE(dev_priv)) {
455240b316d4SVille Syrjälä 		encoder->enable_clock = rkl_ddi_enable_clock;
455340b316d4SVille Syrjälä 		encoder->disable_clock = rkl_ddi_disable_clock;
45540fbd8694SVille Syrjälä 		encoder->is_clock_enabled = rkl_ddi_is_clock_enabled;
4555351221ffSVille Syrjälä 		encoder->get_config = rkl_ddi_get_config;
455636ecb0ecSVille Syrjälä 	} else if (IS_DG1(dev_priv)) {
455735bb6b1aSVille Syrjälä 		encoder->enable_clock = dg1_ddi_enable_clock;
455835bb6b1aSVille Syrjälä 		encoder->disable_clock = dg1_ddi_disable_clock;
45590fbd8694SVille Syrjälä 		encoder->is_clock_enabled = dg1_ddi_is_clock_enabled;
4560351221ffSVille Syrjälä 		encoder->get_config = dg1_ddi_get_config;
456136ecb0ecSVille Syrjälä 	} else if (IS_JSL_EHL(dev_priv)) {
456236ecb0ecSVille Syrjälä 		if (intel_ddi_is_tc(dev_priv, port)) {
456336ecb0ecSVille Syrjälä 			encoder->enable_clock = jsl_ddi_tc_enable_clock;
456436ecb0ecSVille Syrjälä 			encoder->disable_clock = jsl_ddi_tc_disable_clock;
45650fbd8694SVille Syrjälä 			encoder->is_clock_enabled = jsl_ddi_tc_is_clock_enabled;
4566351221ffSVille Syrjälä 			encoder->get_config = icl_ddi_combo_get_config;
456736ecb0ecSVille Syrjälä 		} else {
456836ecb0ecSVille Syrjälä 			encoder->enable_clock = icl_ddi_combo_enable_clock;
456936ecb0ecSVille Syrjälä 			encoder->disable_clock = icl_ddi_combo_disable_clock;
45700fbd8694SVille Syrjälä 			encoder->is_clock_enabled = icl_ddi_combo_is_clock_enabled;
4571351221ffSVille Syrjälä 			encoder->get_config = icl_ddi_combo_get_config;
457236ecb0ecSVille Syrjälä 		}
4573005e9537SMatt Roper 	} else if (DISPLAY_VER(dev_priv) >= 11) {
457436ecb0ecSVille Syrjälä 		if (intel_ddi_is_tc(dev_priv, port)) {
457536ecb0ecSVille Syrjälä 			encoder->enable_clock = icl_ddi_tc_enable_clock;
457636ecb0ecSVille Syrjälä 			encoder->disable_clock = icl_ddi_tc_disable_clock;
45770fbd8694SVille Syrjälä 			encoder->is_clock_enabled = icl_ddi_tc_is_clock_enabled;
4578351221ffSVille Syrjälä 			encoder->get_config = icl_ddi_tc_get_config;
457936ecb0ecSVille Syrjälä 		} else {
458036ecb0ecSVille Syrjälä 			encoder->enable_clock = icl_ddi_combo_enable_clock;
458136ecb0ecSVille Syrjälä 			encoder->disable_clock = icl_ddi_combo_disable_clock;
45820fbd8694SVille Syrjälä 			encoder->is_clock_enabled = icl_ddi_combo_is_clock_enabled;
4583351221ffSVille Syrjälä 			encoder->get_config = icl_ddi_combo_get_config;
458436ecb0ecSVille Syrjälä 		}
458535bb6b1aSVille Syrjälä 	} else if (IS_CANNONLAKE(dev_priv)) {
45862c7b1d34SVille Syrjälä 		encoder->enable_clock = cnl_ddi_enable_clock;
45872c7b1d34SVille Syrjälä 		encoder->disable_clock = cnl_ddi_disable_clock;
45880fbd8694SVille Syrjälä 		encoder->is_clock_enabled = cnl_ddi_is_clock_enabled;
4589351221ffSVille Syrjälä 		encoder->get_config = cnl_ddi_get_config;
45902446e1d6SMatt Roper 	} else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
4591351221ffSVille Syrjälä 		/* BXT/GLK have fixed PLL->port mapping */
4592351221ffSVille Syrjälä 		encoder->get_config = bxt_ddi_get_config;
4593*93e7e61eSLucas De Marchi 	} else if (DISPLAY_VER(dev_priv) == 9) {
459438e31f1aSVille Syrjälä 		encoder->enable_clock = skl_ddi_enable_clock;
459538e31f1aSVille Syrjälä 		encoder->disable_clock = skl_ddi_disable_clock;
45960fbd8694SVille Syrjälä 		encoder->is_clock_enabled = skl_ddi_is_clock_enabled;
4597351221ffSVille Syrjälä 		encoder->get_config = skl_ddi_get_config;
459838e31f1aSVille Syrjälä 	} else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4599d135368dSVille Syrjälä 		encoder->enable_clock = hsw_ddi_enable_clock;
4600d135368dSVille Syrjälä 		encoder->disable_clock = hsw_ddi_disable_clock;
46010fbd8694SVille Syrjälä 		encoder->is_clock_enabled = hsw_ddi_is_clock_enabled;
4602351221ffSVille Syrjälä 		encoder->get_config = hsw_ddi_get_config;
4603d135368dSVille Syrjälä 	}
4604d135368dSVille Syrjälä 
4605229f31e2SLucas De Marchi 	if (IS_DG1(dev_priv))
4606229f31e2SLucas De Marchi 		encoder->hpd_pin = dg1_hpd_pin(dev_priv, port);
4607229f31e2SLucas De Marchi 	else if (IS_ROCKETLAKE(dev_priv))
4608da51e4baSVille Syrjälä 		encoder->hpd_pin = rkl_hpd_pin(dev_priv, port);
4609005e9537SMatt Roper 	else if (DISPLAY_VER(dev_priv) >= 12)
4610da51e4baSVille Syrjälä 		encoder->hpd_pin = tgl_hpd_pin(dev_priv, port);
461124ea098bSTejas Upadhyay 	else if (IS_JSL_EHL(dev_priv))
4612da51e4baSVille Syrjälä 		encoder->hpd_pin = ehl_hpd_pin(dev_priv, port);
4613*93e7e61eSLucas De Marchi 	else if (DISPLAY_VER(dev_priv) == 11)
4614da51e4baSVille Syrjälä 		encoder->hpd_pin = icl_hpd_pin(dev_priv, port);
46156c51f288SVille Syrjälä 	else if (IS_CANNONLAKE(dev_priv))
4616da51e4baSVille Syrjälä 		encoder->hpd_pin = cnl_hpd_pin(dev_priv, port);
4617*93e7e61eSLucas De Marchi 	else if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv))
4618c8455098SLyude Paul 		encoder->hpd_pin = skl_hpd_pin(dev_priv, port);
4619da51e4baSVille Syrjälä 	else
462003c7e4f1SVille Syrjälä 		encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port);
4621379bc100SJani Nikula 
4622005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11)
46237801f3b7SLucas De Marchi 		dig_port->saved_port_bits =
46247801f3b7SLucas De Marchi 			intel_de_read(dev_priv, DDI_BUF_CTL(port))
46257801f3b7SLucas De Marchi 			& DDI_BUF_PORT_REVERSAL;
4626379bc100SJani Nikula 	else
46277801f3b7SLucas De Marchi 		dig_port->saved_port_bits =
46287801f3b7SLucas De Marchi 			intel_de_read(dev_priv, DDI_BUF_CTL(port))
46297801f3b7SLucas De Marchi 			& (DDI_BUF_PORT_REVERSAL | DDI_A_4_LANES);
463070dfbc29SLucas De Marchi 
4631aaab24bbSUma Shankar 	if (intel_bios_is_lane_reversal_needed(dev_priv, port))
4632aaab24bbSUma Shankar 		dig_port->saved_port_bits |= DDI_BUF_PORT_REVERSAL;
4633aaab24bbSUma Shankar 
46347801f3b7SLucas De Marchi 	dig_port->dp.output_reg = INVALID_MMIO_REG;
46357801f3b7SLucas De Marchi 	dig_port->max_lanes = intel_ddi_max_lanes(dig_port);
46367801f3b7SLucas De Marchi 	dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port);
4637379bc100SJani Nikula 
4638d8fe2ab6SMatt Roper 	if (intel_phy_is_tc(dev_priv, phy)) {
4639c5faae5aSJani Nikula 		bool is_legacy =
4640f08fbe6aSJani Nikula 			!intel_bios_encoder_supports_typec_usb(devdata) &&
4641f08fbe6aSJani Nikula 			!intel_bios_encoder_supports_tbt(devdata);
4642379bc100SJani Nikula 
46437801f3b7SLucas De Marchi 		intel_tc_port_init(dig_port, is_legacy);
464424a7bfe0SImre Deak 
464570dfbc29SLucas De Marchi 		encoder->update_prepare = intel_ddi_update_prepare;
464670dfbc29SLucas De Marchi 		encoder->update_complete = intel_ddi_update_complete;
4647ab7bc4e1SImre Deak 	}
4648ab7bc4e1SImre Deak 
46491de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, port > PORT_I);
46507801f3b7SLucas De Marchi 	dig_port->ddi_io_power_domain = POWER_DOMAIN_PORT_DDI_A_IO +
4651327f8d8cSLucas De Marchi 					      port - PORT_A;
4652379bc100SJani Nikula 
4653379bc100SJani Nikula 	if (init_dp) {
46547801f3b7SLucas De Marchi 		if (!intel_ddi_init_dp_connector(dig_port))
4655379bc100SJani Nikula 			goto err;
4656379bc100SJani Nikula 
46577801f3b7SLucas De Marchi 		dig_port->hpd_pulse = intel_dp_hpd_pulse;
4658bc71194eSJani Nikula 
4659bc71194eSJani Nikula 		/* Splitter enable for eDP MSO is supported for pipe A only. */
4660bc71194eSJani Nikula 		if (dig_port->dp.mso_link_count)
4661bc71194eSJani Nikula 			encoder->pipe_mask = BIT(PIPE_A);
4662379bc100SJani Nikula 	}
4663379bc100SJani Nikula 
4664379bc100SJani Nikula 	/* In theory we don't need the encoder->type check, but leave it just in
4665379bc100SJani Nikula 	 * case we have some really bad VBTs... */
466670dfbc29SLucas De Marchi 	if (encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
46677801f3b7SLucas De Marchi 		if (!intel_ddi_init_hdmi_connector(dig_port))
4668379bc100SJani Nikula 			goto err;
4669379bc100SJani Nikula 	}
4670379bc100SJani Nikula 
4671005e9537SMatt Roper 	if (DISPLAY_VER(dev_priv) >= 11) {
4672edc0e09cSVille Syrjälä 		if (intel_phy_is_tc(dev_priv, phy))
46737801f3b7SLucas De Marchi 			dig_port->connected = intel_tc_port_connected;
4674edc0e09cSVille Syrjälä 		else
46757801f3b7SLucas De Marchi 			dig_port->connected = lpt_digital_port_connected;
4676005e9537SMatt Roper 	} else if (DISPLAY_VER(dev_priv) >= 8) {
46772446e1d6SMatt Roper 		if (port == PORT_A || IS_GEMINILAKE(dev_priv) ||
46782446e1d6SMatt Roper 		    IS_BROXTON(dev_priv))
46797801f3b7SLucas De Marchi 			dig_port->connected = bdw_digital_port_connected;
4680edc0e09cSVille Syrjälä 		else
46817801f3b7SLucas De Marchi 			dig_port->connected = lpt_digital_port_connected;
4682edc0e09cSVille Syrjälä 	} else {
4683c7e8a3d6SVille Syrjälä 		if (port == PORT_A)
46847801f3b7SLucas De Marchi 			dig_port->connected = hsw_digital_port_connected;
4685edc0e09cSVille Syrjälä 		else
46867801f3b7SLucas De Marchi 			dig_port->connected = lpt_digital_port_connected;
4687edc0e09cSVille Syrjälä 	}
4688edc0e09cSVille Syrjälä 
46897801f3b7SLucas De Marchi 	intel_infoframe_init(dig_port);
4690379bc100SJani Nikula 
4691379bc100SJani Nikula 	return;
4692379bc100SJani Nikula 
4693379bc100SJani Nikula err:
469470dfbc29SLucas De Marchi 	drm_encoder_cleanup(&encoder->base);
46957801f3b7SLucas De Marchi 	kfree(dig_port);
4696379bc100SJani Nikula }
4697