xref: /linux/drivers/gpu/drm/i915/display/intel_ddi.c (revision fc6097d4fb2988f12954993be70b882a345a35e5)
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"
314e3cdb45SManasi Navare #include "i915_trace.h"
32379bc100SJani Nikula #include "intel_audio.h"
33379bc100SJani Nikula #include "intel_combo_phy.h"
34379bc100SJani Nikula #include "intel_connector.h"
35379bc100SJani Nikula #include "intel_ddi.h"
361d455f8dSJani Nikula #include "intel_display_types.h"
37379bc100SJani Nikula #include "intel_dp.h"
38c59053dcSJosé Roberto de Souza #include "intel_dp_mst.h"
39379bc100SJani Nikula #include "intel_dp_link_training.h"
40379bc100SJani Nikula #include "intel_dpio_phy.h"
41379bc100SJani Nikula #include "intel_dsi.h"
42379bc100SJani Nikula #include "intel_fifo_underrun.h"
43379bc100SJani Nikula #include "intel_gmbus.h"
44379bc100SJani Nikula #include "intel_hdcp.h"
45379bc100SJani Nikula #include "intel_hdmi.h"
46379bc100SJani Nikula #include "intel_hotplug.h"
47379bc100SJani Nikula #include "intel_lspcon.h"
48379bc100SJani Nikula #include "intel_panel.h"
49379bc100SJani Nikula #include "intel_psr.h"
50bdacf087SAnshuman Gupta #include "intel_sprite.h"
51bc85328fSImre Deak #include "intel_tc.h"
52379bc100SJani Nikula #include "intel_vdsc.h"
53379bc100SJani Nikula 
54379bc100SJani Nikula struct ddi_buf_trans {
55379bc100SJani Nikula 	u32 trans1;	/* balance leg enable, de-emph level */
56379bc100SJani Nikula 	u32 trans2;	/* vref sel, vswing */
57379bc100SJani Nikula 	u8 i_boost;	/* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */
58379bc100SJani Nikula };
59379bc100SJani Nikula 
60379bc100SJani Nikula static const u8 index_to_dp_signal_levels[] = {
61379bc100SJani Nikula 	[0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0,
62379bc100SJani Nikula 	[1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1,
63379bc100SJani Nikula 	[2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2,
64379bc100SJani Nikula 	[3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3,
65379bc100SJani Nikula 	[4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0,
66379bc100SJani Nikula 	[5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1,
67379bc100SJani Nikula 	[6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2,
68379bc100SJani Nikula 	[7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0,
69379bc100SJani Nikula 	[8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1,
70379bc100SJani Nikula 	[9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0,
71379bc100SJani Nikula };
72379bc100SJani Nikula 
73379bc100SJani Nikula /* HDMI/DVI modes ignore everything but the last 2 items. So we share
74379bc100SJani Nikula  * them for both DP and FDI transports, allowing those ports to
75379bc100SJani Nikula  * automatically adapt to HDMI connections as well
76379bc100SJani Nikula  */
77379bc100SJani Nikula static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
78379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0006000E, 0x0 },
79379bc100SJani Nikula 	{ 0x00D75FFF, 0x0005000A, 0x0 },
80379bc100SJani Nikula 	{ 0x00C30FFF, 0x00040006, 0x0 },
81379bc100SJani Nikula 	{ 0x80AAAFFF, 0x000B0000, 0x0 },
82379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0005000A, 0x0 },
83379bc100SJani Nikula 	{ 0x00D75FFF, 0x000C0004, 0x0 },
84379bc100SJani Nikula 	{ 0x80C30FFF, 0x000B0000, 0x0 },
85379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00040006, 0x0 },
86379bc100SJani Nikula 	{ 0x80D75FFF, 0x000B0000, 0x0 },
87379bc100SJani Nikula };
88379bc100SJani Nikula 
89379bc100SJani Nikula static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
90379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0007000E, 0x0 },
91379bc100SJani Nikula 	{ 0x00D75FFF, 0x000F000A, 0x0 },
92379bc100SJani Nikula 	{ 0x00C30FFF, 0x00060006, 0x0 },
93379bc100SJani Nikula 	{ 0x00AAAFFF, 0x001E0000, 0x0 },
94379bc100SJani Nikula 	{ 0x00FFFFFF, 0x000F000A, 0x0 },
95379bc100SJani Nikula 	{ 0x00D75FFF, 0x00160004, 0x0 },
96379bc100SJani Nikula 	{ 0x00C30FFF, 0x001E0000, 0x0 },
97379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00060006, 0x0 },
98379bc100SJani Nikula 	{ 0x00D75FFF, 0x001E0000, 0x0 },
99379bc100SJani Nikula };
100379bc100SJani Nikula 
101379bc100SJani Nikula static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
102379bc100SJani Nikula 					/* Idx	NT mV d	T mV d	db	*/
103379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0006000E, 0x0 },/* 0:	400	400	0	*/
104379bc100SJani Nikula 	{ 0x00E79FFF, 0x000E000C, 0x0 },/* 1:	400	500	2	*/
105379bc100SJani Nikula 	{ 0x00D75FFF, 0x0005000A, 0x0 },/* 2:	400	600	3.5	*/
106379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0005000A, 0x0 },/* 3:	600	600	0	*/
107379bc100SJani Nikula 	{ 0x00E79FFF, 0x001D0007, 0x0 },/* 4:	600	750	2	*/
108379bc100SJani Nikula 	{ 0x00D75FFF, 0x000C0004, 0x0 },/* 5:	600	900	3.5	*/
109379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00040006, 0x0 },/* 6:	800	800	0	*/
110379bc100SJani Nikula 	{ 0x80E79FFF, 0x00030002, 0x0 },/* 7:	800	1000	2	*/
111379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00140005, 0x0 },/* 8:	850	850	0	*/
112379bc100SJani Nikula 	{ 0x00FFFFFF, 0x000C0004, 0x0 },/* 9:	900	900	0	*/
113379bc100SJani Nikula 	{ 0x00FFFFFF, 0x001C0003, 0x0 },/* 10:	950	950	0	*/
114379bc100SJani Nikula 	{ 0x80FFFFFF, 0x00030002, 0x0 },/* 11:	1000	1000	0	*/
115379bc100SJani Nikula };
116379bc100SJani Nikula 
117379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
118379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00000012, 0x0 },
119379bc100SJani Nikula 	{ 0x00EBAFFF, 0x00020011, 0x0 },
120379bc100SJani Nikula 	{ 0x00C71FFF, 0x0006000F, 0x0 },
121379bc100SJani Nikula 	{ 0x00AAAFFF, 0x000E000A, 0x0 },
122379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00020011, 0x0 },
123379bc100SJani Nikula 	{ 0x00DB6FFF, 0x0005000F, 0x0 },
124379bc100SJani Nikula 	{ 0x00BEEFFF, 0x000A000C, 0x0 },
125379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0005000F, 0x0 },
126379bc100SJani Nikula 	{ 0x00DB6FFF, 0x000A000C, 0x0 },
127379bc100SJani Nikula };
128379bc100SJani Nikula 
129379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
130379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0007000E, 0x0 },
131379bc100SJani Nikula 	{ 0x00D75FFF, 0x000E000A, 0x0 },
132379bc100SJani Nikula 	{ 0x00BEFFFF, 0x00140006, 0x0 },
133379bc100SJani Nikula 	{ 0x80B2CFFF, 0x001B0002, 0x0 },
134379bc100SJani Nikula 	{ 0x00FFFFFF, 0x000E000A, 0x0 },
135379bc100SJani Nikula 	{ 0x00DB6FFF, 0x00160005, 0x0 },
136379bc100SJani Nikula 	{ 0x80C71FFF, 0x001A0002, 0x0 },
137379bc100SJani Nikula 	{ 0x00F7DFFF, 0x00180004, 0x0 },
138379bc100SJani Nikula 	{ 0x80D75FFF, 0x001B0002, 0x0 },
139379bc100SJani Nikula };
140379bc100SJani Nikula 
141379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
142379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0001000E, 0x0 },
143379bc100SJani Nikula 	{ 0x00D75FFF, 0x0004000A, 0x0 },
144379bc100SJani Nikula 	{ 0x00C30FFF, 0x00070006, 0x0 },
145379bc100SJani Nikula 	{ 0x00AAAFFF, 0x000C0000, 0x0 },
146379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0004000A, 0x0 },
147379bc100SJani Nikula 	{ 0x00D75FFF, 0x00090004, 0x0 },
148379bc100SJani Nikula 	{ 0x00C30FFF, 0x000C0000, 0x0 },
149379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00070006, 0x0 },
150379bc100SJani Nikula 	{ 0x00D75FFF, 0x000C0000, 0x0 },
151379bc100SJani Nikula };
152379bc100SJani Nikula 
153379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
154379bc100SJani Nikula 					/* Idx	NT mV d	T mV df	db	*/
155379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0007000E, 0x0 },/* 0:	400	400	0	*/
156379bc100SJani Nikula 	{ 0x00D75FFF, 0x000E000A, 0x0 },/* 1:	400	600	3.5	*/
157379bc100SJani Nikula 	{ 0x00BEFFFF, 0x00140006, 0x0 },/* 2:	400	800	6	*/
158379bc100SJani Nikula 	{ 0x00FFFFFF, 0x0009000D, 0x0 },/* 3:	450	450	0	*/
159379bc100SJani Nikula 	{ 0x00FFFFFF, 0x000E000A, 0x0 },/* 4:	600	600	0	*/
160379bc100SJani Nikula 	{ 0x00D7FFFF, 0x00140006, 0x0 },/* 5:	600	800	2.5	*/
161379bc100SJani Nikula 	{ 0x80CB2FFF, 0x001B0002, 0x0 },/* 6:	600	1000	4.5	*/
162379bc100SJani Nikula 	{ 0x00FFFFFF, 0x00140006, 0x0 },/* 7:	800	800	0	*/
163379bc100SJani Nikula 	{ 0x80E79FFF, 0x001B0002, 0x0 },/* 8:	800	1000	2	*/
164379bc100SJani Nikula 	{ 0x80FFFFFF, 0x001B0002, 0x0 },/* 9:	1000	1000	0	*/
165379bc100SJani Nikula };
166379bc100SJani Nikula 
167379bc100SJani Nikula /* Skylake H and S */
168379bc100SJani Nikula static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
169379bc100SJani Nikula 	{ 0x00002016, 0x000000A0, 0x0 },
170379bc100SJani Nikula 	{ 0x00005012, 0x0000009B, 0x0 },
171379bc100SJani Nikula 	{ 0x00007011, 0x00000088, 0x0 },
172379bc100SJani Nikula 	{ 0x80009010, 0x000000C0, 0x1 },
173379bc100SJani Nikula 	{ 0x00002016, 0x0000009B, 0x0 },
174379bc100SJani Nikula 	{ 0x00005012, 0x00000088, 0x0 },
175379bc100SJani Nikula 	{ 0x80007011, 0x000000C0, 0x1 },
176379bc100SJani Nikula 	{ 0x00002016, 0x000000DF, 0x0 },
177379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x1 },
178379bc100SJani Nikula };
179379bc100SJani Nikula 
180379bc100SJani Nikula /* Skylake U */
181379bc100SJani Nikula static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
182379bc100SJani Nikula 	{ 0x0000201B, 0x000000A2, 0x0 },
183379bc100SJani Nikula 	{ 0x00005012, 0x00000088, 0x0 },
184379bc100SJani Nikula 	{ 0x80007011, 0x000000CD, 0x1 },
185379bc100SJani Nikula 	{ 0x80009010, 0x000000C0, 0x1 },
186379bc100SJani Nikula 	{ 0x0000201B, 0x0000009D, 0x0 },
187379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x1 },
188379bc100SJani Nikula 	{ 0x80007011, 0x000000C0, 0x1 },
189379bc100SJani Nikula 	{ 0x00002016, 0x00000088, 0x0 },
190379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x1 },
191379bc100SJani Nikula };
192379bc100SJani Nikula 
193379bc100SJani Nikula /* Skylake Y */
194379bc100SJani Nikula static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
195379bc100SJani Nikula 	{ 0x00000018, 0x000000A2, 0x0 },
196379bc100SJani Nikula 	{ 0x00005012, 0x00000088, 0x0 },
197379bc100SJani Nikula 	{ 0x80007011, 0x000000CD, 0x3 },
198379bc100SJani Nikula 	{ 0x80009010, 0x000000C0, 0x3 },
199379bc100SJani Nikula 	{ 0x00000018, 0x0000009D, 0x0 },
200379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x3 },
201379bc100SJani Nikula 	{ 0x80007011, 0x000000C0, 0x3 },
202379bc100SJani Nikula 	{ 0x00000018, 0x00000088, 0x0 },
203379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x3 },
204379bc100SJani Nikula };
205379bc100SJani Nikula 
206379bc100SJani Nikula /* Kabylake H and S */
207379bc100SJani Nikula static const struct ddi_buf_trans kbl_ddi_translations_dp[] = {
208379bc100SJani Nikula 	{ 0x00002016, 0x000000A0, 0x0 },
209379bc100SJani Nikula 	{ 0x00005012, 0x0000009B, 0x0 },
210379bc100SJani Nikula 	{ 0x00007011, 0x00000088, 0x0 },
211379bc100SJani Nikula 	{ 0x80009010, 0x000000C0, 0x1 },
212379bc100SJani Nikula 	{ 0x00002016, 0x0000009B, 0x0 },
213379bc100SJani Nikula 	{ 0x00005012, 0x00000088, 0x0 },
214379bc100SJani Nikula 	{ 0x80007011, 0x000000C0, 0x1 },
215379bc100SJani Nikula 	{ 0x00002016, 0x00000097, 0x0 },
216379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x1 },
217379bc100SJani Nikula };
218379bc100SJani Nikula 
219379bc100SJani Nikula /* Kabylake U */
220379bc100SJani Nikula static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = {
221379bc100SJani Nikula 	{ 0x0000201B, 0x000000A1, 0x0 },
222379bc100SJani Nikula 	{ 0x00005012, 0x00000088, 0x0 },
223379bc100SJani Nikula 	{ 0x80007011, 0x000000CD, 0x3 },
224379bc100SJani Nikula 	{ 0x80009010, 0x000000C0, 0x3 },
225379bc100SJani Nikula 	{ 0x0000201B, 0x0000009D, 0x0 },
226379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x3 },
227379bc100SJani Nikula 	{ 0x80007011, 0x000000C0, 0x3 },
228379bc100SJani Nikula 	{ 0x00002016, 0x0000004F, 0x0 },
229379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x3 },
230379bc100SJani Nikula };
231379bc100SJani Nikula 
232379bc100SJani Nikula /* Kabylake Y */
233379bc100SJani Nikula static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = {
234379bc100SJani Nikula 	{ 0x00001017, 0x000000A1, 0x0 },
235379bc100SJani Nikula 	{ 0x00005012, 0x00000088, 0x0 },
236379bc100SJani Nikula 	{ 0x80007011, 0x000000CD, 0x3 },
237379bc100SJani Nikula 	{ 0x8000800F, 0x000000C0, 0x3 },
238379bc100SJani Nikula 	{ 0x00001017, 0x0000009D, 0x0 },
239379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x3 },
240379bc100SJani Nikula 	{ 0x80007011, 0x000000C0, 0x3 },
241379bc100SJani Nikula 	{ 0x00001017, 0x0000004C, 0x0 },
242379bc100SJani Nikula 	{ 0x80005012, 0x000000C0, 0x3 },
243379bc100SJani Nikula };
244379bc100SJani Nikula 
245379bc100SJani Nikula /*
246379bc100SJani Nikula  * Skylake/Kabylake H and S
247379bc100SJani Nikula  * eDP 1.4 low vswing translation parameters
248379bc100SJani Nikula  */
249379bc100SJani Nikula static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
250379bc100SJani Nikula 	{ 0x00000018, 0x000000A8, 0x0 },
251379bc100SJani Nikula 	{ 0x00004013, 0x000000A9, 0x0 },
252379bc100SJani Nikula 	{ 0x00007011, 0x000000A2, 0x0 },
253379bc100SJani Nikula 	{ 0x00009010, 0x0000009C, 0x0 },
254379bc100SJani Nikula 	{ 0x00000018, 0x000000A9, 0x0 },
255379bc100SJani Nikula 	{ 0x00006013, 0x000000A2, 0x0 },
256379bc100SJani Nikula 	{ 0x00007011, 0x000000A6, 0x0 },
257379bc100SJani Nikula 	{ 0x00000018, 0x000000AB, 0x0 },
258379bc100SJani Nikula 	{ 0x00007013, 0x0000009F, 0x0 },
259379bc100SJani Nikula 	{ 0x00000018, 0x000000DF, 0x0 },
260379bc100SJani Nikula };
261379bc100SJani Nikula 
262379bc100SJani Nikula /*
263379bc100SJani Nikula  * Skylake/Kabylake U
264379bc100SJani Nikula  * eDP 1.4 low vswing translation parameters
265379bc100SJani Nikula  */
266379bc100SJani Nikula static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
267379bc100SJani Nikula 	{ 0x00000018, 0x000000A8, 0x0 },
268379bc100SJani Nikula 	{ 0x00004013, 0x000000A9, 0x0 },
269379bc100SJani Nikula 	{ 0x00007011, 0x000000A2, 0x0 },
270379bc100SJani Nikula 	{ 0x00009010, 0x0000009C, 0x0 },
271379bc100SJani Nikula 	{ 0x00000018, 0x000000A9, 0x0 },
272379bc100SJani Nikula 	{ 0x00006013, 0x000000A2, 0x0 },
273379bc100SJani Nikula 	{ 0x00007011, 0x000000A6, 0x0 },
274379bc100SJani Nikula 	{ 0x00002016, 0x000000AB, 0x0 },
275379bc100SJani Nikula 	{ 0x00005013, 0x0000009F, 0x0 },
276379bc100SJani Nikula 	{ 0x00000018, 0x000000DF, 0x0 },
277379bc100SJani Nikula };
278379bc100SJani Nikula 
279379bc100SJani Nikula /*
280379bc100SJani Nikula  * Skylake/Kabylake Y
281379bc100SJani Nikula  * eDP 1.4 low vswing translation parameters
282379bc100SJani Nikula  */
283379bc100SJani Nikula static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
284379bc100SJani Nikula 	{ 0x00000018, 0x000000A8, 0x0 },
285379bc100SJani Nikula 	{ 0x00004013, 0x000000AB, 0x0 },
286379bc100SJani Nikula 	{ 0x00007011, 0x000000A4, 0x0 },
287379bc100SJani Nikula 	{ 0x00009010, 0x000000DF, 0x0 },
288379bc100SJani Nikula 	{ 0x00000018, 0x000000AA, 0x0 },
289379bc100SJani Nikula 	{ 0x00006013, 0x000000A4, 0x0 },
290379bc100SJani Nikula 	{ 0x00007011, 0x0000009D, 0x0 },
291379bc100SJani Nikula 	{ 0x00000018, 0x000000A0, 0x0 },
292379bc100SJani Nikula 	{ 0x00006012, 0x000000DF, 0x0 },
293379bc100SJani Nikula 	{ 0x00000018, 0x0000008A, 0x0 },
294379bc100SJani Nikula };
295379bc100SJani Nikula 
296379bc100SJani Nikula /* Skylake/Kabylake U, H and S */
297379bc100SJani Nikula static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
298379bc100SJani Nikula 	{ 0x00000018, 0x000000AC, 0x0 },
299379bc100SJani Nikula 	{ 0x00005012, 0x0000009D, 0x0 },
300379bc100SJani Nikula 	{ 0x00007011, 0x00000088, 0x0 },
301379bc100SJani Nikula 	{ 0x00000018, 0x000000A1, 0x0 },
302379bc100SJani Nikula 	{ 0x00000018, 0x00000098, 0x0 },
303379bc100SJani Nikula 	{ 0x00004013, 0x00000088, 0x0 },
304379bc100SJani Nikula 	{ 0x80006012, 0x000000CD, 0x1 },
305379bc100SJani Nikula 	{ 0x00000018, 0x000000DF, 0x0 },
306379bc100SJani Nikula 	{ 0x80003015, 0x000000CD, 0x1 },	/* Default */
307379bc100SJani Nikula 	{ 0x80003015, 0x000000C0, 0x1 },
308379bc100SJani Nikula 	{ 0x80000018, 0x000000C0, 0x1 },
309379bc100SJani Nikula };
310379bc100SJani Nikula 
311379bc100SJani Nikula /* Skylake/Kabylake Y */
312379bc100SJani Nikula static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
313379bc100SJani Nikula 	{ 0x00000018, 0x000000A1, 0x0 },
314379bc100SJani Nikula 	{ 0x00005012, 0x000000DF, 0x0 },
315379bc100SJani Nikula 	{ 0x80007011, 0x000000CB, 0x3 },
316379bc100SJani Nikula 	{ 0x00000018, 0x000000A4, 0x0 },
317379bc100SJani Nikula 	{ 0x00000018, 0x0000009D, 0x0 },
318379bc100SJani Nikula 	{ 0x00004013, 0x00000080, 0x0 },
319379bc100SJani Nikula 	{ 0x80006013, 0x000000C0, 0x3 },
320379bc100SJani Nikula 	{ 0x00000018, 0x0000008A, 0x0 },
321379bc100SJani Nikula 	{ 0x80003015, 0x000000C0, 0x3 },	/* Default */
322379bc100SJani Nikula 	{ 0x80003015, 0x000000C0, 0x3 },
323379bc100SJani Nikula 	{ 0x80000018, 0x000000C0, 0x3 },
324379bc100SJani Nikula };
325379bc100SJani Nikula 
326379bc100SJani Nikula struct bxt_ddi_buf_trans {
327379bc100SJani Nikula 	u8 margin;	/* swing value */
328379bc100SJani Nikula 	u8 scale;	/* scale value */
329379bc100SJani Nikula 	u8 enable;	/* scale enable */
330379bc100SJani Nikula 	u8 deemphasis;
331379bc100SJani Nikula };
332379bc100SJani Nikula 
333379bc100SJani Nikula static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
334379bc100SJani Nikula 					/* Idx	NT mV diff	db  */
335379bc100SJani Nikula 	{ 52,  0x9A, 0, 128, },	/* 0:	400		0   */
336379bc100SJani Nikula 	{ 78,  0x9A, 0, 85,  },	/* 1:	400		3.5 */
337379bc100SJani Nikula 	{ 104, 0x9A, 0, 64,  },	/* 2:	400		6   */
338379bc100SJani Nikula 	{ 154, 0x9A, 0, 43,  },	/* 3:	400		9.5 */
339379bc100SJani Nikula 	{ 77,  0x9A, 0, 128, },	/* 4:	600		0   */
340379bc100SJani Nikula 	{ 116, 0x9A, 0, 85,  },	/* 5:	600		3.5 */
341379bc100SJani Nikula 	{ 154, 0x9A, 0, 64,  },	/* 6:	600		6   */
342379bc100SJani Nikula 	{ 102, 0x9A, 0, 128, },	/* 7:	800		0   */
343379bc100SJani Nikula 	{ 154, 0x9A, 0, 85,  },	/* 8:	800		3.5 */
344379bc100SJani Nikula 	{ 154, 0x9A, 1, 128, },	/* 9:	1200		0   */
345379bc100SJani Nikula };
346379bc100SJani Nikula 
347379bc100SJani Nikula static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
348379bc100SJani Nikula 					/* Idx	NT mV diff	db  */
349379bc100SJani Nikula 	{ 26, 0, 0, 128, },	/* 0:	200		0   */
350379bc100SJani Nikula 	{ 38, 0, 0, 112, },	/* 1:	200		1.5 */
351379bc100SJani Nikula 	{ 48, 0, 0, 96,  },	/* 2:	200		4   */
352379bc100SJani Nikula 	{ 54, 0, 0, 69,  },	/* 3:	200		6   */
353379bc100SJani Nikula 	{ 32, 0, 0, 128, },	/* 4:	250		0   */
354379bc100SJani Nikula 	{ 48, 0, 0, 104, },	/* 5:	250		1.5 */
355379bc100SJani Nikula 	{ 54, 0, 0, 85,  },	/* 6:	250		4   */
356379bc100SJani Nikula 	{ 43, 0, 0, 128, },	/* 7:	300		0   */
357379bc100SJani Nikula 	{ 54, 0, 0, 101, },	/* 8:	300		1.5 */
358379bc100SJani Nikula 	{ 48, 0, 0, 128, },	/* 9:	300		0   */
359379bc100SJani Nikula };
360379bc100SJani Nikula 
361379bc100SJani Nikula /* BSpec has 2 recommended values - entries 0 and 8.
362379bc100SJani Nikula  * Using the entry with higher vswing.
363379bc100SJani Nikula  */
364379bc100SJani Nikula static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
365379bc100SJani Nikula 					/* Idx	NT mV diff	db  */
366379bc100SJani Nikula 	{ 52,  0x9A, 0, 128, },	/* 0:	400		0   */
367379bc100SJani Nikula 	{ 52,  0x9A, 0, 85,  },	/* 1:	400		3.5 */
368379bc100SJani Nikula 	{ 52,  0x9A, 0, 64,  },	/* 2:	400		6   */
369379bc100SJani Nikula 	{ 42,  0x9A, 0, 43,  },	/* 3:	400		9.5 */
370379bc100SJani Nikula 	{ 77,  0x9A, 0, 128, },	/* 4:	600		0   */
371379bc100SJani Nikula 	{ 77,  0x9A, 0, 85,  },	/* 5:	600		3.5 */
372379bc100SJani Nikula 	{ 77,  0x9A, 0, 64,  },	/* 6:	600		6   */
373379bc100SJani Nikula 	{ 102, 0x9A, 0, 128, },	/* 7:	800		0   */
374379bc100SJani Nikula 	{ 102, 0x9A, 0, 85,  },	/* 8:	800		3.5 */
375379bc100SJani Nikula 	{ 154, 0x9A, 1, 128, },	/* 9:	1200		0   */
376379bc100SJani Nikula };
377379bc100SJani Nikula 
378379bc100SJani Nikula struct cnl_ddi_buf_trans {
379379bc100SJani Nikula 	u8 dw2_swing_sel;
380379bc100SJani Nikula 	u8 dw7_n_scalar;
381379bc100SJani Nikula 	u8 dw4_cursor_coeff;
382379bc100SJani Nikula 	u8 dw4_post_cursor_2;
383379bc100SJani Nikula 	u8 dw4_post_cursor_1;
384379bc100SJani Nikula };
385379bc100SJani Nikula 
386379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.85V for DP */
387379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V[] = {
388379bc100SJani Nikula 						/* NT mV Trans mV db    */
389379bc100SJani Nikula 	{ 0xA, 0x5D, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
390379bc100SJani Nikula 	{ 0xA, 0x6A, 0x38, 0x00, 0x07 },	/* 350   500      3.1   */
391379bc100SJani Nikula 	{ 0xB, 0x7A, 0x32, 0x00, 0x0D },	/* 350   700      6.0   */
392379bc100SJani Nikula 	{ 0x6, 0x7C, 0x2D, 0x00, 0x12 },	/* 350   900      8.2   */
393379bc100SJani Nikula 	{ 0xA, 0x69, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
394379bc100SJani Nikula 	{ 0xB, 0x7A, 0x36, 0x00, 0x09 },	/* 500   700      2.9   */
395379bc100SJani Nikula 	{ 0x6, 0x7C, 0x30, 0x00, 0x0F },	/* 500   900      5.1   */
396379bc100SJani Nikula 	{ 0xB, 0x7D, 0x3C, 0x00, 0x03 },	/* 650   725      0.9   */
397379bc100SJani Nikula 	{ 0x6, 0x7C, 0x34, 0x00, 0x0B },	/* 600   900      3.5   */
398379bc100SJani Nikula 	{ 0x6, 0x7B, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
399379bc100SJani Nikula };
400379bc100SJani Nikula 
401379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.85V for HDMI */
402379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V[] = {
403379bc100SJani Nikula 						/* NT mV Trans mV db    */
404379bc100SJani Nikula 	{ 0xA, 0x60, 0x3F, 0x00, 0x00 },	/* 450   450      0.0   */
405379bc100SJani Nikula 	{ 0xB, 0x73, 0x36, 0x00, 0x09 },	/* 450   650      3.2   */
406379bc100SJani Nikula 	{ 0x6, 0x7F, 0x31, 0x00, 0x0E },	/* 450   850      5.5   */
407379bc100SJani Nikula 	{ 0xB, 0x73, 0x3F, 0x00, 0x00 },	/* 650   650      0.0   */
408379bc100SJani Nikula 	{ 0x6, 0x7F, 0x37, 0x00, 0x08 },	/* 650   850      2.3   */
409379bc100SJani Nikula 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 850   850      0.0   */
410379bc100SJani Nikula 	{ 0x6, 0x7F, 0x35, 0x00, 0x0A },	/* 600   850      3.0   */
411379bc100SJani Nikula };
412379bc100SJani Nikula 
413379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.85V for eDP */
414379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V[] = {
415379bc100SJani Nikula 						/* NT mV Trans mV db    */
416379bc100SJani Nikula 	{ 0xA, 0x66, 0x3A, 0x00, 0x05 },	/* 384   500      2.3   */
417379bc100SJani Nikula 	{ 0x0, 0x7F, 0x38, 0x00, 0x07 },	/* 153   200      2.3   */
418379bc100SJani Nikula 	{ 0x8, 0x7F, 0x38, 0x00, 0x07 },	/* 192   250      2.3   */
419379bc100SJani Nikula 	{ 0x1, 0x7F, 0x38, 0x00, 0x07 },	/* 230   300      2.3   */
420379bc100SJani Nikula 	{ 0x9, 0x7F, 0x38, 0x00, 0x07 },	/* 269   350      2.3   */
421379bc100SJani Nikula 	{ 0xA, 0x66, 0x3C, 0x00, 0x03 },	/* 446   500      1.0   */
422379bc100SJani Nikula 	{ 0xB, 0x70, 0x3C, 0x00, 0x03 },	/* 460   600      2.3   */
423379bc100SJani Nikula 	{ 0xC, 0x75, 0x3C, 0x00, 0x03 },	/* 537   700      2.3   */
424379bc100SJani Nikula 	{ 0x2, 0x7F, 0x3F, 0x00, 0x00 },	/* 400   400      0.0   */
425379bc100SJani Nikula };
426379bc100SJani Nikula 
427379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.95V for DP */
428379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V[] = {
429379bc100SJani Nikula 						/* NT mV Trans mV db    */
430379bc100SJani Nikula 	{ 0xA, 0x5D, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
431379bc100SJani Nikula 	{ 0xA, 0x6A, 0x38, 0x00, 0x07 },	/* 350   500      3.1   */
432379bc100SJani Nikula 	{ 0xB, 0x7A, 0x32, 0x00, 0x0D },	/* 350   700      6.0   */
433379bc100SJani Nikula 	{ 0x6, 0x7C, 0x2D, 0x00, 0x12 },	/* 350   900      8.2   */
434379bc100SJani Nikula 	{ 0xA, 0x69, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
435379bc100SJani Nikula 	{ 0xB, 0x7A, 0x36, 0x00, 0x09 },	/* 500   700      2.9   */
436379bc100SJani Nikula 	{ 0x6, 0x7C, 0x30, 0x00, 0x0F },	/* 500   900      5.1   */
437379bc100SJani Nikula 	{ 0xB, 0x7D, 0x3C, 0x00, 0x03 },	/* 650   725      0.9   */
438379bc100SJani Nikula 	{ 0x6, 0x7C, 0x34, 0x00, 0x0B },	/* 600   900      3.5   */
439379bc100SJani Nikula 	{ 0x6, 0x7B, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
440379bc100SJani Nikula };
441379bc100SJani Nikula 
442379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.95V for HDMI */
443379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V[] = {
444379bc100SJani Nikula 						/* NT mV Trans mV db    */
445379bc100SJani Nikula 	{ 0xA, 0x5C, 0x3F, 0x00, 0x00 },	/* 400   400      0.0   */
446379bc100SJani Nikula 	{ 0xB, 0x69, 0x37, 0x00, 0x08 },	/* 400   600      3.5   */
447379bc100SJani Nikula 	{ 0x5, 0x76, 0x31, 0x00, 0x0E },	/* 400   800      6.0   */
448379bc100SJani Nikula 	{ 0xA, 0x5E, 0x3F, 0x00, 0x00 },	/* 450   450      0.0   */
449379bc100SJani Nikula 	{ 0xB, 0x69, 0x3F, 0x00, 0x00 },	/* 600   600      0.0   */
450379bc100SJani Nikula 	{ 0xB, 0x79, 0x35, 0x00, 0x0A },	/* 600   850      3.0   */
451379bc100SJani Nikula 	{ 0x6, 0x7D, 0x32, 0x00, 0x0D },	/* 600   1000     4.4   */
452379bc100SJani Nikula 	{ 0x5, 0x76, 0x3F, 0x00, 0x00 },	/* 800   800      0.0   */
453379bc100SJani Nikula 	{ 0x6, 0x7D, 0x39, 0x00, 0x06 },	/* 800   1000     1.9   */
454379bc100SJani Nikula 	{ 0x6, 0x7F, 0x39, 0x00, 0x06 },	/* 850   1050     1.8   */
455379bc100SJani Nikula 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 1050  1050     0.0   */
456379bc100SJani Nikula };
457379bc100SJani Nikula 
458379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.95V for eDP */
459379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V[] = {
460379bc100SJani Nikula 						/* NT mV Trans mV db    */
461379bc100SJani Nikula 	{ 0xA, 0x61, 0x3A, 0x00, 0x05 },	/* 384   500      2.3   */
462379bc100SJani Nikula 	{ 0x0, 0x7F, 0x38, 0x00, 0x07 },	/* 153   200      2.3   */
463379bc100SJani Nikula 	{ 0x8, 0x7F, 0x38, 0x00, 0x07 },	/* 192   250      2.3   */
464379bc100SJani Nikula 	{ 0x1, 0x7F, 0x38, 0x00, 0x07 },	/* 230   300      2.3   */
465379bc100SJani Nikula 	{ 0x9, 0x7F, 0x38, 0x00, 0x07 },	/* 269   350      2.3   */
466379bc100SJani Nikula 	{ 0xA, 0x61, 0x3C, 0x00, 0x03 },	/* 446   500      1.0   */
467379bc100SJani Nikula 	{ 0xB, 0x68, 0x39, 0x00, 0x06 },	/* 460   600      2.3   */
468379bc100SJani Nikula 	{ 0xC, 0x6E, 0x39, 0x00, 0x06 },	/* 537   700      2.3   */
469379bc100SJani Nikula 	{ 0x4, 0x7F, 0x3A, 0x00, 0x05 },	/* 460   600      2.3   */
470379bc100SJani Nikula 	{ 0x2, 0x7F, 0x3F, 0x00, 0x00 },	/* 400   400      0.0   */
471379bc100SJani Nikula };
472379bc100SJani Nikula 
473379bc100SJani Nikula /* Voltage Swing Programming for VccIO 1.05V for DP */
474379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V[] = {
475379bc100SJani Nikula 						/* NT mV Trans mV db    */
476379bc100SJani Nikula 	{ 0xA, 0x58, 0x3F, 0x00, 0x00 },	/* 400   400      0.0   */
477379bc100SJani Nikula 	{ 0xB, 0x64, 0x37, 0x00, 0x08 },	/* 400   600      3.5   */
478379bc100SJani Nikula 	{ 0x5, 0x70, 0x31, 0x00, 0x0E },	/* 400   800      6.0   */
479379bc100SJani Nikula 	{ 0x6, 0x7F, 0x2C, 0x00, 0x13 },	/* 400   1050     8.4   */
480379bc100SJani Nikula 	{ 0xB, 0x64, 0x3F, 0x00, 0x00 },	/* 600   600      0.0   */
481379bc100SJani Nikula 	{ 0x5, 0x73, 0x35, 0x00, 0x0A },	/* 600   850      3.0   */
482379bc100SJani Nikula 	{ 0x6, 0x7F, 0x30, 0x00, 0x0F },	/* 550   1050     5.6   */
483379bc100SJani Nikula 	{ 0x5, 0x76, 0x3E, 0x00, 0x01 },	/* 850   900      0.5   */
484379bc100SJani Nikula 	{ 0x6, 0x7F, 0x36, 0x00, 0x09 },	/* 750   1050     2.9   */
485379bc100SJani Nikula 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 1050  1050     0.0   */
486379bc100SJani Nikula };
487379bc100SJani Nikula 
488379bc100SJani Nikula /* Voltage Swing Programming for VccIO 1.05V for HDMI */
489379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V[] = {
490379bc100SJani Nikula 						/* NT mV Trans mV db    */
491379bc100SJani Nikula 	{ 0xA, 0x58, 0x3F, 0x00, 0x00 },	/* 400   400      0.0   */
492379bc100SJani Nikula 	{ 0xB, 0x64, 0x37, 0x00, 0x08 },	/* 400   600      3.5   */
493379bc100SJani Nikula 	{ 0x5, 0x70, 0x31, 0x00, 0x0E },	/* 400   800      6.0   */
494379bc100SJani Nikula 	{ 0xA, 0x5B, 0x3F, 0x00, 0x00 },	/* 450   450      0.0   */
495379bc100SJani Nikula 	{ 0xB, 0x64, 0x3F, 0x00, 0x00 },	/* 600   600      0.0   */
496379bc100SJani Nikula 	{ 0x5, 0x73, 0x35, 0x00, 0x0A },	/* 600   850      3.0   */
497379bc100SJani Nikula 	{ 0x6, 0x7C, 0x32, 0x00, 0x0D },	/* 600   1000     4.4   */
498379bc100SJani Nikula 	{ 0x5, 0x70, 0x3F, 0x00, 0x00 },	/* 800   800      0.0   */
499379bc100SJani Nikula 	{ 0x6, 0x7C, 0x39, 0x00, 0x06 },	/* 800   1000     1.9   */
500379bc100SJani Nikula 	{ 0x6, 0x7F, 0x39, 0x00, 0x06 },	/* 850   1050     1.8   */
501379bc100SJani Nikula 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 1050  1050     0.0   */
502379bc100SJani Nikula };
503379bc100SJani Nikula 
504379bc100SJani Nikula /* Voltage Swing Programming for VccIO 1.05V for eDP */
505379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V[] = {
506379bc100SJani Nikula 						/* NT mV Trans mV db    */
507379bc100SJani Nikula 	{ 0xA, 0x5E, 0x3A, 0x00, 0x05 },	/* 384   500      2.3   */
508379bc100SJani Nikula 	{ 0x0, 0x7F, 0x38, 0x00, 0x07 },	/* 153   200      2.3   */
509379bc100SJani Nikula 	{ 0x8, 0x7F, 0x38, 0x00, 0x07 },	/* 192   250      2.3   */
510379bc100SJani Nikula 	{ 0x1, 0x7F, 0x38, 0x00, 0x07 },	/* 230   300      2.3   */
511379bc100SJani Nikula 	{ 0x9, 0x7F, 0x38, 0x00, 0x07 },	/* 269   350      2.3   */
512379bc100SJani Nikula 	{ 0xA, 0x5E, 0x3C, 0x00, 0x03 },	/* 446   500      1.0   */
513379bc100SJani Nikula 	{ 0xB, 0x64, 0x39, 0x00, 0x06 },	/* 460   600      2.3   */
514379bc100SJani Nikula 	{ 0xE, 0x6A, 0x39, 0x00, 0x06 },	/* 537   700      2.3   */
515379bc100SJani Nikula 	{ 0x2, 0x7F, 0x3F, 0x00, 0x00 },	/* 400   400      0.0   */
516379bc100SJani Nikula };
517379bc100SJani Nikula 
518379bc100SJani Nikula /* icl_combo_phy_ddi_translations */
519379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_dp_hbr2[] = {
520379bc100SJani Nikula 						/* NT mV Trans mV db    */
521379bc100SJani Nikula 	{ 0xA, 0x35, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
522379bc100SJani Nikula 	{ 0xA, 0x4F, 0x37, 0x00, 0x08 },	/* 350   500      3.1   */
523379bc100SJani Nikula 	{ 0xC, 0x71, 0x2F, 0x00, 0x10 },	/* 350   700      6.0   */
524379bc100SJani Nikula 	{ 0x6, 0x7F, 0x2B, 0x00, 0x14 },	/* 350   900      8.2   */
525379bc100SJani Nikula 	{ 0xA, 0x4C, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
526379bc100SJani Nikula 	{ 0xC, 0x73, 0x34, 0x00, 0x0B },	/* 500   700      2.9   */
527379bc100SJani Nikula 	{ 0x6, 0x7F, 0x2F, 0x00, 0x10 },	/* 500   900      5.1   */
528379bc100SJani Nikula 	{ 0xC, 0x6C, 0x3C, 0x00, 0x03 },	/* 650   700      0.6   */
529379bc100SJani Nikula 	{ 0x6, 0x7F, 0x35, 0x00, 0x0A },	/* 600   900      3.5   */
530379bc100SJani Nikula 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
531379bc100SJani Nikula };
532379bc100SJani Nikula 
533379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr2[] = {
534379bc100SJani Nikula 						/* NT mV Trans mV db    */
535379bc100SJani Nikula 	{ 0x0, 0x7F, 0x3F, 0x00, 0x00 },	/* 200   200      0.0   */
536379bc100SJani Nikula 	{ 0x8, 0x7F, 0x38, 0x00, 0x07 },	/* 200   250      1.9   */
537379bc100SJani Nikula 	{ 0x1, 0x7F, 0x33, 0x00, 0x0C },	/* 200   300      3.5   */
538379bc100SJani Nikula 	{ 0x9, 0x7F, 0x31, 0x00, 0x0E },	/* 200   350      4.9   */
539379bc100SJani Nikula 	{ 0x8, 0x7F, 0x3F, 0x00, 0x00 },	/* 250   250      0.0   */
540379bc100SJani Nikula 	{ 0x1, 0x7F, 0x38, 0x00, 0x07 },	/* 250   300      1.6   */
541379bc100SJani Nikula 	{ 0x9, 0x7F, 0x35, 0x00, 0x0A },	/* 250   350      2.9   */
542379bc100SJani Nikula 	{ 0x1, 0x7F, 0x3F, 0x00, 0x00 },	/* 300   300      0.0   */
543379bc100SJani Nikula 	{ 0x9, 0x7F, 0x38, 0x00, 0x07 },	/* 300   350      1.3   */
544379bc100SJani Nikula 	{ 0x9, 0x7F, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
545379bc100SJani Nikula };
546379bc100SJani Nikula 
547379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr3[] = {
548379bc100SJani Nikula 						/* NT mV Trans mV db    */
549379bc100SJani Nikula 	{ 0xA, 0x35, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
550379bc100SJani Nikula 	{ 0xA, 0x4F, 0x37, 0x00, 0x08 },	/* 350   500      3.1   */
551379bc100SJani Nikula 	{ 0xC, 0x71, 0x2F, 0x00, 0x10 },	/* 350   700      6.0   */
552379bc100SJani Nikula 	{ 0x6, 0x7F, 0x2B, 0x00, 0x14 },	/* 350   900      8.2   */
553379bc100SJani Nikula 	{ 0xA, 0x4C, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
554379bc100SJani Nikula 	{ 0xC, 0x73, 0x34, 0x00, 0x0B },	/* 500   700      2.9   */
555379bc100SJani Nikula 	{ 0x6, 0x7F, 0x2F, 0x00, 0x10 },	/* 500   900      5.1   */
556379bc100SJani Nikula 	{ 0xC, 0x6C, 0x3C, 0x00, 0x03 },	/* 650   700      0.6   */
557379bc100SJani Nikula 	{ 0x6, 0x7F, 0x35, 0x00, 0x0A },	/* 600   900      3.5   */
558379bc100SJani Nikula 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
559379bc100SJani Nikula };
560379bc100SJani Nikula 
561379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_hdmi[] = {
562379bc100SJani Nikula 						/* NT mV Trans mV db    */
563379bc100SJani Nikula 	{ 0xA, 0x60, 0x3F, 0x00, 0x00 },	/* 450   450      0.0   */
564379bc100SJani Nikula 	{ 0xB, 0x73, 0x36, 0x00, 0x09 },	/* 450   650      3.2   */
565379bc100SJani Nikula 	{ 0x6, 0x7F, 0x31, 0x00, 0x0E },	/* 450   850      5.5   */
566379bc100SJani Nikula 	{ 0xB, 0x73, 0x3F, 0x00, 0x00 },	/* 650   650      0.0   ALS */
567379bc100SJani Nikula 	{ 0x6, 0x7F, 0x37, 0x00, 0x08 },	/* 650   850      2.3   */
568379bc100SJani Nikula 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 850   850      0.0   */
569379bc100SJani Nikula 	{ 0x6, 0x7F, 0x35, 0x00, 0x0A },	/* 600   850      3.0   */
570379bc100SJani Nikula };
571379bc100SJani Nikula 
572a2ae2010SJosé Roberto de Souza static const struct cnl_ddi_buf_trans ehl_combo_phy_ddi_translations_dp[] = {
573b42d5a67SJosé Roberto de Souza 						/* NT mV Trans mV db    */
574b42d5a67SJosé Roberto de Souza 	{ 0xA, 0x33, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
575b42d5a67SJosé Roberto de Souza 	{ 0xA, 0x47, 0x36, 0x00, 0x09 },	/* 350   500      3.1   */
5763baea269SJosé Roberto de Souza 	{ 0xC, 0x64, 0x34, 0x00, 0x0B },	/* 350   700      6.0   */
5773baea269SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x30, 0x00, 0x0F },	/* 350   900      8.2   */
578b42d5a67SJosé Roberto de Souza 	{ 0xA, 0x46, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
5793baea269SJosé Roberto de Souza 	{ 0xC, 0x64, 0x38, 0x00, 0x07 },	/* 500   700      2.9   */
5803baea269SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x32, 0x00, 0x0D },	/* 500   900      5.1   */
581b42d5a67SJosé Roberto de Souza 	{ 0xC, 0x61, 0x3F, 0x00, 0x00 },	/* 650   700      0.6   */
5823baea269SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x38, 0x00, 0x07 },	/* 600   900      3.5   */
583b42d5a67SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
584b42d5a67SJosé Roberto de Souza };
585b42d5a67SJosé Roberto de Souza 
5861ba1014dSTejas Upadhyay static const struct cnl_ddi_buf_trans jsl_combo_phy_ddi_translations_edp_hbr[] = {
5871ba1014dSTejas Upadhyay 						/* NT mV Trans mV db    */
5881ba1014dSTejas Upadhyay 	{ 0x8, 0x7F, 0x3F, 0x00, 0x00 },        /* 200   200      0.0   */
5891ba1014dSTejas Upadhyay 	{ 0x8, 0x7F, 0x38, 0x00, 0x07 },        /* 200   250      1.9   */
5901ba1014dSTejas Upadhyay 	{ 0x1, 0x7F, 0x33, 0x00, 0x0C },        /* 200   300      3.5   */
5911ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x36, 0x00, 0x09 },        /* 200   350      4.9   */
5921ba1014dSTejas Upadhyay 	{ 0x8, 0x7F, 0x3F, 0x00, 0x00 },        /* 250   250      0.0   */
5931ba1014dSTejas Upadhyay 	{ 0x1, 0x7F, 0x38, 0x00, 0x07 },        /* 250   300      1.6   */
5941ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x35, 0x00, 0x0A },        /* 250   350      2.9   */
5951ba1014dSTejas Upadhyay 	{ 0x1, 0x7F, 0x3F, 0x00, 0x00 },        /* 300   300      0.0   */
5961ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x38, 0x00, 0x07 },        /* 300   350      1.3   */
5971ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x3F, 0x00, 0x00 },        /* 350   350      0.0   */
5981ba1014dSTejas Upadhyay };
5991ba1014dSTejas Upadhyay 
6001ba1014dSTejas Upadhyay static const struct cnl_ddi_buf_trans jsl_combo_phy_ddi_translations_edp_hbr2[] = {
6011ba1014dSTejas Upadhyay 						/* NT mV Trans mV db    */
6021ba1014dSTejas Upadhyay 	{ 0x8, 0x7F, 0x3F, 0x00, 0x00 },        /* 200   200      0.0   */
6031ba1014dSTejas Upadhyay 	{ 0x8, 0x7F, 0x3F, 0x00, 0x00 },        /* 200   250      1.9   */
6041ba1014dSTejas Upadhyay 	{ 0x1, 0x7F, 0x3D, 0x00, 0x02 },        /* 200   300      3.5   */
6051ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x38, 0x00, 0x07 },        /* 200   350      4.9   */
6061ba1014dSTejas Upadhyay 	{ 0x8, 0x7F, 0x3F, 0x00, 0x00 },        /* 250   250      0.0   */
6071ba1014dSTejas Upadhyay 	{ 0x1, 0x7F, 0x3F, 0x00, 0x00 },        /* 250   300      1.6   */
6081ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x3A, 0x00, 0x05 },        /* 250   350      2.9   */
6091ba1014dSTejas Upadhyay 	{ 0x1, 0x7F, 0x3F, 0x00, 0x00 },        /* 300   300      0.0   */
6101ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x38, 0x00, 0x07 },        /* 300   350      1.3   */
6111ba1014dSTejas Upadhyay 	{ 0xA, 0x35, 0x3F, 0x00, 0x00 },        /* 350   350      0.0   */
6121ba1014dSTejas Upadhyay };
6131ba1014dSTejas Upadhyay 
614cce73665SMatt Roper static const struct cnl_ddi_buf_trans dg1_combo_phy_ddi_translations_dp_rbr_hbr[] = {
615cce73665SMatt Roper 						/* NT mV Trans mV db    */
616cce73665SMatt Roper 	{ 0xA, 0x32, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
617cce73665SMatt Roper 	{ 0xA, 0x48, 0x35, 0x00, 0x0A },	/* 350   500      3.1   */
618cce73665SMatt Roper 	{ 0xC, 0x63, 0x2F, 0x00, 0x10 },	/* 350   700      6.0   */
619cce73665SMatt Roper 	{ 0x6, 0x7F, 0x2C, 0x00, 0x13 },	/* 350   900      8.2   */
620cce73665SMatt Roper 	{ 0xA, 0x43, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
621cce73665SMatt Roper 	{ 0xC, 0x60, 0x36, 0x00, 0x09 },	/* 500   700      2.9   */
622cce73665SMatt Roper 	{ 0x6, 0x7F, 0x30, 0x00, 0x0F },	/* 500   900      5.1   */
623cce73665SMatt Roper 	{ 0xC, 0x60, 0x3F, 0x00, 0x00 },	/* 650   700      0.6   */
624cce73665SMatt Roper 	{ 0x6, 0x7F, 0x37, 0x00, 0x08 },	/* 600   900      3.5   */
625cce73665SMatt Roper 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
626cce73665SMatt Roper };
627cce73665SMatt Roper 
628cce73665SMatt Roper static const struct cnl_ddi_buf_trans dg1_combo_phy_ddi_translations_dp_hbr2_hbr3[] = {
629cce73665SMatt Roper 						/* NT mV Trans mV db    */
630cce73665SMatt Roper 	{ 0xA, 0x32, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
631cce73665SMatt Roper 	{ 0xA, 0x48, 0x35, 0x00, 0x0A },	/* 350   500      3.1   */
632cce73665SMatt Roper 	{ 0xC, 0x63, 0x2F, 0x00, 0x10 },	/* 350   700      6.0   */
633cce73665SMatt Roper 	{ 0x6, 0x7F, 0x2C, 0x00, 0x13 },	/* 350   900      8.2   */
634cce73665SMatt Roper 	{ 0xA, 0x43, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
635cce73665SMatt Roper 	{ 0xC, 0x60, 0x36, 0x00, 0x09 },	/* 500   700      2.9   */
636cce73665SMatt Roper 	{ 0x6, 0x7F, 0x30, 0x00, 0x0F },	/* 500   900      5.1   */
637cce73665SMatt Roper 	{ 0xC, 0x58, 0x3F, 0x00, 0x00 },	/* 650   700      0.6   */
638cce73665SMatt Roper 	{ 0x6, 0x7F, 0x35, 0x00, 0x0A },	/* 600   900      3.5   */
639cce73665SMatt Roper 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
640cce73665SMatt Roper };
641cce73665SMatt Roper 
642379bc100SJani Nikula struct icl_mg_phy_ddi_buf_trans {
643379bc100SJani Nikula 	u32 cri_txdeemph_override_11_6;
6449f7ffa29SJosé Roberto de Souza 	u32 cri_txdeemph_override_5_0;
645379bc100SJani Nikula 	u32 cri_txdeemph_override_17_12;
646379bc100SJani Nikula };
647379bc100SJani Nikula 
6489f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations_rbr_hbr[] = {
649379bc100SJani Nikula 				/* Voltage swing  pre-emphasis */
6509f7ffa29SJosé Roberto de Souza 	{ 0x18, 0x00, 0x00 },	/* 0              0   */
6519f7ffa29SJosé Roberto de Souza 	{ 0x1D, 0x00, 0x05 },	/* 0              1   */
6529f7ffa29SJosé Roberto de Souza 	{ 0x24, 0x00, 0x0C },	/* 0              2   */
6539f7ffa29SJosé Roberto de Souza 	{ 0x2B, 0x00, 0x14 },	/* 0              3   */
6549f7ffa29SJosé Roberto de Souza 	{ 0x21, 0x00, 0x00 },	/* 1              0   */
6559f7ffa29SJosé Roberto de Souza 	{ 0x2B, 0x00, 0x08 },	/* 1              1   */
6569f7ffa29SJosé Roberto de Souza 	{ 0x30, 0x00, 0x0F },	/* 1              2   */
6579f7ffa29SJosé Roberto de Souza 	{ 0x31, 0x00, 0x03 },	/* 2              0   */
6589f7ffa29SJosé Roberto de Souza 	{ 0x34, 0x00, 0x0B },	/* 2              1   */
6599f7ffa29SJosé Roberto de Souza 	{ 0x3F, 0x00, 0x00 },	/* 3              0   */
6609f7ffa29SJosé Roberto de Souza };
6619f7ffa29SJosé Roberto de Souza 
6629f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations_hbr2_hbr3[] = {
6639f7ffa29SJosé Roberto de Souza 				/* Voltage swing  pre-emphasis */
6649f7ffa29SJosé Roberto de Souza 	{ 0x18, 0x00, 0x00 },	/* 0              0   */
6659f7ffa29SJosé Roberto de Souza 	{ 0x1D, 0x00, 0x05 },	/* 0              1   */
6669f7ffa29SJosé Roberto de Souza 	{ 0x24, 0x00, 0x0C },	/* 0              2   */
6679f7ffa29SJosé Roberto de Souza 	{ 0x2B, 0x00, 0x14 },	/* 0              3   */
6689f7ffa29SJosé Roberto de Souza 	{ 0x26, 0x00, 0x00 },	/* 1              0   */
6699f7ffa29SJosé Roberto de Souza 	{ 0x2C, 0x00, 0x07 },	/* 1              1   */
6709f7ffa29SJosé Roberto de Souza 	{ 0x33, 0x00, 0x0C },	/* 1              2   */
6719f7ffa29SJosé Roberto de Souza 	{ 0x2E, 0x00, 0x00 },	/* 2              0   */
6729f7ffa29SJosé Roberto de Souza 	{ 0x36, 0x00, 0x09 },	/* 2              1   */
6739f7ffa29SJosé Roberto de Souza 	{ 0x3F, 0x00, 0x00 },	/* 3              0   */
6749f7ffa29SJosé Roberto de Souza };
6759f7ffa29SJosé Roberto de Souza 
6769f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations_hdmi[] = {
6779f7ffa29SJosé Roberto de Souza 				/* HDMI Preset	VS	Pre-emph */
6789f7ffa29SJosé Roberto de Souza 	{ 0x1A, 0x0, 0x0 },	/* 1		400mV	0dB */
6799f7ffa29SJosé Roberto de Souza 	{ 0x20, 0x0, 0x0 },	/* 2		500mV	0dB */
6809f7ffa29SJosé Roberto de Souza 	{ 0x29, 0x0, 0x0 },	/* 3		650mV	0dB */
6819f7ffa29SJosé Roberto de Souza 	{ 0x32, 0x0, 0x0 },	/* 4		800mV	0dB */
6829f7ffa29SJosé Roberto de Souza 	{ 0x3F, 0x0, 0x0 },	/* 5		1000mV	0dB */
6839f7ffa29SJosé Roberto de Souza 	{ 0x3A, 0x0, 0x5 },	/* 6		Full	-1.5 dB */
6849f7ffa29SJosé Roberto de Souza 	{ 0x39, 0x0, 0x6 },	/* 7		Full	-1.8 dB */
6859f7ffa29SJosé Roberto de Souza 	{ 0x38, 0x0, 0x7 },	/* 8		Full	-2 dB */
6869f7ffa29SJosé Roberto de Souza 	{ 0x37, 0x0, 0x8 },	/* 9		Full	-2.5 dB */
6879f7ffa29SJosé Roberto de Souza 	{ 0x36, 0x0, 0x9 },	/* 10		Full	-3 dB */
688379bc100SJani Nikula };
689379bc100SJani Nikula 
690978c3e53SClinton A Taylor struct tgl_dkl_phy_ddi_buf_trans {
691978c3e53SClinton A Taylor 	u32 dkl_vswing_control;
692978c3e53SClinton A Taylor 	u32 dkl_preshoot_control;
693978c3e53SClinton A Taylor 	u32 dkl_de_emphasis_control;
694978c3e53SClinton A Taylor };
695978c3e53SClinton A Taylor 
696362bfb99SMatt Roper static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_dp_ddi_trans[] = {
697978c3e53SClinton A Taylor 				/* VS	pre-emp	Non-trans mV	Pre-emph dB */
698978c3e53SClinton A Taylor 	{ 0x7, 0x0, 0x00 },	/* 0	0	400mV		0 dB */
699250a353cSJosé Roberto de Souza 	{ 0x5, 0x0, 0x05 },	/* 0	1	400mV		3.5 dB */
700250a353cSJosé Roberto de Souza 	{ 0x2, 0x0, 0x0B },	/* 0	2	400mV		6 dB */
7019fa67699SJosé Roberto de Souza 	{ 0x0, 0x0, 0x18 },	/* 0	3	400mV		9.5 dB */
7029fa67699SJosé Roberto de Souza 	{ 0x5, 0x0, 0x00 },	/* 1	0	600mV		0 dB */
7039fa67699SJosé Roberto de Souza 	{ 0x2, 0x0, 0x08 },	/* 1	1	600mV		3.5 dB */
7049fa67699SJosé Roberto de Souza 	{ 0x0, 0x0, 0x14 },	/* 1	2	600mV		6 dB */
7059fa67699SJosé Roberto de Souza 	{ 0x2, 0x0, 0x00 },	/* 2	0	800mV		0 dB */
7069fa67699SJosé Roberto de Souza 	{ 0x0, 0x0, 0x0B },	/* 2	1	800mV		3.5 dB */
7079fa67699SJosé Roberto de Souza 	{ 0x0, 0x0, 0x00 },	/* 3	0	1200mV		0 dB HDMI default */
7089fa67699SJosé Roberto de Souza };
7099fa67699SJosé Roberto de Souza 
7109fa67699SJosé Roberto de Souza static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_dp_ddi_trans_hbr2[] = {
7119fa67699SJosé Roberto de Souza 				/* VS	pre-emp	Non-trans mV	Pre-emph dB */
7129fa67699SJosé Roberto de Souza 	{ 0x7, 0x0, 0x00 },	/* 0	0	400mV		0 dB */
7139fa67699SJosé Roberto de Souza 	{ 0x5, 0x0, 0x05 },	/* 0	1	400mV		3.5 dB */
7149fa67699SJosé Roberto de Souza 	{ 0x2, 0x0, 0x0B },	/* 0	2	400mV		6 dB */
715978c3e53SClinton A Taylor 	{ 0x0, 0x0, 0x19 },	/* 0	3	400mV		9.5 dB */
716978c3e53SClinton A Taylor 	{ 0x5, 0x0, 0x00 },	/* 1	0	600mV		0 dB */
717250a353cSJosé Roberto de Souza 	{ 0x2, 0x0, 0x08 },	/* 1	1	600mV		3.5 dB */
718978c3e53SClinton A Taylor 	{ 0x0, 0x0, 0x14 },	/* 1	2	600mV		6 dB */
719978c3e53SClinton A Taylor 	{ 0x2, 0x0, 0x00 },	/* 2	0	800mV		0 dB */
720978c3e53SClinton A Taylor 	{ 0x0, 0x0, 0x0B },	/* 2	1	800mV		3.5 dB */
721978c3e53SClinton A Taylor 	{ 0x0, 0x0, 0x00 },	/* 3	0	1200mV		0 dB HDMI default */
722978c3e53SClinton A Taylor };
723978c3e53SClinton A Taylor 
724362bfb99SMatt Roper static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_hdmi_ddi_trans[] = {
725362bfb99SMatt Roper 				/* HDMI Preset	VS	Pre-emph */
726362bfb99SMatt Roper 	{ 0x7, 0x0, 0x0 },	/* 1		400mV	0dB */
727362bfb99SMatt Roper 	{ 0x6, 0x0, 0x0 },	/* 2		500mV	0dB */
728362bfb99SMatt Roper 	{ 0x4, 0x0, 0x0 },	/* 3		650mV	0dB */
729362bfb99SMatt Roper 	{ 0x2, 0x0, 0x0 },	/* 4		800mV	0dB */
730362bfb99SMatt Roper 	{ 0x0, 0x0, 0x0 },	/* 5		1000mV	0dB */
731362bfb99SMatt Roper 	{ 0x0, 0x0, 0x5 },	/* 6		Full	-1.5 dB */
732362bfb99SMatt Roper 	{ 0x0, 0x0, 0x6 },	/* 7		Full	-1.8 dB */
733362bfb99SMatt Roper 	{ 0x0, 0x0, 0x7 },	/* 8		Full	-2 dB */
734362bfb99SMatt Roper 	{ 0x0, 0x0, 0x8 },	/* 9		Full	-2.5 dB */
735362bfb99SMatt Roper 	{ 0x0, 0x0, 0xA },	/* 10		Full	-3 dB */
736362bfb99SMatt Roper };
737362bfb99SMatt Roper 
738bd3cf6f7SJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_dp_hbr[] = {
739bd3cf6f7SJosé Roberto de Souza 						/* NT mV Trans mV db    */
740bd3cf6f7SJosé Roberto de Souza 	{ 0xA, 0x32, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
741bd3cf6f7SJosé Roberto de Souza 	{ 0xA, 0x4F, 0x37, 0x00, 0x08 },	/* 350   500      3.1   */
742bd3cf6f7SJosé Roberto de Souza 	{ 0xC, 0x71, 0x2F, 0x00, 0x10 },	/* 350   700      6.0   */
743bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7D, 0x2B, 0x00, 0x14 },	/* 350   900      8.2   */
744bd3cf6f7SJosé Roberto de Souza 	{ 0xA, 0x4C, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
745bd3cf6f7SJosé Roberto de Souza 	{ 0xC, 0x73, 0x34, 0x00, 0x0B },	/* 500   700      2.9   */
746bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x2F, 0x00, 0x10 },	/* 500   900      5.1   */
747bd3cf6f7SJosé Roberto de Souza 	{ 0xC, 0x6C, 0x3C, 0x00, 0x03 },	/* 650   700      0.6   */
748bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x35, 0x00, 0x0A },	/* 600   900      3.5   */
749bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
750bd3cf6f7SJosé Roberto de Souza };
751bd3cf6f7SJosé Roberto de Souza 
752bd3cf6f7SJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_dp_hbr2[] = {
753bd3cf6f7SJosé Roberto de Souza 						/* NT mV Trans mV db    */
754bd3cf6f7SJosé Roberto de Souza 	{ 0xA, 0x35, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
755bd3cf6f7SJosé Roberto de Souza 	{ 0xA, 0x4F, 0x37, 0x00, 0x08 },	/* 350   500      3.1   */
756bd3cf6f7SJosé Roberto de Souza 	{ 0xC, 0x63, 0x2F, 0x00, 0x10 },	/* 350   700      6.0   */
757bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x2B, 0x00, 0x14 },	/* 350   900      8.2   */
758bd3cf6f7SJosé Roberto de Souza 	{ 0xA, 0x47, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
759bd3cf6f7SJosé Roberto de Souza 	{ 0xC, 0x63, 0x34, 0x00, 0x0B },	/* 500   700      2.9   */
760bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x2F, 0x00, 0x10 },	/* 500   900      5.1   */
761bd3cf6f7SJosé Roberto de Souza 	{ 0xC, 0x61, 0x3C, 0x00, 0x03 },	/* 650   700      0.6   */
762bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7B, 0x35, 0x00, 0x0A },	/* 600   900      3.5   */
763bd3cf6f7SJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
764bd3cf6f7SJosé Roberto de Souza };
765bd3cf6f7SJosé Roberto de Souza 
76604dfb1acSJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_uy_combo_phy_ddi_translations_dp_hbr2[] = {
76704dfb1acSJosé Roberto de Souza 						/* NT mV Trans mV db    */
76804dfb1acSJosé Roberto de Souza 	{ 0xA, 0x35, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
76904dfb1acSJosé Roberto de Souza 	{ 0xA, 0x4F, 0x36, 0x00, 0x09 },	/* 350   500      3.1   */
77004dfb1acSJosé Roberto de Souza 	{ 0xC, 0x60, 0x32, 0x00, 0x0D },	/* 350   700      6.0   */
77104dfb1acSJosé Roberto de Souza 	{ 0xC, 0x7F, 0x2D, 0x00, 0x12 },	/* 350   900      8.2   */
77204dfb1acSJosé Roberto de Souza 	{ 0xC, 0x47, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
77304dfb1acSJosé Roberto de Souza 	{ 0xC, 0x6F, 0x36, 0x00, 0x09 },	/* 500   700      2.9   */
77404dfb1acSJosé Roberto de Souza 	{ 0x6, 0x7D, 0x32, 0x00, 0x0D },	/* 500   900      5.1   */
77504dfb1acSJosé Roberto de Souza 	{ 0x6, 0x60, 0x3C, 0x00, 0x03 },	/* 650   700      0.6   */
77604dfb1acSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x34, 0x00, 0x0B },	/* 600   900      3.5   */
77704dfb1acSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
77804dfb1acSJosé Roberto de Souza };
77904dfb1acSJosé Roberto de Souza 
78081619f4aSJosé Roberto de Souza /*
78181619f4aSJosé Roberto de Souza  * Cloned the HOBL entry to comply with the voltage and pre-emphasis entries
78281619f4aSJosé Roberto de Souza  * that DisplayPort specification requires
78381619f4aSJosé Roberto de Souza  */
78481619f4aSJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_edp_hbr2_hobl[] = {
78581619f4aSJosé Roberto de Souza 						/* VS	pre-emp	*/
78681619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 0	0	*/
78781619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 0	1	*/
78881619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 0	2	*/
78981619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 0	3	*/
79081619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 1	0	*/
79181619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 1	1	*/
79281619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 1	2	*/
79381619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 2	0	*/
79481619f4aSJosé Roberto de Souza 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 2	1	*/
79581619f4aSJosé Roberto de Souza };
79681619f4aSJosé Roberto de Souza 
797ec9c2e01SMatt Roper static const struct cnl_ddi_buf_trans rkl_combo_phy_ddi_translations_dp_hbr[] = {
798ec9c2e01SMatt Roper 						/* NT mV Trans mV db    */
799ec9c2e01SMatt Roper 	{ 0xA, 0x2F, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
800ec9c2e01SMatt Roper 	{ 0xA, 0x4F, 0x37, 0x00, 0x08 },	/* 350   500      3.1   */
801ec9c2e01SMatt Roper 	{ 0xC, 0x63, 0x2F, 0x00, 0x10 },	/* 350   700      6.0   */
802ec9c2e01SMatt Roper 	{ 0x6, 0x7D, 0x2A, 0x00, 0x15 },	/* 350   900      8.2   */
803ec9c2e01SMatt Roper 	{ 0xA, 0x4C, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
804ec9c2e01SMatt Roper 	{ 0xC, 0x73, 0x34, 0x00, 0x0B },	/* 500   700      2.9   */
805ec9c2e01SMatt Roper 	{ 0x6, 0x7F, 0x2F, 0x00, 0x10 },	/* 500   900      5.1   */
806ec9c2e01SMatt Roper 	{ 0xC, 0x6E, 0x3E, 0x00, 0x01 },	/* 650   700      0.6   */
807ec9c2e01SMatt Roper 	{ 0x6, 0x7F, 0x35, 0x00, 0x0A },	/* 600   900      3.5   */
808ec9c2e01SMatt Roper 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
809ec9c2e01SMatt Roper };
810ec9c2e01SMatt Roper 
811ec9c2e01SMatt Roper static const struct cnl_ddi_buf_trans rkl_combo_phy_ddi_translations_dp_hbr2_hbr3[] = {
812ec9c2e01SMatt Roper 						/* NT mV Trans mV db    */
813ec9c2e01SMatt Roper 	{ 0xA, 0x35, 0x3F, 0x00, 0x00 },	/* 350   350      0.0   */
814ec9c2e01SMatt Roper 	{ 0xA, 0x50, 0x38, 0x00, 0x07 },	/* 350   500      3.1   */
815ec9c2e01SMatt Roper 	{ 0xC, 0x61, 0x33, 0x00, 0x0C },	/* 350   700      6.0   */
816ec9c2e01SMatt Roper 	{ 0x6, 0x7F, 0x2E, 0x00, 0x11 },	/* 350   900      8.2   */
817ec9c2e01SMatt Roper 	{ 0xA, 0x47, 0x3F, 0x00, 0x00 },	/* 500   500      0.0   */
818ec9c2e01SMatt Roper 	{ 0xC, 0x5F, 0x38, 0x00, 0x07 },	/* 500   700      2.9   */
819ec9c2e01SMatt Roper 	{ 0x6, 0x7F, 0x2F, 0x00, 0x10 },	/* 500   900      5.1   */
820ec9c2e01SMatt Roper 	{ 0xC, 0x5F, 0x3F, 0x00, 0x00 },	/* 650   700      0.6   */
821ec9c2e01SMatt Roper 	{ 0x6, 0x7E, 0x36, 0x00, 0x09 },	/* 600   900      3.5   */
822ec9c2e01SMatt Roper 	{ 0x6, 0x7F, 0x3F, 0x00, 0x00 },	/* 900   900      0.0   */
823ec9c2e01SMatt Roper };
824ec9c2e01SMatt Roper 
82581619f4aSJosé Roberto de Souza static bool is_hobl_buf_trans(const struct cnl_ddi_buf_trans *table)
82681619f4aSJosé Roberto de Souza {
82781619f4aSJosé Roberto de Souza 	return table == tgl_combo_phy_ddi_translations_edp_hbr2_hobl;
82881619f4aSJosé Roberto de Souza }
82981619f4aSJosé Roberto de Souza 
830379bc100SJani Nikula static const struct ddi_buf_trans *
831a8143150SJosé Roberto de Souza bdw_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries)
832379bc100SJani Nikula {
833a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
834a8143150SJosé Roberto de Souza 
835379bc100SJani Nikula 	if (dev_priv->vbt.edp.low_vswing) {
836379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
837379bc100SJani Nikula 		return bdw_ddi_translations_edp;
838379bc100SJani Nikula 	} else {
839379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
840379bc100SJani Nikula 		return bdw_ddi_translations_dp;
841379bc100SJani Nikula 	}
842379bc100SJani Nikula }
843379bc100SJani Nikula 
844379bc100SJani Nikula static const struct ddi_buf_trans *
845a8143150SJosé Roberto de Souza skl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries)
846379bc100SJani Nikula {
847a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
848a8143150SJosé Roberto de Souza 
849379bc100SJani Nikula 	if (IS_SKL_ULX(dev_priv)) {
850379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
851379bc100SJani Nikula 		return skl_y_ddi_translations_dp;
852379bc100SJani Nikula 	} else if (IS_SKL_ULT(dev_priv)) {
853379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
854379bc100SJani Nikula 		return skl_u_ddi_translations_dp;
855379bc100SJani Nikula 	} else {
856379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
857379bc100SJani Nikula 		return skl_ddi_translations_dp;
858379bc100SJani Nikula 	}
859379bc100SJani Nikula }
860379bc100SJani Nikula 
861379bc100SJani Nikula static const struct ddi_buf_trans *
862a8143150SJosé Roberto de Souza kbl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries)
863379bc100SJani Nikula {
864a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
865a8143150SJosé Roberto de Souza 
8665f4ae270SChris Wilson 	if (IS_KBL_ULX(dev_priv) ||
8675f4ae270SChris Wilson 	    IS_CFL_ULX(dev_priv) ||
8685f4ae270SChris Wilson 	    IS_CML_ULX(dev_priv)) {
869379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp);
870379bc100SJani Nikula 		return kbl_y_ddi_translations_dp;
8715f4ae270SChris Wilson 	} else if (IS_KBL_ULT(dev_priv) ||
8725f4ae270SChris Wilson 		   IS_CFL_ULT(dev_priv) ||
8735f4ae270SChris Wilson 		   IS_CML_ULT(dev_priv)) {
874379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
875379bc100SJani Nikula 		return kbl_u_ddi_translations_dp;
876379bc100SJani Nikula 	} else {
877379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
878379bc100SJani Nikula 		return kbl_ddi_translations_dp;
879379bc100SJani Nikula 	}
880379bc100SJani Nikula }
881379bc100SJani Nikula 
882379bc100SJani Nikula static const struct ddi_buf_trans *
883a8143150SJosé Roberto de Souza skl_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries)
884379bc100SJani Nikula {
885a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
886a8143150SJosé Roberto de Souza 
887379bc100SJani Nikula 	if (dev_priv->vbt.edp.low_vswing) {
8885f4ae270SChris Wilson 		if (IS_SKL_ULX(dev_priv) ||
8895f4ae270SChris Wilson 		    IS_KBL_ULX(dev_priv) ||
8905f4ae270SChris Wilson 		    IS_CFL_ULX(dev_priv) ||
8915f4ae270SChris Wilson 		    IS_CML_ULX(dev_priv)) {
892379bc100SJani Nikula 			*n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
893379bc100SJani Nikula 			return skl_y_ddi_translations_edp;
8945f4ae270SChris Wilson 		} else if (IS_SKL_ULT(dev_priv) ||
8955f4ae270SChris Wilson 			   IS_KBL_ULT(dev_priv) ||
8965f4ae270SChris Wilson 			   IS_CFL_ULT(dev_priv) ||
8975f4ae270SChris Wilson 			   IS_CML_ULT(dev_priv)) {
898379bc100SJani Nikula 			*n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
899379bc100SJani Nikula 			return skl_u_ddi_translations_edp;
900379bc100SJani Nikula 		} else {
901379bc100SJani Nikula 			*n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
902379bc100SJani Nikula 			return skl_ddi_translations_edp;
903379bc100SJani Nikula 		}
904379bc100SJani Nikula 	}
905379bc100SJani Nikula 
9065f4ae270SChris Wilson 	if (IS_KABYLAKE(dev_priv) ||
9075f4ae270SChris Wilson 	    IS_COFFEELAKE(dev_priv) ||
9085f4ae270SChris Wilson 	    IS_COMETLAKE(dev_priv))
909a8143150SJosé Roberto de Souza 		return kbl_get_buf_trans_dp(encoder, n_entries);
910379bc100SJani Nikula 	else
911a8143150SJosé Roberto de Souza 		return skl_get_buf_trans_dp(encoder, n_entries);
912379bc100SJani Nikula }
913379bc100SJani Nikula 
914379bc100SJani Nikula static const struct ddi_buf_trans *
915379bc100SJani Nikula skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
916379bc100SJani Nikula {
9175f4ae270SChris Wilson 	if (IS_SKL_ULX(dev_priv) ||
9185f4ae270SChris Wilson 	    IS_KBL_ULX(dev_priv) ||
9195f4ae270SChris Wilson 	    IS_CFL_ULX(dev_priv) ||
9205f4ae270SChris Wilson 	    IS_CML_ULX(dev_priv)) {
921379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
922379bc100SJani Nikula 		return skl_y_ddi_translations_hdmi;
923379bc100SJani Nikula 	} else {
924379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
925379bc100SJani Nikula 		return skl_ddi_translations_hdmi;
926379bc100SJani Nikula 	}
927379bc100SJani Nikula }
928379bc100SJani Nikula 
929379bc100SJani Nikula static int skl_buf_trans_num_entries(enum port port, int n_entries)
930379bc100SJani Nikula {
931379bc100SJani Nikula 	/* Only DDIA and DDIE can select the 10th register with DP */
932379bc100SJani Nikula 	if (port == PORT_A || port == PORT_E)
933379bc100SJani Nikula 		return min(n_entries, 10);
934379bc100SJani Nikula 	else
935379bc100SJani Nikula 		return min(n_entries, 9);
936379bc100SJani Nikula }
937379bc100SJani Nikula 
938379bc100SJani Nikula static const struct ddi_buf_trans *
939f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries)
940379bc100SJani Nikula {
941a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
942a8143150SJosé Roberto de Souza 
9435f4ae270SChris Wilson 	if (IS_KABYLAKE(dev_priv) ||
9445f4ae270SChris Wilson 	    IS_COFFEELAKE(dev_priv) ||
9455f4ae270SChris Wilson 	    IS_COMETLAKE(dev_priv)) {
946379bc100SJani Nikula 		const struct ddi_buf_trans *ddi_translations =
947a8143150SJosé Roberto de Souza 			kbl_get_buf_trans_dp(encoder, n_entries);
948f0e86e05SJosé Roberto de Souza 		*n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries);
949379bc100SJani Nikula 		return ddi_translations;
950379bc100SJani Nikula 	} else if (IS_SKYLAKE(dev_priv)) {
951379bc100SJani Nikula 		const struct ddi_buf_trans *ddi_translations =
952a8143150SJosé Roberto de Souza 			skl_get_buf_trans_dp(encoder, n_entries);
953f0e86e05SJosé Roberto de Souza 		*n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries);
954379bc100SJani Nikula 		return ddi_translations;
955379bc100SJani Nikula 	} else if (IS_BROADWELL(dev_priv)) {
956379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
957379bc100SJani Nikula 		return  bdw_ddi_translations_dp;
958379bc100SJani Nikula 	} else if (IS_HASWELL(dev_priv)) {
959379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
960379bc100SJani Nikula 		return hsw_ddi_translations_dp;
961379bc100SJani Nikula 	}
962379bc100SJani Nikula 
963379bc100SJani Nikula 	*n_entries = 0;
964379bc100SJani Nikula 	return NULL;
965379bc100SJani Nikula }
966379bc100SJani Nikula 
967379bc100SJani Nikula static const struct ddi_buf_trans *
968f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries)
969379bc100SJani Nikula {
970a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
971a8143150SJosé Roberto de Souza 
972379bc100SJani Nikula 	if (IS_GEN9_BC(dev_priv)) {
973379bc100SJani Nikula 		const struct ddi_buf_trans *ddi_translations =
974a8143150SJosé Roberto de Souza 			skl_get_buf_trans_edp(encoder, n_entries);
975f0e86e05SJosé Roberto de Souza 		*n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries);
976379bc100SJani Nikula 		return ddi_translations;
977379bc100SJani Nikula 	} else if (IS_BROADWELL(dev_priv)) {
978a8143150SJosé Roberto de Souza 		return bdw_get_buf_trans_edp(encoder, n_entries);
979379bc100SJani Nikula 	} else if (IS_HASWELL(dev_priv)) {
980379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
981379bc100SJani Nikula 		return hsw_ddi_translations_dp;
982379bc100SJani Nikula 	}
983379bc100SJani Nikula 
984379bc100SJani Nikula 	*n_entries = 0;
985379bc100SJani Nikula 	return NULL;
986379bc100SJani Nikula }
987379bc100SJani Nikula 
988379bc100SJani Nikula static const struct ddi_buf_trans *
989379bc100SJani Nikula intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv,
990379bc100SJani Nikula 			    int *n_entries)
991379bc100SJani Nikula {
992379bc100SJani Nikula 	if (IS_BROADWELL(dev_priv)) {
993379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(bdw_ddi_translations_fdi);
994379bc100SJani Nikula 		return bdw_ddi_translations_fdi;
995379bc100SJani Nikula 	} else if (IS_HASWELL(dev_priv)) {
996379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
997379bc100SJani Nikula 		return hsw_ddi_translations_fdi;
998379bc100SJani Nikula 	}
999379bc100SJani Nikula 
1000379bc100SJani Nikula 	*n_entries = 0;
1001379bc100SJani Nikula 	return NULL;
1002379bc100SJani Nikula }
1003379bc100SJani Nikula 
1004379bc100SJani Nikula static const struct ddi_buf_trans *
1005a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(struct intel_encoder *encoder,
1006379bc100SJani Nikula 			     int *n_entries)
1007379bc100SJani Nikula {
1008a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1009a8143150SJosé Roberto de Souza 
1010379bc100SJani Nikula 	if (IS_GEN9_BC(dev_priv)) {
1011379bc100SJani Nikula 		return skl_get_buf_trans_hdmi(dev_priv, n_entries);
1012379bc100SJani Nikula 	} else if (IS_BROADWELL(dev_priv)) {
1013379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
1014379bc100SJani Nikula 		return bdw_ddi_translations_hdmi;
1015379bc100SJani Nikula 	} else if (IS_HASWELL(dev_priv)) {
1016379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
1017379bc100SJani Nikula 		return hsw_ddi_translations_hdmi;
1018379bc100SJani Nikula 	}
1019379bc100SJani Nikula 
1020379bc100SJani Nikula 	*n_entries = 0;
1021379bc100SJani Nikula 	return NULL;
1022379bc100SJani Nikula }
1023379bc100SJani Nikula 
1024379bc100SJani Nikula static const struct bxt_ddi_buf_trans *
1025a8143150SJosé Roberto de Souza bxt_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries)
1026379bc100SJani Nikula {
1027379bc100SJani Nikula 	*n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
1028379bc100SJani Nikula 	return bxt_ddi_translations_dp;
1029379bc100SJani Nikula }
1030379bc100SJani Nikula 
1031379bc100SJani Nikula static const struct bxt_ddi_buf_trans *
1032a8143150SJosé Roberto de Souza bxt_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries)
1033379bc100SJani Nikula {
1034a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1035a8143150SJosé Roberto de Souza 
1036379bc100SJani Nikula 	if (dev_priv->vbt.edp.low_vswing) {
1037379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
1038379bc100SJani Nikula 		return bxt_ddi_translations_edp;
1039379bc100SJani Nikula 	}
1040379bc100SJani Nikula 
1041a8143150SJosé Roberto de Souza 	return bxt_get_buf_trans_dp(encoder, n_entries);
1042379bc100SJani Nikula }
1043379bc100SJani Nikula 
1044379bc100SJani Nikula static const struct bxt_ddi_buf_trans *
1045a8143150SJosé Roberto de Souza bxt_get_buf_trans_hdmi(struct intel_encoder *encoder, int *n_entries)
1046379bc100SJani Nikula {
1047379bc100SJani Nikula 	*n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
1048379bc100SJani Nikula 	return bxt_ddi_translations_hdmi;
1049379bc100SJani Nikula }
1050379bc100SJani Nikula 
1051379bc100SJani Nikula static const struct cnl_ddi_buf_trans *
1052a8143150SJosé Roberto de Souza cnl_get_buf_trans_hdmi(struct intel_encoder *encoder, int *n_entries)
1053379bc100SJani Nikula {
1054a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1055f7960e7fSJani Nikula 	u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
1056379bc100SJani Nikula 
1057379bc100SJani Nikula 	if (voltage == VOLTAGE_INFO_0_85V) {
1058379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V);
1059379bc100SJani Nikula 		return cnl_ddi_translations_hdmi_0_85V;
1060379bc100SJani Nikula 	} else if (voltage == VOLTAGE_INFO_0_95V) {
1061379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V);
1062379bc100SJani Nikula 		return cnl_ddi_translations_hdmi_0_95V;
1063379bc100SJani Nikula 	} else if (voltage == VOLTAGE_INFO_1_05V) {
1064379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V);
1065379bc100SJani Nikula 		return cnl_ddi_translations_hdmi_1_05V;
1066379bc100SJani Nikula 	} else {
1067379bc100SJani Nikula 		*n_entries = 1; /* shut up gcc */
1068379bc100SJani Nikula 		MISSING_CASE(voltage);
1069379bc100SJani Nikula 	}
1070379bc100SJani Nikula 	return NULL;
1071379bc100SJani Nikula }
1072379bc100SJani Nikula 
1073379bc100SJani Nikula static const struct cnl_ddi_buf_trans *
1074a8143150SJosé Roberto de Souza cnl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries)
1075379bc100SJani Nikula {
1076a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1077f7960e7fSJani Nikula 	u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
1078379bc100SJani Nikula 
1079379bc100SJani Nikula 	if (voltage == VOLTAGE_INFO_0_85V) {
1080379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V);
1081379bc100SJani Nikula 		return cnl_ddi_translations_dp_0_85V;
1082379bc100SJani Nikula 	} else if (voltage == VOLTAGE_INFO_0_95V) {
1083379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V);
1084379bc100SJani Nikula 		return cnl_ddi_translations_dp_0_95V;
1085379bc100SJani Nikula 	} else if (voltage == VOLTAGE_INFO_1_05V) {
1086379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V);
1087379bc100SJani Nikula 		return cnl_ddi_translations_dp_1_05V;
1088379bc100SJani Nikula 	} else {
1089379bc100SJani Nikula 		*n_entries = 1; /* shut up gcc */
1090379bc100SJani Nikula 		MISSING_CASE(voltage);
1091379bc100SJani Nikula 	}
1092379bc100SJani Nikula 	return NULL;
1093379bc100SJani Nikula }
1094379bc100SJani Nikula 
1095379bc100SJani Nikula static const struct cnl_ddi_buf_trans *
1096a8143150SJosé Roberto de Souza cnl_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries)
1097379bc100SJani Nikula {
1098a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1099f7960e7fSJani Nikula 	u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
1100379bc100SJani Nikula 
1101379bc100SJani Nikula 	if (dev_priv->vbt.edp.low_vswing) {
1102379bc100SJani Nikula 		if (voltage == VOLTAGE_INFO_0_85V) {
1103379bc100SJani Nikula 			*n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V);
1104379bc100SJani Nikula 			return cnl_ddi_translations_edp_0_85V;
1105379bc100SJani Nikula 		} else if (voltage == VOLTAGE_INFO_0_95V) {
1106379bc100SJani Nikula 			*n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V);
1107379bc100SJani Nikula 			return cnl_ddi_translations_edp_0_95V;
1108379bc100SJani Nikula 		} else if (voltage == VOLTAGE_INFO_1_05V) {
1109379bc100SJani Nikula 			*n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V);
1110379bc100SJani Nikula 			return cnl_ddi_translations_edp_1_05V;
1111379bc100SJani Nikula 		} else {
1112379bc100SJani Nikula 			*n_entries = 1; /* shut up gcc */
1113379bc100SJani Nikula 			MISSING_CASE(voltage);
1114379bc100SJani Nikula 		}
1115379bc100SJani Nikula 		return NULL;
1116379bc100SJani Nikula 	} else {
1117a8143150SJosé Roberto de Souza 		return cnl_get_buf_trans_dp(encoder, n_entries);
1118379bc100SJani Nikula 	}
1119379bc100SJani Nikula }
1120379bc100SJani Nikula 
1121379bc100SJani Nikula static const struct cnl_ddi_buf_trans *
1122a621860aSVille Syrjälä icl_get_combo_buf_trans_hdmi(struct intel_encoder *encoder,
1123a621860aSVille Syrjälä 			     const struct intel_crtc_state *crtc_state,
11246ed9aefaSVille Syrjälä 			     int *n_entries)
11256ed9aefaSVille Syrjälä {
11266ed9aefaSVille Syrjälä 	*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi);
11276ed9aefaSVille Syrjälä 	return icl_combo_phy_ddi_translations_hdmi;
11286ed9aefaSVille Syrjälä }
11296ed9aefaSVille Syrjälä 
11306ed9aefaSVille Syrjälä static const struct cnl_ddi_buf_trans *
1131a621860aSVille Syrjälä icl_get_combo_buf_trans_dp(struct intel_encoder *encoder,
1132a621860aSVille Syrjälä 			   const struct intel_crtc_state *crtc_state,
11336ed9aefaSVille Syrjälä 			   int *n_entries)
11346ed9aefaSVille Syrjälä {
11356ed9aefaSVille Syrjälä 	*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_dp_hbr2);
11366ed9aefaSVille Syrjälä 	return icl_combo_phy_ddi_translations_dp_hbr2;
11376ed9aefaSVille Syrjälä }
11386ed9aefaSVille Syrjälä 
11396ed9aefaSVille Syrjälä static const struct cnl_ddi_buf_trans *
1140a621860aSVille Syrjälä icl_get_combo_buf_trans_edp(struct intel_encoder *encoder,
1141a621860aSVille Syrjälä 			    const struct intel_crtc_state *crtc_state,
11424a8134d5SMatt Roper 			    int *n_entries)
1143379bc100SJani Nikula {
1144a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1145a8143150SJosé Roberto de Souza 
1146a621860aSVille Syrjälä 	if (crtc_state->port_clock > 540000) {
1147379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr3);
1148379bc100SJani Nikula 		return icl_combo_phy_ddi_translations_edp_hbr3;
11496ed9aefaSVille Syrjälä 	} else if (dev_priv->vbt.edp.low_vswing) {
1150379bc100SJani Nikula 		*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2);
1151379bc100SJani Nikula 		return icl_combo_phy_ddi_translations_edp_hbr2;
1152cce73665SMatt Roper 	} else if (IS_DG1(dev_priv) && crtc_state->port_clock > 270000) {
1153cce73665SMatt Roper 		*n_entries = ARRAY_SIZE(dg1_combo_phy_ddi_translations_dp_hbr2_hbr3);
1154cce73665SMatt Roper 		return dg1_combo_phy_ddi_translations_dp_hbr2_hbr3;
1155cce73665SMatt Roper 	} else if (IS_DG1(dev_priv)) {
1156cce73665SMatt Roper 		*n_entries = ARRAY_SIZE(dg1_combo_phy_ddi_translations_dp_rbr_hbr);
1157cce73665SMatt Roper 		return dg1_combo_phy_ddi_translations_dp_rbr_hbr;
1158379bc100SJani Nikula 	}
1159379bc100SJani Nikula 
1160a621860aSVille Syrjälä 	return icl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
11616ed9aefaSVille Syrjälä }
11626ed9aefaSVille Syrjälä 
11636ed9aefaSVille Syrjälä static const struct cnl_ddi_buf_trans *
1164a621860aSVille Syrjälä icl_get_combo_buf_trans(struct intel_encoder *encoder,
1165a621860aSVille Syrjälä 			const struct intel_crtc_state *crtc_state,
11666ed9aefaSVille Syrjälä 			int *n_entries)
11676ed9aefaSVille Syrjälä {
1168a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1169a621860aSVille Syrjälä 		return icl_get_combo_buf_trans_hdmi(encoder, crtc_state, n_entries);
1170a621860aSVille Syrjälä 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
1171a621860aSVille Syrjälä 		return icl_get_combo_buf_trans_edp(encoder, crtc_state, n_entries);
11726ed9aefaSVille Syrjälä 	else
1173a621860aSVille Syrjälä 		return icl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
1174379bc100SJani Nikula }
1175379bc100SJani Nikula 
11769f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans *
1177a621860aSVille Syrjälä icl_get_mg_buf_trans_hdmi(struct intel_encoder *encoder,
1178a621860aSVille Syrjälä 			  const struct intel_crtc_state *crtc_state,
11795ee3e1daSVille Syrjälä 			  int *n_entries)
11805ee3e1daSVille Syrjälä {
11815ee3e1daSVille Syrjälä 	*n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_hdmi);
11825ee3e1daSVille Syrjälä 	return icl_mg_phy_ddi_translations_hdmi;
11835ee3e1daSVille Syrjälä }
11845ee3e1daSVille Syrjälä 
11855ee3e1daSVille Syrjälä static const struct icl_mg_phy_ddi_buf_trans *
1186a621860aSVille Syrjälä icl_get_mg_buf_trans_dp(struct intel_encoder *encoder,
1187a621860aSVille Syrjälä 			const struct intel_crtc_state *crtc_state,
11885ee3e1daSVille Syrjälä 			int *n_entries)
11895ee3e1daSVille Syrjälä {
1190a621860aSVille Syrjälä 	if (crtc_state->port_clock > 270000) {
11915ee3e1daSVille Syrjälä 		*n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_hbr2_hbr3);
11925ee3e1daSVille Syrjälä 		return icl_mg_phy_ddi_translations_hbr2_hbr3;
11935ee3e1daSVille Syrjälä 	} else {
11945ee3e1daSVille Syrjälä 		*n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_rbr_hbr);
11955ee3e1daSVille Syrjälä 		return icl_mg_phy_ddi_translations_rbr_hbr;
11965ee3e1daSVille Syrjälä 	}
11975ee3e1daSVille Syrjälä }
11985ee3e1daSVille Syrjälä 
11995ee3e1daSVille Syrjälä static const struct icl_mg_phy_ddi_buf_trans *
1200a621860aSVille Syrjälä icl_get_mg_buf_trans(struct intel_encoder *encoder,
1201a621860aSVille Syrjälä 		     const struct intel_crtc_state *crtc_state,
12029f7ffa29SJosé Roberto de Souza 		     int *n_entries)
12039f7ffa29SJosé Roberto de Souza {
1204a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1205a621860aSVille Syrjälä 		return icl_get_mg_buf_trans_hdmi(encoder, crtc_state, n_entries);
12065ee3e1daSVille Syrjälä 	else
1207a621860aSVille Syrjälä 		return icl_get_mg_buf_trans_dp(encoder, crtc_state, n_entries);
12089f7ffa29SJosé Roberto de Souza }
12099f7ffa29SJosé Roberto de Souza 
1210bd3cf6f7SJosé Roberto de Souza static const struct cnl_ddi_buf_trans *
1211a621860aSVille Syrjälä ehl_get_combo_buf_trans_hdmi(struct intel_encoder *encoder,
1212a621860aSVille Syrjälä 			     const struct intel_crtc_state *crtc_state,
1213ba30075dSVille Syrjälä 			     int *n_entries)
1214ba30075dSVille Syrjälä {
1215ba30075dSVille Syrjälä 	*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi);
1216ba30075dSVille Syrjälä 	return icl_combo_phy_ddi_translations_hdmi;
1217ba30075dSVille Syrjälä }
1218ba30075dSVille Syrjälä 
1219ba30075dSVille Syrjälä static const struct cnl_ddi_buf_trans *
1220a621860aSVille Syrjälä ehl_get_combo_buf_trans_dp(struct intel_encoder *encoder,
1221a621860aSVille Syrjälä 			   const struct intel_crtc_state *crtc_state,
1222ba30075dSVille Syrjälä 			   int *n_entries)
1223ba30075dSVille Syrjälä {
1224ba30075dSVille Syrjälä 	*n_entries = ARRAY_SIZE(ehl_combo_phy_ddi_translations_dp);
1225ba30075dSVille Syrjälä 	return ehl_combo_phy_ddi_translations_dp;
1226ba30075dSVille Syrjälä }
1227ba30075dSVille Syrjälä 
1228ba30075dSVille Syrjälä static const struct cnl_ddi_buf_trans *
1229a621860aSVille Syrjälä ehl_get_combo_buf_trans_edp(struct intel_encoder *encoder,
1230a621860aSVille Syrjälä 			    const struct intel_crtc_state *crtc_state,
1231b42d5a67SJosé Roberto de Souza 			    int *n_entries)
1232b42d5a67SJosé Roberto de Souza {
12332a498ab4SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
12342a498ab4SJosé Roberto de Souza 
12352a498ab4SJosé Roberto de Souza 	if (dev_priv->vbt.edp.low_vswing) {
12362a498ab4SJosé Roberto de Souza 		*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2);
12372a498ab4SJosé Roberto de Souza 		return icl_combo_phy_ddi_translations_edp_hbr2;
12382a498ab4SJosé Roberto de Souza 	}
1239ba30075dSVille Syrjälä 
1240a621860aSVille Syrjälä 	return ehl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
1241b42d5a67SJosé Roberto de Souza }
1242ba30075dSVille Syrjälä 
1243ba30075dSVille Syrjälä static const struct cnl_ddi_buf_trans *
1244a621860aSVille Syrjälä ehl_get_combo_buf_trans(struct intel_encoder *encoder,
1245a621860aSVille Syrjälä 			const struct intel_crtc_state *crtc_state,
1246ba30075dSVille Syrjälä 			int *n_entries)
1247ba30075dSVille Syrjälä {
1248a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1249a621860aSVille Syrjälä 		return ehl_get_combo_buf_trans_hdmi(encoder, crtc_state, n_entries);
1250a621860aSVille Syrjälä 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
1251a621860aSVille Syrjälä 		return ehl_get_combo_buf_trans_edp(encoder, crtc_state, n_entries);
1252ba30075dSVille Syrjälä 	else
1253a621860aSVille Syrjälä 		return ehl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
1254b42d5a67SJosé Roberto de Souza }
1255b42d5a67SJosé Roberto de Souza 
1256b42d5a67SJosé Roberto de Souza static const struct cnl_ddi_buf_trans *
12571ba1014dSTejas Upadhyay jsl_get_combo_buf_trans_hdmi(struct intel_encoder *encoder,
12581ba1014dSTejas Upadhyay 			     const struct intel_crtc_state *crtc_state,
12591ba1014dSTejas Upadhyay 			     int *n_entries)
12601ba1014dSTejas Upadhyay {
12611ba1014dSTejas Upadhyay 	*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi);
12621ba1014dSTejas Upadhyay 	return icl_combo_phy_ddi_translations_hdmi;
12631ba1014dSTejas Upadhyay }
12641ba1014dSTejas Upadhyay 
12651ba1014dSTejas Upadhyay static const struct cnl_ddi_buf_trans *
12661ba1014dSTejas Upadhyay jsl_get_combo_buf_trans_dp(struct intel_encoder *encoder,
12671ba1014dSTejas Upadhyay 			   const struct intel_crtc_state *crtc_state,
12681ba1014dSTejas Upadhyay 			   int *n_entries)
12691ba1014dSTejas Upadhyay {
12701ba1014dSTejas Upadhyay 	*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_dp_hbr2);
12711ba1014dSTejas Upadhyay 	return icl_combo_phy_ddi_translations_dp_hbr2;
12721ba1014dSTejas Upadhyay }
12731ba1014dSTejas Upadhyay 
12741ba1014dSTejas Upadhyay static const struct cnl_ddi_buf_trans *
12751ba1014dSTejas Upadhyay jsl_get_combo_buf_trans_edp(struct intel_encoder *encoder,
12761ba1014dSTejas Upadhyay 			    const struct intel_crtc_state *crtc_state,
12771ba1014dSTejas Upadhyay 			    int *n_entries)
12781ba1014dSTejas Upadhyay {
12791ba1014dSTejas Upadhyay 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
12801ba1014dSTejas Upadhyay 
12811ba1014dSTejas Upadhyay 	if (dev_priv->vbt.edp.low_vswing) {
12821ba1014dSTejas Upadhyay 		if (crtc_state->port_clock > 270000) {
12831ba1014dSTejas Upadhyay 			*n_entries = ARRAY_SIZE(jsl_combo_phy_ddi_translations_edp_hbr2);
12841ba1014dSTejas Upadhyay 			return jsl_combo_phy_ddi_translations_edp_hbr2;
12851ba1014dSTejas Upadhyay 		} else {
12861ba1014dSTejas Upadhyay 			*n_entries = ARRAY_SIZE(jsl_combo_phy_ddi_translations_edp_hbr);
12871ba1014dSTejas Upadhyay 			return jsl_combo_phy_ddi_translations_edp_hbr;
12881ba1014dSTejas Upadhyay 		}
12891ba1014dSTejas Upadhyay 	}
12901ba1014dSTejas Upadhyay 
12911ba1014dSTejas Upadhyay 	return jsl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
12921ba1014dSTejas Upadhyay }
12931ba1014dSTejas Upadhyay 
12941ba1014dSTejas Upadhyay static const struct cnl_ddi_buf_trans *
12951ba1014dSTejas Upadhyay jsl_get_combo_buf_trans(struct intel_encoder *encoder,
12961ba1014dSTejas Upadhyay 			const struct intel_crtc_state *crtc_state,
12971ba1014dSTejas Upadhyay 			int *n_entries)
12981ba1014dSTejas Upadhyay {
12991ba1014dSTejas Upadhyay 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
13001ba1014dSTejas Upadhyay 		return jsl_get_combo_buf_trans_hdmi(encoder, crtc_state, n_entries);
13011ba1014dSTejas Upadhyay 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
13021ba1014dSTejas Upadhyay 		return jsl_get_combo_buf_trans_edp(encoder, crtc_state, n_entries);
13031ba1014dSTejas Upadhyay 	else
13041ba1014dSTejas Upadhyay 		return jsl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
13051ba1014dSTejas Upadhyay }
13061ba1014dSTejas Upadhyay 
13071ba1014dSTejas Upadhyay static const struct cnl_ddi_buf_trans *
1308a621860aSVille Syrjälä tgl_get_combo_buf_trans_hdmi(struct intel_encoder *encoder,
1309a621860aSVille Syrjälä 			     const struct intel_crtc_state *crtc_state,
13104669f5c2SVille Syrjälä 			     int *n_entries)
13114669f5c2SVille Syrjälä {
13124669f5c2SVille Syrjälä 	*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi);
13134669f5c2SVille Syrjälä 	return icl_combo_phy_ddi_translations_hdmi;
13144669f5c2SVille Syrjälä }
13154669f5c2SVille Syrjälä 
13164669f5c2SVille Syrjälä static const struct cnl_ddi_buf_trans *
1317a621860aSVille Syrjälä tgl_get_combo_buf_trans_dp(struct intel_encoder *encoder,
1318a621860aSVille Syrjälä 			   const struct intel_crtc_state *crtc_state,
1319bd3cf6f7SJosé Roberto de Souza 			   int *n_entries)
1320bd3cf6f7SJosé Roberto de Souza {
132181619f4aSJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
132281619f4aSJosé Roberto de Souza 
1323a621860aSVille Syrjälä 	if (crtc_state->port_clock > 270000) {
1324ec9c2e01SMatt Roper 		if (IS_ROCKETLAKE(dev_priv)) {
1325ec9c2e01SMatt Roper 			*n_entries = ARRAY_SIZE(rkl_combo_phy_ddi_translations_dp_hbr2_hbr3);
1326ec9c2e01SMatt Roper 			return rkl_combo_phy_ddi_translations_dp_hbr2_hbr3;
1327ec9c2e01SMatt Roper 		} else if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
132804dfb1acSJosé Roberto de Souza 			*n_entries = ARRAY_SIZE(tgl_uy_combo_phy_ddi_translations_dp_hbr2);
132904dfb1acSJosé Roberto de Souza 			return tgl_uy_combo_phy_ddi_translations_dp_hbr2;
13304669f5c2SVille Syrjälä 		} else {
1331bd3cf6f7SJosé Roberto de Souza 			*n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr2);
1332bd3cf6f7SJosé Roberto de Souza 			return tgl_combo_phy_ddi_translations_dp_hbr2;
1333bd3cf6f7SJosé Roberto de Souza 		}
13344669f5c2SVille Syrjälä 	} else {
1335ec9c2e01SMatt Roper 		if (IS_ROCKETLAKE(dev_priv)) {
1336ec9c2e01SMatt Roper 			*n_entries = ARRAY_SIZE(rkl_combo_phy_ddi_translations_dp_hbr);
1337ec9c2e01SMatt Roper 			return rkl_combo_phy_ddi_translations_dp_hbr;
1338ec9c2e01SMatt Roper 		} else {
1339bd3cf6f7SJosé Roberto de Souza 			*n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr);
1340bd3cf6f7SJosé Roberto de Souza 			return tgl_combo_phy_ddi_translations_dp_hbr;
1341bd3cf6f7SJosé Roberto de Souza 		}
1342a8c90bc1SJosé Roberto de Souza 	}
1343ec9c2e01SMatt Roper }
1344bd3cf6f7SJosé Roberto de Souza 
13454669f5c2SVille Syrjälä static const struct cnl_ddi_buf_trans *
1346a621860aSVille Syrjälä tgl_get_combo_buf_trans_edp(struct intel_encoder *encoder,
1347a621860aSVille Syrjälä 			    const struct intel_crtc_state *crtc_state,
13484669f5c2SVille Syrjälä 			    int *n_entries)
13494669f5c2SVille Syrjälä {
13504669f5c2SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
13514669f5c2SVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
13524669f5c2SVille Syrjälä 
1353a621860aSVille Syrjälä 	if (crtc_state->port_clock > 540000) {
13544669f5c2SVille Syrjälä 		*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr3);
13554669f5c2SVille Syrjälä 		return icl_combo_phy_ddi_translations_edp_hbr3;
13564669f5c2SVille Syrjälä 	} else if (dev_priv->vbt.edp.hobl && !intel_dp->hobl_failed) {
13574669f5c2SVille Syrjälä 		*n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_edp_hbr2_hobl);
13584669f5c2SVille Syrjälä 		return tgl_combo_phy_ddi_translations_edp_hbr2_hobl;
13594669f5c2SVille Syrjälä 	} else if (dev_priv->vbt.edp.low_vswing) {
13604669f5c2SVille Syrjälä 		*n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2);
13614669f5c2SVille Syrjälä 		return icl_combo_phy_ddi_translations_edp_hbr2;
13624669f5c2SVille Syrjälä 	}
13634669f5c2SVille Syrjälä 
1364a621860aSVille Syrjälä 	return tgl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
13654669f5c2SVille Syrjälä }
13664669f5c2SVille Syrjälä 
13674669f5c2SVille Syrjälä static const struct cnl_ddi_buf_trans *
1368a621860aSVille Syrjälä tgl_get_combo_buf_trans(struct intel_encoder *encoder,
1369a621860aSVille Syrjälä 			const struct intel_crtc_state *crtc_state,
13704669f5c2SVille Syrjälä 			int *n_entries)
13714669f5c2SVille Syrjälä {
1372a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1373a621860aSVille Syrjälä 		return tgl_get_combo_buf_trans_hdmi(encoder, crtc_state, n_entries);
1374a621860aSVille Syrjälä 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
1375a621860aSVille Syrjälä 		return tgl_get_combo_buf_trans_edp(encoder, crtc_state, n_entries);
13764669f5c2SVille Syrjälä 	else
1377a621860aSVille Syrjälä 		return tgl_get_combo_buf_trans_dp(encoder, crtc_state, n_entries);
13784669f5c2SVille Syrjälä }
13794669f5c2SVille Syrjälä 
13809fa67699SJosé Roberto de Souza static const struct tgl_dkl_phy_ddi_buf_trans *
1381a621860aSVille Syrjälä tgl_get_dkl_buf_trans_hdmi(struct intel_encoder *encoder,
1382a621860aSVille Syrjälä 			   const struct intel_crtc_state *crtc_state,
13836a41121fSVille Syrjälä 			   int *n_entries)
13846a41121fSVille Syrjälä {
13856a41121fSVille Syrjälä 	*n_entries = ARRAY_SIZE(tgl_dkl_phy_hdmi_ddi_trans);
13866a41121fSVille Syrjälä 	return tgl_dkl_phy_hdmi_ddi_trans;
13876a41121fSVille Syrjälä }
13886a41121fSVille Syrjälä 
13896a41121fSVille Syrjälä static const struct tgl_dkl_phy_ddi_buf_trans *
1390a621860aSVille Syrjälä tgl_get_dkl_buf_trans_dp(struct intel_encoder *encoder,
1391a621860aSVille Syrjälä 			 const struct intel_crtc_state *crtc_state,
13926a41121fSVille Syrjälä 			 int *n_entries)
13936a41121fSVille Syrjälä {
1394a621860aSVille Syrjälä 	if (crtc_state->port_clock > 270000) {
13956a41121fSVille Syrjälä 		*n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans_hbr2);
13966a41121fSVille Syrjälä 		return tgl_dkl_phy_dp_ddi_trans_hbr2;
13976a41121fSVille Syrjälä 	} else {
13986a41121fSVille Syrjälä 		*n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans);
13996a41121fSVille Syrjälä 		return tgl_dkl_phy_dp_ddi_trans;
14006a41121fSVille Syrjälä 	}
14016a41121fSVille Syrjälä }
14026a41121fSVille Syrjälä 
14036a41121fSVille Syrjälä static const struct tgl_dkl_phy_ddi_buf_trans *
1404a621860aSVille Syrjälä tgl_get_dkl_buf_trans(struct intel_encoder *encoder,
1405a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state,
14069fa67699SJosé Roberto de Souza 		      int *n_entries)
14079fa67699SJosé Roberto de Souza {
1408a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
1409a621860aSVille Syrjälä 		return tgl_get_dkl_buf_trans_hdmi(encoder, crtc_state, n_entries);
14106a41121fSVille Syrjälä 	else
1411a621860aSVille Syrjälä 		return tgl_get_dkl_buf_trans_dp(encoder, crtc_state, n_entries);
14129fa67699SJosé Roberto de Souza }
14139fa67699SJosé Roberto de Souza 
1414a621860aSVille Syrjälä static int intel_ddi_hdmi_level(struct intel_encoder *encoder,
1415a621860aSVille Syrjälä 				const struct intel_crtc_state *crtc_state)
1416379bc100SJani Nikula {
14170aed3bdeSJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1418379bc100SJani Nikula 	int n_entries, level, default_entry;
14190aed3bdeSJani Nikula 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1420379bc100SJani Nikula 
1421978c3e53SClinton A Taylor 	if (INTEL_GEN(dev_priv) >= 12) {
1422978c3e53SClinton A Taylor 		if (intel_phy_is_combo(dev_priv, phy))
1423a621860aSVille Syrjälä 			tgl_get_combo_buf_trans_hdmi(encoder, crtc_state, &n_entries);
1424978c3e53SClinton A Taylor 		else
1425a621860aSVille Syrjälä 			tgl_get_dkl_buf_trans_hdmi(encoder, crtc_state, &n_entries);
1426978c3e53SClinton A Taylor 		default_entry = n_entries - 1;
1427978c3e53SClinton A Taylor 	} else if (INTEL_GEN(dev_priv) == 11) {
1428d8fe2ab6SMatt Roper 		if (intel_phy_is_combo(dev_priv, phy))
1429a621860aSVille Syrjälä 			icl_get_combo_buf_trans_hdmi(encoder, crtc_state, &n_entries);
1430379bc100SJani Nikula 		else
1431a621860aSVille Syrjälä 			icl_get_mg_buf_trans_hdmi(encoder, crtc_state, &n_entries);
1432379bc100SJani Nikula 		default_entry = n_entries - 1;
1433379bc100SJani Nikula 	} else if (IS_CANNONLAKE(dev_priv)) {
1434a8143150SJosé Roberto de Souza 		cnl_get_buf_trans_hdmi(encoder, &n_entries);
1435379bc100SJani Nikula 		default_entry = n_entries - 1;
1436379bc100SJani Nikula 	} else if (IS_GEN9_LP(dev_priv)) {
1437a8143150SJosé Roberto de Souza 		bxt_get_buf_trans_hdmi(encoder, &n_entries);
1438379bc100SJani Nikula 		default_entry = n_entries - 1;
1439379bc100SJani Nikula 	} else if (IS_GEN9_BC(dev_priv)) {
1440a8143150SJosé Roberto de Souza 		intel_ddi_get_buf_trans_hdmi(encoder, &n_entries);
1441379bc100SJani Nikula 		default_entry = 8;
1442379bc100SJani Nikula 	} else if (IS_BROADWELL(dev_priv)) {
1443a8143150SJosé Roberto de Souza 		intel_ddi_get_buf_trans_hdmi(encoder, &n_entries);
1444379bc100SJani Nikula 		default_entry = 7;
1445379bc100SJani Nikula 	} else if (IS_HASWELL(dev_priv)) {
1446a8143150SJosé Roberto de Souza 		intel_ddi_get_buf_trans_hdmi(encoder, &n_entries);
1447379bc100SJani Nikula 		default_entry = 6;
1448379bc100SJani Nikula 	} else {
14491de143ccSPankaj Bharadiya 		drm_WARN(&dev_priv->drm, 1, "ddi translation table missing\n");
1450379bc100SJani Nikula 		return 0;
1451379bc100SJani Nikula 	}
1452379bc100SJani Nikula 
14531de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, n_entries == 0))
1454379bc100SJani Nikula 		return 0;
14557a0073d6SJani Nikula 
14560aed3bdeSJani Nikula 	level = intel_bios_hdmi_level_shift(encoder);
14570aed3bdeSJani Nikula 	if (level < 0)
14587a0073d6SJani Nikula 		level = default_entry;
14597a0073d6SJani Nikula 
14601de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1461379bc100SJani Nikula 		level = n_entries - 1;
1462379bc100SJani Nikula 
1463379bc100SJani Nikula 	return level;
1464379bc100SJani Nikula }
1465379bc100SJani Nikula 
1466379bc100SJani Nikula /*
1467379bc100SJani Nikula  * Starting with Haswell, DDI port buffers must be programmed with correct
1468379bc100SJani Nikula  * values in advance. This function programs the correct values for
1469379bc100SJani Nikula  * DP/eDP/FDI use cases.
1470379bc100SJani Nikula  */
1471379bc100SJani Nikula static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder,
1472379bc100SJani Nikula 					 const struct intel_crtc_state *crtc_state)
1473379bc100SJani Nikula {
1474379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1475379bc100SJani Nikula 	u32 iboost_bit = 0;
1476379bc100SJani Nikula 	int i, n_entries;
1477379bc100SJani Nikula 	enum port port = encoder->port;
1478379bc100SJani Nikula 	const struct ddi_buf_trans *ddi_translations;
1479379bc100SJani Nikula 
1480379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
1481379bc100SJani Nikula 		ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
1482379bc100SJani Nikula 							       &n_entries);
1483379bc100SJani Nikula 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
1484f0e86e05SJosé Roberto de Souza 		ddi_translations = intel_ddi_get_buf_trans_edp(encoder,
1485379bc100SJani Nikula 							       &n_entries);
1486379bc100SJani Nikula 	else
1487f0e86e05SJosé Roberto de Souza 		ddi_translations = intel_ddi_get_buf_trans_dp(encoder,
1488379bc100SJani Nikula 							      &n_entries);
1489379bc100SJani Nikula 
1490379bc100SJani Nikula 	/* If we're boosting the current, set bit 31 of trans1 */
1491605a1872SJani Nikula 	if (IS_GEN9_BC(dev_priv) && intel_bios_dp_boost_level(encoder))
1492379bc100SJani Nikula 		iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
1493379bc100SJani Nikula 
1494379bc100SJani Nikula 	for (i = 0; i < n_entries; i++) {
1495f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, i),
1496379bc100SJani Nikula 			       ddi_translations[i].trans1 | iboost_bit);
1497f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, i),
1498379bc100SJani Nikula 			       ddi_translations[i].trans2);
1499379bc100SJani Nikula 	}
1500379bc100SJani Nikula }
1501379bc100SJani Nikula 
1502379bc100SJani Nikula /*
1503379bc100SJani Nikula  * Starting with Haswell, DDI port buffers must be programmed with correct
1504379bc100SJani Nikula  * values in advance. This function programs the correct values for
1505379bc100SJani Nikula  * HDMI/DVI use cases.
1506379bc100SJani Nikula  */
1507379bc100SJani Nikula static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder,
1508379bc100SJani Nikula 					   int level)
1509379bc100SJani Nikula {
1510379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1511379bc100SJani Nikula 	u32 iboost_bit = 0;
1512379bc100SJani Nikula 	int n_entries;
1513379bc100SJani Nikula 	enum port port = encoder->port;
1514379bc100SJani Nikula 	const struct ddi_buf_trans *ddi_translations;
1515379bc100SJani Nikula 
1516a8143150SJosé Roberto de Souza 	ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries);
1517379bc100SJani Nikula 
15181de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
1519379bc100SJani Nikula 		return;
15201de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
1521379bc100SJani Nikula 		level = n_entries - 1;
1522379bc100SJani Nikula 
1523379bc100SJani Nikula 	/* If we're boosting the current, set bit 31 of trans1 */
152401a60883SJani Nikula 	if (IS_GEN9_BC(dev_priv) && intel_bios_hdmi_boost_level(encoder))
1525379bc100SJani Nikula 		iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
1526379bc100SJani Nikula 
1527379bc100SJani Nikula 	/* Entry 9 is for HDMI: */
1528f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, 9),
1529379bc100SJani Nikula 		       ddi_translations[level].trans1 | iboost_bit);
1530f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, 9),
1531379bc100SJani Nikula 		       ddi_translations[level].trans2);
1532379bc100SJani Nikula }
1533379bc100SJani Nikula 
1534379bc100SJani Nikula static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
1535379bc100SJani Nikula 				    enum port port)
1536379bc100SJani Nikula {
15375a2ad99bSManasi Navare 	if (IS_BROXTON(dev_priv)) {
15385a2ad99bSManasi Navare 		udelay(16);
1539379bc100SJani Nikula 		return;
1540379bc100SJani Nikula 	}
15415a2ad99bSManasi Navare 
15425a2ad99bSManasi Navare 	if (wait_for_us((intel_de_read(dev_priv, DDI_BUF_CTL(port)) &
15435a2ad99bSManasi Navare 			 DDI_BUF_IS_IDLE), 8))
15445a2ad99bSManasi Navare 		drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get idle\n",
154547bdb1caSJani Nikula 			port_name(port));
1546379bc100SJani Nikula }
1547379bc100SJani Nikula 
1548e828da30SManasi Navare static void intel_wait_ddi_buf_active(struct drm_i915_private *dev_priv,
1549e828da30SManasi Navare 				      enum port port)
1550e828da30SManasi Navare {
1551e828da30SManasi Navare 	/* Wait > 518 usecs for DDI_BUF_CTL to be non idle */
1552e828da30SManasi Navare 	if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
1553e828da30SManasi Navare 		usleep_range(518, 1000);
1554e828da30SManasi Navare 		return;
1555e828da30SManasi Navare 	}
1556e828da30SManasi Navare 
1557e828da30SManasi Navare 	if (wait_for_us(!(intel_de_read(dev_priv, DDI_BUF_CTL(port)) &
1558e828da30SManasi Navare 			  DDI_BUF_IS_IDLE), 500))
1559e828da30SManasi Navare 		drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get active\n",
1560e828da30SManasi Navare 			port_name(port));
1561e828da30SManasi Navare }
1562e828da30SManasi Navare 
1563379bc100SJani Nikula static u32 hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll)
1564379bc100SJani Nikula {
1565379bc100SJani Nikula 	switch (pll->info->id) {
1566379bc100SJani Nikula 	case DPLL_ID_WRPLL1:
1567379bc100SJani Nikula 		return PORT_CLK_SEL_WRPLL1;
1568379bc100SJani Nikula 	case DPLL_ID_WRPLL2:
1569379bc100SJani Nikula 		return PORT_CLK_SEL_WRPLL2;
1570379bc100SJani Nikula 	case DPLL_ID_SPLL:
1571379bc100SJani Nikula 		return PORT_CLK_SEL_SPLL;
1572379bc100SJani Nikula 	case DPLL_ID_LCPLL_810:
1573379bc100SJani Nikula 		return PORT_CLK_SEL_LCPLL_810;
1574379bc100SJani Nikula 	case DPLL_ID_LCPLL_1350:
1575379bc100SJani Nikula 		return PORT_CLK_SEL_LCPLL_1350;
1576379bc100SJani Nikula 	case DPLL_ID_LCPLL_2700:
1577379bc100SJani Nikula 		return PORT_CLK_SEL_LCPLL_2700;
1578379bc100SJani Nikula 	default:
1579379bc100SJani Nikula 		MISSING_CASE(pll->info->id);
1580379bc100SJani Nikula 		return PORT_CLK_SEL_NONE;
1581379bc100SJani Nikula 	}
1582379bc100SJani Nikula }
1583379bc100SJani Nikula 
1584379bc100SJani Nikula static u32 icl_pll_to_ddi_clk_sel(struct intel_encoder *encoder,
1585379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state)
1586379bc100SJani Nikula {
1587379bc100SJani Nikula 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
1588379bc100SJani Nikula 	int clock = crtc_state->port_clock;
1589379bc100SJani Nikula 	const enum intel_dpll_id id = pll->info->id;
1590379bc100SJani Nikula 
1591379bc100SJani Nikula 	switch (id) {
1592379bc100SJani Nikula 	default:
1593379bc100SJani Nikula 		/*
1594379bc100SJani Nikula 		 * DPLL_ID_ICL_DPLL0 and DPLL_ID_ICL_DPLL1 should not be used
1595379bc100SJani Nikula 		 * here, so do warn if this get passed in
1596379bc100SJani Nikula 		 */
1597379bc100SJani Nikula 		MISSING_CASE(id);
1598379bc100SJani Nikula 		return DDI_CLK_SEL_NONE;
1599379bc100SJani Nikula 	case DPLL_ID_ICL_TBTPLL:
1600379bc100SJani Nikula 		switch (clock) {
1601379bc100SJani Nikula 		case 162000:
1602379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_162;
1603379bc100SJani Nikula 		case 270000:
1604379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_270;
1605379bc100SJani Nikula 		case 540000:
1606379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_540;
1607379bc100SJani Nikula 		case 810000:
1608379bc100SJani Nikula 			return DDI_CLK_SEL_TBT_810;
1609379bc100SJani Nikula 		default:
1610379bc100SJani Nikula 			MISSING_CASE(clock);
1611379bc100SJani Nikula 			return DDI_CLK_SEL_NONE;
1612379bc100SJani Nikula 		}
1613379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL1:
1614379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL2:
1615379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL3:
1616379bc100SJani Nikula 	case DPLL_ID_ICL_MGPLL4:
16176677c3b1SJosé Roberto de Souza 	case DPLL_ID_TGL_MGPLL5:
16186677c3b1SJosé Roberto de Souza 	case DPLL_ID_TGL_MGPLL6:
1619379bc100SJani Nikula 		return DDI_CLK_SEL_MG;
1620379bc100SJani Nikula 	}
1621379bc100SJani Nikula }
1622379bc100SJani Nikula 
1623379bc100SJani Nikula /* Starting with Haswell, different DDI ports can work in FDI mode for
1624379bc100SJani Nikula  * connection to the PCH-located connectors. For this, it is necessary to train
1625379bc100SJani Nikula  * both the DDI port and PCH receiver for the desired DDI buffer settings.
1626379bc100SJani Nikula  *
1627379bc100SJani Nikula  * The recommended port to work in FDI mode is DDI E, which we use here. Also,
1628379bc100SJani Nikula  * please note that when FDI mode is active on DDI E, it shares 2 lines with
1629379bc100SJani Nikula  * DDI A (which is used for eDP)
1630379bc100SJani Nikula  */
1631379bc100SJani Nikula 
16326a6d79deSVille Syrjälä void hsw_fdi_link_train(struct intel_encoder *encoder,
1633379bc100SJani Nikula 			const struct intel_crtc_state *crtc_state)
1634379bc100SJani Nikula {
16356a6d79deSVille Syrjälä 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
16366a6d79deSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1637379bc100SJani Nikula 	u32 temp, i, rx_ctl_val, ddi_pll_sel;
1638379bc100SJani Nikula 
1639379bc100SJani Nikula 	intel_prepare_dp_ddi_buffers(encoder, crtc_state);
1640379bc100SJani Nikula 
1641379bc100SJani Nikula 	/* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
1642379bc100SJani Nikula 	 * mode set "sequence for CRT port" document:
1643379bc100SJani Nikula 	 * - TP1 to TP2 time with the default value
1644379bc100SJani Nikula 	 * - FDI delay to 90h
1645379bc100SJani Nikula 	 *
1646379bc100SJani Nikula 	 * WaFDIAutoLinkSetTimingOverrride:hsw
1647379bc100SJani Nikula 	 */
1648f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A),
1649f7960e7fSJani Nikula 		       FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2) | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
1650379bc100SJani Nikula 
1651379bc100SJani Nikula 	/* Enable the PCH Receiver FDI PLL */
1652379bc100SJani Nikula 	rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
1653379bc100SJani Nikula 		     FDI_RX_PLL_ENABLE |
1654379bc100SJani Nikula 		     FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
1655f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val);
1656f7960e7fSJani Nikula 	intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A));
1657379bc100SJani Nikula 	udelay(220);
1658379bc100SJani Nikula 
1659379bc100SJani Nikula 	/* Switch from Rawclk to PCDclk */
1660379bc100SJani Nikula 	rx_ctl_val |= FDI_PCDCLK;
1661f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val);
1662379bc100SJani Nikula 
1663379bc100SJani Nikula 	/* Configure Port Clock Select */
1664379bc100SJani Nikula 	ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll);
1665f7960e7fSJani Nikula 	intel_de_write(dev_priv, PORT_CLK_SEL(PORT_E), ddi_pll_sel);
16661de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, ddi_pll_sel != PORT_CLK_SEL_SPLL);
1667379bc100SJani Nikula 
1668379bc100SJani Nikula 	/* Start the training iterating through available voltages and emphasis,
1669379bc100SJani Nikula 	 * testing each value twice. */
1670379bc100SJani Nikula 	for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
1671379bc100SJani Nikula 		/* Configure DP_TP_CTL with auto-training */
1672f7960e7fSJani Nikula 		intel_de_write(dev_priv, DP_TP_CTL(PORT_E),
16737db8736dSVille Syrjälä 			       DP_TP_CTL_FDI_AUTOTRAIN |
16747db8736dSVille Syrjälä 			       DP_TP_CTL_ENHANCED_FRAME_ENABLE |
16757db8736dSVille Syrjälä 			       DP_TP_CTL_LINK_TRAIN_PAT1 |
16767db8736dSVille Syrjälä 			       DP_TP_CTL_ENABLE);
1677379bc100SJani Nikula 
1678379bc100SJani Nikula 		/* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
1679379bc100SJani Nikula 		 * DDI E does not support port reversal, the functionality is
1680379bc100SJani Nikula 		 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
1681379bc100SJani Nikula 		 * port reversal bit */
1682f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_CTL(PORT_E),
1683f7960e7fSJani Nikula 			       DDI_BUF_CTL_ENABLE | ((crtc_state->fdi_lanes - 1) << 1) | DDI_BUF_TRANS_SELECT(i / 2));
1684f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, DDI_BUF_CTL(PORT_E));
1685379bc100SJani Nikula 
1686379bc100SJani Nikula 		udelay(600);
1687379bc100SJani Nikula 
1688379bc100SJani Nikula 		/* Program PCH FDI Receiver TU */
1689f7960e7fSJani Nikula 		intel_de_write(dev_priv, FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
1690379bc100SJani Nikula 
1691379bc100SJani Nikula 		/* Enable PCH FDI Receiver with auto-training */
1692379bc100SJani Nikula 		rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
1693f7960e7fSJani Nikula 		intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val);
1694f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A));
1695379bc100SJani Nikula 
1696379bc100SJani Nikula 		/* Wait for FDI receiver lane calibration */
1697379bc100SJani Nikula 		udelay(30);
1698379bc100SJani Nikula 
1699379bc100SJani Nikula 		/* Unset FDI_RX_MISC pwrdn lanes */
1700f7960e7fSJani Nikula 		temp = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A));
1701379bc100SJani Nikula 		temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1702f7960e7fSJani Nikula 		intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), temp);
1703f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, FDI_RX_MISC(PIPE_A));
1704379bc100SJani Nikula 
1705379bc100SJani Nikula 		/* Wait for FDI auto training time */
1706379bc100SJani Nikula 		udelay(5);
1707379bc100SJani Nikula 
1708f7960e7fSJani Nikula 		temp = intel_de_read(dev_priv, DP_TP_STATUS(PORT_E));
1709379bc100SJani Nikula 		if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
171047bdb1caSJani Nikula 			drm_dbg_kms(&dev_priv->drm,
171147bdb1caSJani Nikula 				    "FDI link training done on step %d\n", i);
1712379bc100SJani Nikula 			break;
1713379bc100SJani Nikula 		}
1714379bc100SJani Nikula 
1715379bc100SJani Nikula 		/*
1716379bc100SJani Nikula 		 * Leave things enabled even if we failed to train FDI.
1717379bc100SJani Nikula 		 * Results in less fireworks from the state checker.
1718379bc100SJani Nikula 		 */
1719379bc100SJani Nikula 		if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
172047bdb1caSJani Nikula 			drm_err(&dev_priv->drm, "FDI link training failed!\n");
1721379bc100SJani Nikula 			break;
1722379bc100SJani Nikula 		}
1723379bc100SJani Nikula 
1724379bc100SJani Nikula 		rx_ctl_val &= ~FDI_RX_ENABLE;
1725f7960e7fSJani Nikula 		intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val);
1726f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A));
1727379bc100SJani Nikula 
1728f7960e7fSJani Nikula 		temp = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_E));
1729379bc100SJani Nikula 		temp &= ~DDI_BUF_CTL_ENABLE;
1730f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_CTL(PORT_E), temp);
1731f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, DDI_BUF_CTL(PORT_E));
1732379bc100SJani Nikula 
1733379bc100SJani Nikula 		/* Disable DP_TP_CTL and FDI_RX_CTL and retry */
1734f7960e7fSJani Nikula 		temp = intel_de_read(dev_priv, DP_TP_CTL(PORT_E));
1735379bc100SJani Nikula 		temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1736379bc100SJani Nikula 		temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
1737f7960e7fSJani Nikula 		intel_de_write(dev_priv, DP_TP_CTL(PORT_E), temp);
1738f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, DP_TP_CTL(PORT_E));
1739379bc100SJani Nikula 
1740379bc100SJani Nikula 		intel_wait_ddi_buf_idle(dev_priv, PORT_E);
1741379bc100SJani Nikula 
1742379bc100SJani Nikula 		/* Reset FDI_RX_MISC pwrdn lanes */
1743f7960e7fSJani Nikula 		temp = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A));
1744379bc100SJani Nikula 		temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1745379bc100SJani Nikula 		temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1746f7960e7fSJani Nikula 		intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), temp);
1747f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, FDI_RX_MISC(PIPE_A));
1748379bc100SJani Nikula 	}
1749379bc100SJani Nikula 
1750379bc100SJani Nikula 	/* Enable normal pixel sending for FDI */
1751f7960e7fSJani Nikula 	intel_de_write(dev_priv, DP_TP_CTL(PORT_E),
17527db8736dSVille Syrjälä 		       DP_TP_CTL_FDI_AUTOTRAIN |
17537db8736dSVille Syrjälä 		       DP_TP_CTL_LINK_TRAIN_NORMAL |
17547db8736dSVille Syrjälä 		       DP_TP_CTL_ENHANCED_FRAME_ENABLE |
17557db8736dSVille Syrjälä 		       DP_TP_CTL_ENABLE);
1756379bc100SJani Nikula }
1757379bc100SJani Nikula 
1758a621860aSVille Syrjälä static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder,
1759a621860aSVille Syrjälä 				      const struct intel_crtc_state *crtc_state)
1760379bc100SJani Nikula {
1761b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
17627801f3b7SLucas De Marchi 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1763379bc100SJani Nikula 
17647801f3b7SLucas De Marchi 	intel_dp->DP = dig_port->saved_port_bits |
1765379bc100SJani Nikula 		DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
1766a621860aSVille Syrjälä 	intel_dp->DP |= DDI_PORT_WIDTH(crtc_state->lane_count);
1767379bc100SJani Nikula }
1768379bc100SJani Nikula 
1769379bc100SJani Nikula static int icl_calc_tbt_pll_link(struct drm_i915_private *dev_priv,
1770379bc100SJani Nikula 				 enum port port)
1771379bc100SJani Nikula {
1772f7960e7fSJani Nikula 	u32 val = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
1773379bc100SJani Nikula 
1774379bc100SJani Nikula 	switch (val) {
1775379bc100SJani Nikula 	case DDI_CLK_SEL_NONE:
1776379bc100SJani Nikula 		return 0;
1777379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_162:
1778379bc100SJani Nikula 		return 162000;
1779379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_270:
1780379bc100SJani Nikula 		return 270000;
1781379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_540:
1782379bc100SJani Nikula 		return 540000;
1783379bc100SJani Nikula 	case DDI_CLK_SEL_TBT_810:
1784379bc100SJani Nikula 		return 810000;
1785379bc100SJani Nikula 	default:
1786379bc100SJani Nikula 		MISSING_CASE(val);
1787379bc100SJani Nikula 		return 0;
1788379bc100SJani Nikula 	}
1789379bc100SJani Nikula }
1790379bc100SJani Nikula 
1791379bc100SJani Nikula static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
1792379bc100SJani Nikula {
1793379bc100SJani Nikula 	int dotclock;
1794379bc100SJani Nikula 
1795379bc100SJani Nikula 	if (pipe_config->has_pch_encoder)
1796379bc100SJani Nikula 		dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1797379bc100SJani Nikula 						    &pipe_config->fdi_m_n);
1798379bc100SJani Nikula 	else if (intel_crtc_has_dp_encoder(pipe_config))
1799379bc100SJani Nikula 		dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1800379bc100SJani Nikula 						    &pipe_config->dp_m_n);
18012969a78aSImre Deak 	else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
18022969a78aSImre Deak 		dotclock = pipe_config->port_clock * 24 / pipe_config->pipe_bpp;
1803379bc100SJani Nikula 	else
1804379bc100SJani Nikula 		dotclock = pipe_config->port_clock;
1805379bc100SJani Nikula 
1806379bc100SJani Nikula 	if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
1807379bc100SJani Nikula 	    !intel_crtc_has_dp_encoder(pipe_config))
1808379bc100SJani Nikula 		dotclock *= 2;
1809379bc100SJani Nikula 
1810379bc100SJani Nikula 	if (pipe_config->pixel_multiplier)
1811379bc100SJani Nikula 		dotclock /= pipe_config->pixel_multiplier;
1812379bc100SJani Nikula 
18131326a92cSMaarten Lankhorst 	pipe_config->hw.adjusted_mode.crtc_clock = dotclock;
1814379bc100SJani Nikula }
1815379bc100SJani Nikula 
1816379bc100SJani Nikula static void intel_ddi_clock_get(struct intel_encoder *encoder,
1817379bc100SJani Nikula 				struct intel_crtc_state *pipe_config)
1818379bc100SJani Nikula {
1819379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
182056ed441aSMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
1821379bc100SJani Nikula 
182256ed441aSMatt Roper 	if (intel_phy_is_tc(dev_priv, phy) &&
182345e4728bSImre Deak 	    intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll) ==
182445e4728bSImre Deak 	    DPLL_ID_ICL_TBTPLL)
182545e4728bSImre Deak 		pipe_config->port_clock = icl_calc_tbt_pll_link(dev_priv,
182645e4728bSImre Deak 								encoder->port);
182745e4728bSImre Deak 	else
1828b953eb21SImre Deak 		pipe_config->port_clock =
18293749de07SVille Syrjälä 			intel_dpll_get_freq(dev_priv, pipe_config->shared_dpll,
18303749de07SVille Syrjälä 					    &pipe_config->dpll_hw_state);
183145e4728bSImre Deak 
183245e4728bSImre Deak 	ddi_dotclock_get(pipe_config);
1833379bc100SJani Nikula }
1834379bc100SJani Nikula 
18350c06fa15SGwan-gyeong Mun void intel_ddi_set_dp_msa(const struct intel_crtc_state *crtc_state,
18360c06fa15SGwan-gyeong Mun 			  const struct drm_connector_state *conn_state)
1837379bc100SJani Nikula {
18382225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1839379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1840379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1841379bc100SJani Nikula 	u32 temp;
1842379bc100SJani Nikula 
1843379bc100SJani Nikula 	if (!intel_crtc_has_dp_encoder(crtc_state))
1844379bc100SJani Nikula 		return;
1845379bc100SJani Nikula 
18461de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder));
1847379bc100SJani Nikula 
18483e706dffSVille Syrjälä 	temp = DP_MSA_MISC_SYNC_CLOCK;
1849379bc100SJani Nikula 
1850379bc100SJani Nikula 	switch (crtc_state->pipe_bpp) {
1851379bc100SJani Nikula 	case 18:
18523e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_6_BPC;
1853379bc100SJani Nikula 		break;
1854379bc100SJani Nikula 	case 24:
18553e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_8_BPC;
1856379bc100SJani Nikula 		break;
1857379bc100SJani Nikula 	case 30:
18583e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_10_BPC;
1859379bc100SJani Nikula 		break;
1860379bc100SJani Nikula 	case 36:
18613e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_12_BPC;
1862379bc100SJani Nikula 		break;
1863379bc100SJani Nikula 	default:
1864379bc100SJani Nikula 		MISSING_CASE(crtc_state->pipe_bpp);
1865379bc100SJani Nikula 		break;
1866379bc100SJani Nikula 	}
1867379bc100SJani Nikula 
1868cae154fcSVille Syrjälä 	/* nonsense combination */
18691de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
1870cae154fcSVille Syrjälä 		    crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
1871cae154fcSVille Syrjälä 
1872cae154fcSVille Syrjälä 	if (crtc_state->limited_color_range)
18733e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_COLOR_CEA_RGB;
1874cae154fcSVille Syrjälä 
1875379bc100SJani Nikula 	/*
1876379bc100SJani Nikula 	 * As per DP 1.2 spec section 2.3.4.3 while sending
1877379bc100SJani Nikula 	 * YCBCR 444 signals we should program MSA MISC1/0 fields with
1878646d3dc8SVille Syrjälä 	 * colorspace information.
1879379bc100SJani Nikula 	 */
1880379bc100SJani Nikula 	if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
18813e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_COLOR_YCBCR_444_BT709;
1882646d3dc8SVille Syrjälä 
1883379bc100SJani Nikula 	/*
1884379bc100SJani Nikula 	 * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication
1885379bc100SJani Nikula 	 * of Color Encoding Format and Content Color Gamut] while sending
18860c06fa15SGwan-gyeong Mun 	 * YCBCR 420, HDR BT.2020 signals we should program MSA MISC1 fields
18870c06fa15SGwan-gyeong Mun 	 * which indicate VSC SDP for the Pixel Encoding/Colorimetry Format.
1888379bc100SJani Nikula 	 */
1889bd8c9ccaSGwan-gyeong Mun 	if (intel_dp_needs_vsc_sdp(crtc_state, conn_state))
18903e706dffSVille Syrjälä 		temp |= DP_MSA_MISC_COLOR_VSC_SDP;
18910c06fa15SGwan-gyeong Mun 
1892f7960e7fSJani Nikula 	intel_de_write(dev_priv, TRANS_MSA_MISC(cpu_transcoder), temp);
1893379bc100SJani Nikula }
1894379bc100SJani Nikula 
1895dc5b8ed5SVille Syrjälä static u32 bdw_trans_port_sync_master_select(enum transcoder master_transcoder)
1896dc5b8ed5SVille Syrjälä {
1897dc5b8ed5SVille Syrjälä 	if (master_transcoder == TRANSCODER_EDP)
1898dc5b8ed5SVille Syrjälä 		return 0;
1899dc5b8ed5SVille Syrjälä 	else
1900dc5b8ed5SVille Syrjälä 		return master_transcoder + 1;
1901dc5b8ed5SVille Syrjälä }
1902dc5b8ed5SVille Syrjälä 
190399389390SJosé Roberto de Souza /*
190499389390SJosé Roberto de Souza  * Returns the TRANS_DDI_FUNC_CTL value based on CRTC state.
190599389390SJosé Roberto de Souza  *
190699389390SJosé Roberto de Souza  * Only intended to be used by intel_ddi_enable_transcoder_func() and
190799389390SJosé Roberto de Souza  * intel_ddi_config_transcoder_func().
190899389390SJosé Roberto de Souza  */
190999389390SJosé Roberto de Souza static u32
1910eed22a46SVille Syrjälä intel_ddi_transcoder_func_reg_val_get(struct intel_encoder *encoder,
1911eed22a46SVille Syrjälä 				      const struct intel_crtc_state *crtc_state)
1912379bc100SJani Nikula {
19132225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1914379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1915379bc100SJani Nikula 	enum pipe pipe = crtc->pipe;
1916379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1917379bc100SJani Nikula 	enum port port = encoder->port;
1918379bc100SJani Nikula 	u32 temp;
1919379bc100SJani Nikula 
1920379bc100SJani Nikula 	/* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1921379bc100SJani Nikula 	temp = TRANS_DDI_FUNC_ENABLE;
1922df16b636SMahesh Kumar 	if (INTEL_GEN(dev_priv) >= 12)
1923df16b636SMahesh Kumar 		temp |= TGL_TRANS_DDI_SELECT_PORT(port);
1924df16b636SMahesh Kumar 	else
1925379bc100SJani Nikula 		temp |= TRANS_DDI_SELECT_PORT(port);
1926379bc100SJani Nikula 
1927379bc100SJani Nikula 	switch (crtc_state->pipe_bpp) {
1928379bc100SJani Nikula 	case 18:
1929379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_6;
1930379bc100SJani Nikula 		break;
1931379bc100SJani Nikula 	case 24:
1932379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_8;
1933379bc100SJani Nikula 		break;
1934379bc100SJani Nikula 	case 30:
1935379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_10;
1936379bc100SJani Nikula 		break;
1937379bc100SJani Nikula 	case 36:
1938379bc100SJani Nikula 		temp |= TRANS_DDI_BPC_12;
1939379bc100SJani Nikula 		break;
1940379bc100SJani Nikula 	default:
1941379bc100SJani Nikula 		BUG();
1942379bc100SJani Nikula 	}
1943379bc100SJani Nikula 
19441326a92cSMaarten Lankhorst 	if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
1945379bc100SJani Nikula 		temp |= TRANS_DDI_PVSYNC;
19461326a92cSMaarten Lankhorst 	if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
1947379bc100SJani Nikula 		temp |= TRANS_DDI_PHSYNC;
1948379bc100SJani Nikula 
1949379bc100SJani Nikula 	if (cpu_transcoder == TRANSCODER_EDP) {
1950379bc100SJani Nikula 		switch (pipe) {
1951379bc100SJani Nikula 		case PIPE_A:
1952379bc100SJani Nikula 			/* On Haswell, can only use the always-on power well for
1953379bc100SJani Nikula 			 * eDP when not using the panel fitter, and when not
1954379bc100SJani Nikula 			 * using motion blur mitigation (which we don't
1955379bc100SJani Nikula 			 * support). */
1956379bc100SJani Nikula 			if (crtc_state->pch_pfit.force_thru)
1957379bc100SJani Nikula 				temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1958379bc100SJani Nikula 			else
1959379bc100SJani Nikula 				temp |= TRANS_DDI_EDP_INPUT_A_ON;
1960379bc100SJani Nikula 			break;
1961379bc100SJani Nikula 		case PIPE_B:
1962379bc100SJani Nikula 			temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1963379bc100SJani Nikula 			break;
1964379bc100SJani Nikula 		case PIPE_C:
1965379bc100SJani Nikula 			temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1966379bc100SJani Nikula 			break;
1967379bc100SJani Nikula 		default:
1968379bc100SJani Nikula 			BUG();
1969379bc100SJani Nikula 			break;
1970379bc100SJani Nikula 		}
1971379bc100SJani Nikula 	}
1972379bc100SJani Nikula 
1973379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
1974379bc100SJani Nikula 		if (crtc_state->has_hdmi_sink)
1975379bc100SJani Nikula 			temp |= TRANS_DDI_MODE_SELECT_HDMI;
1976379bc100SJani Nikula 		else
1977379bc100SJani Nikula 			temp |= TRANS_DDI_MODE_SELECT_DVI;
1978379bc100SJani Nikula 
1979379bc100SJani Nikula 		if (crtc_state->hdmi_scrambling)
1980379bc100SJani Nikula 			temp |= TRANS_DDI_HDMI_SCRAMBLING;
1981379bc100SJani Nikula 		if (crtc_state->hdmi_high_tmds_clock_ratio)
1982379bc100SJani Nikula 			temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
1983379bc100SJani Nikula 	} else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
1984379bc100SJani Nikula 		temp |= TRANS_DDI_MODE_SELECT_FDI;
1985379bc100SJani Nikula 		temp |= (crtc_state->fdi_lanes - 1) << 1;
1986379bc100SJani Nikula 	} else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
1987379bc100SJani Nikula 		temp |= TRANS_DDI_MODE_SELECT_DP_MST;
1988379bc100SJani Nikula 		temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
1989b3545e08SLucas De Marchi 
19906671c367SJosé Roberto de Souza 		if (INTEL_GEN(dev_priv) >= 12) {
19916671c367SJosé Roberto de Souza 			enum transcoder master;
19926671c367SJosé Roberto de Souza 
19936671c367SJosé Roberto de Souza 			master = crtc_state->mst_master_transcoder;
19941de143ccSPankaj Bharadiya 			drm_WARN_ON(&dev_priv->drm,
19951de143ccSPankaj Bharadiya 				    master == INVALID_TRANSCODER);
19966671c367SJosé Roberto de Souza 			temp |= TRANS_DDI_MST_TRANSPORT_SELECT(master);
19976671c367SJosé Roberto de Souza 		}
1998379bc100SJani Nikula 	} else {
1999379bc100SJani Nikula 		temp |= TRANS_DDI_MODE_SELECT_DP_SST;
2000379bc100SJani Nikula 		temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
2001379bc100SJani Nikula 	}
2002379bc100SJani Nikula 
2003dc5b8ed5SVille Syrjälä 	if (IS_GEN_RANGE(dev_priv, 8, 10) &&
2004dc5b8ed5SVille Syrjälä 	    crtc_state->master_transcoder != INVALID_TRANSCODER) {
2005dc5b8ed5SVille Syrjälä 		u8 master_select =
2006dc5b8ed5SVille Syrjälä 			bdw_trans_port_sync_master_select(crtc_state->master_transcoder);
2007dc5b8ed5SVille Syrjälä 
2008dc5b8ed5SVille Syrjälä 		temp |= TRANS_DDI_PORT_SYNC_ENABLE |
2009dc5b8ed5SVille Syrjälä 			TRANS_DDI_PORT_SYNC_MASTER_SELECT(master_select);
2010dc5b8ed5SVille Syrjälä 	}
2011dc5b8ed5SVille Syrjälä 
201299389390SJosé Roberto de Souza 	return temp;
201399389390SJosé Roberto de Souza }
201499389390SJosé Roberto de Souza 
2015eed22a46SVille Syrjälä void intel_ddi_enable_transcoder_func(struct intel_encoder *encoder,
2016eed22a46SVille Syrjälä 				      const struct intel_crtc_state *crtc_state)
201799389390SJosé Roberto de Souza {
20182225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
201999389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
202099389390SJosé Roberto de Souza 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
202199389390SJosé Roberto de Souza 
2022589a4cd6SVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 11) {
2023589a4cd6SVille Syrjälä 		enum transcoder master_transcoder = crtc_state->master_transcoder;
2024589a4cd6SVille Syrjälä 		u32 ctl2 = 0;
2025589a4cd6SVille Syrjälä 
2026589a4cd6SVille Syrjälä 		if (master_transcoder != INVALID_TRANSCODER) {
2027dc5b8ed5SVille Syrjälä 			u8 master_select =
2028dc5b8ed5SVille Syrjälä 				bdw_trans_port_sync_master_select(master_transcoder);
2029589a4cd6SVille Syrjälä 
2030589a4cd6SVille Syrjälä 			ctl2 |= PORT_SYNC_MODE_ENABLE |
2031d4d7d9caSVille Syrjälä 				PORT_SYNC_MODE_MASTER_SELECT(master_select);
2032589a4cd6SVille Syrjälä 		}
2033589a4cd6SVille Syrjälä 
2034589a4cd6SVille Syrjälä 		intel_de_write(dev_priv,
2035589a4cd6SVille Syrjälä 			       TRANS_DDI_FUNC_CTL2(cpu_transcoder), ctl2);
2036589a4cd6SVille Syrjälä 	}
2037589a4cd6SVille Syrjälä 
2038580fbdc5SImre Deak 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder),
2039580fbdc5SImre Deak 		       intel_ddi_transcoder_func_reg_val_get(encoder,
2040580fbdc5SImre Deak 							     crtc_state));
204199389390SJosé Roberto de Souza }
204299389390SJosé Roberto de Souza 
204399389390SJosé Roberto de Souza /*
204499389390SJosé Roberto de Souza  * Same as intel_ddi_enable_transcoder_func(), but it does not set the enable
204599389390SJosé Roberto de Souza  * bit.
204699389390SJosé Roberto de Souza  */
204799389390SJosé Roberto de Souza static void
2048eed22a46SVille Syrjälä intel_ddi_config_transcoder_func(struct intel_encoder *encoder,
2049eed22a46SVille Syrjälä 				 const struct intel_crtc_state *crtc_state)
205099389390SJosé Roberto de Souza {
20512225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
205299389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
205399389390SJosé Roberto de Souza 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2054589a4cd6SVille Syrjälä 	u32 ctl;
205599389390SJosé Roberto de Souza 
2056eed22a46SVille Syrjälä 	ctl = intel_ddi_transcoder_func_reg_val_get(encoder, crtc_state);
2057589a4cd6SVille Syrjälä 	ctl &= ~TRANS_DDI_FUNC_ENABLE;
2058589a4cd6SVille Syrjälä 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl);
2059379bc100SJani Nikula }
2060379bc100SJani Nikula 
2061379bc100SJani Nikula void intel_ddi_disable_transcoder_func(const struct intel_crtc_state *crtc_state)
2062379bc100SJani Nikula {
20632225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2064379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2065379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2066589a4cd6SVille Syrjälä 	u32 ctl;
2067c59053dcSJosé Roberto de Souza 
2068589a4cd6SVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 11)
2069589a4cd6SVille Syrjälä 		intel_de_write(dev_priv,
2070589a4cd6SVille Syrjälä 			       TRANS_DDI_FUNC_CTL2(cpu_transcoder), 0);
2071589a4cd6SVille Syrjälä 
2072589a4cd6SVille Syrjälä 	ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
2073dc5b8ed5SVille Syrjälä 
20741cfcdbf3SSean Paul 	drm_WARN_ON(crtc->base.dev, ctl & TRANS_DDI_HDCP_SIGNALLING);
20751cfcdbf3SSean Paul 
2076589a4cd6SVille Syrjälä 	ctl &= ~TRANS_DDI_FUNC_ENABLE;
2077379bc100SJani Nikula 
2078dc5b8ed5SVille Syrjälä 	if (IS_GEN_RANGE(dev_priv, 8, 10))
2079dc5b8ed5SVille Syrjälä 		ctl &= ~(TRANS_DDI_PORT_SYNC_ENABLE |
2080dc5b8ed5SVille Syrjälä 			 TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK);
2081dc5b8ed5SVille Syrjälä 
2082df16b636SMahesh Kumar 	if (INTEL_GEN(dev_priv) >= 12) {
2083919e4f07SJosé Roberto de Souza 		if (!intel_dp_mst_is_master_trans(crtc_state)) {
2084589a4cd6SVille Syrjälä 			ctl &= ~(TGL_TRANS_DDI_PORT_MASK |
2085919e4f07SJosé Roberto de Souza 				 TRANS_DDI_MODE_SELECT_MASK);
2086919e4f07SJosé Roberto de Souza 		}
2087df16b636SMahesh Kumar 	} else {
2088589a4cd6SVille Syrjälä 		ctl &= ~(TRANS_DDI_PORT_MASK | TRANS_DDI_MODE_SELECT_MASK);
2089df16b636SMahesh Kumar 	}
2090dc5b8ed5SVille Syrjälä 
2091589a4cd6SVille Syrjälä 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl);
2092379bc100SJani Nikula 
2093379bc100SJani Nikula 	if (dev_priv->quirks & QUIRK_INCREASE_DDI_DISABLED_TIME &&
2094379bc100SJani Nikula 	    intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
209547bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
209647bdb1caSJani Nikula 			    "Quirk Increase DDI disabled time\n");
2097379bc100SJani Nikula 		/* Quirk time at 100ms for reliable operation */
2098379bc100SJani Nikula 		msleep(100);
2099379bc100SJani Nikula 	}
2100379bc100SJani Nikula }
2101379bc100SJani Nikula 
2102379bc100SJani Nikula int intel_ddi_toggle_hdcp_signalling(struct intel_encoder *intel_encoder,
21030b9c9290SSean Paul 				     enum transcoder cpu_transcoder,
2104379bc100SJani Nikula 				     bool enable)
2105379bc100SJani Nikula {
2106379bc100SJani Nikula 	struct drm_device *dev = intel_encoder->base.dev;
2107379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
2108379bc100SJani Nikula 	intel_wakeref_t wakeref;
2109379bc100SJani Nikula 	int ret = 0;
2110379bc100SJani Nikula 	u32 tmp;
2111379bc100SJani Nikula 
2112379bc100SJani Nikula 	wakeref = intel_display_power_get_if_enabled(dev_priv,
2113379bc100SJani Nikula 						     intel_encoder->power_domain);
21141de143ccSPankaj Bharadiya 	if (drm_WARN_ON(dev, !wakeref))
2115379bc100SJani Nikula 		return -ENXIO;
2116379bc100SJani Nikula 
21170b9c9290SSean Paul 	tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
2118379bc100SJani Nikula 	if (enable)
2119379bc100SJani Nikula 		tmp |= TRANS_DDI_HDCP_SIGNALLING;
2120379bc100SJani Nikula 	else
2121379bc100SJani Nikula 		tmp &= ~TRANS_DDI_HDCP_SIGNALLING;
21220b9c9290SSean Paul 	intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), tmp);
2123379bc100SJani Nikula 	intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref);
2124379bc100SJani Nikula 	return ret;
2125379bc100SJani Nikula }
2126379bc100SJani Nikula 
2127379bc100SJani Nikula bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
2128379bc100SJani Nikula {
2129379bc100SJani Nikula 	struct drm_device *dev = intel_connector->base.dev;
2130379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
2131fa7edcd2SVille Syrjälä 	struct intel_encoder *encoder = intel_attached_encoder(intel_connector);
2132379bc100SJani Nikula 	int type = intel_connector->base.connector_type;
2133379bc100SJani Nikula 	enum port port = encoder->port;
2134379bc100SJani Nikula 	enum transcoder cpu_transcoder;
2135379bc100SJani Nikula 	intel_wakeref_t wakeref;
2136379bc100SJani Nikula 	enum pipe pipe = 0;
2137379bc100SJani Nikula 	u32 tmp;
2138379bc100SJani Nikula 	bool ret;
2139379bc100SJani Nikula 
2140379bc100SJani Nikula 	wakeref = intel_display_power_get_if_enabled(dev_priv,
2141379bc100SJani Nikula 						     encoder->power_domain);
2142379bc100SJani Nikula 	if (!wakeref)
2143379bc100SJani Nikula 		return false;
2144379bc100SJani Nikula 
2145379bc100SJani Nikula 	if (!encoder->get_hw_state(encoder, &pipe)) {
2146379bc100SJani Nikula 		ret = false;
2147379bc100SJani Nikula 		goto out;
2148379bc100SJani Nikula 	}
2149379bc100SJani Nikula 
215010cf8e75SVille Syrjälä 	if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A)
2151379bc100SJani Nikula 		cpu_transcoder = TRANSCODER_EDP;
2152379bc100SJani Nikula 	else
2153379bc100SJani Nikula 		cpu_transcoder = (enum transcoder) pipe;
2154379bc100SJani Nikula 
2155f7960e7fSJani Nikula 	tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
2156379bc100SJani Nikula 
2157379bc100SJani Nikula 	switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
2158379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_HDMI:
2159379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DVI:
2160379bc100SJani Nikula 		ret = type == DRM_MODE_CONNECTOR_HDMIA;
2161379bc100SJani Nikula 		break;
2162379bc100SJani Nikula 
2163379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_SST:
2164379bc100SJani Nikula 		ret = type == DRM_MODE_CONNECTOR_eDP ||
2165379bc100SJani Nikula 		      type == DRM_MODE_CONNECTOR_DisplayPort;
2166379bc100SJani Nikula 		break;
2167379bc100SJani Nikula 
2168379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_MST:
2169379bc100SJani Nikula 		/* if the transcoder is in MST state then
2170379bc100SJani Nikula 		 * connector isn't connected */
2171379bc100SJani Nikula 		ret = false;
2172379bc100SJani Nikula 		break;
2173379bc100SJani Nikula 
2174379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_FDI:
2175379bc100SJani Nikula 		ret = type == DRM_MODE_CONNECTOR_VGA;
2176379bc100SJani Nikula 		break;
2177379bc100SJani Nikula 
2178379bc100SJani Nikula 	default:
2179379bc100SJani Nikula 		ret = false;
2180379bc100SJani Nikula 		break;
2181379bc100SJani Nikula 	}
2182379bc100SJani Nikula 
2183379bc100SJani Nikula out:
2184379bc100SJani Nikula 	intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
2185379bc100SJani Nikula 
2186379bc100SJani Nikula 	return ret;
2187379bc100SJani Nikula }
2188379bc100SJani Nikula 
2189379bc100SJani Nikula static void intel_ddi_get_encoder_pipes(struct intel_encoder *encoder,
2190379bc100SJani Nikula 					u8 *pipe_mask, bool *is_dp_mst)
2191379bc100SJani Nikula {
2192379bc100SJani Nikula 	struct drm_device *dev = encoder->base.dev;
2193379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
2194379bc100SJani Nikula 	enum port port = encoder->port;
2195379bc100SJani Nikula 	intel_wakeref_t wakeref;
2196379bc100SJani Nikula 	enum pipe p;
2197379bc100SJani Nikula 	u32 tmp;
2198379bc100SJani Nikula 	u8 mst_pipe_mask;
2199379bc100SJani Nikula 
2200379bc100SJani Nikula 	*pipe_mask = 0;
2201379bc100SJani Nikula 	*is_dp_mst = false;
2202379bc100SJani Nikula 
2203379bc100SJani Nikula 	wakeref = intel_display_power_get_if_enabled(dev_priv,
2204379bc100SJani Nikula 						     encoder->power_domain);
2205379bc100SJani Nikula 	if (!wakeref)
2206379bc100SJani Nikula 		return;
2207379bc100SJani Nikula 
2208f7960e7fSJani Nikula 	tmp = intel_de_read(dev_priv, DDI_BUF_CTL(port));
2209379bc100SJani Nikula 	if (!(tmp & DDI_BUF_CTL_ENABLE))
2210379bc100SJani Nikula 		goto out;
2211379bc100SJani Nikula 
221210cf8e75SVille Syrjälä 	if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) {
2213f7960e7fSJani Nikula 		tmp = intel_de_read(dev_priv,
2214f7960e7fSJani Nikula 				    TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
2215379bc100SJani Nikula 
2216379bc100SJani Nikula 		switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
2217379bc100SJani Nikula 		default:
2218379bc100SJani Nikula 			MISSING_CASE(tmp & TRANS_DDI_EDP_INPUT_MASK);
2219df561f66SGustavo A. R. Silva 			fallthrough;
2220379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_A_ON:
2221379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_A_ONOFF:
2222379bc100SJani Nikula 			*pipe_mask = BIT(PIPE_A);
2223379bc100SJani Nikula 			break;
2224379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_B_ONOFF:
2225379bc100SJani Nikula 			*pipe_mask = BIT(PIPE_B);
2226379bc100SJani Nikula 			break;
2227379bc100SJani Nikula 		case TRANS_DDI_EDP_INPUT_C_ONOFF:
2228379bc100SJani Nikula 			*pipe_mask = BIT(PIPE_C);
2229379bc100SJani Nikula 			break;
2230379bc100SJani Nikula 		}
2231379bc100SJani Nikula 
2232379bc100SJani Nikula 		goto out;
2233379bc100SJani Nikula 	}
2234379bc100SJani Nikula 
2235379bc100SJani Nikula 	mst_pipe_mask = 0;
2236379bc100SJani Nikula 	for_each_pipe(dev_priv, p) {
2237379bc100SJani Nikula 		enum transcoder cpu_transcoder = (enum transcoder)p;
2238df16b636SMahesh Kumar 		unsigned int port_mask, ddi_select;
22396aa3bef1SJosé Roberto de Souza 		intel_wakeref_t trans_wakeref;
22406aa3bef1SJosé Roberto de Souza 
22416aa3bef1SJosé Roberto de Souza 		trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
22426aa3bef1SJosé Roberto de Souza 								   POWER_DOMAIN_TRANSCODER(cpu_transcoder));
22436aa3bef1SJosé Roberto de Souza 		if (!trans_wakeref)
22446aa3bef1SJosé Roberto de Souza 			continue;
2245df16b636SMahesh Kumar 
2246df16b636SMahesh Kumar 		if (INTEL_GEN(dev_priv) >= 12) {
2247df16b636SMahesh Kumar 			port_mask = TGL_TRANS_DDI_PORT_MASK;
2248df16b636SMahesh Kumar 			ddi_select = TGL_TRANS_DDI_SELECT_PORT(port);
2249df16b636SMahesh Kumar 		} else {
2250df16b636SMahesh Kumar 			port_mask = TRANS_DDI_PORT_MASK;
2251df16b636SMahesh Kumar 			ddi_select = TRANS_DDI_SELECT_PORT(port);
2252df16b636SMahesh Kumar 		}
2253379bc100SJani Nikula 
2254f7960e7fSJani Nikula 		tmp = intel_de_read(dev_priv,
2255f7960e7fSJani Nikula 				    TRANS_DDI_FUNC_CTL(cpu_transcoder));
22566aa3bef1SJosé Roberto de Souza 		intel_display_power_put(dev_priv, POWER_DOMAIN_TRANSCODER(cpu_transcoder),
22576aa3bef1SJosé Roberto de Souza 					trans_wakeref);
2258379bc100SJani Nikula 
2259df16b636SMahesh Kumar 		if ((tmp & port_mask) != ddi_select)
2260379bc100SJani Nikula 			continue;
2261379bc100SJani Nikula 
2262379bc100SJani Nikula 		if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
2263379bc100SJani Nikula 		    TRANS_DDI_MODE_SELECT_DP_MST)
2264379bc100SJani Nikula 			mst_pipe_mask |= BIT(p);
2265379bc100SJani Nikula 
2266379bc100SJani Nikula 		*pipe_mask |= BIT(p);
2267379bc100SJani Nikula 	}
2268379bc100SJani Nikula 
2269379bc100SJani Nikula 	if (!*pipe_mask)
227047bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
227147bdb1caSJani Nikula 			    "No pipe for [ENCODER:%d:%s] found\n",
227266a990ddSVille Syrjälä 			    encoder->base.base.id, encoder->base.name);
2273379bc100SJani Nikula 
2274379bc100SJani Nikula 	if (!mst_pipe_mask && hweight8(*pipe_mask) > 1) {
227547bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
227647bdb1caSJani Nikula 			    "Multiple pipes for [ENCODER:%d:%s] (pipe_mask %02x)\n",
227766a990ddSVille Syrjälä 			    encoder->base.base.id, encoder->base.name,
227866a990ddSVille Syrjälä 			    *pipe_mask);
2279379bc100SJani Nikula 		*pipe_mask = BIT(ffs(*pipe_mask) - 1);
2280379bc100SJani Nikula 	}
2281379bc100SJani Nikula 
2282379bc100SJani Nikula 	if (mst_pipe_mask && mst_pipe_mask != *pipe_mask)
228347bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
228447bdb1caSJani Nikula 			    "Conflicting MST and non-MST state for [ENCODER:%d:%s] (pipe_mask %02x mst_pipe_mask %02x)\n",
228566a990ddSVille Syrjälä 			    encoder->base.base.id, encoder->base.name,
228666a990ddSVille Syrjälä 			    *pipe_mask, mst_pipe_mask);
2287379bc100SJani Nikula 	else
2288379bc100SJani Nikula 		*is_dp_mst = mst_pipe_mask;
2289379bc100SJani Nikula 
2290379bc100SJani Nikula out:
2291379bc100SJani Nikula 	if (*pipe_mask && IS_GEN9_LP(dev_priv)) {
2292f7960e7fSJani Nikula 		tmp = intel_de_read(dev_priv, BXT_PHY_CTL(port));
2293379bc100SJani Nikula 		if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK |
2294379bc100SJani Nikula 			    BXT_PHY_LANE_POWERDOWN_ACK |
2295379bc100SJani Nikula 			    BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
229647bdb1caSJani Nikula 			drm_err(&dev_priv->drm,
229747bdb1caSJani Nikula 				"[ENCODER:%d:%s] enabled but PHY powered down? (PHY_CTL %08x)\n",
229847bdb1caSJani Nikula 				encoder->base.base.id, encoder->base.name, tmp);
2299379bc100SJani Nikula 	}
2300379bc100SJani Nikula 
2301379bc100SJani Nikula 	intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
2302379bc100SJani Nikula }
2303379bc100SJani Nikula 
2304379bc100SJani Nikula bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
2305379bc100SJani Nikula 			    enum pipe *pipe)
2306379bc100SJani Nikula {
2307379bc100SJani Nikula 	u8 pipe_mask;
2308379bc100SJani Nikula 	bool is_mst;
2309379bc100SJani Nikula 
2310379bc100SJani Nikula 	intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst);
2311379bc100SJani Nikula 
2312379bc100SJani Nikula 	if (is_mst || !pipe_mask)
2313379bc100SJani Nikula 		return false;
2314379bc100SJani Nikula 
2315379bc100SJani Nikula 	*pipe = ffs(pipe_mask) - 1;
2316379bc100SJani Nikula 
2317379bc100SJani Nikula 	return true;
2318379bc100SJani Nikula }
2319379bc100SJani Nikula 
232081b55ef1SJani Nikula static enum intel_display_power_domain
2321379bc100SJani Nikula intel_ddi_main_link_aux_domain(struct intel_digital_port *dig_port)
2322379bc100SJani Nikula {
2323379bc100SJani Nikula 	/* CNL+ HW requires corresponding AUX IOs to be powered up for PSR with
2324379bc100SJani Nikula 	 * DC states enabled at the same time, while for driver initiated AUX
2325379bc100SJani Nikula 	 * transfers we need the same AUX IOs to be powered but with DC states
2326379bc100SJani Nikula 	 * disabled. Accordingly use the AUX power domain here which leaves DC
2327379bc100SJani Nikula 	 * states enabled.
2328379bc100SJani Nikula 	 * However, for non-A AUX ports the corresponding non-EDP transcoders
2329379bc100SJani Nikula 	 * would have already enabled power well 2 and DC_OFF. This means we can
2330379bc100SJani Nikula 	 * acquire a wider POWER_DOMAIN_AUX_{B,C,D,F} reference instead of a
2331379bc100SJani Nikula 	 * specific AUX_IO reference without powering up any extra wells.
2332379bc100SJani Nikula 	 * Note that PSR is enabled only on Port A even though this function
2333379bc100SJani Nikula 	 * returns the correct domain for other ports too.
2334379bc100SJani Nikula 	 */
2335379bc100SJani Nikula 	return dig_port->aux_ch == AUX_CH_A ? POWER_DOMAIN_AUX_IO_A :
2336379bc100SJani Nikula 					      intel_aux_power_domain(dig_port);
2337379bc100SJani Nikula }
2338379bc100SJani Nikula 
2339379bc100SJani Nikula static void intel_ddi_get_power_domains(struct intel_encoder *encoder,
2340379bc100SJani Nikula 					struct intel_crtc_state *crtc_state)
2341379bc100SJani Nikula {
2342379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2343379bc100SJani Nikula 	struct intel_digital_port *dig_port;
2344d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2345379bc100SJani Nikula 
2346379bc100SJani Nikula 	/*
2347379bc100SJani Nikula 	 * TODO: Add support for MST encoders. Atm, the following should never
2348379bc100SJani Nikula 	 * happen since fake-MST encoders don't set their get_power_domains()
2349379bc100SJani Nikula 	 * hook.
2350379bc100SJani Nikula 	 */
23511de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm,
23521de143ccSPankaj Bharadiya 			intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)))
2353379bc100SJani Nikula 		return;
2354379bc100SJani Nikula 
2355b7d02c3aSVille Syrjälä 	dig_port = enc_to_dig_port(encoder);
2356f77a2db2SImre Deak 
2357f77a2db2SImre Deak 	if (!intel_phy_is_tc(dev_priv, phy) ||
2358a4550977SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT) {
2359a4550977SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
2360a4550977SImre Deak 		dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
2361f77a2db2SImre Deak 								   dig_port->ddi_io_power_domain);
2362a4550977SImre Deak 	}
2363379bc100SJani Nikula 
2364379bc100SJani Nikula 	/*
2365379bc100SJani Nikula 	 * AUX power is only needed for (e)DP mode, and for HDMI mode on TC
2366379bc100SJani Nikula 	 * ports.
2367379bc100SJani Nikula 	 */
2368379bc100SJani Nikula 	if (intel_crtc_has_dp_encoder(crtc_state) ||
2369162e68e1SImre Deak 	    intel_phy_is_tc(dev_priv, phy)) {
2370162e68e1SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->aux_wakeref);
2371162e68e1SImre Deak 		dig_port->aux_wakeref =
2372379bc100SJani Nikula 			intel_display_power_get(dev_priv,
2373379bc100SJani Nikula 						intel_ddi_main_link_aux_domain(dig_port));
2374379bc100SJani Nikula 	}
2375162e68e1SImre Deak }
2376379bc100SJani Nikula 
237702a715c3SVille Syrjälä void intel_ddi_enable_pipe_clock(struct intel_encoder *encoder,
237802a715c3SVille Syrjälä 				 const struct intel_crtc_state *crtc_state)
2379379bc100SJani Nikula {
23802225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2381379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2382379bc100SJani Nikula 	enum port port = encoder->port;
2383379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2384379bc100SJani Nikula 
2385df16b636SMahesh Kumar 	if (cpu_transcoder != TRANSCODER_EDP) {
2386df16b636SMahesh Kumar 		if (INTEL_GEN(dev_priv) >= 12)
2387f7960e7fSJani Nikula 			intel_de_write(dev_priv,
2388f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
2389df16b636SMahesh Kumar 				       TGL_TRANS_CLK_SEL_PORT(port));
2390df16b636SMahesh Kumar 		else
2391f7960e7fSJani Nikula 			intel_de_write(dev_priv,
2392f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
2393379bc100SJani Nikula 				       TRANS_CLK_SEL_PORT(port));
2394379bc100SJani Nikula 	}
2395df16b636SMahesh Kumar }
2396379bc100SJani Nikula 
2397379bc100SJani Nikula void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
2398379bc100SJani Nikula {
23992225f3c6SMaarten Lankhorst 	struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2400379bc100SJani Nikula 	enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2401379bc100SJani Nikula 
2402df16b636SMahesh Kumar 	if (cpu_transcoder != TRANSCODER_EDP) {
2403df16b636SMahesh Kumar 		if (INTEL_GEN(dev_priv) >= 12)
2404f7960e7fSJani Nikula 			intel_de_write(dev_priv,
2405f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
2406df16b636SMahesh Kumar 				       TGL_TRANS_CLK_SEL_DISABLED);
2407df16b636SMahesh Kumar 		else
2408f7960e7fSJani Nikula 			intel_de_write(dev_priv,
2409f7960e7fSJani Nikula 				       TRANS_CLK_SEL(cpu_transcoder),
2410379bc100SJani Nikula 				       TRANS_CLK_SEL_DISABLED);
2411379bc100SJani Nikula 	}
2412df16b636SMahesh Kumar }
2413379bc100SJani Nikula 
2414379bc100SJani Nikula static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
2415379bc100SJani Nikula 				enum port port, u8 iboost)
2416379bc100SJani Nikula {
2417379bc100SJani Nikula 	u32 tmp;
2418379bc100SJani Nikula 
2419f7960e7fSJani Nikula 	tmp = intel_de_read(dev_priv, DISPIO_CR_TX_BMU_CR0);
2420379bc100SJani Nikula 	tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
2421379bc100SJani Nikula 	if (iboost)
2422379bc100SJani Nikula 		tmp |= iboost << BALANCE_LEG_SHIFT(port);
2423379bc100SJani Nikula 	else
2424379bc100SJani Nikula 		tmp |= BALANCE_LEG_DISABLE(port);
2425f7960e7fSJani Nikula 	intel_de_write(dev_priv, DISPIO_CR_TX_BMU_CR0, tmp);
2426379bc100SJani Nikula }
2427379bc100SJani Nikula 
2428379bc100SJani Nikula static void skl_ddi_set_iboost(struct intel_encoder *encoder,
2429a621860aSVille Syrjälä 			       const struct intel_crtc_state *crtc_state,
2430a621860aSVille Syrjälä 			       int level)
2431379bc100SJani Nikula {
24327801f3b7SLucas De Marchi 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
2433379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2434379bc100SJani Nikula 	u8 iboost;
2435379bc100SJani Nikula 
2436a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
243701a60883SJani Nikula 		iboost = intel_bios_hdmi_boost_level(encoder);
2438379bc100SJani Nikula 	else
2439605a1872SJani Nikula 		iboost = intel_bios_dp_boost_level(encoder);
2440379bc100SJani Nikula 
2441379bc100SJani Nikula 	if (iboost == 0) {
2442379bc100SJani Nikula 		const struct ddi_buf_trans *ddi_translations;
2443379bc100SJani Nikula 		int n_entries;
2444379bc100SJani Nikula 
2445a621860aSVille Syrjälä 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2446a8143150SJosé Roberto de Souza 			ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries);
2447a621860aSVille Syrjälä 		else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
2448a621860aSVille Syrjälä 			ddi_translations = intel_ddi_get_buf_trans_edp(encoder, &n_entries);
2449379bc100SJani Nikula 		else
2450a621860aSVille Syrjälä 			ddi_translations = intel_ddi_get_buf_trans_dp(encoder, &n_entries);
2451379bc100SJani Nikula 
24521de143ccSPankaj Bharadiya 		if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
2453379bc100SJani Nikula 			return;
24541de143ccSPankaj Bharadiya 		if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
2455379bc100SJani Nikula 			level = n_entries - 1;
2456379bc100SJani Nikula 
2457379bc100SJani Nikula 		iboost = ddi_translations[level].i_boost;
2458379bc100SJani Nikula 	}
2459379bc100SJani Nikula 
2460379bc100SJani Nikula 	/* Make sure that the requested I_boost is valid */
2461379bc100SJani Nikula 	if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
246247bdb1caSJani Nikula 		drm_err(&dev_priv->drm, "Invalid I_boost value %u\n", iboost);
2463379bc100SJani Nikula 		return;
2464379bc100SJani Nikula 	}
2465379bc100SJani Nikula 
2466f0e86e05SJosé Roberto de Souza 	_skl_ddi_set_iboost(dev_priv, encoder->port, iboost);
2467379bc100SJani Nikula 
2468f0e86e05SJosé Roberto de Souza 	if (encoder->port == PORT_A && dig_port->max_lanes == 4)
2469379bc100SJani Nikula 		_skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
2470379bc100SJani Nikula }
2471379bc100SJani Nikula 
2472379bc100SJani Nikula static void bxt_ddi_vswing_sequence(struct intel_encoder *encoder,
2473a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
2474a621860aSVille Syrjälä 				    int level)
2475379bc100SJani Nikula {
2476379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2477379bc100SJani Nikula 	const struct bxt_ddi_buf_trans *ddi_translations;
2478379bc100SJani Nikula 	enum port port = encoder->port;
2479379bc100SJani Nikula 	int n_entries;
2480379bc100SJani Nikula 
2481a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2482a8143150SJosé Roberto de Souza 		ddi_translations = bxt_get_buf_trans_hdmi(encoder, &n_entries);
2483a621860aSVille Syrjälä 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
2484a8143150SJosé Roberto de Souza 		ddi_translations = bxt_get_buf_trans_edp(encoder, &n_entries);
2485379bc100SJani Nikula 	else
2486a8143150SJosé Roberto de Souza 		ddi_translations = bxt_get_buf_trans_dp(encoder, &n_entries);
2487379bc100SJani Nikula 
24881de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
2489379bc100SJani Nikula 		return;
24901de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
2491379bc100SJani Nikula 		level = n_entries - 1;
2492379bc100SJani Nikula 
2493379bc100SJani Nikula 	bxt_ddi_phy_set_signal_level(dev_priv, port,
2494379bc100SJani Nikula 				     ddi_translations[level].margin,
2495379bc100SJani Nikula 				     ddi_translations[level].scale,
2496379bc100SJani Nikula 				     ddi_translations[level].enable,
2497379bc100SJani Nikula 				     ddi_translations[level].deemphasis);
2498379bc100SJani Nikula }
2499379bc100SJani Nikula 
2500a621860aSVille Syrjälä static u8 intel_ddi_dp_voltage_max(struct intel_dp *intel_dp,
2501a621860aSVille Syrjälä 				   const struct intel_crtc_state *crtc_state)
2502379bc100SJani Nikula {
250353de0a20SVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
2504379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2505379bc100SJani Nikula 	enum port port = encoder->port;
2506d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
2507379bc100SJani Nikula 	int n_entries;
2508379bc100SJani Nikula 
2509978c3e53SClinton A Taylor 	if (INTEL_GEN(dev_priv) >= 12) {
2510978c3e53SClinton A Taylor 		if (intel_phy_is_combo(dev_priv, phy))
2511a621860aSVille Syrjälä 			tgl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
2512978c3e53SClinton A Taylor 		else
2513a621860aSVille Syrjälä 			tgl_get_dkl_buf_trans(encoder, crtc_state, &n_entries);
2514978c3e53SClinton A Taylor 	} else if (INTEL_GEN(dev_priv) == 11) {
25151ba1014dSTejas Upadhyay 		if (IS_PLATFORM(dev_priv, INTEL_JASPERLAKE))
25161ba1014dSTejas Upadhyay 			jsl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
25171ba1014dSTejas Upadhyay 		else if (IS_PLATFORM(dev_priv, INTEL_ELKHARTLAKE))
2518a621860aSVille Syrjälä 			ehl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
2519b42d5a67SJosé Roberto de Souza 		else if (intel_phy_is_combo(dev_priv, phy))
2520a621860aSVille Syrjälä 			icl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
2521379bc100SJani Nikula 		else
2522a621860aSVille Syrjälä 			icl_get_mg_buf_trans(encoder, crtc_state, &n_entries);
2523379bc100SJani Nikula 	} else if (IS_CANNONLAKE(dev_priv)) {
2524a621860aSVille Syrjälä 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
2525a8143150SJosé Roberto de Souza 			cnl_get_buf_trans_edp(encoder, &n_entries);
2526379bc100SJani Nikula 		else
2527a8143150SJosé Roberto de Souza 			cnl_get_buf_trans_dp(encoder, &n_entries);
2528379bc100SJani Nikula 	} else if (IS_GEN9_LP(dev_priv)) {
2529a621860aSVille Syrjälä 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
2530a8143150SJosé Roberto de Souza 			bxt_get_buf_trans_edp(encoder, &n_entries);
2531379bc100SJani Nikula 		else
2532a8143150SJosé Roberto de Souza 			bxt_get_buf_trans_dp(encoder, &n_entries);
2533379bc100SJani Nikula 	} else {
2534a621860aSVille Syrjälä 		if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
2535f0e86e05SJosé Roberto de Souza 			intel_ddi_get_buf_trans_edp(encoder, &n_entries);
2536379bc100SJani Nikula 		else
2537f0e86e05SJosé Roberto de Souza 			intel_ddi_get_buf_trans_dp(encoder, &n_entries);
2538379bc100SJani Nikula 	}
2539379bc100SJani Nikula 
25401de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, n_entries < 1))
2541379bc100SJani Nikula 		n_entries = 1;
25421de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm,
25431de143ccSPankaj Bharadiya 			n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
2544379bc100SJani Nikula 		n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
2545379bc100SJani Nikula 
2546379bc100SJani Nikula 	return index_to_dp_signal_levels[n_entries - 1] &
2547379bc100SJani Nikula 		DP_TRAIN_VOLTAGE_SWING_MASK;
2548379bc100SJani Nikula }
2549379bc100SJani Nikula 
2550379bc100SJani Nikula /*
2551379bc100SJani Nikula  * We assume that the full set of pre-emphasis values can be
2552379bc100SJani Nikula  * used on all DDI platforms. Should that change we need to
2553379bc100SJani Nikula  * rethink this code.
2554379bc100SJani Nikula  */
255553de0a20SVille Syrjälä static u8 intel_ddi_dp_preemph_max(struct intel_dp *intel_dp)
2556379bc100SJani Nikula {
2557379bc100SJani Nikula 	return DP_TRAIN_PRE_EMPH_LEVEL_3;
2558379bc100SJani Nikula }
2559379bc100SJani Nikula 
2560379bc100SJani Nikula static void cnl_ddi_vswing_program(struct intel_encoder *encoder,
2561a621860aSVille Syrjälä 				   const struct intel_crtc_state *crtc_state,
2562a621860aSVille Syrjälä 				   int level)
2563379bc100SJani Nikula {
2564379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2565379bc100SJani Nikula 	const struct cnl_ddi_buf_trans *ddi_translations;
2566379bc100SJani Nikula 	enum port port = encoder->port;
2567379bc100SJani Nikula 	int n_entries, ln;
2568379bc100SJani Nikula 	u32 val;
2569379bc100SJani Nikula 
2570a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2571a8143150SJosé Roberto de Souza 		ddi_translations = cnl_get_buf_trans_hdmi(encoder, &n_entries);
2572a621860aSVille Syrjälä 	else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
2573a8143150SJosé Roberto de Souza 		ddi_translations = cnl_get_buf_trans_edp(encoder, &n_entries);
2574379bc100SJani Nikula 	else
2575a8143150SJosé Roberto de Souza 		ddi_translations = cnl_get_buf_trans_dp(encoder, &n_entries);
2576379bc100SJani Nikula 
25771de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations))
2578379bc100SJani Nikula 		return;
25791de143ccSPankaj Bharadiya 	if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries))
2580379bc100SJani Nikula 		level = n_entries - 1;
2581379bc100SJani Nikula 
2582379bc100SJani Nikula 	/* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */
2583f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
2584379bc100SJani Nikula 	val &= ~SCALING_MODE_SEL_MASK;
2585379bc100SJani Nikula 	val |= SCALING_MODE_SEL(2);
2586f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
2587379bc100SJani Nikula 
2588379bc100SJani Nikula 	/* Program PORT_TX_DW2 */
2589f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW2_LN0(port));
2590379bc100SJani Nikula 	val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
2591379bc100SJani Nikula 		 RCOMP_SCALAR_MASK);
2592379bc100SJani Nikula 	val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
2593379bc100SJani Nikula 	val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
2594379bc100SJani Nikula 	/* Rcomp scalar is fixed as 0x98 for every table entry */
2595379bc100SJani Nikula 	val |= RCOMP_SCALAR(0x98);
2596f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW2_GRP(port), val);
2597379bc100SJani Nikula 
2598379bc100SJani Nikula 	/* Program PORT_TX_DW4 */
2599379bc100SJani Nikula 	/* We cannot write to GRP. It would overrite individual loadgen */
2600379bc100SJani Nikula 	for (ln = 0; ln < 4; ln++) {
2601f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port));
2602379bc100SJani Nikula 		val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
2603379bc100SJani Nikula 			 CURSOR_COEFF_MASK);
2604379bc100SJani Nikula 		val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
2605379bc100SJani Nikula 		val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
2606379bc100SJani Nikula 		val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
2607f7960e7fSJani Nikula 		intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val);
2608379bc100SJani Nikula 	}
2609379bc100SJani Nikula 
2610379bc100SJani Nikula 	/* Program PORT_TX_DW5 */
2611379bc100SJani Nikula 	/* All DW5 values are fixed for every table entry */
2612f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
2613379bc100SJani Nikula 	val &= ~RTERM_SELECT_MASK;
2614379bc100SJani Nikula 	val |= RTERM_SELECT(6);
2615379bc100SJani Nikula 	val |= TAP3_DISABLE;
2616f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
2617379bc100SJani Nikula 
2618379bc100SJani Nikula 	/* Program PORT_TX_DW7 */
2619f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW7_LN0(port));
2620379bc100SJani Nikula 	val &= ~N_SCALAR_MASK;
2621379bc100SJani Nikula 	val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
2622f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW7_GRP(port), val);
2623379bc100SJani Nikula }
2624379bc100SJani Nikula 
2625379bc100SJani Nikula static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder,
2626a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
2627a621860aSVille Syrjälä 				    int level)
2628379bc100SJani Nikula {
2629379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2630379bc100SJani Nikula 	enum port port = encoder->port;
2631379bc100SJani Nikula 	int width, rate, ln;
2632379bc100SJani Nikula 	u32 val;
2633379bc100SJani Nikula 
2634a621860aSVille Syrjälä 	width = crtc_state->lane_count;
2635a621860aSVille Syrjälä 	rate = crtc_state->port_clock;
2636379bc100SJani Nikula 
2637379bc100SJani Nikula 	/*
2638379bc100SJani Nikula 	 * 1. If port type is eDP or DP,
2639379bc100SJani Nikula 	 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
2640379bc100SJani Nikula 	 * else clear to 0b.
2641379bc100SJani Nikula 	 */
2642f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_PCS_DW1_LN0(port));
2643a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2644379bc100SJani Nikula 		val &= ~COMMON_KEEPER_EN;
2645a621860aSVille Syrjälä 	else
2646a621860aSVille Syrjälä 		val |= COMMON_KEEPER_EN;
2647f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_PCS_DW1_GRP(port), val);
2648379bc100SJani Nikula 
2649379bc100SJani Nikula 	/* 2. Program loadgen select */
2650379bc100SJani Nikula 	/*
2651379bc100SJani Nikula 	 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
2652379bc100SJani Nikula 	 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
2653379bc100SJani Nikula 	 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
2654379bc100SJani Nikula 	 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
2655379bc100SJani Nikula 	 */
2656379bc100SJani Nikula 	for (ln = 0; ln <= 3; ln++) {
2657f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port));
2658379bc100SJani Nikula 		val &= ~LOADGEN_SELECT;
2659379bc100SJani Nikula 
2660379bc100SJani Nikula 		if ((rate <= 600000 && width == 4 && ln >= 1)  ||
2661379bc100SJani Nikula 		    (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
2662379bc100SJani Nikula 			val |= LOADGEN_SELECT;
2663379bc100SJani Nikula 		}
2664f7960e7fSJani Nikula 		intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val);
2665379bc100SJani Nikula 	}
2666379bc100SJani Nikula 
2667379bc100SJani Nikula 	/* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
2668f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_CL1CM_DW5);
2669379bc100SJani Nikula 	val |= SUS_CLOCK_CONFIG;
2670f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_CL1CM_DW5, val);
2671379bc100SJani Nikula 
2672379bc100SJani Nikula 	/* 4. Clear training enable to change swing values */
2673f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
2674379bc100SJani Nikula 	val &= ~TX_TRAINING_EN;
2675f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
2676379bc100SJani Nikula 
2677379bc100SJani Nikula 	/* 5. Program swing and de-emphasis */
2678a621860aSVille Syrjälä 	cnl_ddi_vswing_program(encoder, crtc_state, level);
2679379bc100SJani Nikula 
2680379bc100SJani Nikula 	/* 6. Set training enable to trigger update */
2681f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port));
2682379bc100SJani Nikula 	val |= TX_TRAINING_EN;
2683f7960e7fSJani Nikula 	intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val);
2684379bc100SJani Nikula }
2685379bc100SJani Nikula 
2686a8143150SJosé Roberto de Souza static void icl_ddi_combo_vswing_program(struct intel_encoder *encoder,
2687a621860aSVille Syrjälä 					 const struct intel_crtc_state *crtc_state,
2688a621860aSVille Syrjälä 					 int level)
2689379bc100SJani Nikula {
2690a8143150SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2691a621860aSVille Syrjälä 	const struct cnl_ddi_buf_trans *ddi_translations;
2692f0e86e05SJosé Roberto de Souza 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2693a621860aSVille Syrjälä 	int n_entries, ln;
2694a621860aSVille Syrjälä 	u32 val;
2695379bc100SJani Nikula 
2696bd3cf6f7SJosé Roberto de Souza 	if (INTEL_GEN(dev_priv) >= 12)
2697a621860aSVille Syrjälä 		ddi_translations = tgl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
26981ba1014dSTejas Upadhyay 	else if (IS_PLATFORM(dev_priv, INTEL_JASPERLAKE))
26991ba1014dSTejas Upadhyay 		ddi_translations = jsl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
27001ba1014dSTejas Upadhyay 	else if (IS_PLATFORM(dev_priv, INTEL_ELKHARTLAKE))
2701a621860aSVille Syrjälä 		ddi_translations = ehl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
2702bd3cf6f7SJosé Roberto de Souza 	else
2703a621860aSVille Syrjälä 		ddi_translations = icl_get_combo_buf_trans(encoder, crtc_state, &n_entries);
2704379bc100SJani Nikula 	if (!ddi_translations)
2705379bc100SJani Nikula 		return;
2706379bc100SJani Nikula 
2707379bc100SJani Nikula 	if (level >= n_entries) {
270847bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
270947bdb1caSJani Nikula 			    "DDI translation not found for level %d. Using %d instead.",
271047bdb1caSJani Nikula 			    level, n_entries - 1);
2711379bc100SJani Nikula 		level = n_entries - 1;
2712379bc100SJani Nikula 	}
2713379bc100SJani Nikula 
2714a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) {
271581619f4aSJosé Roberto de Souza 		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
271681619f4aSJosé Roberto de Souza 
271781619f4aSJosé Roberto de Souza 		val = EDP4K2K_MODE_OVRD_EN | EDP4K2K_MODE_OVRD_OPTIMIZED;
271881619f4aSJosé Roberto de Souza 		intel_dp->hobl_active = is_hobl_buf_trans(ddi_translations);
271981619f4aSJosé Roberto de Souza 		intel_de_rmw(dev_priv, ICL_PORT_CL_DW10(phy), val,
272081619f4aSJosé Roberto de Souza 			     intel_dp->hobl_active ? val : 0);
272181619f4aSJosé Roberto de Souza 	}
272281619f4aSJosé Roberto de Souza 
2723379bc100SJani Nikula 	/* Set PORT_TX_DW5 */
2724f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
2725379bc100SJani Nikula 	val &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK |
2726379bc100SJani Nikula 		  TAP2_DISABLE | TAP3_DISABLE);
2727379bc100SJani Nikula 	val |= SCALING_MODE_SEL(0x2);
2728379bc100SJani Nikula 	val |= RTERM_SELECT(0x6);
2729379bc100SJani Nikula 	val |= TAP3_DISABLE;
2730f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
2731379bc100SJani Nikula 
2732379bc100SJani Nikula 	/* Program PORT_TX_DW2 */
2733f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN0(phy));
2734379bc100SJani Nikula 	val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
2735379bc100SJani Nikula 		 RCOMP_SCALAR_MASK);
2736379bc100SJani Nikula 	val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
2737379bc100SJani Nikula 	val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
2738379bc100SJani Nikula 	/* Program Rcomp scalar for every table entry */
2739379bc100SJani Nikula 	val |= RCOMP_SCALAR(0x98);
2740f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), val);
2741379bc100SJani Nikula 
2742379bc100SJani Nikula 	/* Program PORT_TX_DW4 */
2743379bc100SJani Nikula 	/* We cannot write to GRP. It would overwrite individual loadgen. */
2744379bc100SJani Nikula 	for (ln = 0; ln <= 3; ln++) {
2745f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy));
2746379bc100SJani Nikula 		val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
2747379bc100SJani Nikula 			 CURSOR_COEFF_MASK);
2748379bc100SJani Nikula 		val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
2749379bc100SJani Nikula 		val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
2750379bc100SJani Nikula 		val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
2751f7960e7fSJani Nikula 		intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val);
2752379bc100SJani Nikula 	}
2753379bc100SJani Nikula 
2754379bc100SJani Nikula 	/* Program PORT_TX_DW7 */
2755f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW7_LN0(phy));
2756379bc100SJani Nikula 	val &= ~N_SCALAR_MASK;
2757379bc100SJani Nikula 	val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
2758f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW7_GRP(phy), val);
2759379bc100SJani Nikula }
2760379bc100SJani Nikula 
2761379bc100SJani Nikula static void icl_combo_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
2762a621860aSVille Syrjälä 					      const struct intel_crtc_state *crtc_state,
2763a621860aSVille Syrjälä 					      int level)
2764379bc100SJani Nikula {
2765379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2766dc867bc7SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2767a621860aSVille Syrjälä 	int width, rate, ln;
2768379bc100SJani Nikula 	u32 val;
2769379bc100SJani Nikula 
2770a621860aSVille Syrjälä 	width = crtc_state->lane_count;
2771a621860aSVille Syrjälä 	rate = crtc_state->port_clock;
2772379bc100SJani Nikula 
2773379bc100SJani Nikula 	/*
2774379bc100SJani Nikula 	 * 1. If port type is eDP or DP,
2775379bc100SJani Nikula 	 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
2776379bc100SJani Nikula 	 * else clear to 0b.
2777379bc100SJani Nikula 	 */
2778f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN0(phy));
2779a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2780379bc100SJani Nikula 		val &= ~COMMON_KEEPER_EN;
2781379bc100SJani Nikula 	else
2782379bc100SJani Nikula 		val |= COMMON_KEEPER_EN;
2783f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), val);
2784379bc100SJani Nikula 
2785379bc100SJani Nikula 	/* 2. Program loadgen select */
2786379bc100SJani Nikula 	/*
2787379bc100SJani Nikula 	 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
2788379bc100SJani Nikula 	 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
2789379bc100SJani Nikula 	 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
2790379bc100SJani Nikula 	 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
2791379bc100SJani Nikula 	 */
2792379bc100SJani Nikula 	for (ln = 0; ln <= 3; ln++) {
2793f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy));
2794379bc100SJani Nikula 		val &= ~LOADGEN_SELECT;
2795379bc100SJani Nikula 
2796379bc100SJani Nikula 		if ((rate <= 600000 && width == 4 && ln >= 1) ||
2797379bc100SJani Nikula 		    (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
2798379bc100SJani Nikula 			val |= LOADGEN_SELECT;
2799379bc100SJani Nikula 		}
2800f7960e7fSJani Nikula 		intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val);
2801379bc100SJani Nikula 	}
2802379bc100SJani Nikula 
2803379bc100SJani Nikula 	/* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
2804f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_CL_DW5(phy));
2805379bc100SJani Nikula 	val |= SUS_CLOCK_CONFIG;
2806f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_CL_DW5(phy), val);
2807379bc100SJani Nikula 
2808379bc100SJani Nikula 	/* 4. Clear training enable to change swing values */
2809f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
2810379bc100SJani Nikula 	val &= ~TX_TRAINING_EN;
2811f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
2812379bc100SJani Nikula 
2813379bc100SJani Nikula 	/* 5. Program swing and de-emphasis */
2814a621860aSVille Syrjälä 	icl_ddi_combo_vswing_program(encoder, crtc_state, level);
2815379bc100SJani Nikula 
2816379bc100SJani Nikula 	/* 6. Set training enable to trigger update */
2817f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy));
2818379bc100SJani Nikula 	val |= TX_TRAINING_EN;
2819f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val);
2820379bc100SJani Nikula }
2821379bc100SJani Nikula 
2822379bc100SJani Nikula static void icl_mg_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
2823a621860aSVille Syrjälä 					   const struct intel_crtc_state *crtc_state,
2824a621860aSVille Syrjälä 					   int level)
2825379bc100SJani Nikula {
2826379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2827f21e8b80SJosé Roberto de Souza 	enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port);
2828379bc100SJani Nikula 	const struct icl_mg_phy_ddi_buf_trans *ddi_translations;
2829a621860aSVille Syrjälä 	int n_entries, ln;
2830a621860aSVille Syrjälä 	u32 val;
2831379bc100SJani Nikula 
2832a621860aSVille Syrjälä 	ddi_translations = icl_get_mg_buf_trans(encoder, crtc_state, &n_entries);
2833379bc100SJani Nikula 	/* The table does not have values for level 3 and level 9. */
2834379bc100SJani Nikula 	if (level >= n_entries || level == 3 || level == 9) {
283547bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
283647bdb1caSJani Nikula 			    "DDI translation not found for level %d. Using %d instead.",
2837379bc100SJani Nikula 			    level, n_entries - 2);
2838379bc100SJani Nikula 		level = n_entries - 2;
2839379bc100SJani Nikula 	}
2840379bc100SJani Nikula 
2841379bc100SJani Nikula 	/* Set MG_TX_LINK_PARAMS cri_use_fs32 to 0. */
2842379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
2843f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port));
2844379bc100SJani Nikula 		val &= ~CRI_USE_FS32;
2845f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port), val);
2846379bc100SJani Nikula 
2847f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port));
2848379bc100SJani Nikula 		val &= ~CRI_USE_FS32;
2849f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port), val);
2850379bc100SJani Nikula 	}
2851379bc100SJani Nikula 
2852379bc100SJani Nikula 	/* Program MG_TX_SWINGCTRL with values from vswing table */
2853379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
2854f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port));
2855379bc100SJani Nikula 		val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK;
2856379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_17_12(
2857379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_17_12);
2858f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port), val);
2859379bc100SJani Nikula 
2860f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port));
2861379bc100SJani Nikula 		val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK;
2862379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_17_12(
2863379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_17_12);
2864f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port), val);
2865379bc100SJani Nikula 	}
2866379bc100SJani Nikula 
2867379bc100SJani Nikula 	/* Program MG_TX_DRVCTRL with values from vswing table */
2868379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
2869f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_DRVCTRL(ln, tc_port));
2870379bc100SJani Nikula 		val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK |
2871379bc100SJani Nikula 			 CRI_TXDEEMPH_OVERRIDE_5_0_MASK);
2872379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_5_0(
2873379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_5_0) |
2874379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_11_6(
2875379bc100SJani Nikula 				ddi_translations[level].cri_txdeemph_override_11_6) |
2876379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_EN;
2877f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_DRVCTRL(ln, tc_port), val);
2878379bc100SJani Nikula 
2879f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_DRVCTRL(ln, tc_port));
2880379bc100SJani Nikula 		val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK |
2881379bc100SJani Nikula 			 CRI_TXDEEMPH_OVERRIDE_5_0_MASK);
2882379bc100SJani Nikula 		val |= CRI_TXDEEMPH_OVERRIDE_5_0(
2883379bc100SJani Nikula 			ddi_translations[level].cri_txdeemph_override_5_0) |
2884379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_11_6(
2885379bc100SJani Nikula 				ddi_translations[level].cri_txdeemph_override_11_6) |
2886379bc100SJani Nikula 			CRI_TXDEEMPH_OVERRIDE_EN;
2887f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_DRVCTRL(ln, tc_port), val);
2888379bc100SJani Nikula 
2889379bc100SJani Nikula 		/* FIXME: Program CRI_LOADGEN_SEL after the spec is updated */
2890379bc100SJani Nikula 	}
2891379bc100SJani Nikula 
2892379bc100SJani Nikula 	/*
2893379bc100SJani Nikula 	 * Program MG_CLKHUB<LN, port being used> with value from frequency table
2894379bc100SJani Nikula 	 * In case of Legacy mode on MG PHY, both TX1 and TX2 enabled so use the
2895379bc100SJani Nikula 	 * values from table for which TX1 and TX2 enabled.
2896379bc100SJani Nikula 	 */
2897379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
2898f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_CLKHUB(ln, tc_port));
2899a621860aSVille Syrjälä 		if (crtc_state->port_clock < 300000)
2900379bc100SJani Nikula 			val |= CFG_LOW_RATE_LKREN_EN;
2901379bc100SJani Nikula 		else
2902379bc100SJani Nikula 			val &= ~CFG_LOW_RATE_LKREN_EN;
2903f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_CLKHUB(ln, tc_port), val);
2904379bc100SJani Nikula 	}
2905379bc100SJani Nikula 
2906379bc100SJani Nikula 	/* Program the MG_TX_DCC<LN, port being used> based on the link frequency */
2907379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
2908f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX1_DCC(ln, tc_port));
2909379bc100SJani Nikula 		val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK;
2910a621860aSVille Syrjälä 		if (crtc_state->port_clock <= 500000) {
2911379bc100SJani Nikula 			val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN;
2912379bc100SJani Nikula 		} else {
2913379bc100SJani Nikula 			val |= CFG_AMI_CK_DIV_OVERRIDE_EN |
2914379bc100SJani Nikula 				CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
2915379bc100SJani Nikula 		}
2916f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_DCC(ln, tc_port), val);
2917379bc100SJani Nikula 
2918f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, MG_TX2_DCC(ln, tc_port));
2919379bc100SJani Nikula 		val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK;
2920a621860aSVille Syrjälä 		if (crtc_state->port_clock <= 500000) {
2921379bc100SJani Nikula 			val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN;
2922379bc100SJani Nikula 		} else {
2923379bc100SJani Nikula 			val |= CFG_AMI_CK_DIV_OVERRIDE_EN |
2924379bc100SJani Nikula 				CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
2925379bc100SJani Nikula 		}
2926f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_DCC(ln, tc_port), val);
2927379bc100SJani Nikula 	}
2928379bc100SJani Nikula 
2929379bc100SJani Nikula 	/* Program MG_TX_PISO_READLOAD with values from vswing table */
2930379bc100SJani Nikula 	for (ln = 0; ln < 2; ln++) {
2931f7960e7fSJani Nikula 		val = intel_de_read(dev_priv,
2932f7960e7fSJani Nikula 				    MG_TX1_PISO_READLOAD(ln, tc_port));
2933379bc100SJani Nikula 		val |= CRI_CALCINIT;
2934f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX1_PISO_READLOAD(ln, tc_port),
2935f7960e7fSJani Nikula 			       val);
2936379bc100SJani Nikula 
2937f7960e7fSJani Nikula 		val = intel_de_read(dev_priv,
2938f7960e7fSJani Nikula 				    MG_TX2_PISO_READLOAD(ln, tc_port));
2939379bc100SJani Nikula 		val |= CRI_CALCINIT;
2940f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_TX2_PISO_READLOAD(ln, tc_port),
2941f7960e7fSJani Nikula 			       val);
2942379bc100SJani Nikula 	}
2943379bc100SJani Nikula }
2944379bc100SJani Nikula 
2945379bc100SJani Nikula static void icl_ddi_vswing_sequence(struct intel_encoder *encoder,
2946a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
2947a621860aSVille Syrjälä 				    int level)
2948379bc100SJani Nikula {
2949379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2950d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
2951379bc100SJani Nikula 
2952d8fe2ab6SMatt Roper 	if (intel_phy_is_combo(dev_priv, phy))
2953a621860aSVille Syrjälä 		icl_combo_phy_ddi_vswing_sequence(encoder, crtc_state, level);
2954379bc100SJani Nikula 	else
2955a621860aSVille Syrjälä 		icl_mg_phy_ddi_vswing_sequence(encoder, crtc_state, level);
2956379bc100SJani Nikula }
2957379bc100SJani Nikula 
2958978c3e53SClinton A Taylor static void
2959a621860aSVille Syrjälä tgl_dkl_phy_ddi_vswing_sequence(struct intel_encoder *encoder,
2960a621860aSVille Syrjälä 				const struct intel_crtc_state *crtc_state,
2961a621860aSVille Syrjälä 				int level)
2962978c3e53SClinton A Taylor {
2963978c3e53SClinton A Taylor 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2964978c3e53SClinton A Taylor 	enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port);
2965978c3e53SClinton A Taylor 	const struct tgl_dkl_phy_ddi_buf_trans *ddi_translations;
2966a621860aSVille Syrjälä 	u32 val, dpcnt_mask, dpcnt_val;
2967a621860aSVille Syrjälä 	int n_entries, ln;
2968978c3e53SClinton A Taylor 
2969a621860aSVille Syrjälä 	ddi_translations = tgl_get_dkl_buf_trans(encoder, crtc_state, &n_entries);
29709fa67699SJosé Roberto de Souza 
2971978c3e53SClinton A Taylor 	if (level >= n_entries)
2972978c3e53SClinton A Taylor 		level = n_entries - 1;
2973978c3e53SClinton A Taylor 
2974978c3e53SClinton A Taylor 	dpcnt_mask = (DKL_TX_PRESHOOT_COEFF_MASK |
2975978c3e53SClinton A Taylor 		      DKL_TX_DE_EMPAHSIS_COEFF_MASK |
2976978c3e53SClinton A Taylor 		      DKL_TX_VSWING_CONTROL_MASK);
2977978c3e53SClinton A Taylor 	dpcnt_val = DKL_TX_VSWING_CONTROL(ddi_translations[level].dkl_vswing_control);
2978978c3e53SClinton A Taylor 	dpcnt_val |= DKL_TX_DE_EMPHASIS_COEFF(ddi_translations[level].dkl_de_emphasis_control);
2979978c3e53SClinton A Taylor 	dpcnt_val |= DKL_TX_PRESHOOT_COEFF(ddi_translations[level].dkl_preshoot_control);
2980978c3e53SClinton A Taylor 
2981978c3e53SClinton A Taylor 	for (ln = 0; ln < 2; ln++) {
2982f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
2983f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, ln));
2984978c3e53SClinton A Taylor 
2985f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_PMD_LANE_SUS(tc_port), 0);
29862d69c42eSJosé Roberto de Souza 
2987978c3e53SClinton A Taylor 		/* All the registers are RMW */
2988f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DKL_TX_DPCNTL0(tc_port));
2989978c3e53SClinton A Taylor 		val &= ~dpcnt_mask;
2990978c3e53SClinton A Taylor 		val |= dpcnt_val;
2991f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_DPCNTL0(tc_port), val);
2992978c3e53SClinton A Taylor 
2993f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DKL_TX_DPCNTL1(tc_port));
2994978c3e53SClinton A Taylor 		val &= ~dpcnt_mask;
2995978c3e53SClinton A Taylor 		val |= dpcnt_val;
2996f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_DPCNTL1(tc_port), val);
2997978c3e53SClinton A Taylor 
2998f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DKL_TX_DPCNTL2(tc_port));
2999978c3e53SClinton A Taylor 		val &= ~DKL_TX_DP20BITMODE;
3000f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_TX_DPCNTL2(tc_port), val);
3001978c3e53SClinton A Taylor 	}
3002978c3e53SClinton A Taylor }
3003978c3e53SClinton A Taylor 
3004978c3e53SClinton A Taylor static void tgl_ddi_vswing_sequence(struct intel_encoder *encoder,
3005a621860aSVille Syrjälä 				    const struct intel_crtc_state *crtc_state,
3006a621860aSVille Syrjälä 				    int level)
3007978c3e53SClinton A Taylor {
3008978c3e53SClinton A Taylor 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3009978c3e53SClinton A Taylor 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
3010978c3e53SClinton A Taylor 
3011978c3e53SClinton A Taylor 	if (intel_phy_is_combo(dev_priv, phy))
3012a621860aSVille Syrjälä 		icl_combo_phy_ddi_vswing_sequence(encoder, crtc_state, level);
3013978c3e53SClinton A Taylor 	else
3014a621860aSVille Syrjälä 		tgl_dkl_phy_ddi_vswing_sequence(encoder, crtc_state, level);
3015978c3e53SClinton A Taylor }
3016978c3e53SClinton A Taylor 
3017a621860aSVille Syrjälä static int translate_signal_level(struct intel_dp *intel_dp,
3018a621860aSVille Syrjälä 				  u8 signal_levels)
3019379bc100SJani Nikula {
30208b4f2137SPankaj Bharadiya 	struct drm_i915_private *i915 = dp_to_i915(intel_dp);
3021379bc100SJani Nikula 	int i;
3022379bc100SJani Nikula 
3023379bc100SJani Nikula 	for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
3024379bc100SJani Nikula 		if (index_to_dp_signal_levels[i] == signal_levels)
3025379bc100SJani Nikula 			return i;
3026379bc100SJani Nikula 	}
3027379bc100SJani Nikula 
30288b4f2137SPankaj Bharadiya 	drm_WARN(&i915->drm, 1,
30298b4f2137SPankaj Bharadiya 		 "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
3030379bc100SJani Nikula 		 signal_levels);
3031379bc100SJani Nikula 
3032379bc100SJani Nikula 	return 0;
3033379bc100SJani Nikula }
3034379bc100SJani Nikula 
3035a621860aSVille Syrjälä static int intel_ddi_dp_level(struct intel_dp *intel_dp)
3036379bc100SJani Nikula {
3037379bc100SJani Nikula 	u8 train_set = intel_dp->train_set[0];
3038a621860aSVille Syrjälä 	u8 signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3039379bc100SJani Nikula 					DP_TRAIN_PRE_EMPHASIS_MASK);
3040379bc100SJani Nikula 
30418b4f2137SPankaj Bharadiya 	return translate_signal_level(intel_dp, signal_levels);
3042379bc100SJani Nikula }
3043379bc100SJani Nikula 
3044fb83f72cSVille Syrjälä static void
3045a621860aSVille Syrjälä tgl_set_signal_levels(struct intel_dp *intel_dp,
3046a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
3047379bc100SJani Nikula {
3048fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3049379bc100SJani Nikula 	int level = intel_ddi_dp_level(intel_dp);
3050379bc100SJani Nikula 
3051a621860aSVille Syrjälä 	tgl_ddi_vswing_sequence(encoder, crtc_state, level);
3052379bc100SJani Nikula }
3053379bc100SJani Nikula 
3054fb83f72cSVille Syrjälä static void
3055a621860aSVille Syrjälä icl_set_signal_levels(struct intel_dp *intel_dp,
3056a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
3057379bc100SJani Nikula {
3058fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3059379bc100SJani Nikula 	int level = intel_ddi_dp_level(intel_dp);
3060379bc100SJani Nikula 
3061a621860aSVille Syrjälä 	icl_ddi_vswing_sequence(encoder, crtc_state, level);
3062fb83f72cSVille Syrjälä }
3063fb83f72cSVille Syrjälä 
3064fb83f72cSVille Syrjälä static void
3065a621860aSVille Syrjälä cnl_set_signal_levels(struct intel_dp *intel_dp,
3066a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
3067fb83f72cSVille Syrjälä {
3068fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3069fb83f72cSVille Syrjälä 	int level = intel_ddi_dp_level(intel_dp);
3070fb83f72cSVille Syrjälä 
3071a621860aSVille Syrjälä 	cnl_ddi_vswing_sequence(encoder, crtc_state, level);
3072fb83f72cSVille Syrjälä }
3073fb83f72cSVille Syrjälä 
3074fb83f72cSVille Syrjälä static void
3075a621860aSVille Syrjälä bxt_set_signal_levels(struct intel_dp *intel_dp,
3076a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
3077fb83f72cSVille Syrjälä {
3078fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3079fb83f72cSVille Syrjälä 	int level = intel_ddi_dp_level(intel_dp);
3080fb83f72cSVille Syrjälä 
3081a621860aSVille Syrjälä 	bxt_ddi_vswing_sequence(encoder, crtc_state, level);
3082fb83f72cSVille Syrjälä }
3083fb83f72cSVille Syrjälä 
3084fb83f72cSVille Syrjälä static void
3085a621860aSVille Syrjälä hsw_set_signal_levels(struct intel_dp *intel_dp,
3086a621860aSVille Syrjälä 		      const struct intel_crtc_state *crtc_state)
3087fb83f72cSVille Syrjälä {
3088fb83f72cSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3089fb83f72cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3090fb83f72cSVille Syrjälä 	int level = intel_ddi_dp_level(intel_dp);
3091fb83f72cSVille Syrjälä 	enum port port = encoder->port;
3092fb83f72cSVille Syrjälä 	u32 signal_levels;
3093fb83f72cSVille Syrjälä 
3094fb83f72cSVille Syrjälä 	signal_levels = DDI_BUF_TRANS_SELECT(level);
3095fb83f72cSVille Syrjälä 
3096fb83f72cSVille Syrjälä 	drm_dbg_kms(&dev_priv->drm, "Using signal levels %08x\n",
3097fb83f72cSVille Syrjälä 		    signal_levels);
3098fb83f72cSVille Syrjälä 
3099fb83f72cSVille Syrjälä 	intel_dp->DP &= ~DDI_BUF_EMP_MASK;
3100fb83f72cSVille Syrjälä 	intel_dp->DP |= signal_levels;
3101fb83f72cSVille Syrjälä 
3102379bc100SJani Nikula 	if (IS_GEN9_BC(dev_priv))
3103a621860aSVille Syrjälä 		skl_ddi_set_iboost(encoder, crtc_state, level);
3104379bc100SJani Nikula 
3105fb83f72cSVille Syrjälä 	intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP);
3106fb83f72cSVille Syrjälä 	intel_de_posting_read(dev_priv, DDI_BUF_CTL(port));
3107379bc100SJani Nikula }
3108379bc100SJani Nikula 
310981b55ef1SJani Nikula static u32 icl_dpclka_cfgcr0_clk_off(struct drm_i915_private *dev_priv,
3110befa372bSMatt Roper 				     enum phy phy)
3111379bc100SJani Nikula {
3112cd803bb4SMatt Roper 	if (IS_ROCKETLAKE(dev_priv)) {
3113cd803bb4SMatt Roper 		return RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
3114cd803bb4SMatt Roper 	} else if (intel_phy_is_combo(dev_priv, phy)) {
3115befa372bSMatt Roper 		return ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
3116befa372bSMatt Roper 	} else if (intel_phy_is_tc(dev_priv, phy)) {
3117befa372bSMatt Roper 		enum tc_port tc_port = intel_port_to_tc(dev_priv,
3118befa372bSMatt Roper 							(enum port)phy);
3119379bc100SJani Nikula 
3120379bc100SJani Nikula 		return ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port);
3121379bc100SJani Nikula 	}
3122379bc100SJani Nikula 
3123379bc100SJani Nikula 	return 0;
3124379bc100SJani Nikula }
3125379bc100SJani Nikula 
312611ffe972SLucas De Marchi static void dg1_map_plls_to_ports(struct intel_encoder *encoder,
312711ffe972SLucas De Marchi 				  const struct intel_crtc_state *crtc_state)
312811ffe972SLucas De Marchi {
312911ffe972SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
313011ffe972SLucas De Marchi 	struct intel_shared_dpll *pll = crtc_state->shared_dpll;
313111ffe972SLucas De Marchi 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
313211ffe972SLucas De Marchi 	u32 val;
313311ffe972SLucas De Marchi 
313411ffe972SLucas De Marchi 	/*
313511ffe972SLucas De Marchi 	 * If we fail this, something went very wrong: first 2 PLLs should be
313611ffe972SLucas De Marchi 	 * used by first 2 phys and last 2 PLLs by last phys
313711ffe972SLucas De Marchi 	 */
313811ffe972SLucas De Marchi 	if (drm_WARN_ON(&dev_priv->drm,
313911ffe972SLucas De Marchi 			(pll->info->id < DPLL_ID_DG1_DPLL2 && phy >= PHY_C) ||
314011ffe972SLucas De Marchi 			(pll->info->id >= DPLL_ID_DG1_DPLL2 && phy < PHY_C)))
314111ffe972SLucas De Marchi 		return;
314211ffe972SLucas De Marchi 
314311ffe972SLucas De Marchi 	mutex_lock(&dev_priv->dpll.lock);
314411ffe972SLucas De Marchi 
314511ffe972SLucas De Marchi 	val = intel_de_read(dev_priv, DG1_DPCLKA_CFGCR0(phy));
314611ffe972SLucas De Marchi 	drm_WARN_ON(&dev_priv->drm,
314711ffe972SLucas De Marchi 		    (val & DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy)) == 0);
314811ffe972SLucas De Marchi 
314911ffe972SLucas De Marchi 	val &= ~DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
315011ffe972SLucas De Marchi 	val |= DG1_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy);
315111ffe972SLucas De Marchi 	intel_de_write(dev_priv, DG1_DPCLKA_CFGCR0(phy), val);
315211ffe972SLucas De Marchi 	intel_de_posting_read(dev_priv, DG1_DPCLKA_CFGCR0(phy));
315311ffe972SLucas De Marchi 
315411ffe972SLucas De Marchi 	val &= ~DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
315511ffe972SLucas De Marchi 	intel_de_write(dev_priv, DG1_DPCLKA_CFGCR0(phy), val);
315611ffe972SLucas De Marchi 
315711ffe972SLucas De Marchi 	mutex_unlock(&dev_priv->dpll.lock);
315811ffe972SLucas De Marchi }
315911ffe972SLucas De Marchi 
3160379bc100SJani Nikula static void icl_map_plls_to_ports(struct intel_encoder *encoder,
3161379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state)
3162379bc100SJani Nikula {
3163379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3164379bc100SJani Nikula 	struct intel_shared_dpll *pll = crtc_state->shared_dpll;
3165befa372bSMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
3166379bc100SJani Nikula 	u32 val;
3167379bc100SJani Nikula 
3168353ad959SImre Deak 	mutex_lock(&dev_priv->dpll.lock);
3169379bc100SJani Nikula 
3170f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0);
31711de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm,
31721de143ccSPankaj Bharadiya 		    (val & icl_dpclka_cfgcr0_clk_off(dev_priv, phy)) == 0);
3173379bc100SJani Nikula 
3174befa372bSMatt Roper 	if (intel_phy_is_combo(dev_priv, phy)) {
3175cd803bb4SMatt Roper 		u32 mask, sel;
3176cd803bb4SMatt Roper 
3177cd803bb4SMatt Roper 		if (IS_ROCKETLAKE(dev_priv)) {
3178cd803bb4SMatt Roper 			mask = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
3179cd803bb4SMatt Roper 			sel = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy);
3180cd803bb4SMatt Roper 		} else {
3181cd803bb4SMatt Roper 			mask = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
3182cd803bb4SMatt Roper 			sel = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy);
3183cd803bb4SMatt Roper 		}
3184cd803bb4SMatt Roper 
3185befa372bSMatt Roper 		/*
3186befa372bSMatt Roper 		 * Even though this register references DDIs, note that we
3187befa372bSMatt Roper 		 * want to pass the PHY rather than the port (DDI).  For
3188befa372bSMatt Roper 		 * ICL, port=phy in all cases so it doesn't matter, but for
3189befa372bSMatt Roper 		 * EHL the bspec notes the following:
3190befa372bSMatt Roper 		 *
3191befa372bSMatt Roper 		 *   "DDID clock tied to DDIA clock, so DPCLKA_CFGCR0 DDIA
3192befa372bSMatt Roper 		 *   Clock Select chooses the PLL for both DDIA and DDID and
3193befa372bSMatt Roper 		 *   drives port A in all cases."
3194befa372bSMatt Roper 		 */
3195cd803bb4SMatt Roper 		val &= ~mask;
3196cd803bb4SMatt Roper 		val |= sel;
3197f7960e7fSJani Nikula 		intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val);
3198f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, ICL_DPCLKA_CFGCR0);
3199379bc100SJani Nikula 	}
3200379bc100SJani Nikula 
3201befa372bSMatt Roper 	val &= ~icl_dpclka_cfgcr0_clk_off(dev_priv, phy);
3202f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val);
3203379bc100SJani Nikula 
3204353ad959SImre Deak 	mutex_unlock(&dev_priv->dpll.lock);
3205379bc100SJani Nikula }
3206379bc100SJani Nikula 
320711ffe972SLucas De Marchi static void dg1_unmap_plls_to_ports(struct intel_encoder *encoder)
320811ffe972SLucas De Marchi {
320911ffe972SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
321011ffe972SLucas De Marchi 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
321111ffe972SLucas De Marchi 
321211ffe972SLucas De Marchi 	mutex_lock(&dev_priv->dpll.lock);
321311ffe972SLucas De Marchi 
321411ffe972SLucas De Marchi 	intel_de_rmw(dev_priv, DG1_DPCLKA_CFGCR0(phy), 0,
321511ffe972SLucas De Marchi 		     DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy));
321611ffe972SLucas De Marchi 
321711ffe972SLucas De Marchi 	mutex_unlock(&dev_priv->dpll.lock);
321811ffe972SLucas De Marchi }
321911ffe972SLucas De Marchi 
3220379bc100SJani Nikula static void icl_unmap_plls_to_ports(struct intel_encoder *encoder)
3221379bc100SJani Nikula {
3222379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3223befa372bSMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
3224379bc100SJani Nikula 	u32 val;
3225379bc100SJani Nikula 
3226353ad959SImre Deak 	mutex_lock(&dev_priv->dpll.lock);
3227379bc100SJani Nikula 
3228f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0);
3229befa372bSMatt Roper 	val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy);
3230f7960e7fSJani Nikula 	intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val);
3231379bc100SJani Nikula 
3232353ad959SImre Deak 	mutex_unlock(&dev_priv->dpll.lock);
3233379bc100SJani Nikula }
3234379bc100SJani Nikula 
323511ffe972SLucas De Marchi static void dg1_sanitize_port_clk_off(struct drm_i915_private *dev_priv,
323611ffe972SLucas De Marchi 				      u32 port_mask, bool ddi_clk_needed)
323711ffe972SLucas De Marchi {
323811ffe972SLucas De Marchi 	enum port port;
323911ffe972SLucas De Marchi 	u32 val;
324011ffe972SLucas De Marchi 
324111ffe972SLucas De Marchi 	for_each_port_masked(port, port_mask) {
324211ffe972SLucas De Marchi 		enum phy phy = intel_port_to_phy(dev_priv, port);
324311ffe972SLucas De Marchi 		bool ddi_clk_off;
324411ffe972SLucas De Marchi 
324511ffe972SLucas De Marchi 		val = intel_de_read(dev_priv, DG1_DPCLKA_CFGCR0(phy));
324611ffe972SLucas De Marchi 		ddi_clk_off = val & DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
324711ffe972SLucas De Marchi 
324811ffe972SLucas De Marchi 		if (ddi_clk_needed == !ddi_clk_off)
324911ffe972SLucas De Marchi 			continue;
325011ffe972SLucas De Marchi 
325111ffe972SLucas De Marchi 		/*
325211ffe972SLucas De Marchi 		 * Punt on the case now where clock is gated, but it would
325311ffe972SLucas De Marchi 		 * be needed by the port. Something else is really broken then.
325411ffe972SLucas De Marchi 		 */
325511ffe972SLucas De Marchi 		if (drm_WARN_ON(&dev_priv->drm, ddi_clk_needed))
325611ffe972SLucas De Marchi 			continue;
325711ffe972SLucas De Marchi 
325811ffe972SLucas De Marchi 		drm_notice(&dev_priv->drm,
325911ffe972SLucas De Marchi 			   "PHY %c is disabled with an ungated DDI clock, gate it\n",
326011ffe972SLucas De Marchi 			   phy_name(phy));
326111ffe972SLucas De Marchi 		val |= DG1_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
326211ffe972SLucas De Marchi 		intel_de_write(dev_priv, DG1_DPCLKA_CFGCR0(phy), val);
326311ffe972SLucas De Marchi 	}
326411ffe972SLucas De Marchi }
326511ffe972SLucas De Marchi 
32665956f440SLucas De Marchi static void icl_sanitize_port_clk_off(struct drm_i915_private *dev_priv,
32675956f440SLucas De Marchi 				      u32 port_mask, bool ddi_clk_needed)
32685956f440SLucas De Marchi {
32695956f440SLucas De Marchi 	enum port port;
32705956f440SLucas De Marchi 	u32 val;
32715956f440SLucas De Marchi 
3272f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0);
32735956f440SLucas De Marchi 	for_each_port_masked(port, port_mask) {
32745956f440SLucas De Marchi 		enum phy phy = intel_port_to_phy(dev_priv, port);
327541ba19fcSLucas De Marchi 		bool ddi_clk_off = val & icl_dpclka_cfgcr0_clk_off(dev_priv,
327641ba19fcSLucas De Marchi 								   phy);
32775956f440SLucas De Marchi 
327841ba19fcSLucas De Marchi 		if (ddi_clk_needed == !ddi_clk_off)
32795956f440SLucas De Marchi 			continue;
32805956f440SLucas De Marchi 
32815956f440SLucas De Marchi 		/*
32825956f440SLucas De Marchi 		 * Punt on the case now where clock is gated, but it would
32835956f440SLucas De Marchi 		 * be needed by the port. Something else is really broken then.
32845956f440SLucas De Marchi 		 */
32851de143ccSPankaj Bharadiya 		if (drm_WARN_ON(&dev_priv->drm, ddi_clk_needed))
32865956f440SLucas De Marchi 			continue;
32875956f440SLucas De Marchi 
328847bdb1caSJani Nikula 		drm_notice(&dev_priv->drm,
328947bdb1caSJani Nikula 			   "PHY %c is disabled/in DSI mode with an ungated DDI clock, gate it\n",
3290d6f970f0SLucas De Marchi 			   phy_name(phy));
32915956f440SLucas De Marchi 		val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy);
3292f7960e7fSJani Nikula 		intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val);
32935956f440SLucas De Marchi 	}
32945956f440SLucas De Marchi }
32955956f440SLucas De Marchi 
3296379bc100SJani Nikula void icl_sanitize_encoder_pll_mapping(struct intel_encoder *encoder)
3297379bc100SJani Nikula {
3298379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3299379bc100SJani Nikula 	u32 port_mask;
3300379bc100SJani Nikula 	bool ddi_clk_needed;
3301379bc100SJani Nikula 
3302379bc100SJani Nikula 	/*
3303379bc100SJani Nikula 	 * In case of DP MST, we sanitize the primary encoder only, not the
3304379bc100SJani Nikula 	 * virtual ones.
3305379bc100SJani Nikula 	 */
3306379bc100SJani Nikula 	if (encoder->type == INTEL_OUTPUT_DP_MST)
3307379bc100SJani Nikula 		return;
3308379bc100SJani Nikula 
3309379bc100SJani Nikula 	if (!encoder->base.crtc && intel_encoder_is_dp(encoder)) {
3310379bc100SJani Nikula 		u8 pipe_mask;
3311379bc100SJani Nikula 		bool is_mst;
3312379bc100SJani Nikula 
3313379bc100SJani Nikula 		intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst);
3314379bc100SJani Nikula 		/*
3315379bc100SJani Nikula 		 * In the unlikely case that BIOS enables DP in MST mode, just
3316379bc100SJani Nikula 		 * warn since our MST HW readout is incomplete.
3317379bc100SJani Nikula 		 */
33181de143ccSPankaj Bharadiya 		if (drm_WARN_ON(&dev_priv->drm, is_mst))
3319379bc100SJani Nikula 			return;
3320379bc100SJani Nikula 	}
3321379bc100SJani Nikula 
3322379bc100SJani Nikula 	port_mask = BIT(encoder->port);
3323379bc100SJani Nikula 	ddi_clk_needed = encoder->base.crtc;
3324379bc100SJani Nikula 
3325379bc100SJani Nikula 	if (encoder->type == INTEL_OUTPUT_DSI) {
3326379bc100SJani Nikula 		struct intel_encoder *other_encoder;
3327379bc100SJani Nikula 
3328379bc100SJani Nikula 		port_mask = intel_dsi_encoder_ports(encoder);
3329379bc100SJani Nikula 		/*
3330379bc100SJani Nikula 		 * Sanity check that we haven't incorrectly registered another
3331379bc100SJani Nikula 		 * encoder using any of the ports of this DSI encoder.
3332379bc100SJani Nikula 		 */
3333379bc100SJani Nikula 		for_each_intel_encoder(&dev_priv->drm, other_encoder) {
3334379bc100SJani Nikula 			if (other_encoder == encoder)
3335379bc100SJani Nikula 				continue;
3336379bc100SJani Nikula 
33371de143ccSPankaj Bharadiya 			if (drm_WARN_ON(&dev_priv->drm,
33381de143ccSPankaj Bharadiya 					port_mask & BIT(other_encoder->port)))
3339379bc100SJani Nikula 				return;
3340379bc100SJani Nikula 		}
3341379bc100SJani Nikula 		/*
3342379bc100SJani Nikula 		 * For DSI we keep the ddi clocks gated
3343379bc100SJani Nikula 		 * except during enable/disable sequence.
3344379bc100SJani Nikula 		 */
3345379bc100SJani Nikula 		ddi_clk_needed = false;
3346379bc100SJani Nikula 	}
3347379bc100SJani Nikula 
334811ffe972SLucas De Marchi 	if (IS_DG1(dev_priv))
334911ffe972SLucas De Marchi 		dg1_sanitize_port_clk_off(dev_priv, port_mask, ddi_clk_needed);
335011ffe972SLucas De Marchi 	else
33515956f440SLucas De Marchi 		icl_sanitize_port_clk_off(dev_priv, port_mask, ddi_clk_needed);
3352379bc100SJani Nikula }
3353379bc100SJani Nikula 
3354379bc100SJani Nikula static void intel_ddi_clk_select(struct intel_encoder *encoder,
3355379bc100SJani Nikula 				 const struct intel_crtc_state *crtc_state)
3356379bc100SJani Nikula {
3357379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3358379bc100SJani Nikula 	enum port port = encoder->port;
3359d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
3360379bc100SJani Nikula 	u32 val;
3361379bc100SJani Nikula 	const struct intel_shared_dpll *pll = crtc_state->shared_dpll;
3362379bc100SJani Nikula 
33631de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, !pll))
3364379bc100SJani Nikula 		return;
3365379bc100SJani Nikula 
3366353ad959SImre Deak 	mutex_lock(&dev_priv->dpll.lock);
3367379bc100SJani Nikula 
3368379bc100SJani Nikula 	if (INTEL_GEN(dev_priv) >= 11) {
3369d8fe2ab6SMatt Roper 		if (!intel_phy_is_combo(dev_priv, phy))
3370f7960e7fSJani Nikula 			intel_de_write(dev_priv, DDI_CLK_SEL(port),
3371379bc100SJani Nikula 				       icl_pll_to_ddi_clk_sel(encoder, crtc_state));
337224ea098bSTejas Upadhyay 		else if (IS_JSL_EHL(dev_priv) && port >= PORT_C)
3373c2052d6eSJosé Roberto de Souza 			/*
3374c2052d6eSJosé Roberto de Souza 			 * MG does not exist but the programming is required
3375c2052d6eSJosé Roberto de Souza 			 * to ungate DDIC and DDID
3376c2052d6eSJosé Roberto de Souza 			 */
3377f7960e7fSJani Nikula 			intel_de_write(dev_priv, DDI_CLK_SEL(port),
3378f7960e7fSJani Nikula 				       DDI_CLK_SEL_MG);
3379379bc100SJani Nikula 	} else if (IS_CANNONLAKE(dev_priv)) {
3380379bc100SJani Nikula 		/* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */
3381f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DPCLKA_CFGCR0);
3382379bc100SJani Nikula 		val &= ~DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
3383379bc100SJani Nikula 		val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, port);
3384f7960e7fSJani Nikula 		intel_de_write(dev_priv, DPCLKA_CFGCR0, val);
3385379bc100SJani Nikula 
3386379bc100SJani Nikula 		/*
3387379bc100SJani Nikula 		 * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI.
3388379bc100SJani Nikula 		 * This step and the step before must be done with separate
3389379bc100SJani Nikula 		 * register writes.
3390379bc100SJani Nikula 		 */
3391f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DPCLKA_CFGCR0);
3392379bc100SJani Nikula 		val &= ~DPCLKA_CFGCR0_DDI_CLK_OFF(port);
3393f7960e7fSJani Nikula 		intel_de_write(dev_priv, DPCLKA_CFGCR0, val);
3394379bc100SJani Nikula 	} else if (IS_GEN9_BC(dev_priv)) {
3395379bc100SJani Nikula 		/* DDI -> PLL mapping  */
3396f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, DPLL_CTRL2);
3397379bc100SJani Nikula 
3398379bc100SJani Nikula 		val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
3399379bc100SJani Nikula 			 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
3400379bc100SJani Nikula 		val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->info->id, port) |
3401379bc100SJani Nikula 			DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
3402379bc100SJani Nikula 
3403f7960e7fSJani Nikula 		intel_de_write(dev_priv, DPLL_CTRL2, val);
3404379bc100SJani Nikula 
3405379bc100SJani Nikula 	} else if (INTEL_GEN(dev_priv) < 9) {
3406f7960e7fSJani Nikula 		intel_de_write(dev_priv, PORT_CLK_SEL(port),
3407f7960e7fSJani Nikula 			       hsw_pll_to_ddi_pll_sel(pll));
3408379bc100SJani Nikula 	}
3409379bc100SJani Nikula 
3410353ad959SImre Deak 	mutex_unlock(&dev_priv->dpll.lock);
3411379bc100SJani Nikula }
3412379bc100SJani Nikula 
3413379bc100SJani Nikula static void intel_ddi_clk_disable(struct intel_encoder *encoder)
3414379bc100SJani Nikula {
3415379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3416379bc100SJani Nikula 	enum port port = encoder->port;
3417d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
3418379bc100SJani Nikula 
3419379bc100SJani Nikula 	if (INTEL_GEN(dev_priv) >= 11) {
3420c2052d6eSJosé Roberto de Souza 		if (!intel_phy_is_combo(dev_priv, phy) ||
342124ea098bSTejas Upadhyay 		    (IS_JSL_EHL(dev_priv) && port >= PORT_C))
3422f7960e7fSJani Nikula 			intel_de_write(dev_priv, DDI_CLK_SEL(port),
3423f7960e7fSJani Nikula 				       DDI_CLK_SEL_NONE);
3424379bc100SJani Nikula 	} else if (IS_CANNONLAKE(dev_priv)) {
3425f7960e7fSJani Nikula 		intel_de_write(dev_priv, DPCLKA_CFGCR0,
3426f7960e7fSJani Nikula 			       intel_de_read(dev_priv, DPCLKA_CFGCR0) | DPCLKA_CFGCR0_DDI_CLK_OFF(port));
3427379bc100SJani Nikula 	} else if (IS_GEN9_BC(dev_priv)) {
3428f7960e7fSJani Nikula 		intel_de_write(dev_priv, DPLL_CTRL2,
3429f7960e7fSJani Nikula 			       intel_de_read(dev_priv, DPLL_CTRL2) | DPLL_CTRL2_DDI_CLK_OFF(port));
3430379bc100SJani Nikula 	} else if (INTEL_GEN(dev_priv) < 9) {
3431f7960e7fSJani Nikula 		intel_de_write(dev_priv, PORT_CLK_SEL(port),
3432f7960e7fSJani Nikula 			       PORT_CLK_SEL_NONE);
3433379bc100SJani Nikula 	}
3434379bc100SJani Nikula }
3435379bc100SJani Nikula 
34368aaf5cbdSJosé Roberto de Souza static void
34377801f3b7SLucas De Marchi icl_program_mg_dp_mode(struct intel_digital_port *dig_port,
34383b51be4eSClinton A Taylor 		       const struct intel_crtc_state *crtc_state)
3439379bc100SJani Nikula {
34407801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
34417801f3b7SLucas De Marchi 	enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port);
34423b51be4eSClinton A Taylor 	u32 ln0, ln1, pin_assignment;
34433b51be4eSClinton A Taylor 	u8 width;
3444379bc100SJani Nikula 
34457801f3b7SLucas De Marchi 	if (dig_port->tc_mode == TC_PORT_TBT_ALT)
3446379bc100SJani Nikula 		return;
3447379bc100SJani Nikula 
3448978c3e53SClinton A Taylor 	if (INTEL_GEN(dev_priv) >= 12) {
3449f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
3450f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x0));
3451f7960e7fSJani Nikula 		ln0 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port));
3452f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
3453f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x1));
3454f7960e7fSJani Nikula 		ln1 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port));
3455978c3e53SClinton A Taylor 	} else {
3456f7960e7fSJani Nikula 		ln0 = intel_de_read(dev_priv, MG_DP_MODE(0, tc_port));
3457f7960e7fSJani Nikula 		ln1 = intel_de_read(dev_priv, MG_DP_MODE(1, tc_port));
3458978c3e53SClinton A Taylor 	}
3459379bc100SJani Nikula 
34604f72a8eeSKhaled Almahallawy 	ln0 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE);
3461379bc100SJani Nikula 	ln1 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE);
3462379bc100SJani Nikula 
34633b51be4eSClinton A Taylor 	/* DPPATC */
34647801f3b7SLucas De Marchi 	pin_assignment = intel_tc_port_get_pin_assignment_mask(dig_port);
34653b51be4eSClinton A Taylor 	width = crtc_state->lane_count;
3466379bc100SJani Nikula 
34673b51be4eSClinton A Taylor 	switch (pin_assignment) {
34683b51be4eSClinton A Taylor 	case 0x0:
34691de143ccSPankaj Bharadiya 		drm_WARN_ON(&dev_priv->drm,
34707801f3b7SLucas De Marchi 			    dig_port->tc_mode != TC_PORT_LEGACY);
34713b51be4eSClinton A Taylor 		if (width == 1) {
3472379bc100SJani Nikula 			ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
34733b51be4eSClinton A Taylor 		} else {
34743b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
34753b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
3476379bc100SJani Nikula 		}
3477379bc100SJani Nikula 		break;
34783b51be4eSClinton A Taylor 	case 0x1:
34793b51be4eSClinton A Taylor 		if (width == 4) {
34803b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
34813b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
34823b51be4eSClinton A Taylor 		}
3483379bc100SJani Nikula 		break;
34843b51be4eSClinton A Taylor 	case 0x2:
34853b51be4eSClinton A Taylor 		if (width == 2) {
34863b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
34873b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
34883b51be4eSClinton A Taylor 		}
34893b51be4eSClinton A Taylor 		break;
34903b51be4eSClinton A Taylor 	case 0x3:
34913b51be4eSClinton A Taylor 	case 0x5:
34923b51be4eSClinton A Taylor 		if (width == 1) {
34933b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X1_MODE;
34943b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
34953b51be4eSClinton A Taylor 		} else {
34963b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
34973b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
34983b51be4eSClinton A Taylor 		}
34993b51be4eSClinton A Taylor 		break;
35003b51be4eSClinton A Taylor 	case 0x4:
35013b51be4eSClinton A Taylor 	case 0x6:
35023b51be4eSClinton A Taylor 		if (width == 1) {
35033b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X1_MODE;
35043b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X1_MODE;
35053b51be4eSClinton A Taylor 		} else {
35063b51be4eSClinton A Taylor 			ln0 |= MG_DP_MODE_CFG_DP_X2_MODE;
35073b51be4eSClinton A Taylor 			ln1 |= MG_DP_MODE_CFG_DP_X2_MODE;
35083b51be4eSClinton A Taylor 		}
35093b51be4eSClinton A Taylor 		break;
3510379bc100SJani Nikula 	default:
35113b51be4eSClinton A Taylor 		MISSING_CASE(pin_assignment);
3512379bc100SJani Nikula 	}
3513379bc100SJani Nikula 
3514978c3e53SClinton A Taylor 	if (INTEL_GEN(dev_priv) >= 12) {
3515f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
3516f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x0));
3517f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln0);
3518f7960e7fSJani Nikula 		intel_de_write(dev_priv, HIP_INDEX_REG(tc_port),
3519f7960e7fSJani Nikula 			       HIP_INDEX_VAL(tc_port, 0x1));
3520f7960e7fSJani Nikula 		intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln1);
3521978c3e53SClinton A Taylor 	} else {
3522f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_DP_MODE(0, tc_port), ln0);
3523f7960e7fSJani Nikula 		intel_de_write(dev_priv, MG_DP_MODE(1, tc_port), ln1);
3524379bc100SJani Nikula 	}
3525978c3e53SClinton A Taylor }
3526379bc100SJani Nikula 
3527ef79fafeSVille Syrjälä static enum transcoder
3528ef79fafeSVille Syrjälä tgl_dp_tp_transcoder(const struct intel_crtc_state *crtc_state)
3529ef79fafeSVille Syrjälä {
3530ef79fafeSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))
3531ef79fafeSVille Syrjälä 		return crtc_state->mst_master_transcoder;
3532ef79fafeSVille Syrjälä 	else
3533ef79fafeSVille Syrjälä 		return crtc_state->cpu_transcoder;
3534ef79fafeSVille Syrjälä }
3535ef79fafeSVille Syrjälä 
3536ef79fafeSVille Syrjälä i915_reg_t dp_tp_ctl_reg(struct intel_encoder *encoder,
3537ef79fafeSVille Syrjälä 			 const struct intel_crtc_state *crtc_state)
3538ef79fafeSVille Syrjälä {
3539ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3540ef79fafeSVille Syrjälä 
3541ef79fafeSVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 12)
3542ef79fafeSVille Syrjälä 		return TGL_DP_TP_CTL(tgl_dp_tp_transcoder(crtc_state));
3543ef79fafeSVille Syrjälä 	else
3544ef79fafeSVille Syrjälä 		return DP_TP_CTL(encoder->port);
3545ef79fafeSVille Syrjälä }
3546ef79fafeSVille Syrjälä 
3547ef79fafeSVille Syrjälä i915_reg_t dp_tp_status_reg(struct intel_encoder *encoder,
3548ef79fafeSVille Syrjälä 			    const struct intel_crtc_state *crtc_state)
3549ef79fafeSVille Syrjälä {
3550ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3551ef79fafeSVille Syrjälä 
3552ef79fafeSVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 12)
3553ef79fafeSVille Syrjälä 		return TGL_DP_TP_STATUS(tgl_dp_tp_transcoder(crtc_state));
3554ef79fafeSVille Syrjälä 	else
3555ef79fafeSVille Syrjälä 		return DP_TP_STATUS(encoder->port);
3556ef79fafeSVille Syrjälä }
3557ef79fafeSVille Syrjälä 
3558379bc100SJani Nikula static void intel_dp_sink_set_fec_ready(struct intel_dp *intel_dp,
3559379bc100SJani Nikula 					const struct intel_crtc_state *crtc_state)
3560379bc100SJani Nikula {
356147bdb1caSJani Nikula 	struct drm_i915_private *i915 = dp_to_i915(intel_dp);
356247bdb1caSJani Nikula 
3563379bc100SJani Nikula 	if (!crtc_state->fec_enable)
3564379bc100SJani Nikula 		return;
3565379bc100SJani Nikula 
3566379bc100SJani Nikula 	if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_FEC_CONFIGURATION, DP_FEC_READY) <= 0)
356747bdb1caSJani Nikula 		drm_dbg_kms(&i915->drm,
356847bdb1caSJani Nikula 			    "Failed to set FEC_READY in the sink\n");
3569379bc100SJani Nikula }
3570379bc100SJani Nikula 
3571379bc100SJani Nikula static void intel_ddi_enable_fec(struct intel_encoder *encoder,
3572379bc100SJani Nikula 				 const struct intel_crtc_state *crtc_state)
3573379bc100SJani Nikula {
3574379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
35754444df6eSLucas De Marchi 	struct intel_dp *intel_dp;
3576379bc100SJani Nikula 	u32 val;
3577379bc100SJani Nikula 
3578379bc100SJani Nikula 	if (!crtc_state->fec_enable)
3579379bc100SJani Nikula 		return;
3580379bc100SJani Nikula 
3581b7d02c3aSVille Syrjälä 	intel_dp = enc_to_intel_dp(encoder);
3582ef79fafeSVille Syrjälä 	val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3583379bc100SJani Nikula 	val |= DP_TP_CTL_FEC_ENABLE;
3584ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
3585379bc100SJani Nikula }
3586379bc100SJani Nikula 
3587379bc100SJani Nikula static void intel_ddi_disable_fec_state(struct intel_encoder *encoder,
3588379bc100SJani Nikula 					const struct intel_crtc_state *crtc_state)
3589379bc100SJani Nikula {
3590379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
35914444df6eSLucas De Marchi 	struct intel_dp *intel_dp;
3592379bc100SJani Nikula 	u32 val;
3593379bc100SJani Nikula 
3594379bc100SJani Nikula 	if (!crtc_state->fec_enable)
3595379bc100SJani Nikula 		return;
3596379bc100SJani Nikula 
3597b7d02c3aSVille Syrjälä 	intel_dp = enc_to_intel_dp(encoder);
3598ef79fafeSVille Syrjälä 	val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3599379bc100SJani Nikula 	val &= ~DP_TP_CTL_FEC_ENABLE;
3600ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
3601ef79fafeSVille Syrjälä 	intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3602379bc100SJani Nikula }
3603379bc100SJani Nikula 
3604ede9771dSVille Syrjälä static void tgl_ddi_pre_enable_dp(struct intel_atomic_state *state,
3605ede9771dSVille Syrjälä 				  struct intel_encoder *encoder,
360699389390SJosé Roberto de Souza 				  const struct intel_crtc_state *crtc_state,
360799389390SJosé Roberto de Souza 				  const struct drm_connector_state *conn_state)
360899389390SJosé Roberto de Souza {
3609b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
361099389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
361199389390SJosé Roberto de Souza 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
3612b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
361399389390SJosé Roberto de Souza 	bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
361499389390SJosé Roberto de Souza 	int level = intel_ddi_dp_level(intel_dp);
361599389390SJosé Roberto de Souza 
3616a621860aSVille Syrjälä 	intel_dp_set_link_params(intel_dp,
3617a621860aSVille Syrjälä 				 crtc_state->port_clock,
3618a621860aSVille Syrjälä 				 crtc_state->lane_count);
361999389390SJosé Roberto de Souza 
36205e19c0b0SMatt Roper 	/*
36215e19c0b0SMatt Roper 	 * 1. Enable Power Wells
36225e19c0b0SMatt Roper 	 *
36235e19c0b0SMatt Roper 	 * This was handled at the beginning of intel_atomic_commit_tail(),
36245e19c0b0SMatt Roper 	 * before we called down into this function.
36255e19c0b0SMatt Roper 	 */
362699389390SJosé Roberto de Souza 
36275e19c0b0SMatt Roper 	/* 2. Enable Panel Power if PPS is required */
362899389390SJosé Roberto de Souza 	intel_edp_panel_on(intel_dp);
362999389390SJosé Roberto de Souza 
363099389390SJosé Roberto de Souza 	/*
36315e19c0b0SMatt Roper 	 * 3. For non-TBT Type-C ports, set FIA lane count
36325e19c0b0SMatt Roper 	 * (DFLEXDPSP.DPX4TXLATC)
36335e19c0b0SMatt Roper 	 *
36345e19c0b0SMatt Roper 	 * This was done before tgl_ddi_pre_enable_dp by
36351e98f88cSLucas De Marchi 	 * hsw_crtc_enable()->intel_encoders_pre_pll_enable().
363699389390SJosé Roberto de Souza 	 */
363799389390SJosé Roberto de Souza 
36385e19c0b0SMatt Roper 	/*
36395e19c0b0SMatt Roper 	 * 4. Enable the port PLL.
36405e19c0b0SMatt Roper 	 *
36415e19c0b0SMatt Roper 	 * The PLL enabling itself was already done before this function by
36421e98f88cSLucas De Marchi 	 * hsw_crtc_enable()->intel_enable_shared_dpll().  We need only
36435e19c0b0SMatt Roper 	 * configure the PLL to port mapping here.
36445e19c0b0SMatt Roper 	 */
36456171e58bSClinton A Taylor 	intel_ddi_clk_select(encoder, crtc_state);
36466171e58bSClinton A Taylor 
36475e19c0b0SMatt Roper 	/* 5. If IO power is controlled through PWR_WELL_CTL, Enable IO Power */
364899389390SJosé Roberto de Souza 	if (!intel_phy_is_tc(dev_priv, phy) ||
3649a4550977SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT) {
3650a4550977SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
3651a4550977SImre Deak 		dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
365299389390SJosé Roberto de Souza 								   dig_port->ddi_io_power_domain);
3653a4550977SImre Deak 	}
365499389390SJosé Roberto de Souza 
36555e19c0b0SMatt Roper 	/* 6. Program DP_MODE */
36563b51be4eSClinton A Taylor 	icl_program_mg_dp_mode(dig_port, crtc_state);
365799389390SJosé Roberto de Souza 
365899389390SJosé Roberto de Souza 	/*
36595e19c0b0SMatt Roper 	 * 7. The rest of the below are substeps under the bspec's "Enable and
36605e19c0b0SMatt Roper 	 * Train Display Port" step.  Note that steps that are specific to
36615e19c0b0SMatt Roper 	 * MST will be handled by intel_mst_pre_enable_dp() before/after it
36625e19c0b0SMatt Roper 	 * calls into this function.  Also intel_mst_pre_enable_dp() only calls
36635e19c0b0SMatt Roper 	 * us when active_mst_links==0, so any steps designated for "single
36645e19c0b0SMatt Roper 	 * stream or multi-stream master transcoder" can just be performed
36655e19c0b0SMatt Roper 	 * unconditionally here.
36665e19c0b0SMatt Roper 	 */
36675e19c0b0SMatt Roper 
36685e19c0b0SMatt Roper 	/*
36695e19c0b0SMatt Roper 	 * 7.a Configure Transcoder Clock Select to direct the Port clock to the
36705e19c0b0SMatt Roper 	 * Transcoder.
367199389390SJosé Roberto de Souza 	 */
367202a715c3SVille Syrjälä 	intel_ddi_enable_pipe_clock(encoder, crtc_state);
367399389390SJosé Roberto de Souza 
36745e19c0b0SMatt Roper 	/*
36755e19c0b0SMatt Roper 	 * 7.b Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST
36765e19c0b0SMatt Roper 	 * Transport Select
36775e19c0b0SMatt Roper 	 */
3678eed22a46SVille Syrjälä 	intel_ddi_config_transcoder_func(encoder, crtc_state);
367999389390SJosé Roberto de Souza 
36805e19c0b0SMatt Roper 	/*
36815e19c0b0SMatt Roper 	 * 7.c Configure & enable DP_TP_CTL with link training pattern 1
36825e19c0b0SMatt Roper 	 * selected
36835e19c0b0SMatt Roper 	 *
36845e19c0b0SMatt Roper 	 * This will be handled by the intel_dp_start_link_train() farther
36855e19c0b0SMatt Roper 	 * down this function.
36865e19c0b0SMatt Roper 	 */
36875e19c0b0SMatt Roper 
36885e19c0b0SMatt Roper 	/* 7.e Configure voltage swing and related IO settings */
3689a621860aSVille Syrjälä 	tgl_ddi_vswing_sequence(encoder, crtc_state, level);
369099389390SJosé Roberto de Souza 
36915e19c0b0SMatt Roper 	/*
36925e19c0b0SMatt Roper 	 * 7.f Combo PHY: Configure PORT_CL_DW10 Static Power Down to power up
36935e19c0b0SMatt Roper 	 * the used lanes of the DDI.
36945e19c0b0SMatt Roper 	 */
369599389390SJosé Roberto de Souza 	if (intel_phy_is_combo(dev_priv, phy)) {
369699389390SJosé Roberto de Souza 		bool lane_reversal =
369799389390SJosé Roberto de Souza 			dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL;
369899389390SJosé Roberto de Souza 
369999389390SJosé Roberto de Souza 		intel_combo_phy_power_up_lanes(dev_priv, phy, false,
370099389390SJosé Roberto de Souza 					       crtc_state->lane_count,
370199389390SJosé Roberto de Souza 					       lane_reversal);
370299389390SJosé Roberto de Souza 	}
370399389390SJosé Roberto de Souza 
37045e19c0b0SMatt Roper 	/*
37055e19c0b0SMatt Roper 	 * 7.g Configure and enable DDI_BUF_CTL
37065e19c0b0SMatt Roper 	 * 7.h Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout
37075e19c0b0SMatt Roper 	 *     after 500 us.
37085e19c0b0SMatt Roper 	 *
37095e19c0b0SMatt Roper 	 * We only configure what the register value will be here.  Actual
37105e19c0b0SMatt Roper 	 * enabling happens during link training farther down.
37115e19c0b0SMatt Roper 	 */
3712a621860aSVille Syrjälä 	intel_ddi_init_dp_buf_reg(encoder, crtc_state);
371399389390SJosé Roberto de Souza 
371499389390SJosé Roberto de Souza 	if (!is_mst)
37150e634efdSVille Syrjälä 		intel_dp_set_power(intel_dp, DP_SET_POWER_D0);
371699389390SJosé Roberto de Souza 
3717522508b6SAnkit Nautiyal 	intel_dp_configure_protocol_converter(intel_dp, crtc_state);
371899389390SJosé Roberto de Souza 	intel_dp_sink_set_decompression_state(intel_dp, crtc_state, true);
371999389390SJosé Roberto de Souza 	/*
372099389390SJosé Roberto de Souza 	 * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit
372199389390SJosé Roberto de Souza 	 * in the FEC_CONFIGURATION register to 1 before initiating link
372299389390SJosé Roberto de Souza 	 * training
372399389390SJosé Roberto de Souza 	 */
372499389390SJosé Roberto de Souza 	intel_dp_sink_set_fec_ready(intel_dp, crtc_state);
37255e19c0b0SMatt Roper 
37264f3dd47aSAnkit Nautiyal 	intel_dp_check_frl_training(intel_dp);
372710fec80bSAnkit Nautiyal 	intel_dp_pcon_dsc_configure(intel_dp, crtc_state);
37284f3dd47aSAnkit Nautiyal 
37295e19c0b0SMatt Roper 	/*
37305e19c0b0SMatt Roper 	 * 7.i Follow DisplayPort specification training sequence (see notes for
37315e19c0b0SMatt Roper 	 *     failure handling)
37325e19c0b0SMatt Roper 	 * 7.j If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle
37335e19c0b0SMatt Roper 	 *     Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent)
37345e19c0b0SMatt Roper 	 *     (timeout after 800 us)
37355e19c0b0SMatt Roper 	 */
3736a621860aSVille Syrjälä 	intel_dp_start_link_train(intel_dp, crtc_state);
373799389390SJosé Roberto de Souza 
37385e19c0b0SMatt Roper 	/* 7.k Set DP_TP_CTL link training to Normal */
3739eadf6f91SManasi Navare 	if (!is_trans_port_sync_mode(crtc_state))
3740a621860aSVille Syrjälä 		intel_dp_stop_link_train(intel_dp, crtc_state);
374199389390SJosé Roberto de Souza 
37425e19c0b0SMatt Roper 	/* 7.l Configure and enable FEC if needed */
374399389390SJosé Roberto de Souza 	intel_ddi_enable_fec(encoder, crtc_state);
37444e3cdb45SManasi Navare 	if (!crtc_state->bigjoiner)
374599389390SJosé Roberto de Souza 		intel_dsc_enable(encoder, crtc_state);
374699389390SJosé Roberto de Souza }
374799389390SJosé Roberto de Souza 
3748ede9771dSVille Syrjälä static void hsw_ddi_pre_enable_dp(struct intel_atomic_state *state,
3749ede9771dSVille Syrjälä 				  struct intel_encoder *encoder,
3750379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state,
3751379bc100SJani Nikula 				  const struct drm_connector_state *conn_state)
3752379bc100SJani Nikula {
3753b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3754379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3755379bc100SJani Nikula 	enum port port = encoder->port;
3756dc867bc7SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
3757b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3758379bc100SJani Nikula 	bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
3759379bc100SJani Nikula 	int level = intel_ddi_dp_level(intel_dp);
3760379bc100SJani Nikula 
3761542dfab5SJosé Roberto de Souza 	if (INTEL_GEN(dev_priv) < 11)
37621de143ccSPankaj Bharadiya 		drm_WARN_ON(&dev_priv->drm,
37631de143ccSPankaj Bharadiya 			    is_mst && (port == PORT_A || port == PORT_E));
3764542dfab5SJosé Roberto de Souza 	else
37651de143ccSPankaj Bharadiya 		drm_WARN_ON(&dev_priv->drm, is_mst && port == PORT_A);
3766379bc100SJani Nikula 
3767a621860aSVille Syrjälä 	intel_dp_set_link_params(intel_dp,
3768a621860aSVille Syrjälä 				 crtc_state->port_clock,
3769a621860aSVille Syrjälä 				 crtc_state->lane_count);
3770379bc100SJani Nikula 
3771379bc100SJani Nikula 	intel_edp_panel_on(intel_dp);
3772379bc100SJani Nikula 
3773379bc100SJani Nikula 	intel_ddi_clk_select(encoder, crtc_state);
3774379bc100SJani Nikula 
3775d8fe2ab6SMatt Roper 	if (!intel_phy_is_tc(dev_priv, phy) ||
3776a4550977SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT) {
3777a4550977SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
3778a4550977SImre Deak 		dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
37793b2ed431SImre Deak 								   dig_port->ddi_io_power_domain);
3780a4550977SImre Deak 	}
3781379bc100SJani Nikula 
37823b51be4eSClinton A Taylor 	icl_program_mg_dp_mode(dig_port, crtc_state);
3783379bc100SJani Nikula 
3784379bc100SJani Nikula 	if (INTEL_GEN(dev_priv) >= 11)
3785a621860aSVille Syrjälä 		icl_ddi_vswing_sequence(encoder, crtc_state, level);
3786379bc100SJani Nikula 	else if (IS_CANNONLAKE(dev_priv))
3787a621860aSVille Syrjälä 		cnl_ddi_vswing_sequence(encoder, crtc_state, level);
3788379bc100SJani Nikula 	else if (IS_GEN9_LP(dev_priv))
3789a621860aSVille Syrjälä 		bxt_ddi_vswing_sequence(encoder, crtc_state, level);
3790379bc100SJani Nikula 	else
3791379bc100SJani Nikula 		intel_prepare_dp_ddi_buffers(encoder, crtc_state);
3792379bc100SJani Nikula 
3793d8fe2ab6SMatt Roper 	if (intel_phy_is_combo(dev_priv, phy)) {
3794379bc100SJani Nikula 		bool lane_reversal =
3795379bc100SJani Nikula 			dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL;
3796379bc100SJani Nikula 
3797dc867bc7SMatt Roper 		intel_combo_phy_power_up_lanes(dev_priv, phy, false,
3798379bc100SJani Nikula 					       crtc_state->lane_count,
3799379bc100SJani Nikula 					       lane_reversal);
3800379bc100SJani Nikula 	}
3801379bc100SJani Nikula 
3802a621860aSVille Syrjälä 	intel_ddi_init_dp_buf_reg(encoder, crtc_state);
3803379bc100SJani Nikula 	if (!is_mst)
38040e634efdSVille Syrjälä 		intel_dp_set_power(intel_dp, DP_SET_POWER_D0);
3805522508b6SAnkit Nautiyal 	intel_dp_configure_protocol_converter(intel_dp, crtc_state);
3806379bc100SJani Nikula 	intel_dp_sink_set_decompression_state(intel_dp, crtc_state,
3807379bc100SJani Nikula 					      true);
3808379bc100SJani Nikula 	intel_dp_sink_set_fec_ready(intel_dp, crtc_state);
3809a621860aSVille Syrjälä 	intel_dp_start_link_train(intel_dp, crtc_state);
3810eadf6f91SManasi Navare 	if ((port != PORT_A || INTEL_GEN(dev_priv) >= 9) &&
3811eadf6f91SManasi Navare 	    !is_trans_port_sync_mode(crtc_state))
3812a621860aSVille Syrjälä 		intel_dp_stop_link_train(intel_dp, crtc_state);
3813379bc100SJani Nikula 
3814379bc100SJani Nikula 	intel_ddi_enable_fec(encoder, crtc_state);
3815379bc100SJani Nikula 
3816379bc100SJani Nikula 	if (!is_mst)
381702a715c3SVille Syrjälä 		intel_ddi_enable_pipe_clock(encoder, crtc_state);
3818379bc100SJani Nikula 
38194e3cdb45SManasi Navare 	if (!crtc_state->bigjoiner)
3820379bc100SJani Nikula 		intel_dsc_enable(encoder, crtc_state);
3821379bc100SJani Nikula }
3822379bc100SJani Nikula 
3823ede9771dSVille Syrjälä static void intel_ddi_pre_enable_dp(struct intel_atomic_state *state,
3824ede9771dSVille Syrjälä 				    struct intel_encoder *encoder,
382599389390SJosé Roberto de Souza 				    const struct intel_crtc_state *crtc_state,
382699389390SJosé Roberto de Souza 				    const struct drm_connector_state *conn_state)
382799389390SJosé Roberto de Souza {
382899389390SJosé Roberto de Souza 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
382999389390SJosé Roberto de Souza 
383099389390SJosé Roberto de Souza 	if (INTEL_GEN(dev_priv) >= 12)
3831ede9771dSVille Syrjälä 		tgl_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state);
383299389390SJosé Roberto de Souza 	else
3833ede9771dSVille Syrjälä 		hsw_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state);
38340c06fa15SGwan-gyeong Mun 
3835bd8c9ccaSGwan-gyeong Mun 	/* MST will call a setting of MSA after an allocating of Virtual Channel
3836bd8c9ccaSGwan-gyeong Mun 	 * from MST encoder pre_enable callback.
3837bd8c9ccaSGwan-gyeong Mun 	 */
38381fc1e8d4SJosé Roberto de Souza 	if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
38390c06fa15SGwan-gyeong Mun 		intel_ddi_set_dp_msa(crtc_state, conn_state);
38401c9d2eb2SJani Nikula 
38411c9d2eb2SJani Nikula 		intel_dp_set_m_n(crtc_state, M1_N1);
384299389390SJosé Roberto de Souza 	}
38431fc1e8d4SJosé Roberto de Souza }
384499389390SJosé Roberto de Souza 
3845ede9771dSVille Syrjälä static void intel_ddi_pre_enable_hdmi(struct intel_atomic_state *state,
3846ede9771dSVille Syrjälä 				      struct intel_encoder *encoder,
3847379bc100SJani Nikula 				      const struct intel_crtc_state *crtc_state,
3848379bc100SJani Nikula 				      const struct drm_connector_state *conn_state)
3849379bc100SJani Nikula {
38500ba7ffeaSLucas De Marchi 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
38510ba7ffeaSLucas De Marchi 	struct intel_hdmi *intel_hdmi = &dig_port->hdmi;
3852379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3853a621860aSVille Syrjälä 	int level = intel_ddi_hdmi_level(encoder, crtc_state);
3854379bc100SJani Nikula 
3855379bc100SJani Nikula 	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
3856379bc100SJani Nikula 	intel_ddi_clk_select(encoder, crtc_state);
3857379bc100SJani Nikula 
3858a4550977SImre Deak 	drm_WARN_ON(&dev_priv->drm, dig_port->ddi_io_wakeref);
3859a4550977SImre Deak 	dig_port->ddi_io_wakeref = intel_display_power_get(dev_priv,
3860a4550977SImre Deak 							   dig_port->ddi_io_power_domain);
3861379bc100SJani Nikula 
38623b51be4eSClinton A Taylor 	icl_program_mg_dp_mode(dig_port, crtc_state);
3863379bc100SJani Nikula 
3864978c3e53SClinton A Taylor 	if (INTEL_GEN(dev_priv) >= 12)
3865a621860aSVille Syrjälä 		tgl_ddi_vswing_sequence(encoder, crtc_state, level);
3866978c3e53SClinton A Taylor 	else if (INTEL_GEN(dev_priv) == 11)
3867a621860aSVille Syrjälä 		icl_ddi_vswing_sequence(encoder, crtc_state, level);
3868379bc100SJani Nikula 	else if (IS_CANNONLAKE(dev_priv))
3869a621860aSVille Syrjälä 		cnl_ddi_vswing_sequence(encoder, crtc_state, level);
3870379bc100SJani Nikula 	else if (IS_GEN9_LP(dev_priv))
3871a621860aSVille Syrjälä 		bxt_ddi_vswing_sequence(encoder, crtc_state, level);
3872379bc100SJani Nikula 	else
3873379bc100SJani Nikula 		intel_prepare_hdmi_ddi_buffers(encoder, level);
3874379bc100SJani Nikula 
3875379bc100SJani Nikula 	if (IS_GEN9_BC(dev_priv))
3876a621860aSVille Syrjälä 		skl_ddi_set_iboost(encoder, crtc_state, level);
3877379bc100SJani Nikula 
387802a715c3SVille Syrjälä 	intel_ddi_enable_pipe_clock(encoder, crtc_state);
3879379bc100SJani Nikula 
38800ba7ffeaSLucas De Marchi 	dig_port->set_infoframes(encoder,
3881379bc100SJani Nikula 				 crtc_state->has_infoframe,
3882379bc100SJani Nikula 				 crtc_state, conn_state);
3883379bc100SJani Nikula }
3884379bc100SJani Nikula 
3885ede9771dSVille Syrjälä static void intel_ddi_pre_enable(struct intel_atomic_state *state,
3886ede9771dSVille Syrjälä 				 struct intel_encoder *encoder,
3887379bc100SJani Nikula 				 const struct intel_crtc_state *crtc_state,
3888379bc100SJani Nikula 				 const struct drm_connector_state *conn_state)
3889379bc100SJani Nikula {
38902225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3891379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3892379bc100SJani Nikula 	enum pipe pipe = crtc->pipe;
3893379bc100SJani Nikula 
3894379bc100SJani Nikula 	/*
3895379bc100SJani Nikula 	 * When called from DP MST code:
3896379bc100SJani Nikula 	 * - conn_state will be NULL
3897379bc100SJani Nikula 	 * - encoder will be the main encoder (ie. mst->primary)
3898379bc100SJani Nikula 	 * - the main connector associated with this port
3899379bc100SJani Nikula 	 *   won't be active or linked to a crtc
3900379bc100SJani Nikula 	 * - crtc_state will be the state of the first stream to
3901379bc100SJani Nikula 	 *   be activated on this port, and it may not be the same
3902379bc100SJani Nikula 	 *   stream that will be deactivated last, but each stream
3903379bc100SJani Nikula 	 *   should have a state that is identical when it comes to
3904379bc100SJani Nikula 	 *   the DP link parameteres
3905379bc100SJani Nikula 	 */
3906379bc100SJani Nikula 
39071de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, crtc_state->has_pch_encoder);
3908379bc100SJani Nikula 
390911ffe972SLucas De Marchi 	if (IS_DG1(dev_priv))
391011ffe972SLucas De Marchi 		dg1_map_plls_to_ports(encoder, crtc_state);
391111ffe972SLucas De Marchi 	else if (INTEL_GEN(dev_priv) >= 11)
3912379bc100SJani Nikula 		icl_map_plls_to_ports(encoder, crtc_state);
3913379bc100SJani Nikula 
3914379bc100SJani Nikula 	intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3915379bc100SJani Nikula 
3916379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
3917ede9771dSVille Syrjälä 		intel_ddi_pre_enable_hdmi(state, encoder, crtc_state,
3918ede9771dSVille Syrjälä 					  conn_state);
3919379bc100SJani Nikula 	} else {
3920f7af425dSVille Syrjälä 		struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3921379bc100SJani Nikula 
3922ede9771dSVille Syrjälä 		intel_ddi_pre_enable_dp(state, encoder, crtc_state,
3923ede9771dSVille Syrjälä 					conn_state);
3924379bc100SJani Nikula 
3925f7af425dSVille Syrjälä 		/* FIXME precompute everything properly */
3926f7af425dSVille Syrjälä 		/* FIXME how do we turn infoframes off again? */
3927f7af425dSVille Syrjälä 		if (dig_port->lspcon.active && dig_port->dp.has_hdmi_sink)
3928379bc100SJani Nikula 			dig_port->set_infoframes(encoder,
3929379bc100SJani Nikula 						 crtc_state->has_infoframe,
3930379bc100SJani Nikula 						 crtc_state, conn_state);
3931379bc100SJani Nikula 	}
3932379bc100SJani Nikula }
3933379bc100SJani Nikula 
3934379bc100SJani Nikula static void intel_disable_ddi_buf(struct intel_encoder *encoder,
3935379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state)
3936379bc100SJani Nikula {
3937379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3938379bc100SJani Nikula 	enum port port = encoder->port;
3939379bc100SJani Nikula 	bool wait = false;
3940379bc100SJani Nikula 	u32 val;
3941379bc100SJani Nikula 
3942f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, DDI_BUF_CTL(port));
3943379bc100SJani Nikula 	if (val & DDI_BUF_CTL_ENABLE) {
3944379bc100SJani Nikula 		val &= ~DDI_BUF_CTL_ENABLE;
3945f7960e7fSJani Nikula 		intel_de_write(dev_priv, DDI_BUF_CTL(port), val);
3946379bc100SJani Nikula 		wait = true;
3947379bc100SJani Nikula 	}
3948379bc100SJani Nikula 
3949e468ff06SLucas De Marchi 	if (intel_crtc_has_dp_encoder(crtc_state)) {
3950ef79fafeSVille Syrjälä 		val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
3951379bc100SJani Nikula 		val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
3952379bc100SJani Nikula 		val |= DP_TP_CTL_LINK_TRAIN_PAT1;
3953ef79fafeSVille Syrjälä 		intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
3954e468ff06SLucas De Marchi 	}
3955379bc100SJani Nikula 
3956379bc100SJani Nikula 	/* Disable FEC in DP Sink */
3957379bc100SJani Nikula 	intel_ddi_disable_fec_state(encoder, crtc_state);
3958379bc100SJani Nikula 
3959379bc100SJani Nikula 	if (wait)
3960379bc100SJani Nikula 		intel_wait_ddi_buf_idle(dev_priv, port);
3961379bc100SJani Nikula }
3962379bc100SJani Nikula 
3963ede9771dSVille Syrjälä static void intel_ddi_post_disable_dp(struct intel_atomic_state *state,
3964ede9771dSVille Syrjälä 				      struct intel_encoder *encoder,
3965379bc100SJani Nikula 				      const struct intel_crtc_state *old_crtc_state,
3966379bc100SJani Nikula 				      const struct drm_connector_state *old_conn_state)
3967379bc100SJani Nikula {
3968379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3969b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
3970379bc100SJani Nikula 	struct intel_dp *intel_dp = &dig_port->dp;
3971379bc100SJani Nikula 	bool is_mst = intel_crtc_has_type(old_crtc_state,
3972379bc100SJani Nikula 					  INTEL_OUTPUT_DP_MST);
3973d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
3974379bc100SJani Nikula 
3975c980216dSImre Deak 	if (!is_mst)
3976c980216dSImre Deak 		intel_dp_set_infoframes(encoder, false,
3977c980216dSImre Deak 					old_crtc_state, old_conn_state);
3978fa37a213SGwan-gyeong Mun 
3979379bc100SJani Nikula 	/*
3980379bc100SJani Nikula 	 * Power down sink before disabling the port, otherwise we end
3981379bc100SJani Nikula 	 * up getting interrupts from the sink on detecting link loss.
3982379bc100SJani Nikula 	 */
39830e634efdSVille Syrjälä 	intel_dp_set_power(intel_dp, DP_SET_POWER_D3);
398478eaaba3SJosé Roberto de Souza 
3985c59053dcSJosé Roberto de Souza 	if (INTEL_GEN(dev_priv) >= 12) {
3986c59053dcSJosé Roberto de Souza 		if (is_mst) {
3987c59053dcSJosé Roberto de Souza 			enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
3988c59053dcSJosé Roberto de Souza 			u32 val;
3989c59053dcSJosé Roberto de Souza 
3990f7960e7fSJani Nikula 			val = intel_de_read(dev_priv,
3991f7960e7fSJani Nikula 					    TRANS_DDI_FUNC_CTL(cpu_transcoder));
3992919e4f07SJosé Roberto de Souza 			val &= ~(TGL_TRANS_DDI_PORT_MASK |
3993919e4f07SJosé Roberto de Souza 				 TRANS_DDI_MODE_SELECT_MASK);
3994f7960e7fSJani Nikula 			intel_de_write(dev_priv,
3995f7960e7fSJani Nikula 				       TRANS_DDI_FUNC_CTL(cpu_transcoder),
3996f7960e7fSJani Nikula 				       val);
3997c59053dcSJosé Roberto de Souza 		}
3998c59053dcSJosé Roberto de Souza 	} else {
3999c59053dcSJosé Roberto de Souza 		if (!is_mst)
400050a7efb2SJosé Roberto de Souza 			intel_ddi_disable_pipe_clock(old_crtc_state);
4001c59053dcSJosé Roberto de Souza 	}
4002379bc100SJani Nikula 
4003379bc100SJani Nikula 	intel_disable_ddi_buf(encoder, old_crtc_state);
4004379bc100SJani Nikula 
40053ca8f191SJosé Roberto de Souza 	/*
40063ca8f191SJosé Roberto de Souza 	 * From TGL spec: "If single stream or multi-stream master transcoder:
40073ca8f191SJosé Roberto de Souza 	 * Configure Transcoder Clock select to direct no clock to the
40083ca8f191SJosé Roberto de Souza 	 * transcoder"
40093ca8f191SJosé Roberto de Souza 	 */
40103ca8f191SJosé Roberto de Souza 	if (INTEL_GEN(dev_priv) >= 12)
40113ca8f191SJosé Roberto de Souza 		intel_ddi_disable_pipe_clock(old_crtc_state);
40123ca8f191SJosé Roberto de Souza 
4013379bc100SJani Nikula 	intel_edp_panel_vdd_on(intel_dp);
4014379bc100SJani Nikula 	intel_edp_panel_off(intel_dp);
4015379bc100SJani Nikula 
4016d8fe2ab6SMatt Roper 	if (!intel_phy_is_tc(dev_priv, phy) ||
40173b2ed431SImre Deak 	    dig_port->tc_mode != TC_PORT_TBT_ALT)
4018a4550977SImre Deak 		intel_display_power_put(dev_priv,
4019a4550977SImre Deak 					dig_port->ddi_io_power_domain,
4020a4550977SImre Deak 					fetch_and_zero(&dig_port->ddi_io_wakeref));
4021379bc100SJani Nikula 
4022379bc100SJani Nikula 	intel_ddi_clk_disable(encoder);
4023379bc100SJani Nikula }
4024379bc100SJani Nikula 
4025ede9771dSVille Syrjälä static void intel_ddi_post_disable_hdmi(struct intel_atomic_state *state,
4026ede9771dSVille Syrjälä 					struct intel_encoder *encoder,
4027379bc100SJani Nikula 					const struct intel_crtc_state *old_crtc_state,
4028379bc100SJani Nikula 					const struct drm_connector_state *old_conn_state)
4029379bc100SJani Nikula {
4030379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4031b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
4032379bc100SJani Nikula 	struct intel_hdmi *intel_hdmi = &dig_port->hdmi;
4033379bc100SJani Nikula 
4034379bc100SJani Nikula 	dig_port->set_infoframes(encoder, false,
4035379bc100SJani Nikula 				 old_crtc_state, old_conn_state);
4036379bc100SJani Nikula 
4037379bc100SJani Nikula 	intel_ddi_disable_pipe_clock(old_crtc_state);
4038379bc100SJani Nikula 
4039379bc100SJani Nikula 	intel_disable_ddi_buf(encoder, old_crtc_state);
4040379bc100SJani Nikula 
4041a4550977SImre Deak 	intel_display_power_put(dev_priv,
4042a4550977SImre Deak 				dig_port->ddi_io_power_domain,
4043a4550977SImre Deak 				fetch_and_zero(&dig_port->ddi_io_wakeref));
4044379bc100SJani Nikula 
4045379bc100SJani Nikula 	intel_ddi_clk_disable(encoder);
4046379bc100SJani Nikula 
4047379bc100SJani Nikula 	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
4048379bc100SJani Nikula }
4049379bc100SJani Nikula 
4050ede9771dSVille Syrjälä static void intel_ddi_post_disable(struct intel_atomic_state *state,
4051ede9771dSVille Syrjälä 				   struct intel_encoder *encoder,
4052379bc100SJani Nikula 				   const struct intel_crtc_state *old_crtc_state,
4053379bc100SJani Nikula 				   const struct drm_connector_state *old_conn_state)
4054379bc100SJani Nikula {
4055379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4056b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
405717bef9baSVille Syrjälä 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
405817bef9baSVille Syrjälä 	bool is_tc_port = intel_phy_is_tc(dev_priv, phy);
4059379bc100SJani Nikula 
40607829c92bSVille Syrjälä 	if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) {
4061773b4b54SVille Syrjälä 		intel_crtc_vblank_off(old_crtc_state);
4062773b4b54SVille Syrjälä 
4063773b4b54SVille Syrjälä 		intel_disable_pipe(old_crtc_state);
4064773b4b54SVille Syrjälä 
4065773b4b54SVille Syrjälä 		intel_ddi_disable_transcoder_func(old_crtc_state);
4066773b4b54SVille Syrjälä 
4067773b4b54SVille Syrjälä 		intel_dsc_disable(old_crtc_state);
4068773b4b54SVille Syrjälä 
4069773b4b54SVille Syrjälä 		if (INTEL_GEN(dev_priv) >= 9)
4070f6df4d46SLucas De Marchi 			skl_scaler_disable(old_crtc_state);
4071773b4b54SVille Syrjälä 		else
40729eae5e27SLucas De Marchi 			ilk_pfit_disable(old_crtc_state);
40737829c92bSVille Syrjälä 	}
4074773b4b54SVille Syrjälä 
40754e3cdb45SManasi Navare 	if (old_crtc_state->bigjoiner_linked_crtc) {
40764e3cdb45SManasi Navare 		struct intel_atomic_state *state =
40774e3cdb45SManasi Navare 			to_intel_atomic_state(old_crtc_state->uapi.state);
40784e3cdb45SManasi Navare 		struct intel_crtc *slave =
40794e3cdb45SManasi Navare 			old_crtc_state->bigjoiner_linked_crtc;
40804e3cdb45SManasi Navare 		const struct intel_crtc_state *old_slave_crtc_state =
40814e3cdb45SManasi Navare 			intel_atomic_get_old_crtc_state(state, slave);
40824e3cdb45SManasi Navare 
40834e3cdb45SManasi Navare 		intel_crtc_vblank_off(old_slave_crtc_state);
40844e3cdb45SManasi Navare 		trace_intel_pipe_disable(slave);
40854e3cdb45SManasi Navare 
40864e3cdb45SManasi Navare 		intel_dsc_disable(old_slave_crtc_state);
40874e3cdb45SManasi Navare 		skl_scaler_disable(old_slave_crtc_state);
40884e3cdb45SManasi Navare 	}
40894e3cdb45SManasi Navare 
4090379bc100SJani Nikula 	/*
4091379bc100SJani Nikula 	 * When called from DP MST code:
4092379bc100SJani Nikula 	 * - old_conn_state will be NULL
4093379bc100SJani Nikula 	 * - encoder will be the main encoder (ie. mst->primary)
4094379bc100SJani Nikula 	 * - the main connector associated with this port
4095379bc100SJani Nikula 	 *   won't be active or linked to a crtc
4096379bc100SJani Nikula 	 * - old_crtc_state will be the state of the last stream to
4097379bc100SJani Nikula 	 *   be deactivated on this port, and it may not be the same
4098379bc100SJani Nikula 	 *   stream that was activated last, but each stream
4099379bc100SJani Nikula 	 *   should have a state that is identical when it comes to
4100379bc100SJani Nikula 	 *   the DP link parameteres
4101379bc100SJani Nikula 	 */
4102379bc100SJani Nikula 
4103379bc100SJani Nikula 	if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
4104ede9771dSVille Syrjälä 		intel_ddi_post_disable_hdmi(state, encoder, old_crtc_state,
4105ede9771dSVille Syrjälä 					    old_conn_state);
4106379bc100SJani Nikula 	else
4107ede9771dSVille Syrjälä 		intel_ddi_post_disable_dp(state, encoder, old_crtc_state,
4108ede9771dSVille Syrjälä 					  old_conn_state);
4109379bc100SJani Nikula 
411011ffe972SLucas De Marchi 	if (IS_DG1(dev_priv))
411111ffe972SLucas De Marchi 		dg1_unmap_plls_to_ports(encoder);
411211ffe972SLucas De Marchi 	else if (INTEL_GEN(dev_priv) >= 11)
4113379bc100SJani Nikula 		icl_unmap_plls_to_ports(encoder);
411417bef9baSVille Syrjälä 
411517bef9baSVille Syrjälä 	if (intel_crtc_has_dp_encoder(old_crtc_state) || is_tc_port)
4116162e68e1SImre Deak 		intel_display_power_put(dev_priv,
4117162e68e1SImre Deak 					intel_ddi_main_link_aux_domain(dig_port),
4118162e68e1SImre Deak 					fetch_and_zero(&dig_port->aux_wakeref));
411917bef9baSVille Syrjälä 
412017bef9baSVille Syrjälä 	if (is_tc_port)
412117bef9baSVille Syrjälä 		intel_tc_port_put_link(dig_port);
4122379bc100SJani Nikula }
4123379bc100SJani Nikula 
4124ede9771dSVille Syrjälä void intel_ddi_fdi_post_disable(struct intel_atomic_state *state,
4125ede9771dSVille Syrjälä 				struct intel_encoder *encoder,
4126379bc100SJani Nikula 				const struct intel_crtc_state *old_crtc_state,
4127379bc100SJani Nikula 				const struct drm_connector_state *old_conn_state)
4128379bc100SJani Nikula {
4129379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4130379bc100SJani Nikula 	u32 val;
4131379bc100SJani Nikula 
4132379bc100SJani Nikula 	/*
4133379bc100SJani Nikula 	 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
4134379bc100SJani Nikula 	 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
4135379bc100SJani Nikula 	 * step 13 is the correct place for it. Step 18 is where it was
4136379bc100SJani Nikula 	 * originally before the BUN.
4137379bc100SJani Nikula 	 */
4138f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
4139379bc100SJani Nikula 	val &= ~FDI_RX_ENABLE;
4140f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
4141379bc100SJani Nikula 
4142379bc100SJani Nikula 	intel_disable_ddi_buf(encoder, old_crtc_state);
4143379bc100SJani Nikula 	intel_ddi_clk_disable(encoder);
4144379bc100SJani Nikula 
4145f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A));
4146379bc100SJani Nikula 	val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
4147379bc100SJani Nikula 	val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
4148f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), val);
4149379bc100SJani Nikula 
4150f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
4151379bc100SJani Nikula 	val &= ~FDI_PCDCLK;
4152f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
4153379bc100SJani Nikula 
4154f7960e7fSJani Nikula 	val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
4155379bc100SJani Nikula 	val &= ~FDI_RX_PLL_ENABLE;
4156f7960e7fSJani Nikula 	intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val);
4157379bc100SJani Nikula }
4158379bc100SJani Nikula 
4159d82a855aSVille Syrjälä static void trans_port_sync_stop_link_train(struct intel_atomic_state *state,
4160d82a855aSVille Syrjälä 					    struct intel_encoder *encoder,
4161d82a855aSVille Syrjälä 					    const struct intel_crtc_state *crtc_state)
4162d82a855aSVille Syrjälä {
4163d82a855aSVille Syrjälä 	const struct drm_connector_state *conn_state;
4164d82a855aSVille Syrjälä 	struct drm_connector *conn;
4165d82a855aSVille Syrjälä 	int i;
4166d82a855aSVille Syrjälä 
4167d82a855aSVille Syrjälä 	if (!crtc_state->sync_mode_slaves_mask)
4168d82a855aSVille Syrjälä 		return;
4169d82a855aSVille Syrjälä 
4170d82a855aSVille Syrjälä 	for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
4171d82a855aSVille Syrjälä 		struct intel_encoder *slave_encoder =
4172d82a855aSVille Syrjälä 			to_intel_encoder(conn_state->best_encoder);
4173d82a855aSVille Syrjälä 		struct intel_crtc *slave_crtc = to_intel_crtc(conn_state->crtc);
4174d82a855aSVille Syrjälä 		const struct intel_crtc_state *slave_crtc_state;
4175d82a855aSVille Syrjälä 
4176d82a855aSVille Syrjälä 		if (!slave_crtc)
4177d82a855aSVille Syrjälä 			continue;
4178d82a855aSVille Syrjälä 
4179d82a855aSVille Syrjälä 		slave_crtc_state =
4180d82a855aSVille Syrjälä 			intel_atomic_get_new_crtc_state(state, slave_crtc);
4181d82a855aSVille Syrjälä 
4182d82a855aSVille Syrjälä 		if (slave_crtc_state->master_transcoder !=
4183d82a855aSVille Syrjälä 		    crtc_state->cpu_transcoder)
4184d82a855aSVille Syrjälä 			continue;
4185d82a855aSVille Syrjälä 
4186a621860aSVille Syrjälä 		intel_dp_stop_link_train(enc_to_intel_dp(slave_encoder),
4187a621860aSVille Syrjälä 					 slave_crtc_state);
4188d82a855aSVille Syrjälä 	}
4189d82a855aSVille Syrjälä 
4190d82a855aSVille Syrjälä 	usleep_range(200, 400);
4191d82a855aSVille Syrjälä 
4192a621860aSVille Syrjälä 	intel_dp_stop_link_train(enc_to_intel_dp(encoder),
4193a621860aSVille Syrjälä 				 crtc_state);
4194d82a855aSVille Syrjälä }
4195d82a855aSVille Syrjälä 
4196ede9771dSVille Syrjälä static void intel_enable_ddi_dp(struct intel_atomic_state *state,
4197ede9771dSVille Syrjälä 				struct intel_encoder *encoder,
4198379bc100SJani Nikula 				const struct intel_crtc_state *crtc_state,
4199379bc100SJani Nikula 				const struct drm_connector_state *conn_state)
4200379bc100SJani Nikula {
4201379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4202b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4203998cc864SUma Shankar 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
4204379bc100SJani Nikula 	enum port port = encoder->port;
4205379bc100SJani Nikula 
4206379bc100SJani Nikula 	if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
4207a621860aSVille Syrjälä 		intel_dp_stop_link_train(intel_dp, crtc_state);
4208379bc100SJani Nikula 
4209379bc100SJani Nikula 	intel_edp_backlight_on(crtc_state, conn_state);
42107a00e68bSGwan-gyeong Mun 	intel_psr_enable(intel_dp, crtc_state, conn_state);
4211998cc864SUma Shankar 
4212998cc864SUma Shankar 	if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
42131bf3657cSGwan-gyeong Mun 		intel_dp_set_infoframes(encoder, true, crtc_state, conn_state);
4214998cc864SUma Shankar 
4215379bc100SJani Nikula 	intel_edp_drrs_enable(intel_dp, crtc_state);
4216379bc100SJani Nikula 
4217379bc100SJani Nikula 	if (crtc_state->has_audio)
4218379bc100SJani Nikula 		intel_audio_codec_enable(encoder, crtc_state, conn_state);
4219d82a855aSVille Syrjälä 
4220d82a855aSVille Syrjälä 	trans_port_sync_stop_link_train(state, encoder, crtc_state);
4221379bc100SJani Nikula }
4222379bc100SJani Nikula 
4223379bc100SJani Nikula static i915_reg_t
4224379bc100SJani Nikula gen9_chicken_trans_reg_by_port(struct drm_i915_private *dev_priv,
4225379bc100SJani Nikula 			       enum port port)
4226379bc100SJani Nikula {
422712c4d4c1SVille Syrjälä 	static const enum transcoder trans[] = {
422812c4d4c1SVille Syrjälä 		[PORT_A] = TRANSCODER_EDP,
422912c4d4c1SVille Syrjälä 		[PORT_B] = TRANSCODER_A,
423012c4d4c1SVille Syrjälä 		[PORT_C] = TRANSCODER_B,
423112c4d4c1SVille Syrjälä 		[PORT_D] = TRANSCODER_C,
423212c4d4c1SVille Syrjälä 		[PORT_E] = TRANSCODER_A,
4233379bc100SJani Nikula 	};
4234379bc100SJani Nikula 
42351de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, INTEL_GEN(dev_priv) < 9);
4236379bc100SJani Nikula 
42371de143ccSPankaj Bharadiya 	if (drm_WARN_ON(&dev_priv->drm, port < PORT_A || port > PORT_E))
4238379bc100SJani Nikula 		port = PORT_A;
4239379bc100SJani Nikula 
424012c4d4c1SVille Syrjälä 	return CHICKEN_TRANS(trans[port]);
4241379bc100SJani Nikula }
4242379bc100SJani Nikula 
4243ede9771dSVille Syrjälä static void intel_enable_ddi_hdmi(struct intel_atomic_state *state,
4244ede9771dSVille Syrjälä 				  struct intel_encoder *encoder,
4245379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state,
4246379bc100SJani Nikula 				  const struct drm_connector_state *conn_state)
4247379bc100SJani Nikula {
4248379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4249b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
4250379bc100SJani Nikula 	struct drm_connector *connector = conn_state->connector;
4251379bc100SJani Nikula 	enum port port = encoder->port;
4252379bc100SJani Nikula 
4253379bc100SJani Nikula 	if (!intel_hdmi_handle_sink_scrambling(encoder, connector,
4254379bc100SJani Nikula 					       crtc_state->hdmi_high_tmds_clock_ratio,
4255379bc100SJani Nikula 					       crtc_state->hdmi_scrambling))
425647bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
425747bdb1caSJani Nikula 			    "[CONNECTOR:%d:%s] Failed to configure sink scrambling/TMDS bit clock ratio\n",
4258379bc100SJani Nikula 			    connector->base.id, connector->name);
4259379bc100SJani Nikula 
4260379bc100SJani Nikula 	/* Display WA #1143: skl,kbl,cfl */
4261379bc100SJani Nikula 	if (IS_GEN9_BC(dev_priv)) {
4262379bc100SJani Nikula 		/*
4263379bc100SJani Nikula 		 * For some reason these chicken bits have been
4264379bc100SJani Nikula 		 * stuffed into a transcoder register, event though
4265379bc100SJani Nikula 		 * the bits affect a specific DDI port rather than
4266379bc100SJani Nikula 		 * a specific transcoder.
4267379bc100SJani Nikula 		 */
4268379bc100SJani Nikula 		i915_reg_t reg = gen9_chicken_trans_reg_by_port(dev_priv, port);
4269379bc100SJani Nikula 		u32 val;
4270379bc100SJani Nikula 
4271f7960e7fSJani Nikula 		val = intel_de_read(dev_priv, reg);
4272379bc100SJani Nikula 
4273379bc100SJani Nikula 		if (port == PORT_E)
4274379bc100SJani Nikula 			val |= DDIE_TRAINING_OVERRIDE_ENABLE |
4275379bc100SJani Nikula 				DDIE_TRAINING_OVERRIDE_VALUE;
4276379bc100SJani Nikula 		else
4277379bc100SJani Nikula 			val |= DDI_TRAINING_OVERRIDE_ENABLE |
4278379bc100SJani Nikula 				DDI_TRAINING_OVERRIDE_VALUE;
4279379bc100SJani Nikula 
4280f7960e7fSJani Nikula 		intel_de_write(dev_priv, reg, val);
4281f7960e7fSJani Nikula 		intel_de_posting_read(dev_priv, reg);
4282379bc100SJani Nikula 
4283379bc100SJani Nikula 		udelay(1);
4284379bc100SJani Nikula 
4285379bc100SJani Nikula 		if (port == PORT_E)
4286379bc100SJani Nikula 			val &= ~(DDIE_TRAINING_OVERRIDE_ENABLE |
4287379bc100SJani Nikula 				 DDIE_TRAINING_OVERRIDE_VALUE);
4288379bc100SJani Nikula 		else
4289379bc100SJani Nikula 			val &= ~(DDI_TRAINING_OVERRIDE_ENABLE |
4290379bc100SJani Nikula 				 DDI_TRAINING_OVERRIDE_VALUE);
4291379bc100SJani Nikula 
4292f7960e7fSJani Nikula 		intel_de_write(dev_priv, reg, val);
4293379bc100SJani Nikula 	}
4294379bc100SJani Nikula 
4295379bc100SJani Nikula 	/* In HDMI/DVI mode, the port width, and swing/emphasis values
4296379bc100SJani Nikula 	 * are ignored so nothing special needs to be done besides
4297379bc100SJani Nikula 	 * enabling the port.
4298379bc100SJani Nikula 	 */
4299f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_CTL(port),
4300379bc100SJani Nikula 		       dig_port->saved_port_bits | DDI_BUF_CTL_ENABLE);
4301379bc100SJani Nikula 
4302379bc100SJani Nikula 	if (crtc_state->has_audio)
4303379bc100SJani Nikula 		intel_audio_codec_enable(encoder, crtc_state, conn_state);
4304379bc100SJani Nikula }
4305379bc100SJani Nikula 
4306ede9771dSVille Syrjälä static void intel_enable_ddi(struct intel_atomic_state *state,
4307ede9771dSVille Syrjälä 			     struct intel_encoder *encoder,
4308379bc100SJani Nikula 			     const struct intel_crtc_state *crtc_state,
4309379bc100SJani Nikula 			     const struct drm_connector_state *conn_state)
4310379bc100SJani Nikula {
43118b4f2137SPankaj Bharadiya 	drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder);
431221fd23acSJani Nikula 
43134e3cdb45SManasi Navare 	if (!crtc_state->bigjoiner_slave)
4314eed22a46SVille Syrjälä 		intel_ddi_enable_transcoder_func(encoder, crtc_state);
43157c2fedd7SVille Syrjälä 
431621fd23acSJani Nikula 	intel_enable_pipe(crtc_state);
431721fd23acSJani Nikula 
431821fd23acSJani Nikula 	intel_crtc_vblank_on(crtc_state);
431921fd23acSJani Nikula 
4320379bc100SJani Nikula 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
4321ede9771dSVille Syrjälä 		intel_enable_ddi_hdmi(state, encoder, crtc_state, conn_state);
4322379bc100SJani Nikula 	else
4323ede9771dSVille Syrjälä 		intel_enable_ddi_dp(state, encoder, crtc_state, conn_state);
4324379bc100SJani Nikula 
4325379bc100SJani Nikula 	/* Enable hdcp if it's desired */
4326379bc100SJani Nikula 	if (conn_state->content_protection ==
4327379bc100SJani Nikula 	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
4328d456512cSRamalingam C 		intel_hdcp_enable(to_intel_connector(conn_state->connector),
4329*fc6097d4SAnshuman Gupta 				  crtc_state,
4330d456512cSRamalingam C 				  (u8)conn_state->hdcp_content_type);
4331379bc100SJani Nikula }
4332379bc100SJani Nikula 
4333ede9771dSVille Syrjälä static void intel_disable_ddi_dp(struct intel_atomic_state *state,
4334ede9771dSVille Syrjälä 				 struct intel_encoder *encoder,
4335379bc100SJani Nikula 				 const struct intel_crtc_state *old_crtc_state,
4336379bc100SJani Nikula 				 const struct drm_connector_state *old_conn_state)
4337379bc100SJani Nikula {
4338b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4339379bc100SJani Nikula 
4340379bc100SJani Nikula 	intel_dp->link_trained = false;
4341379bc100SJani Nikula 
4342379bc100SJani Nikula 	if (old_crtc_state->has_audio)
4343379bc100SJani Nikula 		intel_audio_codec_disable(encoder,
4344379bc100SJani Nikula 					  old_crtc_state, old_conn_state);
4345379bc100SJani Nikula 
4346379bc100SJani Nikula 	intel_edp_drrs_disable(intel_dp, old_crtc_state);
4347379bc100SJani Nikula 	intel_psr_disable(intel_dp, old_crtc_state);
4348379bc100SJani Nikula 	intel_edp_backlight_off(old_conn_state);
4349379bc100SJani Nikula 	/* Disable the decompression in DP Sink */
4350379bc100SJani Nikula 	intel_dp_sink_set_decompression_state(intel_dp, old_crtc_state,
4351379bc100SJani Nikula 					      false);
4352379bc100SJani Nikula }
4353379bc100SJani Nikula 
4354ede9771dSVille Syrjälä static void intel_disable_ddi_hdmi(struct intel_atomic_state *state,
4355ede9771dSVille Syrjälä 				   struct intel_encoder *encoder,
4356379bc100SJani Nikula 				   const struct intel_crtc_state *old_crtc_state,
4357379bc100SJani Nikula 				   const struct drm_connector_state *old_conn_state)
4358379bc100SJani Nikula {
435947bdb1caSJani Nikula 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
4360379bc100SJani Nikula 	struct drm_connector *connector = old_conn_state->connector;
4361379bc100SJani Nikula 
4362379bc100SJani Nikula 	if (old_crtc_state->has_audio)
4363379bc100SJani Nikula 		intel_audio_codec_disable(encoder,
4364379bc100SJani Nikula 					  old_crtc_state, old_conn_state);
4365379bc100SJani Nikula 
4366379bc100SJani Nikula 	if (!intel_hdmi_handle_sink_scrambling(encoder, connector,
4367379bc100SJani Nikula 					       false, false))
436847bdb1caSJani Nikula 		drm_dbg_kms(&i915->drm,
436947bdb1caSJani Nikula 			    "[CONNECTOR:%d:%s] Failed to reset sink scrambling/TMDS bit clock ratio\n",
4370379bc100SJani Nikula 			    connector->base.id, connector->name);
4371379bc100SJani Nikula }
4372379bc100SJani Nikula 
4373ede9771dSVille Syrjälä static void intel_disable_ddi(struct intel_atomic_state *state,
4374ede9771dSVille Syrjälä 			      struct intel_encoder *encoder,
4375379bc100SJani Nikula 			      const struct intel_crtc_state *old_crtc_state,
4376379bc100SJani Nikula 			      const struct drm_connector_state *old_conn_state)
4377379bc100SJani Nikula {
4378379bc100SJani Nikula 	intel_hdcp_disable(to_intel_connector(old_conn_state->connector));
4379379bc100SJani Nikula 
4380379bc100SJani Nikula 	if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
4381ede9771dSVille Syrjälä 		intel_disable_ddi_hdmi(state, encoder, old_crtc_state,
4382ede9771dSVille Syrjälä 				       old_conn_state);
4383379bc100SJani Nikula 	else
4384ede9771dSVille Syrjälä 		intel_disable_ddi_dp(state, encoder, old_crtc_state,
4385ede9771dSVille Syrjälä 				     old_conn_state);
4386379bc100SJani Nikula }
4387379bc100SJani Nikula 
4388ede9771dSVille Syrjälä static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state,
4389ede9771dSVille Syrjälä 				     struct intel_encoder *encoder,
4390379bc100SJani Nikula 				     const struct intel_crtc_state *crtc_state,
4391379bc100SJani Nikula 				     const struct drm_connector_state *conn_state)
4392379bc100SJani Nikula {
4393b7d02c3aSVille Syrjälä 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
4394379bc100SJani Nikula 
43950c06fa15SGwan-gyeong Mun 	intel_ddi_set_dp_msa(crtc_state, conn_state);
4396379bc100SJani Nikula 
43977a00e68bSGwan-gyeong Mun 	intel_psr_update(intel_dp, crtc_state, conn_state);
439876d45d06SGwan-gyeong Mun 	intel_dp_set_infoframes(encoder, true, crtc_state, conn_state);
43998040fefaSJosé Roberto de Souza 	intel_edp_drrs_update(intel_dp, crtc_state);
4400379bc100SJani Nikula 
4401ede9771dSVille Syrjälä 	intel_panel_update_backlight(state, encoder, crtc_state, conn_state);
4402379bc100SJani Nikula }
4403379bc100SJani Nikula 
4404f1c7a36bSSean Paul void intel_ddi_update_pipe(struct intel_atomic_state *state,
4405ede9771dSVille Syrjälä 			   struct intel_encoder *encoder,
4406379bc100SJani Nikula 			   const struct intel_crtc_state *crtc_state,
4407379bc100SJani Nikula 			   const struct drm_connector_state *conn_state)
4408379bc100SJani Nikula {
4409d456512cSRamalingam C 
4410f1c7a36bSSean Paul 	if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) &&
4411f1c7a36bSSean Paul 	    !intel_encoder_is_mst(encoder))
4412ede9771dSVille Syrjälä 		intel_ddi_update_pipe_dp(state, encoder, crtc_state,
4413ede9771dSVille Syrjälä 					 conn_state);
4414379bc100SJani Nikula 
4415ede9771dSVille Syrjälä 	intel_hdcp_update_pipe(state, encoder, crtc_state, conn_state);
4416379bc100SJani Nikula }
4417379bc100SJani Nikula 
4418379bc100SJani Nikula static void
441924a7bfe0SImre Deak intel_ddi_update_prepare(struct intel_atomic_state *state,
442024a7bfe0SImre Deak 			 struct intel_encoder *encoder,
442124a7bfe0SImre Deak 			 struct intel_crtc *crtc)
442224a7bfe0SImre Deak {
442324a7bfe0SImre Deak 	struct intel_crtc_state *crtc_state =
442424a7bfe0SImre Deak 		crtc ? intel_atomic_get_new_crtc_state(state, crtc) : NULL;
442524a7bfe0SImre Deak 	int required_lanes = crtc_state ? crtc_state->lane_count : 1;
442624a7bfe0SImre Deak 
44278b4f2137SPankaj Bharadiya 	drm_WARN_ON(state->base.dev, crtc && crtc->active);
442824a7bfe0SImre Deak 
4429b7d02c3aSVille Syrjälä 	intel_tc_port_get_link(enc_to_dig_port(encoder),
4430b7d02c3aSVille Syrjälä 		               required_lanes);
44311326a92cSMaarten Lankhorst 	if (crtc_state && crtc_state->hw.active)
443224a7bfe0SImre Deak 		intel_update_active_dpll(state, crtc, encoder);
443324a7bfe0SImre Deak }
443424a7bfe0SImre Deak 
443524a7bfe0SImre Deak static void
443624a7bfe0SImre Deak intel_ddi_update_complete(struct intel_atomic_state *state,
443724a7bfe0SImre Deak 			  struct intel_encoder *encoder,
443824a7bfe0SImre Deak 			  struct intel_crtc *crtc)
443924a7bfe0SImre Deak {
4440b7d02c3aSVille Syrjälä 	intel_tc_port_put_link(enc_to_dig_port(encoder));
444124a7bfe0SImre Deak }
444224a7bfe0SImre Deak 
444324a7bfe0SImre Deak static void
4444ede9771dSVille Syrjälä intel_ddi_pre_pll_enable(struct intel_atomic_state *state,
4445ede9771dSVille Syrjälä 			 struct intel_encoder *encoder,
4446379bc100SJani Nikula 			 const struct intel_crtc_state *crtc_state,
4447379bc100SJani Nikula 			 const struct drm_connector_state *conn_state)
4448379bc100SJani Nikula {
4449379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4450b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
4451d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
4452d8fe2ab6SMatt Roper 	bool is_tc_port = intel_phy_is_tc(dev_priv, phy);
4453379bc100SJani Nikula 
445424a7bfe0SImre Deak 	if (is_tc_port)
445524a7bfe0SImre Deak 		intel_tc_port_get_link(dig_port, crtc_state->lane_count);
445624a7bfe0SImre Deak 
4457162e68e1SImre Deak 	if (intel_crtc_has_dp_encoder(crtc_state) || is_tc_port) {
4458162e68e1SImre Deak 		drm_WARN_ON(&dev_priv->drm, dig_port->aux_wakeref);
4459162e68e1SImre Deak 		dig_port->aux_wakeref =
4460379bc100SJani Nikula 			intel_display_power_get(dev_priv,
4461379bc100SJani Nikula 						intel_ddi_main_link_aux_domain(dig_port));
4462162e68e1SImre Deak 	}
4463379bc100SJani Nikula 
44649d44dcb9SLucas De Marchi 	if (is_tc_port && dig_port->tc_mode != TC_PORT_TBT_ALT)
44659d44dcb9SLucas De Marchi 		/*
44669d44dcb9SLucas De Marchi 		 * Program the lane count for static/dynamic connections on
44679d44dcb9SLucas De Marchi 		 * Type-C ports.  Skip this step for TBT.
44689d44dcb9SLucas De Marchi 		 */
44699d44dcb9SLucas De Marchi 		intel_tc_port_set_fia_lane_count(dig_port, crtc_state->lane_count);
44709d44dcb9SLucas De Marchi 	else if (IS_GEN9_LP(dev_priv))
4471379bc100SJani Nikula 		bxt_ddi_phy_set_lane_optim_mask(encoder,
4472379bc100SJani Nikula 						crtc_state->lane_lat_optim_mask);
4473379bc100SJani Nikula }
4474379bc100SJani Nikula 
4475a621860aSVille Syrjälä static void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp,
4476a621860aSVille Syrjälä 					   const struct intel_crtc_state *crtc_state)
4477379bc100SJani Nikula {
4478ef79fafeSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4479ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4480ef79fafeSVille Syrjälä 	enum port port = encoder->port;
448135ac28a8SLucas De Marchi 	u32 dp_tp_ctl, ddi_buf_ctl;
4482379bc100SJani Nikula 	bool wait = false;
4483379bc100SJani Nikula 
4484ef79fafeSVille Syrjälä 	dp_tp_ctl = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
448535ac28a8SLucas De Marchi 
448635ac28a8SLucas De Marchi 	if (dp_tp_ctl & DP_TP_CTL_ENABLE) {
4487f7960e7fSJani Nikula 		ddi_buf_ctl = intel_de_read(dev_priv, DDI_BUF_CTL(port));
448835ac28a8SLucas De Marchi 		if (ddi_buf_ctl & DDI_BUF_CTL_ENABLE) {
4489f7960e7fSJani Nikula 			intel_de_write(dev_priv, DDI_BUF_CTL(port),
449035ac28a8SLucas De Marchi 				       ddi_buf_ctl & ~DDI_BUF_CTL_ENABLE);
4491379bc100SJani Nikula 			wait = true;
4492379bc100SJani Nikula 		}
4493379bc100SJani Nikula 
449435ac28a8SLucas De Marchi 		dp_tp_ctl &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
449535ac28a8SLucas De Marchi 		dp_tp_ctl |= DP_TP_CTL_LINK_TRAIN_PAT1;
4496ef79fafeSVille Syrjälä 		intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), dp_tp_ctl);
4497ef79fafeSVille Syrjälä 		intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
4498379bc100SJani Nikula 
4499379bc100SJani Nikula 		if (wait)
4500379bc100SJani Nikula 			intel_wait_ddi_buf_idle(dev_priv, port);
4501379bc100SJani Nikula 	}
4502379bc100SJani Nikula 
4503963501bdSImre Deak 	dp_tp_ctl = DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_PAT1;
4504a621860aSVille Syrjälä 	if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
450535ac28a8SLucas De Marchi 		dp_tp_ctl |= DP_TP_CTL_MODE_MST;
4506a621860aSVille Syrjälä 	} else {
450735ac28a8SLucas De Marchi 		dp_tp_ctl |= DP_TP_CTL_MODE_SST;
4508379bc100SJani Nikula 		if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
450935ac28a8SLucas De Marchi 			dp_tp_ctl |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
4510379bc100SJani Nikula 	}
4511ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), dp_tp_ctl);
4512ef79fafeSVille Syrjälä 	intel_de_posting_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
4513379bc100SJani Nikula 
4514379bc100SJani Nikula 	intel_dp->DP |= DDI_BUF_CTL_ENABLE;
4515f7960e7fSJani Nikula 	intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP);
4516f7960e7fSJani Nikula 	intel_de_posting_read(dev_priv, DDI_BUF_CTL(port));
4517379bc100SJani Nikula 
4518e828da30SManasi Navare 	intel_wait_ddi_buf_active(dev_priv, port);
4519379bc100SJani Nikula }
4520379bc100SJani Nikula 
4521eee3f911SVille Syrjälä static void intel_ddi_set_link_train(struct intel_dp *intel_dp,
4522a621860aSVille Syrjälä 				     const struct intel_crtc_state *crtc_state,
4523eee3f911SVille Syrjälä 				     u8 dp_train_pat)
4524eee3f911SVille Syrjälä {
4525ef79fafeSVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4526ef79fafeSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4527eee3f911SVille Syrjälä 	u32 temp;
4528eee3f911SVille Syrjälä 
4529ef79fafeSVille Syrjälä 	temp = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
4530eee3f911SVille Syrjälä 
4531eee3f911SVille Syrjälä 	temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
45326777a855SImre Deak 	switch (intel_dp_training_pattern_symbol(dp_train_pat)) {
4533eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_DISABLE:
4534eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
4535eee3f911SVille Syrjälä 		break;
4536eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_1:
4537eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
4538eee3f911SVille Syrjälä 		break;
4539eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_2:
4540eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
4541eee3f911SVille Syrjälä 		break;
4542eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_3:
4543eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
4544eee3f911SVille Syrjälä 		break;
4545eee3f911SVille Syrjälä 	case DP_TRAINING_PATTERN_4:
4546eee3f911SVille Syrjälä 		temp |= DP_TP_CTL_LINK_TRAIN_PAT4;
4547eee3f911SVille Syrjälä 		break;
4548eee3f911SVille Syrjälä 	}
4549eee3f911SVille Syrjälä 
4550ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), temp);
4551eee3f911SVille Syrjälä }
4552eee3f911SVille Syrjälä 
4553a621860aSVille Syrjälä static void intel_ddi_set_idle_link_train(struct intel_dp *intel_dp,
4554a621860aSVille Syrjälä 					  const struct intel_crtc_state *crtc_state)
45558fdda385SVille Syrjälä {
45568fdda385SVille Syrjälä 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
45578fdda385SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
45588fdda385SVille Syrjälä 	enum port port = encoder->port;
45598fdda385SVille Syrjälä 	u32 val;
45608fdda385SVille Syrjälä 
4561ef79fafeSVille Syrjälä 	val = intel_de_read(dev_priv, dp_tp_ctl_reg(encoder, crtc_state));
45628fdda385SVille Syrjälä 	val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
45638fdda385SVille Syrjälä 	val |= DP_TP_CTL_LINK_TRAIN_IDLE;
4564ef79fafeSVille Syrjälä 	intel_de_write(dev_priv, dp_tp_ctl_reg(encoder, crtc_state), val);
45658fdda385SVille Syrjälä 
45668fdda385SVille Syrjälä 	/*
45678fdda385SVille Syrjälä 	 * Until TGL on PORT_A we can have only eDP in SST mode. There the only
45688fdda385SVille Syrjälä 	 * reason we need to set idle transmission mode is to work around a HW
45698fdda385SVille Syrjälä 	 * issue where we enable the pipe while not in idle link-training mode.
45708fdda385SVille Syrjälä 	 * In this case there is requirement to wait for a minimum number of
45718fdda385SVille Syrjälä 	 * idle patterns to be sent.
45728fdda385SVille Syrjälä 	 */
45738fdda385SVille Syrjälä 	if (port == PORT_A && INTEL_GEN(dev_priv) < 12)
45748fdda385SVille Syrjälä 		return;
45758fdda385SVille Syrjälä 
4576ef79fafeSVille Syrjälä 	if (intel_de_wait_for_set(dev_priv,
4577ef79fafeSVille Syrjälä 				  dp_tp_status_reg(encoder, crtc_state),
45788fdda385SVille Syrjälä 				  DP_TP_STATUS_IDLE_DONE, 1))
45798fdda385SVille Syrjälä 		drm_err(&dev_priv->drm,
45808fdda385SVille Syrjälä 			"Timed out waiting for DP idle patterns\n");
45818fdda385SVille Syrjälä }
45828fdda385SVille Syrjälä 
4583379bc100SJani Nikula static bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
4584379bc100SJani Nikula 				       enum transcoder cpu_transcoder)
4585379bc100SJani Nikula {
4586379bc100SJani Nikula 	if (cpu_transcoder == TRANSCODER_EDP)
4587379bc100SJani Nikula 		return false;
4588379bc100SJani Nikula 
4589379bc100SJani Nikula 	if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO))
4590379bc100SJani Nikula 		return false;
4591379bc100SJani Nikula 
4592f7960e7fSJani Nikula 	return intel_de_read(dev_priv, HSW_AUD_PIN_ELD_CP_VLD) &
4593379bc100SJani Nikula 		AUDIO_OUTPUT_ENABLE(cpu_transcoder);
4594379bc100SJani Nikula }
4595379bc100SJani Nikula 
4596379bc100SJani Nikula void intel_ddi_compute_min_voltage_level(struct drm_i915_private *dev_priv,
4597379bc100SJani Nikula 					 struct intel_crtc_state *crtc_state)
4598379bc100SJani Nikula {
45990fde0b1dSMatt Roper 	if (INTEL_GEN(dev_priv) >= 12 && crtc_state->port_clock > 594000)
46000fde0b1dSMatt Roper 		crtc_state->min_voltage_level = 2;
460124ea098bSTejas Upadhyay 	else if (IS_JSL_EHL(dev_priv) && crtc_state->port_clock > 594000)
46029d5fd37eSMatt Roper 		crtc_state->min_voltage_level = 3;
46039d5fd37eSMatt Roper 	else if (INTEL_GEN(dev_priv) >= 11 && crtc_state->port_clock > 594000)
4604379bc100SJani Nikula 		crtc_state->min_voltage_level = 1;
4605379bc100SJani Nikula 	else if (IS_CANNONLAKE(dev_priv) && crtc_state->port_clock > 594000)
4606379bc100SJani Nikula 		crtc_state->min_voltage_level = 2;
4607379bc100SJani Nikula }
4608379bc100SJani Nikula 
4609dc5b8ed5SVille Syrjälä static enum transcoder bdw_transcoder_master_readout(struct drm_i915_private *dev_priv,
461002d8ea47SVille Syrjälä 						     enum transcoder cpu_transcoder)
461102d8ea47SVille Syrjälä {
4612dc5b8ed5SVille Syrjälä 	u32 master_select;
461302d8ea47SVille Syrjälä 
4614dc5b8ed5SVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 11) {
4615dc5b8ed5SVille Syrjälä 		u32 ctl2 = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL2(cpu_transcoder));
461602d8ea47SVille Syrjälä 
461702d8ea47SVille Syrjälä 		if ((ctl2 & PORT_SYNC_MODE_ENABLE) == 0)
461802d8ea47SVille Syrjälä 			return INVALID_TRANSCODER;
461902d8ea47SVille Syrjälä 
4620d4d7d9caSVille Syrjälä 		master_select = REG_FIELD_GET(PORT_SYNC_MODE_MASTER_SELECT_MASK, ctl2);
4621dc5b8ed5SVille Syrjälä 	} else {
4622dc5b8ed5SVille Syrjälä 		u32 ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
4623dc5b8ed5SVille Syrjälä 
4624dc5b8ed5SVille Syrjälä 		if ((ctl & TRANS_DDI_PORT_SYNC_ENABLE) == 0)
4625dc5b8ed5SVille Syrjälä 			return INVALID_TRANSCODER;
4626dc5b8ed5SVille Syrjälä 
4627dc5b8ed5SVille Syrjälä 		master_select = REG_FIELD_GET(TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK, ctl);
4628dc5b8ed5SVille Syrjälä 	}
462902d8ea47SVille Syrjälä 
463002d8ea47SVille Syrjälä 	if (master_select == 0)
463102d8ea47SVille Syrjälä 		return TRANSCODER_EDP;
463202d8ea47SVille Syrjälä 	else
463302d8ea47SVille Syrjälä 		return master_select - 1;
463402d8ea47SVille Syrjälä }
463502d8ea47SVille Syrjälä 
4636dc5b8ed5SVille Syrjälä static void bdw_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
463702d8ea47SVille Syrjälä {
463802d8ea47SVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
463902d8ea47SVille Syrjälä 	u32 transcoders = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
464002d8ea47SVille Syrjälä 		BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
464102d8ea47SVille Syrjälä 	enum transcoder cpu_transcoder;
464202d8ea47SVille Syrjälä 
464302d8ea47SVille Syrjälä 	crtc_state->master_transcoder =
4644dc5b8ed5SVille Syrjälä 		bdw_transcoder_master_readout(dev_priv, crtc_state->cpu_transcoder);
464502d8ea47SVille Syrjälä 
464602d8ea47SVille Syrjälä 	for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) {
464702d8ea47SVille Syrjälä 		enum intel_display_power_domain power_domain;
464802d8ea47SVille Syrjälä 		intel_wakeref_t trans_wakeref;
464902d8ea47SVille Syrjälä 
465002d8ea47SVille Syrjälä 		power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
465102d8ea47SVille Syrjälä 		trans_wakeref = intel_display_power_get_if_enabled(dev_priv,
465202d8ea47SVille Syrjälä 								   power_domain);
465302d8ea47SVille Syrjälä 
465402d8ea47SVille Syrjälä 		if (!trans_wakeref)
465502d8ea47SVille Syrjälä 			continue;
465602d8ea47SVille Syrjälä 
4657dc5b8ed5SVille Syrjälä 		if (bdw_transcoder_master_readout(dev_priv, cpu_transcoder) ==
465802d8ea47SVille Syrjälä 		    crtc_state->cpu_transcoder)
465902d8ea47SVille Syrjälä 			crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder);
466002d8ea47SVille Syrjälä 
466102d8ea47SVille Syrjälä 		intel_display_power_put(dev_priv, power_domain, trans_wakeref);
466202d8ea47SVille Syrjälä 	}
466302d8ea47SVille Syrjälä 
466402d8ea47SVille Syrjälä 	drm_WARN_ON(&dev_priv->drm,
466502d8ea47SVille Syrjälä 		    crtc_state->master_transcoder != INVALID_TRANSCODER &&
466602d8ea47SVille Syrjälä 		    crtc_state->sync_mode_slaves_mask);
466702d8ea47SVille Syrjälä }
466802d8ea47SVille Syrjälä 
46690385eceaSManasi Navare static void intel_ddi_read_func_ctl(struct intel_encoder *encoder,
4670379bc100SJani Nikula 				    struct intel_crtc_state *pipe_config)
4671379bc100SJani Nikula {
4672379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
46732225f3c6SMaarten Lankhorst 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
4674379bc100SJani Nikula 	enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
4675a44289b9SUma Shankar 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
4676379bc100SJani Nikula 	u32 temp, flags = 0;
4677379bc100SJani Nikula 
4678f7960e7fSJani Nikula 	temp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
4679379bc100SJani Nikula 	if (temp & TRANS_DDI_PHSYNC)
4680379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_PHSYNC;
4681379bc100SJani Nikula 	else
4682379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_NHSYNC;
4683379bc100SJani Nikula 	if (temp & TRANS_DDI_PVSYNC)
4684379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_PVSYNC;
4685379bc100SJani Nikula 	else
4686379bc100SJani Nikula 		flags |= DRM_MODE_FLAG_NVSYNC;
4687379bc100SJani Nikula 
46881326a92cSMaarten Lankhorst 	pipe_config->hw.adjusted_mode.flags |= flags;
4689379bc100SJani Nikula 
4690379bc100SJani Nikula 	switch (temp & TRANS_DDI_BPC_MASK) {
4691379bc100SJani Nikula 	case TRANS_DDI_BPC_6:
4692379bc100SJani Nikula 		pipe_config->pipe_bpp = 18;
4693379bc100SJani Nikula 		break;
4694379bc100SJani Nikula 	case TRANS_DDI_BPC_8:
4695379bc100SJani Nikula 		pipe_config->pipe_bpp = 24;
4696379bc100SJani Nikula 		break;
4697379bc100SJani Nikula 	case TRANS_DDI_BPC_10:
4698379bc100SJani Nikula 		pipe_config->pipe_bpp = 30;
4699379bc100SJani Nikula 		break;
4700379bc100SJani Nikula 	case TRANS_DDI_BPC_12:
4701379bc100SJani Nikula 		pipe_config->pipe_bpp = 36;
4702379bc100SJani Nikula 		break;
4703379bc100SJani Nikula 	default:
4704379bc100SJani Nikula 		break;
4705379bc100SJani Nikula 	}
4706379bc100SJani Nikula 
4707379bc100SJani Nikula 	switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
4708379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_HDMI:
4709379bc100SJani Nikula 		pipe_config->has_hdmi_sink = true;
4710379bc100SJani Nikula 
4711379bc100SJani Nikula 		pipe_config->infoframes.enable |=
4712379bc100SJani Nikula 			intel_hdmi_infoframes_enabled(encoder, pipe_config);
4713379bc100SJani Nikula 
4714379bc100SJani Nikula 		if (pipe_config->infoframes.enable)
4715379bc100SJani Nikula 			pipe_config->has_infoframe = true;
4716379bc100SJani Nikula 
4717379bc100SJani Nikula 		if (temp & TRANS_DDI_HDMI_SCRAMBLING)
4718379bc100SJani Nikula 			pipe_config->hdmi_scrambling = true;
4719379bc100SJani Nikula 		if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
4720379bc100SJani Nikula 			pipe_config->hdmi_high_tmds_clock_ratio = true;
4721df561f66SGustavo A. R. Silva 		fallthrough;
4722379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DVI:
4723379bc100SJani Nikula 		pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI);
4724379bc100SJani Nikula 		pipe_config->lane_count = 4;
4725379bc100SJani Nikula 		break;
4726379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_FDI:
4727379bc100SJani Nikula 		pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG);
4728379bc100SJani Nikula 		break;
4729379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_SST:
4730379bc100SJani Nikula 		if (encoder->type == INTEL_OUTPUT_EDP)
4731379bc100SJani Nikula 			pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
4732379bc100SJani Nikula 		else
4733379bc100SJani Nikula 			pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
4734379bc100SJani Nikula 		pipe_config->lane_count =
4735379bc100SJani Nikula 			((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
4736379bc100SJani Nikula 		intel_dp_get_m_n(intel_crtc, pipe_config);
47378aa940c8SMaarten Lankhorst 
47388aa940c8SMaarten Lankhorst 		if (INTEL_GEN(dev_priv) >= 11) {
4739ef79fafeSVille Syrjälä 			i915_reg_t dp_tp_ctl = dp_tp_ctl_reg(encoder, pipe_config);
47408aa940c8SMaarten Lankhorst 
47418aa940c8SMaarten Lankhorst 			pipe_config->fec_enable =
4742f7960e7fSJani Nikula 				intel_de_read(dev_priv, dp_tp_ctl) & DP_TP_CTL_FEC_ENABLE;
47438aa940c8SMaarten Lankhorst 
474447bdb1caSJani Nikula 			drm_dbg_kms(&dev_priv->drm,
474547bdb1caSJani Nikula 				    "[ENCODER:%d:%s] Fec status: %u\n",
47468aa940c8SMaarten Lankhorst 				    encoder->base.base.id, encoder->base.name,
47478aa940c8SMaarten Lankhorst 				    pipe_config->fec_enable);
47488aa940c8SMaarten Lankhorst 		}
47498aa940c8SMaarten Lankhorst 
4750a44289b9SUma Shankar 		if (dig_port->lspcon.active && dig_port->dp.has_hdmi_sink)
4751a44289b9SUma Shankar 			pipe_config->infoframes.enable |=
4752a44289b9SUma Shankar 				intel_lspcon_infoframes_enabled(encoder, pipe_config);
4753a44289b9SUma Shankar 		else
4754dee66f3eSGwan-gyeong Mun 			pipe_config->infoframes.enable |=
4755dee66f3eSGwan-gyeong Mun 				intel_hdmi_infoframes_enabled(encoder, pipe_config);
4756379bc100SJani Nikula 		break;
4757379bc100SJani Nikula 	case TRANS_DDI_MODE_SELECT_DP_MST:
4758379bc100SJani Nikula 		pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST);
4759379bc100SJani Nikula 		pipe_config->lane_count =
4760379bc100SJani Nikula 			((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
47616671c367SJosé Roberto de Souza 
47626671c367SJosé Roberto de Souza 		if (INTEL_GEN(dev_priv) >= 12)
47636671c367SJosé Roberto de Souza 			pipe_config->mst_master_transcoder =
47646671c367SJosé Roberto de Souza 					REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK, temp);
47656671c367SJosé Roberto de Souza 
4766379bc100SJani Nikula 		intel_dp_get_m_n(intel_crtc, pipe_config);
4767dee66f3eSGwan-gyeong Mun 
4768dee66f3eSGwan-gyeong Mun 		pipe_config->infoframes.enable |=
4769dee66f3eSGwan-gyeong Mun 			intel_hdmi_infoframes_enabled(encoder, pipe_config);
4770379bc100SJani Nikula 		break;
4771379bc100SJani Nikula 	default:
4772379bc100SJani Nikula 		break;
4773379bc100SJani Nikula 	}
47740385eceaSManasi Navare }
47750385eceaSManasi Navare 
47760385eceaSManasi Navare void intel_ddi_get_config(struct intel_encoder *encoder,
47770385eceaSManasi Navare 			  struct intel_crtc_state *pipe_config)
47780385eceaSManasi Navare {
47790385eceaSManasi Navare 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
47800385eceaSManasi Navare 	enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
47810385eceaSManasi Navare 
47820385eceaSManasi Navare 	/* XXX: DSI transcoder paranoia */
47830385eceaSManasi Navare 	if (drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder)))
47840385eceaSManasi Navare 		return;
47850385eceaSManasi Navare 
47860385eceaSManasi Navare 	if (pipe_config->bigjoiner_slave) {
47870385eceaSManasi Navare 		/* read out pipe settings from master */
47880385eceaSManasi Navare 		enum transcoder save = pipe_config->cpu_transcoder;
47890385eceaSManasi Navare 
47900385eceaSManasi Navare 		/* Our own transcoder needs to be disabled when reading it in intel_ddi_read_func_ctl() */
47910385eceaSManasi Navare 		WARN_ON(pipe_config->output_types);
47920385eceaSManasi Navare 		pipe_config->cpu_transcoder = (enum transcoder)pipe_config->bigjoiner_linked_crtc->pipe;
47930385eceaSManasi Navare 		intel_ddi_read_func_ctl(encoder, pipe_config);
47940385eceaSManasi Navare 		pipe_config->cpu_transcoder = save;
47950385eceaSManasi Navare 	} else {
47960385eceaSManasi Navare 		intel_ddi_read_func_ctl(encoder, pipe_config);
47970385eceaSManasi Navare 	}
4798379bc100SJani Nikula 
4799379bc100SJani Nikula 	pipe_config->has_audio =
4800379bc100SJani Nikula 		intel_ddi_is_audio_enabled(dev_priv, cpu_transcoder);
4801379bc100SJani Nikula 
4802379bc100SJani Nikula 	if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
4803379bc100SJani Nikula 	    pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
4804379bc100SJani Nikula 		/*
4805379bc100SJani Nikula 		 * This is a big fat ugly hack.
4806379bc100SJani Nikula 		 *
4807379bc100SJani Nikula 		 * Some machines in UEFI boot mode provide us a VBT that has 18
4808379bc100SJani Nikula 		 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
4809379bc100SJani Nikula 		 * unknown we fail to light up. Yet the same BIOS boots up with
4810379bc100SJani Nikula 		 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
4811379bc100SJani Nikula 		 * max, not what it tells us to use.
4812379bc100SJani Nikula 		 *
4813379bc100SJani Nikula 		 * Note: This will still be broken if the eDP panel is not lit
4814379bc100SJani Nikula 		 * up by the BIOS, and thus we can't get the mode at module
4815379bc100SJani Nikula 		 * load.
4816379bc100SJani Nikula 		 */
481747bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
481847bdb1caSJani Nikula 			    "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
4819379bc100SJani Nikula 			    pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
4820379bc100SJani Nikula 		dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
4821379bc100SJani Nikula 	}
4822379bc100SJani Nikula 
48230385eceaSManasi Navare 	if (!pipe_config->bigjoiner_slave)
4824379bc100SJani Nikula 		intel_ddi_clock_get(encoder, pipe_config);
4825379bc100SJani Nikula 
4826379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv))
4827379bc100SJani Nikula 		pipe_config->lane_lat_optim_mask =
4828379bc100SJani Nikula 			bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
4829379bc100SJani Nikula 
4830379bc100SJani Nikula 	intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
4831379bc100SJani Nikula 
4832379bc100SJani Nikula 	intel_hdmi_read_gcp_infoframe(encoder, pipe_config);
4833379bc100SJani Nikula 
4834379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
4835379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_AVI,
4836379bc100SJani Nikula 			     &pipe_config->infoframes.avi);
4837379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
4838379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_SPD,
4839379bc100SJani Nikula 			     &pipe_config->infoframes.spd);
4840379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
4841379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_VENDOR,
4842379bc100SJani Nikula 			     &pipe_config->infoframes.hdmi);
4843379bc100SJani Nikula 	intel_read_infoframe(encoder, pipe_config,
4844379bc100SJani Nikula 			     HDMI_INFOFRAME_TYPE_DRM,
4845379bc100SJani Nikula 			     &pipe_config->infoframes.drm);
484602d8ea47SVille Syrjälä 
4847dc5b8ed5SVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 8)
4848dc5b8ed5SVille Syrjälä 		bdw_get_trans_port_sync_config(pipe_config);
4849dee66f3eSGwan-gyeong Mun 
4850dee66f3eSGwan-gyeong Mun 	intel_read_dp_sdp(encoder, pipe_config, HDMI_PACKET_TYPE_GAMUT_METADATA);
48512c3928e4SGwan-gyeong Mun 	intel_read_dp_sdp(encoder, pipe_config, DP_SDP_VSC);
4852379bc100SJani Nikula }
4853379bc100SJani Nikula 
4854f9e76a6eSImre Deak static void intel_ddi_sync_state(struct intel_encoder *encoder,
4855f9e76a6eSImre Deak 				 const struct intel_crtc_state *crtc_state)
4856f9e76a6eSImre Deak {
4857f9e76a6eSImre Deak 	if (intel_crtc_has_dp_encoder(crtc_state))
4858f9e76a6eSImre Deak 		intel_dp_sync_state(encoder, crtc_state);
4859f9e76a6eSImre Deak }
4860f9e76a6eSImre Deak 
4861b671d6efSImre Deak static bool intel_ddi_initial_fastset_check(struct intel_encoder *encoder,
4862b671d6efSImre Deak 					    struct intel_crtc_state *crtc_state)
4863b671d6efSImre Deak {
4864b671d6efSImre Deak 	if (intel_crtc_has_dp_encoder(crtc_state))
4865b671d6efSImre Deak 		return intel_dp_initial_fastset_check(encoder, crtc_state);
4866b671d6efSImre Deak 
4867b671d6efSImre Deak 	return true;
4868b671d6efSImre Deak }
4869b671d6efSImre Deak 
4870379bc100SJani Nikula static enum intel_output_type
4871379bc100SJani Nikula intel_ddi_compute_output_type(struct intel_encoder *encoder,
4872379bc100SJani Nikula 			      struct intel_crtc_state *crtc_state,
4873379bc100SJani Nikula 			      struct drm_connector_state *conn_state)
4874379bc100SJani Nikula {
4875379bc100SJani Nikula 	switch (conn_state->connector->connector_type) {
4876379bc100SJani Nikula 	case DRM_MODE_CONNECTOR_HDMIA:
4877379bc100SJani Nikula 		return INTEL_OUTPUT_HDMI;
4878379bc100SJani Nikula 	case DRM_MODE_CONNECTOR_eDP:
4879379bc100SJani Nikula 		return INTEL_OUTPUT_EDP;
4880379bc100SJani Nikula 	case DRM_MODE_CONNECTOR_DisplayPort:
4881379bc100SJani Nikula 		return INTEL_OUTPUT_DP;
4882379bc100SJani Nikula 	default:
4883379bc100SJani Nikula 		MISSING_CASE(conn_state->connector->connector_type);
4884379bc100SJani Nikula 		return INTEL_OUTPUT_UNUSED;
4885379bc100SJani Nikula 	}
4886379bc100SJani Nikula }
4887379bc100SJani Nikula 
4888379bc100SJani Nikula static int intel_ddi_compute_config(struct intel_encoder *encoder,
4889379bc100SJani Nikula 				    struct intel_crtc_state *pipe_config,
4890379bc100SJani Nikula 				    struct drm_connector_state *conn_state)
4891379bc100SJani Nikula {
48922225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
4893379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4894379bc100SJani Nikula 	enum port port = encoder->port;
4895379bc100SJani Nikula 	int ret;
4896379bc100SJani Nikula 
489710cf8e75SVille Syrjälä 	if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A)
4898379bc100SJani Nikula 		pipe_config->cpu_transcoder = TRANSCODER_EDP;
4899379bc100SJani Nikula 
4900bdacf087SAnshuman Gupta 	if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) {
4901379bc100SJani Nikula 		ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
4902bdacf087SAnshuman Gupta 	} else {
4903379bc100SJani Nikula 		ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
4904bdacf087SAnshuman Gupta 	}
4905bdacf087SAnshuman Gupta 
4906379bc100SJani Nikula 	if (ret)
4907379bc100SJani Nikula 		return ret;
4908379bc100SJani Nikula 
4909379bc100SJani Nikula 	if (IS_HASWELL(dev_priv) && crtc->pipe == PIPE_A &&
4910379bc100SJani Nikula 	    pipe_config->cpu_transcoder == TRANSCODER_EDP)
4911379bc100SJani Nikula 		pipe_config->pch_pfit.force_thru =
4912379bc100SJani Nikula 			pipe_config->pch_pfit.enabled ||
4913379bc100SJani Nikula 			pipe_config->crc_enabled;
4914379bc100SJani Nikula 
4915379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv))
4916379bc100SJani Nikula 		pipe_config->lane_lat_optim_mask =
4917379bc100SJani Nikula 			bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count);
4918379bc100SJani Nikula 
4919379bc100SJani Nikula 	intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
4920379bc100SJani Nikula 
4921379bc100SJani Nikula 	return 0;
4922379bc100SJani Nikula }
4923379bc100SJani Nikula 
4924b50a1aa6SManasi Navare static bool mode_equal(const struct drm_display_mode *mode1,
4925b50a1aa6SManasi Navare 		       const struct drm_display_mode *mode2)
4926b50a1aa6SManasi Navare {
4927b50a1aa6SManasi Navare 	return drm_mode_match(mode1, mode2,
4928b50a1aa6SManasi Navare 			      DRM_MODE_MATCH_TIMINGS |
4929b50a1aa6SManasi Navare 			      DRM_MODE_MATCH_FLAGS |
4930b50a1aa6SManasi Navare 			      DRM_MODE_MATCH_3D_FLAGS) &&
4931b50a1aa6SManasi Navare 		mode1->clock == mode2->clock; /* we want an exact match */
4932b50a1aa6SManasi Navare }
4933b50a1aa6SManasi Navare 
4934b50a1aa6SManasi Navare static bool m_n_equal(const struct intel_link_m_n *m_n_1,
4935b50a1aa6SManasi Navare 		      const struct intel_link_m_n *m_n_2)
4936b50a1aa6SManasi Navare {
4937b50a1aa6SManasi Navare 	return m_n_1->tu == m_n_2->tu &&
4938b50a1aa6SManasi Navare 		m_n_1->gmch_m == m_n_2->gmch_m &&
4939b50a1aa6SManasi Navare 		m_n_1->gmch_n == m_n_2->gmch_n &&
4940b50a1aa6SManasi Navare 		m_n_1->link_m == m_n_2->link_m &&
4941b50a1aa6SManasi Navare 		m_n_1->link_n == m_n_2->link_n;
4942b50a1aa6SManasi Navare }
4943b50a1aa6SManasi Navare 
4944b50a1aa6SManasi Navare static bool crtcs_port_sync_compatible(const struct intel_crtc_state *crtc_state1,
4945b50a1aa6SManasi Navare 				       const struct intel_crtc_state *crtc_state2)
4946b50a1aa6SManasi Navare {
4947b50a1aa6SManasi Navare 	return crtc_state1->hw.active && crtc_state2->hw.active &&
4948b50a1aa6SManasi Navare 		crtc_state1->output_types == crtc_state2->output_types &&
4949b50a1aa6SManasi Navare 		crtc_state1->output_format == crtc_state2->output_format &&
4950b50a1aa6SManasi Navare 		crtc_state1->lane_count == crtc_state2->lane_count &&
4951b50a1aa6SManasi Navare 		crtc_state1->port_clock == crtc_state2->port_clock &&
4952b50a1aa6SManasi Navare 		mode_equal(&crtc_state1->hw.adjusted_mode,
4953b50a1aa6SManasi Navare 			   &crtc_state2->hw.adjusted_mode) &&
4954b50a1aa6SManasi Navare 		m_n_equal(&crtc_state1->dp_m_n, &crtc_state2->dp_m_n);
4955b50a1aa6SManasi Navare }
4956b50a1aa6SManasi Navare 
4957b50a1aa6SManasi Navare static u8
4958b50a1aa6SManasi Navare intel_ddi_port_sync_transcoders(const struct intel_crtc_state *ref_crtc_state,
4959b50a1aa6SManasi Navare 				int tile_group_id)
4960b50a1aa6SManasi Navare {
4961b50a1aa6SManasi Navare 	struct drm_connector *connector;
4962b50a1aa6SManasi Navare 	const struct drm_connector_state *conn_state;
4963b50a1aa6SManasi Navare 	struct drm_i915_private *dev_priv = to_i915(ref_crtc_state->uapi.crtc->dev);
4964b50a1aa6SManasi Navare 	struct intel_atomic_state *state =
4965b50a1aa6SManasi Navare 		to_intel_atomic_state(ref_crtc_state->uapi.state);
4966b50a1aa6SManasi Navare 	u8 transcoders = 0;
4967b50a1aa6SManasi Navare 	int i;
4968b50a1aa6SManasi Navare 
4969dc5b8ed5SVille Syrjälä 	/*
4970dc5b8ed5SVille Syrjälä 	 * We don't enable port sync on BDW due to missing w/as and
4971dc5b8ed5SVille Syrjälä 	 * due to not having adjusted the modeset sequence appropriately.
4972dc5b8ed5SVille Syrjälä 	 */
4973dc5b8ed5SVille Syrjälä 	if (INTEL_GEN(dev_priv) < 9)
4974b50a1aa6SManasi Navare 		return 0;
4975b50a1aa6SManasi Navare 
4976b50a1aa6SManasi Navare 	if (!intel_crtc_has_type(ref_crtc_state, INTEL_OUTPUT_DP))
4977b50a1aa6SManasi Navare 		return 0;
4978b50a1aa6SManasi Navare 
4979b50a1aa6SManasi Navare 	for_each_new_connector_in_state(&state->base, connector, conn_state, i) {
4980b50a1aa6SManasi Navare 		struct intel_crtc *crtc = to_intel_crtc(conn_state->crtc);
4981b50a1aa6SManasi Navare 		const struct intel_crtc_state *crtc_state;
4982b50a1aa6SManasi Navare 
4983b50a1aa6SManasi Navare 		if (!crtc)
4984b50a1aa6SManasi Navare 			continue;
4985b50a1aa6SManasi Navare 
4986b50a1aa6SManasi Navare 		if (!connector->has_tile ||
4987b50a1aa6SManasi Navare 		    connector->tile_group->id !=
4988b50a1aa6SManasi Navare 		    tile_group_id)
4989b50a1aa6SManasi Navare 			continue;
4990b50a1aa6SManasi Navare 		crtc_state = intel_atomic_get_new_crtc_state(state,
4991b50a1aa6SManasi Navare 							     crtc);
4992b50a1aa6SManasi Navare 		if (!crtcs_port_sync_compatible(ref_crtc_state,
4993b50a1aa6SManasi Navare 						crtc_state))
4994b50a1aa6SManasi Navare 			continue;
4995b50a1aa6SManasi Navare 		transcoders |= BIT(crtc_state->cpu_transcoder);
4996b50a1aa6SManasi Navare 	}
4997b50a1aa6SManasi Navare 
4998b50a1aa6SManasi Navare 	return transcoders;
4999b50a1aa6SManasi Navare }
5000b50a1aa6SManasi Navare 
5001b50a1aa6SManasi Navare static int intel_ddi_compute_config_late(struct intel_encoder *encoder,
5002b50a1aa6SManasi Navare 					 struct intel_crtc_state *crtc_state,
5003b50a1aa6SManasi Navare 					 struct drm_connector_state *conn_state)
5004b50a1aa6SManasi Navare {
500547bdb1caSJani Nikula 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
5006b50a1aa6SManasi Navare 	struct drm_connector *connector = conn_state->connector;
5007b50a1aa6SManasi Navare 	u8 port_sync_transcoders = 0;
5008b50a1aa6SManasi Navare 
500947bdb1caSJani Nikula 	drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] [CRTC:%d:%s]",
5010b50a1aa6SManasi Navare 		    encoder->base.base.id, encoder->base.name,
5011b50a1aa6SManasi Navare 		    crtc_state->uapi.crtc->base.id, crtc_state->uapi.crtc->name);
5012b50a1aa6SManasi Navare 
5013b50a1aa6SManasi Navare 	if (connector->has_tile)
5014b50a1aa6SManasi Navare 		port_sync_transcoders = intel_ddi_port_sync_transcoders(crtc_state,
5015b50a1aa6SManasi Navare 									connector->tile_group->id);
5016b50a1aa6SManasi Navare 
5017b50a1aa6SManasi Navare 	/*
5018b50a1aa6SManasi Navare 	 * EDP Transcoders cannot be ensalved
5019b50a1aa6SManasi Navare 	 * make them a master always when present
5020b50a1aa6SManasi Navare 	 */
5021b50a1aa6SManasi Navare 	if (port_sync_transcoders & BIT(TRANSCODER_EDP))
5022b50a1aa6SManasi Navare 		crtc_state->master_transcoder = TRANSCODER_EDP;
5023b50a1aa6SManasi Navare 	else
5024b50a1aa6SManasi Navare 		crtc_state->master_transcoder = ffs(port_sync_transcoders) - 1;
5025b50a1aa6SManasi Navare 
5026b50a1aa6SManasi Navare 	if (crtc_state->master_transcoder == crtc_state->cpu_transcoder) {
5027b50a1aa6SManasi Navare 		crtc_state->master_transcoder = INVALID_TRANSCODER;
5028b50a1aa6SManasi Navare 		crtc_state->sync_mode_slaves_mask =
5029b50a1aa6SManasi Navare 			port_sync_transcoders & ~BIT(crtc_state->cpu_transcoder);
5030b50a1aa6SManasi Navare 	}
5031b50a1aa6SManasi Navare 
5032b50a1aa6SManasi Navare 	return 0;
5033b50a1aa6SManasi Navare }
5034b50a1aa6SManasi Navare 
5035379bc100SJani Nikula static void intel_ddi_encoder_destroy(struct drm_encoder *encoder)
5036379bc100SJani Nikula {
5037b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder));
5038379bc100SJani Nikula 
5039379bc100SJani Nikula 	intel_dp_encoder_flush_work(encoder);
5040379bc100SJani Nikula 
5041379bc100SJani Nikula 	drm_encoder_cleanup(encoder);
5042379bc100SJani Nikula 	kfree(dig_port);
5043379bc100SJani Nikula }
5044379bc100SJani Nikula 
5045379bc100SJani Nikula static const struct drm_encoder_funcs intel_ddi_funcs = {
504632691b58SImre Deak 	.reset = intel_dp_encoder_reset,
5047379bc100SJani Nikula 	.destroy = intel_ddi_encoder_destroy,
5048379bc100SJani Nikula };
5049379bc100SJani Nikula 
5050379bc100SJani Nikula static struct intel_connector *
50517801f3b7SLucas De Marchi intel_ddi_init_dp_connector(struct intel_digital_port *dig_port)
5052379bc100SJani Nikula {
50537801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
5054379bc100SJani Nikula 	struct intel_connector *connector;
50557801f3b7SLucas De Marchi 	enum port port = dig_port->base.port;
5056379bc100SJani Nikula 
5057379bc100SJani Nikula 	connector = intel_connector_alloc();
5058379bc100SJani Nikula 	if (!connector)
5059379bc100SJani Nikula 		return NULL;
5060379bc100SJani Nikula 
50617801f3b7SLucas De Marchi 	dig_port->dp.output_reg = DDI_BUF_CTL(port);
50627801f3b7SLucas De Marchi 	dig_port->dp.prepare_link_retrain = intel_ddi_prepare_link_retrain;
50637801f3b7SLucas De Marchi 	dig_port->dp.set_link_train = intel_ddi_set_link_train;
50647801f3b7SLucas De Marchi 	dig_port->dp.set_idle_link_train = intel_ddi_set_idle_link_train;
5065eee3f911SVille Syrjälä 
5066fb83f72cSVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 12)
50677801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = tgl_set_signal_levels;
5068fb83f72cSVille Syrjälä 	else if (INTEL_GEN(dev_priv) >= 11)
50697801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = icl_set_signal_levels;
5070fb83f72cSVille Syrjälä 	else if (IS_CANNONLAKE(dev_priv))
50717801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = cnl_set_signal_levels;
5072fb83f72cSVille Syrjälä 	else if (IS_GEN9_LP(dev_priv))
50737801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = bxt_set_signal_levels;
5074fb83f72cSVille Syrjälä 	else
50757801f3b7SLucas De Marchi 		dig_port->dp.set_signal_levels = hsw_set_signal_levels;
5076fb83f72cSVille Syrjälä 
50777801f3b7SLucas De Marchi 	dig_port->dp.voltage_max = intel_ddi_dp_voltage_max;
50787801f3b7SLucas De Marchi 	dig_port->dp.preemph_max = intel_ddi_dp_preemph_max;
507953de0a20SVille Syrjälä 
50807801f3b7SLucas De Marchi 	if (!intel_dp_init_connector(dig_port, connector)) {
5081379bc100SJani Nikula 		kfree(connector);
5082379bc100SJani Nikula 		return NULL;
5083379bc100SJani Nikula 	}
5084379bc100SJani Nikula 
5085379bc100SJani Nikula 	return connector;
5086379bc100SJani Nikula }
5087379bc100SJani Nikula 
5088379bc100SJani Nikula static int modeset_pipe(struct drm_crtc *crtc,
5089379bc100SJani Nikula 			struct drm_modeset_acquire_ctx *ctx)
5090379bc100SJani Nikula {
5091379bc100SJani Nikula 	struct drm_atomic_state *state;
5092379bc100SJani Nikula 	struct drm_crtc_state *crtc_state;
5093379bc100SJani Nikula 	int ret;
5094379bc100SJani Nikula 
5095379bc100SJani Nikula 	state = drm_atomic_state_alloc(crtc->dev);
5096379bc100SJani Nikula 	if (!state)
5097379bc100SJani Nikula 		return -ENOMEM;
5098379bc100SJani Nikula 
5099379bc100SJani Nikula 	state->acquire_ctx = ctx;
5100379bc100SJani Nikula 
5101379bc100SJani Nikula 	crtc_state = drm_atomic_get_crtc_state(state, crtc);
5102379bc100SJani Nikula 	if (IS_ERR(crtc_state)) {
5103379bc100SJani Nikula 		ret = PTR_ERR(crtc_state);
5104379bc100SJani Nikula 		goto out;
5105379bc100SJani Nikula 	}
5106379bc100SJani Nikula 
5107379bc100SJani Nikula 	crtc_state->connectors_changed = true;
5108379bc100SJani Nikula 
5109379bc100SJani Nikula 	ret = drm_atomic_commit(state);
5110379bc100SJani Nikula out:
5111379bc100SJani Nikula 	drm_atomic_state_put(state);
5112379bc100SJani Nikula 
5113379bc100SJani Nikula 	return ret;
5114379bc100SJani Nikula }
5115379bc100SJani Nikula 
5116379bc100SJani Nikula static int intel_hdmi_reset_link(struct intel_encoder *encoder,
5117379bc100SJani Nikula 				 struct drm_modeset_acquire_ctx *ctx)
5118379bc100SJani Nikula {
5119379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5120b7d02c3aSVille Syrjälä 	struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder);
5121379bc100SJani Nikula 	struct intel_connector *connector = hdmi->attached_connector;
5122379bc100SJani Nikula 	struct i2c_adapter *adapter =
5123379bc100SJani Nikula 		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
5124379bc100SJani Nikula 	struct drm_connector_state *conn_state;
5125379bc100SJani Nikula 	struct intel_crtc_state *crtc_state;
5126379bc100SJani Nikula 	struct intel_crtc *crtc;
5127379bc100SJani Nikula 	u8 config;
5128379bc100SJani Nikula 	int ret;
5129379bc100SJani Nikula 
5130379bc100SJani Nikula 	if (!connector || connector->base.status != connector_status_connected)
5131379bc100SJani Nikula 		return 0;
5132379bc100SJani Nikula 
5133379bc100SJani Nikula 	ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex,
5134379bc100SJani Nikula 			       ctx);
5135379bc100SJani Nikula 	if (ret)
5136379bc100SJani Nikula 		return ret;
5137379bc100SJani Nikula 
5138379bc100SJani Nikula 	conn_state = connector->base.state;
5139379bc100SJani Nikula 
5140379bc100SJani Nikula 	crtc = to_intel_crtc(conn_state->crtc);
5141379bc100SJani Nikula 	if (!crtc)
5142379bc100SJani Nikula 		return 0;
5143379bc100SJani Nikula 
5144379bc100SJani Nikula 	ret = drm_modeset_lock(&crtc->base.mutex, ctx);
5145379bc100SJani Nikula 	if (ret)
5146379bc100SJani Nikula 		return ret;
5147379bc100SJani Nikula 
5148379bc100SJani Nikula 	crtc_state = to_intel_crtc_state(crtc->base.state);
5149379bc100SJani Nikula 
51501de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm,
51511de143ccSPankaj Bharadiya 		    !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI));
5152379bc100SJani Nikula 
51531326a92cSMaarten Lankhorst 	if (!crtc_state->hw.active)
5154379bc100SJani Nikula 		return 0;
5155379bc100SJani Nikula 
5156379bc100SJani Nikula 	if (!crtc_state->hdmi_high_tmds_clock_ratio &&
5157379bc100SJani Nikula 	    !crtc_state->hdmi_scrambling)
5158379bc100SJani Nikula 		return 0;
5159379bc100SJani Nikula 
5160379bc100SJani Nikula 	if (conn_state->commit &&
5161379bc100SJani Nikula 	    !try_wait_for_completion(&conn_state->commit->hw_done))
5162379bc100SJani Nikula 		return 0;
5163379bc100SJani Nikula 
5164379bc100SJani Nikula 	ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config);
5165379bc100SJani Nikula 	if (ret < 0) {
516647bdb1caSJani Nikula 		drm_err(&dev_priv->drm, "Failed to read TMDS config: %d\n",
516747bdb1caSJani Nikula 			ret);
5168379bc100SJani Nikula 		return 0;
5169379bc100SJani Nikula 	}
5170379bc100SJani Nikula 
5171379bc100SJani Nikula 	if (!!(config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) ==
5172379bc100SJani Nikula 	    crtc_state->hdmi_high_tmds_clock_ratio &&
5173379bc100SJani Nikula 	    !!(config & SCDC_SCRAMBLING_ENABLE) ==
5174379bc100SJani Nikula 	    crtc_state->hdmi_scrambling)
5175379bc100SJani Nikula 		return 0;
5176379bc100SJani Nikula 
5177379bc100SJani Nikula 	/*
5178379bc100SJani Nikula 	 * HDMI 2.0 says that one should not send scrambled data
5179379bc100SJani Nikula 	 * prior to configuring the sink scrambling, and that
5180379bc100SJani Nikula 	 * TMDS clock/data transmission should be suspended when
5181379bc100SJani Nikula 	 * changing the TMDS clock rate in the sink. So let's
5182379bc100SJani Nikula 	 * just do a full modeset here, even though some sinks
5183379bc100SJani Nikula 	 * would be perfectly happy if were to just reconfigure
5184379bc100SJani Nikula 	 * the SCDC settings on the fly.
5185379bc100SJani Nikula 	 */
5186379bc100SJani Nikula 	return modeset_pipe(&crtc->base, ctx);
5187379bc100SJani Nikula }
5188379bc100SJani Nikula 
51893944709dSImre Deak static enum intel_hotplug_state
51903944709dSImre Deak intel_ddi_hotplug(struct intel_encoder *encoder,
51918c8919c7SImre Deak 		  struct intel_connector *connector)
5192379bc100SJani Nikula {
5193b4df5405SImre Deak 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
5194b7d02c3aSVille Syrjälä 	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
5195b4df5405SImre Deak 	enum phy phy = intel_port_to_phy(i915, encoder->port);
5196b4df5405SImre Deak 	bool is_tc = intel_phy_is_tc(i915, phy);
5197379bc100SJani Nikula 	struct drm_modeset_acquire_ctx ctx;
51983944709dSImre Deak 	enum intel_hotplug_state state;
5199379bc100SJani Nikula 	int ret;
5200379bc100SJani Nikula 
52018c8919c7SImre Deak 	state = intel_encoder_hotplug(encoder, connector);
5202379bc100SJani Nikula 
5203379bc100SJani Nikula 	drm_modeset_acquire_init(&ctx, 0);
5204379bc100SJani Nikula 
5205379bc100SJani Nikula 	for (;;) {
5206379bc100SJani Nikula 		if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA)
5207379bc100SJani Nikula 			ret = intel_hdmi_reset_link(encoder, &ctx);
5208379bc100SJani Nikula 		else
5209379bc100SJani Nikula 			ret = intel_dp_retrain_link(encoder, &ctx);
5210379bc100SJani Nikula 
5211379bc100SJani Nikula 		if (ret == -EDEADLK) {
5212379bc100SJani Nikula 			drm_modeset_backoff(&ctx);
5213379bc100SJani Nikula 			continue;
5214379bc100SJani Nikula 		}
5215379bc100SJani Nikula 
5216379bc100SJani Nikula 		break;
5217379bc100SJani Nikula 	}
5218379bc100SJani Nikula 
5219379bc100SJani Nikula 	drm_modeset_drop_locks(&ctx);
5220379bc100SJani Nikula 	drm_modeset_acquire_fini(&ctx);
52213a47ae20SPankaj Bharadiya 	drm_WARN(encoder->base.dev, ret,
52223a47ae20SPankaj Bharadiya 		 "Acquiring modeset locks failed with %i\n", ret);
5223379bc100SJani Nikula 
5224bb80c925SJosé Roberto de Souza 	/*
5225bb80c925SJosé Roberto de Souza 	 * Unpowered type-c dongles can take some time to boot and be
5226bb80c925SJosé Roberto de Souza 	 * responsible, so here giving some time to those dongles to power up
5227bb80c925SJosé Roberto de Souza 	 * and then retrying the probe.
5228bb80c925SJosé Roberto de Souza 	 *
5229bb80c925SJosé Roberto de Souza 	 * On many platforms the HDMI live state signal is known to be
5230bb80c925SJosé Roberto de Souza 	 * unreliable, so we can't use it to detect if a sink is connected or
5231bb80c925SJosé Roberto de Souza 	 * not. Instead we detect if it's connected based on whether we can
5232bb80c925SJosé Roberto de Souza 	 * read the EDID or not. That in turn has a problem during disconnect,
5233bb80c925SJosé Roberto de Souza 	 * since the HPD interrupt may be raised before the DDC lines get
5234bb80c925SJosé Roberto de Souza 	 * disconnected (due to how the required length of DDC vs. HPD
5235bb80c925SJosé Roberto de Souza 	 * connector pins are specified) and so we'll still be able to get a
5236bb80c925SJosé Roberto de Souza 	 * valid EDID. To solve this schedule another detection cycle if this
5237bb80c925SJosé Roberto de Souza 	 * time around we didn't detect any change in the sink's connection
5238bb80c925SJosé Roberto de Souza 	 * status.
5239b4df5405SImre Deak 	 *
5240b4df5405SImre Deak 	 * Type-c connectors which get their HPD signal deasserted then
5241b4df5405SImre Deak 	 * reasserted, without unplugging/replugging the sink from the
5242b4df5405SImre Deak 	 * connector, introduce a delay until the AUX channel communication
5243b4df5405SImre Deak 	 * becomes functional. Retry the detection for 5 seconds on type-c
5244b4df5405SImre Deak 	 * connectors to account for this delay.
5245bb80c925SJosé Roberto de Souza 	 */
5246b4df5405SImre Deak 	if (state == INTEL_HOTPLUG_UNCHANGED &&
5247b4df5405SImre Deak 	    connector->hotplug_retries < (is_tc ? 5 : 1) &&
5248bb80c925SJosé Roberto de Souza 	    !dig_port->dp.is_mst)
5249bb80c925SJosé Roberto de Souza 		state = INTEL_HOTPLUG_RETRY;
5250bb80c925SJosé Roberto de Souza 
52513944709dSImre Deak 	return state;
5252379bc100SJani Nikula }
5253379bc100SJani Nikula 
5254edc0e09cSVille Syrjälä static bool lpt_digital_port_connected(struct intel_encoder *encoder)
5255edc0e09cSVille Syrjälä {
5256edc0e09cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5257c7e8a3d6SVille Syrjälä 	u32 bit = dev_priv->hotplug.pch_hpd[encoder->hpd_pin];
5258edc0e09cSVille Syrjälä 
5259edc0e09cSVille Syrjälä 	return intel_de_read(dev_priv, SDEISR) & bit;
5260edc0e09cSVille Syrjälä }
5261edc0e09cSVille Syrjälä 
5262edc0e09cSVille Syrjälä static bool hsw_digital_port_connected(struct intel_encoder *encoder)
5263edc0e09cSVille Syrjälä {
5264edc0e09cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5265c7e8a3d6SVille Syrjälä 	u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin];
5266edc0e09cSVille Syrjälä 
5267c7e8a3d6SVille Syrjälä 	return intel_de_read(dev_priv, DEISR) & bit;
5268edc0e09cSVille Syrjälä }
5269edc0e09cSVille Syrjälä 
5270edc0e09cSVille Syrjälä static bool bdw_digital_port_connected(struct intel_encoder *encoder)
5271edc0e09cSVille Syrjälä {
5272edc0e09cSVille Syrjälä 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5273c7e8a3d6SVille Syrjälä 	u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin];
5274edc0e09cSVille Syrjälä 
5275edc0e09cSVille Syrjälä 	return intel_de_read(dev_priv, GEN8_DE_PORT_ISR) & bit;
5276edc0e09cSVille Syrjälä }
5277edc0e09cSVille Syrjälä 
5278379bc100SJani Nikula static struct intel_connector *
52797801f3b7SLucas De Marchi intel_ddi_init_hdmi_connector(struct intel_digital_port *dig_port)
5280379bc100SJani Nikula {
5281379bc100SJani Nikula 	struct intel_connector *connector;
52827801f3b7SLucas De Marchi 	enum port port = dig_port->base.port;
5283379bc100SJani Nikula 
5284379bc100SJani Nikula 	connector = intel_connector_alloc();
5285379bc100SJani Nikula 	if (!connector)
5286379bc100SJani Nikula 		return NULL;
5287379bc100SJani Nikula 
52887801f3b7SLucas De Marchi 	dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
52897801f3b7SLucas De Marchi 	intel_hdmi_init_connector(dig_port, connector);
5290379bc100SJani Nikula 
5291379bc100SJani Nikula 	return connector;
5292379bc100SJani Nikula }
5293379bc100SJani Nikula 
52947801f3b7SLucas De Marchi static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dig_port)
5295379bc100SJani Nikula {
52967801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
5297379bc100SJani Nikula 
52987801f3b7SLucas De Marchi 	if (dig_port->base.port != PORT_A)
5299379bc100SJani Nikula 		return false;
5300379bc100SJani Nikula 
53017801f3b7SLucas De Marchi 	if (dig_port->saved_port_bits & DDI_A_4_LANES)
5302379bc100SJani Nikula 		return false;
5303379bc100SJani Nikula 
5304379bc100SJani Nikula 	/* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only
5305379bc100SJani Nikula 	 *                     supported configuration
5306379bc100SJani Nikula 	 */
5307379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv))
5308379bc100SJani Nikula 		return true;
5309379bc100SJani Nikula 
5310379bc100SJani Nikula 	/* Cannonlake: Most of SKUs don't support DDI_E, and the only
5311379bc100SJani Nikula 	 *             one who does also have a full A/E split called
5312379bc100SJani Nikula 	 *             DDI_F what makes DDI_E useless. However for this
5313379bc100SJani Nikula 	 *             case let's trust VBT info.
5314379bc100SJani Nikula 	 */
5315379bc100SJani Nikula 	if (IS_CANNONLAKE(dev_priv) &&
5316379bc100SJani Nikula 	    !intel_bios_is_port_present(dev_priv, PORT_E))
5317379bc100SJani Nikula 		return true;
5318379bc100SJani Nikula 
5319379bc100SJani Nikula 	return false;
5320379bc100SJani Nikula }
5321379bc100SJani Nikula 
5322379bc100SJani Nikula static int
53237801f3b7SLucas De Marchi intel_ddi_max_lanes(struct intel_digital_port *dig_port)
5324379bc100SJani Nikula {
53257801f3b7SLucas De Marchi 	struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
53267801f3b7SLucas De Marchi 	enum port port = dig_port->base.port;
5327379bc100SJani Nikula 	int max_lanes = 4;
5328379bc100SJani Nikula 
5329379bc100SJani Nikula 	if (INTEL_GEN(dev_priv) >= 11)
5330379bc100SJani Nikula 		return max_lanes;
5331379bc100SJani Nikula 
5332379bc100SJani Nikula 	if (port == PORT_A || port == PORT_E) {
5333f7960e7fSJani Nikula 		if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
5334379bc100SJani Nikula 			max_lanes = port == PORT_A ? 4 : 0;
5335379bc100SJani Nikula 		else
5336379bc100SJani Nikula 			/* Both A and E share 2 lanes */
5337379bc100SJani Nikula 			max_lanes = 2;
5338379bc100SJani Nikula 	}
5339379bc100SJani Nikula 
5340379bc100SJani Nikula 	/*
5341379bc100SJani Nikula 	 * Some BIOS might fail to set this bit on port A if eDP
5342379bc100SJani Nikula 	 * wasn't lit up at boot.  Force this bit set when needed
5343379bc100SJani Nikula 	 * so we use the proper lane count for our calculations.
5344379bc100SJani Nikula 	 */
53457801f3b7SLucas De Marchi 	if (intel_ddi_a_force_4_lanes(dig_port)) {
534647bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
534747bdb1caSJani Nikula 			    "Forcing DDI_A_4_LANES for port A\n");
53487801f3b7SLucas De Marchi 		dig_port->saved_port_bits |= DDI_A_4_LANES;
5349379bc100SJani Nikula 		max_lanes = 4;
5350379bc100SJani Nikula 	}
5351379bc100SJani Nikula 
5352379bc100SJani Nikula 	return max_lanes;
5353379bc100SJani Nikula }
5354379bc100SJani Nikula 
5355ddff9a60SMatt Roper static bool hti_uses_phy(struct drm_i915_private *i915, enum phy phy)
5356ddff9a60SMatt Roper {
5357ddff9a60SMatt Roper 	return i915->hti_state & HDPORT_ENABLED &&
5358ff7fb44dSJosé Roberto de Souza 	       i915->hti_state & HDPORT_DDI_USED(phy);
5359ddff9a60SMatt Roper }
5360ddff9a60SMatt Roper 
5361229f31e2SLucas De Marchi static enum hpd_pin dg1_hpd_pin(struct drm_i915_private *dev_priv,
5362229f31e2SLucas De Marchi 				enum port port)
5363229f31e2SLucas De Marchi {
53641d8ca002SVille Syrjälä 	if (port >= PORT_TC1)
53651d8ca002SVille Syrjälä 		return HPD_PORT_C + port - PORT_TC1;
5366229f31e2SLucas De Marchi 	else
5367229f31e2SLucas De Marchi 		return HPD_PORT_A + port - PORT_A;
5368229f31e2SLucas De Marchi }
5369229f31e2SLucas De Marchi 
5370da51e4baSVille Syrjälä static enum hpd_pin tgl_hpd_pin(struct drm_i915_private *dev_priv,
5371da51e4baSVille Syrjälä 				enum port port)
5372da51e4baSVille Syrjälä {
53731d8ca002SVille Syrjälä 	if (port >= PORT_TC1)
53741d8ca002SVille Syrjälä 		return HPD_PORT_TC1 + port - PORT_TC1;
5375da51e4baSVille Syrjälä 	else
5376da51e4baSVille Syrjälä 		return HPD_PORT_A + port - PORT_A;
5377da51e4baSVille Syrjälä }
5378da51e4baSVille Syrjälä 
5379da51e4baSVille Syrjälä static enum hpd_pin rkl_hpd_pin(struct drm_i915_private *dev_priv,
5380da51e4baSVille Syrjälä 				enum port port)
5381da51e4baSVille Syrjälä {
5382da51e4baSVille Syrjälä 	if (HAS_PCH_TGP(dev_priv))
5383da51e4baSVille Syrjälä 		return tgl_hpd_pin(dev_priv, port);
5384da51e4baSVille Syrjälä 
53851d8ca002SVille Syrjälä 	if (port >= PORT_TC1)
53861d8ca002SVille Syrjälä 		return HPD_PORT_C + port - PORT_TC1;
5387da51e4baSVille Syrjälä 	else
5388da51e4baSVille Syrjälä 		return HPD_PORT_A + port - PORT_A;
5389da51e4baSVille Syrjälä }
5390da51e4baSVille Syrjälä 
5391da51e4baSVille Syrjälä static enum hpd_pin icl_hpd_pin(struct drm_i915_private *dev_priv,
5392da51e4baSVille Syrjälä 				enum port port)
5393da51e4baSVille Syrjälä {
5394da51e4baSVille Syrjälä 	if (port >= PORT_C)
5395da51e4baSVille Syrjälä 		return HPD_PORT_TC1 + port - PORT_C;
5396da51e4baSVille Syrjälä 	else
5397da51e4baSVille Syrjälä 		return HPD_PORT_A + port - PORT_A;
5398da51e4baSVille Syrjälä }
5399da51e4baSVille Syrjälä 
5400da51e4baSVille Syrjälä static enum hpd_pin ehl_hpd_pin(struct drm_i915_private *dev_priv,
5401da51e4baSVille Syrjälä 				enum port port)
5402da51e4baSVille Syrjälä {
5403da51e4baSVille Syrjälä 	if (port == PORT_D)
5404da51e4baSVille Syrjälä 		return HPD_PORT_A;
5405da51e4baSVille Syrjälä 
5406da51e4baSVille Syrjälä 	if (HAS_PCH_MCC(dev_priv))
5407da51e4baSVille Syrjälä 		return icl_hpd_pin(dev_priv, port);
5408da51e4baSVille Syrjälä 
5409da51e4baSVille Syrjälä 	return HPD_PORT_A + port - PORT_A;
5410da51e4baSVille Syrjälä }
5411da51e4baSVille Syrjälä 
5412da51e4baSVille Syrjälä static enum hpd_pin cnl_hpd_pin(struct drm_i915_private *dev_priv,
5413da51e4baSVille Syrjälä 				enum port port)
5414da51e4baSVille Syrjälä {
5415da51e4baSVille Syrjälä 	if (port == PORT_F)
5416da51e4baSVille Syrjälä 		return HPD_PORT_E;
5417da51e4baSVille Syrjälä 
5418da51e4baSVille Syrjälä 	return HPD_PORT_A + port - PORT_A;
5419da51e4baSVille Syrjälä }
5420da51e4baSVille Syrjälä 
542183566d13SVille Syrjälä #define port_tc_name(port) ((port) - PORT_TC1 + '1')
542283566d13SVille Syrjälä #define tc_port_name(tc_port) ((tc_port) - TC_PORT_1 + '1')
542383566d13SVille Syrjälä 
5424379bc100SJani Nikula void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
5425379bc100SJani Nikula {
54267801f3b7SLucas De Marchi 	struct intel_digital_port *dig_port;
542770dfbc29SLucas De Marchi 	struct intel_encoder *encoder;
5428f542d671SKai-Heng Feng 	bool init_hdmi, init_dp;
5429d8fe2ab6SMatt Roper 	enum phy phy = intel_port_to_phy(dev_priv, port);
5430379bc100SJani Nikula 
5431ddff9a60SMatt Roper 	/*
5432ddff9a60SMatt Roper 	 * On platforms with HTI (aka HDPORT), if it's enabled at boot it may
5433ddff9a60SMatt Roper 	 * have taken over some of the PHYs and made them unavailable to the
5434ddff9a60SMatt Roper 	 * driver.  In that case we should skip initializing the corresponding
5435ddff9a60SMatt Roper 	 * outputs.
5436ddff9a60SMatt Roper 	 */
5437ddff9a60SMatt Roper 	if (hti_uses_phy(dev_priv, phy)) {
5438ddff9a60SMatt Roper 		drm_dbg_kms(&dev_priv->drm, "PORT %c / PHY %c reserved by HTI\n",
5439ddff9a60SMatt Roper 			    port_name(port), phy_name(phy));
5440ddff9a60SMatt Roper 		return;
5441ddff9a60SMatt Roper 	}
5442ddff9a60SMatt Roper 
5443c5faae5aSJani Nikula 	init_hdmi = intel_bios_port_supports_dvi(dev_priv, port) ||
5444c5faae5aSJani Nikula 		intel_bios_port_supports_hdmi(dev_priv, port);
5445c5faae5aSJani Nikula 	init_dp = intel_bios_port_supports_dp(dev_priv, port);
5446379bc100SJani Nikula 
5447379bc100SJani Nikula 	if (intel_bios_is_lspcon_present(dev_priv, port)) {
5448379bc100SJani Nikula 		/*
5449379bc100SJani Nikula 		 * Lspcon device needs to be driven with DP connector
5450379bc100SJani Nikula 		 * with special detection sequence. So make sure DP
5451379bc100SJani Nikula 		 * is initialized before lspcon.
5452379bc100SJani Nikula 		 */
5453379bc100SJani Nikula 		init_dp = true;
5454379bc100SJani Nikula 		init_hdmi = false;
545547bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm, "VBT says port %c has lspcon\n",
545647bdb1caSJani Nikula 			    port_name(port));
5457379bc100SJani Nikula 	}
5458379bc100SJani Nikula 
5459379bc100SJani Nikula 	if (!init_dp && !init_hdmi) {
546047bdb1caSJani Nikula 		drm_dbg_kms(&dev_priv->drm,
546147bdb1caSJani Nikula 			    "VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
5462379bc100SJani Nikula 			    port_name(port));
5463379bc100SJani Nikula 		return;
5464379bc100SJani Nikula 	}
5465379bc100SJani Nikula 
54667801f3b7SLucas De Marchi 	dig_port = kzalloc(sizeof(*dig_port), GFP_KERNEL);
54677801f3b7SLucas De Marchi 	if (!dig_port)
5468379bc100SJani Nikula 		return;
5469379bc100SJani Nikula 
54707801f3b7SLucas De Marchi 	encoder = &dig_port->base;
5471379bc100SJani Nikula 
54722d709a5aSVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 12) {
54732d709a5aSVille Syrjälä 		enum tc_port tc_port = intel_port_to_tc(dev_priv, port);
54742d709a5aSVille Syrjälä 
547570dfbc29SLucas De Marchi 		drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
54762d709a5aSVille Syrjälä 				 DRM_MODE_ENCODER_TMDS,
54772d709a5aSVille Syrjälä 				 "DDI %s%c/PHY %s%c",
54782d709a5aSVille Syrjälä 				 port >= PORT_TC1 ? "TC" : "",
547983566d13SVille Syrjälä 				 port >= PORT_TC1 ? port_tc_name(port) : port_name(port),
54802d709a5aSVille Syrjälä 				 tc_port != TC_PORT_NONE ? "TC" : "",
548183566d13SVille Syrjälä 				 tc_port != TC_PORT_NONE ? tc_port_name(tc_port) : phy_name(phy));
54822d709a5aSVille Syrjälä 	} else if (INTEL_GEN(dev_priv) >= 11) {
54832d709a5aSVille Syrjälä 		enum tc_port tc_port = intel_port_to_tc(dev_priv, port);
54842d709a5aSVille Syrjälä 
54852d709a5aSVille Syrjälä 		drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
54862d709a5aSVille Syrjälä 				 DRM_MODE_ENCODER_TMDS,
54872d709a5aSVille Syrjälä 				 "DDI %c%s/PHY %s%c",
54882d709a5aSVille Syrjälä 				 port_name(port),
54892d709a5aSVille Syrjälä 				 port >= PORT_C ? " (TC)" : "",
54902d709a5aSVille Syrjälä 				 tc_port != TC_PORT_NONE ? "TC" : "",
549183566d13SVille Syrjälä 				 tc_port != TC_PORT_NONE ? tc_port_name(tc_port) : phy_name(phy));
54922d709a5aSVille Syrjälä 	} else {
54932d709a5aSVille Syrjälä 		drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs,
54942d709a5aSVille Syrjälä 				 DRM_MODE_ENCODER_TMDS,
54952d709a5aSVille Syrjälä 				 "DDI %c/PHY %c", port_name(port),  phy_name(phy));
54962d709a5aSVille Syrjälä 	}
5497379bc100SJani Nikula 
549836e5e704SSean Paul 	mutex_init(&dig_port->hdcp_mutex);
549936e5e704SSean Paul 	dig_port->num_hdcp_streams = 0;
550036e5e704SSean Paul 
550170dfbc29SLucas De Marchi 	encoder->hotplug = intel_ddi_hotplug;
550270dfbc29SLucas De Marchi 	encoder->compute_output_type = intel_ddi_compute_output_type;
550370dfbc29SLucas De Marchi 	encoder->compute_config = intel_ddi_compute_config;
5504b50a1aa6SManasi Navare 	encoder->compute_config_late = intel_ddi_compute_config_late;
550570dfbc29SLucas De Marchi 	encoder->enable = intel_enable_ddi;
550670dfbc29SLucas De Marchi 	encoder->pre_pll_enable = intel_ddi_pre_pll_enable;
550770dfbc29SLucas De Marchi 	encoder->pre_enable = intel_ddi_pre_enable;
550870dfbc29SLucas De Marchi 	encoder->disable = intel_disable_ddi;
550970dfbc29SLucas De Marchi 	encoder->post_disable = intel_ddi_post_disable;
551070dfbc29SLucas De Marchi 	encoder->update_pipe = intel_ddi_update_pipe;
551170dfbc29SLucas De Marchi 	encoder->get_hw_state = intel_ddi_get_hw_state;
551270dfbc29SLucas De Marchi 	encoder->get_config = intel_ddi_get_config;
5513f9e76a6eSImre Deak 	encoder->sync_state = intel_ddi_sync_state;
5514b671d6efSImre Deak 	encoder->initial_fastset_check = intel_ddi_initial_fastset_check;
551570dfbc29SLucas De Marchi 	encoder->suspend = intel_dp_encoder_suspend;
5516e219ef91SVille Syrjälä 	encoder->shutdown = intel_dp_encoder_shutdown;
551770dfbc29SLucas De Marchi 	encoder->get_power_domains = intel_ddi_get_power_domains;
551870dfbc29SLucas De Marchi 
551970dfbc29SLucas De Marchi 	encoder->type = INTEL_OUTPUT_DDI;
552070dfbc29SLucas De Marchi 	encoder->power_domain = intel_port_to_power_domain(port);
552170dfbc29SLucas De Marchi 	encoder->port = port;
552270dfbc29SLucas De Marchi 	encoder->cloneable = 0;
552370dfbc29SLucas De Marchi 	encoder->pipe_mask = ~0;
5524da51e4baSVille Syrjälä 
5525229f31e2SLucas De Marchi 	if (IS_DG1(dev_priv))
5526229f31e2SLucas De Marchi 		encoder->hpd_pin = dg1_hpd_pin(dev_priv, port);
5527229f31e2SLucas De Marchi 	else if (IS_ROCKETLAKE(dev_priv))
5528da51e4baSVille Syrjälä 		encoder->hpd_pin = rkl_hpd_pin(dev_priv, port);
5529da51e4baSVille Syrjälä 	else if (INTEL_GEN(dev_priv) >= 12)
5530da51e4baSVille Syrjälä 		encoder->hpd_pin = tgl_hpd_pin(dev_priv, port);
553124ea098bSTejas Upadhyay 	else if (IS_JSL_EHL(dev_priv))
5532da51e4baSVille Syrjälä 		encoder->hpd_pin = ehl_hpd_pin(dev_priv, port);
5533da51e4baSVille Syrjälä 	else if (IS_GEN(dev_priv, 11))
5534da51e4baSVille Syrjälä 		encoder->hpd_pin = icl_hpd_pin(dev_priv, port);
5535da51e4baSVille Syrjälä 	else if (IS_GEN(dev_priv, 10))
5536da51e4baSVille Syrjälä 		encoder->hpd_pin = cnl_hpd_pin(dev_priv, port);
5537da51e4baSVille Syrjälä 	else
553803c7e4f1SVille Syrjälä 		encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port);
5539379bc100SJani Nikula 
5540379bc100SJani Nikula 	if (INTEL_GEN(dev_priv) >= 11)
55417801f3b7SLucas De Marchi 		dig_port->saved_port_bits =
55427801f3b7SLucas De Marchi 			intel_de_read(dev_priv, DDI_BUF_CTL(port))
55437801f3b7SLucas De Marchi 			& DDI_BUF_PORT_REVERSAL;
5544379bc100SJani Nikula 	else
55457801f3b7SLucas De Marchi 		dig_port->saved_port_bits =
55467801f3b7SLucas De Marchi 			intel_de_read(dev_priv, DDI_BUF_CTL(port))
55477801f3b7SLucas De Marchi 			& (DDI_BUF_PORT_REVERSAL | DDI_A_4_LANES);
554870dfbc29SLucas De Marchi 
55497801f3b7SLucas De Marchi 	dig_port->dp.output_reg = INVALID_MMIO_REG;
55507801f3b7SLucas De Marchi 	dig_port->max_lanes = intel_ddi_max_lanes(dig_port);
55517801f3b7SLucas De Marchi 	dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port);
5552379bc100SJani Nikula 
5553d8fe2ab6SMatt Roper 	if (intel_phy_is_tc(dev_priv, phy)) {
5554c5faae5aSJani Nikula 		bool is_legacy =
5555c5faae5aSJani Nikula 			!intel_bios_port_supports_typec_usb(dev_priv, port) &&
5556c5faae5aSJani Nikula 			!intel_bios_port_supports_tbt(dev_priv, port);
5557379bc100SJani Nikula 
55587801f3b7SLucas De Marchi 		intel_tc_port_init(dig_port, is_legacy);
555924a7bfe0SImre Deak 
556070dfbc29SLucas De Marchi 		encoder->update_prepare = intel_ddi_update_prepare;
556170dfbc29SLucas De Marchi 		encoder->update_complete = intel_ddi_update_complete;
5562ab7bc4e1SImre Deak 	}
5563ab7bc4e1SImre Deak 
55641de143ccSPankaj Bharadiya 	drm_WARN_ON(&dev_priv->drm, port > PORT_I);
55657801f3b7SLucas De Marchi 	dig_port->ddi_io_power_domain = POWER_DOMAIN_PORT_DDI_A_IO +
5566327f8d8cSLucas De Marchi 					      port - PORT_A;
5567379bc100SJani Nikula 
5568379bc100SJani Nikula 	if (init_dp) {
55697801f3b7SLucas De Marchi 		if (!intel_ddi_init_dp_connector(dig_port))
5570379bc100SJani Nikula 			goto err;
5571379bc100SJani Nikula 
55727801f3b7SLucas De Marchi 		dig_port->hpd_pulse = intel_dp_hpd_pulse;
5573379bc100SJani Nikula 	}
5574379bc100SJani Nikula 
5575379bc100SJani Nikula 	/* In theory we don't need the encoder->type check, but leave it just in
5576379bc100SJani Nikula 	 * case we have some really bad VBTs... */
557770dfbc29SLucas De Marchi 	if (encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
55787801f3b7SLucas De Marchi 		if (!intel_ddi_init_hdmi_connector(dig_port))
5579379bc100SJani Nikula 			goto err;
5580379bc100SJani Nikula 	}
5581379bc100SJani Nikula 
5582edc0e09cSVille Syrjälä 	if (INTEL_GEN(dev_priv) >= 11) {
5583edc0e09cSVille Syrjälä 		if (intel_phy_is_tc(dev_priv, phy))
55847801f3b7SLucas De Marchi 			dig_port->connected = intel_tc_port_connected;
5585edc0e09cSVille Syrjälä 		else
55867801f3b7SLucas De Marchi 			dig_port->connected = lpt_digital_port_connected;
5587c7e8a3d6SVille Syrjälä 	} else if (INTEL_GEN(dev_priv) >= 8) {
5588c7e8a3d6SVille Syrjälä 		if (port == PORT_A || IS_GEN9_LP(dev_priv))
55897801f3b7SLucas De Marchi 			dig_port->connected = bdw_digital_port_connected;
5590edc0e09cSVille Syrjälä 		else
55917801f3b7SLucas De Marchi 			dig_port->connected = lpt_digital_port_connected;
5592edc0e09cSVille Syrjälä 	} else {
5593c7e8a3d6SVille Syrjälä 		if (port == PORT_A)
55947801f3b7SLucas De Marchi 			dig_port->connected = hsw_digital_port_connected;
5595edc0e09cSVille Syrjälä 		else
55967801f3b7SLucas De Marchi 			dig_port->connected = lpt_digital_port_connected;
5597edc0e09cSVille Syrjälä 	}
5598edc0e09cSVille Syrjälä 
55997801f3b7SLucas De Marchi 	intel_infoframe_init(dig_port);
5600379bc100SJani Nikula 
5601379bc100SJani Nikula 	return;
5602379bc100SJani Nikula 
5603379bc100SJani Nikula err:
560470dfbc29SLucas De Marchi 	drm_encoder_cleanup(&encoder->base);
56057801f3b7SLucas De Marchi 	kfree(dig_port);
5606379bc100SJani Nikula }
5607