blob: b307b6fe1ce385300627f080f773b4d9294a360c [file] [log] [blame]
Eugeni Dodonov45244b82012-05-09 15:37:20 -03001/*
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
Jani Nikula10122052014-08-27 16:27:30 +030031struct ddi_buf_trans {
32 u32 trans1; /* balance leg enable, de-emph level */
33 u32 trans2; /* vref sel, vswing */
David Weinehallf8896f52015-06-25 11:11:03 +030034 u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */
Jani Nikula10122052014-08-27 16:27:30 +030035};
36
Ville Syrjälä97eeb872017-02-23 19:35:06 +020037static 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
Eugeni Dodonov45244b82012-05-09 15:37:20 -030050/* 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 */
Jani Nikula10122052014-08-27 16:27:30 +030054static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030055 { 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 },
Eugeni Dodonov45244b82012-05-09 15:37:20 -030064};
65
Jani Nikula10122052014-08-27 16:27:30 +030066static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030067 { 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 },
Paulo Zanoni6acab152013-09-12 17:06:24 -030076};
77
Jani Nikula10122052014-08-27 16:27:30 +030078static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
79 /* Idx NT mV d T mV d db */
David Weinehallf8896f52015-06-25 11:11:03 +030080 { 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 */
Eugeni Dodonov45244b82012-05-09 15:37:20 -030092};
93
Jani Nikula10122052014-08-27 16:27:30 +030094static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030095 { 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 },
Paulo Zanoni300644c2013-11-02 21:07:42 -0700104};
105
Jani Nikula10122052014-08-27 16:27:30 +0300106static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300107 { 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 },
Art Runyane58623c2013-11-02 21:07:41 -0700116};
117
Jani Nikula10122052014-08-27 16:27:30 +0300118static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300119 { 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 },
Art Runyane58623c2013-11-02 21:07:41 -0700128};
129
Jani Nikula10122052014-08-27 16:27:30 +0300130static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
131 /* Idx NT mV d T mV df db */
David Weinehallf8896f52015-06-25 11:11:03 +0300132 { 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 */
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100142};
143
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700144/* Skylake H and S */
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000145static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300146 { 0x00002016, 0x000000A0, 0x0 },
147 { 0x00005012, 0x0000009B, 0x0 },
148 { 0x00007011, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800149 { 0x80009010, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300150 { 0x00002016, 0x0000009B, 0x0 },
151 { 0x00005012, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800152 { 0x80007011, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300153 { 0x00002016, 0x000000DF, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800154 { 0x80005012, 0x000000C0, 0x1 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000155};
156
David Weinehallf8896f52015-06-25 11:11:03 +0300157/* Skylake U */
158static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700159 { 0x0000201B, 0x000000A2, 0x0 },
David Weinehallf8896f52015-06-25 11:11:03 +0300160 { 0x00005012, 0x00000088, 0x0 },
Ville Syrjälä5ac90562016-08-02 15:21:57 +0300161 { 0x80007011, 0x000000CD, 0x1 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800162 { 0x80009010, 0x000000C0, 0x1 },
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700163 { 0x0000201B, 0x0000009D, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800164 { 0x80005012, 0x000000C0, 0x1 },
165 { 0x80007011, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300166 { 0x00002016, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800167 { 0x80005012, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300168};
169
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700170/* Skylake Y */
171static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300172 { 0x00000018, 0x000000A2, 0x0 },
173 { 0x00005012, 0x00000088, 0x0 },
Ville Syrjälä5ac90562016-08-02 15:21:57 +0300174 { 0x80007011, 0x000000CD, 0x3 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800175 { 0x80009010, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300176 { 0x00000018, 0x0000009D, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800177 { 0x80005012, 0x000000C0, 0x3 },
178 { 0x80007011, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300179 { 0x00000018, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800180 { 0x80005012, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300181};
182
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700183/* 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
David Weinehallf8896f52015-06-25 11:11:03 +0300222/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700223 * Skylake/Kabylake H and S
David Weinehallf8896f52015-06-25 11:11:03 +0300224 * eDP 1.4 low vswing translation parameters
225 */
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530226static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300227 { 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 },
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530237};
238
David Weinehallf8896f52015-06-25 11:11:03 +0300239/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700240 * Skylake/Kabylake U
David Weinehallf8896f52015-06-25 11:11:03 +0300241 * 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 },
254};
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530255
David Weinehallf8896f52015-06-25 11:11:03 +0300256/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700257 * Skylake/Kabylake Y
David Weinehallf8896f52015-06-25 11:11:03 +0300258 * eDP 1.4 low vswing translation parameters
259 */
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700260static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300261 { 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};
272
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700273/* Skylake/Kabylake U, H and S */
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000274static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300275 { 0x00000018, 0x000000AC, 0x0 },
276 { 0x00005012, 0x0000009D, 0x0 },
277 { 0x00007011, 0x00000088, 0x0 },
278 { 0x00000018, 0x000000A1, 0x0 },
279 { 0x00000018, 0x00000098, 0x0 },
280 { 0x00004013, 0x00000088, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800281 { 0x80006012, 0x000000CD, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300282 { 0x00000018, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800283 { 0x80003015, 0x000000CD, 0x1 }, /* Default */
284 { 0x80003015, 0x000000C0, 0x1 },
285 { 0x80000018, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300286};
287
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700288/* Skylake/Kabylake Y */
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700289static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300290 { 0x00000018, 0x000000A1, 0x0 },
291 { 0x00005012, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800292 { 0x80007011, 0x000000CB, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300293 { 0x00000018, 0x000000A4, 0x0 },
294 { 0x00000018, 0x0000009D, 0x0 },
295 { 0x00004013, 0x00000080, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800296 { 0x80006013, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300297 { 0x00000018, 0x0000008A, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800298 { 0x80003015, 0x000000C0, 0x3 }, /* Default */
299 { 0x80003015, 0x000000C0, 0x3 },
300 { 0x80000018, 0x000000C0, 0x3 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000301};
302
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530303struct bxt_ddi_buf_trans {
Ville Syrjäläac3ad6c2017-09-18 21:25:37 +0300304 u8 margin; /* swing value */
305 u8 scale; /* scale value */
306 u8 enable; /* scale enable */
307 u8 deemphasis;
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530308 bool default_index; /* true if the entry represents default value */
309};
310
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530311static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
312 /* Idx NT mV diff db */
Imre Deakfe4c63c2015-06-04 18:01:35 +0300313 { 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 */
David Weinehallf8896f52015-06-25 11:11:03 +0300322 { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530323};
324
Sonika Jindald9d70002015-09-24 10:24:56 +0530325static 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
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530339/* 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 */
Imre Deakfe4c63c2015-06-04 18:01:35 +0300344 { 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 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530353 { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
354};
355
Rodrigo Vivi83fb7ab2017-06-09 15:26:07 -0700356struct cnl_ddi_buf_trans {
Ville Syrjäläfb5f4e92017-09-18 21:25:38 +0300357 u8 dw2_swing_sel;
358 u8 dw7_n_scalar;
359 u8 dw4_cursor_coeff;
360 u8 dw4_post_cursor_2;
361 u8 dw4_post_cursor_1;
Rodrigo Vivi83fb7ab2017-06-09 15:26:07 -0700362};
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
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300496enum port intel_ddi_get_encoder_port(struct intel_encoder *encoder)
Paulo Zanonifc914632012-10-05 12:05:54 -0300497{
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300498 switch (encoder->type) {
Jani Nikula8cd21b72015-09-29 10:24:26 +0300499 case INTEL_OUTPUT_DP_MST:
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300500 return enc_to_mst(&encoder->base)->primary->port;
Ville Syrjäläcca05022016-06-22 21:57:06 +0300501 case INTEL_OUTPUT_DP:
Jani Nikula8cd21b72015-09-29 10:24:26 +0300502 case INTEL_OUTPUT_EDP:
503 case INTEL_OUTPUT_HDMI:
504 case INTEL_OUTPUT_UNKNOWN:
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300505 return enc_to_dig_port(&encoder->base)->port;
Jani Nikula8cd21b72015-09-29 10:24:26 +0300506 case INTEL_OUTPUT_ANALOG:
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300507 return PORT_E;
508 default:
509 MISSING_CASE(encoder->type);
510 return PORT_A;
Paulo Zanonifc914632012-10-05 12:05:54 -0300511 }
512}
513
Ville Syrjäläacee2992015-12-08 19:59:39 +0200514static const struct ddi_buf_trans *
Ville Syrjäläa930acd2016-07-12 15:59:36 +0300515bdw_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
526static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200527skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300528{
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700529 if (IS_SKL_ULX(dev_priv)) {
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700530 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200531 return skl_y_ddi_translations_dp;
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700532 } else if (IS_SKL_ULT(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +0300533 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200534 return skl_u_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300535 } else {
David Weinehallf8896f52015-06-25 11:11:03 +0300536 *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200537 return skl_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300538 }
David Weinehallf8896f52015-06-25 11:11:03 +0300539}
540
541static const struct ddi_buf_trans *
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700542kbl_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;
Rodrigo Vivida411a42017-06-09 15:02:50 -0700547 } else if (IS_KBL_ULT(dev_priv) || IS_CFL_ULT(dev_priv)) {
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700548 *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
556static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200557skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300558{
Jani Nikula06411f02016-03-24 17:50:21 +0200559 if (dev_priv->vbt.edp.low_vswing) {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200560 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200561 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
562 return skl_y_ddi_translations_edp;
Rodrigo Vivida411a42017-06-09 15:02:50 -0700563 } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv) ||
564 IS_CFL_ULT(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200565 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
566 return skl_u_ddi_translations_edp;
567 } else {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200568 *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
569 return skl_ddi_translations_edp;
Ville Syrjäläacee2992015-12-08 19:59:39 +0200570 }
David Weinehallf8896f52015-06-25 11:11:03 +0300571 }
Ville Syrjäläcd1101c2015-12-08 19:59:40 +0200572
Rodrigo Vivida411a42017-06-09 15:02:50 -0700573 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700574 return kbl_get_buf_trans_dp(dev_priv, n_entries);
575 else
576 return skl_get_buf_trans_dp(dev_priv, n_entries);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200577}
David Weinehallf8896f52015-06-25 11:11:03 +0300578
Ville Syrjäläacee2992015-12-08 19:59:39 +0200579static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200580skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
Ville Syrjäläacee2992015-12-08 19:59:39 +0200581{
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200582 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200583 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
584 return skl_y_ddi_translations_hdmi;
585 } else {
586 *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
587 return skl_ddi_translations_hdmi;
588 }
David Weinehallf8896f52015-06-25 11:11:03 +0300589}
590
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700591static const struct cnl_ddi_buf_trans *
592cnl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
593{
594 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
595
596 if (voltage == VOLTAGE_INFO_0_85V) {
597 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V);
598 return cnl_ddi_translations_hdmi_0_85V;
599 } else if (voltage == VOLTAGE_INFO_0_95V) {
600 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V);
601 return cnl_ddi_translations_hdmi_0_95V;
602 } else if (voltage == VOLTAGE_INFO_1_05V) {
603 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V);
604 return cnl_ddi_translations_hdmi_1_05V;
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200605 } else {
606 *n_entries = 1; /* shut up gcc */
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700607 MISSING_CASE(voltage);
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200608 }
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700609 return NULL;
610}
611
612static const struct cnl_ddi_buf_trans *
613cnl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
614{
615 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
616
617 if (voltage == VOLTAGE_INFO_0_85V) {
618 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V);
619 return cnl_ddi_translations_dp_0_85V;
620 } else if (voltage == VOLTAGE_INFO_0_95V) {
621 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V);
622 return cnl_ddi_translations_dp_0_95V;
623 } else if (voltage == VOLTAGE_INFO_1_05V) {
624 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V);
625 return cnl_ddi_translations_dp_1_05V;
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200626 } else {
627 *n_entries = 1; /* shut up gcc */
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700628 MISSING_CASE(voltage);
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200629 }
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700630 return NULL;
631}
632
633static const struct cnl_ddi_buf_trans *
634cnl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
635{
636 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
637
638 if (dev_priv->vbt.edp.low_vswing) {
639 if (voltage == VOLTAGE_INFO_0_85V) {
640 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V);
641 return cnl_ddi_translations_edp_0_85V;
642 } else if (voltage == VOLTAGE_INFO_0_95V) {
643 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V);
644 return cnl_ddi_translations_edp_0_95V;
645 } else if (voltage == VOLTAGE_INFO_1_05V) {
646 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V);
647 return cnl_ddi_translations_edp_1_05V;
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200648 } else {
649 *n_entries = 1; /* shut up gcc */
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700650 MISSING_CASE(voltage);
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200651 }
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700652 return NULL;
653 } else {
654 return cnl_get_buf_trans_dp(dev_priv, n_entries);
655 }
656}
657
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300658static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
659{
660 int n_hdmi_entries;
661 int hdmi_level;
662 int hdmi_default_entry;
663
664 hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
665
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200666 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300667 return hdmi_level;
668
Rodrigo Vivibf503552017-08-29 16:22:29 -0700669 if (IS_CANNONLAKE(dev_priv)) {
670 cnl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
671 hdmi_default_entry = n_hdmi_entries - 1;
672 } else if (IS_GEN9_BC(dev_priv)) {
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300673 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
674 hdmi_default_entry = 8;
675 } else if (IS_BROADWELL(dev_priv)) {
676 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
677 hdmi_default_entry = 7;
678 } else if (IS_HASWELL(dev_priv)) {
679 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
680 hdmi_default_entry = 6;
681 } else {
682 WARN(1, "ddi translation table missing\n");
683 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
684 hdmi_default_entry = 7;
685 }
686
687 /* Choose a good default if VBT is badly populated */
688 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
689 hdmi_level >= n_hdmi_entries)
690 hdmi_level = hdmi_default_entry;
691
692 return hdmi_level;
693}
694
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200695static const struct ddi_buf_trans *
696intel_ddi_get_buf_trans_dp(struct drm_i915_private *dev_priv,
697 int *n_entries)
698{
Rodrigo Vivida411a42017-06-09 15:02:50 -0700699 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200700 return kbl_get_buf_trans_dp(dev_priv, n_entries);
701 } else if (IS_SKYLAKE(dev_priv)) {
702 return skl_get_buf_trans_dp(dev_priv, n_entries);
703 } else if (IS_BROADWELL(dev_priv)) {
704 *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
705 return bdw_ddi_translations_dp;
706 } else if (IS_HASWELL(dev_priv)) {
707 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
708 return hsw_ddi_translations_dp;
709 }
710
711 *n_entries = 0;
712 return NULL;
713}
714
715static const struct ddi_buf_trans *
716intel_ddi_get_buf_trans_edp(struct drm_i915_private *dev_priv,
717 int *n_entries)
718{
Rodrigo Vivida411a42017-06-09 15:02:50 -0700719 if (IS_GEN9_BC(dev_priv)) {
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200720 return skl_get_buf_trans_edp(dev_priv, n_entries);
721 } else if (IS_BROADWELL(dev_priv)) {
722 return bdw_get_buf_trans_edp(dev_priv, n_entries);
723 } else if (IS_HASWELL(dev_priv)) {
724 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
725 return hsw_ddi_translations_dp;
726 }
727
728 *n_entries = 0;
729 return NULL;
730}
731
732static const struct ddi_buf_trans *
733intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv,
734 int *n_entries)
735{
736 if (IS_BROADWELL(dev_priv)) {
737 *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
738 return hsw_ddi_translations_fdi;
739 } else if (IS_HASWELL(dev_priv)) {
740 *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
741 return hsw_ddi_translations_fdi;
742 }
743
744 *n_entries = 0;
745 return NULL;
746}
747
Art Runyane58623c2013-11-02 21:07:41 -0700748/*
749 * Starting with Haswell, DDI port buffers must be programmed with correct
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300750 * values in advance. This function programs the correct values for
751 * DP/eDP/FDI use cases.
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300752 */
Paulo Zanonid7c530b2017-03-30 17:57:52 -0300753static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300754{
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200755 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300756 u32 iboost_bit = 0;
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200757 int i, n_entries;
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300758 enum port port = intel_ddi_get_encoder_port(encoder);
Jani Nikula10122052014-08-27 16:27:30 +0300759 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700760
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200761 switch (encoder->type) {
762 case INTEL_OUTPUT_EDP:
763 ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv,
764 &n_entries);
765 break;
766 case INTEL_OUTPUT_DP:
767 ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv,
768 &n_entries);
769 break;
770 case INTEL_OUTPUT_ANALOG:
771 ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
772 &n_entries);
773 break;
774 default:
775 MISSING_CASE(encoder->type);
776 return;
Art Runyane58623c2013-11-02 21:07:41 -0700777 }
778
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800779 if (IS_GEN9_BC(dev_priv)) {
Rodrigo Vivi0a918772016-09-30 11:05:56 -0700780 /* If we're boosting the current, set bit 31 of trans1 */
781 if (dev_priv->vbt.ddi_port_info[port].dp_boost_level)
782 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
783
784 if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
785 port != PORT_A && port != PORT_E &&
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200786 n_entries > 9))
787 n_entries = 9;
Rodrigo Vivi0a918772016-09-30 11:05:56 -0700788 }
789
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200790 for (i = 0; i < n_entries; i++) {
Ville Syrjälä9712e682015-09-18 20:03:22 +0300791 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
792 ddi_translations[i].trans1 | iboost_bit);
793 I915_WRITE(DDI_BUF_TRANS_HI(port, i),
794 ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300795 }
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300796}
Damien Lespiauce4dd492014-08-01 11:07:54 +0100797
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300798/*
799 * Starting with Haswell, DDI port buffers must be programmed with correct
800 * values in advance. This function programs the correct values for
801 * HDMI/DVI use cases.
802 */
803static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder)
804{
805 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
806 u32 iboost_bit = 0;
807 int n_hdmi_entries, hdmi_level;
808 enum port port = intel_ddi_get_encoder_port(encoder);
809 const struct ddi_buf_trans *ddi_translations_hdmi;
810
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300811 hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
812
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800813 if (IS_GEN9_BC(dev_priv)) {
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300814 ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
Ville Syrjälä1edaaa22016-07-12 15:59:34 +0300815
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300816 /* If we're boosting the current, set bit 31 of trans1 */
Ville Syrjälä1edaaa22016-07-12 15:59:34 +0300817 if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300818 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
819 } else if (IS_BROADWELL(dev_priv)) {
820 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
821 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
822 } else if (IS_HASWELL(dev_priv)) {
823 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
824 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
825 } else {
826 WARN(1, "ddi translation table missing\n");
827 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
828 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
829 }
830
Paulo Zanoni6acab152013-09-12 17:06:24 -0300831 /* Entry 9 is for HDMI: */
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300832 I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
Ville Syrjälä9712e682015-09-18 20:03:22 +0300833 ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300834 I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
Ville Syrjälä9712e682015-09-18 20:03:22 +0300835 ddi_translations_hdmi[hdmi_level].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300836}
837
Paulo Zanoni248138b2012-11-29 11:29:31 -0200838static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
839 enum port port)
840{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200841 i915_reg_t reg = DDI_BUF_CTL(port);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200842 int i;
843
Vandana Kannan3449ca82015-03-27 14:19:09 +0200844 for (i = 0; i < 16; i++) {
Paulo Zanoni248138b2012-11-29 11:29:31 -0200845 udelay(1);
846 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
847 return;
848 }
849 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
850}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300851
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +0300852static uint32_t hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll)
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700853{
854 switch (pll->id) {
855 case DPLL_ID_WRPLL1:
856 return PORT_CLK_SEL_WRPLL1;
857 case DPLL_ID_WRPLL2:
858 return PORT_CLK_SEL_WRPLL2;
859 case DPLL_ID_SPLL:
860 return PORT_CLK_SEL_SPLL;
861 case DPLL_ID_LCPLL_810:
862 return PORT_CLK_SEL_LCPLL_810;
863 case DPLL_ID_LCPLL_1350:
864 return PORT_CLK_SEL_LCPLL_1350;
865 case DPLL_ID_LCPLL_2700:
866 return PORT_CLK_SEL_LCPLL_2700;
867 default:
868 MISSING_CASE(pll->id);
869 return PORT_CLK_SEL_NONE;
870 }
871}
872
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300873/* Starting with Haswell, different DDI ports can work in FDI mode for
874 * connection to the PCH-located connectors. For this, it is necessary to train
875 * both the DDI port and PCH receiver for the desired DDI buffer settings.
876 *
877 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
878 * please note that when FDI mode is active on DDI E, it shares 2 lines with
879 * DDI A (which is used for eDP)
880 */
881
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200882void hsw_fdi_link_train(struct intel_crtc *crtc,
883 const struct intel_crtc_state *crtc_state)
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300884{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +0200885 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100886 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200887 struct intel_encoder *encoder;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700888 u32 temp, i, rx_ctl_val, ddi_pll_sel;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300889
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +0200890 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200891 WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300892 intel_prepare_dp_ddi_buffers(encoder);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200893 }
894
Paulo Zanoni04945642012-11-01 21:00:59 -0200895 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
896 * mode set "sequence for CRT port" document:
897 * - TP1 to TP2 time with the default value
898 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100899 *
900 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200901 */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300902 I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200903 FDI_RX_PWRDN_LANE0_VAL(2) |
904 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
905
906 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000907 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100908 FDI_RX_PLL_ENABLE |
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200909 FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300910 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
911 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200912 udelay(220);
913
914 /* Switch from Rawclk to PCDclk */
915 rx_ctl_val |= FDI_PCDCLK;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300916 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
Paulo Zanoni04945642012-11-01 21:00:59 -0200917
918 /* Configure Port Clock Select */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200919 ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700920 I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
921 WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200922
923 /* Start the training iterating through available voltages and emphasis,
924 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300925 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300926 /* Configure DP_TP_CTL with auto-training */
927 I915_WRITE(DP_TP_CTL(PORT_E),
928 DP_TP_CTL_FDI_AUTOTRAIN |
929 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
930 DP_TP_CTL_LINK_TRAIN_PAT1 |
931 DP_TP_CTL_ENABLE);
932
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000933 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
934 * DDI E does not support port reversal, the functionality is
935 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
936 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300937 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200938 DDI_BUF_CTL_ENABLE |
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200939 ((crtc_state->fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530940 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200941 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300942
943 udelay(600);
944
Paulo Zanoni04945642012-11-01 21:00:59 -0200945 /* Program PCH FDI Receiver TU */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300946 I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300947
Paulo Zanoni04945642012-11-01 21:00:59 -0200948 /* Enable PCH FDI Receiver with auto-training */
949 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300950 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
951 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200952
953 /* Wait for FDI receiver lane calibration */
954 udelay(30);
955
956 /* Unset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300957 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200958 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300959 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
960 POSTING_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200961
962 /* Wait for FDI auto training time */
963 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300964
965 temp = I915_READ(DP_TP_STATUS(PORT_E));
966 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200967 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200968 break;
969 }
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300970
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200971 /*
972 * Leave things enabled even if we failed to train FDI.
973 * Results in less fireworks from the state checker.
974 */
975 if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
976 DRM_ERROR("FDI link training failed!\n");
977 break;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300978 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200979
Ville Syrjälä5b421c52016-03-01 16:16:23 +0200980 rx_ctl_val &= ~FDI_RX_ENABLE;
981 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
982 POSTING_READ(FDI_RX_CTL(PIPE_A));
983
Paulo Zanoni248138b2012-11-29 11:29:31 -0200984 temp = I915_READ(DDI_BUF_CTL(PORT_E));
985 temp &= ~DDI_BUF_CTL_ENABLE;
986 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
987 POSTING_READ(DDI_BUF_CTL(PORT_E));
988
Paulo Zanoni04945642012-11-01 21:00:59 -0200989 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200990 temp = I915_READ(DP_TP_CTL(PORT_E));
991 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
992 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
993 I915_WRITE(DP_TP_CTL(PORT_E), temp);
994 POSTING_READ(DP_TP_CTL(PORT_E));
995
996 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200997
Paulo Zanoni04945642012-11-01 21:00:59 -0200998 /* Reset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300999 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -02001000 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1001 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001002 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
1003 POSTING_READ(FDI_RX_MISC(PIPE_A));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -03001004 }
1005
Ville Syrjäläa308ccb2015-12-04 22:22:50 +02001006 /* Enable normal pixel sending for FDI */
1007 I915_WRITE(DP_TP_CTL(PORT_E),
1008 DP_TP_CTL_FDI_AUTOTRAIN |
1009 DP_TP_CTL_LINK_TRAIN_NORMAL |
1010 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
1011 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -03001012}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -03001013
Paulo Zanonid7c530b2017-03-30 17:57:52 -03001014static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
Dave Airlie44905a272014-05-02 13:36:43 +10001015{
1016 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1017 struct intel_digital_port *intel_dig_port =
1018 enc_to_dig_port(&encoder->base);
1019
1020 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05301021 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001022 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Dave Airlie44905a272014-05-02 13:36:43 +10001023}
1024
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001025static struct intel_encoder *
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001026intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001027{
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001028 struct drm_device *dev = crtc->base.dev;
Shashank Sharma1524e932017-03-09 19:13:41 +05301029 struct intel_encoder *encoder, *ret = NULL;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001030 int num_encoders = 0;
1031
Shashank Sharma1524e932017-03-09 19:13:41 +05301032 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
1033 ret = encoder;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001034 num_encoders++;
1035 }
1036
1037 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001038 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001039 pipe_name(crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001040
1041 BUG_ON(ret == NULL);
1042 return ret;
1043}
1044
Paulo Zanoni44a126b2017-03-22 15:58:45 -03001045/* Finds the only possible encoder associated with the given CRTC. */
1046struct intel_encoder *
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001047intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001048{
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001049 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1050 struct intel_encoder *ret = NULL;
1051 struct drm_atomic_state *state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001052 struct drm_connector *connector;
1053 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001054 int num_encoders = 0;
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001055 int i;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001056
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001057 state = crtc_state->base.state;
1058
Maarten Lankhorstb77c7a92017-03-09 15:52:01 +01001059 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001060 if (connector_state->crtc != crtc_state->base.crtc)
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001061 continue;
1062
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001063 ret = to_intel_encoder(connector_state->best_encoder);
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001064 num_encoders++;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001065 }
1066
1067 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
1068 pipe_name(crtc->pipe));
1069
1070 BUG_ON(ret == NULL);
1071 return ret;
1072}
1073
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001074#define LC_FREQ 2700
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001075
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001076static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
1077 i915_reg_t reg)
Jesse Barnes11578552014-01-21 12:42:10 -08001078{
1079 int refclk = LC_FREQ;
1080 int n, p, r;
1081 u32 wrpll;
1082
1083 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +03001084 switch (wrpll & WRPLL_PLL_REF_MASK) {
1085 case WRPLL_PLL_SSC:
1086 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -08001087 /*
1088 * We could calculate spread here, but our checking
1089 * code only cares about 5% accuracy, and spread is a max of
1090 * 0.5% downspread.
1091 */
1092 refclk = 135;
1093 break;
Daniel Vetter114fe482014-06-25 22:01:48 +03001094 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -08001095 refclk = LC_FREQ;
1096 break;
1097 default:
1098 WARN(1, "bad wrpll refclk\n");
1099 return 0;
1100 }
1101
1102 r = wrpll & WRPLL_DIVIDER_REF_MASK;
1103 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
1104 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
1105
Jesse Barnes20f0ec12014-01-22 12:58:04 -08001106 /* Convert to KHz, p & r have a fixed point portion */
1107 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -08001108}
1109
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001110static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
1111 uint32_t dpll)
1112{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001113 i915_reg_t cfgcr1_reg, cfgcr2_reg;
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001114 uint32_t cfgcr1_val, cfgcr2_val;
1115 uint32_t p0, p1, p2, dco_freq;
1116
Ville Syrjälä923c12412015-09-30 17:06:43 +03001117 cfgcr1_reg = DPLL_CFGCR1(dpll);
1118 cfgcr2_reg = DPLL_CFGCR2(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001119
1120 cfgcr1_val = I915_READ(cfgcr1_reg);
1121 cfgcr2_val = I915_READ(cfgcr2_reg);
1122
1123 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
1124 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
1125
1126 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
1127 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
1128 else
1129 p1 = 1;
1130
1131
1132 switch (p0) {
1133 case DPLL_CFGCR2_PDIV_1:
1134 p0 = 1;
1135 break;
1136 case DPLL_CFGCR2_PDIV_2:
1137 p0 = 2;
1138 break;
1139 case DPLL_CFGCR2_PDIV_3:
1140 p0 = 3;
1141 break;
1142 case DPLL_CFGCR2_PDIV_7:
1143 p0 = 7;
1144 break;
1145 }
1146
1147 switch (p2) {
1148 case DPLL_CFGCR2_KDIV_5:
1149 p2 = 5;
1150 break;
1151 case DPLL_CFGCR2_KDIV_2:
1152 p2 = 2;
1153 break;
1154 case DPLL_CFGCR2_KDIV_3:
1155 p2 = 3;
1156 break;
1157 case DPLL_CFGCR2_KDIV_1:
1158 p2 = 1;
1159 break;
1160 }
1161
1162 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
1163
1164 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
1165 1000) / 0x8000;
1166
1167 return dco_freq / (p0 * p1 * p2 * 5);
1168}
1169
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001170static int cnl_calc_wrpll_link(struct drm_i915_private *dev_priv,
1171 uint32_t pll_id)
1172{
1173 uint32_t cfgcr0, cfgcr1;
1174 uint32_t p0, p1, p2, dco_freq, ref_clock;
1175
1176 cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
1177 cfgcr1 = I915_READ(CNL_DPLL_CFGCR1(pll_id));
1178
1179 p0 = cfgcr1 & DPLL_CFGCR1_PDIV_MASK;
1180 p2 = cfgcr1 & DPLL_CFGCR1_KDIV_MASK;
1181
1182 if (cfgcr1 & DPLL_CFGCR1_QDIV_MODE(1))
1183 p1 = (cfgcr1 & DPLL_CFGCR1_QDIV_RATIO_MASK) >>
1184 DPLL_CFGCR1_QDIV_RATIO_SHIFT;
1185 else
1186 p1 = 1;
1187
1188
1189 switch (p0) {
1190 case DPLL_CFGCR1_PDIV_2:
1191 p0 = 2;
1192 break;
1193 case DPLL_CFGCR1_PDIV_3:
1194 p0 = 3;
1195 break;
1196 case DPLL_CFGCR1_PDIV_5:
1197 p0 = 5;
1198 break;
1199 case DPLL_CFGCR1_PDIV_7:
1200 p0 = 7;
1201 break;
1202 }
1203
1204 switch (p2) {
1205 case DPLL_CFGCR1_KDIV_1:
1206 p2 = 1;
1207 break;
1208 case DPLL_CFGCR1_KDIV_2:
1209 p2 = 2;
1210 break;
1211 case DPLL_CFGCR1_KDIV_4:
1212 p2 = 4;
1213 break;
1214 }
1215
1216 ref_clock = dev_priv->cdclk.hw.ref;
1217
1218 dco_freq = (cfgcr0 & DPLL_CFGCR0_DCO_INTEGER_MASK) * ref_clock;
1219
1220 dco_freq += (((cfgcr0 & DPLL_CFGCR0_DCO_FRACTION_MASK) >>
Manasi Navare442aa272017-09-14 11:31:39 -07001221 DPLL_CFGCR0_DCO_FRACTION_SHIFT) * ref_clock) / 0x8000;
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001222
Paulo Zanoni0e005882017-10-05 18:38:42 -03001223 if (WARN_ON(p0 == 0 || p1 == 0 || p2 == 0))
1224 return 0;
1225
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001226 return dco_freq / (p0 * p1 * p2 * 5);
1227}
1228
Ville Syrjälä398a0172015-06-30 15:33:51 +03001229static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
1230{
1231 int dotclock;
1232
1233 if (pipe_config->has_pch_encoder)
1234 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1235 &pipe_config->fdi_m_n);
Ville Syrjälä37a56502016-06-22 21:57:04 +03001236 else if (intel_crtc_has_dp_encoder(pipe_config))
Ville Syrjälä398a0172015-06-30 15:33:51 +03001237 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1238 &pipe_config->dp_m_n);
1239 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
1240 dotclock = pipe_config->port_clock * 2 / 3;
1241 else
1242 dotclock = pipe_config->port_clock;
1243
Shashank Sharmab22ca992017-07-24 19:19:32 +05301244 if (pipe_config->ycbcr420)
1245 dotclock *= 2;
1246
Ville Syrjälä398a0172015-06-30 15:33:51 +03001247 if (pipe_config->pixel_multiplier)
1248 dotclock /= pipe_config->pixel_multiplier;
1249
1250 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
1251}
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001252
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001253static void cnl_ddi_clock_get(struct intel_encoder *encoder,
1254 struct intel_crtc_state *pipe_config)
1255{
1256 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1257 int link_clock = 0;
1258 uint32_t cfgcr0, pll_id;
1259
1260 pll_id = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
1261
1262 cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
1263
1264 if (cfgcr0 & DPLL_CFGCR0_HDMI_MODE) {
1265 link_clock = cnl_calc_wrpll_link(dev_priv, pll_id);
1266 } else {
1267 link_clock = cfgcr0 & DPLL_CFGCR0_LINK_RATE_MASK;
1268
1269 switch (link_clock) {
1270 case DPLL_CFGCR0_LINK_RATE_810:
1271 link_clock = 81000;
1272 break;
1273 case DPLL_CFGCR0_LINK_RATE_1080:
1274 link_clock = 108000;
1275 break;
1276 case DPLL_CFGCR0_LINK_RATE_1350:
1277 link_clock = 135000;
1278 break;
1279 case DPLL_CFGCR0_LINK_RATE_1620:
1280 link_clock = 162000;
1281 break;
1282 case DPLL_CFGCR0_LINK_RATE_2160:
1283 link_clock = 216000;
1284 break;
1285 case DPLL_CFGCR0_LINK_RATE_2700:
1286 link_clock = 270000;
1287 break;
1288 case DPLL_CFGCR0_LINK_RATE_3240:
1289 link_clock = 324000;
1290 break;
1291 case DPLL_CFGCR0_LINK_RATE_4050:
1292 link_clock = 405000;
1293 break;
1294 default:
1295 WARN(1, "Unsupported link rate\n");
1296 break;
1297 }
1298 link_clock *= 2;
1299 }
1300
1301 pipe_config->port_clock = link_clock;
1302
1303 ddi_dotclock_get(pipe_config);
1304}
1305
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001306static void skl_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001307 struct intel_crtc_state *pipe_config)
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001308{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001309 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001310 int link_clock = 0;
1311 uint32_t dpll_ctl1, dpll;
1312
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001313 dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001314
1315 dpll_ctl1 = I915_READ(DPLL_CTRL1);
1316
1317 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
1318 link_clock = skl_calc_wrpll_link(dev_priv, dpll);
1319 } else {
Damien Lespiau71cd8422015-04-30 16:39:17 +01001320 link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
1321 link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001322
1323 switch (link_clock) {
Damien Lespiau71cd8422015-04-30 16:39:17 +01001324 case DPLL_CTRL1_LINK_RATE_810:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001325 link_clock = 81000;
1326 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001327 case DPLL_CTRL1_LINK_RATE_1080:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301328 link_clock = 108000;
1329 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001330 case DPLL_CTRL1_LINK_RATE_1350:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001331 link_clock = 135000;
1332 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001333 case DPLL_CTRL1_LINK_RATE_1620:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301334 link_clock = 162000;
1335 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001336 case DPLL_CTRL1_LINK_RATE_2160:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301337 link_clock = 216000;
1338 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001339 case DPLL_CTRL1_LINK_RATE_2700:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001340 link_clock = 270000;
1341 break;
1342 default:
1343 WARN(1, "Unsupported link rate\n");
1344 break;
1345 }
1346 link_clock *= 2;
1347 }
1348
1349 pipe_config->port_clock = link_clock;
1350
Ville Syrjälä398a0172015-06-30 15:33:51 +03001351 ddi_dotclock_get(pipe_config);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001352}
1353
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001354static void hsw_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001355 struct intel_crtc_state *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -08001356{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001357 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes11578552014-01-21 12:42:10 -08001358 int link_clock = 0;
1359 u32 val, pll;
1360
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001361 val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
Jesse Barnes11578552014-01-21 12:42:10 -08001362 switch (val & PORT_CLK_SEL_MASK) {
1363 case PORT_CLK_SEL_LCPLL_810:
1364 link_clock = 81000;
1365 break;
1366 case PORT_CLK_SEL_LCPLL_1350:
1367 link_clock = 135000;
1368 break;
1369 case PORT_CLK_SEL_LCPLL_2700:
1370 link_clock = 270000;
1371 break;
1372 case PORT_CLK_SEL_WRPLL1:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001373 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
Jesse Barnes11578552014-01-21 12:42:10 -08001374 break;
1375 case PORT_CLK_SEL_WRPLL2:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001376 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
Jesse Barnes11578552014-01-21 12:42:10 -08001377 break;
1378 case PORT_CLK_SEL_SPLL:
1379 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
1380 if (pll == SPLL_PLL_FREQ_810MHz)
1381 link_clock = 81000;
1382 else if (pll == SPLL_PLL_FREQ_1350MHz)
1383 link_clock = 135000;
1384 else if (pll == SPLL_PLL_FREQ_2700MHz)
1385 link_clock = 270000;
1386 else {
1387 WARN(1, "bad spll freq\n");
1388 return;
1389 }
1390 break;
1391 default:
1392 WARN(1, "bad port clock sel\n");
1393 return;
1394 }
1395
1396 pipe_config->port_clock = link_clock * 2;
1397
Ville Syrjälä398a0172015-06-30 15:33:51 +03001398 ddi_dotclock_get(pipe_config);
Jesse Barnes11578552014-01-21 12:42:10 -08001399}
1400
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301401static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
1402 enum intel_dpll_id dpll)
1403{
Imre Deakaa610dc2015-06-22 23:35:52 +03001404 struct intel_shared_dpll *pll;
1405 struct intel_dpll_hw_state *state;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03001406 struct dpll clock;
Imre Deakaa610dc2015-06-22 23:35:52 +03001407
1408 /* For DDI ports we always use a shared PLL. */
1409 if (WARN_ON(dpll == DPLL_ID_PRIVATE))
1410 return 0;
1411
1412 pll = &dev_priv->shared_dplls[dpll];
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02001413 state = &pll->state.hw_state;
Imre Deakaa610dc2015-06-22 23:35:52 +03001414
1415 clock.m1 = 2;
1416 clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
1417 if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
1418 clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
1419 clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
1420 clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
1421 clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
1422
1423 return chv_calc_dpll_params(100000, &clock);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301424}
1425
1426static void bxt_ddi_clock_get(struct intel_encoder *encoder,
1427 struct intel_crtc_state *pipe_config)
1428{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001429 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301430 enum port port = intel_ddi_get_encoder_port(encoder);
1431 uint32_t dpll = port;
1432
Ville Syrjälä398a0172015-06-30 15:33:51 +03001433 pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301434
Ville Syrjälä398a0172015-06-30 15:33:51 +03001435 ddi_dotclock_get(pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301436}
1437
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001438void intel_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001439 struct intel_crtc_state *pipe_config)
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001440{
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001441 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Damien Lespiau22606a12014-12-12 14:26:57 +00001442
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001443 if (INTEL_GEN(dev_priv) <= 8)
Damien Lespiau22606a12014-12-12 14:26:57 +00001444 hsw_ddi_clock_get(encoder, pipe_config);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001445 else if (IS_GEN9_BC(dev_priv))
Damien Lespiau22606a12014-12-12 14:26:57 +00001446 skl_ddi_clock_get(encoder, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001447 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301448 bxt_ddi_clock_get(encoder, pipe_config);
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001449 else if (IS_CANNONLAKE(dev_priv))
1450 cnl_ddi_clock_get(encoder, pipe_config);
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001451}
1452
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001453void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
Paulo Zanonidae84792012-10-15 15:51:30 -03001454{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001455 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001456 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301457 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001458 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Shashank Sharma1524e932017-03-09 19:13:41 +05301459 int type = encoder->type;
Paulo Zanonidae84792012-10-15 15:51:30 -03001460 uint32_t temp;
1461
Ville Syrjäläcca05022016-06-22 21:57:06 +03001462 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Jani Nikula4d1de972016-03-18 17:05:42 +02001463 WARN_ON(transcoder_is_dsi(cpu_transcoder));
1464
Paulo Zanonic9809792012-10-23 18:30:00 -02001465 temp = TRANS_MSA_SYNC_CLK;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001466 switch (crtc_state->pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -03001467 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -02001468 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001469 break;
1470 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -02001471 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001472 break;
1473 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -02001474 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001475 break;
1476 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -02001477 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001478 break;
1479 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001480 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -03001481 }
Paulo Zanonic9809792012-10-23 18:30:00 -02001482 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -03001483 }
1484}
1485
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001486void intel_ddi_set_vc_payload_alloc(const struct intel_crtc_state *crtc_state,
1487 bool state)
Dave Airlie0e32b392014-05-02 14:02:48 +10001488{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001489 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001490 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001491 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +10001492 uint32_t temp;
1493 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1494 if (state == true)
1495 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1496 else
1497 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1498 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1499}
1500
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001501void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001502{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001503 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Shashank Sharma1524e932017-03-09 19:13:41 +05301504 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001505 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1506 enum pipe pipe = crtc->pipe;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001507 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Shashank Sharma1524e932017-03-09 19:13:41 +05301508 enum port port = intel_ddi_get_encoder_port(encoder);
1509 int type = encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001510 uint32_t temp;
1511
Paulo Zanoniad80a812012-10-24 16:06:19 -02001512 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1513 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001514 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001515
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001516 switch (crtc_state->pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001517 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001518 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001519 break;
1520 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001521 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001522 break;
1523 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001524 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001525 break;
1526 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001527 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001528 break;
1529 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001530 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001531 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001532
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001533 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001534 temp |= TRANS_DDI_PVSYNC;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001535 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001536 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -03001537
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001538 if (cpu_transcoder == TRANSCODER_EDP) {
1539 switch (pipe) {
1540 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001541 /* On Haswell, can only use the always-on power well for
1542 * eDP when not using the panel fitter, and when not
1543 * using motion blur mitigation (which we don't
1544 * support). */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01001545 if (IS_HASWELL(dev_priv) &&
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001546 (crtc_state->pch_pfit.enabled ||
1547 crtc_state->pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001548 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1549 else
1550 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001551 break;
1552 case PIPE_B:
1553 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1554 break;
1555 case PIPE_C:
1556 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1557 break;
1558 default:
1559 BUG();
1560 break;
1561 }
1562 }
1563
Paulo Zanoni7739c332012-10-15 15:51:29 -03001564 if (type == INTEL_OUTPUT_HDMI) {
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001565 if (crtc_state->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001566 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001567 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001568 temp |= TRANS_DDI_MODE_SELECT_DVI;
Shashank Sharma15953632017-03-13 16:54:03 +05301569
1570 if (crtc_state->hdmi_scrambling)
1571 temp |= TRANS_DDI_HDMI_SCRAMBLING_MASK;
1572 if (crtc_state->hdmi_high_tmds_clock_ratio)
1573 temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001574 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001575 temp |= TRANS_DDI_MODE_SELECT_FDI;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001576 temp |= (crtc_state->fdi_lanes - 1) << 1;
Ville Syrjäläcca05022016-06-22 21:57:06 +03001577 } else if (type == INTEL_OUTPUT_DP ||
Paulo Zanoni7739c332012-10-15 15:51:29 -03001578 type == INTEL_OUTPUT_EDP) {
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001579 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001580 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
Dave Airlie0e32b392014-05-02 14:02:48 +10001581 } else if (type == INTEL_OUTPUT_DP_MST) {
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001582 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001583 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001584 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001585 WARN(1, "Invalid encoder type %d for pipe %c\n",
Shashank Sharma1524e932017-03-09 19:13:41 +05301586 encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001587 }
1588
Paulo Zanoniad80a812012-10-24 16:06:19 -02001589 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001590}
1591
Paulo Zanoniad80a812012-10-24 16:06:19 -02001592void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1593 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001594{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001595 i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001596 uint32_t val = I915_READ(reg);
1597
Dave Airlie0e32b392014-05-02 14:02:48 +10001598 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -02001599 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001600 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001601}
1602
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001603bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1604{
1605 struct drm_device *dev = intel_connector->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001606 struct drm_i915_private *dev_priv = to_i915(dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301607 struct intel_encoder *encoder = intel_connector->encoder;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001608 int type = intel_connector->base.connector_type;
Shashank Sharma1524e932017-03-09 19:13:41 +05301609 enum port port = intel_ddi_get_encoder_port(encoder);
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001610 enum pipe pipe = 0;
1611 enum transcoder cpu_transcoder;
1612 uint32_t tmp;
Imre Deake27daab2016-02-12 18:55:16 +02001613 bool ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001614
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001615 if (!intel_display_power_get_if_enabled(dev_priv,
Shashank Sharma1524e932017-03-09 19:13:41 +05301616 encoder->power_domain))
Paulo Zanoni882244a2014-04-01 14:55:12 -03001617 return false;
1618
Shashank Sharma1524e932017-03-09 19:13:41 +05301619 if (!encoder->get_hw_state(encoder, &pipe)) {
Imre Deake27daab2016-02-12 18:55:16 +02001620 ret = false;
1621 goto out;
1622 }
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001623
1624 if (port == PORT_A)
1625 cpu_transcoder = TRANSCODER_EDP;
1626 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001627 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001628
1629 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1630
1631 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1632 case TRANS_DDI_MODE_SELECT_HDMI:
1633 case TRANS_DDI_MODE_SELECT_DVI:
Imre Deake27daab2016-02-12 18:55:16 +02001634 ret = type == DRM_MODE_CONNECTOR_HDMIA;
1635 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001636
1637 case TRANS_DDI_MODE_SELECT_DP_SST:
Imre Deake27daab2016-02-12 18:55:16 +02001638 ret = type == DRM_MODE_CONNECTOR_eDP ||
1639 type == DRM_MODE_CONNECTOR_DisplayPort;
1640 break;
1641
Dave Airlie0e32b392014-05-02 14:02:48 +10001642 case TRANS_DDI_MODE_SELECT_DP_MST:
1643 /* if the transcoder is in MST state then
1644 * connector isn't connected */
Imre Deake27daab2016-02-12 18:55:16 +02001645 ret = false;
1646 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001647
1648 case TRANS_DDI_MODE_SELECT_FDI:
Imre Deake27daab2016-02-12 18:55:16 +02001649 ret = type == DRM_MODE_CONNECTOR_VGA;
1650 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001651
1652 default:
Imre Deake27daab2016-02-12 18:55:16 +02001653 ret = false;
1654 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001655 }
Imre Deake27daab2016-02-12 18:55:16 +02001656
1657out:
Shashank Sharma1524e932017-03-09 19:13:41 +05301658 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deake27daab2016-02-12 18:55:16 +02001659
1660 return ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001661}
1662
Daniel Vetter85234cd2012-07-02 13:27:29 +02001663bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1664 enum pipe *pipe)
1665{
1666 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001667 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001668 enum port port = intel_ddi_get_encoder_port(encoder);
Daniel Vetter85234cd2012-07-02 13:27:29 +02001669 u32 tmp;
1670 int i;
Imre Deake27daab2016-02-12 18:55:16 +02001671 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001672
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001673 if (!intel_display_power_get_if_enabled(dev_priv,
1674 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001675 return false;
1676
Imre Deake27daab2016-02-12 18:55:16 +02001677 ret = false;
1678
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001679 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001680
1681 if (!(tmp & DDI_BUF_CTL_ENABLE))
Imre Deake27daab2016-02-12 18:55:16 +02001682 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001683
Paulo Zanoniad80a812012-10-24 16:06:19 -02001684 if (port == PORT_A) {
1685 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001686
Paulo Zanoniad80a812012-10-24 16:06:19 -02001687 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1688 case TRANS_DDI_EDP_INPUT_A_ON:
1689 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1690 *pipe = PIPE_A;
1691 break;
1692 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1693 *pipe = PIPE_B;
1694 break;
1695 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1696 *pipe = PIPE_C;
1697 break;
1698 }
1699
Imre Deake27daab2016-02-12 18:55:16 +02001700 ret = true;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001701
Imre Deake27daab2016-02-12 18:55:16 +02001702 goto out;
1703 }
Dave Airlie0e32b392014-05-02 14:02:48 +10001704
Imre Deake27daab2016-02-12 18:55:16 +02001705 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1706 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1707
1708 if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
1709 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
1710 TRANS_DDI_MODE_SELECT_DP_MST)
1711 goto out;
1712
1713 *pipe = i;
1714 ret = true;
1715
1716 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001717 }
1718 }
1719
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001720 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001721
Imre Deake27daab2016-02-12 18:55:16 +02001722out:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001723 if (ret && IS_GEN9_LP(dev_priv)) {
Imre Deake93da0a2016-06-13 16:44:37 +03001724 tmp = I915_READ(BXT_PHY_CTL(port));
Imre Deake19c1eb2017-10-02 16:53:07 +03001725 if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK |
1726 BXT_PHY_LANE_POWERDOWN_ACK |
Imre Deake93da0a2016-06-13 16:44:37 +03001727 BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
1728 DRM_ERROR("Port %c enabled but PHY powered down? "
1729 "(PHY_CTL %08x)\n", port_name(port), tmp);
1730 }
1731
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001732 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deake27daab2016-02-12 18:55:16 +02001733
1734 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001735}
1736
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001737static u64 intel_ddi_get_power_domains(struct intel_encoder *encoder)
1738{
1739 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
1740 enum pipe pipe;
1741
1742 if (intel_ddi_get_hw_state(encoder, &pipe))
1743 return BIT_ULL(dig_port->ddi_io_power_domain);
1744
1745 return 0;
1746}
1747
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001748void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state)
Paulo Zanonifc914632012-10-05 12:05:54 -03001749{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001750 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001751 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301752 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
1753 enum port port = intel_ddi_get_encoder_port(encoder);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001754 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001755
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001756 if (cpu_transcoder != TRANSCODER_EDP)
1757 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1758 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001759}
1760
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001761void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
Paulo Zanonifc914632012-10-05 12:05:54 -03001762{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001763 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1764 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001765
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001766 if (cpu_transcoder != TRANSCODER_EDP)
1767 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1768 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001769}
1770
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001771static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1772 enum port port, uint8_t iboost)
David Weinehallf8896f52015-06-25 11:11:03 +03001773{
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001774 u32 tmp;
1775
1776 tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
1777 tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
1778 if (iboost)
1779 tmp |= iboost << BALANCE_LEG_SHIFT(port);
1780 else
1781 tmp |= BALANCE_LEG_DISABLE(port);
1782 I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
1783}
1784
1785static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
1786{
1787 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
1788 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
1789 enum port port = intel_dig_port->port;
1790 int type = encoder->type;
David Weinehallf8896f52015-06-25 11:11:03 +03001791 const struct ddi_buf_trans *ddi_translations;
1792 uint8_t iboost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001793 uint8_t dp_iboost, hdmi_iboost;
David Weinehallf8896f52015-06-25 11:11:03 +03001794 int n_entries;
David Weinehallf8896f52015-06-25 11:11:03 +03001795
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001796 /* VBT may override standard boost values */
1797 dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
1798 hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
1799
Ville Syrjäläcca05022016-06-22 21:57:06 +03001800 if (type == INTEL_OUTPUT_DP) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001801 if (dp_iboost) {
1802 iboost = dp_iboost;
1803 } else {
Rodrigo Vivida411a42017-06-09 15:02:50 -07001804 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -07001805 ddi_translations = kbl_get_buf_trans_dp(dev_priv,
1806 &n_entries);
1807 else
1808 ddi_translations = skl_get_buf_trans_dp(dev_priv,
1809 &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001810 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001811 }
David Weinehallf8896f52015-06-25 11:11:03 +03001812 } else if (type == INTEL_OUTPUT_EDP) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001813 if (dp_iboost) {
1814 iboost = dp_iboost;
1815 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001816 ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
Ville Syrjälä10afa0b2015-12-08 19:59:43 +02001817
1818 if (WARN_ON(port != PORT_A &&
1819 port != PORT_E && n_entries > 9))
1820 n_entries = 9;
1821
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001822 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001823 }
David Weinehallf8896f52015-06-25 11:11:03 +03001824 } else if (type == INTEL_OUTPUT_HDMI) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001825 if (hdmi_iboost) {
1826 iboost = hdmi_iboost;
1827 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001828 ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001829 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001830 }
David Weinehallf8896f52015-06-25 11:11:03 +03001831 } else {
1832 return;
1833 }
1834
1835 /* Make sure that the requested I_boost is valid */
1836 if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
1837 DRM_ERROR("Invalid I_boost value %u\n", iboost);
1838 return;
1839 }
1840
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001841 _skl_ddi_set_iboost(dev_priv, port, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001842
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001843 if (port == PORT_A && intel_dig_port->max_lanes == 4)
1844 _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001845}
1846
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001847static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
1848 u32 level, enum port port, int type)
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301849{
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301850 const struct bxt_ddi_buf_trans *ddi_translations;
1851 u32 n_entries, i;
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301852
Jani Nikula06411f02016-03-24 17:50:21 +02001853 if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
Sonika Jindald9d70002015-09-24 10:24:56 +05301854 n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
1855 ddi_translations = bxt_ddi_translations_edp;
Ville Syrjäläcca05022016-06-22 21:57:06 +03001856 } else if (type == INTEL_OUTPUT_DP
Sonika Jindald9d70002015-09-24 10:24:56 +05301857 || type == INTEL_OUTPUT_EDP) {
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301858 n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
1859 ddi_translations = bxt_ddi_translations_dp;
1860 } else if (type == INTEL_OUTPUT_HDMI) {
1861 n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
1862 ddi_translations = bxt_ddi_translations_hdmi;
1863 } else {
1864 DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
1865 type);
1866 return;
1867 }
1868
1869 /* Check if default value has to be used */
1870 if (level >= n_entries ||
1871 (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
1872 for (i = 0; i < n_entries; i++) {
1873 if (ddi_translations[i].default_index) {
1874 level = i;
1875 break;
1876 }
1877 }
1878 }
1879
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +03001880 bxt_ddi_phy_set_signal_level(dev_priv, port,
1881 ddi_translations[level].margin,
1882 ddi_translations[level].scale,
1883 ddi_translations[level].enable,
1884 ddi_translations[level].deemphasis);
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301885}
1886
Ville Syrjäläffe51112017-02-23 19:49:01 +02001887u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder)
1888{
1889 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1890 int n_entries;
1891
Rodrigo Vivi5fcf34b2017-08-31 07:53:56 -07001892 if (IS_CANNONLAKE(dev_priv)) {
1893 if (encoder->type == INTEL_OUTPUT_EDP)
1894 cnl_get_buf_trans_edp(dev_priv, &n_entries);
1895 else
1896 cnl_get_buf_trans_dp(dev_priv, &n_entries);
1897 } else {
1898 if (encoder->type == INTEL_OUTPUT_EDP)
1899 intel_ddi_get_buf_trans_edp(dev_priv, &n_entries);
1900 else
1901 intel_ddi_get_buf_trans_dp(dev_priv, &n_entries);
1902 }
Ville Syrjäläffe51112017-02-23 19:49:01 +02001903
1904 if (WARN_ON(n_entries < 1))
1905 n_entries = 1;
1906 if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
1907 n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
1908
1909 return index_to_dp_signal_levels[n_entries - 1] &
1910 DP_TRAIN_VOLTAGE_SWING_MASK;
1911}
1912
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001913static void cnl_ddi_vswing_program(struct drm_i915_private *dev_priv,
1914 u32 level, enum port port, int type)
1915{
1916 const struct cnl_ddi_buf_trans *ddi_translations = NULL;
Rodrigo Vivicc9cabf2017-08-29 16:22:27 -07001917 u32 n_entries, val;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001918 int ln;
1919
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001920 if (type == INTEL_OUTPUT_HDMI) {
Rodrigo Vivicc9cabf2017-08-29 16:22:27 -07001921 ddi_translations = cnl_get_buf_trans_hdmi(dev_priv, &n_entries);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001922 } else if (type == INTEL_OUTPUT_DP) {
Rodrigo Vivicc9cabf2017-08-29 16:22:27 -07001923 ddi_translations = cnl_get_buf_trans_dp(dev_priv, &n_entries);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001924 } else if (type == INTEL_OUTPUT_EDP) {
Rodrigo Vivicc9cabf2017-08-29 16:22:27 -07001925 ddi_translations = cnl_get_buf_trans_edp(dev_priv, &n_entries);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001926 }
1927
Rodrigo Vivicc9cabf2017-08-29 16:22:27 -07001928 if (WARN_ON(ddi_translations == NULL))
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001929 return;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001930
1931 if (level >= n_entries) {
1932 DRM_DEBUG_KMS("DDI translation not found for level %d. Using %d instead.", level, n_entries - 1);
1933 level = n_entries - 1;
1934 }
1935
1936 /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */
1937 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001938 val &= ~SCALING_MODE_SEL_MASK;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001939 val |= SCALING_MODE_SEL(2);
1940 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
1941
1942 /* Program PORT_TX_DW2 */
1943 val = I915_READ(CNL_PORT_TX_DW2_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001944 val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
1945 RCOMP_SCALAR_MASK);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001946 val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
1947 val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
1948 /* Rcomp scalar is fixed as 0x98 for every table entry */
1949 val |= RCOMP_SCALAR(0x98);
1950 I915_WRITE(CNL_PORT_TX_DW2_GRP(port), val);
1951
Ville Syrjälä20303eb2017-09-18 21:25:36 +03001952 /* Program PORT_TX_DW4 */
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001953 /* We cannot write to GRP. It would overrite individual loadgen */
1954 for (ln = 0; ln < 4; ln++) {
1955 val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001956 val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
1957 CURSOR_COEFF_MASK);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001958 val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
1959 val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
1960 val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
1961 I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
1962 }
1963
Ville Syrjälä20303eb2017-09-18 21:25:36 +03001964 /* Program PORT_TX_DW5 */
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001965 /* All DW5 values are fixed for every table entry */
1966 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001967 val &= ~RTERM_SELECT_MASK;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001968 val |= RTERM_SELECT(6);
1969 val |= TAP3_DISABLE;
1970 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
1971
Ville Syrjälä20303eb2017-09-18 21:25:36 +03001972 /* Program PORT_TX_DW7 */
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001973 val = I915_READ(CNL_PORT_TX_DW7_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001974 val &= ~N_SCALAR_MASK;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001975 val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
1976 I915_WRITE(CNL_PORT_TX_DW7_GRP(port), val);
1977}
1978
Clint Taylor0091abc2017-06-09 15:26:09 -07001979static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder, u32 level)
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001980{
Clint Taylor0091abc2017-06-09 15:26:09 -07001981 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1982 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1983 enum port port = intel_ddi_get_encoder_port(encoder);
1984 int type = encoder->type;
1985 int width = 0;
1986 int rate = 0;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001987 u32 val;
Clint Taylor0091abc2017-06-09 15:26:09 -07001988 int ln = 0;
1989
1990 if ((intel_dp) && (type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP)) {
1991 width = intel_dp->lane_count;
1992 rate = intel_dp->link_rate;
Rodrigo Vivi61f3e772017-07-10 13:58:52 -07001993 } else if (type == INTEL_OUTPUT_HDMI) {
Clint Taylor0091abc2017-06-09 15:26:09 -07001994 width = 4;
1995 /* Rate is always < than 6GHz for HDMI */
Rodrigo Vivi61f3e772017-07-10 13:58:52 -07001996 } else {
1997 MISSING_CASE(type);
1998 return;
Clint Taylor0091abc2017-06-09 15:26:09 -07001999 }
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07002000
2001 /*
2002 * 1. If port type is eDP or DP,
2003 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
2004 * else clear to 0b.
2005 */
2006 val = I915_READ(CNL_PORT_PCS_DW1_LN0(port));
2007 if (type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP)
2008 val |= COMMON_KEEPER_EN;
2009 else
2010 val &= ~COMMON_KEEPER_EN;
2011 I915_WRITE(CNL_PORT_PCS_DW1_GRP(port), val);
2012
2013 /* 2. Program loadgen select */
2014 /*
Clint Taylor0091abc2017-06-09 15:26:09 -07002015 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
2016 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
2017 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
2018 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07002019 */
Clint Taylor0091abc2017-06-09 15:26:09 -07002020 for (ln = 0; ln <= 3; ln++) {
2021 val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
2022 val &= ~LOADGEN_SELECT;
2023
Navare, Manasi Da8e45a12017-07-17 15:05:22 -07002024 if ((rate <= 600000 && width == 4 && ln >= 1) ||
2025 (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
Clint Taylor0091abc2017-06-09 15:26:09 -07002026 val |= LOADGEN_SELECT;
2027 }
2028 I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
2029 }
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07002030
2031 /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
2032 val = I915_READ(CNL_PORT_CL1CM_DW5);
2033 val |= SUS_CLOCK_CONFIG;
2034 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2035
2036 /* 4. Clear training enable to change swing values */
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 /* 5. Program swing and de-emphasis */
2042 cnl_ddi_vswing_program(dev_priv, level, port, type);
2043
2044 /* 6. Set training enable to trigger update */
2045 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
2046 val |= TX_TRAINING_EN;
2047 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
2048}
2049
David Weinehallf8896f52015-06-25 11:11:03 +03002050static uint32_t translate_signal_level(int signal_levels)
2051{
Ville Syrjälä97eeb872017-02-23 19:35:06 +02002052 int i;
David Weinehallf8896f52015-06-25 11:11:03 +03002053
Ville Syrjälä97eeb872017-02-23 19:35:06 +02002054 for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
2055 if (index_to_dp_signal_levels[i] == signal_levels)
2056 return i;
David Weinehallf8896f52015-06-25 11:11:03 +03002057 }
2058
Ville Syrjälä97eeb872017-02-23 19:35:06 +02002059 WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
2060 signal_levels);
2061
2062 return 0;
David Weinehallf8896f52015-06-25 11:11:03 +03002063}
2064
Rodrigo Vivi1b6e2fd2017-08-29 16:22:23 -07002065static uint32_t intel_ddi_dp_level(struct intel_dp *intel_dp)
2066{
2067 uint8_t train_set = intel_dp->train_set[0];
2068 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2069 DP_TRAIN_PRE_EMPHASIS_MASK);
2070
2071 return translate_signal_level(signal_levels);
2072}
2073
Rodrigo Vivid509af62017-08-29 16:22:24 -07002074u32 bxt_signal_levels(struct intel_dp *intel_dp)
David Weinehallf8896f52015-06-25 11:11:03 +03002075{
2076 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02002077 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
David Weinehallf8896f52015-06-25 11:11:03 +03002078 struct intel_encoder *encoder = &dport->base;
David Weinehallf8896f52015-06-25 11:11:03 +03002079 enum port port = dport->port;
Rodrigo Vivid509af62017-08-29 16:22:24 -07002080 u32 level = intel_ddi_dp_level(intel_dp);
2081
2082 if (IS_CANNONLAKE(dev_priv))
2083 cnl_ddi_vswing_sequence(encoder, level);
2084 else
2085 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
2086
2087 return 0;
2088}
2089
2090uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
2091{
2092 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2093 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
2094 struct intel_encoder *encoder = &dport->base;
Rodrigo Vivi1b6e2fd2017-08-29 16:22:23 -07002095 uint32_t level = intel_ddi_dp_level(intel_dp);
David Weinehallf8896f52015-06-25 11:11:03 +03002096
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002097 if (IS_GEN9_BC(dev_priv))
Rodrigo Vivid509af62017-08-29 16:22:24 -07002098 skl_ddi_set_iboost(encoder, level);
2099
David Weinehallf8896f52015-06-25 11:11:03 +03002100 return DDI_BUF_TRANS_SELECT(level);
2101}
2102
Paulo Zanonid7c530b2017-03-30 17:57:52 -03002103static void intel_ddi_clk_select(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002104 const struct intel_shared_dpll *pll)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002105{
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002106 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2107 enum port port = intel_ddi_get_encoder_port(encoder);
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002108 uint32_t val;
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02002109
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07002110 if (WARN_ON(!pll))
2111 return;
2112
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002113 if (IS_CANNONLAKE(dev_priv)) {
2114 /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */
2115 val = I915_READ(DPCLKA_CFGCR0);
2116 val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->id, port);
2117 I915_WRITE(DPCLKA_CFGCR0, val);
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002118
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002119 /*
2120 * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI.
2121 * This step and the step before must be done with separate
2122 * register writes.
2123 */
2124 val = I915_READ(DPCLKA_CFGCR0);
2125 val &= ~(DPCLKA_CFGCR0_DDI_CLK_OFF(port) |
2126 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port));
2127 I915_WRITE(DPCLKA_CFGCR0, val);
2128 } else if (IS_GEN9_BC(dev_priv)) {
Damien Lespiau5416d872014-11-14 17:24:33 +00002129 /* DDI -> PLL mapping */
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002130 val = I915_READ(DPLL_CTRL2);
2131
2132 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
2133 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07002134 val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002135 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
2136
2137 I915_WRITE(DPLL_CTRL2, val);
Damien Lespiau5416d872014-11-14 17:24:33 +00002138
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002139 } else if (INTEL_INFO(dev_priv)->gen < 9) {
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07002140 I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002141 }
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002142}
2143
Manasi Navareba88d152016-09-01 15:08:08 -07002144static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
2145 int link_rate, uint32_t lane_count,
2146 struct intel_shared_dpll *pll,
2147 bool link_mst)
2148{
2149 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2150 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2151 enum port port = intel_ddi_get_encoder_port(encoder);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002152 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
Rodrigo Vivi381f9572017-08-29 16:22:26 -07002153 uint32_t level = intel_ddi_dp_level(intel_dp);
Manasi Navareba88d152016-09-01 15:08:08 -07002154
Ander Conselvan de Oliveirae081c842017-03-02 14:58:57 +02002155 WARN_ON(link_mst && (port == PORT_A || port == PORT_E));
2156
Manasi Navareba88d152016-09-01 15:08:08 -07002157 intel_dp_set_link_params(intel_dp, link_rate, lane_count,
2158 link_mst);
2159 if (encoder->type == INTEL_OUTPUT_EDP)
2160 intel_edp_panel_on(intel_dp);
2161
2162 intel_ddi_clk_select(encoder, pll);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002163
2164 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
2165
Rodrigo Vivi381f9572017-08-29 16:22:26 -07002166 if (IS_CANNONLAKE(dev_priv))
2167 cnl_ddi_vswing_sequence(encoder, level);
2168 else if (IS_GEN9_LP(dev_priv))
2169 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
2170 else
Rodrigo Vivi2f7460a2017-08-29 16:22:25 -07002171 intel_prepare_dp_ddi_buffers(encoder);
2172
Manasi Navareba88d152016-09-01 15:08:08 -07002173 intel_ddi_init_dp_buf_reg(encoder);
Dhinakaran Pandiyan5ea23552017-10-03 17:22:11 +03002174 if (!link_mst)
2175 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Manasi Navareba88d152016-09-01 15:08:08 -07002176 intel_dp_start_link_train(intel_dp);
2177 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
2178 intel_dp_stop_link_train(intel_dp);
2179}
2180
2181static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
Ville Syrjäläb47ef0f2017-08-18 16:49:52 +03002182 bool has_infoframe,
Maarten Lankhorstac240282016-11-23 15:57:00 +01002183 const struct intel_crtc_state *crtc_state,
2184 const struct drm_connector_state *conn_state,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002185 const struct intel_shared_dpll *pll)
Manasi Navareba88d152016-09-01 15:08:08 -07002186{
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002187 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
2188 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Manasi Navareba88d152016-09-01 15:08:08 -07002189 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Manasi Navareba88d152016-09-01 15:08:08 -07002190 enum port port = intel_ddi_get_encoder_port(encoder);
2191 int level = intel_ddi_hdmi_level(dev_priv, port);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002192 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
Manasi Navareba88d152016-09-01 15:08:08 -07002193
2194 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
2195 intel_ddi_clk_select(encoder, pll);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002196
2197 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
2198
Rodrigo Vivi2f7460a2017-08-29 16:22:25 -07002199 if (IS_CANNONLAKE(dev_priv))
2200 cnl_ddi_vswing_sequence(encoder, level);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002201 else if (IS_GEN9_LP(dev_priv))
Manasi Navareba88d152016-09-01 15:08:08 -07002202 bxt_ddi_vswing_sequence(dev_priv, level, port,
2203 INTEL_OUTPUT_HDMI);
Rodrigo Vivi2f7460a2017-08-29 16:22:25 -07002204 else
2205 intel_prepare_hdmi_ddi_buffers(encoder);
2206
2207 if (IS_GEN9_BC(dev_priv))
2208 skl_ddi_set_iboost(encoder, level);
Manasi Navareba88d152016-09-01 15:08:08 -07002209
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002210 intel_dig_port->set_infoframes(&encoder->base,
2211 has_infoframe,
2212 crtc_state, conn_state);
Manasi Navareba88d152016-09-01 15:08:08 -07002213}
2214
Shashank Sharma1524e932017-03-09 19:13:41 +05302215static void intel_ddi_pre_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002216 const struct intel_crtc_state *pipe_config,
2217 const struct drm_connector_state *conn_state)
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002218{
Jani Nikula364a3fe2017-10-05 13:52:12 +03002219 struct drm_crtc *crtc = pipe_config->base.crtc;
2220 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
2221 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2222 int pipe = intel_crtc->pipe;
Shashank Sharma1524e932017-03-09 19:13:41 +05302223 int type = encoder->type;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +02002224
Jani Nikula364a3fe2017-10-05 13:52:12 +03002225 WARN_ON(intel_crtc->config->has_pch_encoder);
2226
2227 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2228
Ville Syrjäläcca05022016-06-22 21:57:06 +03002229 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
Shashank Sharma1524e932017-03-09 19:13:41 +05302230 intel_ddi_pre_enable_dp(encoder,
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02002231 pipe_config->port_clock,
2232 pipe_config->lane_count,
2233 pipe_config->shared_dpll,
2234 intel_crtc_has_type(pipe_config,
Manasi Navareba88d152016-09-01 15:08:08 -07002235 INTEL_OUTPUT_DP_MST));
2236 }
2237 if (type == INTEL_OUTPUT_HDMI) {
Shashank Sharma1524e932017-03-09 19:13:41 +05302238 intel_ddi_pre_enable_hdmi(encoder,
Ville Syrjäläb47ef0f2017-08-18 16:49:52 +03002239 pipe_config->has_infoframe,
Maarten Lankhorstac240282016-11-23 15:57:00 +01002240 pipe_config, conn_state,
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02002241 pipe_config->shared_dpll);
Paulo Zanonic19b0662012-10-15 15:51:41 -03002242 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002243}
2244
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002245static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002246 const struct intel_crtc_state *old_crtc_state,
2247 const struct drm_connector_state *old_conn_state)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002248{
2249 struct drm_encoder *encoder = &intel_encoder->base;
Tvrtko Ursulin66478472016-11-16 08:55:40 +00002250 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002251 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002252 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02002253 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03002254 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03002255 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03002256
Imre Deak76181382017-05-31 20:05:35 +03002257 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
Dhinakaran Pandiyan5ea23552017-10-03 17:22:11 +03002258 /*
2259 * old_crtc_state and old_conn_state are NULL when called from
2260 * DP_MST. The main connector associated with this port is never
2261 * bound to a crtc for MST.
2262 */
2263 bool is_mst = !old_crtc_state;
Ville Syrjäläc5f93fc2017-08-22 17:09:14 +03002264 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2265
Dhinakaran Pandiyan5ea23552017-10-03 17:22:11 +03002266 /*
2267 * Power down sink before disabling the port, otherwise we end
2268 * up getting interrupts from the sink on detecting link loss.
2269 */
2270 if (!is_mst)
2271 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Imre Deak76181382017-05-31 20:05:35 +03002272 }
2273
Paulo Zanoni2886e932012-10-05 12:06:00 -03002274 val = I915_READ(DDI_BUF_CTL(port));
2275 if (val & DDI_BUF_CTL_ENABLE) {
2276 val &= ~DDI_BUF_CTL_ENABLE;
2277 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03002278 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03002279 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002280
Paulo Zanonia836bdf2012-10-15 15:51:32 -03002281 val = I915_READ(DP_TP_CTL(port));
2282 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2283 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2284 I915_WRITE(DP_TP_CTL(port), val);
2285
2286 if (wait)
2287 intel_wait_ddi_buf_idle(dev_priv, port);
2288
Ville Syrjäläc5f93fc2017-08-22 17:09:14 +03002289 if (type == INTEL_OUTPUT_HDMI) {
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002290 dig_port->set_infoframes(encoder, false,
2291 old_crtc_state, old_conn_state);
Ville Syrjäläc5f93fc2017-08-22 17:09:14 +03002292 }
2293
2294 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
2295 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2296
Jani Nikula24f3e092014-03-17 16:43:36 +02002297 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002298 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02002299 }
2300
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002301 if (dig_port)
2302 intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
2303
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002304 if (IS_CANNONLAKE(dev_priv))
2305 I915_WRITE(DPCLKA_CFGCR0, I915_READ(DPCLKA_CFGCR0) |
2306 DPCLKA_CFGCR0_DDI_CLK_OFF(port));
2307 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002308 I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
2309 DPLL_CTRL2_DDI_CLK_OFF(port)));
Tvrtko Ursulin66478472016-11-16 08:55:40 +00002310 else if (INTEL_GEN(dev_priv) < 9)
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002311 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
Ville Syrjäläb2ccb822016-05-02 22:08:24 +03002312
2313 if (type == INTEL_OUTPUT_HDMI) {
2314 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
2315
2316 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
2317 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002318}
2319
Shashank Sharma1524e932017-03-09 19:13:41 +05302320void intel_ddi_fdi_post_disable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002321 const struct intel_crtc_state *old_crtc_state,
2322 const struct drm_connector_state *old_conn_state)
Maarten Lankhorstb7076542016-08-23 16:18:08 +02002323{
Shashank Sharma1524e932017-03-09 19:13:41 +05302324 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Maarten Lankhorstb7076542016-08-23 16:18:08 +02002325 uint32_t val;
2326
2327 /*
2328 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
2329 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
2330 * step 13 is the correct place for it. Step 18 is where it was
2331 * originally before the BUN.
2332 */
2333 val = I915_READ(FDI_RX_CTL(PIPE_A));
2334 val &= ~FDI_RX_ENABLE;
2335 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2336
Shashank Sharma1524e932017-03-09 19:13:41 +05302337 intel_ddi_post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstb7076542016-08-23 16:18:08 +02002338
2339 val = I915_READ(FDI_RX_MISC(PIPE_A));
2340 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
2341 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
2342 I915_WRITE(FDI_RX_MISC(PIPE_A), val);
2343
2344 val = I915_READ(FDI_RX_CTL(PIPE_A));
2345 val &= ~FDI_PCDCLK;
2346 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2347
2348 val = I915_READ(FDI_RX_CTL(PIPE_A));
2349 val &= ~FDI_RX_PLL_ENABLE;
2350 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2351}
2352
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002353static void intel_enable_ddi(struct intel_encoder *intel_encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002354 const struct intel_crtc_state *pipe_config,
2355 const struct drm_connector_state *conn_state)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002356{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002357 struct drm_encoder *encoder = &intel_encoder->base;
Tvrtko Ursulin66478472016-11-16 08:55:40 +00002358 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002359 enum port port = intel_ddi_get_encoder_port(intel_encoder);
2360 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002361
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002362 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002363 struct intel_digital_port *intel_dig_port =
2364 enc_to_dig_port(encoder);
Shashank Sharma15953632017-03-13 16:54:03 +05302365 bool clock_ratio = pipe_config->hdmi_high_tmds_clock_ratio;
2366 bool scrambling = pipe_config->hdmi_scrambling;
2367
2368 intel_hdmi_handle_sink_scrambling(intel_encoder,
2369 conn_state->connector,
2370 clock_ratio, scrambling);
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002371
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002372 /* In HDMI/DVI mode, the port width, and swing/emphasis values
2373 * are ignored so nothing special needs to be done besides
2374 * enabling the port.
2375 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002376 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de42013-07-12 13:54:41 -07002377 intel_dig_port->saved_port_bits |
2378 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002379 } else if (type == INTEL_OUTPUT_EDP) {
2380 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2381
Tvrtko Ursulin66478472016-11-16 08:55:40 +00002382 if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03002383 intel_dp_stop_link_train(intel_dp);
2384
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002385 intel_edp_backlight_on(pipe_config, conn_state);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002386 intel_psr_enable(intel_dp, pipe_config);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002387 intel_edp_drrs_enable(intel_dp, pipe_config);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002388 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08002389
Maarten Lankhorst37255d82016-12-15 15:29:43 +01002390 if (pipe_config->has_audio)
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002391 intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002392}
2393
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002394static void intel_disable_ddi(struct intel_encoder *intel_encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002395 const struct intel_crtc_state *old_crtc_state,
2396 const struct drm_connector_state *old_conn_state)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002397{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002398 struct drm_encoder *encoder = &intel_encoder->base;
2399 int type = intel_encoder->type;
2400
Maarten Lankhorst37255d82016-12-15 15:29:43 +01002401 if (old_crtc_state->has_audio)
Jani Nikula69bfe1a2014-10-27 16:26:50 +02002402 intel_audio_codec_disable(intel_encoder);
Paulo Zanoni2831d8422013-03-06 20:03:09 -03002403
Shashank Sharma15953632017-03-13 16:54:03 +05302404 if (type == INTEL_OUTPUT_HDMI) {
2405 intel_hdmi_handle_sink_scrambling(intel_encoder,
2406 old_conn_state->connector,
2407 false, false);
2408 }
2409
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002410 if (type == INTEL_OUTPUT_EDP) {
2411 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2412
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002413 intel_edp_drrs_disable(intel_dp, old_crtc_state);
Ville Syrjäläd2419ff2017-08-18 16:49:56 +03002414 intel_psr_disable(intel_dp, old_crtc_state);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002415 intel_edp_backlight_off(old_conn_state);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002416 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002417}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002418
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002419static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002420 const struct intel_crtc_state *pipe_config,
2421 const struct drm_connector_state *conn_state)
Imre Deak95a7a2a2016-06-13 16:44:35 +03002422{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02002423 uint8_t mask = pipe_config->lane_lat_optim_mask;
Imre Deak95a7a2a2016-06-13 16:44:35 +03002424
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +03002425 bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002426}
2427
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03002428void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
Paulo Zanonic19b0662012-10-15 15:51:41 -03002429{
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03002430 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2431 struct drm_i915_private *dev_priv =
2432 to_i915(intel_dig_port->base.base.dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02002433 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002434 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05302435 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002436
2437 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
2438 val = I915_READ(DDI_BUF_CTL(port));
2439 if (val & DDI_BUF_CTL_ENABLE) {
2440 val &= ~DDI_BUF_CTL_ENABLE;
2441 I915_WRITE(DDI_BUF_CTL(port), val);
2442 wait = true;
2443 }
2444
2445 val = I915_READ(DP_TP_CTL(port));
2446 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2447 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2448 I915_WRITE(DP_TP_CTL(port), val);
2449 POSTING_READ(DP_TP_CTL(port));
2450
2451 if (wait)
2452 intel_wait_ddi_buf_idle(dev_priv, port);
2453 }
2454
Dave Airlie0e32b392014-05-02 14:02:48 +10002455 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03002456 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03002457 if (intel_dp->link_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10002458 val |= DP_TP_CTL_MODE_MST;
2459 else {
2460 val |= DP_TP_CTL_MODE_SST;
2461 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2462 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
2463 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03002464 I915_WRITE(DP_TP_CTL(port), val);
2465 POSTING_READ(DP_TP_CTL(port));
2466
2467 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
2468 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
2469 POSTING_READ(DDI_BUF_CTL(port));
2470
2471 udelay(600);
2472}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002473
Libin Yang9935f7f2016-11-28 20:07:06 +08002474bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
2475 struct intel_crtc *intel_crtc)
2476{
2477 u32 temp;
2478
2479 if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
2480 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
2481 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
2482 return true;
2483 }
2484 return false;
2485}
2486
Ville Syrjälä6801c182013-09-24 14:24:05 +03002487void intel_ddi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002488 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002489{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002490 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002491 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +02002492 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002493 struct intel_digital_port *intel_dig_port;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002494 u32 temp, flags = 0;
2495
Jani Nikula4d1de972016-03-18 17:05:42 +02002496 /* XXX: DSI transcoder paranoia */
2497 if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
2498 return;
2499
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002500 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
2501 if (temp & TRANS_DDI_PHSYNC)
2502 flags |= DRM_MODE_FLAG_PHSYNC;
2503 else
2504 flags |= DRM_MODE_FLAG_NHSYNC;
2505 if (temp & TRANS_DDI_PVSYNC)
2506 flags |= DRM_MODE_FLAG_PVSYNC;
2507 else
2508 flags |= DRM_MODE_FLAG_NVSYNC;
2509
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002510 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03002511
2512 switch (temp & TRANS_DDI_BPC_MASK) {
2513 case TRANS_DDI_BPC_6:
2514 pipe_config->pipe_bpp = 18;
2515 break;
2516 case TRANS_DDI_BPC_8:
2517 pipe_config->pipe_bpp = 24;
2518 break;
2519 case TRANS_DDI_BPC_10:
2520 pipe_config->pipe_bpp = 30;
2521 break;
2522 case TRANS_DDI_BPC_12:
2523 pipe_config->pipe_bpp = 36;
2524 break;
2525 default:
2526 break;
2527 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002528
2529 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
2530 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02002531 pipe_config->has_hdmi_sink = true;
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002532 intel_dig_port = enc_to_dig_port(&encoder->base);
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002533
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002534 if (intel_dig_port->infoframe_enabled(&encoder->base, pipe_config))
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002535 pipe_config->has_infoframe = true;
Shashank Sharma15953632017-03-13 16:54:03 +05302536
2537 if ((temp & TRANS_DDI_HDMI_SCRAMBLING_MASK) ==
2538 TRANS_DDI_HDMI_SCRAMBLING_MASK)
2539 pipe_config->hdmi_scrambling = true;
2540 if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
2541 pipe_config->hdmi_high_tmds_clock_ratio = true;
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002542 /* fall through */
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002543 case TRANS_DDI_MODE_SELECT_DVI:
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002544 pipe_config->lane_count = 4;
2545 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002546 case TRANS_DDI_MODE_SELECT_FDI:
2547 break;
2548 case TRANS_DDI_MODE_SELECT_DP_SST:
2549 case TRANS_DDI_MODE_SELECT_DP_MST:
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002550 pipe_config->lane_count =
2551 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002552 intel_dp_get_m_n(intel_crtc, pipe_config);
2553 break;
2554 default:
2555 break;
2556 }
Daniel Vetter10214422013-11-18 07:38:16 +01002557
Libin Yang9935f7f2016-11-28 20:07:06 +08002558 pipe_config->has_audio =
2559 intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002560
Jani Nikula6aa23e62016-03-24 17:50:20 +02002561 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
2562 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Daniel Vetter10214422013-11-18 07:38:16 +01002563 /*
2564 * This is a big fat ugly hack.
2565 *
2566 * Some machines in UEFI boot mode provide us a VBT that has 18
2567 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2568 * unknown we fail to light up. Yet the same BIOS boots up with
2569 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2570 * max, not what it tells us to use.
2571 *
2572 * Note: This will still be broken if the eDP panel is not lit
2573 * up by the BIOS, and thus we can't get the mode at module
2574 * load.
2575 */
2576 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002577 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2578 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Daniel Vetter10214422013-11-18 07:38:16 +01002579 }
Jesse Barnes11578552014-01-21 12:42:10 -08002580
Damien Lespiau22606a12014-12-12 14:26:57 +00002581 intel_ddi_clock_get(encoder, pipe_config);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002582
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002583 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002584 pipe_config->lane_lat_optim_mask =
2585 bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002586}
2587
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002588static bool intel_ddi_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002589 struct intel_crtc_state *pipe_config,
2590 struct drm_connector_state *conn_state)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002591{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002592 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002593 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02002594 int port = intel_ddi_get_encoder_port(encoder);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002595 int ret;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002596
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002597 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002598
Daniel Vettereccb1402013-05-22 00:50:22 +02002599 if (port == PORT_A)
2600 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2601
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002602 if (type == INTEL_OUTPUT_HDMI)
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002603 ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002604 else
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002605 ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002606
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002607 if (IS_GEN9_LP(dev_priv) && ret)
Imre Deak95a7a2a2016-06-13 16:44:35 +03002608 pipe_config->lane_lat_optim_mask =
2609 bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
Ander Conselvan de Oliveirab284eed2016-10-06 19:22:16 +03002610 pipe_config->lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002611
2612 return ret;
2613
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002614}
2615
2616static const struct drm_encoder_funcs intel_ddi_funcs = {
Imre Deakbf93ba62016-04-18 10:04:21 +03002617 .reset = intel_dp_encoder_reset,
2618 .destroy = intel_dp_encoder_destroy,
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002619};
2620
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002621static struct intel_connector *
2622intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2623{
2624 struct intel_connector *connector;
2625 enum port port = intel_dig_port->port;
2626
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002627 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002628 if (!connector)
2629 return NULL;
2630
2631 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2632 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2633 kfree(connector);
2634 return NULL;
2635 }
2636
2637 return connector;
2638}
2639
2640static struct intel_connector *
2641intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2642{
2643 struct intel_connector *connector;
2644 enum port port = intel_dig_port->port;
2645
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002646 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002647 if (!connector)
2648 return NULL;
2649
2650 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2651 intel_hdmi_init_connector(intel_dig_port, connector);
2652
2653 return connector;
2654}
2655
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002656void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002657{
2658 struct intel_digital_port *intel_dig_port;
2659 struct intel_encoder *intel_encoder;
2660 struct drm_encoder *encoder;
Shashank Sharmaff662122016-10-14 19:56:51 +05302661 bool init_hdmi, init_dp, init_lspcon = false;
Ville Syrjälä10e7bec2015-12-08 19:59:37 +02002662 int max_lanes;
2663
2664 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
2665 switch (port) {
2666 case PORT_A:
2667 max_lanes = 4;
2668 break;
2669 case PORT_E:
2670 max_lanes = 0;
2671 break;
2672 default:
2673 max_lanes = 4;
2674 break;
2675 }
2676 } else {
2677 switch (port) {
2678 case PORT_A:
2679 max_lanes = 2;
2680 break;
2681 case PORT_E:
2682 max_lanes = 2;
2683 break;
2684 default:
2685 max_lanes = 4;
2686 break;
2687 }
2688 }
Paulo Zanoni311a2092013-09-12 17:12:18 -03002689
2690 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2691 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2692 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
Shashank Sharmaff662122016-10-14 19:56:51 +05302693
2694 if (intel_bios_is_lspcon_present(dev_priv, port)) {
2695 /*
2696 * Lspcon device needs to be driven with DP connector
2697 * with special detection sequence. So make sure DP
2698 * is initialized before lspcon.
2699 */
2700 init_dp = true;
2701 init_lspcon = true;
2702 init_hdmi = false;
2703 DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
2704 }
2705
Paulo Zanoni311a2092013-09-12 17:12:18 -03002706 if (!init_dp && !init_hdmi) {
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002707 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03002708 port_name(port));
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002709 return;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002710 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002711
Daniel Vetterb14c5672013-09-19 12:18:32 +02002712 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002713 if (!intel_dig_port)
2714 return;
2715
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002716 intel_encoder = &intel_dig_port->base;
2717 encoder = &intel_encoder->base;
2718
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002719 drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03002720 DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002721
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002722 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002723 intel_encoder->enable = intel_enable_ddi;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002724 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002725 intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002726 intel_encoder->pre_enable = intel_ddi_pre_enable;
2727 intel_encoder->disable = intel_disable_ddi;
2728 intel_encoder->post_disable = intel_ddi_post_disable;
2729 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002730 intel_encoder->get_config = intel_ddi_get_config;
Imre Deakbf93ba62016-04-18 10:04:21 +03002731 intel_encoder->suspend = intel_dp_encoder_suspend;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002732 intel_encoder->get_power_domains = intel_ddi_get_power_domains;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002733
2734 intel_dig_port->port = port;
Stéphane Marchesinbcf53de42013-07-12 13:54:41 -07002735 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2736 (DDI_BUF_PORT_REVERSAL |
2737 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002738
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002739 switch (port) {
2740 case PORT_A:
2741 intel_dig_port->ddi_io_power_domain =
2742 POWER_DOMAIN_PORT_DDI_A_IO;
2743 break;
2744 case PORT_B:
2745 intel_dig_port->ddi_io_power_domain =
2746 POWER_DOMAIN_PORT_DDI_B_IO;
2747 break;
2748 case PORT_C:
2749 intel_dig_port->ddi_io_power_domain =
2750 POWER_DOMAIN_PORT_DDI_C_IO;
2751 break;
2752 case PORT_D:
2753 intel_dig_port->ddi_io_power_domain =
2754 POWER_DOMAIN_PORT_DDI_D_IO;
2755 break;
2756 case PORT_E:
2757 intel_dig_port->ddi_io_power_domain =
2758 POWER_DOMAIN_PORT_DDI_E_IO;
2759 break;
2760 default:
2761 MISSING_CASE(port);
2762 }
2763
Matt Roper6c566dc2015-11-05 14:53:32 -08002764 /*
2765 * Bspec says that DDI_A_4_LANES is the only supported configuration
2766 * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
2767 * wasn't lit up at boot. Force this bit on in our internal
2768 * configuration so that we use the proper lane count for our
2769 * calculations.
2770 */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002771 if (IS_GEN9_LP(dev_priv) && port == PORT_A) {
Matt Roper6c566dc2015-11-05 14:53:32 -08002772 if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
2773 DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
2774 intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
Matt Ropered8d60f2016-01-28 15:09:37 -08002775 max_lanes = 4;
Matt Roper6c566dc2015-11-05 14:53:32 -08002776 }
2777 }
2778
Matt Ropered8d60f2016-01-28 15:09:37 -08002779 intel_dig_port->max_lanes = max_lanes;
2780
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002781 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002782 intel_encoder->power_domain = intel_port_to_power_domain(port);
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07002783 intel_encoder->port = port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002784 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02002785 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002786
Ville Syrjälä385e4de2017-08-18 16:49:55 +03002787 intel_infoframe_init(intel_dig_port);
2788
Chris Wilsonf68d6972014-08-04 07:15:09 +01002789 if (init_dp) {
2790 if (!intel_ddi_init_dp_connector(intel_dig_port))
2791 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10002792
Chris Wilsonf68d6972014-08-04 07:15:09 +01002793 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Ander Conselvan de Oliveiraca4c3892017-02-03 16:03:13 +02002794 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002795 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002796
Paulo Zanoni311a2092013-09-12 17:12:18 -03002797 /* In theory we don't need the encoder->type check, but leave it just in
2798 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01002799 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2800 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2801 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002802 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01002803
Shashank Sharmaff662122016-10-14 19:56:51 +05302804 if (init_lspcon) {
2805 if (lspcon_init(intel_dig_port))
2806 /* TODO: handle hdmi info frame part */
2807 DRM_DEBUG_KMS("LSPCON init success on port %c\n",
2808 port_name(port));
2809 else
2810 /*
2811 * LSPCON init faied, but DP init was success, so
2812 * lets try to drive as DP++ port.
2813 */
2814 DRM_ERROR("LSPCON init failed on port %c\n",
2815 port_name(port));
2816 }
2817
Chris Wilsonf68d6972014-08-04 07:15:09 +01002818 return;
2819
2820err:
2821 drm_encoder_cleanup(encoder);
2822 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002823}