2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
28 #include <drm/drm_scdc_helper.h>
31 #include "intel_audio.h"
32 #include "intel_combo_phy.h"
33 #include "intel_connector.h"
34 #include "intel_ddi.h"
35 #include "intel_display_types.h"
37 #include "intel_dp_mst.h"
38 #include "intel_dp_link_training.h"
39 #include "intel_dpio_phy.h"
40 #include "intel_dsi.h"
41 #include "intel_fifo_underrun.h"
42 #include "intel_gmbus.h"
43 #include "intel_hdcp.h"
44 #include "intel_hdmi.h"
45 #include "intel_hotplug.h"
46 #include "intel_lspcon.h"
47 #include "intel_panel.h"
48 #include "intel_psr.h"
49 #include "intel_sprite.h"
51 #include "intel_vdsc.h"
53 struct ddi_buf_trans
{
54 u32 trans1
; /* balance leg enable, de-emph level */
55 u32 trans2
; /* vref sel, vswing */
56 u8 i_boost
; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */
59 static const u8 index_to_dp_signal_levels
[] = {
60 [0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0
| DP_TRAIN_PRE_EMPH_LEVEL_0
,
61 [1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0
| DP_TRAIN_PRE_EMPH_LEVEL_1
,
62 [2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0
| DP_TRAIN_PRE_EMPH_LEVEL_2
,
63 [3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0
| DP_TRAIN_PRE_EMPH_LEVEL_3
,
64 [4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1
| DP_TRAIN_PRE_EMPH_LEVEL_0
,
65 [5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1
| DP_TRAIN_PRE_EMPH_LEVEL_1
,
66 [6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1
| DP_TRAIN_PRE_EMPH_LEVEL_2
,
67 [7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2
| DP_TRAIN_PRE_EMPH_LEVEL_0
,
68 [8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2
| DP_TRAIN_PRE_EMPH_LEVEL_1
,
69 [9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3
| DP_TRAIN_PRE_EMPH_LEVEL_0
,
72 /* HDMI/DVI modes ignore everything but the last 2 items. So we share
73 * them for both DP and FDI transports, allowing those ports to
74 * automatically adapt to HDMI connections as well
76 static const struct ddi_buf_trans hsw_ddi_translations_dp
[] = {
77 { 0x00FFFFFF, 0x0006000E, 0x0 },
78 { 0x00D75FFF, 0x0005000A, 0x0 },
79 { 0x00C30FFF, 0x00040006, 0x0 },
80 { 0x80AAAFFF, 0x000B0000, 0x0 },
81 { 0x00FFFFFF, 0x0005000A, 0x0 },
82 { 0x00D75FFF, 0x000C0004, 0x0 },
83 { 0x80C30FFF, 0x000B0000, 0x0 },
84 { 0x00FFFFFF, 0x00040006, 0x0 },
85 { 0x80D75FFF, 0x000B0000, 0x0 },
88 static const struct ddi_buf_trans hsw_ddi_translations_fdi
[] = {
89 { 0x00FFFFFF, 0x0007000E, 0x0 },
90 { 0x00D75FFF, 0x000F000A, 0x0 },
91 { 0x00C30FFF, 0x00060006, 0x0 },
92 { 0x00AAAFFF, 0x001E0000, 0x0 },
93 { 0x00FFFFFF, 0x000F000A, 0x0 },
94 { 0x00D75FFF, 0x00160004, 0x0 },
95 { 0x00C30FFF, 0x001E0000, 0x0 },
96 { 0x00FFFFFF, 0x00060006, 0x0 },
97 { 0x00D75FFF, 0x001E0000, 0x0 },
100 static const struct ddi_buf_trans hsw_ddi_translations_hdmi
[] = {
101 /* Idx NT mV d T mV d db */
102 { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */
103 { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */
104 { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */
105 { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */
106 { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */
107 { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */
108 { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */
109 { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */
110 { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */
111 { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */
112 { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */
113 { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */
116 static const struct ddi_buf_trans bdw_ddi_translations_edp
[] = {
117 { 0x00FFFFFF, 0x00000012, 0x0 },
118 { 0x00EBAFFF, 0x00020011, 0x0 },
119 { 0x00C71FFF, 0x0006000F, 0x0 },
120 { 0x00AAAFFF, 0x000E000A, 0x0 },
121 { 0x00FFFFFF, 0x00020011, 0x0 },
122 { 0x00DB6FFF, 0x0005000F, 0x0 },
123 { 0x00BEEFFF, 0x000A000C, 0x0 },
124 { 0x00FFFFFF, 0x0005000F, 0x0 },
125 { 0x00DB6FFF, 0x000A000C, 0x0 },
128 static const struct ddi_buf_trans bdw_ddi_translations_dp
[] = {
129 { 0x00FFFFFF, 0x0007000E, 0x0 },
130 { 0x00D75FFF, 0x000E000A, 0x0 },
131 { 0x00BEFFFF, 0x00140006, 0x0 },
132 { 0x80B2CFFF, 0x001B0002, 0x0 },
133 { 0x00FFFFFF, 0x000E000A, 0x0 },
134 { 0x00DB6FFF, 0x00160005, 0x0 },
135 { 0x80C71FFF, 0x001A0002, 0x0 },
136 { 0x00F7DFFF, 0x00180004, 0x0 },
137 { 0x80D75FFF, 0x001B0002, 0x0 },
140 static const struct ddi_buf_trans bdw_ddi_translations_fdi
[] = {
141 { 0x00FFFFFF, 0x0001000E, 0x0 },
142 { 0x00D75FFF, 0x0004000A, 0x0 },
143 { 0x00C30FFF, 0x00070006, 0x0 },
144 { 0x00AAAFFF, 0x000C0000, 0x0 },
145 { 0x00FFFFFF, 0x0004000A, 0x0 },
146 { 0x00D75FFF, 0x00090004, 0x0 },
147 { 0x00C30FFF, 0x000C0000, 0x0 },
148 { 0x00FFFFFF, 0x00070006, 0x0 },
149 { 0x00D75FFF, 0x000C0000, 0x0 },
152 static const struct ddi_buf_trans bdw_ddi_translations_hdmi
[] = {
153 /* Idx NT mV d T mV df db */
154 { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */
155 { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */
156 { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */
157 { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */
158 { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */
159 { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */
160 { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */
161 { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */
162 { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */
163 { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */
166 /* Skylake H and S */
167 static const struct ddi_buf_trans skl_ddi_translations_dp
[] = {
168 { 0x00002016, 0x000000A0, 0x0 },
169 { 0x00005012, 0x0000009B, 0x0 },
170 { 0x00007011, 0x00000088, 0x0 },
171 { 0x80009010, 0x000000C0, 0x1 },
172 { 0x00002016, 0x0000009B, 0x0 },
173 { 0x00005012, 0x00000088, 0x0 },
174 { 0x80007011, 0x000000C0, 0x1 },
175 { 0x00002016, 0x000000DF, 0x0 },
176 { 0x80005012, 0x000000C0, 0x1 },
180 static const struct ddi_buf_trans skl_u_ddi_translations_dp
[] = {
181 { 0x0000201B, 0x000000A2, 0x0 },
182 { 0x00005012, 0x00000088, 0x0 },
183 { 0x80007011, 0x000000CD, 0x1 },
184 { 0x80009010, 0x000000C0, 0x1 },
185 { 0x0000201B, 0x0000009D, 0x0 },
186 { 0x80005012, 0x000000C0, 0x1 },
187 { 0x80007011, 0x000000C0, 0x1 },
188 { 0x00002016, 0x00000088, 0x0 },
189 { 0x80005012, 0x000000C0, 0x1 },
193 static const struct ddi_buf_trans skl_y_ddi_translations_dp
[] = {
194 { 0x00000018, 0x000000A2, 0x0 },
195 { 0x00005012, 0x00000088, 0x0 },
196 { 0x80007011, 0x000000CD, 0x3 },
197 { 0x80009010, 0x000000C0, 0x3 },
198 { 0x00000018, 0x0000009D, 0x0 },
199 { 0x80005012, 0x000000C0, 0x3 },
200 { 0x80007011, 0x000000C0, 0x3 },
201 { 0x00000018, 0x00000088, 0x0 },
202 { 0x80005012, 0x000000C0, 0x3 },
205 /* Kabylake H and S */
206 static const struct ddi_buf_trans kbl_ddi_translations_dp
[] = {
207 { 0x00002016, 0x000000A0, 0x0 },
208 { 0x00005012, 0x0000009B, 0x0 },
209 { 0x00007011, 0x00000088, 0x0 },
210 { 0x80009010, 0x000000C0, 0x1 },
211 { 0x00002016, 0x0000009B, 0x0 },
212 { 0x00005012, 0x00000088, 0x0 },
213 { 0x80007011, 0x000000C0, 0x1 },
214 { 0x00002016, 0x00000097, 0x0 },
215 { 0x80005012, 0x000000C0, 0x1 },
219 static const struct ddi_buf_trans kbl_u_ddi_translations_dp
[] = {
220 { 0x0000201B, 0x000000A1, 0x0 },
221 { 0x00005012, 0x00000088, 0x0 },
222 { 0x80007011, 0x000000CD, 0x3 },
223 { 0x80009010, 0x000000C0, 0x3 },
224 { 0x0000201B, 0x0000009D, 0x0 },
225 { 0x80005012, 0x000000C0, 0x3 },
226 { 0x80007011, 0x000000C0, 0x3 },
227 { 0x00002016, 0x0000004F, 0x0 },
228 { 0x80005012, 0x000000C0, 0x3 },
232 static const struct ddi_buf_trans kbl_y_ddi_translations_dp
[] = {
233 { 0x00001017, 0x000000A1, 0x0 },
234 { 0x00005012, 0x00000088, 0x0 },
235 { 0x80007011, 0x000000CD, 0x3 },
236 { 0x8000800F, 0x000000C0, 0x3 },
237 { 0x00001017, 0x0000009D, 0x0 },
238 { 0x80005012, 0x000000C0, 0x3 },
239 { 0x80007011, 0x000000C0, 0x3 },
240 { 0x00001017, 0x0000004C, 0x0 },
241 { 0x80005012, 0x000000C0, 0x3 },
245 * Skylake/Kabylake H and S
246 * eDP 1.4 low vswing translation parameters
248 static const struct ddi_buf_trans skl_ddi_translations_edp
[] = {
249 { 0x00000018, 0x000000A8, 0x0 },
250 { 0x00004013, 0x000000A9, 0x0 },
251 { 0x00007011, 0x000000A2, 0x0 },
252 { 0x00009010, 0x0000009C, 0x0 },
253 { 0x00000018, 0x000000A9, 0x0 },
254 { 0x00006013, 0x000000A2, 0x0 },
255 { 0x00007011, 0x000000A6, 0x0 },
256 { 0x00000018, 0x000000AB, 0x0 },
257 { 0x00007013, 0x0000009F, 0x0 },
258 { 0x00000018, 0x000000DF, 0x0 },
263 * eDP 1.4 low vswing translation parameters
265 static const struct ddi_buf_trans skl_u_ddi_translations_edp
[] = {
266 { 0x00000018, 0x000000A8, 0x0 },
267 { 0x00004013, 0x000000A9, 0x0 },
268 { 0x00007011, 0x000000A2, 0x0 },
269 { 0x00009010, 0x0000009C, 0x0 },
270 { 0x00000018, 0x000000A9, 0x0 },
271 { 0x00006013, 0x000000A2, 0x0 },
272 { 0x00007011, 0x000000A6, 0x0 },
273 { 0x00002016, 0x000000AB, 0x0 },
274 { 0x00005013, 0x0000009F, 0x0 },
275 { 0x00000018, 0x000000DF, 0x0 },
280 * eDP 1.4 low vswing translation parameters
282 static const struct ddi_buf_trans skl_y_ddi_translations_edp
[] = {
283 { 0x00000018, 0x000000A8, 0x0 },
284 { 0x00004013, 0x000000AB, 0x0 },
285 { 0x00007011, 0x000000A4, 0x0 },
286 { 0x00009010, 0x000000DF, 0x0 },
287 { 0x00000018, 0x000000AA, 0x0 },
288 { 0x00006013, 0x000000A4, 0x0 },
289 { 0x00007011, 0x0000009D, 0x0 },
290 { 0x00000018, 0x000000A0, 0x0 },
291 { 0x00006012, 0x000000DF, 0x0 },
292 { 0x00000018, 0x0000008A, 0x0 },
295 /* Skylake/Kabylake U, H and S */
296 static const struct ddi_buf_trans skl_ddi_translations_hdmi
[] = {
297 { 0x00000018, 0x000000AC, 0x0 },
298 { 0x00005012, 0x0000009D, 0x0 },
299 { 0x00007011, 0x00000088, 0x0 },
300 { 0x00000018, 0x000000A1, 0x0 },
301 { 0x00000018, 0x00000098, 0x0 },
302 { 0x00004013, 0x00000088, 0x0 },
303 { 0x80006012, 0x000000CD, 0x1 },
304 { 0x00000018, 0x000000DF, 0x0 },
305 { 0x80003015, 0x000000CD, 0x1 }, /* Default */
306 { 0x80003015, 0x000000C0, 0x1 },
307 { 0x80000018, 0x000000C0, 0x1 },
310 /* Skylake/Kabylake Y */
311 static const struct ddi_buf_trans skl_y_ddi_translations_hdmi
[] = {
312 { 0x00000018, 0x000000A1, 0x0 },
313 { 0x00005012, 0x000000DF, 0x0 },
314 { 0x80007011, 0x000000CB, 0x3 },
315 { 0x00000018, 0x000000A4, 0x0 },
316 { 0x00000018, 0x0000009D, 0x0 },
317 { 0x00004013, 0x00000080, 0x0 },
318 { 0x80006013, 0x000000C0, 0x3 },
319 { 0x00000018, 0x0000008A, 0x0 },
320 { 0x80003015, 0x000000C0, 0x3 }, /* Default */
321 { 0x80003015, 0x000000C0, 0x3 },
322 { 0x80000018, 0x000000C0, 0x3 },
325 struct bxt_ddi_buf_trans
{
326 u8 margin
; /* swing value */
327 u8 scale
; /* scale value */
328 u8 enable
; /* scale enable */
332 static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp
[] = {
333 /* Idx NT mV diff db */
334 { 52, 0x9A, 0, 128, }, /* 0: 400 0 */
335 { 78, 0x9A, 0, 85, }, /* 1: 400 3.5 */
336 { 104, 0x9A, 0, 64, }, /* 2: 400 6 */
337 { 154, 0x9A, 0, 43, }, /* 3: 400 9.5 */
338 { 77, 0x9A, 0, 128, }, /* 4: 600 0 */
339 { 116, 0x9A, 0, 85, }, /* 5: 600 3.5 */
340 { 154, 0x9A, 0, 64, }, /* 6: 600 6 */
341 { 102, 0x9A, 0, 128, }, /* 7: 800 0 */
342 { 154, 0x9A, 0, 85, }, /* 8: 800 3.5 */
343 { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */
346 static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp
[] = {
347 /* Idx NT mV diff db */
348 { 26, 0, 0, 128, }, /* 0: 200 0 */
349 { 38, 0, 0, 112, }, /* 1: 200 1.5 */
350 { 48, 0, 0, 96, }, /* 2: 200 4 */
351 { 54, 0, 0, 69, }, /* 3: 200 6 */
352 { 32, 0, 0, 128, }, /* 4: 250 0 */
353 { 48, 0, 0, 104, }, /* 5: 250 1.5 */
354 { 54, 0, 0, 85, }, /* 6: 250 4 */
355 { 43, 0, 0, 128, }, /* 7: 300 0 */
356 { 54, 0, 0, 101, }, /* 8: 300 1.5 */
357 { 48, 0, 0, 128, }, /* 9: 300 0 */
360 /* BSpec has 2 recommended values - entries 0 and 8.
361 * Using the entry with higher vswing.
363 static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi
[] = {
364 /* Idx NT mV diff db */
365 { 52, 0x9A, 0, 128, }, /* 0: 400 0 */
366 { 52, 0x9A, 0, 85, }, /* 1: 400 3.5 */
367 { 52, 0x9A, 0, 64, }, /* 2: 400 6 */
368 { 42, 0x9A, 0, 43, }, /* 3: 400 9.5 */
369 { 77, 0x9A, 0, 128, }, /* 4: 600 0 */
370 { 77, 0x9A, 0, 85, }, /* 5: 600 3.5 */
371 { 77, 0x9A, 0, 64, }, /* 6: 600 6 */
372 { 102, 0x9A, 0, 128, }, /* 7: 800 0 */
373 { 102, 0x9A, 0, 85, }, /* 8: 800 3.5 */
374 { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */
377 struct cnl_ddi_buf_trans
{
381 u8 dw4_post_cursor_2
;
382 u8 dw4_post_cursor_1
;
385 /* Voltage Swing Programming for VccIO 0.85V for DP */
386 static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V
[] = {
387 /* NT mV Trans mV db */
388 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
389 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
390 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
391 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
392 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
393 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
394 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
395 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
396 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
397 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
400 /* Voltage Swing Programming for VccIO 0.85V for HDMI */
401 static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V
[] = {
402 /* NT mV Trans mV db */
403 { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
404 { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */
405 { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */
406 { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 */
407 { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */
408 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */
409 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
412 /* Voltage Swing Programming for VccIO 0.85V for eDP */
413 static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V
[] = {
414 /* NT mV Trans mV db */
415 { 0xA, 0x66, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
416 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
417 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
418 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
419 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
420 { 0xA, 0x66, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
421 { 0xB, 0x70, 0x3C, 0x00, 0x03 }, /* 460 600 2.3 */
422 { 0xC, 0x75, 0x3C, 0x00, 0x03 }, /* 537 700 2.3 */
423 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
426 /* Voltage Swing Programming for VccIO 0.95V for DP */
427 static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V
[] = {
428 /* NT mV Trans mV db */
429 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
430 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
431 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
432 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
433 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
434 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
435 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
436 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
437 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
438 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
441 /* Voltage Swing Programming for VccIO 0.95V for HDMI */
442 static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V
[] = {
443 /* NT mV Trans mV db */
444 { 0xA, 0x5C, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
445 { 0xB, 0x69, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
446 { 0x5, 0x76, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
447 { 0xA, 0x5E, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
448 { 0xB, 0x69, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
449 { 0xB, 0x79, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
450 { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
451 { 0x5, 0x76, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
452 { 0x6, 0x7D, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
453 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
454 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
457 /* Voltage Swing Programming for VccIO 0.95V for eDP */
458 static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V
[] = {
459 /* NT mV Trans mV db */
460 { 0xA, 0x61, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
461 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
462 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
463 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
464 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
465 { 0xA, 0x61, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
466 { 0xB, 0x68, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
467 { 0xC, 0x6E, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
468 { 0x4, 0x7F, 0x3A, 0x00, 0x05 }, /* 460 600 2.3 */
469 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
472 /* Voltage Swing Programming for VccIO 1.05V for DP */
473 static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V
[] = {
474 /* NT mV Trans mV db */
475 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
476 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
477 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
478 { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 400 1050 8.4 */
479 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
480 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
481 { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 550 1050 5.6 */
482 { 0x5, 0x76, 0x3E, 0x00, 0x01 }, /* 850 900 0.5 */
483 { 0x6, 0x7F, 0x36, 0x00, 0x09 }, /* 750 1050 2.9 */
484 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
487 /* Voltage Swing Programming for VccIO 1.05V for HDMI */
488 static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V
[] = {
489 /* NT mV Trans mV db */
490 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
491 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
492 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
493 { 0xA, 0x5B, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
494 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
495 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
496 { 0x6, 0x7C, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
497 { 0x5, 0x70, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
498 { 0x6, 0x7C, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
499 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
500 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
503 /* Voltage Swing Programming for VccIO 1.05V for eDP */
504 static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V
[] = {
505 /* NT mV Trans mV db */
506 { 0xA, 0x5E, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
507 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
508 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
509 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
510 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
511 { 0xA, 0x5E, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
512 { 0xB, 0x64, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
513 { 0xE, 0x6A, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
514 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
517 /* icl_combo_phy_ddi_translations */
518 static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_dp_hbr2
[] = {
519 /* NT mV Trans mV db */
520 { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
521 { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */
522 { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */
523 { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */
524 { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
525 { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */
526 { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */
527 { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */
528 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */
529 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
532 static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr2
[] = {
533 /* NT mV Trans mV db */
534 { 0x0, 0x7F, 0x3F, 0x00, 0x00 }, /* 200 200 0.0 */
535 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 200 250 1.9 */
536 { 0x1, 0x7F, 0x33, 0x00, 0x0C }, /* 200 300 3.5 */
537 { 0x9, 0x7F, 0x31, 0x00, 0x0E }, /* 200 350 4.9 */
538 { 0x8, 0x7F, 0x3F, 0x00, 0x00 }, /* 250 250 0.0 */
539 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 250 300 1.6 */
540 { 0x9, 0x7F, 0x35, 0x00, 0x0A }, /* 250 350 2.9 */
541 { 0x1, 0x7F, 0x3F, 0x00, 0x00 }, /* 300 300 0.0 */
542 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 300 350 1.3 */
543 { 0x9, 0x7F, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
546 static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr3
[] = {
547 /* NT mV Trans mV db */
548 { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
549 { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */
550 { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */
551 { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */
552 { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
553 { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */
554 { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */
555 { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */
556 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */
557 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
560 static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_hdmi
[] = {
561 /* NT mV Trans mV db */
562 { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
563 { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */
564 { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */
565 { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 ALS */
566 { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */
567 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */
568 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
571 static const struct cnl_ddi_buf_trans ehl_combo_phy_ddi_translations_hbr2_hbr3
[] = {
572 /* NT mV Trans mV db */
573 { 0xA, 0x33, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
574 { 0xA, 0x47, 0x36, 0x00, 0x09 }, /* 350 500 3.1 */
575 { 0xC, 0x64, 0x30, 0x00, 0x0F }, /* 350 700 6.0 */
576 { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 350 900 8.2 */
577 { 0xA, 0x46, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
578 { 0xC, 0x64, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
579 { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
580 { 0xC, 0x61, 0x3F, 0x00, 0x00 }, /* 650 700 0.6 */
581 { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 600 900 3.5 */
582 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
585 struct icl_mg_phy_ddi_buf_trans
{
586 u32 cri_txdeemph_override_5_0
;
587 u32 cri_txdeemph_override_11_6
;
588 u32 cri_txdeemph_override_17_12
;
591 static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations
[] = {
592 /* Voltage swing pre-emphasis */
593 { 0x0, 0x1B, 0x00 }, /* 0 0 */
594 { 0x0, 0x23, 0x08 }, /* 0 1 */
595 { 0x0, 0x2D, 0x12 }, /* 0 2 */
596 { 0x0, 0x00, 0x00 }, /* 0 3 */
597 { 0x0, 0x23, 0x00 }, /* 1 0 */
598 { 0x0, 0x2B, 0x09 }, /* 1 1 */
599 { 0x0, 0x2E, 0x11 }, /* 1 2 */
600 { 0x0, 0x2F, 0x00 }, /* 2 0 */
601 { 0x0, 0x33, 0x0C }, /* 2 1 */
602 { 0x0, 0x00, 0x00 }, /* 3 0 */
605 struct tgl_dkl_phy_ddi_buf_trans
{
606 u32 dkl_vswing_control
;
607 u32 dkl_preshoot_control
;
608 u32 dkl_de_emphasis_control
;
611 static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_dp_ddi_trans
[] = {
612 /* VS pre-emp Non-trans mV Pre-emph dB */
613 { 0x7, 0x0, 0x00 }, /* 0 0 400mV 0 dB */
614 { 0x5, 0x0, 0x03 }, /* 0 1 400mV 3.5 dB */
615 { 0x2, 0x0, 0x0b }, /* 0 2 400mV 6 dB */
616 { 0x0, 0x0, 0x19 }, /* 0 3 400mV 9.5 dB */
617 { 0x5, 0x0, 0x00 }, /* 1 0 600mV 0 dB */
618 { 0x2, 0x0, 0x03 }, /* 1 1 600mV 3.5 dB */
619 { 0x0, 0x0, 0x14 }, /* 1 2 600mV 6 dB */
620 { 0x2, 0x0, 0x00 }, /* 2 0 800mV 0 dB */
621 { 0x0, 0x0, 0x0B }, /* 2 1 800mV 3.5 dB */
622 { 0x0, 0x0, 0x00 }, /* 3 0 1200mV 0 dB HDMI default */
625 static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_hdmi_ddi_trans
[] = {
626 /* HDMI Preset VS Pre-emph */
627 { 0x7, 0x0, 0x0 }, /* 1 400mV 0dB */
628 { 0x6, 0x0, 0x0 }, /* 2 500mV 0dB */
629 { 0x4, 0x0, 0x0 }, /* 3 650mV 0dB */
630 { 0x2, 0x0, 0x0 }, /* 4 800mV 0dB */
631 { 0x0, 0x0, 0x0 }, /* 5 1000mV 0dB */
632 { 0x0, 0x0, 0x5 }, /* 6 Full -1.5 dB */
633 { 0x0, 0x0, 0x6 }, /* 7 Full -1.8 dB */
634 { 0x0, 0x0, 0x7 }, /* 8 Full -2 dB */
635 { 0x0, 0x0, 0x8 }, /* 9 Full -2.5 dB */
636 { 0x0, 0x0, 0xA }, /* 10 Full -3 dB */
639 static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_dp_hbr
[] = {
640 /* NT mV Trans mV db */
641 { 0xA, 0x32, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
642 { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */
643 { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */
644 { 0x6, 0x7D, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */
645 { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
646 { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */
647 { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */
648 { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */
649 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */
650 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
653 static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_dp_hbr2
[] = {
654 /* NT mV Trans mV db */
655 { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
656 { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */
657 { 0xC, 0x63, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */
658 { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */
659 { 0xA, 0x47, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
660 { 0xC, 0x63, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */
661 { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */
662 { 0xC, 0x61, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */
663 { 0x6, 0x7B, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */
664 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
667 static const struct ddi_buf_trans
*
668 bdw_get_buf_trans_edp(struct drm_i915_private
*dev_priv
, int *n_entries
)
670 if (dev_priv
->vbt
.edp
.low_vswing
) {
671 *n_entries
= ARRAY_SIZE(bdw_ddi_translations_edp
);
672 return bdw_ddi_translations_edp
;
674 *n_entries
= ARRAY_SIZE(bdw_ddi_translations_dp
);
675 return bdw_ddi_translations_dp
;
679 static const struct ddi_buf_trans
*
680 skl_get_buf_trans_dp(struct drm_i915_private
*dev_priv
, int *n_entries
)
682 if (IS_SKL_ULX(dev_priv
)) {
683 *n_entries
= ARRAY_SIZE(skl_y_ddi_translations_dp
);
684 return skl_y_ddi_translations_dp
;
685 } else if (IS_SKL_ULT(dev_priv
)) {
686 *n_entries
= ARRAY_SIZE(skl_u_ddi_translations_dp
);
687 return skl_u_ddi_translations_dp
;
689 *n_entries
= ARRAY_SIZE(skl_ddi_translations_dp
);
690 return skl_ddi_translations_dp
;
694 static const struct ddi_buf_trans
*
695 kbl_get_buf_trans_dp(struct drm_i915_private
*dev_priv
, int *n_entries
)
697 if (IS_KBL_ULX(dev_priv
) || IS_CFL_ULX(dev_priv
)) {
698 *n_entries
= ARRAY_SIZE(kbl_y_ddi_translations_dp
);
699 return kbl_y_ddi_translations_dp
;
700 } else if (IS_KBL_ULT(dev_priv
) || IS_CFL_ULT(dev_priv
)) {
701 *n_entries
= ARRAY_SIZE(kbl_u_ddi_translations_dp
);
702 return kbl_u_ddi_translations_dp
;
704 *n_entries
= ARRAY_SIZE(kbl_ddi_translations_dp
);
705 return kbl_ddi_translations_dp
;
709 static const struct ddi_buf_trans
*
710 skl_get_buf_trans_edp(struct drm_i915_private
*dev_priv
, int *n_entries
)
712 if (dev_priv
->vbt
.edp
.low_vswing
) {
713 if (IS_SKL_ULX(dev_priv
) || IS_KBL_ULX(dev_priv
) ||
714 IS_CFL_ULX(dev_priv
)) {
715 *n_entries
= ARRAY_SIZE(skl_y_ddi_translations_edp
);
716 return skl_y_ddi_translations_edp
;
717 } else if (IS_SKL_ULT(dev_priv
) || IS_KBL_ULT(dev_priv
) ||
718 IS_CFL_ULT(dev_priv
)) {
719 *n_entries
= ARRAY_SIZE(skl_u_ddi_translations_edp
);
720 return skl_u_ddi_translations_edp
;
722 *n_entries
= ARRAY_SIZE(skl_ddi_translations_edp
);
723 return skl_ddi_translations_edp
;
727 if (IS_KABYLAKE(dev_priv
) || IS_COFFEELAKE(dev_priv
))
728 return kbl_get_buf_trans_dp(dev_priv
, n_entries
);
730 return skl_get_buf_trans_dp(dev_priv
, n_entries
);
733 static const struct ddi_buf_trans
*
734 skl_get_buf_trans_hdmi(struct drm_i915_private
*dev_priv
, int *n_entries
)
736 if (IS_SKL_ULX(dev_priv
) || IS_KBL_ULX(dev_priv
) ||
737 IS_CFL_ULX(dev_priv
)) {
738 *n_entries
= ARRAY_SIZE(skl_y_ddi_translations_hdmi
);
739 return skl_y_ddi_translations_hdmi
;
741 *n_entries
= ARRAY_SIZE(skl_ddi_translations_hdmi
);
742 return skl_ddi_translations_hdmi
;
746 static int skl_buf_trans_num_entries(enum port port
, int n_entries
)
748 /* Only DDIA and DDIE can select the 10th register with DP */
749 if (port
== PORT_A
|| port
== PORT_E
)
750 return min(n_entries
, 10);
752 return min(n_entries
, 9);
755 static const struct ddi_buf_trans
*
756 intel_ddi_get_buf_trans_dp(struct drm_i915_private
*dev_priv
,
757 enum port port
, int *n_entries
)
759 if (IS_KABYLAKE(dev_priv
) || IS_COFFEELAKE(dev_priv
)) {
760 const struct ddi_buf_trans
*ddi_translations
=
761 kbl_get_buf_trans_dp(dev_priv
, n_entries
);
762 *n_entries
= skl_buf_trans_num_entries(port
, *n_entries
);
763 return ddi_translations
;
764 } else if (IS_SKYLAKE(dev_priv
)) {
765 const struct ddi_buf_trans
*ddi_translations
=
766 skl_get_buf_trans_dp(dev_priv
, n_entries
);
767 *n_entries
= skl_buf_trans_num_entries(port
, *n_entries
);
768 return ddi_translations
;
769 } else if (IS_BROADWELL(dev_priv
)) {
770 *n_entries
= ARRAY_SIZE(bdw_ddi_translations_dp
);
771 return bdw_ddi_translations_dp
;
772 } else if (IS_HASWELL(dev_priv
)) {
773 *n_entries
= ARRAY_SIZE(hsw_ddi_translations_dp
);
774 return hsw_ddi_translations_dp
;
781 static const struct ddi_buf_trans
*
782 intel_ddi_get_buf_trans_edp(struct drm_i915_private
*dev_priv
,
783 enum port port
, int *n_entries
)
785 if (IS_GEN9_BC(dev_priv
)) {
786 const struct ddi_buf_trans
*ddi_translations
=
787 skl_get_buf_trans_edp(dev_priv
, n_entries
);
788 *n_entries
= skl_buf_trans_num_entries(port
, *n_entries
);
789 return ddi_translations
;
790 } else if (IS_BROADWELL(dev_priv
)) {
791 return bdw_get_buf_trans_edp(dev_priv
, n_entries
);
792 } else if (IS_HASWELL(dev_priv
)) {
793 *n_entries
= ARRAY_SIZE(hsw_ddi_translations_dp
);
794 return hsw_ddi_translations_dp
;
801 static const struct ddi_buf_trans
*
802 intel_ddi_get_buf_trans_fdi(struct drm_i915_private
*dev_priv
,
805 if (IS_BROADWELL(dev_priv
)) {
806 *n_entries
= ARRAY_SIZE(bdw_ddi_translations_fdi
);
807 return bdw_ddi_translations_fdi
;
808 } else if (IS_HASWELL(dev_priv
)) {
809 *n_entries
= ARRAY_SIZE(hsw_ddi_translations_fdi
);
810 return hsw_ddi_translations_fdi
;
817 static const struct ddi_buf_trans
*
818 intel_ddi_get_buf_trans_hdmi(struct drm_i915_private
*dev_priv
,
821 if (IS_GEN9_BC(dev_priv
)) {
822 return skl_get_buf_trans_hdmi(dev_priv
, n_entries
);
823 } else if (IS_BROADWELL(dev_priv
)) {
824 *n_entries
= ARRAY_SIZE(bdw_ddi_translations_hdmi
);
825 return bdw_ddi_translations_hdmi
;
826 } else if (IS_HASWELL(dev_priv
)) {
827 *n_entries
= ARRAY_SIZE(hsw_ddi_translations_hdmi
);
828 return hsw_ddi_translations_hdmi
;
835 static const struct bxt_ddi_buf_trans
*
836 bxt_get_buf_trans_dp(struct drm_i915_private
*dev_priv
, int *n_entries
)
838 *n_entries
= ARRAY_SIZE(bxt_ddi_translations_dp
);
839 return bxt_ddi_translations_dp
;
842 static const struct bxt_ddi_buf_trans
*
843 bxt_get_buf_trans_edp(struct drm_i915_private
*dev_priv
, int *n_entries
)
845 if (dev_priv
->vbt
.edp
.low_vswing
) {
846 *n_entries
= ARRAY_SIZE(bxt_ddi_translations_edp
);
847 return bxt_ddi_translations_edp
;
850 return bxt_get_buf_trans_dp(dev_priv
, n_entries
);
853 static const struct bxt_ddi_buf_trans
*
854 bxt_get_buf_trans_hdmi(struct drm_i915_private
*dev_priv
, int *n_entries
)
856 *n_entries
= ARRAY_SIZE(bxt_ddi_translations_hdmi
);
857 return bxt_ddi_translations_hdmi
;
860 static const struct cnl_ddi_buf_trans
*
861 cnl_get_buf_trans_hdmi(struct drm_i915_private
*dev_priv
, int *n_entries
)
863 u32 voltage
= intel_de_read(dev_priv
, CNL_PORT_COMP_DW3
) & VOLTAGE_INFO_MASK
;
865 if (voltage
== VOLTAGE_INFO_0_85V
) {
866 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V
);
867 return cnl_ddi_translations_hdmi_0_85V
;
868 } else if (voltage
== VOLTAGE_INFO_0_95V
) {
869 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V
);
870 return cnl_ddi_translations_hdmi_0_95V
;
871 } else if (voltage
== VOLTAGE_INFO_1_05V
) {
872 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V
);
873 return cnl_ddi_translations_hdmi_1_05V
;
875 *n_entries
= 1; /* shut up gcc */
876 MISSING_CASE(voltage
);
881 static const struct cnl_ddi_buf_trans
*
882 cnl_get_buf_trans_dp(struct drm_i915_private
*dev_priv
, int *n_entries
)
884 u32 voltage
= intel_de_read(dev_priv
, CNL_PORT_COMP_DW3
) & VOLTAGE_INFO_MASK
;
886 if (voltage
== VOLTAGE_INFO_0_85V
) {
887 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_dp_0_85V
);
888 return cnl_ddi_translations_dp_0_85V
;
889 } else if (voltage
== VOLTAGE_INFO_0_95V
) {
890 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_dp_0_95V
);
891 return cnl_ddi_translations_dp_0_95V
;
892 } else if (voltage
== VOLTAGE_INFO_1_05V
) {
893 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_dp_1_05V
);
894 return cnl_ddi_translations_dp_1_05V
;
896 *n_entries
= 1; /* shut up gcc */
897 MISSING_CASE(voltage
);
902 static const struct cnl_ddi_buf_trans
*
903 cnl_get_buf_trans_edp(struct drm_i915_private
*dev_priv
, int *n_entries
)
905 u32 voltage
= intel_de_read(dev_priv
, CNL_PORT_COMP_DW3
) & VOLTAGE_INFO_MASK
;
907 if (dev_priv
->vbt
.edp
.low_vswing
) {
908 if (voltage
== VOLTAGE_INFO_0_85V
) {
909 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_edp_0_85V
);
910 return cnl_ddi_translations_edp_0_85V
;
911 } else if (voltage
== VOLTAGE_INFO_0_95V
) {
912 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_edp_0_95V
);
913 return cnl_ddi_translations_edp_0_95V
;
914 } else if (voltage
== VOLTAGE_INFO_1_05V
) {
915 *n_entries
= ARRAY_SIZE(cnl_ddi_translations_edp_1_05V
);
916 return cnl_ddi_translations_edp_1_05V
;
918 *n_entries
= 1; /* shut up gcc */
919 MISSING_CASE(voltage
);
923 return cnl_get_buf_trans_dp(dev_priv
, n_entries
);
927 static const struct cnl_ddi_buf_trans
*
928 icl_get_combo_buf_trans(struct drm_i915_private
*dev_priv
, int type
, int rate
,
931 if (type
== INTEL_OUTPUT_HDMI
) {
932 *n_entries
= ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi
);
933 return icl_combo_phy_ddi_translations_hdmi
;
934 } else if (rate
> 540000 && type
== INTEL_OUTPUT_EDP
) {
935 *n_entries
= ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr3
);
936 return icl_combo_phy_ddi_translations_edp_hbr3
;
937 } else if (type
== INTEL_OUTPUT_EDP
&& dev_priv
->vbt
.edp
.low_vswing
) {
938 *n_entries
= ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2
);
939 return icl_combo_phy_ddi_translations_edp_hbr2
;
942 *n_entries
= ARRAY_SIZE(icl_combo_phy_ddi_translations_dp_hbr2
);
943 return icl_combo_phy_ddi_translations_dp_hbr2
;
946 static const struct cnl_ddi_buf_trans
*
947 ehl_get_combo_buf_trans(struct drm_i915_private
*dev_priv
, int type
, int rate
,
950 if (type
!= INTEL_OUTPUT_HDMI
&& type
!= INTEL_OUTPUT_EDP
&&
952 *n_entries
= ARRAY_SIZE(ehl_combo_phy_ddi_translations_hbr2_hbr3
);
953 return ehl_combo_phy_ddi_translations_hbr2_hbr3
;
956 return icl_get_combo_buf_trans(dev_priv
, type
, rate
, n_entries
);
959 static const struct cnl_ddi_buf_trans
*
960 tgl_get_combo_buf_trans(struct drm_i915_private
*dev_priv
, int type
, int rate
,
963 if (type
== INTEL_OUTPUT_HDMI
|| type
== INTEL_OUTPUT_EDP
) {
964 return icl_get_combo_buf_trans(dev_priv
, type
, rate
, n_entries
);
965 } else if (rate
> 270000) {
966 *n_entries
= ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr2
);
967 return tgl_combo_phy_ddi_translations_dp_hbr2
;
970 *n_entries
= ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr
);
971 return tgl_combo_phy_ddi_translations_dp_hbr
;
974 static int intel_ddi_hdmi_level(struct intel_encoder
*encoder
)
976 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
977 int n_entries
, level
, default_entry
;
978 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
980 if (INTEL_GEN(dev_priv
) >= 12) {
981 if (intel_phy_is_combo(dev_priv
, phy
))
982 tgl_get_combo_buf_trans(dev_priv
, INTEL_OUTPUT_HDMI
,
985 n_entries
= ARRAY_SIZE(tgl_dkl_phy_hdmi_ddi_trans
);
986 default_entry
= n_entries
- 1;
987 } else if (INTEL_GEN(dev_priv
) == 11) {
988 if (intel_phy_is_combo(dev_priv
, phy
))
989 icl_get_combo_buf_trans(dev_priv
, INTEL_OUTPUT_HDMI
,
992 n_entries
= ARRAY_SIZE(icl_mg_phy_ddi_translations
);
993 default_entry
= n_entries
- 1;
994 } else if (IS_CANNONLAKE(dev_priv
)) {
995 cnl_get_buf_trans_hdmi(dev_priv
, &n_entries
);
996 default_entry
= n_entries
- 1;
997 } else if (IS_GEN9_LP(dev_priv
)) {
998 bxt_get_buf_trans_hdmi(dev_priv
, &n_entries
);
999 default_entry
= n_entries
- 1;
1000 } else if (IS_GEN9_BC(dev_priv
)) {
1001 intel_ddi_get_buf_trans_hdmi(dev_priv
, &n_entries
);
1003 } else if (IS_BROADWELL(dev_priv
)) {
1004 intel_ddi_get_buf_trans_hdmi(dev_priv
, &n_entries
);
1006 } else if (IS_HASWELL(dev_priv
)) {
1007 intel_ddi_get_buf_trans_hdmi(dev_priv
, &n_entries
);
1010 drm_WARN(&dev_priv
->drm
, 1, "ddi translation table missing\n");
1014 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, n_entries
== 0))
1017 level
= intel_bios_hdmi_level_shift(encoder
);
1019 level
= default_entry
;
1021 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, level
>= n_entries
))
1022 level
= n_entries
- 1;
1028 * Starting with Haswell, DDI port buffers must be programmed with correct
1029 * values in advance. This function programs the correct values for
1030 * DP/eDP/FDI use cases.
1032 static void intel_prepare_dp_ddi_buffers(struct intel_encoder
*encoder
,
1033 const struct intel_crtc_state
*crtc_state
)
1035 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1038 enum port port
= encoder
->port
;
1039 const struct ddi_buf_trans
*ddi_translations
;
1041 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
))
1042 ddi_translations
= intel_ddi_get_buf_trans_fdi(dev_priv
,
1044 else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_EDP
))
1045 ddi_translations
= intel_ddi_get_buf_trans_edp(dev_priv
, port
,
1048 ddi_translations
= intel_ddi_get_buf_trans_dp(dev_priv
, port
,
1051 /* If we're boosting the current, set bit 31 of trans1 */
1052 if (IS_GEN9_BC(dev_priv
) && intel_bios_dp_boost_level(encoder
))
1053 iboost_bit
= DDI_BUF_BALANCE_LEG_ENABLE
;
1055 for (i
= 0; i
< n_entries
; i
++) {
1056 intel_de_write(dev_priv
, DDI_BUF_TRANS_LO(port
, i
),
1057 ddi_translations
[i
].trans1
| iboost_bit
);
1058 intel_de_write(dev_priv
, DDI_BUF_TRANS_HI(port
, i
),
1059 ddi_translations
[i
].trans2
);
1064 * Starting with Haswell, DDI port buffers must be programmed with correct
1065 * values in advance. This function programs the correct values for
1066 * HDMI/DVI use cases.
1068 static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder
*encoder
,
1071 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1074 enum port port
= encoder
->port
;
1075 const struct ddi_buf_trans
*ddi_translations
;
1077 ddi_translations
= intel_ddi_get_buf_trans_hdmi(dev_priv
, &n_entries
);
1079 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, !ddi_translations
))
1081 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, level
>= n_entries
))
1082 level
= n_entries
- 1;
1084 /* If we're boosting the current, set bit 31 of trans1 */
1085 if (IS_GEN9_BC(dev_priv
) && intel_bios_hdmi_boost_level(encoder
))
1086 iboost_bit
= DDI_BUF_BALANCE_LEG_ENABLE
;
1088 /* Entry 9 is for HDMI: */
1089 intel_de_write(dev_priv
, DDI_BUF_TRANS_LO(port
, 9),
1090 ddi_translations
[level
].trans1
| iboost_bit
);
1091 intel_de_write(dev_priv
, DDI_BUF_TRANS_HI(port
, 9),
1092 ddi_translations
[level
].trans2
);
1095 static void intel_wait_ddi_buf_idle(struct drm_i915_private
*dev_priv
,
1098 i915_reg_t reg
= DDI_BUF_CTL(port
);
1101 for (i
= 0; i
< 16; i
++) {
1103 if (intel_de_read(dev_priv
, reg
) & DDI_BUF_IS_IDLE
)
1106 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port
));
1109 static u32
hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll
*pll
)
1111 switch (pll
->info
->id
) {
1112 case DPLL_ID_WRPLL1
:
1113 return PORT_CLK_SEL_WRPLL1
;
1114 case DPLL_ID_WRPLL2
:
1115 return PORT_CLK_SEL_WRPLL2
;
1117 return PORT_CLK_SEL_SPLL
;
1118 case DPLL_ID_LCPLL_810
:
1119 return PORT_CLK_SEL_LCPLL_810
;
1120 case DPLL_ID_LCPLL_1350
:
1121 return PORT_CLK_SEL_LCPLL_1350
;
1122 case DPLL_ID_LCPLL_2700
:
1123 return PORT_CLK_SEL_LCPLL_2700
;
1125 MISSING_CASE(pll
->info
->id
);
1126 return PORT_CLK_SEL_NONE
;
1130 static u32
icl_pll_to_ddi_clk_sel(struct intel_encoder
*encoder
,
1131 const struct intel_crtc_state
*crtc_state
)
1133 const struct intel_shared_dpll
*pll
= crtc_state
->shared_dpll
;
1134 int clock
= crtc_state
->port_clock
;
1135 const enum intel_dpll_id id
= pll
->info
->id
;
1140 * DPLL_ID_ICL_DPLL0 and DPLL_ID_ICL_DPLL1 should not be used
1141 * here, so do warn if this get passed in
1144 return DDI_CLK_SEL_NONE
;
1145 case DPLL_ID_ICL_TBTPLL
:
1148 return DDI_CLK_SEL_TBT_162
;
1150 return DDI_CLK_SEL_TBT_270
;
1152 return DDI_CLK_SEL_TBT_540
;
1154 return DDI_CLK_SEL_TBT_810
;
1156 MISSING_CASE(clock
);
1157 return DDI_CLK_SEL_NONE
;
1159 case DPLL_ID_ICL_MGPLL1
:
1160 case DPLL_ID_ICL_MGPLL2
:
1161 case DPLL_ID_ICL_MGPLL3
:
1162 case DPLL_ID_ICL_MGPLL4
:
1163 case DPLL_ID_TGL_MGPLL5
:
1164 case DPLL_ID_TGL_MGPLL6
:
1165 return DDI_CLK_SEL_MG
;
1169 /* Starting with Haswell, different DDI ports can work in FDI mode for
1170 * connection to the PCH-located connectors. For this, it is necessary to train
1171 * both the DDI port and PCH receiver for the desired DDI buffer settings.
1173 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
1174 * please note that when FDI mode is active on DDI E, it shares 2 lines with
1175 * DDI A (which is used for eDP)
1178 void hsw_fdi_link_train(struct intel_encoder
*encoder
,
1179 const struct intel_crtc_state
*crtc_state
)
1181 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1182 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1183 u32 temp
, i
, rx_ctl_val
, ddi_pll_sel
;
1185 intel_prepare_dp_ddi_buffers(encoder
, crtc_state
);
1187 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
1188 * mode set "sequence for CRT port" document:
1189 * - TP1 to TP2 time with the default value
1190 * - FDI delay to 90h
1192 * WaFDIAutoLinkSetTimingOverrride:hsw
1194 intel_de_write(dev_priv
, FDI_RX_MISC(PIPE_A
),
1195 FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2) | FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
1197 /* Enable the PCH Receiver FDI PLL */
1198 rx_ctl_val
= dev_priv
->fdi_rx_config
| FDI_RX_ENHANCE_FRAME_ENABLE
|
1200 FDI_DP_PORT_WIDTH(crtc_state
->fdi_lanes
);
1201 intel_de_write(dev_priv
, FDI_RX_CTL(PIPE_A
), rx_ctl_val
);
1202 intel_de_posting_read(dev_priv
, FDI_RX_CTL(PIPE_A
));
1205 /* Switch from Rawclk to PCDclk */
1206 rx_ctl_val
|= FDI_PCDCLK
;
1207 intel_de_write(dev_priv
, FDI_RX_CTL(PIPE_A
), rx_ctl_val
);
1209 /* Configure Port Clock Select */
1210 ddi_pll_sel
= hsw_pll_to_ddi_pll_sel(crtc_state
->shared_dpll
);
1211 intel_de_write(dev_priv
, PORT_CLK_SEL(PORT_E
), ddi_pll_sel
);
1212 drm_WARN_ON(&dev_priv
->drm
, ddi_pll_sel
!= PORT_CLK_SEL_SPLL
);
1214 /* Start the training iterating through available voltages and emphasis,
1215 * testing each value twice. */
1216 for (i
= 0; i
< ARRAY_SIZE(hsw_ddi_translations_fdi
) * 2; i
++) {
1217 /* Configure DP_TP_CTL with auto-training */
1218 intel_de_write(dev_priv
, DP_TP_CTL(PORT_E
),
1219 DP_TP_CTL_FDI_AUTOTRAIN
| DP_TP_CTL_ENHANCED_FRAME_ENABLE
| DP_TP_CTL_LINK_TRAIN_PAT1
| DP_TP_CTL_ENABLE
);
1221 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
1222 * DDI E does not support port reversal, the functionality is
1223 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
1224 * port reversal bit */
1225 intel_de_write(dev_priv
, DDI_BUF_CTL(PORT_E
),
1226 DDI_BUF_CTL_ENABLE
| ((crtc_state
->fdi_lanes
- 1) << 1) | DDI_BUF_TRANS_SELECT(i
/ 2));
1227 intel_de_posting_read(dev_priv
, DDI_BUF_CTL(PORT_E
));
1231 /* Program PCH FDI Receiver TU */
1232 intel_de_write(dev_priv
, FDI_RX_TUSIZE1(PIPE_A
), TU_SIZE(64));
1234 /* Enable PCH FDI Receiver with auto-training */
1235 rx_ctl_val
|= FDI_RX_ENABLE
| FDI_LINK_TRAIN_AUTO
;
1236 intel_de_write(dev_priv
, FDI_RX_CTL(PIPE_A
), rx_ctl_val
);
1237 intel_de_posting_read(dev_priv
, FDI_RX_CTL(PIPE_A
));
1239 /* Wait for FDI receiver lane calibration */
1242 /* Unset FDI_RX_MISC pwrdn lanes */
1243 temp
= intel_de_read(dev_priv
, FDI_RX_MISC(PIPE_A
));
1244 temp
&= ~(FDI_RX_PWRDN_LANE1_MASK
| FDI_RX_PWRDN_LANE0_MASK
);
1245 intel_de_write(dev_priv
, FDI_RX_MISC(PIPE_A
), temp
);
1246 intel_de_posting_read(dev_priv
, FDI_RX_MISC(PIPE_A
));
1248 /* Wait for FDI auto training time */
1251 temp
= intel_de_read(dev_priv
, DP_TP_STATUS(PORT_E
));
1252 if (temp
& DP_TP_STATUS_AUTOTRAIN_DONE
) {
1253 DRM_DEBUG_KMS("FDI link training done on step %d\n", i
);
1258 * Leave things enabled even if we failed to train FDI.
1259 * Results in less fireworks from the state checker.
1261 if (i
== ARRAY_SIZE(hsw_ddi_translations_fdi
) * 2 - 1) {
1262 DRM_ERROR("FDI link training failed!\n");
1266 rx_ctl_val
&= ~FDI_RX_ENABLE
;
1267 intel_de_write(dev_priv
, FDI_RX_CTL(PIPE_A
), rx_ctl_val
);
1268 intel_de_posting_read(dev_priv
, FDI_RX_CTL(PIPE_A
));
1270 temp
= intel_de_read(dev_priv
, DDI_BUF_CTL(PORT_E
));
1271 temp
&= ~DDI_BUF_CTL_ENABLE
;
1272 intel_de_write(dev_priv
, DDI_BUF_CTL(PORT_E
), temp
);
1273 intel_de_posting_read(dev_priv
, DDI_BUF_CTL(PORT_E
));
1275 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
1276 temp
= intel_de_read(dev_priv
, DP_TP_CTL(PORT_E
));
1277 temp
&= ~(DP_TP_CTL_ENABLE
| DP_TP_CTL_LINK_TRAIN_MASK
);
1278 temp
|= DP_TP_CTL_LINK_TRAIN_PAT1
;
1279 intel_de_write(dev_priv
, DP_TP_CTL(PORT_E
), temp
);
1280 intel_de_posting_read(dev_priv
, DP_TP_CTL(PORT_E
));
1282 intel_wait_ddi_buf_idle(dev_priv
, PORT_E
);
1284 /* Reset FDI_RX_MISC pwrdn lanes */
1285 temp
= intel_de_read(dev_priv
, FDI_RX_MISC(PIPE_A
));
1286 temp
&= ~(FDI_RX_PWRDN_LANE1_MASK
| FDI_RX_PWRDN_LANE0_MASK
);
1287 temp
|= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1288 intel_de_write(dev_priv
, FDI_RX_MISC(PIPE_A
), temp
);
1289 intel_de_posting_read(dev_priv
, FDI_RX_MISC(PIPE_A
));
1292 /* Enable normal pixel sending for FDI */
1293 intel_de_write(dev_priv
, DP_TP_CTL(PORT_E
),
1294 DP_TP_CTL_FDI_AUTOTRAIN
| DP_TP_CTL_LINK_TRAIN_NORMAL
| DP_TP_CTL_ENHANCED_FRAME_ENABLE
| DP_TP_CTL_ENABLE
);
1297 static void intel_ddi_init_dp_buf_reg(struct intel_encoder
*encoder
)
1299 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
1300 struct intel_digital_port
*intel_dig_port
=
1301 enc_to_dig_port(encoder
);
1303 intel_dp
->DP
= intel_dig_port
->saved_port_bits
|
1304 DDI_BUF_CTL_ENABLE
| DDI_BUF_TRANS_SELECT(0);
1305 intel_dp
->DP
|= DDI_PORT_WIDTH(intel_dp
->lane_count
);
1308 static struct intel_encoder
*
1309 intel_ddi_get_crtc_encoder(struct intel_crtc
*crtc
)
1311 struct drm_device
*dev
= crtc
->base
.dev
;
1312 struct intel_encoder
*encoder
, *ret
= NULL
;
1313 int num_encoders
= 0;
1315 for_each_encoder_on_crtc(dev
, &crtc
->base
, encoder
) {
1320 if (num_encoders
!= 1)
1321 drm_WARN(dev
, 1, "%d encoders on crtc for pipe %c\n",
1323 pipe_name(crtc
->pipe
));
1325 BUG_ON(ret
== NULL
);
1329 static int icl_calc_tbt_pll_link(struct drm_i915_private
*dev_priv
,
1332 u32 val
= intel_de_read(dev_priv
, DDI_CLK_SEL(port
)) & DDI_CLK_SEL_MASK
;
1335 case DDI_CLK_SEL_NONE
:
1337 case DDI_CLK_SEL_TBT_162
:
1339 case DDI_CLK_SEL_TBT_270
:
1341 case DDI_CLK_SEL_TBT_540
:
1343 case DDI_CLK_SEL_TBT_810
:
1351 static void ddi_dotclock_get(struct intel_crtc_state
*pipe_config
)
1355 if (pipe_config
->has_pch_encoder
)
1356 dotclock
= intel_dotclock_calculate(pipe_config
->port_clock
,
1357 &pipe_config
->fdi_m_n
);
1358 else if (intel_crtc_has_dp_encoder(pipe_config
))
1359 dotclock
= intel_dotclock_calculate(pipe_config
->port_clock
,
1360 &pipe_config
->dp_m_n
);
1361 else if (pipe_config
->has_hdmi_sink
&& pipe_config
->pipe_bpp
> 24)
1362 dotclock
= pipe_config
->port_clock
* 24 / pipe_config
->pipe_bpp
;
1364 dotclock
= pipe_config
->port_clock
;
1366 if (pipe_config
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR420
&&
1367 !intel_crtc_has_dp_encoder(pipe_config
))
1370 if (pipe_config
->pixel_multiplier
)
1371 dotclock
/= pipe_config
->pixel_multiplier
;
1373 pipe_config
->hw
.adjusted_mode
.crtc_clock
= dotclock
;
1376 static void intel_ddi_clock_get(struct intel_encoder
*encoder
,
1377 struct intel_crtc_state
*pipe_config
)
1379 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1380 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
1382 if (intel_phy_is_tc(dev_priv
, phy
) &&
1383 intel_get_shared_dpll_id(dev_priv
, pipe_config
->shared_dpll
) ==
1385 pipe_config
->port_clock
= icl_calc_tbt_pll_link(dev_priv
,
1388 pipe_config
->port_clock
=
1389 intel_dpll_get_freq(dev_priv
, pipe_config
->shared_dpll
);
1391 ddi_dotclock_get(pipe_config
);
1394 void intel_ddi_set_dp_msa(const struct intel_crtc_state
*crtc_state
,
1395 const struct drm_connector_state
*conn_state
)
1397 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1398 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1399 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
1402 if (!intel_crtc_has_dp_encoder(crtc_state
))
1405 drm_WARN_ON(&dev_priv
->drm
, transcoder_is_dsi(cpu_transcoder
));
1407 temp
= DP_MSA_MISC_SYNC_CLOCK
;
1409 switch (crtc_state
->pipe_bpp
) {
1411 temp
|= DP_MSA_MISC_6_BPC
;
1414 temp
|= DP_MSA_MISC_8_BPC
;
1417 temp
|= DP_MSA_MISC_10_BPC
;
1420 temp
|= DP_MSA_MISC_12_BPC
;
1423 MISSING_CASE(crtc_state
->pipe_bpp
);
1427 /* nonsense combination */
1428 drm_WARN_ON(&dev_priv
->drm
, crtc_state
->limited_color_range
&&
1429 crtc_state
->output_format
!= INTEL_OUTPUT_FORMAT_RGB
);
1431 if (crtc_state
->limited_color_range
)
1432 temp
|= DP_MSA_MISC_COLOR_CEA_RGB
;
1435 * As per DP 1.2 spec section 2.3.4.3 while sending
1436 * YCBCR 444 signals we should program MSA MISC1/0 fields with
1437 * colorspace information.
1439 if (crtc_state
->output_format
== INTEL_OUTPUT_FORMAT_YCBCR444
)
1440 temp
|= DP_MSA_MISC_COLOR_YCBCR_444_BT709
;
1443 * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication
1444 * of Color Encoding Format and Content Color Gamut] while sending
1445 * YCBCR 420, HDR BT.2020 signals we should program MSA MISC1 fields
1446 * which indicate VSC SDP for the Pixel Encoding/Colorimetry Format.
1448 if (intel_dp_needs_vsc_sdp(crtc_state
, conn_state
))
1449 temp
|= DP_MSA_MISC_COLOR_VSC_SDP
;
1451 intel_de_write(dev_priv
, TRANS_MSA_MISC(cpu_transcoder
), temp
);
1455 * Returns the TRANS_DDI_FUNC_CTL value based on CRTC state.
1457 * Only intended to be used by intel_ddi_enable_transcoder_func() and
1458 * intel_ddi_config_transcoder_func().
1461 intel_ddi_transcoder_func_reg_val_get(const struct intel_crtc_state
*crtc_state
)
1463 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1464 struct intel_encoder
*encoder
= intel_ddi_get_crtc_encoder(crtc
);
1465 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1466 enum pipe pipe
= crtc
->pipe
;
1467 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
1468 enum port port
= encoder
->port
;
1471 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1472 temp
= TRANS_DDI_FUNC_ENABLE
;
1473 if (INTEL_GEN(dev_priv
) >= 12)
1474 temp
|= TGL_TRANS_DDI_SELECT_PORT(port
);
1476 temp
|= TRANS_DDI_SELECT_PORT(port
);
1478 switch (crtc_state
->pipe_bpp
) {
1480 temp
|= TRANS_DDI_BPC_6
;
1483 temp
|= TRANS_DDI_BPC_8
;
1486 temp
|= TRANS_DDI_BPC_10
;
1489 temp
|= TRANS_DDI_BPC_12
;
1495 if (crtc_state
->hw
.adjusted_mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
1496 temp
|= TRANS_DDI_PVSYNC
;
1497 if (crtc_state
->hw
.adjusted_mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
1498 temp
|= TRANS_DDI_PHSYNC
;
1500 if (cpu_transcoder
== TRANSCODER_EDP
) {
1503 /* On Haswell, can only use the always-on power well for
1504 * eDP when not using the panel fitter, and when not
1505 * using motion blur mitigation (which we don't
1507 if (crtc_state
->pch_pfit
.force_thru
)
1508 temp
|= TRANS_DDI_EDP_INPUT_A_ONOFF
;
1510 temp
|= TRANS_DDI_EDP_INPUT_A_ON
;
1513 temp
|= TRANS_DDI_EDP_INPUT_B_ONOFF
;
1516 temp
|= TRANS_DDI_EDP_INPUT_C_ONOFF
;
1524 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
)) {
1525 if (crtc_state
->has_hdmi_sink
)
1526 temp
|= TRANS_DDI_MODE_SELECT_HDMI
;
1528 temp
|= TRANS_DDI_MODE_SELECT_DVI
;
1530 if (crtc_state
->hdmi_scrambling
)
1531 temp
|= TRANS_DDI_HDMI_SCRAMBLING
;
1532 if (crtc_state
->hdmi_high_tmds_clock_ratio
)
1533 temp
|= TRANS_DDI_HIGH_TMDS_CHAR_RATE
;
1534 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_ANALOG
)) {
1535 temp
|= TRANS_DDI_MODE_SELECT_FDI
;
1536 temp
|= (crtc_state
->fdi_lanes
- 1) << 1;
1537 } else if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DP_MST
)) {
1538 temp
|= TRANS_DDI_MODE_SELECT_DP_MST
;
1539 temp
|= DDI_PORT_WIDTH(crtc_state
->lane_count
);
1541 if (INTEL_GEN(dev_priv
) >= 12) {
1542 enum transcoder master
;
1544 master
= crtc_state
->mst_master_transcoder
;
1545 drm_WARN_ON(&dev_priv
->drm
,
1546 master
== INVALID_TRANSCODER
);
1547 temp
|= TRANS_DDI_MST_TRANSPORT_SELECT(master
);
1550 temp
|= TRANS_DDI_MODE_SELECT_DP_SST
;
1551 temp
|= DDI_PORT_WIDTH(crtc_state
->lane_count
);
1557 void intel_ddi_enable_transcoder_func(const struct intel_crtc_state
*crtc_state
)
1559 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1560 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1561 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
1564 temp
= intel_ddi_transcoder_func_reg_val_get(crtc_state
);
1565 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DP_MST
))
1566 temp
|= TRANS_DDI_DP_VC_PAYLOAD_ALLOC
;
1567 intel_de_write(dev_priv
, TRANS_DDI_FUNC_CTL(cpu_transcoder
), temp
);
1571 * Same as intel_ddi_enable_transcoder_func(), but it does not set the enable
1575 intel_ddi_config_transcoder_func(const struct intel_crtc_state
*crtc_state
)
1577 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1578 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1579 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
1582 temp
= intel_ddi_transcoder_func_reg_val_get(crtc_state
);
1583 temp
&= ~TRANS_DDI_FUNC_ENABLE
;
1584 intel_de_write(dev_priv
, TRANS_DDI_FUNC_CTL(cpu_transcoder
), temp
);
1587 void intel_ddi_disable_transcoder_func(const struct intel_crtc_state
*crtc_state
)
1589 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1590 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1591 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
1594 val
= intel_de_read(dev_priv
, TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1595 val
&= ~TRANS_DDI_FUNC_ENABLE
;
1597 if (INTEL_GEN(dev_priv
) >= 12) {
1598 if (!intel_dp_mst_is_master_trans(crtc_state
)) {
1599 val
&= ~(TGL_TRANS_DDI_PORT_MASK
|
1600 TRANS_DDI_MODE_SELECT_MASK
);
1603 val
&= ~(TRANS_DDI_PORT_MASK
| TRANS_DDI_MODE_SELECT_MASK
);
1605 intel_de_write(dev_priv
, TRANS_DDI_FUNC_CTL(cpu_transcoder
), val
);
1607 if (dev_priv
->quirks
& QUIRK_INCREASE_DDI_DISABLED_TIME
&&
1608 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
)) {
1609 DRM_DEBUG_KMS("Quirk Increase DDI disabled time\n");
1610 /* Quirk time at 100ms for reliable operation */
1615 int intel_ddi_toggle_hdcp_signalling(struct intel_encoder
*intel_encoder
,
1618 struct drm_device
*dev
= intel_encoder
->base
.dev
;
1619 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1620 intel_wakeref_t wakeref
;
1625 wakeref
= intel_display_power_get_if_enabled(dev_priv
,
1626 intel_encoder
->power_domain
);
1627 if (drm_WARN_ON(dev
, !wakeref
))
1630 if (drm_WARN_ON(dev
,
1631 !intel_encoder
->get_hw_state(intel_encoder
, &pipe
))) {
1636 tmp
= intel_de_read(dev_priv
, TRANS_DDI_FUNC_CTL(pipe
));
1638 tmp
|= TRANS_DDI_HDCP_SIGNALLING
;
1640 tmp
&= ~TRANS_DDI_HDCP_SIGNALLING
;
1641 intel_de_write(dev_priv
, TRANS_DDI_FUNC_CTL(pipe
), tmp
);
1643 intel_display_power_put(dev_priv
, intel_encoder
->power_domain
, wakeref
);
1647 bool intel_ddi_connector_get_hw_state(struct intel_connector
*intel_connector
)
1649 struct drm_device
*dev
= intel_connector
->base
.dev
;
1650 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1651 struct intel_encoder
*encoder
= intel_attached_encoder(intel_connector
);
1652 int type
= intel_connector
->base
.connector_type
;
1653 enum port port
= encoder
->port
;
1654 enum transcoder cpu_transcoder
;
1655 intel_wakeref_t wakeref
;
1660 wakeref
= intel_display_power_get_if_enabled(dev_priv
,
1661 encoder
->power_domain
);
1665 if (!encoder
->get_hw_state(encoder
, &pipe
)) {
1670 if (HAS_TRANSCODER_EDP(dev_priv
) && port
== PORT_A
)
1671 cpu_transcoder
= TRANSCODER_EDP
;
1673 cpu_transcoder
= (enum transcoder
) pipe
;
1675 tmp
= intel_de_read(dev_priv
, TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1677 switch (tmp
& TRANS_DDI_MODE_SELECT_MASK
) {
1678 case TRANS_DDI_MODE_SELECT_HDMI
:
1679 case TRANS_DDI_MODE_SELECT_DVI
:
1680 ret
= type
== DRM_MODE_CONNECTOR_HDMIA
;
1683 case TRANS_DDI_MODE_SELECT_DP_SST
:
1684 ret
= type
== DRM_MODE_CONNECTOR_eDP
||
1685 type
== DRM_MODE_CONNECTOR_DisplayPort
;
1688 case TRANS_DDI_MODE_SELECT_DP_MST
:
1689 /* if the transcoder is in MST state then
1690 * connector isn't connected */
1694 case TRANS_DDI_MODE_SELECT_FDI
:
1695 ret
= type
== DRM_MODE_CONNECTOR_VGA
;
1704 intel_display_power_put(dev_priv
, encoder
->power_domain
, wakeref
);
1709 static void intel_ddi_get_encoder_pipes(struct intel_encoder
*encoder
,
1710 u8
*pipe_mask
, bool *is_dp_mst
)
1712 struct drm_device
*dev
= encoder
->base
.dev
;
1713 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1714 enum port port
= encoder
->port
;
1715 intel_wakeref_t wakeref
;
1723 wakeref
= intel_display_power_get_if_enabled(dev_priv
,
1724 encoder
->power_domain
);
1728 tmp
= intel_de_read(dev_priv
, DDI_BUF_CTL(port
));
1729 if (!(tmp
& DDI_BUF_CTL_ENABLE
))
1732 if (HAS_TRANSCODER_EDP(dev_priv
) && port
== PORT_A
) {
1733 tmp
= intel_de_read(dev_priv
,
1734 TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
1736 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
1738 MISSING_CASE(tmp
& TRANS_DDI_EDP_INPUT_MASK
);
1740 case TRANS_DDI_EDP_INPUT_A_ON
:
1741 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
1742 *pipe_mask
= BIT(PIPE_A
);
1744 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
1745 *pipe_mask
= BIT(PIPE_B
);
1747 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
1748 *pipe_mask
= BIT(PIPE_C
);
1756 for_each_pipe(dev_priv
, p
) {
1757 enum transcoder cpu_transcoder
= (enum transcoder
)p
;
1758 unsigned int port_mask
, ddi_select
;
1759 intel_wakeref_t trans_wakeref
;
1761 trans_wakeref
= intel_display_power_get_if_enabled(dev_priv
,
1762 POWER_DOMAIN_TRANSCODER(cpu_transcoder
));
1766 if (INTEL_GEN(dev_priv
) >= 12) {
1767 port_mask
= TGL_TRANS_DDI_PORT_MASK
;
1768 ddi_select
= TGL_TRANS_DDI_SELECT_PORT(port
);
1770 port_mask
= TRANS_DDI_PORT_MASK
;
1771 ddi_select
= TRANS_DDI_SELECT_PORT(port
);
1774 tmp
= intel_de_read(dev_priv
,
1775 TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1776 intel_display_power_put(dev_priv
, POWER_DOMAIN_TRANSCODER(cpu_transcoder
),
1779 if ((tmp
& port_mask
) != ddi_select
)
1782 if ((tmp
& TRANS_DDI_MODE_SELECT_MASK
) ==
1783 TRANS_DDI_MODE_SELECT_DP_MST
)
1784 mst_pipe_mask
|= BIT(p
);
1786 *pipe_mask
|= BIT(p
);
1790 DRM_DEBUG_KMS("No pipe for [ENCODER:%d:%s] found\n",
1791 encoder
->base
.base
.id
, encoder
->base
.name
);
1793 if (!mst_pipe_mask
&& hweight8(*pipe_mask
) > 1) {
1794 DRM_DEBUG_KMS("Multiple pipes for [ENCODER:%d:%s] (pipe_mask %02x)\n",
1795 encoder
->base
.base
.id
, encoder
->base
.name
,
1797 *pipe_mask
= BIT(ffs(*pipe_mask
) - 1);
1800 if (mst_pipe_mask
&& mst_pipe_mask
!= *pipe_mask
)
1801 DRM_DEBUG_KMS("Conflicting MST and non-MST state for [ENCODER:%d:%s] (pipe_mask %02x mst_pipe_mask %02x)\n",
1802 encoder
->base
.base
.id
, encoder
->base
.name
,
1803 *pipe_mask
, mst_pipe_mask
);
1805 *is_dp_mst
= mst_pipe_mask
;
1808 if (*pipe_mask
&& IS_GEN9_LP(dev_priv
)) {
1809 tmp
= intel_de_read(dev_priv
, BXT_PHY_CTL(port
));
1810 if ((tmp
& (BXT_PHY_CMNLANE_POWERDOWN_ACK
|
1811 BXT_PHY_LANE_POWERDOWN_ACK
|
1812 BXT_PHY_LANE_ENABLED
)) != BXT_PHY_LANE_ENABLED
)
1813 DRM_ERROR("[ENCODER:%d:%s] enabled but PHY powered down? "
1814 "(PHY_CTL %08x)\n", encoder
->base
.base
.id
,
1815 encoder
->base
.name
, tmp
);
1818 intel_display_power_put(dev_priv
, encoder
->power_domain
, wakeref
);
1821 bool intel_ddi_get_hw_state(struct intel_encoder
*encoder
,
1827 intel_ddi_get_encoder_pipes(encoder
, &pipe_mask
, &is_mst
);
1829 if (is_mst
|| !pipe_mask
)
1832 *pipe
= ffs(pipe_mask
) - 1;
1837 static inline enum intel_display_power_domain
1838 intel_ddi_main_link_aux_domain(struct intel_digital_port
*dig_port
)
1840 /* CNL+ HW requires corresponding AUX IOs to be powered up for PSR with
1841 * DC states enabled at the same time, while for driver initiated AUX
1842 * transfers we need the same AUX IOs to be powered but with DC states
1843 * disabled. Accordingly use the AUX power domain here which leaves DC
1845 * However, for non-A AUX ports the corresponding non-EDP transcoders
1846 * would have already enabled power well 2 and DC_OFF. This means we can
1847 * acquire a wider POWER_DOMAIN_AUX_{B,C,D,F} reference instead of a
1848 * specific AUX_IO reference without powering up any extra wells.
1849 * Note that PSR is enabled only on Port A even though this function
1850 * returns the correct domain for other ports too.
1852 return dig_port
->aux_ch
== AUX_CH_A
? POWER_DOMAIN_AUX_IO_A
:
1853 intel_aux_power_domain(dig_port
);
1856 static void intel_ddi_get_power_domains(struct intel_encoder
*encoder
,
1857 struct intel_crtc_state
*crtc_state
)
1859 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1860 struct intel_digital_port
*dig_port
;
1861 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
1864 * TODO: Add support for MST encoders. Atm, the following should never
1865 * happen since fake-MST encoders don't set their get_power_domains()
1868 if (drm_WARN_ON(&dev_priv
->drm
,
1869 intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DP_MST
)))
1872 dig_port
= enc_to_dig_port(encoder
);
1874 if (!intel_phy_is_tc(dev_priv
, phy
) ||
1875 dig_port
->tc_mode
!= TC_PORT_TBT_ALT
)
1876 intel_display_power_get(dev_priv
,
1877 dig_port
->ddi_io_power_domain
);
1880 * AUX power is only needed for (e)DP mode, and for HDMI mode on TC
1883 if (intel_crtc_has_dp_encoder(crtc_state
) ||
1884 intel_phy_is_tc(dev_priv
, phy
))
1885 intel_display_power_get(dev_priv
,
1886 intel_ddi_main_link_aux_domain(dig_port
));
1889 * VDSC power is needed when DSC is enabled
1891 if (crtc_state
->dsc
.compression_enable
)
1892 intel_display_power_get(dev_priv
,
1893 intel_dsc_power_domain(crtc_state
));
1896 void intel_ddi_enable_pipe_clock(const struct intel_crtc_state
*crtc_state
)
1898 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
1899 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
1900 struct intel_encoder
*encoder
= intel_ddi_get_crtc_encoder(crtc
);
1901 enum port port
= encoder
->port
;
1902 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
1904 if (cpu_transcoder
!= TRANSCODER_EDP
) {
1905 if (INTEL_GEN(dev_priv
) >= 12)
1906 intel_de_write(dev_priv
,
1907 TRANS_CLK_SEL(cpu_transcoder
),
1908 TGL_TRANS_CLK_SEL_PORT(port
));
1910 intel_de_write(dev_priv
,
1911 TRANS_CLK_SEL(cpu_transcoder
),
1912 TRANS_CLK_SEL_PORT(port
));
1916 void intel_ddi_disable_pipe_clock(const struct intel_crtc_state
*crtc_state
)
1918 struct drm_i915_private
*dev_priv
= to_i915(crtc_state
->uapi
.crtc
->dev
);
1919 enum transcoder cpu_transcoder
= crtc_state
->cpu_transcoder
;
1921 if (cpu_transcoder
!= TRANSCODER_EDP
) {
1922 if (INTEL_GEN(dev_priv
) >= 12)
1923 intel_de_write(dev_priv
,
1924 TRANS_CLK_SEL(cpu_transcoder
),
1925 TGL_TRANS_CLK_SEL_DISABLED
);
1927 intel_de_write(dev_priv
,
1928 TRANS_CLK_SEL(cpu_transcoder
),
1929 TRANS_CLK_SEL_DISABLED
);
1933 static void _skl_ddi_set_iboost(struct drm_i915_private
*dev_priv
,
1934 enum port port
, u8 iboost
)
1938 tmp
= intel_de_read(dev_priv
, DISPIO_CR_TX_BMU_CR0
);
1939 tmp
&= ~(BALANCE_LEG_MASK(port
) | BALANCE_LEG_DISABLE(port
));
1941 tmp
|= iboost
<< BALANCE_LEG_SHIFT(port
);
1943 tmp
|= BALANCE_LEG_DISABLE(port
);
1944 intel_de_write(dev_priv
, DISPIO_CR_TX_BMU_CR0
, tmp
);
1947 static void skl_ddi_set_iboost(struct intel_encoder
*encoder
,
1948 int level
, enum intel_output_type type
)
1950 struct intel_digital_port
*intel_dig_port
= enc_to_dig_port(encoder
);
1951 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1952 enum port port
= encoder
->port
;
1955 if (type
== INTEL_OUTPUT_HDMI
)
1956 iboost
= intel_bios_hdmi_boost_level(encoder
);
1958 iboost
= intel_bios_dp_boost_level(encoder
);
1961 const struct ddi_buf_trans
*ddi_translations
;
1964 if (type
== INTEL_OUTPUT_HDMI
)
1965 ddi_translations
= intel_ddi_get_buf_trans_hdmi(dev_priv
, &n_entries
);
1966 else if (type
== INTEL_OUTPUT_EDP
)
1967 ddi_translations
= intel_ddi_get_buf_trans_edp(dev_priv
, port
, &n_entries
);
1969 ddi_translations
= intel_ddi_get_buf_trans_dp(dev_priv
, port
, &n_entries
);
1971 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, !ddi_translations
))
1973 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, level
>= n_entries
))
1974 level
= n_entries
- 1;
1976 iboost
= ddi_translations
[level
].i_boost
;
1979 /* Make sure that the requested I_boost is valid */
1980 if (iboost
&& iboost
!= 0x1 && iboost
!= 0x3 && iboost
!= 0x7) {
1981 DRM_ERROR("Invalid I_boost value %u\n", iboost
);
1985 _skl_ddi_set_iboost(dev_priv
, port
, iboost
);
1987 if (port
== PORT_A
&& intel_dig_port
->max_lanes
== 4)
1988 _skl_ddi_set_iboost(dev_priv
, PORT_E
, iboost
);
1991 static void bxt_ddi_vswing_sequence(struct intel_encoder
*encoder
,
1992 int level
, enum intel_output_type type
)
1994 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
1995 const struct bxt_ddi_buf_trans
*ddi_translations
;
1996 enum port port
= encoder
->port
;
1999 if (type
== INTEL_OUTPUT_HDMI
)
2000 ddi_translations
= bxt_get_buf_trans_hdmi(dev_priv
, &n_entries
);
2001 else if (type
== INTEL_OUTPUT_EDP
)
2002 ddi_translations
= bxt_get_buf_trans_edp(dev_priv
, &n_entries
);
2004 ddi_translations
= bxt_get_buf_trans_dp(dev_priv
, &n_entries
);
2006 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, !ddi_translations
))
2008 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, level
>= n_entries
))
2009 level
= n_entries
- 1;
2011 bxt_ddi_phy_set_signal_level(dev_priv
, port
,
2012 ddi_translations
[level
].margin
,
2013 ddi_translations
[level
].scale
,
2014 ddi_translations
[level
].enable
,
2015 ddi_translations
[level
].deemphasis
);
2018 u8
intel_ddi_dp_voltage_max(struct intel_encoder
*encoder
)
2020 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2021 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
2022 enum port port
= encoder
->port
;
2023 enum phy phy
= intel_port_to_phy(dev_priv
, port
);
2026 if (INTEL_GEN(dev_priv
) >= 12) {
2027 if (intel_phy_is_combo(dev_priv
, phy
))
2028 tgl_get_combo_buf_trans(dev_priv
, encoder
->type
,
2029 intel_dp
->link_rate
, &n_entries
);
2031 n_entries
= ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans
);
2032 } else if (INTEL_GEN(dev_priv
) == 11) {
2033 if (IS_ELKHARTLAKE(dev_priv
))
2034 ehl_get_combo_buf_trans(dev_priv
, encoder
->type
,
2035 intel_dp
->link_rate
, &n_entries
);
2036 else if (intel_phy_is_combo(dev_priv
, phy
))
2037 icl_get_combo_buf_trans(dev_priv
, encoder
->type
,
2038 intel_dp
->link_rate
, &n_entries
);
2040 n_entries
= ARRAY_SIZE(icl_mg_phy_ddi_translations
);
2041 } else if (IS_CANNONLAKE(dev_priv
)) {
2042 if (encoder
->type
== INTEL_OUTPUT_EDP
)
2043 cnl_get_buf_trans_edp(dev_priv
, &n_entries
);
2045 cnl_get_buf_trans_dp(dev_priv
, &n_entries
);
2046 } else if (IS_GEN9_LP(dev_priv
)) {
2047 if (encoder
->type
== INTEL_OUTPUT_EDP
)
2048 bxt_get_buf_trans_edp(dev_priv
, &n_entries
);
2050 bxt_get_buf_trans_dp(dev_priv
, &n_entries
);
2052 if (encoder
->type
== INTEL_OUTPUT_EDP
)
2053 intel_ddi_get_buf_trans_edp(dev_priv
, port
, &n_entries
);
2055 intel_ddi_get_buf_trans_dp(dev_priv
, port
, &n_entries
);
2058 if (drm_WARN_ON(&dev_priv
->drm
, n_entries
< 1))
2060 if (drm_WARN_ON(&dev_priv
->drm
,
2061 n_entries
> ARRAY_SIZE(index_to_dp_signal_levels
)))
2062 n_entries
= ARRAY_SIZE(index_to_dp_signal_levels
);
2064 return index_to_dp_signal_levels
[n_entries
- 1] &
2065 DP_TRAIN_VOLTAGE_SWING_MASK
;
2069 * We assume that the full set of pre-emphasis values can be
2070 * used on all DDI platforms. Should that change we need to
2071 * rethink this code.
2073 u8
intel_ddi_dp_pre_emphasis_max(struct intel_encoder
*encoder
, u8 voltage_swing
)
2075 switch (voltage_swing
& DP_TRAIN_VOLTAGE_SWING_MASK
) {
2076 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0
:
2077 return DP_TRAIN_PRE_EMPH_LEVEL_3
;
2078 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1
:
2079 return DP_TRAIN_PRE_EMPH_LEVEL_2
;
2080 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2
:
2081 return DP_TRAIN_PRE_EMPH_LEVEL_1
;
2082 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3
:
2084 return DP_TRAIN_PRE_EMPH_LEVEL_0
;
2088 static void cnl_ddi_vswing_program(struct intel_encoder
*encoder
,
2089 int level
, enum intel_output_type type
)
2091 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2092 const struct cnl_ddi_buf_trans
*ddi_translations
;
2093 enum port port
= encoder
->port
;
2097 if (type
== INTEL_OUTPUT_HDMI
)
2098 ddi_translations
= cnl_get_buf_trans_hdmi(dev_priv
, &n_entries
);
2099 else if (type
== INTEL_OUTPUT_EDP
)
2100 ddi_translations
= cnl_get_buf_trans_edp(dev_priv
, &n_entries
);
2102 ddi_translations
= cnl_get_buf_trans_dp(dev_priv
, &n_entries
);
2104 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, !ddi_translations
))
2106 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, level
>= n_entries
))
2107 level
= n_entries
- 1;
2109 /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */
2110 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW5_LN0(port
));
2111 val
&= ~SCALING_MODE_SEL_MASK
;
2112 val
|= SCALING_MODE_SEL(2);
2113 intel_de_write(dev_priv
, CNL_PORT_TX_DW5_GRP(port
), val
);
2115 /* Program PORT_TX_DW2 */
2116 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW2_LN0(port
));
2117 val
&= ~(SWING_SEL_LOWER_MASK
| SWING_SEL_UPPER_MASK
|
2119 val
|= SWING_SEL_UPPER(ddi_translations
[level
].dw2_swing_sel
);
2120 val
|= SWING_SEL_LOWER(ddi_translations
[level
].dw2_swing_sel
);
2121 /* Rcomp scalar is fixed as 0x98 for every table entry */
2122 val
|= RCOMP_SCALAR(0x98);
2123 intel_de_write(dev_priv
, CNL_PORT_TX_DW2_GRP(port
), val
);
2125 /* Program PORT_TX_DW4 */
2126 /* We cannot write to GRP. It would overrite individual loadgen */
2127 for (ln
= 0; ln
< 4; ln
++) {
2128 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW4_LN(ln
, port
));
2129 val
&= ~(POST_CURSOR_1_MASK
| POST_CURSOR_2_MASK
|
2131 val
|= POST_CURSOR_1(ddi_translations
[level
].dw4_post_cursor_1
);
2132 val
|= POST_CURSOR_2(ddi_translations
[level
].dw4_post_cursor_2
);
2133 val
|= CURSOR_COEFF(ddi_translations
[level
].dw4_cursor_coeff
);
2134 intel_de_write(dev_priv
, CNL_PORT_TX_DW4_LN(ln
, port
), val
);
2137 /* Program PORT_TX_DW5 */
2138 /* All DW5 values are fixed for every table entry */
2139 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW5_LN0(port
));
2140 val
&= ~RTERM_SELECT_MASK
;
2141 val
|= RTERM_SELECT(6);
2142 val
|= TAP3_DISABLE
;
2143 intel_de_write(dev_priv
, CNL_PORT_TX_DW5_GRP(port
), val
);
2145 /* Program PORT_TX_DW7 */
2146 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW7_LN0(port
));
2147 val
&= ~N_SCALAR_MASK
;
2148 val
|= N_SCALAR(ddi_translations
[level
].dw7_n_scalar
);
2149 intel_de_write(dev_priv
, CNL_PORT_TX_DW7_GRP(port
), val
);
2152 static void cnl_ddi_vswing_sequence(struct intel_encoder
*encoder
,
2153 int level
, enum intel_output_type type
)
2155 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2156 enum port port
= encoder
->port
;
2157 int width
, rate
, ln
;
2160 if (type
== INTEL_OUTPUT_HDMI
) {
2162 rate
= 0; /* Rate is always < than 6GHz for HDMI */
2164 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
2166 width
= intel_dp
->lane_count
;
2167 rate
= intel_dp
->link_rate
;
2171 * 1. If port type is eDP or DP,
2172 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
2175 val
= intel_de_read(dev_priv
, CNL_PORT_PCS_DW1_LN0(port
));
2176 if (type
!= INTEL_OUTPUT_HDMI
)
2177 val
|= COMMON_KEEPER_EN
;
2179 val
&= ~COMMON_KEEPER_EN
;
2180 intel_de_write(dev_priv
, CNL_PORT_PCS_DW1_GRP(port
), val
);
2182 /* 2. Program loadgen select */
2184 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
2185 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
2186 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
2187 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
2189 for (ln
= 0; ln
<= 3; ln
++) {
2190 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW4_LN(ln
, port
));
2191 val
&= ~LOADGEN_SELECT
;
2193 if ((rate
<= 600000 && width
== 4 && ln
>= 1) ||
2194 (rate
<= 600000 && width
< 4 && (ln
== 1 || ln
== 2))) {
2195 val
|= LOADGEN_SELECT
;
2197 intel_de_write(dev_priv
, CNL_PORT_TX_DW4_LN(ln
, port
), val
);
2200 /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
2201 val
= intel_de_read(dev_priv
, CNL_PORT_CL1CM_DW5
);
2202 val
|= SUS_CLOCK_CONFIG
;
2203 intel_de_write(dev_priv
, CNL_PORT_CL1CM_DW5
, val
);
2205 /* 4. Clear training enable to change swing values */
2206 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW5_LN0(port
));
2207 val
&= ~TX_TRAINING_EN
;
2208 intel_de_write(dev_priv
, CNL_PORT_TX_DW5_GRP(port
), val
);
2210 /* 5. Program swing and de-emphasis */
2211 cnl_ddi_vswing_program(encoder
, level
, type
);
2213 /* 6. Set training enable to trigger update */
2214 val
= intel_de_read(dev_priv
, CNL_PORT_TX_DW5_LN0(port
));
2215 val
|= TX_TRAINING_EN
;
2216 intel_de_write(dev_priv
, CNL_PORT_TX_DW5_GRP(port
), val
);
2219 static void icl_ddi_combo_vswing_program(struct drm_i915_private
*dev_priv
,
2220 u32 level
, enum phy phy
, int type
,
2223 const struct cnl_ddi_buf_trans
*ddi_translations
= NULL
;
2227 if (INTEL_GEN(dev_priv
) >= 12)
2228 ddi_translations
= tgl_get_combo_buf_trans(dev_priv
, type
, rate
,
2230 else if (IS_ELKHARTLAKE(dev_priv
))
2231 ddi_translations
= ehl_get_combo_buf_trans(dev_priv
, type
, rate
,
2234 ddi_translations
= icl_get_combo_buf_trans(dev_priv
, type
, rate
,
2236 if (!ddi_translations
)
2239 if (level
>= n_entries
) {
2240 DRM_DEBUG_KMS("DDI translation not found for level %d. Using %d instead.", level
, n_entries
- 1);
2241 level
= n_entries
- 1;
2244 /* Set PORT_TX_DW5 */
2245 val
= intel_de_read(dev_priv
, ICL_PORT_TX_DW5_LN0(phy
));
2246 val
&= ~(SCALING_MODE_SEL_MASK
| RTERM_SELECT_MASK
|
2247 TAP2_DISABLE
| TAP3_DISABLE
);
2248 val
|= SCALING_MODE_SEL(0x2);
2249 val
|= RTERM_SELECT(0x6);
2250 val
|= TAP3_DISABLE
;
2251 intel_de_write(dev_priv
, ICL_PORT_TX_DW5_GRP(phy
), val
);
2253 /* Program PORT_TX_DW2 */
2254 val
= intel_de_read(dev_priv
, ICL_PORT_TX_DW2_LN0(phy
));
2255 val
&= ~(SWING_SEL_LOWER_MASK
| SWING_SEL_UPPER_MASK
|
2257 val
|= SWING_SEL_UPPER(ddi_translations
[level
].dw2_swing_sel
);
2258 val
|= SWING_SEL_LOWER(ddi_translations
[level
].dw2_swing_sel
);
2259 /* Program Rcomp scalar for every table entry */
2260 val
|= RCOMP_SCALAR(0x98);
2261 intel_de_write(dev_priv
, ICL_PORT_TX_DW2_GRP(phy
), val
);
2263 /* Program PORT_TX_DW4 */
2264 /* We cannot write to GRP. It would overwrite individual loadgen. */
2265 for (ln
= 0; ln
<= 3; ln
++) {
2266 val
= intel_de_read(dev_priv
, ICL_PORT_TX_DW4_LN(ln
, phy
));
2267 val
&= ~(POST_CURSOR_1_MASK
| POST_CURSOR_2_MASK
|
2269 val
|= POST_CURSOR_1(ddi_translations
[level
].dw4_post_cursor_1
);
2270 val
|= POST_CURSOR_2(ddi_translations
[level
].dw4_post_cursor_2
);
2271 val
|= CURSOR_COEFF(ddi_translations
[level
].dw4_cursor_coeff
);
2272 intel_de_write(dev_priv
, ICL_PORT_TX_DW4_LN(ln
, phy
), val
);
2275 /* Program PORT_TX_DW7 */
2276 val
= intel_de_read(dev_priv
, ICL_PORT_TX_DW7_LN0(phy
));
2277 val
&= ~N_SCALAR_MASK
;
2278 val
|= N_SCALAR(ddi_translations
[level
].dw7_n_scalar
);
2279 intel_de_write(dev_priv
, ICL_PORT_TX_DW7_GRP(phy
), val
);
2282 static void icl_combo_phy_ddi_vswing_sequence(struct intel_encoder
*encoder
,
2284 enum intel_output_type type
)
2286 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2287 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
2293 if (type
== INTEL_OUTPUT_HDMI
) {
2295 /* Rate is always < than 6GHz for HDMI */
2297 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
2299 width
= intel_dp
->lane_count
;
2300 rate
= intel_dp
->link_rate
;
2304 * 1. If port type is eDP or DP,
2305 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
2308 val
= intel_de_read(dev_priv
, ICL_PORT_PCS_DW1_LN0(phy
));
2309 if (type
== INTEL_OUTPUT_HDMI
)
2310 val
&= ~COMMON_KEEPER_EN
;
2312 val
|= COMMON_KEEPER_EN
;
2313 intel_de_write(dev_priv
, ICL_PORT_PCS_DW1_GRP(phy
), val
);
2315 /* 2. Program loadgen select */
2317 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
2318 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
2319 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
2320 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
2322 for (ln
= 0; ln
<= 3; ln
++) {
2323 val
= intel_de_read(dev_priv
, ICL_PORT_TX_DW4_LN(ln
, phy
));
2324 val
&= ~LOADGEN_SELECT
;
2326 if ((rate
<= 600000 && width
== 4 && ln
>= 1) ||
2327 (rate
<= 600000 && width
< 4 && (ln
== 1 || ln
== 2))) {
2328 val
|= LOADGEN_SELECT
;
2330 intel_de_write(dev_priv
, ICL_PORT_TX_DW4_LN(ln
, phy
), val
);
2333 /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
2334 val
= intel_de_read(dev_priv
, ICL_PORT_CL_DW5(phy
));
2335 val
|= SUS_CLOCK_CONFIG
;
2336 intel_de_write(dev_priv
, ICL_PORT_CL_DW5(phy
), val
);
2338 /* 4. Clear training enable to change swing values */
2339 val
= intel_de_read(dev_priv
, ICL_PORT_TX_DW5_LN0(phy
));
2340 val
&= ~TX_TRAINING_EN
;
2341 intel_de_write(dev_priv
, ICL_PORT_TX_DW5_GRP(phy
), val
);
2343 /* 5. Program swing and de-emphasis */
2344 icl_ddi_combo_vswing_program(dev_priv
, level
, phy
, type
, rate
);
2346 /* 6. Set training enable to trigger update */
2347 val
= intel_de_read(dev_priv
, ICL_PORT_TX_DW5_LN0(phy
));
2348 val
|= TX_TRAINING_EN
;
2349 intel_de_write(dev_priv
, ICL_PORT_TX_DW5_GRP(phy
), val
);
2352 static void icl_mg_phy_ddi_vswing_sequence(struct intel_encoder
*encoder
,
2356 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2357 enum tc_port tc_port
= intel_port_to_tc(dev_priv
, encoder
->port
);
2358 const struct icl_mg_phy_ddi_buf_trans
*ddi_translations
;
2362 n_entries
= ARRAY_SIZE(icl_mg_phy_ddi_translations
);
2363 ddi_translations
= icl_mg_phy_ddi_translations
;
2364 /* The table does not have values for level 3 and level 9. */
2365 if (level
>= n_entries
|| level
== 3 || level
== 9) {
2366 DRM_DEBUG_KMS("DDI translation not found for level %d. Using %d instead.",
2367 level
, n_entries
- 2);
2368 level
= n_entries
- 2;
2371 /* Set MG_TX_LINK_PARAMS cri_use_fs32 to 0. */
2372 for (ln
= 0; ln
< 2; ln
++) {
2373 val
= intel_de_read(dev_priv
, MG_TX1_LINK_PARAMS(ln
, tc_port
));
2374 val
&= ~CRI_USE_FS32
;
2375 intel_de_write(dev_priv
, MG_TX1_LINK_PARAMS(ln
, tc_port
), val
);
2377 val
= intel_de_read(dev_priv
, MG_TX2_LINK_PARAMS(ln
, tc_port
));
2378 val
&= ~CRI_USE_FS32
;
2379 intel_de_write(dev_priv
, MG_TX2_LINK_PARAMS(ln
, tc_port
), val
);
2382 /* Program MG_TX_SWINGCTRL with values from vswing table */
2383 for (ln
= 0; ln
< 2; ln
++) {
2384 val
= intel_de_read(dev_priv
, MG_TX1_SWINGCTRL(ln
, tc_port
));
2385 val
&= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK
;
2386 val
|= CRI_TXDEEMPH_OVERRIDE_17_12(
2387 ddi_translations
[level
].cri_txdeemph_override_17_12
);
2388 intel_de_write(dev_priv
, MG_TX1_SWINGCTRL(ln
, tc_port
), val
);
2390 val
= intel_de_read(dev_priv
, MG_TX2_SWINGCTRL(ln
, tc_port
));
2391 val
&= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK
;
2392 val
|= CRI_TXDEEMPH_OVERRIDE_17_12(
2393 ddi_translations
[level
].cri_txdeemph_override_17_12
);
2394 intel_de_write(dev_priv
, MG_TX2_SWINGCTRL(ln
, tc_port
), val
);
2397 /* Program MG_TX_DRVCTRL with values from vswing table */
2398 for (ln
= 0; ln
< 2; ln
++) {
2399 val
= intel_de_read(dev_priv
, MG_TX1_DRVCTRL(ln
, tc_port
));
2400 val
&= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK
|
2401 CRI_TXDEEMPH_OVERRIDE_5_0_MASK
);
2402 val
|= CRI_TXDEEMPH_OVERRIDE_5_0(
2403 ddi_translations
[level
].cri_txdeemph_override_5_0
) |
2404 CRI_TXDEEMPH_OVERRIDE_11_6(
2405 ddi_translations
[level
].cri_txdeemph_override_11_6
) |
2406 CRI_TXDEEMPH_OVERRIDE_EN
;
2407 intel_de_write(dev_priv
, MG_TX1_DRVCTRL(ln
, tc_port
), val
);
2409 val
= intel_de_read(dev_priv
, MG_TX2_DRVCTRL(ln
, tc_port
));
2410 val
&= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK
|
2411 CRI_TXDEEMPH_OVERRIDE_5_0_MASK
);
2412 val
|= CRI_TXDEEMPH_OVERRIDE_5_0(
2413 ddi_translations
[level
].cri_txdeemph_override_5_0
) |
2414 CRI_TXDEEMPH_OVERRIDE_11_6(
2415 ddi_translations
[level
].cri_txdeemph_override_11_6
) |
2416 CRI_TXDEEMPH_OVERRIDE_EN
;
2417 intel_de_write(dev_priv
, MG_TX2_DRVCTRL(ln
, tc_port
), val
);
2419 /* FIXME: Program CRI_LOADGEN_SEL after the spec is updated */
2423 * Program MG_CLKHUB<LN, port being used> with value from frequency table
2424 * In case of Legacy mode on MG PHY, both TX1 and TX2 enabled so use the
2425 * values from table for which TX1 and TX2 enabled.
2427 for (ln
= 0; ln
< 2; ln
++) {
2428 val
= intel_de_read(dev_priv
, MG_CLKHUB(ln
, tc_port
));
2429 if (link_clock
< 300000)
2430 val
|= CFG_LOW_RATE_LKREN_EN
;
2432 val
&= ~CFG_LOW_RATE_LKREN_EN
;
2433 intel_de_write(dev_priv
, MG_CLKHUB(ln
, tc_port
), val
);
2436 /* Program the MG_TX_DCC<LN, port being used> based on the link frequency */
2437 for (ln
= 0; ln
< 2; ln
++) {
2438 val
= intel_de_read(dev_priv
, MG_TX1_DCC(ln
, tc_port
));
2439 val
&= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK
;
2440 if (link_clock
<= 500000) {
2441 val
&= ~CFG_AMI_CK_DIV_OVERRIDE_EN
;
2443 val
|= CFG_AMI_CK_DIV_OVERRIDE_EN
|
2444 CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
2446 intel_de_write(dev_priv
, MG_TX1_DCC(ln
, tc_port
), val
);
2448 val
= intel_de_read(dev_priv
, MG_TX2_DCC(ln
, tc_port
));
2449 val
&= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK
;
2450 if (link_clock
<= 500000) {
2451 val
&= ~CFG_AMI_CK_DIV_OVERRIDE_EN
;
2453 val
|= CFG_AMI_CK_DIV_OVERRIDE_EN
|
2454 CFG_AMI_CK_DIV_OVERRIDE_VAL(1);
2456 intel_de_write(dev_priv
, MG_TX2_DCC(ln
, tc_port
), val
);
2459 /* Program MG_TX_PISO_READLOAD with values from vswing table */
2460 for (ln
= 0; ln
< 2; ln
++) {
2461 val
= intel_de_read(dev_priv
,
2462 MG_TX1_PISO_READLOAD(ln
, tc_port
));
2463 val
|= CRI_CALCINIT
;
2464 intel_de_write(dev_priv
, MG_TX1_PISO_READLOAD(ln
, tc_port
),
2467 val
= intel_de_read(dev_priv
,
2468 MG_TX2_PISO_READLOAD(ln
, tc_port
));
2469 val
|= CRI_CALCINIT
;
2470 intel_de_write(dev_priv
, MG_TX2_PISO_READLOAD(ln
, tc_port
),
2475 static void icl_ddi_vswing_sequence(struct intel_encoder
*encoder
,
2478 enum intel_output_type type
)
2480 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2481 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
2483 if (intel_phy_is_combo(dev_priv
, phy
))
2484 icl_combo_phy_ddi_vswing_sequence(encoder
, level
, type
);
2486 icl_mg_phy_ddi_vswing_sequence(encoder
, link_clock
, level
);
2490 tgl_dkl_phy_ddi_vswing_sequence(struct intel_encoder
*encoder
, int link_clock
,
2493 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2494 enum tc_port tc_port
= intel_port_to_tc(dev_priv
, encoder
->port
);
2495 const struct tgl_dkl_phy_ddi_buf_trans
*ddi_translations
;
2496 u32 n_entries
, val
, ln
, dpcnt_mask
, dpcnt_val
;
2498 if (encoder
->type
== INTEL_OUTPUT_HDMI
) {
2499 n_entries
= ARRAY_SIZE(tgl_dkl_phy_hdmi_ddi_trans
);
2500 ddi_translations
= tgl_dkl_phy_hdmi_ddi_trans
;
2502 n_entries
= ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans
);
2503 ddi_translations
= tgl_dkl_phy_dp_ddi_trans
;
2506 if (level
>= n_entries
)
2507 level
= n_entries
- 1;
2509 dpcnt_mask
= (DKL_TX_PRESHOOT_COEFF_MASK
|
2510 DKL_TX_DE_EMPAHSIS_COEFF_MASK
|
2511 DKL_TX_VSWING_CONTROL_MASK
);
2512 dpcnt_val
= DKL_TX_VSWING_CONTROL(ddi_translations
[level
].dkl_vswing_control
);
2513 dpcnt_val
|= DKL_TX_DE_EMPHASIS_COEFF(ddi_translations
[level
].dkl_de_emphasis_control
);
2514 dpcnt_val
|= DKL_TX_PRESHOOT_COEFF(ddi_translations
[level
].dkl_preshoot_control
);
2516 for (ln
= 0; ln
< 2; ln
++) {
2517 intel_de_write(dev_priv
, HIP_INDEX_REG(tc_port
),
2518 HIP_INDEX_VAL(tc_port
, ln
));
2520 intel_de_write(dev_priv
, DKL_TX_PMD_LANE_SUS(tc_port
), 0);
2522 /* All the registers are RMW */
2523 val
= intel_de_read(dev_priv
, DKL_TX_DPCNTL0(tc_port
));
2526 intel_de_write(dev_priv
, DKL_TX_DPCNTL0(tc_port
), val
);
2528 val
= intel_de_read(dev_priv
, DKL_TX_DPCNTL1(tc_port
));
2531 intel_de_write(dev_priv
, DKL_TX_DPCNTL1(tc_port
), val
);
2533 val
= intel_de_read(dev_priv
, DKL_TX_DPCNTL2(tc_port
));
2534 val
&= ~DKL_TX_DP20BITMODE
;
2535 intel_de_write(dev_priv
, DKL_TX_DPCNTL2(tc_port
), val
);
2539 static void tgl_ddi_vswing_sequence(struct intel_encoder
*encoder
,
2542 enum intel_output_type type
)
2544 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2545 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
2547 if (intel_phy_is_combo(dev_priv
, phy
))
2548 icl_combo_phy_ddi_vswing_sequence(encoder
, level
, type
);
2550 tgl_dkl_phy_ddi_vswing_sequence(encoder
, link_clock
, level
);
2553 static u32
translate_signal_level(int signal_levels
)
2557 for (i
= 0; i
< ARRAY_SIZE(index_to_dp_signal_levels
); i
++) {
2558 if (index_to_dp_signal_levels
[i
] == signal_levels
)
2562 WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
2568 static u32
intel_ddi_dp_level(struct intel_dp
*intel_dp
)
2570 u8 train_set
= intel_dp
->train_set
[0];
2571 int signal_levels
= train_set
& (DP_TRAIN_VOLTAGE_SWING_MASK
|
2572 DP_TRAIN_PRE_EMPHASIS_MASK
);
2574 return translate_signal_level(signal_levels
);
2577 u32
bxt_signal_levels(struct intel_dp
*intel_dp
)
2579 struct intel_digital_port
*dport
= dp_to_dig_port(intel_dp
);
2580 struct drm_i915_private
*dev_priv
= to_i915(dport
->base
.base
.dev
);
2581 struct intel_encoder
*encoder
= &dport
->base
;
2582 int level
= intel_ddi_dp_level(intel_dp
);
2584 if (INTEL_GEN(dev_priv
) >= 12)
2585 tgl_ddi_vswing_sequence(encoder
, intel_dp
->link_rate
,
2586 level
, encoder
->type
);
2587 else if (INTEL_GEN(dev_priv
) >= 11)
2588 icl_ddi_vswing_sequence(encoder
, intel_dp
->link_rate
,
2589 level
, encoder
->type
);
2590 else if (IS_CANNONLAKE(dev_priv
))
2591 cnl_ddi_vswing_sequence(encoder
, level
, encoder
->type
);
2593 bxt_ddi_vswing_sequence(encoder
, level
, encoder
->type
);
2598 u32
ddi_signal_levels(struct intel_dp
*intel_dp
)
2600 struct intel_digital_port
*dport
= dp_to_dig_port(intel_dp
);
2601 struct drm_i915_private
*dev_priv
= to_i915(dport
->base
.base
.dev
);
2602 struct intel_encoder
*encoder
= &dport
->base
;
2603 int level
= intel_ddi_dp_level(intel_dp
);
2605 if (IS_GEN9_BC(dev_priv
))
2606 skl_ddi_set_iboost(encoder
, level
, encoder
->type
);
2608 return DDI_BUF_TRANS_SELECT(level
);
2612 u32
icl_dpclka_cfgcr0_clk_off(struct drm_i915_private
*dev_priv
,
2615 if (intel_phy_is_combo(dev_priv
, phy
)) {
2616 return ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy
);
2617 } else if (intel_phy_is_tc(dev_priv
, phy
)) {
2618 enum tc_port tc_port
= intel_port_to_tc(dev_priv
,
2621 return ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port
);
2627 static void icl_map_plls_to_ports(struct intel_encoder
*encoder
,
2628 const struct intel_crtc_state
*crtc_state
)
2630 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2631 struct intel_shared_dpll
*pll
= crtc_state
->shared_dpll
;
2632 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
2635 mutex_lock(&dev_priv
->dpll
.lock
);
2637 val
= intel_de_read(dev_priv
, ICL_DPCLKA_CFGCR0
);
2638 drm_WARN_ON(&dev_priv
->drm
,
2639 (val
& icl_dpclka_cfgcr0_clk_off(dev_priv
, phy
)) == 0);
2641 if (intel_phy_is_combo(dev_priv
, phy
)) {
2643 * Even though this register references DDIs, note that we
2644 * want to pass the PHY rather than the port (DDI). For
2645 * ICL, port=phy in all cases so it doesn't matter, but for
2646 * EHL the bspec notes the following:
2648 * "DDID clock tied to DDIA clock, so DPCLKA_CFGCR0 DDIA
2649 * Clock Select chooses the PLL for both DDIA and DDID and
2650 * drives port A in all cases."
2652 val
&= ~ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy
);
2653 val
|= ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll
->info
->id
, phy
);
2654 intel_de_write(dev_priv
, ICL_DPCLKA_CFGCR0
, val
);
2655 intel_de_posting_read(dev_priv
, ICL_DPCLKA_CFGCR0
);
2658 val
&= ~icl_dpclka_cfgcr0_clk_off(dev_priv
, phy
);
2659 intel_de_write(dev_priv
, ICL_DPCLKA_CFGCR0
, val
);
2661 mutex_unlock(&dev_priv
->dpll
.lock
);
2664 static void icl_unmap_plls_to_ports(struct intel_encoder
*encoder
)
2666 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2667 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
2670 mutex_lock(&dev_priv
->dpll
.lock
);
2672 val
= intel_de_read(dev_priv
, ICL_DPCLKA_CFGCR0
);
2673 val
|= icl_dpclka_cfgcr0_clk_off(dev_priv
, phy
);
2674 intel_de_write(dev_priv
, ICL_DPCLKA_CFGCR0
, val
);
2676 mutex_unlock(&dev_priv
->dpll
.lock
);
2679 static void icl_sanitize_port_clk_off(struct drm_i915_private
*dev_priv
,
2680 u32 port_mask
, bool ddi_clk_needed
)
2685 val
= intel_de_read(dev_priv
, ICL_DPCLKA_CFGCR0
);
2686 for_each_port_masked(port
, port_mask
) {
2687 enum phy phy
= intel_port_to_phy(dev_priv
, port
);
2688 bool ddi_clk_off
= val
& icl_dpclka_cfgcr0_clk_off(dev_priv
,
2691 if (ddi_clk_needed
== !ddi_clk_off
)
2695 * Punt on the case now where clock is gated, but it would
2696 * be needed by the port. Something else is really broken then.
2698 if (drm_WARN_ON(&dev_priv
->drm
, ddi_clk_needed
))
2701 DRM_NOTE("PHY %c is disabled/in DSI mode with an ungated DDI clock, gate it\n",
2703 val
|= icl_dpclka_cfgcr0_clk_off(dev_priv
, phy
);
2704 intel_de_write(dev_priv
, ICL_DPCLKA_CFGCR0
, val
);
2708 void icl_sanitize_encoder_pll_mapping(struct intel_encoder
*encoder
)
2710 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2712 bool ddi_clk_needed
;
2715 * In case of DP MST, we sanitize the primary encoder only, not the
2718 if (encoder
->type
== INTEL_OUTPUT_DP_MST
)
2721 if (!encoder
->base
.crtc
&& intel_encoder_is_dp(encoder
)) {
2725 intel_ddi_get_encoder_pipes(encoder
, &pipe_mask
, &is_mst
);
2727 * In the unlikely case that BIOS enables DP in MST mode, just
2728 * warn since our MST HW readout is incomplete.
2730 if (drm_WARN_ON(&dev_priv
->drm
, is_mst
))
2734 port_mask
= BIT(encoder
->port
);
2735 ddi_clk_needed
= encoder
->base
.crtc
;
2737 if (encoder
->type
== INTEL_OUTPUT_DSI
) {
2738 struct intel_encoder
*other_encoder
;
2740 port_mask
= intel_dsi_encoder_ports(encoder
);
2742 * Sanity check that we haven't incorrectly registered another
2743 * encoder using any of the ports of this DSI encoder.
2745 for_each_intel_encoder(&dev_priv
->drm
, other_encoder
) {
2746 if (other_encoder
== encoder
)
2749 if (drm_WARN_ON(&dev_priv
->drm
,
2750 port_mask
& BIT(other_encoder
->port
)))
2754 * For DSI we keep the ddi clocks gated
2755 * except during enable/disable sequence.
2757 ddi_clk_needed
= false;
2760 icl_sanitize_port_clk_off(dev_priv
, port_mask
, ddi_clk_needed
);
2763 static void intel_ddi_clk_select(struct intel_encoder
*encoder
,
2764 const struct intel_crtc_state
*crtc_state
)
2766 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2767 enum port port
= encoder
->port
;
2768 enum phy phy
= intel_port_to_phy(dev_priv
, port
);
2770 const struct intel_shared_dpll
*pll
= crtc_state
->shared_dpll
;
2772 if (drm_WARN_ON(&dev_priv
->drm
, !pll
))
2775 mutex_lock(&dev_priv
->dpll
.lock
);
2777 if (INTEL_GEN(dev_priv
) >= 11) {
2778 if (!intel_phy_is_combo(dev_priv
, phy
))
2779 intel_de_write(dev_priv
, DDI_CLK_SEL(port
),
2780 icl_pll_to_ddi_clk_sel(encoder
, crtc_state
));
2781 else if (IS_ELKHARTLAKE(dev_priv
) && port
>= PORT_C
)
2783 * MG does not exist but the programming is required
2784 * to ungate DDIC and DDID
2786 intel_de_write(dev_priv
, DDI_CLK_SEL(port
),
2788 } else if (IS_CANNONLAKE(dev_priv
)) {
2789 /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */
2790 val
= intel_de_read(dev_priv
, DPCLKA_CFGCR0
);
2791 val
&= ~DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port
);
2792 val
|= DPCLKA_CFGCR0_DDI_CLK_SEL(pll
->info
->id
, port
);
2793 intel_de_write(dev_priv
, DPCLKA_CFGCR0
, val
);
2796 * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI.
2797 * This step and the step before must be done with separate
2800 val
= intel_de_read(dev_priv
, DPCLKA_CFGCR0
);
2801 val
&= ~DPCLKA_CFGCR0_DDI_CLK_OFF(port
);
2802 intel_de_write(dev_priv
, DPCLKA_CFGCR0
, val
);
2803 } else if (IS_GEN9_BC(dev_priv
)) {
2804 /* DDI -> PLL mapping */
2805 val
= intel_de_read(dev_priv
, DPLL_CTRL2
);
2807 val
&= ~(DPLL_CTRL2_DDI_CLK_OFF(port
) |
2808 DPLL_CTRL2_DDI_CLK_SEL_MASK(port
));
2809 val
|= (DPLL_CTRL2_DDI_CLK_SEL(pll
->info
->id
, port
) |
2810 DPLL_CTRL2_DDI_SEL_OVERRIDE(port
));
2812 intel_de_write(dev_priv
, DPLL_CTRL2
, val
);
2814 } else if (INTEL_GEN(dev_priv
) < 9) {
2815 intel_de_write(dev_priv
, PORT_CLK_SEL(port
),
2816 hsw_pll_to_ddi_pll_sel(pll
));
2819 mutex_unlock(&dev_priv
->dpll
.lock
);
2822 static void intel_ddi_clk_disable(struct intel_encoder
*encoder
)
2824 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2825 enum port port
= encoder
->port
;
2826 enum phy phy
= intel_port_to_phy(dev_priv
, port
);
2828 if (INTEL_GEN(dev_priv
) >= 11) {
2829 if (!intel_phy_is_combo(dev_priv
, phy
) ||
2830 (IS_ELKHARTLAKE(dev_priv
) && port
>= PORT_C
))
2831 intel_de_write(dev_priv
, DDI_CLK_SEL(port
),
2833 } else if (IS_CANNONLAKE(dev_priv
)) {
2834 intel_de_write(dev_priv
, DPCLKA_CFGCR0
,
2835 intel_de_read(dev_priv
, DPCLKA_CFGCR0
) | DPCLKA_CFGCR0_DDI_CLK_OFF(port
));
2836 } else if (IS_GEN9_BC(dev_priv
)) {
2837 intel_de_write(dev_priv
, DPLL_CTRL2
,
2838 intel_de_read(dev_priv
, DPLL_CTRL2
) | DPLL_CTRL2_DDI_CLK_OFF(port
));
2839 } else if (INTEL_GEN(dev_priv
) < 9) {
2840 intel_de_write(dev_priv
, PORT_CLK_SEL(port
),
2846 icl_program_mg_dp_mode(struct intel_digital_port
*intel_dig_port
,
2847 const struct intel_crtc_state
*crtc_state
)
2849 struct drm_i915_private
*dev_priv
= to_i915(intel_dig_port
->base
.base
.dev
);
2850 enum tc_port tc_port
= intel_port_to_tc(dev_priv
, intel_dig_port
->base
.port
);
2851 u32 ln0
, ln1
, pin_assignment
;
2854 if (intel_dig_port
->tc_mode
== TC_PORT_TBT_ALT
)
2857 if (INTEL_GEN(dev_priv
) >= 12) {
2858 intel_de_write(dev_priv
, HIP_INDEX_REG(tc_port
),
2859 HIP_INDEX_VAL(tc_port
, 0x0));
2860 ln0
= intel_de_read(dev_priv
, DKL_DP_MODE(tc_port
));
2861 intel_de_write(dev_priv
, HIP_INDEX_REG(tc_port
),
2862 HIP_INDEX_VAL(tc_port
, 0x1));
2863 ln1
= intel_de_read(dev_priv
, DKL_DP_MODE(tc_port
));
2865 ln0
= intel_de_read(dev_priv
, MG_DP_MODE(0, tc_port
));
2866 ln1
= intel_de_read(dev_priv
, MG_DP_MODE(1, tc_port
));
2869 ln0
&= ~(MG_DP_MODE_CFG_DP_X1_MODE
| MG_DP_MODE_CFG_DP_X1_MODE
);
2870 ln1
&= ~(MG_DP_MODE_CFG_DP_X1_MODE
| MG_DP_MODE_CFG_DP_X2_MODE
);
2873 pin_assignment
= intel_tc_port_get_pin_assignment_mask(intel_dig_port
);
2874 width
= crtc_state
->lane_count
;
2876 switch (pin_assignment
) {
2878 drm_WARN_ON(&dev_priv
->drm
,
2879 intel_dig_port
->tc_mode
!= TC_PORT_LEGACY
);
2881 ln1
|= MG_DP_MODE_CFG_DP_X1_MODE
;
2883 ln0
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2884 ln1
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2889 ln0
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2890 ln1
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2895 ln0
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2896 ln1
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2902 ln0
|= MG_DP_MODE_CFG_DP_X1_MODE
;
2903 ln1
|= MG_DP_MODE_CFG_DP_X1_MODE
;
2905 ln0
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2906 ln1
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2912 ln0
|= MG_DP_MODE_CFG_DP_X1_MODE
;
2913 ln1
|= MG_DP_MODE_CFG_DP_X1_MODE
;
2915 ln0
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2916 ln1
|= MG_DP_MODE_CFG_DP_X2_MODE
;
2920 MISSING_CASE(pin_assignment
);
2923 if (INTEL_GEN(dev_priv
) >= 12) {
2924 intel_de_write(dev_priv
, HIP_INDEX_REG(tc_port
),
2925 HIP_INDEX_VAL(tc_port
, 0x0));
2926 intel_de_write(dev_priv
, DKL_DP_MODE(tc_port
), ln0
);
2927 intel_de_write(dev_priv
, HIP_INDEX_REG(tc_port
),
2928 HIP_INDEX_VAL(tc_port
, 0x1));
2929 intel_de_write(dev_priv
, DKL_DP_MODE(tc_port
), ln1
);
2931 intel_de_write(dev_priv
, MG_DP_MODE(0, tc_port
), ln0
);
2932 intel_de_write(dev_priv
, MG_DP_MODE(1, tc_port
), ln1
);
2936 static void intel_dp_sink_set_fec_ready(struct intel_dp
*intel_dp
,
2937 const struct intel_crtc_state
*crtc_state
)
2939 if (!crtc_state
->fec_enable
)
2942 if (drm_dp_dpcd_writeb(&intel_dp
->aux
, DP_FEC_CONFIGURATION
, DP_FEC_READY
) <= 0)
2943 DRM_DEBUG_KMS("Failed to set FEC_READY in the sink\n");
2946 static void intel_ddi_enable_fec(struct intel_encoder
*encoder
,
2947 const struct intel_crtc_state
*crtc_state
)
2949 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2950 struct intel_dp
*intel_dp
;
2953 if (!crtc_state
->fec_enable
)
2956 intel_dp
= enc_to_intel_dp(encoder
);
2957 val
= intel_de_read(dev_priv
, intel_dp
->regs
.dp_tp_ctl
);
2958 val
|= DP_TP_CTL_FEC_ENABLE
;
2959 intel_de_write(dev_priv
, intel_dp
->regs
.dp_tp_ctl
, val
);
2961 if (intel_de_wait_for_set(dev_priv
, intel_dp
->regs
.dp_tp_status
,
2962 DP_TP_STATUS_FEC_ENABLE_LIVE
, 1))
2963 DRM_ERROR("Timed out waiting for FEC Enable Status\n");
2966 static void intel_ddi_disable_fec_state(struct intel_encoder
*encoder
,
2967 const struct intel_crtc_state
*crtc_state
)
2969 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2970 struct intel_dp
*intel_dp
;
2973 if (!crtc_state
->fec_enable
)
2976 intel_dp
= enc_to_intel_dp(encoder
);
2977 val
= intel_de_read(dev_priv
, intel_dp
->regs
.dp_tp_ctl
);
2978 val
&= ~DP_TP_CTL_FEC_ENABLE
;
2979 intel_de_write(dev_priv
, intel_dp
->regs
.dp_tp_ctl
, val
);
2980 intel_de_posting_read(dev_priv
, intel_dp
->regs
.dp_tp_ctl
);
2983 static void tgl_ddi_pre_enable_dp(struct intel_encoder
*encoder
,
2984 const struct intel_crtc_state
*crtc_state
,
2985 const struct drm_connector_state
*conn_state
)
2987 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
2988 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
2989 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
2990 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
2991 bool is_mst
= intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DP_MST
);
2992 int level
= intel_ddi_dp_level(intel_dp
);
2993 enum transcoder transcoder
= crtc_state
->cpu_transcoder
;
2995 intel_dp_set_link_params(intel_dp
, crtc_state
->port_clock
,
2996 crtc_state
->lane_count
, is_mst
);
2998 intel_dp
->regs
.dp_tp_ctl
= TGL_DP_TP_CTL(transcoder
);
2999 intel_dp
->regs
.dp_tp_status
= TGL_DP_TP_STATUS(transcoder
);
3002 * 1. Enable Power Wells
3004 * This was handled at the beginning of intel_atomic_commit_tail(),
3005 * before we called down into this function.
3008 /* 2. Enable Panel Power if PPS is required */
3009 intel_edp_panel_on(intel_dp
);
3012 * 3. For non-TBT Type-C ports, set FIA lane count
3013 * (DFLEXDPSP.DPX4TXLATC)
3015 * This was done before tgl_ddi_pre_enable_dp by
3016 * hsw_crtc_enable()->intel_encoders_pre_pll_enable().
3020 * 4. Enable the port PLL.
3022 * The PLL enabling itself was already done before this function by
3023 * hsw_crtc_enable()->intel_enable_shared_dpll(). We need only
3024 * configure the PLL to port mapping here.
3026 intel_ddi_clk_select(encoder
, crtc_state
);
3028 /* 5. If IO power is controlled through PWR_WELL_CTL, Enable IO Power */
3029 if (!intel_phy_is_tc(dev_priv
, phy
) ||
3030 dig_port
->tc_mode
!= TC_PORT_TBT_ALT
)
3031 intel_display_power_get(dev_priv
,
3032 dig_port
->ddi_io_power_domain
);
3034 /* 6. Program DP_MODE */
3035 icl_program_mg_dp_mode(dig_port
, crtc_state
);
3038 * 7. The rest of the below are substeps under the bspec's "Enable and
3039 * Train Display Port" step. Note that steps that are specific to
3040 * MST will be handled by intel_mst_pre_enable_dp() before/after it
3041 * calls into this function. Also intel_mst_pre_enable_dp() only calls
3042 * us when active_mst_links==0, so any steps designated for "single
3043 * stream or multi-stream master transcoder" can just be performed
3044 * unconditionally here.
3048 * 7.a Configure Transcoder Clock Select to direct the Port clock to the
3051 intel_ddi_enable_pipe_clock(crtc_state
);
3054 * 7.b Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST
3057 intel_ddi_config_transcoder_func(crtc_state
);
3060 * 7.c Configure & enable DP_TP_CTL with link training pattern 1
3063 * This will be handled by the intel_dp_start_link_train() farther
3064 * down this function.
3067 /* 7.e Configure voltage swing and related IO settings */
3068 tgl_ddi_vswing_sequence(encoder
, crtc_state
->port_clock
, level
,
3072 * 7.f Combo PHY: Configure PORT_CL_DW10 Static Power Down to power up
3073 * the used lanes of the DDI.
3075 if (intel_phy_is_combo(dev_priv
, phy
)) {
3076 bool lane_reversal
=
3077 dig_port
->saved_port_bits
& DDI_BUF_PORT_REVERSAL
;
3079 intel_combo_phy_power_up_lanes(dev_priv
, phy
, false,
3080 crtc_state
->lane_count
,
3085 * 7.g Configure and enable DDI_BUF_CTL
3086 * 7.h Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout
3089 * We only configure what the register value will be here. Actual
3090 * enabling happens during link training farther down.
3092 intel_ddi_init_dp_buf_reg(encoder
);
3095 intel_dp_sink_dpms(intel_dp
, DRM_MODE_DPMS_ON
);
3097 intel_dp_sink_set_decompression_state(intel_dp
, crtc_state
, true);
3099 * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit
3100 * in the FEC_CONFIGURATION register to 1 before initiating link
3103 intel_dp_sink_set_fec_ready(intel_dp
, crtc_state
);
3106 * 7.i Follow DisplayPort specification training sequence (see notes for
3108 * 7.j If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle
3109 * Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent)
3110 * (timeout after 800 us)
3112 intel_dp_start_link_train(intel_dp
);
3114 /* 7.k Set DP_TP_CTL link training to Normal */
3115 if (!is_trans_port_sync_mode(crtc_state
))
3116 intel_dp_stop_link_train(intel_dp
);
3118 /* 7.l Configure and enable FEC if needed */
3119 intel_ddi_enable_fec(encoder
, crtc_state
);
3120 intel_dsc_enable(encoder
, crtc_state
);
3123 static void hsw_ddi_pre_enable_dp(struct intel_encoder
*encoder
,
3124 const struct intel_crtc_state
*crtc_state
,
3125 const struct drm_connector_state
*conn_state
)
3127 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
3128 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3129 enum port port
= encoder
->port
;
3130 enum phy phy
= intel_port_to_phy(dev_priv
, port
);
3131 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
3132 bool is_mst
= intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DP_MST
);
3133 int level
= intel_ddi_dp_level(intel_dp
);
3135 if (INTEL_GEN(dev_priv
) < 11)
3136 drm_WARN_ON(&dev_priv
->drm
,
3137 is_mst
&& (port
== PORT_A
|| port
== PORT_E
));
3139 drm_WARN_ON(&dev_priv
->drm
, is_mst
&& port
== PORT_A
);
3141 intel_dp_set_link_params(intel_dp
, crtc_state
->port_clock
,
3142 crtc_state
->lane_count
, is_mst
);
3144 intel_dp
->regs
.dp_tp_ctl
= DP_TP_CTL(port
);
3145 intel_dp
->regs
.dp_tp_status
= DP_TP_STATUS(port
);
3147 intel_edp_panel_on(intel_dp
);
3149 intel_ddi_clk_select(encoder
, crtc_state
);
3151 if (!intel_phy_is_tc(dev_priv
, phy
) ||
3152 dig_port
->tc_mode
!= TC_PORT_TBT_ALT
)
3153 intel_display_power_get(dev_priv
,
3154 dig_port
->ddi_io_power_domain
);
3156 icl_program_mg_dp_mode(dig_port
, crtc_state
);
3158 if (INTEL_GEN(dev_priv
) >= 11)
3159 icl_ddi_vswing_sequence(encoder
, crtc_state
->port_clock
,
3160 level
, encoder
->type
);
3161 else if (IS_CANNONLAKE(dev_priv
))
3162 cnl_ddi_vswing_sequence(encoder
, level
, encoder
->type
);
3163 else if (IS_GEN9_LP(dev_priv
))
3164 bxt_ddi_vswing_sequence(encoder
, level
, encoder
->type
);
3166 intel_prepare_dp_ddi_buffers(encoder
, crtc_state
);
3168 if (intel_phy_is_combo(dev_priv
, phy
)) {
3169 bool lane_reversal
=
3170 dig_port
->saved_port_bits
& DDI_BUF_PORT_REVERSAL
;
3172 intel_combo_phy_power_up_lanes(dev_priv
, phy
, false,
3173 crtc_state
->lane_count
,
3177 intel_ddi_init_dp_buf_reg(encoder
);
3179 intel_dp_sink_dpms(intel_dp
, DRM_MODE_DPMS_ON
);
3180 intel_dp_sink_set_decompression_state(intel_dp
, crtc_state
,
3182 intel_dp_sink_set_fec_ready(intel_dp
, crtc_state
);
3183 intel_dp_start_link_train(intel_dp
);
3184 if ((port
!= PORT_A
|| INTEL_GEN(dev_priv
) >= 9) &&
3185 !is_trans_port_sync_mode(crtc_state
))
3186 intel_dp_stop_link_train(intel_dp
);
3188 intel_ddi_enable_fec(encoder
, crtc_state
);
3191 intel_ddi_enable_pipe_clock(crtc_state
);
3193 intel_dsc_enable(encoder
, crtc_state
);
3196 static void intel_ddi_pre_enable_dp(struct intel_encoder
*encoder
,
3197 const struct intel_crtc_state
*crtc_state
,
3198 const struct drm_connector_state
*conn_state
)
3200 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3202 if (INTEL_GEN(dev_priv
) >= 12)
3203 tgl_ddi_pre_enable_dp(encoder
, crtc_state
, conn_state
);
3205 hsw_ddi_pre_enable_dp(encoder
, crtc_state
, conn_state
);
3207 /* MST will call a setting of MSA after an allocating of Virtual Channel
3208 * from MST encoder pre_enable callback.
3210 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_DP_MST
)) {
3211 intel_ddi_set_dp_msa(crtc_state
, conn_state
);
3213 intel_dp_set_m_n(crtc_state
, M1_N1
);
3217 static void intel_ddi_pre_enable_hdmi(struct intel_encoder
*encoder
,
3218 const struct intel_crtc_state
*crtc_state
,
3219 const struct drm_connector_state
*conn_state
)
3221 struct intel_digital_port
*intel_dig_port
= enc_to_dig_port(encoder
);
3222 struct intel_hdmi
*intel_hdmi
= &intel_dig_port
->hdmi
;
3223 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3224 int level
= intel_ddi_hdmi_level(encoder
);
3225 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
3227 intel_dp_dual_mode_set_tmds_output(intel_hdmi
, true);
3228 intel_ddi_clk_select(encoder
, crtc_state
);
3230 intel_display_power_get(dev_priv
, dig_port
->ddi_io_power_domain
);
3232 icl_program_mg_dp_mode(dig_port
, crtc_state
);
3234 if (INTEL_GEN(dev_priv
) >= 12)
3235 tgl_ddi_vswing_sequence(encoder
, crtc_state
->port_clock
,
3236 level
, INTEL_OUTPUT_HDMI
);
3237 else if (INTEL_GEN(dev_priv
) == 11)
3238 icl_ddi_vswing_sequence(encoder
, crtc_state
->port_clock
,
3239 level
, INTEL_OUTPUT_HDMI
);
3240 else if (IS_CANNONLAKE(dev_priv
))
3241 cnl_ddi_vswing_sequence(encoder
, level
, INTEL_OUTPUT_HDMI
);
3242 else if (IS_GEN9_LP(dev_priv
))
3243 bxt_ddi_vswing_sequence(encoder
, level
, INTEL_OUTPUT_HDMI
);
3245 intel_prepare_hdmi_ddi_buffers(encoder
, level
);
3247 if (IS_GEN9_BC(dev_priv
))
3248 skl_ddi_set_iboost(encoder
, level
, INTEL_OUTPUT_HDMI
);
3250 intel_ddi_enable_pipe_clock(crtc_state
);
3252 intel_dig_port
->set_infoframes(encoder
,
3253 crtc_state
->has_infoframe
,
3254 crtc_state
, conn_state
);
3257 static void intel_ddi_pre_enable(struct intel_encoder
*encoder
,
3258 const struct intel_crtc_state
*crtc_state
,
3259 const struct drm_connector_state
*conn_state
)
3261 struct intel_crtc
*crtc
= to_intel_crtc(crtc_state
->uapi
.crtc
);
3262 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3263 enum pipe pipe
= crtc
->pipe
;
3266 * When called from DP MST code:
3267 * - conn_state will be NULL
3268 * - encoder will be the main encoder (ie. mst->primary)
3269 * - the main connector associated with this port
3270 * won't be active or linked to a crtc
3271 * - crtc_state will be the state of the first stream to
3272 * be activated on this port, and it may not be the same
3273 * stream that will be deactivated last, but each stream
3274 * should have a state that is identical when it comes to
3275 * the DP link parameteres
3278 drm_WARN_ON(&dev_priv
->drm
, crtc_state
->has_pch_encoder
);
3280 if (INTEL_GEN(dev_priv
) >= 11)
3281 icl_map_plls_to_ports(encoder
, crtc_state
);
3283 intel_set_cpu_fifo_underrun_reporting(dev_priv
, pipe
, true);
3285 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
)) {
3286 intel_ddi_pre_enable_hdmi(encoder
, crtc_state
, conn_state
);
3288 struct intel_lspcon
*lspcon
=
3289 enc_to_intel_lspcon(encoder
);
3291 intel_ddi_pre_enable_dp(encoder
, crtc_state
, conn_state
);
3292 if (lspcon
->active
) {
3293 struct intel_digital_port
*dig_port
=
3294 enc_to_dig_port(encoder
);
3296 dig_port
->set_infoframes(encoder
,
3297 crtc_state
->has_infoframe
,
3298 crtc_state
, conn_state
);
3303 static void intel_disable_ddi_buf(struct intel_encoder
*encoder
,
3304 const struct intel_crtc_state
*crtc_state
)
3306 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3307 enum port port
= encoder
->port
;
3311 val
= intel_de_read(dev_priv
, DDI_BUF_CTL(port
));
3312 if (val
& DDI_BUF_CTL_ENABLE
) {
3313 val
&= ~DDI_BUF_CTL_ENABLE
;
3314 intel_de_write(dev_priv
, DDI_BUF_CTL(port
), val
);
3318 if (intel_crtc_has_dp_encoder(crtc_state
)) {
3319 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
3321 val
= intel_de_read(dev_priv
, intel_dp
->regs
.dp_tp_ctl
);
3322 val
&= ~(DP_TP_CTL_ENABLE
| DP_TP_CTL_LINK_TRAIN_MASK
);
3323 val
|= DP_TP_CTL_LINK_TRAIN_PAT1
;
3324 intel_de_write(dev_priv
, intel_dp
->regs
.dp_tp_ctl
, val
);
3327 /* Disable FEC in DP Sink */
3328 intel_ddi_disable_fec_state(encoder
, crtc_state
);
3331 intel_wait_ddi_buf_idle(dev_priv
, port
);
3334 static void intel_ddi_post_disable_dp(struct intel_encoder
*encoder
,
3335 const struct intel_crtc_state
*old_crtc_state
,
3336 const struct drm_connector_state
*old_conn_state
)
3338 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3339 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
3340 struct intel_dp
*intel_dp
= &dig_port
->dp
;
3341 bool is_mst
= intel_crtc_has_type(old_crtc_state
,
3342 INTEL_OUTPUT_DP_MST
);
3343 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
3346 * Power down sink before disabling the port, otherwise we end
3347 * up getting interrupts from the sink on detecting link loss.
3349 intel_dp_sink_dpms(intel_dp
, DRM_MODE_DPMS_OFF
);
3351 if (INTEL_GEN(dev_priv
) >= 12) {
3353 enum transcoder cpu_transcoder
= old_crtc_state
->cpu_transcoder
;
3356 val
= intel_de_read(dev_priv
,
3357 TRANS_DDI_FUNC_CTL(cpu_transcoder
));
3358 val
&= ~(TGL_TRANS_DDI_PORT_MASK
|
3359 TRANS_DDI_MODE_SELECT_MASK
);
3360 intel_de_write(dev_priv
,
3361 TRANS_DDI_FUNC_CTL(cpu_transcoder
),
3366 intel_ddi_disable_pipe_clock(old_crtc_state
);
3369 intel_disable_ddi_buf(encoder
, old_crtc_state
);
3372 * From TGL spec: "If single stream or multi-stream master transcoder:
3373 * Configure Transcoder Clock select to direct no clock to the
3376 if (INTEL_GEN(dev_priv
) >= 12)
3377 intel_ddi_disable_pipe_clock(old_crtc_state
);
3379 intel_edp_panel_vdd_on(intel_dp
);
3380 intel_edp_panel_off(intel_dp
);
3382 if (!intel_phy_is_tc(dev_priv
, phy
) ||
3383 dig_port
->tc_mode
!= TC_PORT_TBT_ALT
)
3384 intel_display_power_put_unchecked(dev_priv
,
3385 dig_port
->ddi_io_power_domain
);
3387 intel_ddi_clk_disable(encoder
);
3390 static void intel_ddi_post_disable_hdmi(struct intel_encoder
*encoder
,
3391 const struct intel_crtc_state
*old_crtc_state
,
3392 const struct drm_connector_state
*old_conn_state
)
3394 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3395 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
3396 struct intel_hdmi
*intel_hdmi
= &dig_port
->hdmi
;
3398 dig_port
->set_infoframes(encoder
, false,
3399 old_crtc_state
, old_conn_state
);
3401 intel_ddi_disable_pipe_clock(old_crtc_state
);
3403 intel_disable_ddi_buf(encoder
, old_crtc_state
);
3405 intel_display_power_put_unchecked(dev_priv
,
3406 dig_port
->ddi_io_power_domain
);
3408 intel_ddi_clk_disable(encoder
);
3410 intel_dp_dual_mode_set_tmds_output(intel_hdmi
, false);
3413 static void icl_disable_transcoder_port_sync(const struct intel_crtc_state
*old_crtc_state
)
3415 struct intel_crtc
*crtc
= to_intel_crtc(old_crtc_state
->uapi
.crtc
);
3416 struct drm_i915_private
*dev_priv
= to_i915(crtc
->base
.dev
);
3418 if (old_crtc_state
->master_transcoder
== INVALID_TRANSCODER
)
3421 DRM_DEBUG_KMS("Disabling Transcoder Port Sync on Slave Transcoder %s\n",
3422 transcoder_name(old_crtc_state
->cpu_transcoder
));
3424 intel_de_write(dev_priv
,
3425 TRANS_DDI_FUNC_CTL2(old_crtc_state
->cpu_transcoder
), 0);
3428 static void intel_ddi_post_disable(struct intel_encoder
*encoder
,
3429 const struct intel_crtc_state
*old_crtc_state
,
3430 const struct drm_connector_state
*old_conn_state
)
3432 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3433 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
3434 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
3435 bool is_tc_port
= intel_phy_is_tc(dev_priv
, phy
);
3437 if (!intel_crtc_has_type(old_crtc_state
, INTEL_OUTPUT_DP_MST
)) {
3438 intel_crtc_vblank_off(old_crtc_state
);
3440 intel_disable_pipe(old_crtc_state
);
3442 if (INTEL_GEN(dev_priv
) >= 11)
3443 icl_disable_transcoder_port_sync(old_crtc_state
);
3445 intel_ddi_disable_transcoder_func(old_crtc_state
);
3447 intel_dsc_disable(old_crtc_state
);
3449 if (INTEL_GEN(dev_priv
) >= 9)
3450 skl_scaler_disable(old_crtc_state
);
3452 ilk_pfit_disable(old_crtc_state
);
3456 * When called from DP MST code:
3457 * - old_conn_state will be NULL
3458 * - encoder will be the main encoder (ie. mst->primary)
3459 * - the main connector associated with this port
3460 * won't be active or linked to a crtc
3461 * - old_crtc_state will be the state of the last stream to
3462 * be deactivated on this port, and it may not be the same
3463 * stream that was activated last, but each stream
3464 * should have a state that is identical when it comes to
3465 * the DP link parameteres
3468 if (intel_crtc_has_type(old_crtc_state
, INTEL_OUTPUT_HDMI
))
3469 intel_ddi_post_disable_hdmi(encoder
,
3470 old_crtc_state
, old_conn_state
);
3472 intel_ddi_post_disable_dp(encoder
,
3473 old_crtc_state
, old_conn_state
);
3475 if (INTEL_GEN(dev_priv
) >= 11)
3476 icl_unmap_plls_to_ports(encoder
);
3478 if (intel_crtc_has_dp_encoder(old_crtc_state
) || is_tc_port
)
3479 intel_display_power_put_unchecked(dev_priv
,
3480 intel_ddi_main_link_aux_domain(dig_port
));
3483 intel_tc_port_put_link(dig_port
);
3486 void intel_ddi_fdi_post_disable(struct intel_encoder
*encoder
,
3487 const struct intel_crtc_state
*old_crtc_state
,
3488 const struct drm_connector_state
*old_conn_state
)
3490 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3494 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
3495 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
3496 * step 13 is the correct place for it. Step 18 is where it was
3497 * originally before the BUN.
3499 val
= intel_de_read(dev_priv
, FDI_RX_CTL(PIPE_A
));
3500 val
&= ~FDI_RX_ENABLE
;
3501 intel_de_write(dev_priv
, FDI_RX_CTL(PIPE_A
), val
);
3503 intel_disable_ddi_buf(encoder
, old_crtc_state
);
3504 intel_ddi_clk_disable(encoder
);
3506 val
= intel_de_read(dev_priv
, FDI_RX_MISC(PIPE_A
));
3507 val
&= ~(FDI_RX_PWRDN_LANE1_MASK
| FDI_RX_PWRDN_LANE0_MASK
);
3508 val
|= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
3509 intel_de_write(dev_priv
, FDI_RX_MISC(PIPE_A
), val
);
3511 val
= intel_de_read(dev_priv
, FDI_RX_CTL(PIPE_A
));
3513 intel_de_write(dev_priv
, FDI_RX_CTL(PIPE_A
), val
);
3515 val
= intel_de_read(dev_priv
, FDI_RX_CTL(PIPE_A
));
3516 val
&= ~FDI_RX_PLL_ENABLE
;
3517 intel_de_write(dev_priv
, FDI_RX_CTL(PIPE_A
), val
);
3520 static void intel_enable_ddi_dp(struct intel_encoder
*encoder
,
3521 const struct intel_crtc_state
*crtc_state
,
3522 const struct drm_connector_state
*conn_state
)
3524 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3525 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
3526 enum port port
= encoder
->port
;
3528 if (port
== PORT_A
&& INTEL_GEN(dev_priv
) < 9)
3529 intel_dp_stop_link_train(intel_dp
);
3531 intel_edp_backlight_on(crtc_state
, conn_state
);
3532 intel_psr_enable(intel_dp
, crtc_state
);
3533 intel_dp_vsc_enable(intel_dp
, crtc_state
, conn_state
);
3534 intel_dp_hdr_metadata_enable(intel_dp
, crtc_state
, conn_state
);
3535 intel_edp_drrs_enable(intel_dp
, crtc_state
);
3537 if (crtc_state
->has_audio
)
3538 intel_audio_codec_enable(encoder
, crtc_state
, conn_state
);
3542 gen9_chicken_trans_reg_by_port(struct drm_i915_private
*dev_priv
,
3545 static const enum transcoder trans
[] = {
3546 [PORT_A
] = TRANSCODER_EDP
,
3547 [PORT_B
] = TRANSCODER_A
,
3548 [PORT_C
] = TRANSCODER_B
,
3549 [PORT_D
] = TRANSCODER_C
,
3550 [PORT_E
] = TRANSCODER_A
,
3553 drm_WARN_ON(&dev_priv
->drm
, INTEL_GEN(dev_priv
) < 9);
3555 if (drm_WARN_ON(&dev_priv
->drm
, port
< PORT_A
|| port
> PORT_E
))
3558 return CHICKEN_TRANS(trans
[port
]);
3561 static void intel_enable_ddi_hdmi(struct intel_encoder
*encoder
,
3562 const struct intel_crtc_state
*crtc_state
,
3563 const struct drm_connector_state
*conn_state
)
3565 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3566 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
3567 struct drm_connector
*connector
= conn_state
->connector
;
3568 enum port port
= encoder
->port
;
3570 if (!intel_hdmi_handle_sink_scrambling(encoder
, connector
,
3571 crtc_state
->hdmi_high_tmds_clock_ratio
,
3572 crtc_state
->hdmi_scrambling
))
3573 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Failed to configure sink "
3574 "scrambling/TMDS bit clock ratio\n",
3575 connector
->base
.id
, connector
->name
);
3577 /* Display WA #1143: skl,kbl,cfl */
3578 if (IS_GEN9_BC(dev_priv
)) {
3580 * For some reason these chicken bits have been
3581 * stuffed into a transcoder register, event though
3582 * the bits affect a specific DDI port rather than
3583 * a specific transcoder.
3585 i915_reg_t reg
= gen9_chicken_trans_reg_by_port(dev_priv
, port
);
3588 val
= intel_de_read(dev_priv
, reg
);
3591 val
|= DDIE_TRAINING_OVERRIDE_ENABLE
|
3592 DDIE_TRAINING_OVERRIDE_VALUE
;
3594 val
|= DDI_TRAINING_OVERRIDE_ENABLE
|
3595 DDI_TRAINING_OVERRIDE_VALUE
;
3597 intel_de_write(dev_priv
, reg
, val
);
3598 intel_de_posting_read(dev_priv
, reg
);
3603 val
&= ~(DDIE_TRAINING_OVERRIDE_ENABLE
|
3604 DDIE_TRAINING_OVERRIDE_VALUE
);
3606 val
&= ~(DDI_TRAINING_OVERRIDE_ENABLE
|
3607 DDI_TRAINING_OVERRIDE_VALUE
);
3609 intel_de_write(dev_priv
, reg
, val
);
3612 /* In HDMI/DVI mode, the port width, and swing/emphasis values
3613 * are ignored so nothing special needs to be done besides
3614 * enabling the port.
3616 intel_de_write(dev_priv
, DDI_BUF_CTL(port
),
3617 dig_port
->saved_port_bits
| DDI_BUF_CTL_ENABLE
);
3619 if (crtc_state
->has_audio
)
3620 intel_audio_codec_enable(encoder
, crtc_state
, conn_state
);
3623 static void intel_enable_ddi(struct intel_encoder
*encoder
,
3624 const struct intel_crtc_state
*crtc_state
,
3625 const struct drm_connector_state
*conn_state
)
3627 WARN_ON(crtc_state
->has_pch_encoder
);
3629 intel_enable_pipe(crtc_state
);
3631 intel_crtc_vblank_on(crtc_state
);
3633 if (intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
3634 intel_enable_ddi_hdmi(encoder
, crtc_state
, conn_state
);
3636 intel_enable_ddi_dp(encoder
, crtc_state
, conn_state
);
3638 /* Enable hdcp if it's desired */
3639 if (conn_state
->content_protection
==
3640 DRM_MODE_CONTENT_PROTECTION_DESIRED
)
3641 intel_hdcp_enable(to_intel_connector(conn_state
->connector
),
3642 crtc_state
->cpu_transcoder
,
3643 (u8
)conn_state
->hdcp_content_type
);
3646 static void intel_disable_ddi_dp(struct intel_encoder
*encoder
,
3647 const struct intel_crtc_state
*old_crtc_state
,
3648 const struct drm_connector_state
*old_conn_state
)
3650 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
3652 intel_dp
->link_trained
= false;
3654 if (old_crtc_state
->has_audio
)
3655 intel_audio_codec_disable(encoder
,
3656 old_crtc_state
, old_conn_state
);
3658 intel_edp_drrs_disable(intel_dp
, old_crtc_state
);
3659 intel_psr_disable(intel_dp
, old_crtc_state
);
3660 intel_edp_backlight_off(old_conn_state
);
3661 /* Disable the decompression in DP Sink */
3662 intel_dp_sink_set_decompression_state(intel_dp
, old_crtc_state
,
3666 static void intel_disable_ddi_hdmi(struct intel_encoder
*encoder
,
3667 const struct intel_crtc_state
*old_crtc_state
,
3668 const struct drm_connector_state
*old_conn_state
)
3670 struct drm_connector
*connector
= old_conn_state
->connector
;
3672 if (old_crtc_state
->has_audio
)
3673 intel_audio_codec_disable(encoder
,
3674 old_crtc_state
, old_conn_state
);
3676 if (!intel_hdmi_handle_sink_scrambling(encoder
, connector
,
3678 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Failed to reset sink scrambling/TMDS bit clock ratio\n",
3679 connector
->base
.id
, connector
->name
);
3682 static void intel_disable_ddi(struct intel_encoder
*encoder
,
3683 const struct intel_crtc_state
*old_crtc_state
,
3684 const struct drm_connector_state
*old_conn_state
)
3686 intel_hdcp_disable(to_intel_connector(old_conn_state
->connector
));
3688 if (intel_crtc_has_type(old_crtc_state
, INTEL_OUTPUT_HDMI
))
3689 intel_disable_ddi_hdmi(encoder
, old_crtc_state
, old_conn_state
);
3691 intel_disable_ddi_dp(encoder
, old_crtc_state
, old_conn_state
);
3694 static void intel_ddi_update_pipe_dp(struct intel_encoder
*encoder
,
3695 const struct intel_crtc_state
*crtc_state
,
3696 const struct drm_connector_state
*conn_state
)
3698 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
3700 intel_ddi_set_dp_msa(crtc_state
, conn_state
);
3702 intel_psr_update(intel_dp
, crtc_state
);
3703 intel_edp_drrs_enable(intel_dp
, crtc_state
);
3705 intel_panel_update_backlight(encoder
, crtc_state
, conn_state
);
3708 static void intel_ddi_update_pipe(struct intel_encoder
*encoder
,
3709 const struct intel_crtc_state
*crtc_state
,
3710 const struct drm_connector_state
*conn_state
)
3713 if (!intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
))
3714 intel_ddi_update_pipe_dp(encoder
, crtc_state
, conn_state
);
3716 intel_hdcp_update_pipe(encoder
, crtc_state
, conn_state
);
3720 intel_ddi_update_prepare(struct intel_atomic_state
*state
,
3721 struct intel_encoder
*encoder
,
3722 struct intel_crtc
*crtc
)
3724 struct intel_crtc_state
*crtc_state
=
3725 crtc
? intel_atomic_get_new_crtc_state(state
, crtc
) : NULL
;
3726 int required_lanes
= crtc_state
? crtc_state
->lane_count
: 1;
3728 WARN_ON(crtc
&& crtc
->active
);
3730 intel_tc_port_get_link(enc_to_dig_port(encoder
),
3732 if (crtc_state
&& crtc_state
->hw
.active
)
3733 intel_update_active_dpll(state
, crtc
, encoder
);
3737 intel_ddi_update_complete(struct intel_atomic_state
*state
,
3738 struct intel_encoder
*encoder
,
3739 struct intel_crtc
*crtc
)
3741 intel_tc_port_put_link(enc_to_dig_port(encoder
));
3745 intel_ddi_pre_pll_enable(struct intel_encoder
*encoder
,
3746 const struct intel_crtc_state
*crtc_state
,
3747 const struct drm_connector_state
*conn_state
)
3749 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3750 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
3751 enum phy phy
= intel_port_to_phy(dev_priv
, encoder
->port
);
3752 bool is_tc_port
= intel_phy_is_tc(dev_priv
, phy
);
3755 intel_tc_port_get_link(dig_port
, crtc_state
->lane_count
);
3757 if (intel_crtc_has_dp_encoder(crtc_state
) || is_tc_port
)
3758 intel_display_power_get(dev_priv
,
3759 intel_ddi_main_link_aux_domain(dig_port
));
3761 if (is_tc_port
&& dig_port
->tc_mode
!= TC_PORT_TBT_ALT
)
3763 * Program the lane count for static/dynamic connections on
3764 * Type-C ports. Skip this step for TBT.
3766 intel_tc_port_set_fia_lane_count(dig_port
, crtc_state
->lane_count
);
3767 else if (IS_GEN9_LP(dev_priv
))
3768 bxt_ddi_phy_set_lane_optim_mask(encoder
,
3769 crtc_state
->lane_lat_optim_mask
);
3772 static void intel_ddi_prepare_link_retrain(struct intel_dp
*intel_dp
)
3774 struct intel_digital_port
*intel_dig_port
= dp_to_dig_port(intel_dp
);
3775 struct drm_i915_private
*dev_priv
=
3776 to_i915(intel_dig_port
->base
.base
.dev
);
3777 enum port port
= intel_dig_port
->base
.port
;
3778 u32 dp_tp_ctl
, ddi_buf_ctl
;
3781 dp_tp_ctl
= intel_de_read(dev_priv
, intel_dp
->regs
.dp_tp_ctl
);
3783 if (dp_tp_ctl
& DP_TP_CTL_ENABLE
) {
3784 ddi_buf_ctl
= intel_de_read(dev_priv
, DDI_BUF_CTL(port
));
3785 if (ddi_buf_ctl
& DDI_BUF_CTL_ENABLE
) {
3786 intel_de_write(dev_priv
, DDI_BUF_CTL(port
),
3787 ddi_buf_ctl
& ~DDI_BUF_CTL_ENABLE
);
3791 dp_tp_ctl
&= ~(DP_TP_CTL_ENABLE
| DP_TP_CTL_LINK_TRAIN_MASK
);
3792 dp_tp_ctl
|= DP_TP_CTL_LINK_TRAIN_PAT1
;
3793 intel_de_write(dev_priv
, intel_dp
->regs
.dp_tp_ctl
, dp_tp_ctl
);
3794 intel_de_posting_read(dev_priv
, intel_dp
->regs
.dp_tp_ctl
);
3797 intel_wait_ddi_buf_idle(dev_priv
, port
);
3800 dp_tp_ctl
= DP_TP_CTL_ENABLE
|
3801 DP_TP_CTL_LINK_TRAIN_PAT1
| DP_TP_CTL_SCRAMBLE_DISABLE
;
3802 if (intel_dp
->link_mst
)
3803 dp_tp_ctl
|= DP_TP_CTL_MODE_MST
;
3805 dp_tp_ctl
|= DP_TP_CTL_MODE_SST
;
3806 if (drm_dp_enhanced_frame_cap(intel_dp
->dpcd
))
3807 dp_tp_ctl
|= DP_TP_CTL_ENHANCED_FRAME_ENABLE
;
3809 intel_de_write(dev_priv
, intel_dp
->regs
.dp_tp_ctl
, dp_tp_ctl
);
3810 intel_de_posting_read(dev_priv
, intel_dp
->regs
.dp_tp_ctl
);
3812 intel_dp
->DP
|= DDI_BUF_CTL_ENABLE
;
3813 intel_de_write(dev_priv
, DDI_BUF_CTL(port
), intel_dp
->DP
);
3814 intel_de_posting_read(dev_priv
, DDI_BUF_CTL(port
));
3819 static bool intel_ddi_is_audio_enabled(struct drm_i915_private
*dev_priv
,
3820 enum transcoder cpu_transcoder
)
3822 if (cpu_transcoder
== TRANSCODER_EDP
)
3825 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_AUDIO
))
3828 return intel_de_read(dev_priv
, HSW_AUD_PIN_ELD_CP_VLD
) &
3829 AUDIO_OUTPUT_ENABLE(cpu_transcoder
);
3832 void intel_ddi_compute_min_voltage_level(struct drm_i915_private
*dev_priv
,
3833 struct intel_crtc_state
*crtc_state
)
3835 if (INTEL_GEN(dev_priv
) >= 12 && crtc_state
->port_clock
> 594000)
3836 crtc_state
->min_voltage_level
= 2;
3837 else if (IS_ELKHARTLAKE(dev_priv
) && crtc_state
->port_clock
> 594000)
3838 crtc_state
->min_voltage_level
= 3;
3839 else if (INTEL_GEN(dev_priv
) >= 11 && crtc_state
->port_clock
> 594000)
3840 crtc_state
->min_voltage_level
= 1;
3841 else if (IS_CANNONLAKE(dev_priv
) && crtc_state
->port_clock
> 594000)
3842 crtc_state
->min_voltage_level
= 2;
3845 void intel_ddi_get_config(struct intel_encoder
*encoder
,
3846 struct intel_crtc_state
*pipe_config
)
3848 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
3849 struct intel_crtc
*intel_crtc
= to_intel_crtc(pipe_config
->uapi
.crtc
);
3850 enum transcoder cpu_transcoder
= pipe_config
->cpu_transcoder
;
3851 u32 temp
, flags
= 0;
3853 /* XXX: DSI transcoder paranoia */
3854 if (drm_WARN_ON(&dev_priv
->drm
, transcoder_is_dsi(cpu_transcoder
)))
3857 intel_dsc_get_config(encoder
, pipe_config
);
3859 temp
= intel_de_read(dev_priv
, TRANS_DDI_FUNC_CTL(cpu_transcoder
));
3860 if (temp
& TRANS_DDI_PHSYNC
)
3861 flags
|= DRM_MODE_FLAG_PHSYNC
;
3863 flags
|= DRM_MODE_FLAG_NHSYNC
;
3864 if (temp
& TRANS_DDI_PVSYNC
)
3865 flags
|= DRM_MODE_FLAG_PVSYNC
;
3867 flags
|= DRM_MODE_FLAG_NVSYNC
;
3869 pipe_config
->hw
.adjusted_mode
.flags
|= flags
;
3871 switch (temp
& TRANS_DDI_BPC_MASK
) {
3872 case TRANS_DDI_BPC_6
:
3873 pipe_config
->pipe_bpp
= 18;
3875 case TRANS_DDI_BPC_8
:
3876 pipe_config
->pipe_bpp
= 24;
3878 case TRANS_DDI_BPC_10
:
3879 pipe_config
->pipe_bpp
= 30;
3881 case TRANS_DDI_BPC_12
:
3882 pipe_config
->pipe_bpp
= 36;
3888 switch (temp
& TRANS_DDI_MODE_SELECT_MASK
) {
3889 case TRANS_DDI_MODE_SELECT_HDMI
:
3890 pipe_config
->has_hdmi_sink
= true;
3892 pipe_config
->infoframes
.enable
|=
3893 intel_hdmi_infoframes_enabled(encoder
, pipe_config
);
3895 if (pipe_config
->infoframes
.enable
)
3896 pipe_config
->has_infoframe
= true;
3898 if (temp
& TRANS_DDI_HDMI_SCRAMBLING
)
3899 pipe_config
->hdmi_scrambling
= true;
3900 if (temp
& TRANS_DDI_HIGH_TMDS_CHAR_RATE
)
3901 pipe_config
->hdmi_high_tmds_clock_ratio
= true;
3903 case TRANS_DDI_MODE_SELECT_DVI
:
3904 pipe_config
->output_types
|= BIT(INTEL_OUTPUT_HDMI
);
3905 pipe_config
->lane_count
= 4;
3907 case TRANS_DDI_MODE_SELECT_FDI
:
3908 pipe_config
->output_types
|= BIT(INTEL_OUTPUT_ANALOG
);
3910 case TRANS_DDI_MODE_SELECT_DP_SST
:
3911 if (encoder
->type
== INTEL_OUTPUT_EDP
)
3912 pipe_config
->output_types
|= BIT(INTEL_OUTPUT_EDP
);
3914 pipe_config
->output_types
|= BIT(INTEL_OUTPUT_DP
);
3915 pipe_config
->lane_count
=
3916 ((temp
& DDI_PORT_WIDTH_MASK
) >> DDI_PORT_WIDTH_SHIFT
) + 1;
3917 intel_dp_get_m_n(intel_crtc
, pipe_config
);
3919 if (INTEL_GEN(dev_priv
) >= 11) {
3920 i915_reg_t dp_tp_ctl
;
3922 if (IS_GEN(dev_priv
, 11))
3923 dp_tp_ctl
= DP_TP_CTL(encoder
->port
);
3925 dp_tp_ctl
= TGL_DP_TP_CTL(pipe_config
->cpu_transcoder
);
3927 pipe_config
->fec_enable
=
3928 intel_de_read(dev_priv
, dp_tp_ctl
) & DP_TP_CTL_FEC_ENABLE
;
3930 DRM_DEBUG_KMS("[ENCODER:%d:%s] Fec status: %u\n",
3931 encoder
->base
.base
.id
, encoder
->base
.name
,
3932 pipe_config
->fec_enable
);
3936 case TRANS_DDI_MODE_SELECT_DP_MST
:
3937 pipe_config
->output_types
|= BIT(INTEL_OUTPUT_DP_MST
);
3938 pipe_config
->lane_count
=
3939 ((temp
& DDI_PORT_WIDTH_MASK
) >> DDI_PORT_WIDTH_SHIFT
) + 1;
3941 if (INTEL_GEN(dev_priv
) >= 12)
3942 pipe_config
->mst_master_transcoder
=
3943 REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK
, temp
);
3945 intel_dp_get_m_n(intel_crtc
, pipe_config
);
3951 pipe_config
->has_audio
=
3952 intel_ddi_is_audio_enabled(dev_priv
, cpu_transcoder
);
3954 if (encoder
->type
== INTEL_OUTPUT_EDP
&& dev_priv
->vbt
.edp
.bpp
&&
3955 pipe_config
->pipe_bpp
> dev_priv
->vbt
.edp
.bpp
) {
3957 * This is a big fat ugly hack.
3959 * Some machines in UEFI boot mode provide us a VBT that has 18
3960 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
3961 * unknown we fail to light up. Yet the same BIOS boots up with
3962 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
3963 * max, not what it tells us to use.
3965 * Note: This will still be broken if the eDP panel is not lit
3966 * up by the BIOS, and thus we can't get the mode at module
3969 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
3970 pipe_config
->pipe_bpp
, dev_priv
->vbt
.edp
.bpp
);
3971 dev_priv
->vbt
.edp
.bpp
= pipe_config
->pipe_bpp
;
3974 intel_ddi_clock_get(encoder
, pipe_config
);
3976 if (IS_GEN9_LP(dev_priv
))
3977 pipe_config
->lane_lat_optim_mask
=
3978 bxt_ddi_phy_get_lane_lat_optim_mask(encoder
);
3980 intel_ddi_compute_min_voltage_level(dev_priv
, pipe_config
);
3982 intel_hdmi_read_gcp_infoframe(encoder
, pipe_config
);
3984 intel_read_infoframe(encoder
, pipe_config
,
3985 HDMI_INFOFRAME_TYPE_AVI
,
3986 &pipe_config
->infoframes
.avi
);
3987 intel_read_infoframe(encoder
, pipe_config
,
3988 HDMI_INFOFRAME_TYPE_SPD
,
3989 &pipe_config
->infoframes
.spd
);
3990 intel_read_infoframe(encoder
, pipe_config
,
3991 HDMI_INFOFRAME_TYPE_VENDOR
,
3992 &pipe_config
->infoframes
.hdmi
);
3993 intel_read_infoframe(encoder
, pipe_config
,
3994 HDMI_INFOFRAME_TYPE_DRM
,
3995 &pipe_config
->infoframes
.drm
);
3998 static enum intel_output_type
3999 intel_ddi_compute_output_type(struct intel_encoder
*encoder
,
4000 struct intel_crtc_state
*crtc_state
,
4001 struct drm_connector_state
*conn_state
)
4003 switch (conn_state
->connector
->connector_type
) {
4004 case DRM_MODE_CONNECTOR_HDMIA
:
4005 return INTEL_OUTPUT_HDMI
;
4006 case DRM_MODE_CONNECTOR_eDP
:
4007 return INTEL_OUTPUT_EDP
;
4008 case DRM_MODE_CONNECTOR_DisplayPort
:
4009 return INTEL_OUTPUT_DP
;
4011 MISSING_CASE(conn_state
->connector
->connector_type
);
4012 return INTEL_OUTPUT_UNUSED
;
4016 static int intel_ddi_compute_config(struct intel_encoder
*encoder
,
4017 struct intel_crtc_state
*pipe_config
,
4018 struct drm_connector_state
*conn_state
)
4020 struct intel_crtc
*crtc
= to_intel_crtc(pipe_config
->uapi
.crtc
);
4021 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
4022 enum port port
= encoder
->port
;
4025 if (HAS_TRANSCODER_EDP(dev_priv
) && port
== PORT_A
)
4026 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
4028 if (intel_crtc_has_type(pipe_config
, INTEL_OUTPUT_HDMI
)) {
4029 ret
= intel_hdmi_compute_config(encoder
, pipe_config
, conn_state
);
4031 ret
= intel_dp_compute_config(encoder
, pipe_config
, conn_state
);
4037 if (IS_HASWELL(dev_priv
) && crtc
->pipe
== PIPE_A
&&
4038 pipe_config
->cpu_transcoder
== TRANSCODER_EDP
)
4039 pipe_config
->pch_pfit
.force_thru
=
4040 pipe_config
->pch_pfit
.enabled
||
4041 pipe_config
->crc_enabled
;
4043 if (IS_GEN9_LP(dev_priv
))
4044 pipe_config
->lane_lat_optim_mask
=
4045 bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config
->lane_count
);
4047 intel_ddi_compute_min_voltage_level(dev_priv
, pipe_config
);
4052 static bool mode_equal(const struct drm_display_mode
*mode1
,
4053 const struct drm_display_mode
*mode2
)
4055 return drm_mode_match(mode1
, mode2
,
4056 DRM_MODE_MATCH_TIMINGS
|
4057 DRM_MODE_MATCH_FLAGS
|
4058 DRM_MODE_MATCH_3D_FLAGS
) &&
4059 mode1
->clock
== mode2
->clock
; /* we want an exact match */
4062 static bool m_n_equal(const struct intel_link_m_n
*m_n_1
,
4063 const struct intel_link_m_n
*m_n_2
)
4065 return m_n_1
->tu
== m_n_2
->tu
&&
4066 m_n_1
->gmch_m
== m_n_2
->gmch_m
&&
4067 m_n_1
->gmch_n
== m_n_2
->gmch_n
&&
4068 m_n_1
->link_m
== m_n_2
->link_m
&&
4069 m_n_1
->link_n
== m_n_2
->link_n
;
4072 static bool crtcs_port_sync_compatible(const struct intel_crtc_state
*crtc_state1
,
4073 const struct intel_crtc_state
*crtc_state2
)
4075 return crtc_state1
->hw
.active
&& crtc_state2
->hw
.active
&&
4076 crtc_state1
->output_types
== crtc_state2
->output_types
&&
4077 crtc_state1
->output_format
== crtc_state2
->output_format
&&
4078 crtc_state1
->lane_count
== crtc_state2
->lane_count
&&
4079 crtc_state1
->port_clock
== crtc_state2
->port_clock
&&
4080 mode_equal(&crtc_state1
->hw
.adjusted_mode
,
4081 &crtc_state2
->hw
.adjusted_mode
) &&
4082 m_n_equal(&crtc_state1
->dp_m_n
, &crtc_state2
->dp_m_n
);
4086 intel_ddi_port_sync_transcoders(const struct intel_crtc_state
*ref_crtc_state
,
4089 struct drm_connector
*connector
;
4090 const struct drm_connector_state
*conn_state
;
4091 struct drm_i915_private
*dev_priv
= to_i915(ref_crtc_state
->uapi
.crtc
->dev
);
4092 struct intel_atomic_state
*state
=
4093 to_intel_atomic_state(ref_crtc_state
->uapi
.state
);
4097 if (INTEL_GEN(dev_priv
) < 11)
4100 if (!intel_crtc_has_type(ref_crtc_state
, INTEL_OUTPUT_DP
))
4103 for_each_new_connector_in_state(&state
->base
, connector
, conn_state
, i
) {
4104 struct intel_crtc
*crtc
= to_intel_crtc(conn_state
->crtc
);
4105 const struct intel_crtc_state
*crtc_state
;
4110 if (!connector
->has_tile
||
4111 connector
->tile_group
->id
!=
4114 crtc_state
= intel_atomic_get_new_crtc_state(state
,
4116 if (!crtcs_port_sync_compatible(ref_crtc_state
,
4119 transcoders
|= BIT(crtc_state
->cpu_transcoder
);
4125 static int intel_ddi_compute_config_late(struct intel_encoder
*encoder
,
4126 struct intel_crtc_state
*crtc_state
,
4127 struct drm_connector_state
*conn_state
)
4129 struct drm_connector
*connector
= conn_state
->connector
;
4130 u8 port_sync_transcoders
= 0;
4132 DRM_DEBUG_KMS("[ENCODER:%d:%s] [CRTC:%d:%s]",
4133 encoder
->base
.base
.id
, encoder
->base
.name
,
4134 crtc_state
->uapi
.crtc
->base
.id
, crtc_state
->uapi
.crtc
->name
);
4136 if (connector
->has_tile
)
4137 port_sync_transcoders
= intel_ddi_port_sync_transcoders(crtc_state
,
4138 connector
->tile_group
->id
);
4141 * EDP Transcoders cannot be ensalved
4142 * make them a master always when present
4144 if (port_sync_transcoders
& BIT(TRANSCODER_EDP
))
4145 crtc_state
->master_transcoder
= TRANSCODER_EDP
;
4147 crtc_state
->master_transcoder
= ffs(port_sync_transcoders
) - 1;
4149 if (crtc_state
->master_transcoder
== crtc_state
->cpu_transcoder
) {
4150 crtc_state
->master_transcoder
= INVALID_TRANSCODER
;
4151 crtc_state
->sync_mode_slaves_mask
=
4152 port_sync_transcoders
& ~BIT(crtc_state
->cpu_transcoder
);
4158 static void intel_ddi_encoder_destroy(struct drm_encoder
*encoder
)
4160 struct intel_digital_port
*dig_port
= enc_to_dig_port(to_intel_encoder(encoder
));
4162 intel_dp_encoder_flush_work(encoder
);
4164 drm_encoder_cleanup(encoder
);
4168 static const struct drm_encoder_funcs intel_ddi_funcs
= {
4169 .reset
= intel_dp_encoder_reset
,
4170 .destroy
= intel_ddi_encoder_destroy
,
4173 static struct intel_connector
*
4174 intel_ddi_init_dp_connector(struct intel_digital_port
*intel_dig_port
)
4176 struct intel_connector
*connector
;
4177 enum port port
= intel_dig_port
->base
.port
;
4179 connector
= intel_connector_alloc();
4183 intel_dig_port
->dp
.output_reg
= DDI_BUF_CTL(port
);
4184 intel_dig_port
->dp
.prepare_link_retrain
=
4185 intel_ddi_prepare_link_retrain
;
4187 if (!intel_dp_init_connector(intel_dig_port
, connector
)) {
4195 static int modeset_pipe(struct drm_crtc
*crtc
,
4196 struct drm_modeset_acquire_ctx
*ctx
)
4198 struct drm_atomic_state
*state
;
4199 struct drm_crtc_state
*crtc_state
;
4202 state
= drm_atomic_state_alloc(crtc
->dev
);
4206 state
->acquire_ctx
= ctx
;
4208 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
4209 if (IS_ERR(crtc_state
)) {
4210 ret
= PTR_ERR(crtc_state
);
4214 crtc_state
->connectors_changed
= true;
4216 ret
= drm_atomic_commit(state
);
4218 drm_atomic_state_put(state
);
4223 static int intel_hdmi_reset_link(struct intel_encoder
*encoder
,
4224 struct drm_modeset_acquire_ctx
*ctx
)
4226 struct drm_i915_private
*dev_priv
= to_i915(encoder
->base
.dev
);
4227 struct intel_hdmi
*hdmi
= enc_to_intel_hdmi(encoder
);
4228 struct intel_connector
*connector
= hdmi
->attached_connector
;
4229 struct i2c_adapter
*adapter
=
4230 intel_gmbus_get_adapter(dev_priv
, hdmi
->ddc_bus
);
4231 struct drm_connector_state
*conn_state
;
4232 struct intel_crtc_state
*crtc_state
;
4233 struct intel_crtc
*crtc
;
4237 if (!connector
|| connector
->base
.status
!= connector_status_connected
)
4240 ret
= drm_modeset_lock(&dev_priv
->drm
.mode_config
.connection_mutex
,
4245 conn_state
= connector
->base
.state
;
4247 crtc
= to_intel_crtc(conn_state
->crtc
);
4251 ret
= drm_modeset_lock(&crtc
->base
.mutex
, ctx
);
4255 crtc_state
= to_intel_crtc_state(crtc
->base
.state
);
4257 drm_WARN_ON(&dev_priv
->drm
,
4258 !intel_crtc_has_type(crtc_state
, INTEL_OUTPUT_HDMI
));
4260 if (!crtc_state
->hw
.active
)
4263 if (!crtc_state
->hdmi_high_tmds_clock_ratio
&&
4264 !crtc_state
->hdmi_scrambling
)
4267 if (conn_state
->commit
&&
4268 !try_wait_for_completion(&conn_state
->commit
->hw_done
))
4271 ret
= drm_scdc_readb(adapter
, SCDC_TMDS_CONFIG
, &config
);
4273 DRM_ERROR("Failed to read TMDS config: %d\n", ret
);
4277 if (!!(config
& SCDC_TMDS_BIT_CLOCK_RATIO_BY_40
) ==
4278 crtc_state
->hdmi_high_tmds_clock_ratio
&&
4279 !!(config
& SCDC_SCRAMBLING_ENABLE
) ==
4280 crtc_state
->hdmi_scrambling
)
4284 * HDMI 2.0 says that one should not send scrambled data
4285 * prior to configuring the sink scrambling, and that
4286 * TMDS clock/data transmission should be suspended when
4287 * changing the TMDS clock rate in the sink. So let's
4288 * just do a full modeset here, even though some sinks
4289 * would be perfectly happy if were to just reconfigure
4290 * the SCDC settings on the fly.
4292 return modeset_pipe(&crtc
->base
, ctx
);
4295 static enum intel_hotplug_state
4296 intel_ddi_hotplug(struct intel_encoder
*encoder
,
4297 struct intel_connector
*connector
,
4300 struct intel_digital_port
*dig_port
= enc_to_dig_port(encoder
);
4301 struct drm_modeset_acquire_ctx ctx
;
4302 enum intel_hotplug_state state
;
4305 state
= intel_encoder_hotplug(encoder
, connector
, irq_received
);
4307 drm_modeset_acquire_init(&ctx
, 0);
4310 if (connector
->base
.connector_type
== DRM_MODE_CONNECTOR_HDMIA
)
4311 ret
= intel_hdmi_reset_link(encoder
, &ctx
);
4313 ret
= intel_dp_retrain_link(encoder
, &ctx
);
4315 if (ret
== -EDEADLK
) {
4316 drm_modeset_backoff(&ctx
);
4323 drm_modeset_drop_locks(&ctx
);
4324 drm_modeset_acquire_fini(&ctx
);
4325 drm_WARN(encoder
->base
.dev
, ret
,
4326 "Acquiring modeset locks failed with %i\n", ret
);
4329 * Unpowered type-c dongles can take some time to boot and be
4330 * responsible, so here giving some time to those dongles to power up
4331 * and then retrying the probe.
4333 * On many platforms the HDMI live state signal is known to be
4334 * unreliable, so we can't use it to detect if a sink is connected or
4335 * not. Instead we detect if it's connected based on whether we can
4336 * read the EDID or not. That in turn has a problem during disconnect,
4337 * since the HPD interrupt may be raised before the DDC lines get
4338 * disconnected (due to how the required length of DDC vs. HPD
4339 * connector pins are specified) and so we'll still be able to get a
4340 * valid EDID. To solve this schedule another detection cycle if this
4341 * time around we didn't detect any change in the sink's connection
4344 if (state
== INTEL_HOTPLUG_UNCHANGED
&& irq_received
&&
4345 !dig_port
->dp
.is_mst
)
4346 state
= INTEL_HOTPLUG_RETRY
;
4351 static struct intel_connector
*
4352 intel_ddi_init_hdmi_connector(struct intel_digital_port
*intel_dig_port
)
4354 struct intel_connector
*connector
;
4355 enum port port
= intel_dig_port
->base
.port
;
4357 connector
= intel_connector_alloc();
4361 intel_dig_port
->hdmi
.hdmi_reg
= DDI_BUF_CTL(port
);
4362 intel_hdmi_init_connector(intel_dig_port
, connector
);
4367 static bool intel_ddi_a_force_4_lanes(struct intel_digital_port
*dport
)
4369 struct drm_i915_private
*dev_priv
= to_i915(dport
->base
.base
.dev
);
4371 if (dport
->base
.port
!= PORT_A
)
4374 if (dport
->saved_port_bits
& DDI_A_4_LANES
)
4377 /* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only
4378 * supported configuration
4380 if (IS_GEN9_LP(dev_priv
))
4383 /* Cannonlake: Most of SKUs don't support DDI_E, and the only
4384 * one who does also have a full A/E split called
4385 * DDI_F what makes DDI_E useless. However for this
4386 * case let's trust VBT info.
4388 if (IS_CANNONLAKE(dev_priv
) &&
4389 !intel_bios_is_port_present(dev_priv
, PORT_E
))
4396 intel_ddi_max_lanes(struct intel_digital_port
*intel_dport
)
4398 struct drm_i915_private
*dev_priv
= to_i915(intel_dport
->base
.base
.dev
);
4399 enum port port
= intel_dport
->base
.port
;
4402 if (INTEL_GEN(dev_priv
) >= 11)
4405 if (port
== PORT_A
|| port
== PORT_E
) {
4406 if (intel_de_read(dev_priv
, DDI_BUF_CTL(PORT_A
)) & DDI_A_4_LANES
)
4407 max_lanes
= port
== PORT_A
? 4 : 0;
4409 /* Both A and E share 2 lanes */
4414 * Some BIOS might fail to set this bit on port A if eDP
4415 * wasn't lit up at boot. Force this bit set when needed
4416 * so we use the proper lane count for our calculations.
4418 if (intel_ddi_a_force_4_lanes(intel_dport
)) {
4419 DRM_DEBUG_KMS("Forcing DDI_A_4_LANES for port A\n");
4420 intel_dport
->saved_port_bits
|= DDI_A_4_LANES
;
4427 void intel_ddi_init(struct drm_i915_private
*dev_priv
, enum port port
)
4429 struct intel_digital_port
*intel_dig_port
;
4430 struct intel_encoder
*encoder
;
4431 bool init_hdmi
, init_dp
, init_lspcon
= false;
4432 enum phy phy
= intel_port_to_phy(dev_priv
, port
);
4434 init_hdmi
= intel_bios_port_supports_dvi(dev_priv
, port
) ||
4435 intel_bios_port_supports_hdmi(dev_priv
, port
);
4436 init_dp
= intel_bios_port_supports_dp(dev_priv
, port
);
4438 if (intel_bios_is_lspcon_present(dev_priv
, port
)) {
4440 * Lspcon device needs to be driven with DP connector
4441 * with special detection sequence. So make sure DP
4442 * is initialized before lspcon.
4447 DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port
));
4450 if (!init_dp
&& !init_hdmi
) {
4451 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
4456 intel_dig_port
= kzalloc(sizeof(*intel_dig_port
), GFP_KERNEL
);
4457 if (!intel_dig_port
)
4460 encoder
= &intel_dig_port
->base
;
4462 drm_encoder_init(&dev_priv
->drm
, &encoder
->base
, &intel_ddi_funcs
,
4463 DRM_MODE_ENCODER_TMDS
, "DDI %c", port_name(port
));
4465 encoder
->hotplug
= intel_ddi_hotplug
;
4466 encoder
->compute_output_type
= intel_ddi_compute_output_type
;
4467 encoder
->compute_config
= intel_ddi_compute_config
;
4468 encoder
->compute_config_late
= intel_ddi_compute_config_late
;
4469 encoder
->enable
= intel_enable_ddi
;
4470 encoder
->pre_pll_enable
= intel_ddi_pre_pll_enable
;
4471 encoder
->pre_enable
= intel_ddi_pre_enable
;
4472 encoder
->disable
= intel_disable_ddi
;
4473 encoder
->post_disable
= intel_ddi_post_disable
;
4474 encoder
->update_pipe
= intel_ddi_update_pipe
;
4475 encoder
->get_hw_state
= intel_ddi_get_hw_state
;
4476 encoder
->get_config
= intel_ddi_get_config
;
4477 encoder
->suspend
= intel_dp_encoder_suspend
;
4478 encoder
->get_power_domains
= intel_ddi_get_power_domains
;
4480 encoder
->type
= INTEL_OUTPUT_DDI
;
4481 encoder
->power_domain
= intel_port_to_power_domain(port
);
4482 encoder
->port
= port
;
4483 encoder
->cloneable
= 0;
4484 encoder
->pipe_mask
= ~0;
4486 if (INTEL_GEN(dev_priv
) >= 11)
4487 intel_dig_port
->saved_port_bits
= intel_de_read(dev_priv
,
4488 DDI_BUF_CTL(port
)) &
4489 DDI_BUF_PORT_REVERSAL
;
4491 intel_dig_port
->saved_port_bits
= intel_de_read(dev_priv
,
4492 DDI_BUF_CTL(port
)) &
4493 (DDI_BUF_PORT_REVERSAL
| DDI_A_4_LANES
);
4495 intel_dig_port
->dp
.output_reg
= INVALID_MMIO_REG
;
4496 intel_dig_port
->max_lanes
= intel_ddi_max_lanes(intel_dig_port
);
4497 intel_dig_port
->aux_ch
= intel_bios_port_aux_ch(dev_priv
, port
);
4499 if (intel_phy_is_tc(dev_priv
, phy
)) {
4501 !intel_bios_port_supports_typec_usb(dev_priv
, port
) &&
4502 !intel_bios_port_supports_tbt(dev_priv
, port
);
4504 intel_tc_port_init(intel_dig_port
, is_legacy
);
4506 encoder
->update_prepare
= intel_ddi_update_prepare
;
4507 encoder
->update_complete
= intel_ddi_update_complete
;
4510 drm_WARN_ON(&dev_priv
->drm
, port
> PORT_I
);
4511 intel_dig_port
->ddi_io_power_domain
= POWER_DOMAIN_PORT_DDI_A_IO
+
4515 if (!intel_ddi_init_dp_connector(intel_dig_port
))
4518 intel_dig_port
->hpd_pulse
= intel_dp_hpd_pulse
;
4521 /* In theory we don't need the encoder->type check, but leave it just in
4522 * case we have some really bad VBTs... */
4523 if (encoder
->type
!= INTEL_OUTPUT_EDP
&& init_hdmi
) {
4524 if (!intel_ddi_init_hdmi_connector(intel_dig_port
))
4529 if (lspcon_init(intel_dig_port
))
4530 /* TODO: handle hdmi info frame part */
4531 DRM_DEBUG_KMS("LSPCON init success on port %c\n",
4535 * LSPCON init faied, but DP init was success, so
4536 * lets try to drive as DP++ port.
4538 DRM_ERROR("LSPCON init failed on port %c\n",
4542 intel_infoframe_init(intel_dig_port
);
4547 drm_encoder_cleanup(&encoder
->base
);
4548 kfree(intel_dig_port
);