blob: ee75d3ba89ae0a5cae863aad2a0ca6dce0ae8923 [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 {
304 u32 margin; /* swing value */
305 u32 scale; /* scale value */
306 u32 enable; /* scale enable */
307 u32 deemphasis;
308 bool default_index; /* true if the entry represents default value */
309};
310
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 {
357 u32 dw2_swing_sel;
358 u32 dw7_n_scalar;
359 u32 dw4_cursor_coeff;
360 u32 dw4_post_cursor_2;
361 u32 dw4_post_cursor_1;
362};
363
364/* Voltage Swing Programming for VccIO 0.85V for DP */
365static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V[] = {
366 /* NT mV Trans mV db */
367 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
368 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
369 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
370 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
371 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
372 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
373 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
374 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
375 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
376 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
377};
378
379/* Voltage Swing Programming for VccIO 0.85V for HDMI */
380static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V[] = {
381 /* NT mV Trans mV db */
382 { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
383 { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */
384 { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */
385 { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 */
386 { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */
387 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */
388 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
389};
390
391/* Voltage Swing Programming for VccIO 0.85V for eDP */
392static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V[] = {
393 /* NT mV Trans mV db */
394 { 0xA, 0x66, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
395 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
396 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
397 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
398 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
399 { 0xA, 0x66, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
400 { 0xB, 0x70, 0x3C, 0x00, 0x03 }, /* 460 600 2.3 */
401 { 0xC, 0x75, 0x3C, 0x00, 0x03 }, /* 537 700 2.3 */
402 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
403};
404
405/* Voltage Swing Programming for VccIO 0.95V for DP */
406static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V[] = {
407 /* NT mV Trans mV db */
408 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
409 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
410 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
411 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
412 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
413 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
414 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
415 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
416 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
417 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
418};
419
420/* Voltage Swing Programming for VccIO 0.95V for HDMI */
421static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V[] = {
422 /* NT mV Trans mV db */
423 { 0xA, 0x5C, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
424 { 0xB, 0x69, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
425 { 0x5, 0x76, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
426 { 0xA, 0x5E, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
427 { 0xB, 0x69, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
428 { 0xB, 0x79, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
429 { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
430 { 0x5, 0x76, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
431 { 0x6, 0x7D, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
432 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
433 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
434};
435
436/* Voltage Swing Programming for VccIO 0.95V for eDP */
437static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V[] = {
438 /* NT mV Trans mV db */
439 { 0xA, 0x61, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
440 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
441 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
442 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
443 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
444 { 0xA, 0x61, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
445 { 0xB, 0x68, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
446 { 0xC, 0x6E, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
447 { 0x4, 0x7F, 0x3A, 0x00, 0x05 }, /* 460 600 2.3 */
448 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
449};
450
451/* Voltage Swing Programming for VccIO 1.05V for DP */
452static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V[] = {
453 /* NT mV Trans mV db */
454 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
455 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
456 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
457 { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 400 1050 8.4 */
458 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
459 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
460 { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 550 1050 5.6 */
461 { 0x5, 0x76, 0x3E, 0x00, 0x01 }, /* 850 900 0.5 */
462 { 0x6, 0x7F, 0x36, 0x00, 0x09 }, /* 750 1050 2.9 */
463 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
464};
465
466/* Voltage Swing Programming for VccIO 1.05V for HDMI */
467static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V[] = {
468 /* NT mV Trans mV db */
469 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
470 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
471 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
472 { 0xA, 0x5B, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
473 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
474 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
475 { 0x6, 0x7C, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
476 { 0x5, 0x70, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
477 { 0x6, 0x7C, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
478 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
479 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
480};
481
482/* Voltage Swing Programming for VccIO 1.05V for eDP */
483static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V[] = {
484 /* NT mV Trans mV db */
485 { 0xA, 0x5E, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
486 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
487 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
488 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
489 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
490 { 0xA, 0x5E, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
491 { 0xB, 0x64, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
492 { 0xE, 0x6A, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
493 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
494};
495
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;
547 } else if (IS_KBL_ULT(dev_priv)) {
548 *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
549 return kbl_u_ddi_translations_dp;
550 } else {
551 *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
552 return kbl_ddi_translations_dp;
553 }
554}
555
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;
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200563 } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200564 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
565 return skl_u_ddi_translations_edp;
566 } else {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200567 *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
568 return skl_ddi_translations_edp;
Ville Syrjäläacee2992015-12-08 19:59:39 +0200569 }
David Weinehallf8896f52015-06-25 11:11:03 +0300570 }
Ville Syrjäläcd1101c2015-12-08 19:59:40 +0200571
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700572 if (IS_KABYLAKE(dev_priv))
573 return kbl_get_buf_trans_dp(dev_priv, n_entries);
574 else
575 return skl_get_buf_trans_dp(dev_priv, n_entries);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200576}
David Weinehallf8896f52015-06-25 11:11:03 +0300577
Ville Syrjäläacee2992015-12-08 19:59:39 +0200578static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200579skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
Ville Syrjäläacee2992015-12-08 19:59:39 +0200580{
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200581 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200582 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
583 return skl_y_ddi_translations_hdmi;
584 } else {
585 *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
586 return skl_ddi_translations_hdmi;
587 }
David Weinehallf8896f52015-06-25 11:11:03 +0300588}
589
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300590static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
591{
592 int n_hdmi_entries;
593 int hdmi_level;
594 int hdmi_default_entry;
595
596 hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
597
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200598 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300599 return hdmi_level;
600
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800601 if (IS_GEN9_BC(dev_priv)) {
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300602 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
603 hdmi_default_entry = 8;
604 } else if (IS_BROADWELL(dev_priv)) {
605 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
606 hdmi_default_entry = 7;
607 } else if (IS_HASWELL(dev_priv)) {
608 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
609 hdmi_default_entry = 6;
610 } else {
611 WARN(1, "ddi translation table missing\n");
612 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
613 hdmi_default_entry = 7;
614 }
615
616 /* Choose a good default if VBT is badly populated */
617 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
618 hdmi_level >= n_hdmi_entries)
619 hdmi_level = hdmi_default_entry;
620
621 return hdmi_level;
622}
623
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200624static const struct ddi_buf_trans *
625intel_ddi_get_buf_trans_dp(struct drm_i915_private *dev_priv,
626 int *n_entries)
627{
628 if (IS_KABYLAKE(dev_priv)) {
629 return kbl_get_buf_trans_dp(dev_priv, n_entries);
630 } else if (IS_SKYLAKE(dev_priv)) {
631 return skl_get_buf_trans_dp(dev_priv, n_entries);
632 } else if (IS_BROADWELL(dev_priv)) {
633 *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
634 return bdw_ddi_translations_dp;
635 } else if (IS_HASWELL(dev_priv)) {
636 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
637 return hsw_ddi_translations_dp;
638 }
639
640 *n_entries = 0;
641 return NULL;
642}
643
644static const struct ddi_buf_trans *
645intel_ddi_get_buf_trans_edp(struct drm_i915_private *dev_priv,
646 int *n_entries)
647{
648 if (IS_KABYLAKE(dev_priv) || IS_SKYLAKE(dev_priv)) {
649 return skl_get_buf_trans_edp(dev_priv, n_entries);
650 } else if (IS_BROADWELL(dev_priv)) {
651 return bdw_get_buf_trans_edp(dev_priv, n_entries);
652 } else if (IS_HASWELL(dev_priv)) {
653 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
654 return hsw_ddi_translations_dp;
655 }
656
657 *n_entries = 0;
658 return NULL;
659}
660
661static const struct ddi_buf_trans *
662intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv,
663 int *n_entries)
664{
665 if (IS_BROADWELL(dev_priv)) {
666 *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
667 return hsw_ddi_translations_fdi;
668 } else if (IS_HASWELL(dev_priv)) {
669 *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
670 return hsw_ddi_translations_fdi;
671 }
672
673 *n_entries = 0;
674 return NULL;
675}
676
Art Runyane58623c2013-11-02 21:07:41 -0700677/*
678 * Starting with Haswell, DDI port buffers must be programmed with correct
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300679 * values in advance. This function programs the correct values for
680 * DP/eDP/FDI use cases.
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300681 */
Paulo Zanonid7c530b2017-03-30 17:57:52 -0300682static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300683{
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200684 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300685 u32 iboost_bit = 0;
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200686 int i, n_entries;
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300687 enum port port = intel_ddi_get_encoder_port(encoder);
Jani Nikula10122052014-08-27 16:27:30 +0300688 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700689
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200690 if (IS_GEN9_LP(dev_priv))
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530691 return;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200692
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200693 switch (encoder->type) {
694 case INTEL_OUTPUT_EDP:
695 ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv,
696 &n_entries);
697 break;
698 case INTEL_OUTPUT_DP:
699 ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv,
700 &n_entries);
701 break;
702 case INTEL_OUTPUT_ANALOG:
703 ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
704 &n_entries);
705 break;
706 default:
707 MISSING_CASE(encoder->type);
708 return;
Art Runyane58623c2013-11-02 21:07:41 -0700709 }
710
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800711 if (IS_GEN9_BC(dev_priv)) {
Rodrigo Vivi0a918772016-09-30 11:05:56 -0700712 /* If we're boosting the current, set bit 31 of trans1 */
713 if (dev_priv->vbt.ddi_port_info[port].dp_boost_level)
714 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
715
716 if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
717 port != PORT_A && port != PORT_E &&
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200718 n_entries > 9))
719 n_entries = 9;
Rodrigo Vivi0a918772016-09-30 11:05:56 -0700720 }
721
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200722 for (i = 0; i < n_entries; i++) {
Ville Syrjälä9712e682015-09-18 20:03:22 +0300723 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
724 ddi_translations[i].trans1 | iboost_bit);
725 I915_WRITE(DDI_BUF_TRANS_HI(port, i),
726 ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300727 }
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300728}
Damien Lespiauce4dd492014-08-01 11:07:54 +0100729
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300730/*
731 * Starting with Haswell, DDI port buffers must be programmed with correct
732 * values in advance. This function programs the correct values for
733 * HDMI/DVI use cases.
734 */
735static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder)
736{
737 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
738 u32 iboost_bit = 0;
739 int n_hdmi_entries, hdmi_level;
740 enum port port = intel_ddi_get_encoder_port(encoder);
741 const struct ddi_buf_trans *ddi_translations_hdmi;
742
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200743 if (IS_GEN9_LP(dev_priv))
Damien Lespiauce3b7e92014-08-04 15:04:43 +0100744 return;
745
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300746 hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
747
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800748 if (IS_GEN9_BC(dev_priv)) {
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300749 ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
Ville Syrjälä1edaaa22016-07-12 15:59:34 +0300750
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300751 /* If we're boosting the current, set bit 31 of trans1 */
Ville Syrjälä1edaaa22016-07-12 15:59:34 +0300752 if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300753 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
754 } else if (IS_BROADWELL(dev_priv)) {
755 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
756 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
757 } else if (IS_HASWELL(dev_priv)) {
758 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
759 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
760 } else {
761 WARN(1, "ddi translation table missing\n");
762 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
763 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
764 }
765
Paulo Zanoni6acab152013-09-12 17:06:24 -0300766 /* Entry 9 is for HDMI: */
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300767 I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
Ville Syrjälä9712e682015-09-18 20:03:22 +0300768 ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300769 I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
Ville Syrjälä9712e682015-09-18 20:03:22 +0300770 ddi_translations_hdmi[hdmi_level].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300771}
772
Paulo Zanoni248138b2012-11-29 11:29:31 -0200773static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
774 enum port port)
775{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200776 i915_reg_t reg = DDI_BUF_CTL(port);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200777 int i;
778
Vandana Kannan3449ca82015-03-27 14:19:09 +0200779 for (i = 0; i < 16; i++) {
Paulo Zanoni248138b2012-11-29 11:29:31 -0200780 udelay(1);
781 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
782 return;
783 }
784 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
785}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300786
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700787static uint32_t hsw_pll_to_ddi_pll_sel(struct intel_shared_dpll *pll)
788{
789 switch (pll->id) {
790 case DPLL_ID_WRPLL1:
791 return PORT_CLK_SEL_WRPLL1;
792 case DPLL_ID_WRPLL2:
793 return PORT_CLK_SEL_WRPLL2;
794 case DPLL_ID_SPLL:
795 return PORT_CLK_SEL_SPLL;
796 case DPLL_ID_LCPLL_810:
797 return PORT_CLK_SEL_LCPLL_810;
798 case DPLL_ID_LCPLL_1350:
799 return PORT_CLK_SEL_LCPLL_1350;
800 case DPLL_ID_LCPLL_2700:
801 return PORT_CLK_SEL_LCPLL_2700;
802 default:
803 MISSING_CASE(pll->id);
804 return PORT_CLK_SEL_NONE;
805 }
806}
807
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300808/* Starting with Haswell, different DDI ports can work in FDI mode for
809 * connection to the PCH-located connectors. For this, it is necessary to train
810 * both the DDI port and PCH receiver for the desired DDI buffer settings.
811 *
812 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
813 * please note that when FDI mode is active on DDI E, it shares 2 lines with
814 * DDI A (which is used for eDP)
815 */
816
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200817void hsw_fdi_link_train(struct intel_crtc *crtc,
818 const struct intel_crtc_state *crtc_state)
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300819{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +0200820 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100821 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200822 struct intel_encoder *encoder;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700823 u32 temp, i, rx_ctl_val, ddi_pll_sel;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300824
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +0200825 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200826 WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300827 intel_prepare_dp_ddi_buffers(encoder);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200828 }
829
Paulo Zanoni04945642012-11-01 21:00:59 -0200830 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
831 * mode set "sequence for CRT port" document:
832 * - TP1 to TP2 time with the default value
833 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100834 *
835 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200836 */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300837 I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200838 FDI_RX_PWRDN_LANE0_VAL(2) |
839 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
840
841 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000842 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100843 FDI_RX_PLL_ENABLE |
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200844 FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300845 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
846 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200847 udelay(220);
848
849 /* Switch from Rawclk to PCDclk */
850 rx_ctl_val |= FDI_PCDCLK;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300851 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
Paulo Zanoni04945642012-11-01 21:00:59 -0200852
853 /* Configure Port Clock Select */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200854 ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700855 I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
856 WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200857
858 /* Start the training iterating through available voltages and emphasis,
859 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300860 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300861 /* Configure DP_TP_CTL with auto-training */
862 I915_WRITE(DP_TP_CTL(PORT_E),
863 DP_TP_CTL_FDI_AUTOTRAIN |
864 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
865 DP_TP_CTL_LINK_TRAIN_PAT1 |
866 DP_TP_CTL_ENABLE);
867
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000868 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
869 * DDI E does not support port reversal, the functionality is
870 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
871 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300872 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200873 DDI_BUF_CTL_ENABLE |
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200874 ((crtc_state->fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530875 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200876 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300877
878 udelay(600);
879
Paulo Zanoni04945642012-11-01 21:00:59 -0200880 /* Program PCH FDI Receiver TU */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300881 I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300882
Paulo Zanoni04945642012-11-01 21:00:59 -0200883 /* Enable PCH FDI Receiver with auto-training */
884 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300885 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
886 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200887
888 /* Wait for FDI receiver lane calibration */
889 udelay(30);
890
891 /* Unset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300892 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200893 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300894 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
895 POSTING_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200896
897 /* Wait for FDI auto training time */
898 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300899
900 temp = I915_READ(DP_TP_STATUS(PORT_E));
901 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200902 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200903 break;
904 }
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300905
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200906 /*
907 * Leave things enabled even if we failed to train FDI.
908 * Results in less fireworks from the state checker.
909 */
910 if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
911 DRM_ERROR("FDI link training failed!\n");
912 break;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300913 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200914
Ville Syrjälä5b421c52016-03-01 16:16:23 +0200915 rx_ctl_val &= ~FDI_RX_ENABLE;
916 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
917 POSTING_READ(FDI_RX_CTL(PIPE_A));
918
Paulo Zanoni248138b2012-11-29 11:29:31 -0200919 temp = I915_READ(DDI_BUF_CTL(PORT_E));
920 temp &= ~DDI_BUF_CTL_ENABLE;
921 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
922 POSTING_READ(DDI_BUF_CTL(PORT_E));
923
Paulo Zanoni04945642012-11-01 21:00:59 -0200924 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200925 temp = I915_READ(DP_TP_CTL(PORT_E));
926 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
927 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
928 I915_WRITE(DP_TP_CTL(PORT_E), temp);
929 POSTING_READ(DP_TP_CTL(PORT_E));
930
931 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200932
Paulo Zanoni04945642012-11-01 21:00:59 -0200933 /* Reset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300934 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200935 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
936 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300937 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
938 POSTING_READ(FDI_RX_MISC(PIPE_A));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300939 }
940
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200941 /* Enable normal pixel sending for FDI */
942 I915_WRITE(DP_TP_CTL(PORT_E),
943 DP_TP_CTL_FDI_AUTOTRAIN |
944 DP_TP_CTL_LINK_TRAIN_NORMAL |
945 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
946 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300947}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300948
Paulo Zanonid7c530b2017-03-30 17:57:52 -0300949static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
Dave Airlie44905a272014-05-02 13:36:43 +1000950{
951 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
952 struct intel_digital_port *intel_dig_port =
953 enc_to_dig_port(&encoder->base);
954
955 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530956 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Ville Syrjälä901c2da2015-08-17 18:05:12 +0300957 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Dave Airlie44905a272014-05-02 13:36:43 +1000958}
959
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300960static struct intel_encoder *
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +0200961intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300962{
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +0200963 struct drm_device *dev = crtc->base.dev;
Shashank Sharma1524e932017-03-09 19:13:41 +0530964 struct intel_encoder *encoder, *ret = NULL;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300965 int num_encoders = 0;
966
Shashank Sharma1524e932017-03-09 19:13:41 +0530967 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
968 ret = encoder;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300969 num_encoders++;
970 }
971
972 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300973 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +0200974 pipe_name(crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300975
976 BUG_ON(ret == NULL);
977 return ret;
978}
979
Paulo Zanoni44a126b2017-03-22 15:58:45 -0300980/* Finds the only possible encoder associated with the given CRTC. */
981struct intel_encoder *
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200982intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200983{
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200984 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
985 struct intel_encoder *ret = NULL;
986 struct drm_atomic_state *state;
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300987 struct drm_connector *connector;
988 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200989 int num_encoders = 0;
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200990 int i;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200991
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200992 state = crtc_state->base.state;
993
Maarten Lankhorstb77c7a92017-03-09 15:52:01 +0100994 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300995 if (connector_state->crtc != crtc_state->base.crtc)
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200996 continue;
997
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300998 ret = to_intel_encoder(connector_state->best_encoder);
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200999 num_encoders++;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001000 }
1001
1002 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
1003 pipe_name(crtc->pipe));
1004
1005 BUG_ON(ret == NULL);
1006 return ret;
1007}
1008
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001009#define LC_FREQ 2700
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001010
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001011static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
1012 i915_reg_t reg)
Jesse Barnes11578552014-01-21 12:42:10 -08001013{
1014 int refclk = LC_FREQ;
1015 int n, p, r;
1016 u32 wrpll;
1017
1018 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +03001019 switch (wrpll & WRPLL_PLL_REF_MASK) {
1020 case WRPLL_PLL_SSC:
1021 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -08001022 /*
1023 * We could calculate spread here, but our checking
1024 * code only cares about 5% accuracy, and spread is a max of
1025 * 0.5% downspread.
1026 */
1027 refclk = 135;
1028 break;
Daniel Vetter114fe482014-06-25 22:01:48 +03001029 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -08001030 refclk = LC_FREQ;
1031 break;
1032 default:
1033 WARN(1, "bad wrpll refclk\n");
1034 return 0;
1035 }
1036
1037 r = wrpll & WRPLL_DIVIDER_REF_MASK;
1038 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
1039 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
1040
Jesse Barnes20f0ec12014-01-22 12:58:04 -08001041 /* Convert to KHz, p & r have a fixed point portion */
1042 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -08001043}
1044
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001045static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
1046 uint32_t dpll)
1047{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001048 i915_reg_t cfgcr1_reg, cfgcr2_reg;
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001049 uint32_t cfgcr1_val, cfgcr2_val;
1050 uint32_t p0, p1, p2, dco_freq;
1051
Ville Syrjälä923c12412015-09-30 17:06:43 +03001052 cfgcr1_reg = DPLL_CFGCR1(dpll);
1053 cfgcr2_reg = DPLL_CFGCR2(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001054
1055 cfgcr1_val = I915_READ(cfgcr1_reg);
1056 cfgcr2_val = I915_READ(cfgcr2_reg);
1057
1058 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
1059 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
1060
1061 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
1062 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
1063 else
1064 p1 = 1;
1065
1066
1067 switch (p0) {
1068 case DPLL_CFGCR2_PDIV_1:
1069 p0 = 1;
1070 break;
1071 case DPLL_CFGCR2_PDIV_2:
1072 p0 = 2;
1073 break;
1074 case DPLL_CFGCR2_PDIV_3:
1075 p0 = 3;
1076 break;
1077 case DPLL_CFGCR2_PDIV_7:
1078 p0 = 7;
1079 break;
1080 }
1081
1082 switch (p2) {
1083 case DPLL_CFGCR2_KDIV_5:
1084 p2 = 5;
1085 break;
1086 case DPLL_CFGCR2_KDIV_2:
1087 p2 = 2;
1088 break;
1089 case DPLL_CFGCR2_KDIV_3:
1090 p2 = 3;
1091 break;
1092 case DPLL_CFGCR2_KDIV_1:
1093 p2 = 1;
1094 break;
1095 }
1096
1097 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
1098
1099 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
1100 1000) / 0x8000;
1101
1102 return dco_freq / (p0 * p1 * p2 * 5);
1103}
1104
Ville Syrjälä398a0172015-06-30 15:33:51 +03001105static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
1106{
1107 int dotclock;
1108
1109 if (pipe_config->has_pch_encoder)
1110 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1111 &pipe_config->fdi_m_n);
Ville Syrjälä37a56502016-06-22 21:57:04 +03001112 else if (intel_crtc_has_dp_encoder(pipe_config))
Ville Syrjälä398a0172015-06-30 15:33:51 +03001113 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1114 &pipe_config->dp_m_n);
1115 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
1116 dotclock = pipe_config->port_clock * 2 / 3;
1117 else
1118 dotclock = pipe_config->port_clock;
1119
1120 if (pipe_config->pixel_multiplier)
1121 dotclock /= pipe_config->pixel_multiplier;
1122
1123 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
1124}
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001125
1126static void skl_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001127 struct intel_crtc_state *pipe_config)
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001128{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001129 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001130 int link_clock = 0;
1131 uint32_t dpll_ctl1, dpll;
1132
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001133 dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001134
1135 dpll_ctl1 = I915_READ(DPLL_CTRL1);
1136
1137 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
1138 link_clock = skl_calc_wrpll_link(dev_priv, dpll);
1139 } else {
Damien Lespiau71cd8422015-04-30 16:39:17 +01001140 link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
1141 link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001142
1143 switch (link_clock) {
Damien Lespiau71cd8422015-04-30 16:39:17 +01001144 case DPLL_CTRL1_LINK_RATE_810:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001145 link_clock = 81000;
1146 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001147 case DPLL_CTRL1_LINK_RATE_1080:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301148 link_clock = 108000;
1149 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001150 case DPLL_CTRL1_LINK_RATE_1350:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001151 link_clock = 135000;
1152 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001153 case DPLL_CTRL1_LINK_RATE_1620:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301154 link_clock = 162000;
1155 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001156 case DPLL_CTRL1_LINK_RATE_2160:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301157 link_clock = 216000;
1158 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001159 case DPLL_CTRL1_LINK_RATE_2700:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001160 link_clock = 270000;
1161 break;
1162 default:
1163 WARN(1, "Unsupported link rate\n");
1164 break;
1165 }
1166 link_clock *= 2;
1167 }
1168
1169 pipe_config->port_clock = link_clock;
1170
Ville Syrjälä398a0172015-06-30 15:33:51 +03001171 ddi_dotclock_get(pipe_config);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001172}
1173
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001174static void hsw_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001175 struct intel_crtc_state *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -08001176{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001177 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes11578552014-01-21 12:42:10 -08001178 int link_clock = 0;
1179 u32 val, pll;
1180
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001181 val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
Jesse Barnes11578552014-01-21 12:42:10 -08001182 switch (val & PORT_CLK_SEL_MASK) {
1183 case PORT_CLK_SEL_LCPLL_810:
1184 link_clock = 81000;
1185 break;
1186 case PORT_CLK_SEL_LCPLL_1350:
1187 link_clock = 135000;
1188 break;
1189 case PORT_CLK_SEL_LCPLL_2700:
1190 link_clock = 270000;
1191 break;
1192 case PORT_CLK_SEL_WRPLL1:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001193 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
Jesse Barnes11578552014-01-21 12:42:10 -08001194 break;
1195 case PORT_CLK_SEL_WRPLL2:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001196 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
Jesse Barnes11578552014-01-21 12:42:10 -08001197 break;
1198 case PORT_CLK_SEL_SPLL:
1199 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
1200 if (pll == SPLL_PLL_FREQ_810MHz)
1201 link_clock = 81000;
1202 else if (pll == SPLL_PLL_FREQ_1350MHz)
1203 link_clock = 135000;
1204 else if (pll == SPLL_PLL_FREQ_2700MHz)
1205 link_clock = 270000;
1206 else {
1207 WARN(1, "bad spll freq\n");
1208 return;
1209 }
1210 break;
1211 default:
1212 WARN(1, "bad port clock sel\n");
1213 return;
1214 }
1215
1216 pipe_config->port_clock = link_clock * 2;
1217
Ville Syrjälä398a0172015-06-30 15:33:51 +03001218 ddi_dotclock_get(pipe_config);
Jesse Barnes11578552014-01-21 12:42:10 -08001219}
1220
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301221static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
1222 enum intel_dpll_id dpll)
1223{
Imre Deakaa610dc2015-06-22 23:35:52 +03001224 struct intel_shared_dpll *pll;
1225 struct intel_dpll_hw_state *state;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03001226 struct dpll clock;
Imre Deakaa610dc2015-06-22 23:35:52 +03001227
1228 /* For DDI ports we always use a shared PLL. */
1229 if (WARN_ON(dpll == DPLL_ID_PRIVATE))
1230 return 0;
1231
1232 pll = &dev_priv->shared_dplls[dpll];
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02001233 state = &pll->state.hw_state;
Imre Deakaa610dc2015-06-22 23:35:52 +03001234
1235 clock.m1 = 2;
1236 clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
1237 if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
1238 clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
1239 clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
1240 clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
1241 clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
1242
1243 return chv_calc_dpll_params(100000, &clock);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301244}
1245
1246static void bxt_ddi_clock_get(struct intel_encoder *encoder,
1247 struct intel_crtc_state *pipe_config)
1248{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001249 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301250 enum port port = intel_ddi_get_encoder_port(encoder);
1251 uint32_t dpll = port;
1252
Ville Syrjälä398a0172015-06-30 15:33:51 +03001253 pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301254
Ville Syrjälä398a0172015-06-30 15:33:51 +03001255 ddi_dotclock_get(pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301256}
1257
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001258void intel_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001259 struct intel_crtc_state *pipe_config)
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001260{
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001261 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Damien Lespiau22606a12014-12-12 14:26:57 +00001262
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001263 if (INTEL_GEN(dev_priv) <= 8)
Damien Lespiau22606a12014-12-12 14:26:57 +00001264 hsw_ddi_clock_get(encoder, pipe_config);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001265 else if (IS_GEN9_BC(dev_priv))
Damien Lespiau22606a12014-12-12 14:26:57 +00001266 skl_ddi_clock_get(encoder, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001267 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301268 bxt_ddi_clock_get(encoder, pipe_config);
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001269}
1270
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001271void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
Paulo Zanonidae84792012-10-15 15:51:30 -03001272{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001273 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001274 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301275 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001276 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Shashank Sharma1524e932017-03-09 19:13:41 +05301277 int type = encoder->type;
Paulo Zanonidae84792012-10-15 15:51:30 -03001278 uint32_t temp;
1279
Ville Syrjäläcca05022016-06-22 21:57:06 +03001280 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Jani Nikula4d1de972016-03-18 17:05:42 +02001281 WARN_ON(transcoder_is_dsi(cpu_transcoder));
1282
Paulo Zanonic9809792012-10-23 18:30:00 -02001283 temp = TRANS_MSA_SYNC_CLK;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001284 switch (crtc_state->pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -03001285 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -02001286 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001287 break;
1288 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -02001289 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001290 break;
1291 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -02001292 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001293 break;
1294 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -02001295 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001296 break;
1297 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001298 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -03001299 }
Paulo Zanonic9809792012-10-23 18:30:00 -02001300 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -03001301 }
1302}
1303
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001304void intel_ddi_set_vc_payload_alloc(const struct intel_crtc_state *crtc_state,
1305 bool state)
Dave Airlie0e32b392014-05-02 14:02:48 +10001306{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001307 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001308 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001309 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +10001310 uint32_t temp;
1311 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1312 if (state == true)
1313 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1314 else
1315 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1316 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1317}
1318
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001319void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001320{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001321 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Shashank Sharma1524e932017-03-09 19:13:41 +05301322 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001323 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1324 enum pipe pipe = crtc->pipe;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001325 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Shashank Sharma1524e932017-03-09 19:13:41 +05301326 enum port port = intel_ddi_get_encoder_port(encoder);
1327 int type = encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001328 uint32_t temp;
1329
Paulo Zanoniad80a812012-10-24 16:06:19 -02001330 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1331 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001332 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001333
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001334 switch (crtc_state->pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001335 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001336 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001337 break;
1338 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001339 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001340 break;
1341 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001342 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001343 break;
1344 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001345 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001346 break;
1347 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001348 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001349 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001350
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001351 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001352 temp |= TRANS_DDI_PVSYNC;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001353 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001354 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -03001355
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001356 if (cpu_transcoder == TRANSCODER_EDP) {
1357 switch (pipe) {
1358 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001359 /* On Haswell, can only use the always-on power well for
1360 * eDP when not using the panel fitter, and when not
1361 * using motion blur mitigation (which we don't
1362 * support). */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01001363 if (IS_HASWELL(dev_priv) &&
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001364 (crtc_state->pch_pfit.enabled ||
1365 crtc_state->pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001366 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1367 else
1368 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001369 break;
1370 case PIPE_B:
1371 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1372 break;
1373 case PIPE_C:
1374 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1375 break;
1376 default:
1377 BUG();
1378 break;
1379 }
1380 }
1381
Paulo Zanoni7739c332012-10-15 15:51:29 -03001382 if (type == INTEL_OUTPUT_HDMI) {
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001383 if (crtc_state->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001384 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001385 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001386 temp |= TRANS_DDI_MODE_SELECT_DVI;
Shashank Sharma15953632017-03-13 16:54:03 +05301387
1388 if (crtc_state->hdmi_scrambling)
1389 temp |= TRANS_DDI_HDMI_SCRAMBLING_MASK;
1390 if (crtc_state->hdmi_high_tmds_clock_ratio)
1391 temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001392 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001393 temp |= TRANS_DDI_MODE_SELECT_FDI;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001394 temp |= (crtc_state->fdi_lanes - 1) << 1;
Ville Syrjäläcca05022016-06-22 21:57:06 +03001395 } else if (type == INTEL_OUTPUT_DP ||
Paulo Zanoni7739c332012-10-15 15:51:29 -03001396 type == INTEL_OUTPUT_EDP) {
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001397 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001398 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
Dave Airlie0e32b392014-05-02 14:02:48 +10001399 } else if (type == INTEL_OUTPUT_DP_MST) {
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001400 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001401 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001402 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001403 WARN(1, "Invalid encoder type %d for pipe %c\n",
Shashank Sharma1524e932017-03-09 19:13:41 +05301404 encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001405 }
1406
Paulo Zanoniad80a812012-10-24 16:06:19 -02001407 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001408}
1409
Paulo Zanoniad80a812012-10-24 16:06:19 -02001410void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1411 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001412{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001413 i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001414 uint32_t val = I915_READ(reg);
1415
Dave Airlie0e32b392014-05-02 14:02:48 +10001416 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -02001417 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001418 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001419}
1420
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001421bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1422{
1423 struct drm_device *dev = intel_connector->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001424 struct drm_i915_private *dev_priv = to_i915(dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301425 struct intel_encoder *encoder = intel_connector->encoder;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001426 int type = intel_connector->base.connector_type;
Shashank Sharma1524e932017-03-09 19:13:41 +05301427 enum port port = intel_ddi_get_encoder_port(encoder);
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001428 enum pipe pipe = 0;
1429 enum transcoder cpu_transcoder;
1430 uint32_t tmp;
Imre Deake27daab2016-02-12 18:55:16 +02001431 bool ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001432
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001433 if (!intel_display_power_get_if_enabled(dev_priv,
Shashank Sharma1524e932017-03-09 19:13:41 +05301434 encoder->power_domain))
Paulo Zanoni882244a2014-04-01 14:55:12 -03001435 return false;
1436
Shashank Sharma1524e932017-03-09 19:13:41 +05301437 if (!encoder->get_hw_state(encoder, &pipe)) {
Imre Deake27daab2016-02-12 18:55:16 +02001438 ret = false;
1439 goto out;
1440 }
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001441
1442 if (port == PORT_A)
1443 cpu_transcoder = TRANSCODER_EDP;
1444 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001445 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001446
1447 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1448
1449 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1450 case TRANS_DDI_MODE_SELECT_HDMI:
1451 case TRANS_DDI_MODE_SELECT_DVI:
Imre Deake27daab2016-02-12 18:55:16 +02001452 ret = type == DRM_MODE_CONNECTOR_HDMIA;
1453 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001454
1455 case TRANS_DDI_MODE_SELECT_DP_SST:
Imre Deake27daab2016-02-12 18:55:16 +02001456 ret = type == DRM_MODE_CONNECTOR_eDP ||
1457 type == DRM_MODE_CONNECTOR_DisplayPort;
1458 break;
1459
Dave Airlie0e32b392014-05-02 14:02:48 +10001460 case TRANS_DDI_MODE_SELECT_DP_MST:
1461 /* if the transcoder is in MST state then
1462 * connector isn't connected */
Imre Deake27daab2016-02-12 18:55:16 +02001463 ret = false;
1464 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001465
1466 case TRANS_DDI_MODE_SELECT_FDI:
Imre Deake27daab2016-02-12 18:55:16 +02001467 ret = type == DRM_MODE_CONNECTOR_VGA;
1468 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001469
1470 default:
Imre Deake27daab2016-02-12 18:55:16 +02001471 ret = false;
1472 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001473 }
Imre Deake27daab2016-02-12 18:55:16 +02001474
1475out:
Shashank Sharma1524e932017-03-09 19:13:41 +05301476 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deake27daab2016-02-12 18:55:16 +02001477
1478 return ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001479}
1480
Daniel Vetter85234cd2012-07-02 13:27:29 +02001481bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1482 enum pipe *pipe)
1483{
1484 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001485 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001486 enum port port = intel_ddi_get_encoder_port(encoder);
Daniel Vetter85234cd2012-07-02 13:27:29 +02001487 u32 tmp;
1488 int i;
Imre Deake27daab2016-02-12 18:55:16 +02001489 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001490
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001491 if (!intel_display_power_get_if_enabled(dev_priv,
1492 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001493 return false;
1494
Imre Deake27daab2016-02-12 18:55:16 +02001495 ret = false;
1496
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001497 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001498
1499 if (!(tmp & DDI_BUF_CTL_ENABLE))
Imre Deake27daab2016-02-12 18:55:16 +02001500 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001501
Paulo Zanoniad80a812012-10-24 16:06:19 -02001502 if (port == PORT_A) {
1503 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001504
Paulo Zanoniad80a812012-10-24 16:06:19 -02001505 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1506 case TRANS_DDI_EDP_INPUT_A_ON:
1507 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1508 *pipe = PIPE_A;
1509 break;
1510 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1511 *pipe = PIPE_B;
1512 break;
1513 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1514 *pipe = PIPE_C;
1515 break;
1516 }
1517
Imre Deake27daab2016-02-12 18:55:16 +02001518 ret = true;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001519
Imre Deake27daab2016-02-12 18:55:16 +02001520 goto out;
1521 }
Dave Airlie0e32b392014-05-02 14:02:48 +10001522
Imre Deake27daab2016-02-12 18:55:16 +02001523 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1524 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1525
1526 if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
1527 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
1528 TRANS_DDI_MODE_SELECT_DP_MST)
1529 goto out;
1530
1531 *pipe = i;
1532 ret = true;
1533
1534 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001535 }
1536 }
1537
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001538 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001539
Imre Deake27daab2016-02-12 18:55:16 +02001540out:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001541 if (ret && IS_GEN9_LP(dev_priv)) {
Imre Deake93da0a2016-06-13 16:44:37 +03001542 tmp = I915_READ(BXT_PHY_CTL(port));
1543 if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK |
1544 BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
1545 DRM_ERROR("Port %c enabled but PHY powered down? "
1546 "(PHY_CTL %08x)\n", port_name(port), tmp);
1547 }
1548
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001549 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deake27daab2016-02-12 18:55:16 +02001550
1551 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001552}
1553
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001554static u64 intel_ddi_get_power_domains(struct intel_encoder *encoder)
1555{
1556 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
1557 enum pipe pipe;
1558
1559 if (intel_ddi_get_hw_state(encoder, &pipe))
1560 return BIT_ULL(dig_port->ddi_io_power_domain);
1561
1562 return 0;
1563}
1564
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001565void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state)
Paulo Zanonifc914632012-10-05 12:05:54 -03001566{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001567 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001568 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301569 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
1570 enum port port = intel_ddi_get_encoder_port(encoder);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001571 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001572
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001573 if (cpu_transcoder != TRANSCODER_EDP)
1574 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1575 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001576}
1577
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001578void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
Paulo Zanonifc914632012-10-05 12:05:54 -03001579{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001580 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1581 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001582
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001583 if (cpu_transcoder != TRANSCODER_EDP)
1584 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1585 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001586}
1587
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001588static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1589 enum port port, uint8_t iboost)
David Weinehallf8896f52015-06-25 11:11:03 +03001590{
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001591 u32 tmp;
1592
1593 tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
1594 tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
1595 if (iboost)
1596 tmp |= iboost << BALANCE_LEG_SHIFT(port);
1597 else
1598 tmp |= BALANCE_LEG_DISABLE(port);
1599 I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
1600}
1601
1602static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
1603{
1604 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
1605 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
1606 enum port port = intel_dig_port->port;
1607 int type = encoder->type;
David Weinehallf8896f52015-06-25 11:11:03 +03001608 const struct ddi_buf_trans *ddi_translations;
1609 uint8_t iboost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001610 uint8_t dp_iboost, hdmi_iboost;
David Weinehallf8896f52015-06-25 11:11:03 +03001611 int n_entries;
David Weinehallf8896f52015-06-25 11:11:03 +03001612
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001613 /* VBT may override standard boost values */
1614 dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
1615 hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
1616
Ville Syrjäläcca05022016-06-22 21:57:06 +03001617 if (type == INTEL_OUTPUT_DP) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001618 if (dp_iboost) {
1619 iboost = dp_iboost;
1620 } else {
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -07001621 if (IS_KABYLAKE(dev_priv))
1622 ddi_translations = kbl_get_buf_trans_dp(dev_priv,
1623 &n_entries);
1624 else
1625 ddi_translations = skl_get_buf_trans_dp(dev_priv,
1626 &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001627 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001628 }
David Weinehallf8896f52015-06-25 11:11:03 +03001629 } else if (type == INTEL_OUTPUT_EDP) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001630 if (dp_iboost) {
1631 iboost = dp_iboost;
1632 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001633 ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
Ville Syrjälä10afa0b2015-12-08 19:59:43 +02001634
1635 if (WARN_ON(port != PORT_A &&
1636 port != PORT_E && n_entries > 9))
1637 n_entries = 9;
1638
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001639 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001640 }
David Weinehallf8896f52015-06-25 11:11:03 +03001641 } else if (type == INTEL_OUTPUT_HDMI) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001642 if (hdmi_iboost) {
1643 iboost = hdmi_iboost;
1644 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001645 ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001646 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001647 }
David Weinehallf8896f52015-06-25 11:11:03 +03001648 } else {
1649 return;
1650 }
1651
1652 /* Make sure that the requested I_boost is valid */
1653 if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
1654 DRM_ERROR("Invalid I_boost value %u\n", iboost);
1655 return;
1656 }
1657
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001658 _skl_ddi_set_iboost(dev_priv, port, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001659
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001660 if (port == PORT_A && intel_dig_port->max_lanes == 4)
1661 _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001662}
1663
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001664static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
1665 u32 level, enum port port, int type)
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301666{
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301667 const struct bxt_ddi_buf_trans *ddi_translations;
1668 u32 n_entries, i;
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301669
Jani Nikula06411f02016-03-24 17:50:21 +02001670 if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
Sonika Jindald9d70002015-09-24 10:24:56 +05301671 n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
1672 ddi_translations = bxt_ddi_translations_edp;
Ville Syrjäläcca05022016-06-22 21:57:06 +03001673 } else if (type == INTEL_OUTPUT_DP
Sonika Jindald9d70002015-09-24 10:24:56 +05301674 || type == INTEL_OUTPUT_EDP) {
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301675 n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
1676 ddi_translations = bxt_ddi_translations_dp;
1677 } else if (type == INTEL_OUTPUT_HDMI) {
1678 n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
1679 ddi_translations = bxt_ddi_translations_hdmi;
1680 } else {
1681 DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
1682 type);
1683 return;
1684 }
1685
1686 /* Check if default value has to be used */
1687 if (level >= n_entries ||
1688 (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
1689 for (i = 0; i < n_entries; i++) {
1690 if (ddi_translations[i].default_index) {
1691 level = i;
1692 break;
1693 }
1694 }
1695 }
1696
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +03001697 bxt_ddi_phy_set_signal_level(dev_priv, port,
1698 ddi_translations[level].margin,
1699 ddi_translations[level].scale,
1700 ddi_translations[level].enable,
1701 ddi_translations[level].deemphasis);
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301702}
1703
Ville Syrjäläffe51112017-02-23 19:49:01 +02001704u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder)
1705{
1706 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1707 int n_entries;
1708
1709 if (encoder->type == INTEL_OUTPUT_EDP)
1710 intel_ddi_get_buf_trans_edp(dev_priv, &n_entries);
1711 else
1712 intel_ddi_get_buf_trans_dp(dev_priv, &n_entries);
1713
1714 if (WARN_ON(n_entries < 1))
1715 n_entries = 1;
1716 if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
1717 n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
1718
1719 return index_to_dp_signal_levels[n_entries - 1] &
1720 DP_TRAIN_VOLTAGE_SWING_MASK;
1721}
1722
David Weinehallf8896f52015-06-25 11:11:03 +03001723static uint32_t translate_signal_level(int signal_levels)
1724{
Ville Syrjälä97eeb872017-02-23 19:35:06 +02001725 int i;
David Weinehallf8896f52015-06-25 11:11:03 +03001726
Ville Syrjälä97eeb872017-02-23 19:35:06 +02001727 for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
1728 if (index_to_dp_signal_levels[i] == signal_levels)
1729 return i;
David Weinehallf8896f52015-06-25 11:11:03 +03001730 }
1731
Ville Syrjälä97eeb872017-02-23 19:35:06 +02001732 WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
1733 signal_levels);
1734
1735 return 0;
David Weinehallf8896f52015-06-25 11:11:03 +03001736}
1737
1738uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
1739{
1740 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001741 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
David Weinehallf8896f52015-06-25 11:11:03 +03001742 struct intel_encoder *encoder = &dport->base;
1743 uint8_t train_set = intel_dp->train_set[0];
1744 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1745 DP_TRAIN_PRE_EMPHASIS_MASK);
1746 enum port port = dport->port;
1747 uint32_t level;
1748
1749 level = translate_signal_level(signal_levels);
1750
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001751 if (IS_GEN9_BC(dev_priv))
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001752 skl_ddi_set_iboost(encoder, level);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001753 else if (IS_GEN9_LP(dev_priv))
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001754 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
David Weinehallf8896f52015-06-25 11:11:03 +03001755
1756 return DDI_BUF_TRANS_SELECT(level);
1757}
1758
Paulo Zanonid7c530b2017-03-30 17:57:52 -03001759static void intel_ddi_clk_select(struct intel_encoder *encoder,
1760 struct intel_shared_dpll *pll)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001761{
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001762 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1763 enum port port = intel_ddi_get_encoder_port(encoder);
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07001764 uint32_t val;
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001765
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001766 if (WARN_ON(!pll))
1767 return;
1768
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07001769 if (IS_CANNONLAKE(dev_priv)) {
1770 /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */
1771 val = I915_READ(DPCLKA_CFGCR0);
1772 val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->id, port);
1773 I915_WRITE(DPCLKA_CFGCR0, val);
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001774
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07001775 /*
1776 * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI.
1777 * This step and the step before must be done with separate
1778 * register writes.
1779 */
1780 val = I915_READ(DPCLKA_CFGCR0);
1781 val &= ~(DPCLKA_CFGCR0_DDI_CLK_OFF(port) |
1782 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port));
1783 I915_WRITE(DPCLKA_CFGCR0, val);
1784 } else if (IS_GEN9_BC(dev_priv)) {
Damien Lespiau5416d872014-11-14 17:24:33 +00001785 /* DDI -> PLL mapping */
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001786 val = I915_READ(DPLL_CTRL2);
1787
1788 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
1789 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001790 val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001791 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
1792
1793 I915_WRITE(DPLL_CTRL2, val);
Damien Lespiau5416d872014-11-14 17:24:33 +00001794
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001795 } else if (INTEL_INFO(dev_priv)->gen < 9) {
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001796 I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001797 }
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001798}
1799
Manasi Navareba88d152016-09-01 15:08:08 -07001800static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
1801 int link_rate, uint32_t lane_count,
1802 struct intel_shared_dpll *pll,
1803 bool link_mst)
1804{
1805 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1806 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1807 enum port port = intel_ddi_get_encoder_port(encoder);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001808 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
Manasi Navareba88d152016-09-01 15:08:08 -07001809
Ander Conselvan de Oliveirae081c842017-03-02 14:58:57 +02001810 WARN_ON(link_mst && (port == PORT_A || port == PORT_E));
1811
Manasi Navareba88d152016-09-01 15:08:08 -07001812 intel_dp_set_link_params(intel_dp, link_rate, lane_count,
1813 link_mst);
1814 if (encoder->type == INTEL_OUTPUT_EDP)
1815 intel_edp_panel_on(intel_dp);
1816
1817 intel_ddi_clk_select(encoder, pll);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001818
1819 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
1820
Manasi Navareba88d152016-09-01 15:08:08 -07001821 intel_prepare_dp_ddi_buffers(encoder);
1822 intel_ddi_init_dp_buf_reg(encoder);
1823 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1824 intel_dp_start_link_train(intel_dp);
1825 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
1826 intel_dp_stop_link_train(intel_dp);
1827}
1828
1829static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
1830 bool has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001831 const struct intel_crtc_state *crtc_state,
1832 const struct drm_connector_state *conn_state,
Manasi Navareba88d152016-09-01 15:08:08 -07001833 struct intel_shared_dpll *pll)
1834{
1835 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1836 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1837 struct drm_encoder *drm_encoder = &encoder->base;
1838 enum port port = intel_ddi_get_encoder_port(encoder);
1839 int level = intel_ddi_hdmi_level(dev_priv, port);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001840 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
Manasi Navareba88d152016-09-01 15:08:08 -07001841
1842 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
1843 intel_ddi_clk_select(encoder, pll);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001844
1845 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
1846
Manasi Navareba88d152016-09-01 15:08:08 -07001847 intel_prepare_hdmi_ddi_buffers(encoder);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001848 if (IS_GEN9_BC(dev_priv))
Manasi Navareba88d152016-09-01 15:08:08 -07001849 skl_ddi_set_iboost(encoder, level);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001850 else if (IS_GEN9_LP(dev_priv))
Manasi Navareba88d152016-09-01 15:08:08 -07001851 bxt_ddi_vswing_sequence(dev_priv, level, port,
1852 INTEL_OUTPUT_HDMI);
1853
1854 intel_hdmi->set_infoframes(drm_encoder,
1855 has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001856 crtc_state, conn_state);
Manasi Navareba88d152016-09-01 15:08:08 -07001857}
1858
Shashank Sharma1524e932017-03-09 19:13:41 +05301859static void intel_ddi_pre_enable(struct intel_encoder *encoder,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001860 struct intel_crtc_state *pipe_config,
1861 struct drm_connector_state *conn_state)
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001862{
Shashank Sharma1524e932017-03-09 19:13:41 +05301863 int type = encoder->type;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +02001864
Ville Syrjäläcca05022016-06-22 21:57:06 +03001865 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
Shashank Sharma1524e932017-03-09 19:13:41 +05301866 intel_ddi_pre_enable_dp(encoder,
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001867 pipe_config->port_clock,
1868 pipe_config->lane_count,
1869 pipe_config->shared_dpll,
1870 intel_crtc_has_type(pipe_config,
Manasi Navareba88d152016-09-01 15:08:08 -07001871 INTEL_OUTPUT_DP_MST));
1872 }
1873 if (type == INTEL_OUTPUT_HDMI) {
Shashank Sharma1524e932017-03-09 19:13:41 +05301874 intel_ddi_pre_enable_hdmi(encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001875 pipe_config->has_hdmi_sink,
1876 pipe_config, conn_state,
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001877 pipe_config->shared_dpll);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001878 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001879}
1880
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001881static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
1882 struct intel_crtc_state *old_crtc_state,
1883 struct drm_connector_state *old_conn_state)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001884{
1885 struct drm_encoder *encoder = &intel_encoder->base;
Tvrtko Ursulin66478472016-11-16 08:55:40 +00001886 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001887 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001888 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
Imre Deak76181382017-05-31 20:05:35 +03001889 struct intel_dp *intel_dp = NULL;
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001890 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001891 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001892 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001893
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001894 /* old_crtc_state and old_conn_state are NULL when called from DP_MST */
1895
Imre Deak76181382017-05-31 20:05:35 +03001896 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
1897 intel_dp = enc_to_intel_dp(encoder);
1898 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1899 }
1900
Paulo Zanoni2886e932012-10-05 12:06:00 -03001901 val = I915_READ(DDI_BUF_CTL(port));
1902 if (val & DDI_BUF_CTL_ENABLE) {
1903 val &= ~DDI_BUF_CTL_ENABLE;
1904 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001905 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001906 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001907
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001908 val = I915_READ(DP_TP_CTL(port));
1909 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1910 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1911 I915_WRITE(DP_TP_CTL(port), val);
1912
1913 if (wait)
1914 intel_wait_ddi_buf_idle(dev_priv, port);
1915
Imre Deak76181382017-05-31 20:05:35 +03001916 if (intel_dp) {
Jani Nikula24f3e092014-03-17 16:43:36 +02001917 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001918 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001919 }
1920
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001921 if (dig_port)
1922 intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
1923
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07001924 if (IS_CANNONLAKE(dev_priv))
1925 I915_WRITE(DPCLKA_CFGCR0, I915_READ(DPCLKA_CFGCR0) |
1926 DPCLKA_CFGCR0_DDI_CLK_OFF(port));
1927 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001928 I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
1929 DPLL_CTRL2_DDI_CLK_OFF(port)));
Tvrtko Ursulin66478472016-11-16 08:55:40 +00001930 else if (INTEL_GEN(dev_priv) < 9)
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001931 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
Ville Syrjäläb2ccb822016-05-02 22:08:24 +03001932
1933 if (type == INTEL_OUTPUT_HDMI) {
1934 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1935
1936 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
1937 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001938}
1939
Shashank Sharma1524e932017-03-09 19:13:41 +05301940void intel_ddi_fdi_post_disable(struct intel_encoder *encoder,
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001941 struct intel_crtc_state *old_crtc_state,
1942 struct drm_connector_state *old_conn_state)
1943{
Shashank Sharma1524e932017-03-09 19:13:41 +05301944 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001945 uint32_t val;
1946
1947 /*
1948 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
1949 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
1950 * step 13 is the correct place for it. Step 18 is where it was
1951 * originally before the BUN.
1952 */
1953 val = I915_READ(FDI_RX_CTL(PIPE_A));
1954 val &= ~FDI_RX_ENABLE;
1955 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
1956
Shashank Sharma1524e932017-03-09 19:13:41 +05301957 intel_ddi_post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001958
1959 val = I915_READ(FDI_RX_MISC(PIPE_A));
1960 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1961 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1962 I915_WRITE(FDI_RX_MISC(PIPE_A), val);
1963
1964 val = I915_READ(FDI_RX_CTL(PIPE_A));
1965 val &= ~FDI_PCDCLK;
1966 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
1967
1968 val = I915_READ(FDI_RX_CTL(PIPE_A));
1969 val &= ~FDI_RX_PLL_ENABLE;
1970 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
1971}
1972
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001973static void intel_enable_ddi(struct intel_encoder *intel_encoder,
1974 struct intel_crtc_state *pipe_config,
1975 struct drm_connector_state *conn_state)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001976{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001977 struct drm_encoder *encoder = &intel_encoder->base;
Tvrtko Ursulin66478472016-11-16 08:55:40 +00001978 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001979 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1980 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001981
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001982 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001983 struct intel_digital_port *intel_dig_port =
1984 enc_to_dig_port(encoder);
Shashank Sharma15953632017-03-13 16:54:03 +05301985 bool clock_ratio = pipe_config->hdmi_high_tmds_clock_ratio;
1986 bool scrambling = pipe_config->hdmi_scrambling;
1987
1988 intel_hdmi_handle_sink_scrambling(intel_encoder,
1989 conn_state->connector,
1990 clock_ratio, scrambling);
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001991
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001992 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1993 * are ignored so nothing special needs to be done besides
1994 * enabling the port.
1995 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001996 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001997 intel_dig_port->saved_port_bits |
1998 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001999 } else if (type == INTEL_OUTPUT_EDP) {
2000 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2001
Tvrtko Ursulin66478472016-11-16 08:55:40 +00002002 if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03002003 intel_dp_stop_link_train(intel_dp);
2004
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002005 intel_edp_backlight_on(pipe_config, conn_state);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08002006 intel_psr_enable(intel_dp);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002007 intel_edp_drrs_enable(intel_dp, pipe_config);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002008 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08002009
Maarten Lankhorst37255d82016-12-15 15:29:43 +01002010 if (pipe_config->has_audio)
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01002011 intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002012}
2013
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002014static void intel_disable_ddi(struct intel_encoder *intel_encoder,
2015 struct intel_crtc_state *old_crtc_state,
2016 struct drm_connector_state *old_conn_state)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002017{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002018 struct drm_encoder *encoder = &intel_encoder->base;
2019 int type = intel_encoder->type;
2020
Maarten Lankhorst37255d82016-12-15 15:29:43 +01002021 if (old_crtc_state->has_audio)
Jani Nikula69bfe1a2014-10-27 16:26:50 +02002022 intel_audio_codec_disable(intel_encoder);
Paulo Zanoni2831d8422013-03-06 20:03:09 -03002023
Shashank Sharma15953632017-03-13 16:54:03 +05302024 if (type == INTEL_OUTPUT_HDMI) {
2025 intel_hdmi_handle_sink_scrambling(intel_encoder,
2026 old_conn_state->connector,
2027 false, false);
2028 }
2029
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002030 if (type == INTEL_OUTPUT_EDP) {
2031 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2032
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02002033 intel_edp_drrs_disable(intel_dp, old_crtc_state);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08002034 intel_psr_disable(intel_dp);
Maarten Lankhorstb037d582017-06-12 12:21:13 +02002035 intel_edp_backlight_off(old_conn_state);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002036 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002037}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002038
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002039static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
2040 struct intel_crtc_state *pipe_config,
2041 struct drm_connector_state *conn_state)
Imre Deak95a7a2a2016-06-13 16:44:35 +03002042{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02002043 uint8_t mask = pipe_config->lane_lat_optim_mask;
Imre Deak95a7a2a2016-06-13 16:44:35 +03002044
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +03002045 bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002046}
2047
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03002048void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
Paulo Zanonic19b0662012-10-15 15:51:41 -03002049{
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03002050 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2051 struct drm_i915_private *dev_priv =
2052 to_i915(intel_dig_port->base.base.dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02002053 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002054 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05302055 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002056
2057 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
2058 val = I915_READ(DDI_BUF_CTL(port));
2059 if (val & DDI_BUF_CTL_ENABLE) {
2060 val &= ~DDI_BUF_CTL_ENABLE;
2061 I915_WRITE(DDI_BUF_CTL(port), val);
2062 wait = true;
2063 }
2064
2065 val = I915_READ(DP_TP_CTL(port));
2066 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2067 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2068 I915_WRITE(DP_TP_CTL(port), val);
2069 POSTING_READ(DP_TP_CTL(port));
2070
2071 if (wait)
2072 intel_wait_ddi_buf_idle(dev_priv, port);
2073 }
2074
Dave Airlie0e32b392014-05-02 14:02:48 +10002075 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03002076 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03002077 if (intel_dp->link_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10002078 val |= DP_TP_CTL_MODE_MST;
2079 else {
2080 val |= DP_TP_CTL_MODE_SST;
2081 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2082 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
2083 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03002084 I915_WRITE(DP_TP_CTL(port), val);
2085 POSTING_READ(DP_TP_CTL(port));
2086
2087 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
2088 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
2089 POSTING_READ(DDI_BUF_CTL(port));
2090
2091 udelay(600);
2092}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002093
Libin Yang9935f7f2016-11-28 20:07:06 +08002094bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
2095 struct intel_crtc *intel_crtc)
2096{
2097 u32 temp;
2098
2099 if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
2100 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
2101 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
2102 return true;
2103 }
2104 return false;
2105}
2106
Ville Syrjälä6801c182013-09-24 14:24:05 +03002107void intel_ddi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002108 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002109{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002110 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002111 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +02002112 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002113 struct intel_hdmi *intel_hdmi;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002114 u32 temp, flags = 0;
2115
Jani Nikula4d1de972016-03-18 17:05:42 +02002116 /* XXX: DSI transcoder paranoia */
2117 if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
2118 return;
2119
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002120 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
2121 if (temp & TRANS_DDI_PHSYNC)
2122 flags |= DRM_MODE_FLAG_PHSYNC;
2123 else
2124 flags |= DRM_MODE_FLAG_NHSYNC;
2125 if (temp & TRANS_DDI_PVSYNC)
2126 flags |= DRM_MODE_FLAG_PVSYNC;
2127 else
2128 flags |= DRM_MODE_FLAG_NVSYNC;
2129
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002130 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03002131
2132 switch (temp & TRANS_DDI_BPC_MASK) {
2133 case TRANS_DDI_BPC_6:
2134 pipe_config->pipe_bpp = 18;
2135 break;
2136 case TRANS_DDI_BPC_8:
2137 pipe_config->pipe_bpp = 24;
2138 break;
2139 case TRANS_DDI_BPC_10:
2140 pipe_config->pipe_bpp = 30;
2141 break;
2142 case TRANS_DDI_BPC_12:
2143 pipe_config->pipe_bpp = 36;
2144 break;
2145 default:
2146 break;
2147 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002148
2149 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
2150 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02002151 pipe_config->has_hdmi_sink = true;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002152 intel_hdmi = enc_to_intel_hdmi(&encoder->base);
2153
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +02002154 if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002155 pipe_config->has_infoframe = true;
Shashank Sharma15953632017-03-13 16:54:03 +05302156
2157 if ((temp & TRANS_DDI_HDMI_SCRAMBLING_MASK) ==
2158 TRANS_DDI_HDMI_SCRAMBLING_MASK)
2159 pipe_config->hdmi_scrambling = true;
2160 if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
2161 pipe_config->hdmi_high_tmds_clock_ratio = true;
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002162 /* fall through */
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002163 case TRANS_DDI_MODE_SELECT_DVI:
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002164 pipe_config->lane_count = 4;
2165 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002166 case TRANS_DDI_MODE_SELECT_FDI:
2167 break;
2168 case TRANS_DDI_MODE_SELECT_DP_SST:
2169 case TRANS_DDI_MODE_SELECT_DP_MST:
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002170 pipe_config->lane_count =
2171 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002172 intel_dp_get_m_n(intel_crtc, pipe_config);
2173 break;
2174 default:
2175 break;
2176 }
Daniel Vetter10214422013-11-18 07:38:16 +01002177
Libin Yang9935f7f2016-11-28 20:07:06 +08002178 pipe_config->has_audio =
2179 intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002180
Jani Nikula6aa23e62016-03-24 17:50:20 +02002181 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
2182 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Daniel Vetter10214422013-11-18 07:38:16 +01002183 /*
2184 * This is a big fat ugly hack.
2185 *
2186 * Some machines in UEFI boot mode provide us a VBT that has 18
2187 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2188 * unknown we fail to light up. Yet the same BIOS boots up with
2189 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2190 * max, not what it tells us to use.
2191 *
2192 * Note: This will still be broken if the eDP panel is not lit
2193 * up by the BIOS, and thus we can't get the mode at module
2194 * load.
2195 */
2196 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002197 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2198 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Daniel Vetter10214422013-11-18 07:38:16 +01002199 }
Jesse Barnes11578552014-01-21 12:42:10 -08002200
Damien Lespiau22606a12014-12-12 14:26:57 +00002201 intel_ddi_clock_get(encoder, pipe_config);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002202
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002203 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002204 pipe_config->lane_lat_optim_mask =
2205 bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002206}
2207
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002208static bool intel_ddi_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002209 struct intel_crtc_state *pipe_config,
2210 struct drm_connector_state *conn_state)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002211{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002212 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002213 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02002214 int port = intel_ddi_get_encoder_port(encoder);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002215 int ret;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002216
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002217 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002218
Daniel Vettereccb1402013-05-22 00:50:22 +02002219 if (port == PORT_A)
2220 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2221
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002222 if (type == INTEL_OUTPUT_HDMI)
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002223 ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002224 else
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002225 ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002226
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002227 if (IS_GEN9_LP(dev_priv) && ret)
Imre Deak95a7a2a2016-06-13 16:44:35 +03002228 pipe_config->lane_lat_optim_mask =
2229 bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
Ander Conselvan de Oliveirab284eed2016-10-06 19:22:16 +03002230 pipe_config->lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002231
2232 return ret;
2233
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002234}
2235
2236static const struct drm_encoder_funcs intel_ddi_funcs = {
Imre Deakbf93ba62016-04-18 10:04:21 +03002237 .reset = intel_dp_encoder_reset,
2238 .destroy = intel_dp_encoder_destroy,
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002239};
2240
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002241static struct intel_connector *
2242intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2243{
2244 struct intel_connector *connector;
2245 enum port port = intel_dig_port->port;
2246
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002247 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002248 if (!connector)
2249 return NULL;
2250
2251 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2252 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2253 kfree(connector);
2254 return NULL;
2255 }
2256
2257 return connector;
2258}
2259
2260static struct intel_connector *
2261intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2262{
2263 struct intel_connector *connector;
2264 enum port port = intel_dig_port->port;
2265
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002266 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002267 if (!connector)
2268 return NULL;
2269
2270 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2271 intel_hdmi_init_connector(intel_dig_port, connector);
2272
2273 return connector;
2274}
2275
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002276void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002277{
2278 struct intel_digital_port *intel_dig_port;
2279 struct intel_encoder *intel_encoder;
2280 struct drm_encoder *encoder;
Shashank Sharmaff662122016-10-14 19:56:51 +05302281 bool init_hdmi, init_dp, init_lspcon = false;
Ville Syrjälä10e7bec2015-12-08 19:59:37 +02002282 int max_lanes;
2283
2284 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
2285 switch (port) {
2286 case PORT_A:
2287 max_lanes = 4;
2288 break;
2289 case PORT_E:
2290 max_lanes = 0;
2291 break;
2292 default:
2293 max_lanes = 4;
2294 break;
2295 }
2296 } else {
2297 switch (port) {
2298 case PORT_A:
2299 max_lanes = 2;
2300 break;
2301 case PORT_E:
2302 max_lanes = 2;
2303 break;
2304 default:
2305 max_lanes = 4;
2306 break;
2307 }
2308 }
Paulo Zanoni311a2092013-09-12 17:12:18 -03002309
2310 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2311 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2312 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
Shashank Sharmaff662122016-10-14 19:56:51 +05302313
2314 if (intel_bios_is_lspcon_present(dev_priv, port)) {
2315 /*
2316 * Lspcon device needs to be driven with DP connector
2317 * with special detection sequence. So make sure DP
2318 * is initialized before lspcon.
2319 */
2320 init_dp = true;
2321 init_lspcon = true;
2322 init_hdmi = false;
2323 DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
2324 }
2325
Paulo Zanoni311a2092013-09-12 17:12:18 -03002326 if (!init_dp && !init_hdmi) {
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002327 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03002328 port_name(port));
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002329 return;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002330 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002331
Daniel Vetterb14c5672013-09-19 12:18:32 +02002332 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002333 if (!intel_dig_port)
2334 return;
2335
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002336 intel_encoder = &intel_dig_port->base;
2337 encoder = &intel_encoder->base;
2338
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002339 drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03002340 DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002341
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002342 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002343 intel_encoder->enable = intel_enable_ddi;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002344 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002345 intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002346 intel_encoder->pre_enable = intel_ddi_pre_enable;
2347 intel_encoder->disable = intel_disable_ddi;
2348 intel_encoder->post_disable = intel_ddi_post_disable;
2349 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002350 intel_encoder->get_config = intel_ddi_get_config;
Imre Deakbf93ba62016-04-18 10:04:21 +03002351 intel_encoder->suspend = intel_dp_encoder_suspend;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002352 intel_encoder->get_power_domains = intel_ddi_get_power_domains;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002353
2354 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07002355 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2356 (DDI_BUF_PORT_REVERSAL |
2357 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002358
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002359 switch (port) {
2360 case PORT_A:
2361 intel_dig_port->ddi_io_power_domain =
2362 POWER_DOMAIN_PORT_DDI_A_IO;
2363 break;
2364 case PORT_B:
2365 intel_dig_port->ddi_io_power_domain =
2366 POWER_DOMAIN_PORT_DDI_B_IO;
2367 break;
2368 case PORT_C:
2369 intel_dig_port->ddi_io_power_domain =
2370 POWER_DOMAIN_PORT_DDI_C_IO;
2371 break;
2372 case PORT_D:
2373 intel_dig_port->ddi_io_power_domain =
2374 POWER_DOMAIN_PORT_DDI_D_IO;
2375 break;
2376 case PORT_E:
2377 intel_dig_port->ddi_io_power_domain =
2378 POWER_DOMAIN_PORT_DDI_E_IO;
2379 break;
2380 default:
2381 MISSING_CASE(port);
2382 }
2383
Matt Roper6c566dc2015-11-05 14:53:32 -08002384 /*
2385 * Bspec says that DDI_A_4_LANES is the only supported configuration
2386 * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
2387 * wasn't lit up at boot. Force this bit on in our internal
2388 * configuration so that we use the proper lane count for our
2389 * calculations.
2390 */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002391 if (IS_GEN9_LP(dev_priv) && port == PORT_A) {
Matt Roper6c566dc2015-11-05 14:53:32 -08002392 if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
2393 DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
2394 intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
Matt Ropered8d60f2016-01-28 15:09:37 -08002395 max_lanes = 4;
Matt Roper6c566dc2015-11-05 14:53:32 -08002396 }
2397 }
2398
Matt Ropered8d60f2016-01-28 15:09:37 -08002399 intel_dig_port->max_lanes = max_lanes;
2400
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002401 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002402 intel_encoder->power_domain = intel_port_to_power_domain(port);
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07002403 intel_encoder->port = port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002404 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02002405 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002406
Chris Wilsonf68d6972014-08-04 07:15:09 +01002407 if (init_dp) {
2408 if (!intel_ddi_init_dp_connector(intel_dig_port))
2409 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10002410
Chris Wilsonf68d6972014-08-04 07:15:09 +01002411 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Ander Conselvan de Oliveiraca4c3892017-02-03 16:03:13 +02002412 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002413 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002414
Paulo Zanoni311a2092013-09-12 17:12:18 -03002415 /* In theory we don't need the encoder->type check, but leave it just in
2416 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01002417 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2418 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2419 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002420 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01002421
Shashank Sharmaff662122016-10-14 19:56:51 +05302422 if (init_lspcon) {
2423 if (lspcon_init(intel_dig_port))
2424 /* TODO: handle hdmi info frame part */
2425 DRM_DEBUG_KMS("LSPCON init success on port %c\n",
2426 port_name(port));
2427 else
2428 /*
2429 * LSPCON init faied, but DP init was success, so
2430 * lets try to drive as DP++ port.
2431 */
2432 DRM_ERROR("LSPCON init failed on port %c\n",
2433 port_name(port));
2434 }
2435
Chris Wilsonf68d6972014-08-04 07:15:09 +01002436 return;
2437
2438err:
2439 drm_encoder_cleanup(encoder);
2440 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002441}