]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/i915/intel_ddi.c
drm/i915: Introduce intel_ddi_dp_level.
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / i915 / intel_ddi.c
CommitLineData
45244b87
ED
1/*
2 * Copyright © 2012 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 *
26 */
27
28#include "i915_drv.h"
29#include "intel_drv.h"
30
10122051
JN
31struct ddi_buf_trans {
32 u32 trans1; /* balance leg enable, de-emph level */
33 u32 trans2; /* vref sel, vswing */
f8896f5d 34 u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */
10122051
JN
35};
36
97eeb872
VS
37static const u8 index_to_dp_signal_levels[] = {
38 [0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0,
39 [1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1,
40 [2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2,
41 [3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3,
42 [4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0,
43 [5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1,
44 [6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2,
45 [7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0,
46 [8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1,
47 [9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0,
48};
49
45244b87
ED
50/* HDMI/DVI modes ignore everything but the last 2 items. So we share
51 * them for both DP and FDI transports, allowing those ports to
52 * automatically adapt to HDMI connections as well
53 */
10122051 54static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
f8896f5d
DW
55 { 0x00FFFFFF, 0x0006000E, 0x0 },
56 { 0x00D75FFF, 0x0005000A, 0x0 },
57 { 0x00C30FFF, 0x00040006, 0x0 },
58 { 0x80AAAFFF, 0x000B0000, 0x0 },
59 { 0x00FFFFFF, 0x0005000A, 0x0 },
60 { 0x00D75FFF, 0x000C0004, 0x0 },
61 { 0x80C30FFF, 0x000B0000, 0x0 },
62 { 0x00FFFFFF, 0x00040006, 0x0 },
63 { 0x80D75FFF, 0x000B0000, 0x0 },
45244b87
ED
64};
65
10122051 66static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
f8896f5d
DW
67 { 0x00FFFFFF, 0x0007000E, 0x0 },
68 { 0x00D75FFF, 0x000F000A, 0x0 },
69 { 0x00C30FFF, 0x00060006, 0x0 },
70 { 0x00AAAFFF, 0x001E0000, 0x0 },
71 { 0x00FFFFFF, 0x000F000A, 0x0 },
72 { 0x00D75FFF, 0x00160004, 0x0 },
73 { 0x00C30FFF, 0x001E0000, 0x0 },
74 { 0x00FFFFFF, 0x00060006, 0x0 },
75 { 0x00D75FFF, 0x001E0000, 0x0 },
6acab15a
PZ
76};
77
10122051
JN
78static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
79 /* Idx NT mV d T mV d db */
f8896f5d
DW
80 { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */
81 { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */
82 { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */
83 { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */
84 { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */
85 { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */
86 { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */
87 { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */
88 { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */
89 { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */
90 { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */
91 { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */
45244b87
ED
92};
93
10122051 94static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
f8896f5d
DW
95 { 0x00FFFFFF, 0x00000012, 0x0 },
96 { 0x00EBAFFF, 0x00020011, 0x0 },
97 { 0x00C71FFF, 0x0006000F, 0x0 },
98 { 0x00AAAFFF, 0x000E000A, 0x0 },
99 { 0x00FFFFFF, 0x00020011, 0x0 },
100 { 0x00DB6FFF, 0x0005000F, 0x0 },
101 { 0x00BEEFFF, 0x000A000C, 0x0 },
102 { 0x00FFFFFF, 0x0005000F, 0x0 },
103 { 0x00DB6FFF, 0x000A000C, 0x0 },
300644c7
PZ
104};
105
10122051 106static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
f8896f5d
DW
107 { 0x00FFFFFF, 0x0007000E, 0x0 },
108 { 0x00D75FFF, 0x000E000A, 0x0 },
109 { 0x00BEFFFF, 0x00140006, 0x0 },
110 { 0x80B2CFFF, 0x001B0002, 0x0 },
111 { 0x00FFFFFF, 0x000E000A, 0x0 },
112 { 0x00DB6FFF, 0x00160005, 0x0 },
113 { 0x80C71FFF, 0x001A0002, 0x0 },
114 { 0x00F7DFFF, 0x00180004, 0x0 },
115 { 0x80D75FFF, 0x001B0002, 0x0 },
e58623cb
AR
116};
117
10122051 118static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
f8896f5d
DW
119 { 0x00FFFFFF, 0x0001000E, 0x0 },
120 { 0x00D75FFF, 0x0004000A, 0x0 },
121 { 0x00C30FFF, 0x00070006, 0x0 },
122 { 0x00AAAFFF, 0x000C0000, 0x0 },
123 { 0x00FFFFFF, 0x0004000A, 0x0 },
124 { 0x00D75FFF, 0x00090004, 0x0 },
125 { 0x00C30FFF, 0x000C0000, 0x0 },
126 { 0x00FFFFFF, 0x00070006, 0x0 },
127 { 0x00D75FFF, 0x000C0000, 0x0 },
e58623cb
AR
128};
129
10122051
JN
130static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
131 /* Idx NT mV d T mV df db */
f8896f5d
DW
132 { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */
133 { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */
134 { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */
135 { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */
136 { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */
137 { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */
138 { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */
139 { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */
140 { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */
141 { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */
a26aa8ba
DL
142};
143
5f8b2531 144/* Skylake H and S */
7f88e3af 145static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
f8896f5d
DW
146 { 0x00002016, 0x000000A0, 0x0 },
147 { 0x00005012, 0x0000009B, 0x0 },
148 { 0x00007011, 0x00000088, 0x0 },
d7097cff 149 { 0x80009010, 0x000000C0, 0x1 },
f8896f5d
DW
150 { 0x00002016, 0x0000009B, 0x0 },
151 { 0x00005012, 0x00000088, 0x0 },
d7097cff 152 { 0x80007011, 0x000000C0, 0x1 },
f8896f5d 153 { 0x00002016, 0x000000DF, 0x0 },
d7097cff 154 { 0x80005012, 0x000000C0, 0x1 },
7f88e3af
DL
155};
156
f8896f5d
DW
157/* Skylake U */
158static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
5f8b2531 159 { 0x0000201B, 0x000000A2, 0x0 },
f8896f5d 160 { 0x00005012, 0x00000088, 0x0 },
5ac90567 161 { 0x80007011, 0x000000CD, 0x1 },
d7097cff 162 { 0x80009010, 0x000000C0, 0x1 },
5f8b2531 163 { 0x0000201B, 0x0000009D, 0x0 },
d7097cff
RV
164 { 0x80005012, 0x000000C0, 0x1 },
165 { 0x80007011, 0x000000C0, 0x1 },
f8896f5d 166 { 0x00002016, 0x00000088, 0x0 },
d7097cff 167 { 0x80005012, 0x000000C0, 0x1 },
f8896f5d
DW
168};
169
5f8b2531
RV
170/* Skylake Y */
171static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
f8896f5d
DW
172 { 0x00000018, 0x000000A2, 0x0 },
173 { 0x00005012, 0x00000088, 0x0 },
5ac90567 174 { 0x80007011, 0x000000CD, 0x3 },
d7097cff 175 { 0x80009010, 0x000000C0, 0x3 },
f8896f5d 176 { 0x00000018, 0x0000009D, 0x0 },
d7097cff
RV
177 { 0x80005012, 0x000000C0, 0x3 },
178 { 0x80007011, 0x000000C0, 0x3 },
f8896f5d 179 { 0x00000018, 0x00000088, 0x0 },
d7097cff 180 { 0x80005012, 0x000000C0, 0x3 },
f8896f5d
DW
181};
182
0fdd4918
RV
183/* Kabylake H and S */
184static const struct ddi_buf_trans kbl_ddi_translations_dp[] = {
185 { 0x00002016, 0x000000A0, 0x0 },
186 { 0x00005012, 0x0000009B, 0x0 },
187 { 0x00007011, 0x00000088, 0x0 },
188 { 0x80009010, 0x000000C0, 0x1 },
189 { 0x00002016, 0x0000009B, 0x0 },
190 { 0x00005012, 0x00000088, 0x0 },
191 { 0x80007011, 0x000000C0, 0x1 },
192 { 0x00002016, 0x00000097, 0x0 },
193 { 0x80005012, 0x000000C0, 0x1 },
194};
195
196/* Kabylake U */
197static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = {
198 { 0x0000201B, 0x000000A1, 0x0 },
199 { 0x00005012, 0x00000088, 0x0 },
200 { 0x80007011, 0x000000CD, 0x3 },
201 { 0x80009010, 0x000000C0, 0x3 },
202 { 0x0000201B, 0x0000009D, 0x0 },
203 { 0x80005012, 0x000000C0, 0x3 },
204 { 0x80007011, 0x000000C0, 0x3 },
205 { 0x00002016, 0x0000004F, 0x0 },
206 { 0x80005012, 0x000000C0, 0x3 },
207};
208
209/* Kabylake Y */
210static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = {
211 { 0x00001017, 0x000000A1, 0x0 },
212 { 0x00005012, 0x00000088, 0x0 },
213 { 0x80007011, 0x000000CD, 0x3 },
214 { 0x8000800F, 0x000000C0, 0x3 },
215 { 0x00001017, 0x0000009D, 0x0 },
216 { 0x80005012, 0x000000C0, 0x3 },
217 { 0x80007011, 0x000000C0, 0x3 },
218 { 0x00001017, 0x0000004C, 0x0 },
219 { 0x80005012, 0x000000C0, 0x3 },
220};
221
f8896f5d 222/*
0fdd4918 223 * Skylake/Kabylake H and S
f8896f5d
DW
224 * eDP 1.4 low vswing translation parameters
225 */
7ad14a29 226static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
f8896f5d
DW
227 { 0x00000018, 0x000000A8, 0x0 },
228 { 0x00004013, 0x000000A9, 0x0 },
229 { 0x00007011, 0x000000A2, 0x0 },
230 { 0x00009010, 0x0000009C, 0x0 },
231 { 0x00000018, 0x000000A9, 0x0 },
232 { 0x00006013, 0x000000A2, 0x0 },
233 { 0x00007011, 0x000000A6, 0x0 },
234 { 0x00000018, 0x000000AB, 0x0 },
235 { 0x00007013, 0x0000009F, 0x0 },
236 { 0x00000018, 0x000000DF, 0x0 },
237};
238
239/*
0fdd4918 240 * Skylake/Kabylake U
f8896f5d
DW
241 * eDP 1.4 low vswing translation parameters
242 */
243static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
244 { 0x00000018, 0x000000A8, 0x0 },
245 { 0x00004013, 0x000000A9, 0x0 },
246 { 0x00007011, 0x000000A2, 0x0 },
247 { 0x00009010, 0x0000009C, 0x0 },
248 { 0x00000018, 0x000000A9, 0x0 },
249 { 0x00006013, 0x000000A2, 0x0 },
250 { 0x00007011, 0x000000A6, 0x0 },
251 { 0x00002016, 0x000000AB, 0x0 },
252 { 0x00005013, 0x0000009F, 0x0 },
253 { 0x00000018, 0x000000DF, 0x0 },
7ad14a29
SJ
254};
255
f8896f5d 256/*
0fdd4918 257 * Skylake/Kabylake Y
f8896f5d
DW
258 * eDP 1.4 low vswing translation parameters
259 */
5f8b2531 260static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
f8896f5d
DW
261 { 0x00000018, 0x000000A8, 0x0 },
262 { 0x00004013, 0x000000AB, 0x0 },
263 { 0x00007011, 0x000000A4, 0x0 },
264 { 0x00009010, 0x000000DF, 0x0 },
265 { 0x00000018, 0x000000AA, 0x0 },
266 { 0x00006013, 0x000000A4, 0x0 },
267 { 0x00007011, 0x0000009D, 0x0 },
268 { 0x00000018, 0x000000A0, 0x0 },
269 { 0x00006012, 0x000000DF, 0x0 },
270 { 0x00000018, 0x0000008A, 0x0 },
271};
7ad14a29 272
0fdd4918 273/* Skylake/Kabylake U, H and S */
7f88e3af 274static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
f8896f5d
DW
275 { 0x00000018, 0x000000AC, 0x0 },
276 { 0x00005012, 0x0000009D, 0x0 },
277 { 0x00007011, 0x00000088, 0x0 },
278 { 0x00000018, 0x000000A1, 0x0 },
279 { 0x00000018, 0x00000098, 0x0 },
280 { 0x00004013, 0x00000088, 0x0 },
2e78416e 281 { 0x80006012, 0x000000CD, 0x1 },
f8896f5d 282 { 0x00000018, 0x000000DF, 0x0 },
2e78416e
RV
283 { 0x80003015, 0x000000CD, 0x1 }, /* Default */
284 { 0x80003015, 0x000000C0, 0x1 },
285 { 0x80000018, 0x000000C0, 0x1 },
f8896f5d
DW
286};
287
0fdd4918 288/* Skylake/Kabylake Y */
5f8b2531 289static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
f8896f5d
DW
290 { 0x00000018, 0x000000A1, 0x0 },
291 { 0x00005012, 0x000000DF, 0x0 },
2e78416e 292 { 0x80007011, 0x000000CB, 0x3 },
f8896f5d
DW
293 { 0x00000018, 0x000000A4, 0x0 },
294 { 0x00000018, 0x0000009D, 0x0 },
295 { 0x00004013, 0x00000080, 0x0 },
2e78416e 296 { 0x80006013, 0x000000C0, 0x3 },
f8896f5d 297 { 0x00000018, 0x0000008A, 0x0 },
2e78416e
RV
298 { 0x80003015, 0x000000C0, 0x3 }, /* Default */
299 { 0x80003015, 0x000000C0, 0x3 },
300 { 0x80000018, 0x000000C0, 0x3 },
7f88e3af
DL
301};
302
96fb9f9b
VK
303struct bxt_ddi_buf_trans {
304 u32 margin; /* swing value */
305 u32 scale; /* scale value */
306 u32 enable; /* scale enable */
307 u32 deemphasis;
308 bool default_index; /* true if the entry represents default value */
309};
310
96fb9f9b
VK
311static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
312 /* Idx NT mV diff db */
fe4c63c8
ID
313 { 52, 0x9A, 0, 128, true }, /* 0: 400 0 */
314 { 78, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
315 { 104, 0x9A, 0, 64, false }, /* 2: 400 6 */
316 { 154, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
317 { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
318 { 116, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
319 { 154, 0x9A, 0, 64, false }, /* 6: 600 6 */
320 { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
321 { 154, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
f8896f5d 322 { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
96fb9f9b
VK
323};
324
d9d7000d
SJ
325static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
326 /* Idx NT mV diff db */
327 { 26, 0, 0, 128, false }, /* 0: 200 0 */
328 { 38, 0, 0, 112, false }, /* 1: 200 1.5 */
329 { 48, 0, 0, 96, false }, /* 2: 200 4 */
330 { 54, 0, 0, 69, false }, /* 3: 200 6 */
331 { 32, 0, 0, 128, false }, /* 4: 250 0 */
332 { 48, 0, 0, 104, false }, /* 5: 250 1.5 */
333 { 54, 0, 0, 85, false }, /* 6: 250 4 */
334 { 43, 0, 0, 128, false }, /* 7: 300 0 */
335 { 54, 0, 0, 101, false }, /* 8: 300 1.5 */
336 { 48, 0, 0, 128, false }, /* 9: 300 0 */
337};
338
96fb9f9b
VK
339/* BSpec has 2 recommended values - entries 0 and 8.
340 * Using the entry with higher vswing.
341 */
342static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
343 /* Idx NT mV diff db */
fe4c63c8
ID
344 { 52, 0x9A, 0, 128, false }, /* 0: 400 0 */
345 { 52, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
346 { 52, 0x9A, 0, 64, false }, /* 2: 400 6 */
347 { 42, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
348 { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
349 { 77, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
350 { 77, 0x9A, 0, 64, false }, /* 6: 600 6 */
351 { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
352 { 102, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
96fb9f9b
VK
353 { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
354};
355
83fb7ab4
RV
356struct cnl_ddi_buf_trans {
357 u32 dw2_swing_sel;
358 u32 dw7_n_scalar;
359 u32 dw4_cursor_coeff;
360 u32 dw4_post_cursor_2;
361 u32 dw4_post_cursor_1;
362};
363
364/* Voltage Swing Programming for VccIO 0.85V for DP */
365static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V[] = {
366 /* NT mV Trans mV db */
367 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
368 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
369 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
370 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
371 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
372 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
373 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
374 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
375 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
376 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
377};
378
379/* Voltage Swing Programming for VccIO 0.85V for HDMI */
380static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V[] = {
381 /* NT mV Trans mV db */
382 { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
383 { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */
384 { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */
385 { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 */
386 { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */
387 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */
388 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
389};
390
391/* Voltage Swing Programming for VccIO 0.85V for eDP */
392static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V[] = {
393 /* NT mV Trans mV db */
394 { 0xA, 0x66, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
395 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
396 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
397 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
398 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
399 { 0xA, 0x66, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
400 { 0xB, 0x70, 0x3C, 0x00, 0x03 }, /* 460 600 2.3 */
401 { 0xC, 0x75, 0x3C, 0x00, 0x03 }, /* 537 700 2.3 */
402 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
403};
404
405/* Voltage Swing Programming for VccIO 0.95V for DP */
406static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V[] = {
407 /* NT mV Trans mV db */
408 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
409 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
410 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
411 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
412 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
413 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
414 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
415 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
416 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
417 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
418};
419
420/* Voltage Swing Programming for VccIO 0.95V for HDMI */
421static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V[] = {
422 /* NT mV Trans mV db */
423 { 0xA, 0x5C, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
424 { 0xB, 0x69, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
425 { 0x5, 0x76, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
426 { 0xA, 0x5E, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
427 { 0xB, 0x69, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
428 { 0xB, 0x79, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
429 { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
430 { 0x5, 0x76, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
431 { 0x6, 0x7D, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
432 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
433 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
434};
435
436/* Voltage Swing Programming for VccIO 0.95V for eDP */
437static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V[] = {
438 /* NT mV Trans mV db */
439 { 0xA, 0x61, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
440 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
441 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
442 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
443 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
444 { 0xA, 0x61, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
445 { 0xB, 0x68, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
446 { 0xC, 0x6E, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
447 { 0x4, 0x7F, 0x3A, 0x00, 0x05 }, /* 460 600 2.3 */
448 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
449};
450
451/* Voltage Swing Programming for VccIO 1.05V for DP */
452static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V[] = {
453 /* NT mV Trans mV db */
454 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
455 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
456 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
457 { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 400 1050 8.4 */
458 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
459 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
460 { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 550 1050 5.6 */
461 { 0x5, 0x76, 0x3E, 0x00, 0x01 }, /* 850 900 0.5 */
462 { 0x6, 0x7F, 0x36, 0x00, 0x09 }, /* 750 1050 2.9 */
463 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
464};
465
466/* Voltage Swing Programming for VccIO 1.05V for HDMI */
467static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V[] = {
468 /* NT mV Trans mV db */
469 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
470 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
471 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
472 { 0xA, 0x5B, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
473 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
474 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
475 { 0x6, 0x7C, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
476 { 0x5, 0x70, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
477 { 0x6, 0x7C, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
478 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
479 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
480};
481
482/* Voltage Swing Programming for VccIO 1.05V for eDP */
483static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V[] = {
484 /* NT mV Trans mV db */
485 { 0xA, 0x5E, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
486 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
487 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
488 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
489 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
490 { 0xA, 0x5E, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
491 { 0xB, 0x64, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
492 { 0xE, 0x6A, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
493 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
494};
495
5a5d24dc 496enum port intel_ddi_get_encoder_port(struct intel_encoder *encoder)
fc914639 497{
5a5d24dc 498 switch (encoder->type) {
8cd21b7f 499 case INTEL_OUTPUT_DP_MST:
5a5d24dc 500 return enc_to_mst(&encoder->base)->primary->port;
cca0502b 501 case INTEL_OUTPUT_DP:
8cd21b7f
JN
502 case INTEL_OUTPUT_EDP:
503 case INTEL_OUTPUT_HDMI:
504 case INTEL_OUTPUT_UNKNOWN:
5a5d24dc 505 return enc_to_dig_port(&encoder->base)->port;
8cd21b7f 506 case INTEL_OUTPUT_ANALOG:
5a5d24dc
VS
507 return PORT_E;
508 default:
509 MISSING_CASE(encoder->type);
510 return PORT_A;
fc914639
PZ
511 }
512}
513
a930acd9
VS
514static const struct ddi_buf_trans *
515bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
516{
517 if (dev_priv->vbt.edp.low_vswing) {
518 *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
519 return bdw_ddi_translations_edp;
520 } else {
521 *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
522 return bdw_ddi_translations_dp;
523 }
524}
525
acee2998 526static const struct ddi_buf_trans *
78ab0bae 527skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
f8896f5d 528{
0fdd4918 529 if (IS_SKL_ULX(dev_priv)) {
5f8b2531 530 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
acee2998 531 return skl_y_ddi_translations_dp;
0fdd4918 532 } else if (IS_SKL_ULT(dev_priv)) {
f8896f5d 533 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
acee2998 534 return skl_u_ddi_translations_dp;
f8896f5d 535 } else {
f8896f5d 536 *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
acee2998 537 return skl_ddi_translations_dp;
f8896f5d 538 }
f8896f5d
DW
539}
540
0fdd4918
RV
541static const struct ddi_buf_trans *
542kbl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
543{
544 if (IS_KBL_ULX(dev_priv)) {
545 *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp);
546 return kbl_y_ddi_translations_dp;
da411a48 547 } else if (IS_KBL_ULT(dev_priv) || IS_CFL_ULT(dev_priv)) {
0fdd4918
RV
548 *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
549 return kbl_u_ddi_translations_dp;
550 } else {
551 *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
552 return kbl_ddi_translations_dp;
553 }
554}
555
acee2998 556static const struct ddi_buf_trans *
78ab0bae 557skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
f8896f5d 558{
06411f08 559 if (dev_priv->vbt.edp.low_vswing) {
78ab0bae 560 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
5f8b2531 561 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
acee2998 562 return skl_y_ddi_translations_edp;
da411a48
RV
563 } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv) ||
564 IS_CFL_ULT(dev_priv)) {
f8896f5d 565 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
acee2998 566 return skl_u_ddi_translations_edp;
f8896f5d 567 } else {
f8896f5d 568 *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
acee2998 569 return skl_ddi_translations_edp;
f8896f5d
DW
570 }
571 }
cd1101cb 572
da411a48 573 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
0fdd4918
RV
574 return kbl_get_buf_trans_dp(dev_priv, n_entries);
575 else
576 return skl_get_buf_trans_dp(dev_priv, n_entries);
f8896f5d
DW
577}
578
579static const struct ddi_buf_trans *
78ab0bae 580skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
f8896f5d 581{
78ab0bae 582 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
5f8b2531 583 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
acee2998 584 return skl_y_ddi_translations_hdmi;
f8896f5d 585 } else {
f8896f5d 586 *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
acee2998 587 return skl_ddi_translations_hdmi;
f8896f5d 588 }
f8896f5d
DW
589}
590
8d8bb85e
VS
591static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
592{
593 int n_hdmi_entries;
594 int hdmi_level;
595 int hdmi_default_entry;
596
597 hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
598
cc3f90f0 599 if (IS_GEN9_LP(dev_priv))
8d8bb85e
VS
600 return hdmi_level;
601
b976dc53 602 if (IS_GEN9_BC(dev_priv)) {
8d8bb85e
VS
603 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
604 hdmi_default_entry = 8;
605 } else if (IS_BROADWELL(dev_priv)) {
606 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
607 hdmi_default_entry = 7;
608 } else if (IS_HASWELL(dev_priv)) {
609 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
610 hdmi_default_entry = 6;
611 } else {
612 WARN(1, "ddi translation table missing\n");
613 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
614 hdmi_default_entry = 7;
615 }
616
617 /* Choose a good default if VBT is badly populated */
618 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
619 hdmi_level >= n_hdmi_entries)
620 hdmi_level = hdmi_default_entry;
621
622 return hdmi_level;
623}
624
7d1c42e6
VS
625static const struct ddi_buf_trans *
626intel_ddi_get_buf_trans_dp(struct drm_i915_private *dev_priv,
627 int *n_entries)
628{
da411a48 629 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
7d1c42e6
VS
630 return kbl_get_buf_trans_dp(dev_priv, n_entries);
631 } else if (IS_SKYLAKE(dev_priv)) {
632 return skl_get_buf_trans_dp(dev_priv, n_entries);
633 } else if (IS_BROADWELL(dev_priv)) {
634 *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
635 return bdw_ddi_translations_dp;
636 } else if (IS_HASWELL(dev_priv)) {
637 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
638 return hsw_ddi_translations_dp;
639 }
640
641 *n_entries = 0;
642 return NULL;
643}
644
645static const struct ddi_buf_trans *
646intel_ddi_get_buf_trans_edp(struct drm_i915_private *dev_priv,
647 int *n_entries)
648{
da411a48 649 if (IS_GEN9_BC(dev_priv)) {
7d1c42e6
VS
650 return skl_get_buf_trans_edp(dev_priv, n_entries);
651 } else if (IS_BROADWELL(dev_priv)) {
652 return bdw_get_buf_trans_edp(dev_priv, n_entries);
653 } else if (IS_HASWELL(dev_priv)) {
654 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
655 return hsw_ddi_translations_dp;
656 }
657
658 *n_entries = 0;
659 return NULL;
660}
661
662static const struct ddi_buf_trans *
663intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv,
664 int *n_entries)
665{
666 if (IS_BROADWELL(dev_priv)) {
667 *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
668 return hsw_ddi_translations_fdi;
669 } else if (IS_HASWELL(dev_priv)) {
670 *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
671 return hsw_ddi_translations_fdi;
672 }
673
674 *n_entries = 0;
675 return NULL;
676}
677
e58623cb
AR
678/*
679 * Starting with Haswell, DDI port buffers must be programmed with correct
32bdc400
VS
680 * values in advance. This function programs the correct values for
681 * DP/eDP/FDI use cases.
45244b87 682 */
d7c530b2 683static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder)
45244b87 684{
6a7e4f99 685 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
75067dde 686 u32 iboost_bit = 0;
7d1c42e6 687 int i, n_entries;
32bdc400 688 enum port port = intel_ddi_get_encoder_port(encoder);
10122051 689 const struct ddi_buf_trans *ddi_translations;
e58623cb 690
cc3f90f0 691 if (IS_GEN9_LP(dev_priv))
96fb9f9b 692 return;
6a7e4f99 693
7d1c42e6
VS
694 switch (encoder->type) {
695 case INTEL_OUTPUT_EDP:
696 ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv,
697 &n_entries);
698 break;
699 case INTEL_OUTPUT_DP:
700 ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv,
701 &n_entries);
702 break;
703 case INTEL_OUTPUT_ANALOG:
704 ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
705 &n_entries);
706 break;
707 default:
708 MISSING_CASE(encoder->type);
709 return;
e58623cb
AR
710 }
711
b976dc53 712 if (IS_GEN9_BC(dev_priv)) {
0a91877c
RV
713 /* If we're boosting the current, set bit 31 of trans1 */
714 if (dev_priv->vbt.ddi_port_info[port].dp_boost_level)
715 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
716
717 if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
718 port != PORT_A && port != PORT_E &&
7d1c42e6
VS
719 n_entries > 9))
720 n_entries = 9;
300644c7 721 }
45244b87 722
7d1c42e6 723 for (i = 0; i < n_entries; i++) {
9712e688
VS
724 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
725 ddi_translations[i].trans1 | iboost_bit);
726 I915_WRITE(DDI_BUF_TRANS_HI(port, i),
727 ddi_translations[i].trans2);
45244b87 728 }
32bdc400
VS
729}
730
731/*
732 * Starting with Haswell, DDI port buffers must be programmed with correct
733 * values in advance. This function programs the correct values for
734 * HDMI/DVI use cases.
735 */
736static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder)
737{
738 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
739 u32 iboost_bit = 0;
740 int n_hdmi_entries, hdmi_level;
741 enum port port = intel_ddi_get_encoder_port(encoder);
742 const struct ddi_buf_trans *ddi_translations_hdmi;
ce4dd49e 743
cc3f90f0 744 if (IS_GEN9_LP(dev_priv))
ce3b7e9b
DL
745 return;
746
32bdc400
VS
747 hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
748
b976dc53 749 if (IS_GEN9_BC(dev_priv)) {
32bdc400 750 ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
1edaaa2f 751
32bdc400 752 /* If we're boosting the current, set bit 31 of trans1 */
1edaaa2f 753 if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
32bdc400
VS
754 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
755 } else if (IS_BROADWELL(dev_priv)) {
756 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
757 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
758 } else if (IS_HASWELL(dev_priv)) {
759 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
760 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
761 } else {
762 WARN(1, "ddi translation table missing\n");
763 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
764 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
765 }
766
6acab15a 767 /* Entry 9 is for HDMI: */
ed9c77d2 768 I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
9712e688 769 ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
ed9c77d2 770 I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
9712e688 771 ddi_translations_hdmi[hdmi_level].trans2);
45244b87
ED
772}
773
248138b5
PZ
774static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
775 enum port port)
776{
f0f59a00 777 i915_reg_t reg = DDI_BUF_CTL(port);
248138b5
PZ
778 int i;
779
3449ca85 780 for (i = 0; i < 16; i++) {
248138b5
PZ
781 udelay(1);
782 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
783 return;
784 }
785 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
786}
c82e4d26 787
5f88a9c6 788static uint32_t hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll)
c856052a
ACO
789{
790 switch (pll->id) {
791 case DPLL_ID_WRPLL1:
792 return PORT_CLK_SEL_WRPLL1;
793 case DPLL_ID_WRPLL2:
794 return PORT_CLK_SEL_WRPLL2;
795 case DPLL_ID_SPLL:
796 return PORT_CLK_SEL_SPLL;
797 case DPLL_ID_LCPLL_810:
798 return PORT_CLK_SEL_LCPLL_810;
799 case DPLL_ID_LCPLL_1350:
800 return PORT_CLK_SEL_LCPLL_1350;
801 case DPLL_ID_LCPLL_2700:
802 return PORT_CLK_SEL_LCPLL_2700;
803 default:
804 MISSING_CASE(pll->id);
805 return PORT_CLK_SEL_NONE;
806 }
807}
808
c82e4d26
ED
809/* Starting with Haswell, different DDI ports can work in FDI mode for
810 * connection to the PCH-located connectors. For this, it is necessary to train
811 * both the DDI port and PCH receiver for the desired DDI buffer settings.
812 *
813 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
814 * please note that when FDI mode is active on DDI E, it shares 2 lines with
815 * DDI A (which is used for eDP)
816 */
817
dc4a1094
ACO
818void hsw_fdi_link_train(struct intel_crtc *crtc,
819 const struct intel_crtc_state *crtc_state)
c82e4d26 820{
4cbe4b2b 821 struct drm_device *dev = crtc->base.dev;
fac5e23e 822 struct drm_i915_private *dev_priv = to_i915(dev);
6a7e4f99 823 struct intel_encoder *encoder;
c856052a 824 u32 temp, i, rx_ctl_val, ddi_pll_sel;
c82e4d26 825
4cbe4b2b 826 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
6a7e4f99 827 WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
32bdc400 828 intel_prepare_dp_ddi_buffers(encoder);
6a7e4f99
VS
829 }
830
04945641
PZ
831 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
832 * mode set "sequence for CRT port" document:
833 * - TP1 to TP2 time with the default value
834 * - FDI delay to 90h
8693a824
DL
835 *
836 * WaFDIAutoLinkSetTimingOverrride:hsw
04945641 837 */
eede3b53 838 I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
04945641
PZ
839 FDI_RX_PWRDN_LANE0_VAL(2) |
840 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
841
842 /* Enable the PCH Receiver FDI PLL */
3e68320e 843 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
33d29b14 844 FDI_RX_PLL_ENABLE |
dc4a1094 845 FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
eede3b53
VS
846 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
847 POSTING_READ(FDI_RX_CTL(PIPE_A));
04945641
PZ
848 udelay(220);
849
850 /* Switch from Rawclk to PCDclk */
851 rx_ctl_val |= FDI_PCDCLK;
eede3b53 852 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
04945641
PZ
853
854 /* Configure Port Clock Select */
dc4a1094 855 ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll);
c856052a
ACO
856 I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
857 WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
04945641
PZ
858
859 /* Start the training iterating through available voltages and emphasis,
860 * testing each value twice. */
10122051 861 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
c82e4d26
ED
862 /* Configure DP_TP_CTL with auto-training */
863 I915_WRITE(DP_TP_CTL(PORT_E),
864 DP_TP_CTL_FDI_AUTOTRAIN |
865 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
866 DP_TP_CTL_LINK_TRAIN_PAT1 |
867 DP_TP_CTL_ENABLE);
868
876a8cdf
DL
869 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
870 * DDI E does not support port reversal, the functionality is
871 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
872 * port reversal bit */
c82e4d26 873 I915_WRITE(DDI_BUF_CTL(PORT_E),
04945641 874 DDI_BUF_CTL_ENABLE |
dc4a1094 875 ((crtc_state->fdi_lanes - 1) << 1) |
c5fe6a06 876 DDI_BUF_TRANS_SELECT(i / 2));
04945641 877 POSTING_READ(DDI_BUF_CTL(PORT_E));
c82e4d26
ED
878
879 udelay(600);
880
04945641 881 /* Program PCH FDI Receiver TU */
eede3b53 882 I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
04945641
PZ
883
884 /* Enable PCH FDI Receiver with auto-training */
885 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
eede3b53
VS
886 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
887 POSTING_READ(FDI_RX_CTL(PIPE_A));
04945641
PZ
888
889 /* Wait for FDI receiver lane calibration */
890 udelay(30);
891
892 /* Unset FDI_RX_MISC pwrdn lanes */
eede3b53 893 temp = I915_READ(FDI_RX_MISC(PIPE_A));
04945641 894 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
eede3b53
VS
895 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
896 POSTING_READ(FDI_RX_MISC(PIPE_A));
04945641
PZ
897
898 /* Wait for FDI auto training time */
899 udelay(5);
c82e4d26
ED
900
901 temp = I915_READ(DP_TP_STATUS(PORT_E));
902 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
04945641 903 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
a308ccb3
VS
904 break;
905 }
c82e4d26 906
a308ccb3
VS
907 /*
908 * Leave things enabled even if we failed to train FDI.
909 * Results in less fireworks from the state checker.
910 */
911 if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
912 DRM_ERROR("FDI link training failed!\n");
913 break;
c82e4d26 914 }
04945641 915
5b421c57
VS
916 rx_ctl_val &= ~FDI_RX_ENABLE;
917 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
918 POSTING_READ(FDI_RX_CTL(PIPE_A));
919
248138b5
PZ
920 temp = I915_READ(DDI_BUF_CTL(PORT_E));
921 temp &= ~DDI_BUF_CTL_ENABLE;
922 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
923 POSTING_READ(DDI_BUF_CTL(PORT_E));
924
04945641 925 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
248138b5
PZ
926 temp = I915_READ(DP_TP_CTL(PORT_E));
927 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
928 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
929 I915_WRITE(DP_TP_CTL(PORT_E), temp);
930 POSTING_READ(DP_TP_CTL(PORT_E));
931
932 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
04945641 933
04945641 934 /* Reset FDI_RX_MISC pwrdn lanes */
eede3b53 935 temp = I915_READ(FDI_RX_MISC(PIPE_A));
04945641
PZ
936 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
937 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
eede3b53
VS
938 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
939 POSTING_READ(FDI_RX_MISC(PIPE_A));
c82e4d26
ED
940 }
941
a308ccb3
VS
942 /* Enable normal pixel sending for FDI */
943 I915_WRITE(DP_TP_CTL(PORT_E),
944 DP_TP_CTL_FDI_AUTOTRAIN |
945 DP_TP_CTL_LINK_TRAIN_NORMAL |
946 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
947 DP_TP_CTL_ENABLE);
c82e4d26 948}
0e72a5b5 949
d7c530b2 950static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
44905a27
DA
951{
952 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
953 struct intel_digital_port *intel_dig_port =
954 enc_to_dig_port(&encoder->base);
955
956 intel_dp->DP = intel_dig_port->saved_port_bits |
c5fe6a06 957 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
901c2daf 958 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
44905a27
DA
959}
960
8d9ddbcb 961static struct intel_encoder *
e9ce1a62 962intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
8d9ddbcb 963{
e9ce1a62 964 struct drm_device *dev = crtc->base.dev;
1524e93e 965 struct intel_encoder *encoder, *ret = NULL;
8d9ddbcb
PZ
966 int num_encoders = 0;
967
1524e93e
SS
968 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
969 ret = encoder;
8d9ddbcb
PZ
970 num_encoders++;
971 }
972
973 if (num_encoders != 1)
84f44ce7 974 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
e9ce1a62 975 pipe_name(crtc->pipe));
8d9ddbcb
PZ
976
977 BUG_ON(ret == NULL);
978 return ret;
979}
980
44a126ba
PZ
981/* Finds the only possible encoder associated with the given CRTC. */
982struct intel_encoder *
3165c074 983intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
d0737e1d 984{
3165c074
ACO
985 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
986 struct intel_encoder *ret = NULL;
987 struct drm_atomic_state *state;
da3ced29
ACO
988 struct drm_connector *connector;
989 struct drm_connector_state *connector_state;
d0737e1d 990 int num_encoders = 0;
3165c074 991 int i;
d0737e1d 992
3165c074
ACO
993 state = crtc_state->base.state;
994
b77c7a90 995 for_each_new_connector_in_state(state, connector, connector_state, i) {
da3ced29 996 if (connector_state->crtc != crtc_state->base.crtc)
3165c074
ACO
997 continue;
998
da3ced29 999 ret = to_intel_encoder(connector_state->best_encoder);
3165c074 1000 num_encoders++;
d0737e1d
ACO
1001 }
1002
1003 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
1004 pipe_name(crtc->pipe));
1005
1006 BUG_ON(ret == NULL);
1007 return ret;
1008}
1009
1c0b85c5 1010#define LC_FREQ 2700
1c0b85c5 1011
f0f59a00
VS
1012static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
1013 i915_reg_t reg)
11578553
JB
1014{
1015 int refclk = LC_FREQ;
1016 int n, p, r;
1017 u32 wrpll;
1018
1019 wrpll = I915_READ(reg);
114fe488
DV
1020 switch (wrpll & WRPLL_PLL_REF_MASK) {
1021 case WRPLL_PLL_SSC:
1022 case WRPLL_PLL_NON_SSC:
11578553
JB
1023 /*
1024 * We could calculate spread here, but our checking
1025 * code only cares about 5% accuracy, and spread is a max of
1026 * 0.5% downspread.
1027 */
1028 refclk = 135;
1029 break;
114fe488 1030 case WRPLL_PLL_LCPLL:
11578553
JB
1031 refclk = LC_FREQ;
1032 break;
1033 default:
1034 WARN(1, "bad wrpll refclk\n");
1035 return 0;
1036 }
1037
1038 r = wrpll & WRPLL_DIVIDER_REF_MASK;
1039 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
1040 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
1041
20f0ec16
JB
1042 /* Convert to KHz, p & r have a fixed point portion */
1043 return (refclk * n * 100) / (p * r);
11578553
JB
1044}
1045
540e732c
S
1046static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
1047 uint32_t dpll)
1048{
f0f59a00 1049 i915_reg_t cfgcr1_reg, cfgcr2_reg;
540e732c
S
1050 uint32_t cfgcr1_val, cfgcr2_val;
1051 uint32_t p0, p1, p2, dco_freq;
1052
923c1241
VS
1053 cfgcr1_reg = DPLL_CFGCR1(dpll);
1054 cfgcr2_reg = DPLL_CFGCR2(dpll);
540e732c
S
1055
1056 cfgcr1_val = I915_READ(cfgcr1_reg);
1057 cfgcr2_val = I915_READ(cfgcr2_reg);
1058
1059 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
1060 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
1061
1062 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
1063 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
1064 else
1065 p1 = 1;
1066
1067
1068 switch (p0) {
1069 case DPLL_CFGCR2_PDIV_1:
1070 p0 = 1;
1071 break;
1072 case DPLL_CFGCR2_PDIV_2:
1073 p0 = 2;
1074 break;
1075 case DPLL_CFGCR2_PDIV_3:
1076 p0 = 3;
1077 break;
1078 case DPLL_CFGCR2_PDIV_7:
1079 p0 = 7;
1080 break;
1081 }
1082
1083 switch (p2) {
1084 case DPLL_CFGCR2_KDIV_5:
1085 p2 = 5;
1086 break;
1087 case DPLL_CFGCR2_KDIV_2:
1088 p2 = 2;
1089 break;
1090 case DPLL_CFGCR2_KDIV_3:
1091 p2 = 3;
1092 break;
1093 case DPLL_CFGCR2_KDIV_1:
1094 p2 = 1;
1095 break;
1096 }
1097
1098 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
1099
1100 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
1101 1000) / 0x8000;
1102
1103 return dco_freq / (p0 * p1 * p2 * 5);
1104}
1105
a9701a89
RV
1106static int cnl_calc_wrpll_link(struct drm_i915_private *dev_priv,
1107 uint32_t pll_id)
1108{
1109 uint32_t cfgcr0, cfgcr1;
1110 uint32_t p0, p1, p2, dco_freq, ref_clock;
1111
1112 cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
1113 cfgcr1 = I915_READ(CNL_DPLL_CFGCR1(pll_id));
1114
1115 p0 = cfgcr1 & DPLL_CFGCR1_PDIV_MASK;
1116 p2 = cfgcr1 & DPLL_CFGCR1_KDIV_MASK;
1117
1118 if (cfgcr1 & DPLL_CFGCR1_QDIV_MODE(1))
1119 p1 = (cfgcr1 & DPLL_CFGCR1_QDIV_RATIO_MASK) >>
1120 DPLL_CFGCR1_QDIV_RATIO_SHIFT;
1121 else
1122 p1 = 1;
1123
1124
1125 switch (p0) {
1126 case DPLL_CFGCR1_PDIV_2:
1127 p0 = 2;
1128 break;
1129 case DPLL_CFGCR1_PDIV_3:
1130 p0 = 3;
1131 break;
1132 case DPLL_CFGCR1_PDIV_5:
1133 p0 = 5;
1134 break;
1135 case DPLL_CFGCR1_PDIV_7:
1136 p0 = 7;
1137 break;
1138 }
1139
1140 switch (p2) {
1141 case DPLL_CFGCR1_KDIV_1:
1142 p2 = 1;
1143 break;
1144 case DPLL_CFGCR1_KDIV_2:
1145 p2 = 2;
1146 break;
1147 case DPLL_CFGCR1_KDIV_4:
1148 p2 = 4;
1149 break;
1150 }
1151
1152 ref_clock = dev_priv->cdclk.hw.ref;
1153
1154 dco_freq = (cfgcr0 & DPLL_CFGCR0_DCO_INTEGER_MASK) * ref_clock;
1155
1156 dco_freq += (((cfgcr0 & DPLL_CFGCR0_DCO_FRACTION_MASK) >>
1157 DPLL_CFGCR0_DCO_FRAC_SHIFT) * ref_clock) / 0x8000;
1158
1159 return dco_freq / (p0 * p1 * p2 * 5);
1160}
1161
398a017e
VS
1162static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
1163{
1164 int dotclock;
1165
1166 if (pipe_config->has_pch_encoder)
1167 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1168 &pipe_config->fdi_m_n);
37a5650b 1169 else if (intel_crtc_has_dp_encoder(pipe_config))
398a017e
VS
1170 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1171 &pipe_config->dp_m_n);
1172 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
1173 dotclock = pipe_config->port_clock * 2 / 3;
1174 else
1175 dotclock = pipe_config->port_clock;
1176
b22ca995
SS
1177 if (pipe_config->ycbcr420)
1178 dotclock *= 2;
1179
398a017e
VS
1180 if (pipe_config->pixel_multiplier)
1181 dotclock /= pipe_config->pixel_multiplier;
1182
1183 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
1184}
540e732c 1185
a9701a89
RV
1186static void cnl_ddi_clock_get(struct intel_encoder *encoder,
1187 struct intel_crtc_state *pipe_config)
1188{
1189 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1190 int link_clock = 0;
1191 uint32_t cfgcr0, pll_id;
1192
1193 pll_id = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
1194
1195 cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
1196
1197 if (cfgcr0 & DPLL_CFGCR0_HDMI_MODE) {
1198 link_clock = cnl_calc_wrpll_link(dev_priv, pll_id);
1199 } else {
1200 link_clock = cfgcr0 & DPLL_CFGCR0_LINK_RATE_MASK;
1201
1202 switch (link_clock) {
1203 case DPLL_CFGCR0_LINK_RATE_810:
1204 link_clock = 81000;
1205 break;
1206 case DPLL_CFGCR0_LINK_RATE_1080:
1207 link_clock = 108000;
1208 break;
1209 case DPLL_CFGCR0_LINK_RATE_1350:
1210 link_clock = 135000;
1211 break;
1212 case DPLL_CFGCR0_LINK_RATE_1620:
1213 link_clock = 162000;
1214 break;
1215 case DPLL_CFGCR0_LINK_RATE_2160:
1216 link_clock = 216000;
1217 break;
1218 case DPLL_CFGCR0_LINK_RATE_2700:
1219 link_clock = 270000;
1220 break;
1221 case DPLL_CFGCR0_LINK_RATE_3240:
1222 link_clock = 324000;
1223 break;
1224 case DPLL_CFGCR0_LINK_RATE_4050:
1225 link_clock = 405000;
1226 break;
1227 default:
1228 WARN(1, "Unsupported link rate\n");
1229 break;
1230 }
1231 link_clock *= 2;
1232 }
1233
1234 pipe_config->port_clock = link_clock;
1235
1236 ddi_dotclock_get(pipe_config);
1237}
1238
540e732c 1239static void skl_ddi_clock_get(struct intel_encoder *encoder,
5cec258b 1240 struct intel_crtc_state *pipe_config)
540e732c 1241{
fac5e23e 1242 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
540e732c
S
1243 int link_clock = 0;
1244 uint32_t dpll_ctl1, dpll;
1245
c856052a 1246 dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
540e732c
S
1247
1248 dpll_ctl1 = I915_READ(DPLL_CTRL1);
1249
1250 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
1251 link_clock = skl_calc_wrpll_link(dev_priv, dpll);
1252 } else {
71cd8423
DL
1253 link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
1254 link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
540e732c
S
1255
1256 switch (link_clock) {
71cd8423 1257 case DPLL_CTRL1_LINK_RATE_810:
540e732c
S
1258 link_clock = 81000;
1259 break;
71cd8423 1260 case DPLL_CTRL1_LINK_RATE_1080:
a8f3ef61
SJ
1261 link_clock = 108000;
1262 break;
71cd8423 1263 case DPLL_CTRL1_LINK_RATE_1350:
540e732c
S
1264 link_clock = 135000;
1265 break;
71cd8423 1266 case DPLL_CTRL1_LINK_RATE_1620:
a8f3ef61
SJ
1267 link_clock = 162000;
1268 break;
71cd8423 1269 case DPLL_CTRL1_LINK_RATE_2160:
a8f3ef61
SJ
1270 link_clock = 216000;
1271 break;
71cd8423 1272 case DPLL_CTRL1_LINK_RATE_2700:
540e732c
S
1273 link_clock = 270000;
1274 break;
1275 default:
1276 WARN(1, "Unsupported link rate\n");
1277 break;
1278 }
1279 link_clock *= 2;
1280 }
1281
1282 pipe_config->port_clock = link_clock;
1283
398a017e 1284 ddi_dotclock_get(pipe_config);
540e732c
S
1285}
1286
3d51278a 1287static void hsw_ddi_clock_get(struct intel_encoder *encoder,
5cec258b 1288 struct intel_crtc_state *pipe_config)
11578553 1289{
fac5e23e 1290 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
11578553
JB
1291 int link_clock = 0;
1292 u32 val, pll;
1293
c856052a 1294 val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
11578553
JB
1295 switch (val & PORT_CLK_SEL_MASK) {
1296 case PORT_CLK_SEL_LCPLL_810:
1297 link_clock = 81000;
1298 break;
1299 case PORT_CLK_SEL_LCPLL_1350:
1300 link_clock = 135000;
1301 break;
1302 case PORT_CLK_SEL_LCPLL_2700:
1303 link_clock = 270000;
1304 break;
1305 case PORT_CLK_SEL_WRPLL1:
01403de3 1306 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
11578553
JB
1307 break;
1308 case PORT_CLK_SEL_WRPLL2:
01403de3 1309 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
11578553
JB
1310 break;
1311 case PORT_CLK_SEL_SPLL:
1312 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
1313 if (pll == SPLL_PLL_FREQ_810MHz)
1314 link_clock = 81000;
1315 else if (pll == SPLL_PLL_FREQ_1350MHz)
1316 link_clock = 135000;
1317 else if (pll == SPLL_PLL_FREQ_2700MHz)
1318 link_clock = 270000;
1319 else {
1320 WARN(1, "bad spll freq\n");
1321 return;
1322 }
1323 break;
1324 default:
1325 WARN(1, "bad port clock sel\n");
1326 return;
1327 }
1328
1329 pipe_config->port_clock = link_clock * 2;
1330
398a017e 1331 ddi_dotclock_get(pipe_config);
11578553
JB
1332}
1333
977bb38d
S
1334static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
1335 enum intel_dpll_id dpll)
1336{
aa610dcb
ID
1337 struct intel_shared_dpll *pll;
1338 struct intel_dpll_hw_state *state;
9e2c8475 1339 struct dpll clock;
aa610dcb
ID
1340
1341 /* For DDI ports we always use a shared PLL. */
1342 if (WARN_ON(dpll == DPLL_ID_PRIVATE))
1343 return 0;
1344
1345 pll = &dev_priv->shared_dplls[dpll];
2c42e535 1346 state = &pll->state.hw_state;
aa610dcb
ID
1347
1348 clock.m1 = 2;
1349 clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
1350 if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
1351 clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
1352 clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
1353 clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
1354 clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
1355
1356 return chv_calc_dpll_params(100000, &clock);
977bb38d
S
1357}
1358
1359static void bxt_ddi_clock_get(struct intel_encoder *encoder,
1360 struct intel_crtc_state *pipe_config)
1361{
fac5e23e 1362 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
977bb38d
S
1363 enum port port = intel_ddi_get_encoder_port(encoder);
1364 uint32_t dpll = port;
1365
398a017e 1366 pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
977bb38d 1367
398a017e 1368 ddi_dotclock_get(pipe_config);
977bb38d
S
1369}
1370
3d51278a 1371void intel_ddi_clock_get(struct intel_encoder *encoder,
5cec258b 1372 struct intel_crtc_state *pipe_config)
3d51278a 1373{
0853723b 1374 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
22606a18 1375
0853723b 1376 if (INTEL_GEN(dev_priv) <= 8)
22606a18 1377 hsw_ddi_clock_get(encoder, pipe_config);
b976dc53 1378 else if (IS_GEN9_BC(dev_priv))
22606a18 1379 skl_ddi_clock_get(encoder, pipe_config);
cc3f90f0 1380 else if (IS_GEN9_LP(dev_priv))
977bb38d 1381 bxt_ddi_clock_get(encoder, pipe_config);
a9701a89
RV
1382 else if (IS_CANNONLAKE(dev_priv))
1383 cnl_ddi_clock_get(encoder, pipe_config);
3d51278a
DV
1384}
1385
3dc38eea 1386void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
dae84799 1387{
3dc38eea 1388 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
e9ce1a62 1389 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1524e93e 1390 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
3dc38eea 1391 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1524e93e 1392 int type = encoder->type;
dae84799
PZ
1393 uint32_t temp;
1394
cca0502b 1395 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
4d1de975
JN
1396 WARN_ON(transcoder_is_dsi(cpu_transcoder));
1397
c9809791 1398 temp = TRANS_MSA_SYNC_CLK;
3dc38eea 1399 switch (crtc_state->pipe_bpp) {
dae84799 1400 case 18:
c9809791 1401 temp |= TRANS_MSA_6_BPC;
dae84799
PZ
1402 break;
1403 case 24:
c9809791 1404 temp |= TRANS_MSA_8_BPC;
dae84799
PZ
1405 break;
1406 case 30:
c9809791 1407 temp |= TRANS_MSA_10_BPC;
dae84799
PZ
1408 break;
1409 case 36:
c9809791 1410 temp |= TRANS_MSA_12_BPC;
dae84799
PZ
1411 break;
1412 default:
4e53c2e0 1413 BUG();
dae84799 1414 }
c9809791 1415 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
dae84799
PZ
1416 }
1417}
1418
3dc38eea
ACO
1419void intel_ddi_set_vc_payload_alloc(const struct intel_crtc_state *crtc_state,
1420 bool state)
0e32b39c 1421{
3dc38eea 1422 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
e9ce1a62 1423 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3dc38eea 1424 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
0e32b39c
DA
1425 uint32_t temp;
1426 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1427 if (state == true)
1428 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1429 else
1430 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1431 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1432}
1433
3dc38eea 1434void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state)
8d9ddbcb 1435{
3dc38eea 1436 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1524e93e 1437 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
e9ce1a62
ACO
1438 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1439 enum pipe pipe = crtc->pipe;
3dc38eea 1440 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1524e93e
SS
1441 enum port port = intel_ddi_get_encoder_port(encoder);
1442 int type = encoder->type;
8d9ddbcb
PZ
1443 uint32_t temp;
1444
ad80a810
PZ
1445 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1446 temp = TRANS_DDI_FUNC_ENABLE;
174edf1f 1447 temp |= TRANS_DDI_SELECT_PORT(port);
dfcef252 1448
3dc38eea 1449 switch (crtc_state->pipe_bpp) {
dfcef252 1450 case 18:
ad80a810 1451 temp |= TRANS_DDI_BPC_6;
dfcef252
PZ
1452 break;
1453 case 24:
ad80a810 1454 temp |= TRANS_DDI_BPC_8;
dfcef252
PZ
1455 break;
1456 case 30:
ad80a810 1457 temp |= TRANS_DDI_BPC_10;
dfcef252
PZ
1458 break;
1459 case 36:
ad80a810 1460 temp |= TRANS_DDI_BPC_12;
dfcef252
PZ
1461 break;
1462 default:
4e53c2e0 1463 BUG();
dfcef252 1464 }
72662e10 1465
3dc38eea 1466 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
ad80a810 1467 temp |= TRANS_DDI_PVSYNC;
3dc38eea 1468 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
ad80a810 1469 temp |= TRANS_DDI_PHSYNC;
f63eb7c4 1470
e6f0bfc4
PZ
1471 if (cpu_transcoder == TRANSCODER_EDP) {
1472 switch (pipe) {
1473 case PIPE_A:
c7670b10
PZ
1474 /* On Haswell, can only use the always-on power well for
1475 * eDP when not using the panel fitter, and when not
1476 * using motion blur mitigation (which we don't
1477 * support). */
772c2a51 1478 if (IS_HASWELL(dev_priv) &&
3dc38eea
ACO
1479 (crtc_state->pch_pfit.enabled ||
1480 crtc_state->pch_pfit.force_thru))
d6dd9eb1
DV
1481 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1482 else
1483 temp |= TRANS_DDI_EDP_INPUT_A_ON;
e6f0bfc4
PZ
1484 break;
1485 case PIPE_B:
1486 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1487 break;
1488 case PIPE_C:
1489 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1490 break;
1491 default:
1492 BUG();
1493 break;
1494 }
1495 }
1496
7739c33b 1497 if (type == INTEL_OUTPUT_HDMI) {
3dc38eea 1498 if (crtc_state->has_hdmi_sink)
ad80a810 1499 temp |= TRANS_DDI_MODE_SELECT_HDMI;
8d9ddbcb 1500 else
ad80a810 1501 temp |= TRANS_DDI_MODE_SELECT_DVI;
15953637
SS
1502
1503 if (crtc_state->hdmi_scrambling)
1504 temp |= TRANS_DDI_HDMI_SCRAMBLING_MASK;
1505 if (crtc_state->hdmi_high_tmds_clock_ratio)
1506 temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
7739c33b 1507 } else if (type == INTEL_OUTPUT_ANALOG) {
ad80a810 1508 temp |= TRANS_DDI_MODE_SELECT_FDI;
3dc38eea 1509 temp |= (crtc_state->fdi_lanes - 1) << 1;
cca0502b 1510 } else if (type == INTEL_OUTPUT_DP ||
7739c33b 1511 type == INTEL_OUTPUT_EDP) {
64ee2fd2 1512 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
3dc38eea 1513 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
0e32b39c 1514 } else if (type == INTEL_OUTPUT_DP_MST) {
64ee2fd2 1515 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
3dc38eea 1516 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
8d9ddbcb 1517 } else {
84f44ce7 1518 WARN(1, "Invalid encoder type %d for pipe %c\n",
1524e93e 1519 encoder->type, pipe_name(pipe));
8d9ddbcb
PZ
1520 }
1521
ad80a810 1522 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
8d9ddbcb 1523}
72662e10 1524
ad80a810
PZ
1525void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1526 enum transcoder cpu_transcoder)
8d9ddbcb 1527{
f0f59a00 1528 i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
8d9ddbcb
PZ
1529 uint32_t val = I915_READ(reg);
1530
0e32b39c 1531 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
ad80a810 1532 val |= TRANS_DDI_PORT_NONE;
8d9ddbcb 1533 I915_WRITE(reg, val);
72662e10
ED
1534}
1535
bcbc889b
PZ
1536bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1537{
1538 struct drm_device *dev = intel_connector->base.dev;
fac5e23e 1539 struct drm_i915_private *dev_priv = to_i915(dev);
1524e93e 1540 struct intel_encoder *encoder = intel_connector->encoder;
bcbc889b 1541 int type = intel_connector->base.connector_type;
1524e93e 1542 enum port port = intel_ddi_get_encoder_port(encoder);
bcbc889b
PZ
1543 enum pipe pipe = 0;
1544 enum transcoder cpu_transcoder;
1545 uint32_t tmp;
e27daab4 1546 bool ret;
bcbc889b 1547
79f255a0 1548 if (!intel_display_power_get_if_enabled(dev_priv,
1524e93e 1549 encoder->power_domain))
882244a3
PZ
1550 return false;
1551
1524e93e 1552 if (!encoder->get_hw_state(encoder, &pipe)) {
e27daab4
ID
1553 ret = false;
1554 goto out;
1555 }
bcbc889b
PZ
1556
1557 if (port == PORT_A)
1558 cpu_transcoder = TRANSCODER_EDP;
1559 else
1a240d4d 1560 cpu_transcoder = (enum transcoder) pipe;
bcbc889b
PZ
1561
1562 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1563
1564 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1565 case TRANS_DDI_MODE_SELECT_HDMI:
1566 case TRANS_DDI_MODE_SELECT_DVI:
e27daab4
ID
1567 ret = type == DRM_MODE_CONNECTOR_HDMIA;
1568 break;
bcbc889b
PZ
1569
1570 case TRANS_DDI_MODE_SELECT_DP_SST:
e27daab4
ID
1571 ret = type == DRM_MODE_CONNECTOR_eDP ||
1572 type == DRM_MODE_CONNECTOR_DisplayPort;
1573 break;
1574
0e32b39c
DA
1575 case TRANS_DDI_MODE_SELECT_DP_MST:
1576 /* if the transcoder is in MST state then
1577 * connector isn't connected */
e27daab4
ID
1578 ret = false;
1579 break;
bcbc889b
PZ
1580
1581 case TRANS_DDI_MODE_SELECT_FDI:
e27daab4
ID
1582 ret = type == DRM_MODE_CONNECTOR_VGA;
1583 break;
bcbc889b
PZ
1584
1585 default:
e27daab4
ID
1586 ret = false;
1587 break;
bcbc889b 1588 }
e27daab4
ID
1589
1590out:
1524e93e 1591 intel_display_power_put(dev_priv, encoder->power_domain);
e27daab4
ID
1592
1593 return ret;
bcbc889b
PZ
1594}
1595
85234cdc
DV
1596bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1597 enum pipe *pipe)
1598{
1599 struct drm_device *dev = encoder->base.dev;
fac5e23e 1600 struct drm_i915_private *dev_priv = to_i915(dev);
fe43d3f5 1601 enum port port = intel_ddi_get_encoder_port(encoder);
85234cdc
DV
1602 u32 tmp;
1603 int i;
e27daab4 1604 bool ret;
85234cdc 1605
79f255a0
ACO
1606 if (!intel_display_power_get_if_enabled(dev_priv,
1607 encoder->power_domain))
6d129bea
ID
1608 return false;
1609
e27daab4
ID
1610 ret = false;
1611
fe43d3f5 1612 tmp = I915_READ(DDI_BUF_CTL(port));
85234cdc
DV
1613
1614 if (!(tmp & DDI_BUF_CTL_ENABLE))
e27daab4 1615 goto out;
85234cdc 1616
ad80a810
PZ
1617 if (port == PORT_A) {
1618 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
85234cdc 1619
ad80a810
PZ
1620 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1621 case TRANS_DDI_EDP_INPUT_A_ON:
1622 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1623 *pipe = PIPE_A;
1624 break;
1625 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1626 *pipe = PIPE_B;
1627 break;
1628 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1629 *pipe = PIPE_C;
1630 break;
1631 }
1632
e27daab4 1633 ret = true;
ad80a810 1634
e27daab4
ID
1635 goto out;
1636 }
0e32b39c 1637
e27daab4
ID
1638 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1639 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1640
1641 if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
1642 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
1643 TRANS_DDI_MODE_SELECT_DP_MST)
1644 goto out;
1645
1646 *pipe = i;
1647 ret = true;
1648
1649 goto out;
85234cdc
DV
1650 }
1651 }
1652
84f44ce7 1653 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
85234cdc 1654
e27daab4 1655out:
cc3f90f0 1656 if (ret && IS_GEN9_LP(dev_priv)) {
e93da0a0
ID
1657 tmp = I915_READ(BXT_PHY_CTL(port));
1658 if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK |
1659 BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
1660 DRM_ERROR("Port %c enabled but PHY powered down? "
1661 "(PHY_CTL %08x)\n", port_name(port), tmp);
1662 }
1663
79f255a0 1664 intel_display_power_put(dev_priv, encoder->power_domain);
e27daab4
ID
1665
1666 return ret;
85234cdc
DV
1667}
1668
62b69566
ACO
1669static u64 intel_ddi_get_power_domains(struct intel_encoder *encoder)
1670{
1671 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
1672 enum pipe pipe;
1673
1674 if (intel_ddi_get_hw_state(encoder, &pipe))
1675 return BIT_ULL(dig_port->ddi_io_power_domain);
1676
1677 return 0;
1678}
1679
3dc38eea 1680void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state)
fc914639 1681{
3dc38eea 1682 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
e9ce1a62 1683 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1524e93e
SS
1684 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
1685 enum port port = intel_ddi_get_encoder_port(encoder);
3dc38eea 1686 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
fc914639 1687
bb523fc0
PZ
1688 if (cpu_transcoder != TRANSCODER_EDP)
1689 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1690 TRANS_CLK_SEL_PORT(port));
fc914639
PZ
1691}
1692
3dc38eea 1693void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
fc914639 1694{
3dc38eea
ACO
1695 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1696 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
fc914639 1697
bb523fc0
PZ
1698 if (cpu_transcoder != TRANSCODER_EDP)
1699 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1700 TRANS_CLK_SEL_DISABLED);
fc914639
PZ
1701}
1702
a7d8dbc0
VS
1703static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1704 enum port port, uint8_t iboost)
f8896f5d 1705{
a7d8dbc0
VS
1706 u32 tmp;
1707
1708 tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
1709 tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
1710 if (iboost)
1711 tmp |= iboost << BALANCE_LEG_SHIFT(port);
1712 else
1713 tmp |= BALANCE_LEG_DISABLE(port);
1714 I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
1715}
1716
1717static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
1718{
1719 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
1720 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
1721 enum port port = intel_dig_port->port;
1722 int type = encoder->type;
f8896f5d
DW
1723 const struct ddi_buf_trans *ddi_translations;
1724 uint8_t iboost;
75067dde 1725 uint8_t dp_iboost, hdmi_iboost;
f8896f5d 1726 int n_entries;
f8896f5d 1727
75067dde
AK
1728 /* VBT may override standard boost values */
1729 dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
1730 hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
1731
cca0502b 1732 if (type == INTEL_OUTPUT_DP) {
75067dde
AK
1733 if (dp_iboost) {
1734 iboost = dp_iboost;
1735 } else {
da411a48 1736 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
0fdd4918
RV
1737 ddi_translations = kbl_get_buf_trans_dp(dev_priv,
1738 &n_entries);
1739 else
1740 ddi_translations = skl_get_buf_trans_dp(dev_priv,
1741 &n_entries);
e4d4c05b 1742 iboost = ddi_translations[level].i_boost;
75067dde 1743 }
f8896f5d 1744 } else if (type == INTEL_OUTPUT_EDP) {
75067dde
AK
1745 if (dp_iboost) {
1746 iboost = dp_iboost;
1747 } else {
78ab0bae 1748 ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
10afa0b6
VS
1749
1750 if (WARN_ON(port != PORT_A &&
1751 port != PORT_E && n_entries > 9))
1752 n_entries = 9;
1753
e4d4c05b 1754 iboost = ddi_translations[level].i_boost;
75067dde 1755 }
f8896f5d 1756 } else if (type == INTEL_OUTPUT_HDMI) {
75067dde
AK
1757 if (hdmi_iboost) {
1758 iboost = hdmi_iboost;
1759 } else {
78ab0bae 1760 ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
e4d4c05b 1761 iboost = ddi_translations[level].i_boost;
75067dde 1762 }
f8896f5d
DW
1763 } else {
1764 return;
1765 }
1766
1767 /* Make sure that the requested I_boost is valid */
1768 if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
1769 DRM_ERROR("Invalid I_boost value %u\n", iboost);
1770 return;
1771 }
1772
a7d8dbc0 1773 _skl_ddi_set_iboost(dev_priv, port, iboost);
f8896f5d 1774
a7d8dbc0
VS
1775 if (port == PORT_A && intel_dig_port->max_lanes == 4)
1776 _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
f8896f5d
DW
1777}
1778
78ab0bae
VS
1779static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
1780 u32 level, enum port port, int type)
96fb9f9b 1781{
96fb9f9b
VK
1782 const struct bxt_ddi_buf_trans *ddi_translations;
1783 u32 n_entries, i;
96fb9f9b 1784
06411f08 1785 if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
d9d7000d
SJ
1786 n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
1787 ddi_translations = bxt_ddi_translations_edp;
cca0502b 1788 } else if (type == INTEL_OUTPUT_DP
d9d7000d 1789 || type == INTEL_OUTPUT_EDP) {
96fb9f9b
VK
1790 n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
1791 ddi_translations = bxt_ddi_translations_dp;
1792 } else if (type == INTEL_OUTPUT_HDMI) {
1793 n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
1794 ddi_translations = bxt_ddi_translations_hdmi;
1795 } else {
1796 DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
1797 type);
1798 return;
1799 }
1800
1801 /* Check if default value has to be used */
1802 if (level >= n_entries ||
1803 (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
1804 for (i = 0; i < n_entries; i++) {
1805 if (ddi_translations[i].default_index) {
1806 level = i;
1807 break;
1808 }
1809 }
1810 }
1811
b6e08203
ACO
1812 bxt_ddi_phy_set_signal_level(dev_priv, port,
1813 ddi_translations[level].margin,
1814 ddi_translations[level].scale,
1815 ddi_translations[level].enable,
1816 ddi_translations[level].deemphasis);
96fb9f9b
VK
1817}
1818
ffe5111e
VS
1819u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder)
1820{
1821 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1822 int n_entries;
1823
1824 if (encoder->type == INTEL_OUTPUT_EDP)
1825 intel_ddi_get_buf_trans_edp(dev_priv, &n_entries);
1826 else
1827 intel_ddi_get_buf_trans_dp(dev_priv, &n_entries);
1828
1829 if (WARN_ON(n_entries < 1))
1830 n_entries = 1;
1831 if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
1832 n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
1833
1834 return index_to_dp_signal_levels[n_entries - 1] &
1835 DP_TRAIN_VOLTAGE_SWING_MASK;
1836}
1837
cf54ca8b
RV
1838static const struct cnl_ddi_buf_trans *
1839cnl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv,
1840 u32 voltage, int *n_entries)
1841{
1842 if (voltage == VOLTAGE_INFO_0_85V) {
1843 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V);
1844 return cnl_ddi_translations_hdmi_0_85V;
1845 } else if (voltage == VOLTAGE_INFO_0_95V) {
1846 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V);
1847 return cnl_ddi_translations_hdmi_0_95V;
1848 } else if (voltage == VOLTAGE_INFO_1_05V) {
1849 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V);
1850 return cnl_ddi_translations_hdmi_1_05V;
1851 }
1852 return NULL;
1853}
1854
1855static const struct cnl_ddi_buf_trans *
1856cnl_get_buf_trans_dp(struct drm_i915_private *dev_priv,
1857 u32 voltage, int *n_entries)
1858{
1859 if (voltage == VOLTAGE_INFO_0_85V) {
1860 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V);
1861 return cnl_ddi_translations_dp_0_85V;
1862 } else if (voltage == VOLTAGE_INFO_0_95V) {
1863 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V);
1864 return cnl_ddi_translations_dp_0_95V;
1865 } else if (voltage == VOLTAGE_INFO_1_05V) {
1866 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V);
1867 return cnl_ddi_translations_dp_1_05V;
1868 }
1869 return NULL;
1870}
1871
1872static const struct cnl_ddi_buf_trans *
1873cnl_get_buf_trans_edp(struct drm_i915_private *dev_priv,
1874 u32 voltage, int *n_entries)
1875{
1876 if (dev_priv->vbt.edp.low_vswing) {
1877 if (voltage == VOLTAGE_INFO_0_85V) {
1878 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V);
50946c89 1879 return cnl_ddi_translations_edp_0_85V;
cf54ca8b
RV
1880 } else if (voltage == VOLTAGE_INFO_0_95V) {
1881 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V);
1882 return cnl_ddi_translations_edp_0_95V;
1883 } else if (voltage == VOLTAGE_INFO_1_05V) {
1884 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V);
1885 return cnl_ddi_translations_edp_1_05V;
1886 }
1887 return NULL;
1888 } else {
1889 return cnl_get_buf_trans_dp(dev_priv, voltage, n_entries);
1890 }
1891}
1892
1893static void cnl_ddi_vswing_program(struct drm_i915_private *dev_priv,
1894 u32 level, enum port port, int type)
1895{
1896 const struct cnl_ddi_buf_trans *ddi_translations = NULL;
1897 u32 n_entries, val, voltage;
1898 int ln;
1899
1900 /*
1901 * Values for each port type are listed in
1902 * voltage swing programming tables.
1903 * Vccio voltage found in PORT_COMP_DW3.
1904 */
1905 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
1906
1907 if (type == INTEL_OUTPUT_HDMI) {
1908 ddi_translations = cnl_get_buf_trans_hdmi(dev_priv,
1909 voltage, &n_entries);
1910 } else if (type == INTEL_OUTPUT_DP) {
1911 ddi_translations = cnl_get_buf_trans_dp(dev_priv,
1912 voltage, &n_entries);
1913 } else if (type == INTEL_OUTPUT_EDP) {
1914 ddi_translations = cnl_get_buf_trans_edp(dev_priv,
1915 voltage, &n_entries);
1916 }
1917
1918 if (ddi_translations == NULL) {
1919 MISSING_CASE(voltage);
1920 return;
1921 }
1922
1923 if (level >= n_entries) {
1924 DRM_DEBUG_KMS("DDI translation not found for level %d. Using %d instead.", level, n_entries - 1);
1925 level = n_entries - 1;
1926 }
1927
1928 /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */
1929 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
1f588aeb 1930 val &= ~SCALING_MODE_SEL_MASK;
cf54ca8b
RV
1931 val |= SCALING_MODE_SEL(2);
1932 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
1933
1934 /* Program PORT_TX_DW2 */
1935 val = I915_READ(CNL_PORT_TX_DW2_LN0(port));
1f588aeb
RV
1936 val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
1937 RCOMP_SCALAR_MASK);
cf54ca8b
RV
1938 val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
1939 val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
1940 /* Rcomp scalar is fixed as 0x98 for every table entry */
1941 val |= RCOMP_SCALAR(0x98);
1942 I915_WRITE(CNL_PORT_TX_DW2_GRP(port), val);
1943
1944 /* Program PORT_TX_DW4 */
1945 /* We cannot write to GRP. It would overrite individual loadgen */
1946 for (ln = 0; ln < 4; ln++) {
1947 val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
1f588aeb
RV
1948 val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
1949 CURSOR_COEFF_MASK);
cf54ca8b
RV
1950 val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
1951 val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
1952 val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
1953 I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
1954 }
1955
1956 /* Program PORT_TX_DW5 */
1957 /* All DW5 values are fixed for every table entry */
1958 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
1f588aeb 1959 val &= ~RTERM_SELECT_MASK;
cf54ca8b
RV
1960 val |= RTERM_SELECT(6);
1961 val |= TAP3_DISABLE;
1962 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
1963
1964 /* Program PORT_TX_DW7 */
1965 val = I915_READ(CNL_PORT_TX_DW7_LN0(port));
1f588aeb 1966 val &= ~N_SCALAR_MASK;
cf54ca8b
RV
1967 val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
1968 I915_WRITE(CNL_PORT_TX_DW7_GRP(port), val);
1969}
1970
0091abc3 1971static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder, u32 level)
cf54ca8b 1972{
0091abc3
CT
1973 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1974 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1975 enum port port = intel_ddi_get_encoder_port(encoder);
1976 int type = encoder->type;
1977 int width = 0;
1978 int rate = 0;
cf54ca8b 1979 u32 val;
0091abc3
CT
1980 int ln = 0;
1981
1982 if ((intel_dp) && (type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP)) {
1983 width = intel_dp->lane_count;
1984 rate = intel_dp->link_rate;
61f3e770 1985 } else if (type == INTEL_OUTPUT_HDMI) {
0091abc3
CT
1986 width = 4;
1987 /* Rate is always < than 6GHz for HDMI */
61f3e770
RV
1988 } else {
1989 MISSING_CASE(type);
1990 return;
0091abc3 1991 }
cf54ca8b
RV
1992
1993 /*
1994 * 1. If port type is eDP or DP,
1995 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
1996 * else clear to 0b.
1997 */
1998 val = I915_READ(CNL_PORT_PCS_DW1_LN0(port));
1999 if (type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP)
2000 val |= COMMON_KEEPER_EN;
2001 else
2002 val &= ~COMMON_KEEPER_EN;
2003 I915_WRITE(CNL_PORT_PCS_DW1_GRP(port), val);
2004
2005 /* 2. Program loadgen select */
2006 /*
0091abc3
CT
2007 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
2008 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
2009 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
2010 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
cf54ca8b 2011 */
0091abc3
CT
2012 for (ln = 0; ln <= 3; ln++) {
2013 val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
2014 val &= ~LOADGEN_SELECT;
2015
a8e45a1c
NM
2016 if ((rate <= 600000 && width == 4 && ln >= 1) ||
2017 (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
0091abc3
CT
2018 val |= LOADGEN_SELECT;
2019 }
2020 I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
2021 }
cf54ca8b
RV
2022
2023 /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
2024 val = I915_READ(CNL_PORT_CL1CM_DW5);
2025 val |= SUS_CLOCK_CONFIG;
2026 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2027
2028 /* 4. Clear training enable to change swing values */
2029 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
2030 val &= ~TX_TRAINING_EN;
2031 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
2032
2033 /* 5. Program swing and de-emphasis */
2034 cnl_ddi_vswing_program(dev_priv, level, port, type);
2035
2036 /* 6. Set training enable to trigger update */
2037 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
2038 val |= TX_TRAINING_EN;
2039 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
2040}
2041
f8896f5d
DW
2042static uint32_t translate_signal_level(int signal_levels)
2043{
97eeb872 2044 int i;
f8896f5d 2045
97eeb872
VS
2046 for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
2047 if (index_to_dp_signal_levels[i] == signal_levels)
2048 return i;
f8896f5d
DW
2049 }
2050
97eeb872
VS
2051 WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
2052 signal_levels);
2053
2054 return 0;
f8896f5d
DW
2055}
2056
1b6e2fd2
RV
2057static uint32_t intel_ddi_dp_level(struct intel_dp *intel_dp)
2058{
2059 uint8_t train_set = intel_dp->train_set[0];
2060 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2061 DP_TRAIN_PRE_EMPHASIS_MASK);
2062
2063 return translate_signal_level(signal_levels);
2064}
2065
f8896f5d
DW
2066uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
2067{
2068 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
78ab0bae 2069 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
f8896f5d 2070 struct intel_encoder *encoder = &dport->base;
f8896f5d 2071 enum port port = dport->port;
1b6e2fd2 2072 uint32_t level = intel_ddi_dp_level(intel_dp);
f8896f5d 2073
b976dc53 2074 if (IS_GEN9_BC(dev_priv))
a7d8dbc0 2075 skl_ddi_set_iboost(encoder, level);
cc3f90f0 2076 else if (IS_GEN9_LP(dev_priv))
78ab0bae 2077 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
cf54ca8b 2078 else if (IS_CANNONLAKE(dev_priv)) {
0091abc3 2079 cnl_ddi_vswing_sequence(encoder, level);
cf54ca8b
RV
2080 /* DDI_BUF_CTL bits 27:24 are reserved on CNL */
2081 return 0;
2082 }
f8896f5d
DW
2083 return DDI_BUF_TRANS_SELECT(level);
2084}
2085
d7c530b2 2086static void intel_ddi_clk_select(struct intel_encoder *encoder,
5f88a9c6 2087 const struct intel_shared_dpll *pll)
6441ab5f 2088{
e404ba8d
VS
2089 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2090 enum port port = intel_ddi_get_encoder_port(encoder);
555e38d2 2091 uint32_t val;
6441ab5f 2092
c856052a
ACO
2093 if (WARN_ON(!pll))
2094 return;
2095
555e38d2
RV
2096 if (IS_CANNONLAKE(dev_priv)) {
2097 /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */
2098 val = I915_READ(DPCLKA_CFGCR0);
2099 val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->id, port);
2100 I915_WRITE(DPCLKA_CFGCR0, val);
efa80add 2101
555e38d2
RV
2102 /*
2103 * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI.
2104 * This step and the step before must be done with separate
2105 * register writes.
2106 */
2107 val = I915_READ(DPCLKA_CFGCR0);
2108 val &= ~(DPCLKA_CFGCR0_DDI_CLK_OFF(port) |
2109 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port));
2110 I915_WRITE(DPCLKA_CFGCR0, val);
2111 } else if (IS_GEN9_BC(dev_priv)) {
5416d871 2112 /* DDI -> PLL mapping */
efa80add
S
2113 val = I915_READ(DPLL_CTRL2);
2114
2115 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
2116 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
c856052a 2117 val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
efa80add
S
2118 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
2119
2120 I915_WRITE(DPLL_CTRL2, val);
5416d871 2121
e404ba8d 2122 } else if (INTEL_INFO(dev_priv)->gen < 9) {
c856052a 2123 I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
efa80add 2124 }
e404ba8d
VS
2125}
2126
ba88d153
MN
2127static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
2128 int link_rate, uint32_t lane_count,
2129 struct intel_shared_dpll *pll,
2130 bool link_mst)
e404ba8d 2131{
ba88d153
MN
2132 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2133 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2134 enum port port = intel_ddi_get_encoder_port(encoder);
62b69566 2135 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
b2ccb822 2136
e081c846
ACO
2137 WARN_ON(link_mst && (port == PORT_A || port == PORT_E));
2138
ba88d153
MN
2139 intel_dp_set_link_params(intel_dp, link_rate, lane_count,
2140 link_mst);
2141 if (encoder->type == INTEL_OUTPUT_EDP)
e404ba8d 2142 intel_edp_panel_on(intel_dp);
32bdc400 2143
ba88d153 2144 intel_ddi_clk_select(encoder, pll);
62b69566
ACO
2145
2146 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
2147
ba88d153
MN
2148 intel_prepare_dp_ddi_buffers(encoder);
2149 intel_ddi_init_dp_buf_reg(encoder);
2150 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2151 intel_dp_start_link_train(intel_dp);
2152 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
2153 intel_dp_stop_link_train(intel_dp);
2154}
901c2daf 2155
ba88d153 2156static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
b47ef0f7 2157 bool has_infoframe,
ac240288
ML
2158 const struct intel_crtc_state *crtc_state,
2159 const struct drm_connector_state *conn_state,
5f88a9c6 2160 const struct intel_shared_dpll *pll)
ba88d153 2161{
f99be1b3
VS
2162 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
2163 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
ba88d153 2164 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
ba88d153
MN
2165 enum port port = intel_ddi_get_encoder_port(encoder);
2166 int level = intel_ddi_hdmi_level(dev_priv, port);
62b69566 2167 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
c19b0669 2168
ba88d153
MN
2169 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
2170 intel_ddi_clk_select(encoder, pll);
62b69566
ACO
2171
2172 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
2173
ba88d153 2174 intel_prepare_hdmi_ddi_buffers(encoder);
b976dc53 2175 if (IS_GEN9_BC(dev_priv))
ba88d153 2176 skl_ddi_set_iboost(encoder, level);
cc3f90f0 2177 else if (IS_GEN9_LP(dev_priv))
ba88d153
MN
2178 bxt_ddi_vswing_sequence(dev_priv, level, port,
2179 INTEL_OUTPUT_HDMI);
cf54ca8b 2180 else if (IS_CANNONLAKE(dev_priv))
0091abc3 2181 cnl_ddi_vswing_sequence(encoder, level);
8d8bb85e 2182
f99be1b3
VS
2183 intel_dig_port->set_infoframes(&encoder->base,
2184 has_infoframe,
2185 crtc_state, conn_state);
ba88d153 2186}
32bdc400 2187
1524e93e 2188static void intel_ddi_pre_enable(struct intel_encoder *encoder,
5f88a9c6
VS
2189 const struct intel_crtc_state *pipe_config,
2190 const struct drm_connector_state *conn_state)
ba88d153 2191{
1524e93e 2192 int type = encoder->type;
30cf6db8 2193
ba88d153 2194 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
1524e93e 2195 intel_ddi_pre_enable_dp(encoder,
3dc38eea
ACO
2196 pipe_config->port_clock,
2197 pipe_config->lane_count,
2198 pipe_config->shared_dpll,
2199 intel_crtc_has_type(pipe_config,
ba88d153
MN
2200 INTEL_OUTPUT_DP_MST));
2201 }
2202 if (type == INTEL_OUTPUT_HDMI) {
1524e93e 2203 intel_ddi_pre_enable_hdmi(encoder,
b47ef0f7 2204 pipe_config->has_infoframe,
ac240288 2205 pipe_config, conn_state,
3dc38eea 2206 pipe_config->shared_dpll);
c19b0669 2207 }
6441ab5f
PZ
2208}
2209
fd6bbda9 2210static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
5f88a9c6
VS
2211 const struct intel_crtc_state *old_crtc_state,
2212 const struct drm_connector_state *old_conn_state)
6441ab5f
PZ
2213{
2214 struct drm_encoder *encoder = &intel_encoder->base;
66478475 2215 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
6441ab5f 2216 enum port port = intel_ddi_get_encoder_port(intel_encoder);
62b69566 2217 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
82a4d9c0 2218 int type = intel_encoder->type;
2886e93f 2219 uint32_t val;
a836bdf9 2220 bool wait = false;
2886e93f 2221
fd6bbda9
ML
2222 /* old_crtc_state and old_conn_state are NULL when called from DP_MST */
2223
7618138d 2224 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
c5f93fcf
VS
2225 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2226
7618138d
ID
2227 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2228 }
2229
2886e93f
PZ
2230 val = I915_READ(DDI_BUF_CTL(port));
2231 if (val & DDI_BUF_CTL_ENABLE) {
2232 val &= ~DDI_BUF_CTL_ENABLE;
2233 I915_WRITE(DDI_BUF_CTL(port), val);
a836bdf9 2234 wait = true;
2886e93f 2235 }
6441ab5f 2236
a836bdf9
PZ
2237 val = I915_READ(DP_TP_CTL(port));
2238 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2239 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2240 I915_WRITE(DP_TP_CTL(port), val);
2241
2242 if (wait)
2243 intel_wait_ddi_buf_idle(dev_priv, port);
2244
c5f93fcf 2245 if (type == INTEL_OUTPUT_HDMI) {
f99be1b3
VS
2246 dig_port->set_infoframes(encoder, false,
2247 old_crtc_state, old_conn_state);
c5f93fcf
VS
2248 }
2249
2250 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
2251 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2252
24f3e092 2253 intel_edp_panel_vdd_on(intel_dp);
4be73780 2254 intel_edp_panel_off(intel_dp);
82a4d9c0
PZ
2255 }
2256
62b69566
ACO
2257 if (dig_port)
2258 intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
2259
555e38d2
RV
2260 if (IS_CANNONLAKE(dev_priv))
2261 I915_WRITE(DPCLKA_CFGCR0, I915_READ(DPCLKA_CFGCR0) |
2262 DPCLKA_CFGCR0_DDI_CLK_OFF(port));
2263 else if (IS_GEN9_BC(dev_priv))
efa80add
S
2264 I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
2265 DPLL_CTRL2_DDI_CLK_OFF(port)));
66478475 2266 else if (INTEL_GEN(dev_priv) < 9)
efa80add 2267 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
b2ccb822
VS
2268
2269 if (type == INTEL_OUTPUT_HDMI) {
2270 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
2271
2272 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
2273 }
6441ab5f
PZ
2274}
2275
1524e93e 2276void intel_ddi_fdi_post_disable(struct intel_encoder *encoder,
5f88a9c6
VS
2277 const struct intel_crtc_state *old_crtc_state,
2278 const struct drm_connector_state *old_conn_state)
b7076546 2279{
1524e93e 2280 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
b7076546
ML
2281 uint32_t val;
2282
2283 /*
2284 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
2285 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
2286 * step 13 is the correct place for it. Step 18 is where it was
2287 * originally before the BUN.
2288 */
2289 val = I915_READ(FDI_RX_CTL(PIPE_A));
2290 val &= ~FDI_RX_ENABLE;
2291 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2292
1524e93e 2293 intel_ddi_post_disable(encoder, old_crtc_state, old_conn_state);
b7076546
ML
2294
2295 val = I915_READ(FDI_RX_MISC(PIPE_A));
2296 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
2297 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
2298 I915_WRITE(FDI_RX_MISC(PIPE_A), val);
2299
2300 val = I915_READ(FDI_RX_CTL(PIPE_A));
2301 val &= ~FDI_PCDCLK;
2302 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2303
2304 val = I915_READ(FDI_RX_CTL(PIPE_A));
2305 val &= ~FDI_RX_PLL_ENABLE;
2306 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2307}
2308
fd6bbda9 2309static void intel_enable_ddi(struct intel_encoder *intel_encoder,
5f88a9c6
VS
2310 const struct intel_crtc_state *pipe_config,
2311 const struct drm_connector_state *conn_state)
72662e10 2312{
6547fef8 2313 struct drm_encoder *encoder = &intel_encoder->base;
66478475 2314 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
6547fef8
PZ
2315 enum port port = intel_ddi_get_encoder_port(intel_encoder);
2316 int type = intel_encoder->type;
72662e10 2317
6547fef8 2318 if (type == INTEL_OUTPUT_HDMI) {
876a8cdf
DL
2319 struct intel_digital_port *intel_dig_port =
2320 enc_to_dig_port(encoder);
15953637
SS
2321 bool clock_ratio = pipe_config->hdmi_high_tmds_clock_ratio;
2322 bool scrambling = pipe_config->hdmi_scrambling;
2323
2324 intel_hdmi_handle_sink_scrambling(intel_encoder,
2325 conn_state->connector,
2326 clock_ratio, scrambling);
876a8cdf 2327
6547fef8
PZ
2328 /* In HDMI/DVI mode, the port width, and swing/emphasis values
2329 * are ignored so nothing special needs to be done besides
2330 * enabling the port.
2331 */
876a8cdf 2332 I915_WRITE(DDI_BUF_CTL(port),
bcf53de4
SM
2333 intel_dig_port->saved_port_bits |
2334 DDI_BUF_CTL_ENABLE);
d6c50ff8
PZ
2335 } else if (type == INTEL_OUTPUT_EDP) {
2336 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2337
66478475 2338 if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
3ab9c637
ID
2339 intel_dp_stop_link_train(intel_dp);
2340
b037d58f 2341 intel_edp_backlight_on(pipe_config, conn_state);
d2419ffc 2342 intel_psr_enable(intel_dp, pipe_config);
85cb48a1 2343 intel_edp_drrs_enable(intel_dp, pipe_config);
6547fef8 2344 }
7b9f35a6 2345
37255d8d 2346 if (pipe_config->has_audio)
bbf35e9d 2347 intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
5ab432ef
DV
2348}
2349
fd6bbda9 2350static void intel_disable_ddi(struct intel_encoder *intel_encoder,
5f88a9c6
VS
2351 const struct intel_crtc_state *old_crtc_state,
2352 const struct drm_connector_state *old_conn_state)
5ab432ef 2353{
d6c50ff8
PZ
2354 struct drm_encoder *encoder = &intel_encoder->base;
2355 int type = intel_encoder->type;
2356
37255d8d 2357 if (old_crtc_state->has_audio)
69bfe1a9 2358 intel_audio_codec_disable(intel_encoder);
2831d842 2359
15953637
SS
2360 if (type == INTEL_OUTPUT_HDMI) {
2361 intel_hdmi_handle_sink_scrambling(intel_encoder,
2362 old_conn_state->connector,
2363 false, false);
2364 }
2365
d6c50ff8
PZ
2366 if (type == INTEL_OUTPUT_EDP) {
2367 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2368
85cb48a1 2369 intel_edp_drrs_disable(intel_dp, old_crtc_state);
d2419ffc 2370 intel_psr_disable(intel_dp, old_crtc_state);
b037d58f 2371 intel_edp_backlight_off(old_conn_state);
d6c50ff8 2372 }
72662e10 2373}
79f689aa 2374
fd6bbda9 2375static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
5f88a9c6
VS
2376 const struct intel_crtc_state *pipe_config,
2377 const struct drm_connector_state *conn_state)
95a7a2ae 2378{
3dc38eea 2379 uint8_t mask = pipe_config->lane_lat_optim_mask;
95a7a2ae 2380
47a6bc61 2381 bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
95a7a2ae
ID
2382}
2383
ad64217b 2384void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
c19b0669 2385{
ad64217b
ACO
2386 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2387 struct drm_i915_private *dev_priv =
2388 to_i915(intel_dig_port->base.base.dev);
174edf1f 2389 enum port port = intel_dig_port->port;
c19b0669 2390 uint32_t val;
f3e227df 2391 bool wait = false;
c19b0669
PZ
2392
2393 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
2394 val = I915_READ(DDI_BUF_CTL(port));
2395 if (val & DDI_BUF_CTL_ENABLE) {
2396 val &= ~DDI_BUF_CTL_ENABLE;
2397 I915_WRITE(DDI_BUF_CTL(port), val);
2398 wait = true;
2399 }
2400
2401 val = I915_READ(DP_TP_CTL(port));
2402 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2403 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2404 I915_WRITE(DP_TP_CTL(port), val);
2405 POSTING_READ(DP_TP_CTL(port));
2406
2407 if (wait)
2408 intel_wait_ddi_buf_idle(dev_priv, port);
2409 }
2410
0e32b39c 2411 val = DP_TP_CTL_ENABLE |
c19b0669 2412 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
64ee2fd2 2413 if (intel_dp->link_mst)
0e32b39c
DA
2414 val |= DP_TP_CTL_MODE_MST;
2415 else {
2416 val |= DP_TP_CTL_MODE_SST;
2417 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2418 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
2419 }
c19b0669
PZ
2420 I915_WRITE(DP_TP_CTL(port), val);
2421 POSTING_READ(DP_TP_CTL(port));
2422
2423 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
2424 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
2425 POSTING_READ(DDI_BUF_CTL(port));
2426
2427 udelay(600);
2428}
00c09d70 2429
9935f7fa
LY
2430bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
2431 struct intel_crtc *intel_crtc)
2432{
2433 u32 temp;
2434
2435 if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
2436 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
2437 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
2438 return true;
2439 }
2440 return false;
2441}
2442
6801c18c 2443void intel_ddi_get_config(struct intel_encoder *encoder,
5cec258b 2444 struct intel_crtc_state *pipe_config)
045ac3b5 2445{
fac5e23e 2446 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
045ac3b5 2447 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
0cb09a97 2448 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
f99be1b3 2449 struct intel_digital_port *intel_dig_port;
045ac3b5
JB
2450 u32 temp, flags = 0;
2451
4d1de975
JN
2452 /* XXX: DSI transcoder paranoia */
2453 if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
2454 return;
2455
045ac3b5
JB
2456 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
2457 if (temp & TRANS_DDI_PHSYNC)
2458 flags |= DRM_MODE_FLAG_PHSYNC;
2459 else
2460 flags |= DRM_MODE_FLAG_NHSYNC;
2461 if (temp & TRANS_DDI_PVSYNC)
2462 flags |= DRM_MODE_FLAG_PVSYNC;
2463 else
2464 flags |= DRM_MODE_FLAG_NVSYNC;
2465
2d112de7 2466 pipe_config->base.adjusted_mode.flags |= flags;
42571aef
VS
2467
2468 switch (temp & TRANS_DDI_BPC_MASK) {
2469 case TRANS_DDI_BPC_6:
2470 pipe_config->pipe_bpp = 18;
2471 break;
2472 case TRANS_DDI_BPC_8:
2473 pipe_config->pipe_bpp = 24;
2474 break;
2475 case TRANS_DDI_BPC_10:
2476 pipe_config->pipe_bpp = 30;
2477 break;
2478 case TRANS_DDI_BPC_12:
2479 pipe_config->pipe_bpp = 36;
2480 break;
2481 default:
2482 break;
2483 }
eb14cb74
VS
2484
2485 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
2486 case TRANS_DDI_MODE_SELECT_HDMI:
6897b4b5 2487 pipe_config->has_hdmi_sink = true;
f99be1b3 2488 intel_dig_port = enc_to_dig_port(&encoder->base);
bbd440fb 2489
f99be1b3 2490 if (intel_dig_port->infoframe_enabled(&encoder->base, pipe_config))
bbd440fb 2491 pipe_config->has_infoframe = true;
15953637
SS
2492
2493 if ((temp & TRANS_DDI_HDMI_SCRAMBLING_MASK) ==
2494 TRANS_DDI_HDMI_SCRAMBLING_MASK)
2495 pipe_config->hdmi_scrambling = true;
2496 if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
2497 pipe_config->hdmi_high_tmds_clock_ratio = true;
d4d6279a 2498 /* fall through */
eb14cb74 2499 case TRANS_DDI_MODE_SELECT_DVI:
d4d6279a
ACO
2500 pipe_config->lane_count = 4;
2501 break;
eb14cb74
VS
2502 case TRANS_DDI_MODE_SELECT_FDI:
2503 break;
2504 case TRANS_DDI_MODE_SELECT_DP_SST:
2505 case TRANS_DDI_MODE_SELECT_DP_MST:
90a6b7b0
VS
2506 pipe_config->lane_count =
2507 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
eb14cb74
VS
2508 intel_dp_get_m_n(intel_crtc, pipe_config);
2509 break;
2510 default:
2511 break;
2512 }
10214420 2513
9935f7fa
LY
2514 pipe_config->has_audio =
2515 intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
9ed109a7 2516
6aa23e65
JN
2517 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
2518 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
10214420
DV
2519 /*
2520 * This is a big fat ugly hack.
2521 *
2522 * Some machines in UEFI boot mode provide us a VBT that has 18
2523 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2524 * unknown we fail to light up. Yet the same BIOS boots up with
2525 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2526 * max, not what it tells us to use.
2527 *
2528 * Note: This will still be broken if the eDP panel is not lit
2529 * up by the BIOS, and thus we can't get the mode at module
2530 * load.
2531 */
2532 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
6aa23e65
JN
2533 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2534 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
10214420 2535 }
11578553 2536
22606a18 2537 intel_ddi_clock_get(encoder, pipe_config);
95a7a2ae 2538
cc3f90f0 2539 if (IS_GEN9_LP(dev_priv))
95a7a2ae
ID
2540 pipe_config->lane_lat_optim_mask =
2541 bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
045ac3b5
JB
2542}
2543
5bfe2ac0 2544static bool intel_ddi_compute_config(struct intel_encoder *encoder,
0a478c27
ML
2545 struct intel_crtc_state *pipe_config,
2546 struct drm_connector_state *conn_state)
00c09d70 2547{
fac5e23e 2548 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5bfe2ac0 2549 int type = encoder->type;
eccb140b 2550 int port = intel_ddi_get_encoder_port(encoder);
95a7a2ae 2551 int ret;
00c09d70 2552
5bfe2ac0 2553 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
00c09d70 2554
eccb140b
DV
2555 if (port == PORT_A)
2556 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2557
00c09d70 2558 if (type == INTEL_OUTPUT_HDMI)
0a478c27 2559 ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
00c09d70 2560 else
0a478c27 2561 ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
95a7a2ae 2562
cc3f90f0 2563 if (IS_GEN9_LP(dev_priv) && ret)
95a7a2ae
ID
2564 pipe_config->lane_lat_optim_mask =
2565 bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
b284eeda 2566 pipe_config->lane_count);
95a7a2ae
ID
2567
2568 return ret;
2569
00c09d70
PZ
2570}
2571
2572static const struct drm_encoder_funcs intel_ddi_funcs = {
bf93ba67
ID
2573 .reset = intel_dp_encoder_reset,
2574 .destroy = intel_dp_encoder_destroy,
00c09d70
PZ
2575};
2576
4a28ae58
PZ
2577static struct intel_connector *
2578intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2579{
2580 struct intel_connector *connector;
2581 enum port port = intel_dig_port->port;
2582
9bdbd0b9 2583 connector = intel_connector_alloc();
4a28ae58
PZ
2584 if (!connector)
2585 return NULL;
2586
2587 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2588 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2589 kfree(connector);
2590 return NULL;
2591 }
2592
2593 return connector;
2594}
2595
2596static struct intel_connector *
2597intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2598{
2599 struct intel_connector *connector;
2600 enum port port = intel_dig_port->port;
2601
9bdbd0b9 2602 connector = intel_connector_alloc();
4a28ae58
PZ
2603 if (!connector)
2604 return NULL;
2605
2606 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2607 intel_hdmi_init_connector(intel_dig_port, connector);
2608
2609 return connector;
2610}
2611
c39055b0 2612void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
00c09d70
PZ
2613{
2614 struct intel_digital_port *intel_dig_port;
2615 struct intel_encoder *intel_encoder;
2616 struct drm_encoder *encoder;
ff662124 2617 bool init_hdmi, init_dp, init_lspcon = false;
10e7bec3
VS
2618 int max_lanes;
2619
2620 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
2621 switch (port) {
2622 case PORT_A:
2623 max_lanes = 4;
2624 break;
2625 case PORT_E:
2626 max_lanes = 0;
2627 break;
2628 default:
2629 max_lanes = 4;
2630 break;
2631 }
2632 } else {
2633 switch (port) {
2634 case PORT_A:
2635 max_lanes = 2;
2636 break;
2637 case PORT_E:
2638 max_lanes = 2;
2639 break;
2640 default:
2641 max_lanes = 4;
2642 break;
2643 }
2644 }
311a2094
PZ
2645
2646 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2647 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2648 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
ff662124
SS
2649
2650 if (intel_bios_is_lspcon_present(dev_priv, port)) {
2651 /*
2652 * Lspcon device needs to be driven with DP connector
2653 * with special detection sequence. So make sure DP
2654 * is initialized before lspcon.
2655 */
2656 init_dp = true;
2657 init_lspcon = true;
2658 init_hdmi = false;
2659 DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
2660 }
2661
311a2094 2662 if (!init_dp && !init_hdmi) {
500ea70d 2663 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
311a2094 2664 port_name(port));
500ea70d 2665 return;
311a2094 2666 }
00c09d70 2667
b14c5679 2668 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
00c09d70
PZ
2669 if (!intel_dig_port)
2670 return;
2671
00c09d70
PZ
2672 intel_encoder = &intel_dig_port->base;
2673 encoder = &intel_encoder->base;
2674
c39055b0 2675 drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
580d8ed5 2676 DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
00c09d70 2677
5bfe2ac0 2678 intel_encoder->compute_config = intel_ddi_compute_config;
00c09d70 2679 intel_encoder->enable = intel_enable_ddi;
cc3f90f0 2680 if (IS_GEN9_LP(dev_priv))
95a7a2ae 2681 intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
00c09d70
PZ
2682 intel_encoder->pre_enable = intel_ddi_pre_enable;
2683 intel_encoder->disable = intel_disable_ddi;
2684 intel_encoder->post_disable = intel_ddi_post_disable;
2685 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
045ac3b5 2686 intel_encoder->get_config = intel_ddi_get_config;
bf93ba67 2687 intel_encoder->suspend = intel_dp_encoder_suspend;
62b69566 2688 intel_encoder->get_power_domains = intel_ddi_get_power_domains;
00c09d70
PZ
2689
2690 intel_dig_port->port = port;
bcf53de4
SM
2691 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2692 (DDI_BUF_PORT_REVERSAL |
2693 DDI_A_4_LANES);
00c09d70 2694
62b69566
ACO
2695 switch (port) {
2696 case PORT_A:
2697 intel_dig_port->ddi_io_power_domain =
2698 POWER_DOMAIN_PORT_DDI_A_IO;
2699 break;
2700 case PORT_B:
2701 intel_dig_port->ddi_io_power_domain =
2702 POWER_DOMAIN_PORT_DDI_B_IO;
2703 break;
2704 case PORT_C:
2705 intel_dig_port->ddi_io_power_domain =
2706 POWER_DOMAIN_PORT_DDI_C_IO;
2707 break;
2708 case PORT_D:
2709 intel_dig_port->ddi_io_power_domain =
2710 POWER_DOMAIN_PORT_DDI_D_IO;
2711 break;
2712 case PORT_E:
2713 intel_dig_port->ddi_io_power_domain =
2714 POWER_DOMAIN_PORT_DDI_E_IO;
2715 break;
2716 default:
2717 MISSING_CASE(port);
2718 }
2719
6c566dc9
MR
2720 /*
2721 * Bspec says that DDI_A_4_LANES is the only supported configuration
2722 * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
2723 * wasn't lit up at boot. Force this bit on in our internal
2724 * configuration so that we use the proper lane count for our
2725 * calculations.
2726 */
cc3f90f0 2727 if (IS_GEN9_LP(dev_priv) && port == PORT_A) {
6c566dc9
MR
2728 if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
2729 DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
2730 intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
ed8d60f4 2731 max_lanes = 4;
6c566dc9
MR
2732 }
2733 }
2734
ed8d60f4
MR
2735 intel_dig_port->max_lanes = max_lanes;
2736
00c09d70 2737 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
79f255a0 2738 intel_encoder->power_domain = intel_port_to_power_domain(port);
03cdc1d4 2739 intel_encoder->port = port;
f68d697e 2740 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
bc079e8b 2741 intel_encoder->cloneable = 0;
00c09d70 2742
385e4de0
VS
2743 intel_infoframe_init(intel_dig_port);
2744
f68d697e
CW
2745 if (init_dp) {
2746 if (!intel_ddi_init_dp_connector(intel_dig_port))
2747 goto err;
13cf5504 2748
f68d697e 2749 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
ca4c3890 2750 dev_priv->hotplug.irq_port[port] = intel_dig_port;
f68d697e 2751 }
21a8e6a4 2752
311a2094
PZ
2753 /* In theory we don't need the encoder->type check, but leave it just in
2754 * case we have some really bad VBTs... */
f68d697e
CW
2755 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2756 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2757 goto err;
21a8e6a4 2758 }
f68d697e 2759
ff662124
SS
2760 if (init_lspcon) {
2761 if (lspcon_init(intel_dig_port))
2762 /* TODO: handle hdmi info frame part */
2763 DRM_DEBUG_KMS("LSPCON init success on port %c\n",
2764 port_name(port));
2765 else
2766 /*
2767 * LSPCON init faied, but DP init was success, so
2768 * lets try to drive as DP++ port.
2769 */
2770 DRM_ERROR("LSPCON init failed on port %c\n",
2771 port_name(port));
2772 }
2773
f68d697e
CW
2774 return;
2775
2776err:
2777 drm_encoder_cleanup(encoder);
2778 kfree(intel_dig_port);
00c09d70 2779}