blob: aaaca906c97fa37ae21c0cc8a505028c294977fc [file] [log] [blame]
Eugeni Dodonov45244b82012-05-09 15:37:20 -03001/*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 *
26 */
27
28#include "i915_drv.h"
29#include "intel_drv.h"
30
Jani Nikula10122052014-08-27 16:27:30 +030031struct ddi_buf_trans {
32 u32 trans1; /* balance leg enable, de-emph level */
33 u32 trans2; /* vref sel, vswing */
David Weinehallf8896f52015-06-25 11:11:03 +030034 u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */
Jani Nikula10122052014-08-27 16:27:30 +030035};
36
Ville Syrjälä97eeb872017-02-23 19:35:06 +020037static const u8 index_to_dp_signal_levels[] = {
38 [0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0,
39 [1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1,
40 [2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2,
41 [3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3,
42 [4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0,
43 [5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1,
44 [6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2,
45 [7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0,
46 [8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1,
47 [9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0,
48};
49
Eugeni Dodonov45244b82012-05-09 15:37:20 -030050/* HDMI/DVI modes ignore everything but the last 2 items. So we share
51 * them for both DP and FDI transports, allowing those ports to
52 * automatically adapt to HDMI connections as well
53 */
Jani Nikula10122052014-08-27 16:27:30 +030054static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030055 { 0x00FFFFFF, 0x0006000E, 0x0 },
56 { 0x00D75FFF, 0x0005000A, 0x0 },
57 { 0x00C30FFF, 0x00040006, 0x0 },
58 { 0x80AAAFFF, 0x000B0000, 0x0 },
59 { 0x00FFFFFF, 0x0005000A, 0x0 },
60 { 0x00D75FFF, 0x000C0004, 0x0 },
61 { 0x80C30FFF, 0x000B0000, 0x0 },
62 { 0x00FFFFFF, 0x00040006, 0x0 },
63 { 0x80D75FFF, 0x000B0000, 0x0 },
Eugeni Dodonov45244b82012-05-09 15:37:20 -030064};
65
Jani Nikula10122052014-08-27 16:27:30 +030066static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030067 { 0x00FFFFFF, 0x0007000E, 0x0 },
68 { 0x00D75FFF, 0x000F000A, 0x0 },
69 { 0x00C30FFF, 0x00060006, 0x0 },
70 { 0x00AAAFFF, 0x001E0000, 0x0 },
71 { 0x00FFFFFF, 0x000F000A, 0x0 },
72 { 0x00D75FFF, 0x00160004, 0x0 },
73 { 0x00C30FFF, 0x001E0000, 0x0 },
74 { 0x00FFFFFF, 0x00060006, 0x0 },
75 { 0x00D75FFF, 0x001E0000, 0x0 },
Paulo Zanoni6acab152013-09-12 17:06:24 -030076};
77
Jani Nikula10122052014-08-27 16:27:30 +030078static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
79 /* Idx NT mV d T mV d db */
David Weinehallf8896f52015-06-25 11:11:03 +030080 { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */
81 { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */
82 { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */
83 { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */
84 { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */
85 { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */
86 { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */
87 { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */
88 { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */
89 { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */
90 { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */
91 { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */
Eugeni Dodonov45244b82012-05-09 15:37:20 -030092};
93
Jani Nikula10122052014-08-27 16:27:30 +030094static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030095 { 0x00FFFFFF, 0x00000012, 0x0 },
96 { 0x00EBAFFF, 0x00020011, 0x0 },
97 { 0x00C71FFF, 0x0006000F, 0x0 },
98 { 0x00AAAFFF, 0x000E000A, 0x0 },
99 { 0x00FFFFFF, 0x00020011, 0x0 },
100 { 0x00DB6FFF, 0x0005000F, 0x0 },
101 { 0x00BEEFFF, 0x000A000C, 0x0 },
102 { 0x00FFFFFF, 0x0005000F, 0x0 },
103 { 0x00DB6FFF, 0x000A000C, 0x0 },
Paulo Zanoni300644c2013-11-02 21:07:42 -0700104};
105
Jani Nikula10122052014-08-27 16:27:30 +0300106static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300107 { 0x00FFFFFF, 0x0007000E, 0x0 },
108 { 0x00D75FFF, 0x000E000A, 0x0 },
109 { 0x00BEFFFF, 0x00140006, 0x0 },
110 { 0x80B2CFFF, 0x001B0002, 0x0 },
111 { 0x00FFFFFF, 0x000E000A, 0x0 },
112 { 0x00DB6FFF, 0x00160005, 0x0 },
113 { 0x80C71FFF, 0x001A0002, 0x0 },
114 { 0x00F7DFFF, 0x00180004, 0x0 },
115 { 0x80D75FFF, 0x001B0002, 0x0 },
Art Runyane58623c2013-11-02 21:07:41 -0700116};
117
Jani Nikula10122052014-08-27 16:27:30 +0300118static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300119 { 0x00FFFFFF, 0x0001000E, 0x0 },
120 { 0x00D75FFF, 0x0004000A, 0x0 },
121 { 0x00C30FFF, 0x00070006, 0x0 },
122 { 0x00AAAFFF, 0x000C0000, 0x0 },
123 { 0x00FFFFFF, 0x0004000A, 0x0 },
124 { 0x00D75FFF, 0x00090004, 0x0 },
125 { 0x00C30FFF, 0x000C0000, 0x0 },
126 { 0x00FFFFFF, 0x00070006, 0x0 },
127 { 0x00D75FFF, 0x000C0000, 0x0 },
Art Runyane58623c2013-11-02 21:07:41 -0700128};
129
Jani Nikula10122052014-08-27 16:27:30 +0300130static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
131 /* Idx NT mV d T mV df db */
David Weinehallf8896f52015-06-25 11:11:03 +0300132 { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */
133 { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */
134 { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */
135 { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */
136 { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */
137 { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */
138 { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */
139 { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */
140 { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */
141 { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100142};
143
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700144/* Skylake H and S */
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000145static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300146 { 0x00002016, 0x000000A0, 0x0 },
147 { 0x00005012, 0x0000009B, 0x0 },
148 { 0x00007011, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800149 { 0x80009010, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300150 { 0x00002016, 0x0000009B, 0x0 },
151 { 0x00005012, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800152 { 0x80007011, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300153 { 0x00002016, 0x000000DF, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800154 { 0x80005012, 0x000000C0, 0x1 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000155};
156
David Weinehallf8896f52015-06-25 11:11:03 +0300157/* Skylake U */
158static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700159 { 0x0000201B, 0x000000A2, 0x0 },
David Weinehallf8896f52015-06-25 11:11:03 +0300160 { 0x00005012, 0x00000088, 0x0 },
Ville Syrjälä5ac90562016-08-02 15:21:57 +0300161 { 0x80007011, 0x000000CD, 0x1 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800162 { 0x80009010, 0x000000C0, 0x1 },
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700163 { 0x0000201B, 0x0000009D, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800164 { 0x80005012, 0x000000C0, 0x1 },
165 { 0x80007011, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300166 { 0x00002016, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800167 { 0x80005012, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300168};
169
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700170/* Skylake Y */
171static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300172 { 0x00000018, 0x000000A2, 0x0 },
173 { 0x00005012, 0x00000088, 0x0 },
Ville Syrjälä5ac90562016-08-02 15:21:57 +0300174 { 0x80007011, 0x000000CD, 0x3 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800175 { 0x80009010, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300176 { 0x00000018, 0x0000009D, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800177 { 0x80005012, 0x000000C0, 0x3 },
178 { 0x80007011, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300179 { 0x00000018, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800180 { 0x80005012, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300181};
182
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700183/* Kabylake H and S */
184static const struct ddi_buf_trans kbl_ddi_translations_dp[] = {
185 { 0x00002016, 0x000000A0, 0x0 },
186 { 0x00005012, 0x0000009B, 0x0 },
187 { 0x00007011, 0x00000088, 0x0 },
188 { 0x80009010, 0x000000C0, 0x1 },
189 { 0x00002016, 0x0000009B, 0x0 },
190 { 0x00005012, 0x00000088, 0x0 },
191 { 0x80007011, 0x000000C0, 0x1 },
192 { 0x00002016, 0x00000097, 0x0 },
193 { 0x80005012, 0x000000C0, 0x1 },
194};
195
196/* Kabylake U */
197static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = {
198 { 0x0000201B, 0x000000A1, 0x0 },
199 { 0x00005012, 0x00000088, 0x0 },
200 { 0x80007011, 0x000000CD, 0x3 },
201 { 0x80009010, 0x000000C0, 0x3 },
202 { 0x0000201B, 0x0000009D, 0x0 },
203 { 0x80005012, 0x000000C0, 0x3 },
204 { 0x80007011, 0x000000C0, 0x3 },
205 { 0x00002016, 0x0000004F, 0x0 },
206 { 0x80005012, 0x000000C0, 0x3 },
207};
208
209/* Kabylake Y */
210static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = {
211 { 0x00001017, 0x000000A1, 0x0 },
212 { 0x00005012, 0x00000088, 0x0 },
213 { 0x80007011, 0x000000CD, 0x3 },
214 { 0x8000800F, 0x000000C0, 0x3 },
215 { 0x00001017, 0x0000009D, 0x0 },
216 { 0x80005012, 0x000000C0, 0x3 },
217 { 0x80007011, 0x000000C0, 0x3 },
218 { 0x00001017, 0x0000004C, 0x0 },
219 { 0x80005012, 0x000000C0, 0x3 },
220};
221
David Weinehallf8896f52015-06-25 11:11:03 +0300222/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700223 * Skylake/Kabylake H and S
David Weinehallf8896f52015-06-25 11:11:03 +0300224 * eDP 1.4 low vswing translation parameters
225 */
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530226static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300227 { 0x00000018, 0x000000A8, 0x0 },
228 { 0x00004013, 0x000000A9, 0x0 },
229 { 0x00007011, 0x000000A2, 0x0 },
230 { 0x00009010, 0x0000009C, 0x0 },
231 { 0x00000018, 0x000000A9, 0x0 },
232 { 0x00006013, 0x000000A2, 0x0 },
233 { 0x00007011, 0x000000A6, 0x0 },
234 { 0x00000018, 0x000000AB, 0x0 },
235 { 0x00007013, 0x0000009F, 0x0 },
236 { 0x00000018, 0x000000DF, 0x0 },
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530237};
238
David Weinehallf8896f52015-06-25 11:11:03 +0300239/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700240 * Skylake/Kabylake U
David Weinehallf8896f52015-06-25 11:11:03 +0300241 * eDP 1.4 low vswing translation parameters
242 */
243static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
244 { 0x00000018, 0x000000A8, 0x0 },
245 { 0x00004013, 0x000000A9, 0x0 },
246 { 0x00007011, 0x000000A2, 0x0 },
247 { 0x00009010, 0x0000009C, 0x0 },
248 { 0x00000018, 0x000000A9, 0x0 },
249 { 0x00006013, 0x000000A2, 0x0 },
250 { 0x00007011, 0x000000A6, 0x0 },
251 { 0x00002016, 0x000000AB, 0x0 },
252 { 0x00005013, 0x0000009F, 0x0 },
253 { 0x00000018, 0x000000DF, 0x0 },
254};
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530255
David Weinehallf8896f52015-06-25 11:11:03 +0300256/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700257 * Skylake/Kabylake Y
David Weinehallf8896f52015-06-25 11:11:03 +0300258 * eDP 1.4 low vswing translation parameters
259 */
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700260static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300261 { 0x00000018, 0x000000A8, 0x0 },
262 { 0x00004013, 0x000000AB, 0x0 },
263 { 0x00007011, 0x000000A4, 0x0 },
264 { 0x00009010, 0x000000DF, 0x0 },
265 { 0x00000018, 0x000000AA, 0x0 },
266 { 0x00006013, 0x000000A4, 0x0 },
267 { 0x00007011, 0x0000009D, 0x0 },
268 { 0x00000018, 0x000000A0, 0x0 },
269 { 0x00006012, 0x000000DF, 0x0 },
270 { 0x00000018, 0x0000008A, 0x0 },
271};
272
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700273/* Skylake/Kabylake U, H and S */
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000274static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300275 { 0x00000018, 0x000000AC, 0x0 },
276 { 0x00005012, 0x0000009D, 0x0 },
277 { 0x00007011, 0x00000088, 0x0 },
278 { 0x00000018, 0x000000A1, 0x0 },
279 { 0x00000018, 0x00000098, 0x0 },
280 { 0x00004013, 0x00000088, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800281 { 0x80006012, 0x000000CD, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300282 { 0x00000018, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800283 { 0x80003015, 0x000000CD, 0x1 }, /* Default */
284 { 0x80003015, 0x000000C0, 0x1 },
285 { 0x80000018, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300286};
287
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700288/* Skylake/Kabylake Y */
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700289static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300290 { 0x00000018, 0x000000A1, 0x0 },
291 { 0x00005012, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800292 { 0x80007011, 0x000000CB, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300293 { 0x00000018, 0x000000A4, 0x0 },
294 { 0x00000018, 0x0000009D, 0x0 },
295 { 0x00004013, 0x00000080, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800296 { 0x80006013, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300297 { 0x00000018, 0x0000008A, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800298 { 0x80003015, 0x000000C0, 0x3 }, /* Default */
299 { 0x80003015, 0x000000C0, 0x3 },
300 { 0x80000018, 0x000000C0, 0x3 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000301};
302
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530303struct bxt_ddi_buf_trans {
Ville Syrjäläac3ad6c2017-09-18 21:25:37 +0300304 u8 margin; /* swing value */
305 u8 scale; /* scale value */
306 u8 enable; /* scale enable */
307 u8 deemphasis;
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530308};
309
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530310static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
311 /* Idx NT mV diff db */
Ville Syrjälä043eaf32017-10-16 17:57:02 +0300312 { 52, 0x9A, 0, 128, }, /* 0: 400 0 */
313 { 78, 0x9A, 0, 85, }, /* 1: 400 3.5 */
314 { 104, 0x9A, 0, 64, }, /* 2: 400 6 */
315 { 154, 0x9A, 0, 43, }, /* 3: 400 9.5 */
316 { 77, 0x9A, 0, 128, }, /* 4: 600 0 */
317 { 116, 0x9A, 0, 85, }, /* 5: 600 3.5 */
318 { 154, 0x9A, 0, 64, }, /* 6: 600 6 */
319 { 102, 0x9A, 0, 128, }, /* 7: 800 0 */
320 { 154, 0x9A, 0, 85, }, /* 8: 800 3.5 */
321 { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530322};
323
Sonika Jindald9d70002015-09-24 10:24:56 +0530324static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
325 /* Idx NT mV diff db */
Ville Syrjälä043eaf32017-10-16 17:57:02 +0300326 { 26, 0, 0, 128, }, /* 0: 200 0 */
327 { 38, 0, 0, 112, }, /* 1: 200 1.5 */
328 { 48, 0, 0, 96, }, /* 2: 200 4 */
329 { 54, 0, 0, 69, }, /* 3: 200 6 */
330 { 32, 0, 0, 128, }, /* 4: 250 0 */
331 { 48, 0, 0, 104, }, /* 5: 250 1.5 */
332 { 54, 0, 0, 85, }, /* 6: 250 4 */
333 { 43, 0, 0, 128, }, /* 7: 300 0 */
334 { 54, 0, 0, 101, }, /* 8: 300 1.5 */
335 { 48, 0, 0, 128, }, /* 9: 300 0 */
Sonika Jindald9d70002015-09-24 10:24:56 +0530336};
337
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530338/* BSpec has 2 recommended values - entries 0 and 8.
339 * Using the entry with higher vswing.
340 */
341static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
342 /* Idx NT mV diff db */
Ville Syrjälä043eaf32017-10-16 17:57:02 +0300343 { 52, 0x9A, 0, 128, }, /* 0: 400 0 */
344 { 52, 0x9A, 0, 85, }, /* 1: 400 3.5 */
345 { 52, 0x9A, 0, 64, }, /* 2: 400 6 */
346 { 42, 0x9A, 0, 43, }, /* 3: 400 9.5 */
347 { 77, 0x9A, 0, 128, }, /* 4: 600 0 */
348 { 77, 0x9A, 0, 85, }, /* 5: 600 3.5 */
349 { 77, 0x9A, 0, 64, }, /* 6: 600 6 */
350 { 102, 0x9A, 0, 128, }, /* 7: 800 0 */
351 { 102, 0x9A, 0, 85, }, /* 8: 800 3.5 */
352 { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530353};
354
Rodrigo Vivi83fb7ab2017-06-09 15:26:07 -0700355struct cnl_ddi_buf_trans {
Ville Syrjäläfb5f4e92017-09-18 21:25:38 +0300356 u8 dw2_swing_sel;
357 u8 dw7_n_scalar;
358 u8 dw4_cursor_coeff;
359 u8 dw4_post_cursor_2;
360 u8 dw4_post_cursor_1;
Rodrigo Vivi83fb7ab2017-06-09 15:26:07 -0700361};
362
363/* Voltage Swing Programming for VccIO 0.85V for DP */
364static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V[] = {
365 /* NT mV Trans mV db */
366 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
367 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
368 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
369 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
370 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
371 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
372 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
373 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
374 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
375 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
376};
377
378/* Voltage Swing Programming for VccIO 0.85V for HDMI */
379static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V[] = {
380 /* NT mV Trans mV db */
381 { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
382 { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */
383 { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */
384 { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 */
385 { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */
386 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */
387 { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
388};
389
390/* Voltage Swing Programming for VccIO 0.85V for eDP */
391static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V[] = {
392 /* NT mV Trans mV db */
393 { 0xA, 0x66, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
394 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
395 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
396 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
397 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
398 { 0xA, 0x66, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
399 { 0xB, 0x70, 0x3C, 0x00, 0x03 }, /* 460 600 2.3 */
400 { 0xC, 0x75, 0x3C, 0x00, 0x03 }, /* 537 700 2.3 */
401 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
402};
403
404/* Voltage Swing Programming for VccIO 0.95V for DP */
405static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V[] = {
406 /* NT mV Trans mV db */
407 { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
408 { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
409 { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
410 { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
411 { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
412 { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
413 { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
414 { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
415 { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
416 { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
417};
418
419/* Voltage Swing Programming for VccIO 0.95V for HDMI */
420static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V[] = {
421 /* NT mV Trans mV db */
422 { 0xA, 0x5C, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
423 { 0xB, 0x69, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
424 { 0x5, 0x76, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
425 { 0xA, 0x5E, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
426 { 0xB, 0x69, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
427 { 0xB, 0x79, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
428 { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
429 { 0x5, 0x76, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
430 { 0x6, 0x7D, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
431 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
432 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
433};
434
435/* Voltage Swing Programming for VccIO 0.95V for eDP */
436static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V[] = {
437 /* NT mV Trans mV db */
438 { 0xA, 0x61, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
439 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
440 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
441 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
442 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
443 { 0xA, 0x61, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
444 { 0xB, 0x68, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
445 { 0xC, 0x6E, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
446 { 0x4, 0x7F, 0x3A, 0x00, 0x05 }, /* 460 600 2.3 */
447 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
448};
449
450/* Voltage Swing Programming for VccIO 1.05V for DP */
451static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V[] = {
452 /* NT mV Trans mV db */
453 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
454 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
455 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
456 { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 400 1050 8.4 */
457 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
458 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
459 { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 550 1050 5.6 */
460 { 0x5, 0x76, 0x3E, 0x00, 0x01 }, /* 850 900 0.5 */
461 { 0x6, 0x7F, 0x36, 0x00, 0x09 }, /* 750 1050 2.9 */
462 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
463};
464
465/* Voltage Swing Programming for VccIO 1.05V for HDMI */
466static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V[] = {
467 /* NT mV Trans mV db */
468 { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
469 { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
470 { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
471 { 0xA, 0x5B, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
472 { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
473 { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
474 { 0x6, 0x7C, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
475 { 0x5, 0x70, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
476 { 0x6, 0x7C, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
477 { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
478 { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
479};
480
481/* Voltage Swing Programming for VccIO 1.05V for eDP */
482static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V[] = {
483 /* NT mV Trans mV db */
484 { 0xA, 0x5E, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
485 { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
486 { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
487 { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
488 { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
489 { 0xA, 0x5E, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
490 { 0xB, 0x64, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
491 { 0xE, 0x6A, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
492 { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
493};
494
Ville Syrjäläacee2992015-12-08 19:59:39 +0200495static const struct ddi_buf_trans *
Ville Syrjäläa930acd2016-07-12 15:59:36 +0300496bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
497{
498 if (dev_priv->vbt.edp.low_vswing) {
499 *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
500 return bdw_ddi_translations_edp;
501 } else {
502 *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
503 return bdw_ddi_translations_dp;
504 }
505}
506
507static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200508skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300509{
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700510 if (IS_SKL_ULX(dev_priv)) {
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700511 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200512 return skl_y_ddi_translations_dp;
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700513 } else if (IS_SKL_ULT(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +0300514 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200515 return skl_u_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300516 } else {
David Weinehallf8896f52015-06-25 11:11:03 +0300517 *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200518 return skl_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300519 }
David Weinehallf8896f52015-06-25 11:11:03 +0300520}
521
522static const struct ddi_buf_trans *
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700523kbl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
524{
525 if (IS_KBL_ULX(dev_priv)) {
526 *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp);
527 return kbl_y_ddi_translations_dp;
Rodrigo Vivida411a42017-06-09 15:02:50 -0700528 } else if (IS_KBL_ULT(dev_priv) || IS_CFL_ULT(dev_priv)) {
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700529 *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
530 return kbl_u_ddi_translations_dp;
531 } else {
532 *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
533 return kbl_ddi_translations_dp;
534 }
535}
536
537static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200538skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300539{
Jani Nikula06411f02016-03-24 17:50:21 +0200540 if (dev_priv->vbt.edp.low_vswing) {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200541 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200542 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
543 return skl_y_ddi_translations_edp;
Rodrigo Vivida411a42017-06-09 15:02:50 -0700544 } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv) ||
545 IS_CFL_ULT(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200546 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
547 return skl_u_ddi_translations_edp;
548 } else {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200549 *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
550 return skl_ddi_translations_edp;
Ville Syrjäläacee2992015-12-08 19:59:39 +0200551 }
David Weinehallf8896f52015-06-25 11:11:03 +0300552 }
Ville Syrjäläcd1101c2015-12-08 19:59:40 +0200553
Rodrigo Vivida411a42017-06-09 15:02:50 -0700554 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700555 return kbl_get_buf_trans_dp(dev_priv, n_entries);
556 else
557 return skl_get_buf_trans_dp(dev_priv, n_entries);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200558}
David Weinehallf8896f52015-06-25 11:11:03 +0300559
Ville Syrjäläacee2992015-12-08 19:59:39 +0200560static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200561skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
Ville Syrjäläacee2992015-12-08 19:59:39 +0200562{
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200563 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200564 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
565 return skl_y_ddi_translations_hdmi;
566 } else {
567 *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
568 return skl_ddi_translations_hdmi;
569 }
David Weinehallf8896f52015-06-25 11:11:03 +0300570}
571
Ville Syrjäläedba48f2017-10-16 17:57:03 +0300572static int skl_buf_trans_num_entries(enum port port, int n_entries)
573{
574 /* Only DDIA and DDIE can select the 10th register with DP */
575 if (port == PORT_A || port == PORT_E)
576 return min(n_entries, 10);
577 else
578 return min(n_entries, 9);
579}
580
Ville Syrjäläd8fe2c72017-10-16 17:56:56 +0300581static const struct ddi_buf_trans *
582intel_ddi_get_buf_trans_dp(struct drm_i915_private *dev_priv,
Ville Syrjäläedba48f2017-10-16 17:57:03 +0300583 enum port port, int *n_entries)
Ville Syrjäläd8fe2c72017-10-16 17:56:56 +0300584{
585 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
Ville Syrjäläedba48f2017-10-16 17:57:03 +0300586 const struct ddi_buf_trans *ddi_translations =
587 kbl_get_buf_trans_dp(dev_priv, n_entries);
588 *n_entries = skl_buf_trans_num_entries(port, *n_entries);
589 return ddi_translations;
Ville Syrjäläd8fe2c72017-10-16 17:56:56 +0300590 } else if (IS_SKYLAKE(dev_priv)) {
Ville Syrjäläedba48f2017-10-16 17:57:03 +0300591 const struct ddi_buf_trans *ddi_translations =
592 skl_get_buf_trans_dp(dev_priv, n_entries);
593 *n_entries = skl_buf_trans_num_entries(port, *n_entries);
594 return ddi_translations;
Ville Syrjäläd8fe2c72017-10-16 17:56:56 +0300595 } else if (IS_BROADWELL(dev_priv)) {
596 *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
597 return bdw_ddi_translations_dp;
598 } else if (IS_HASWELL(dev_priv)) {
599 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
600 return hsw_ddi_translations_dp;
601 }
602
603 *n_entries = 0;
604 return NULL;
605}
606
607static const struct ddi_buf_trans *
608intel_ddi_get_buf_trans_edp(struct drm_i915_private *dev_priv,
Ville Syrjäläedba48f2017-10-16 17:57:03 +0300609 enum port port, int *n_entries)
Ville Syrjäläd8fe2c72017-10-16 17:56:56 +0300610{
611 if (IS_GEN9_BC(dev_priv)) {
Ville Syrjäläedba48f2017-10-16 17:57:03 +0300612 const struct ddi_buf_trans *ddi_translations =
613 skl_get_buf_trans_edp(dev_priv, n_entries);
614 *n_entries = skl_buf_trans_num_entries(port, *n_entries);
615 return ddi_translations;
Ville Syrjäläd8fe2c72017-10-16 17:56:56 +0300616 } else if (IS_BROADWELL(dev_priv)) {
617 return bdw_get_buf_trans_edp(dev_priv, n_entries);
618 } else if (IS_HASWELL(dev_priv)) {
619 *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
620 return hsw_ddi_translations_dp;
621 }
622
623 *n_entries = 0;
624 return NULL;
625}
626
627static const struct ddi_buf_trans *
628intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv,
629 int *n_entries)
630{
631 if (IS_BROADWELL(dev_priv)) {
632 *n_entries = ARRAY_SIZE(bdw_ddi_translations_fdi);
633 return bdw_ddi_translations_fdi;
634 } else if (IS_HASWELL(dev_priv)) {
635 *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
636 return hsw_ddi_translations_fdi;
637 }
638
639 *n_entries = 0;
640 return NULL;
641}
642
Ville Syrjälä975786e2017-10-16 17:56:57 +0300643static const struct ddi_buf_trans *
644intel_ddi_get_buf_trans_hdmi(struct drm_i915_private *dev_priv,
645 int *n_entries)
646{
647 if (IS_GEN9_BC(dev_priv)) {
648 return skl_get_buf_trans_hdmi(dev_priv, n_entries);
649 } else if (IS_BROADWELL(dev_priv)) {
650 *n_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
651 return bdw_ddi_translations_hdmi;
652 } else if (IS_HASWELL(dev_priv)) {
653 *n_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
654 return hsw_ddi_translations_hdmi;
655 }
656
657 *n_entries = 0;
658 return NULL;
659}
660
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +0300661static const struct bxt_ddi_buf_trans *
662bxt_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
663{
664 *n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
665 return bxt_ddi_translations_dp;
666}
667
668static const struct bxt_ddi_buf_trans *
669bxt_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
670{
671 if (dev_priv->vbt.edp.low_vswing) {
672 *n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
673 return bxt_ddi_translations_edp;
674 }
675
676 return bxt_get_buf_trans_dp(dev_priv, n_entries);
677}
678
679static const struct bxt_ddi_buf_trans *
680bxt_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
681{
682 *n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
683 return bxt_ddi_translations_hdmi;
684}
685
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700686static const struct cnl_ddi_buf_trans *
687cnl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
688{
689 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
690
691 if (voltage == VOLTAGE_INFO_0_85V) {
692 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V);
693 return cnl_ddi_translations_hdmi_0_85V;
694 } else if (voltage == VOLTAGE_INFO_0_95V) {
695 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V);
696 return cnl_ddi_translations_hdmi_0_95V;
697 } else if (voltage == VOLTAGE_INFO_1_05V) {
698 *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V);
699 return cnl_ddi_translations_hdmi_1_05V;
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200700 } else {
701 *n_entries = 1; /* shut up gcc */
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700702 MISSING_CASE(voltage);
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200703 }
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700704 return NULL;
705}
706
707static const struct cnl_ddi_buf_trans *
708cnl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
709{
710 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
711
712 if (voltage == VOLTAGE_INFO_0_85V) {
713 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V);
714 return cnl_ddi_translations_dp_0_85V;
715 } else if (voltage == VOLTAGE_INFO_0_95V) {
716 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V);
717 return cnl_ddi_translations_dp_0_95V;
718 } else if (voltage == VOLTAGE_INFO_1_05V) {
719 *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V);
720 return cnl_ddi_translations_dp_1_05V;
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200721 } else {
722 *n_entries = 1; /* shut up gcc */
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700723 MISSING_CASE(voltage);
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200724 }
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700725 return NULL;
726}
727
728static const struct cnl_ddi_buf_trans *
729cnl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
730{
731 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
732
733 if (dev_priv->vbt.edp.low_vswing) {
734 if (voltage == VOLTAGE_INFO_0_85V) {
735 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V);
736 return cnl_ddi_translations_edp_0_85V;
737 } else if (voltage == VOLTAGE_INFO_0_95V) {
738 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V);
739 return cnl_ddi_translations_edp_0_95V;
740 } else if (voltage == VOLTAGE_INFO_1_05V) {
741 *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V);
742 return cnl_ddi_translations_edp_1_05V;
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200743 } else {
744 *n_entries = 1; /* shut up gcc */
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700745 MISSING_CASE(voltage);
Arnd Bergmann83482ca2017-10-05 14:08:26 +0200746 }
Rodrigo Vivicf3e0fb2017-08-29 16:22:28 -0700747 return NULL;
748 } else {
749 return cnl_get_buf_trans_dp(dev_priv, n_entries);
750 }
751}
752
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300753static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
754{
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300755 int n_entries, level, default_entry;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300756
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300757 level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300758
Rodrigo Vivibf503552017-08-29 16:22:29 -0700759 if (IS_CANNONLAKE(dev_priv)) {
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300760 cnl_get_buf_trans_hdmi(dev_priv, &n_entries);
761 default_entry = n_entries - 1;
Ville Syrjälä043eaf32017-10-16 17:57:02 +0300762 } else if (IS_GEN9_LP(dev_priv)) {
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300763 bxt_get_buf_trans_hdmi(dev_priv, &n_entries);
764 default_entry = n_entries - 1;
Rodrigo Vivibf503552017-08-29 16:22:29 -0700765 } else if (IS_GEN9_BC(dev_priv)) {
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300766 intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries);
767 default_entry = 8;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300768 } else if (IS_BROADWELL(dev_priv)) {
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300769 intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries);
770 default_entry = 7;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300771 } else if (IS_HASWELL(dev_priv)) {
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300772 intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries);
773 default_entry = 6;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300774 } else {
775 WARN(1, "ddi translation table missing\n");
Ville Syrjälä975786e2017-10-16 17:56:57 +0300776 return 0;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300777 }
778
779 /* Choose a good default if VBT is badly populated */
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300780 if (level == HDMI_LEVEL_SHIFT_UNKNOWN || level >= n_entries)
781 level = default_entry;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300782
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300783 if (WARN_ON_ONCE(n_entries == 0))
Ville Syrjälä21b39d22017-10-18 21:19:34 +0300784 return 0;
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300785 if (WARN_ON_ONCE(level >= n_entries))
786 level = n_entries - 1;
Ville Syrjälä21b39d22017-10-18 21:19:34 +0300787
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300788 return level;
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300789}
790
Art Runyane58623c2013-11-02 21:07:41 -0700791/*
792 * Starting with Haswell, DDI port buffers must be programmed with correct
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300793 * values in advance. This function programs the correct values for
794 * DP/eDP/FDI use cases.
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300795 */
Ville Syrjälä3a6d84e2017-10-19 16:37:13 +0300796static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder,
797 const struct intel_crtc_state *crtc_state)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300798{
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200799 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300800 u32 iboost_bit = 0;
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200801 int i, n_entries;
Ville Syrjälä0fce04c2017-10-27 22:31:25 +0300802 enum port port = encoder->port;
Jani Nikula10122052014-08-27 16:27:30 +0300803 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700804
Ville Syrjälä3a6d84e2017-10-19 16:37:13 +0300805 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200806 ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
807 &n_entries);
Ville Syrjälä3a6d84e2017-10-19 16:37:13 +0300808 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP))
809 ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv, port,
810 &n_entries);
811 else
812 ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv, port,
813 &n_entries);
Art Runyane58623c2013-11-02 21:07:41 -0700814
Ville Syrjäläedba48f2017-10-16 17:57:03 +0300815 /* If we're boosting the current, set bit 31 of trans1 */
816 if (IS_GEN9_BC(dev_priv) &&
817 dev_priv->vbt.ddi_port_info[port].dp_boost_level)
818 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
Rodrigo Vivi0a918772016-09-30 11:05:56 -0700819
Ville Syrjälä7d1c42e2017-02-23 19:35:05 +0200820 for (i = 0; i < n_entries; i++) {
Ville Syrjälä9712e682015-09-18 20:03:22 +0300821 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
822 ddi_translations[i].trans1 | iboost_bit);
823 I915_WRITE(DDI_BUF_TRANS_HI(port, i),
824 ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300825 }
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300826}
Damien Lespiauce4dd492014-08-01 11:07:54 +0100827
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300828/*
829 * Starting with Haswell, DDI port buffers must be programmed with correct
830 * values in advance. This function programs the correct values for
831 * HDMI/DVI use cases.
832 */
Ville Syrjälä7ea79332017-10-16 17:56:59 +0300833static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder,
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300834 int level)
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300835{
836 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
837 u32 iboost_bit = 0;
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300838 int n_entries;
Ville Syrjälä0fce04c2017-10-27 22:31:25 +0300839 enum port port = encoder->port;
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300840 const struct ddi_buf_trans *ddi_translations;
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300841
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300842 ddi_translations = intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries);
Ville Syrjälä1edaaa22016-07-12 15:59:34 +0300843
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300844 if (WARN_ON_ONCE(!ddi_translations))
Ville Syrjälä21b39d22017-10-18 21:19:34 +0300845 return;
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300846 if (WARN_ON_ONCE(level >= n_entries))
847 level = n_entries - 1;
Ville Syrjälä21b39d22017-10-18 21:19:34 +0300848
Ville Syrjälä975786e2017-10-16 17:56:57 +0300849 /* If we're boosting the current, set bit 31 of trans1 */
850 if (IS_GEN9_BC(dev_priv) &&
851 dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
852 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300853
Paulo Zanoni6acab152013-09-12 17:06:24 -0300854 /* Entry 9 is for HDMI: */
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300855 I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300856 ddi_translations[level].trans1 | iboost_bit);
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300857 I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
Ville Syrjäläd02ace82017-10-18 21:19:58 +0300858 ddi_translations[level].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300859}
860
Paulo Zanoni248138b2012-11-29 11:29:31 -0200861static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
862 enum port port)
863{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200864 i915_reg_t reg = DDI_BUF_CTL(port);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200865 int i;
866
Vandana Kannan3449ca82015-03-27 14:19:09 +0200867 for (i = 0; i < 16; i++) {
Paulo Zanoni248138b2012-11-29 11:29:31 -0200868 udelay(1);
869 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
870 return;
871 }
872 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
873}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300874
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +0300875static uint32_t hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll)
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700876{
877 switch (pll->id) {
878 case DPLL_ID_WRPLL1:
879 return PORT_CLK_SEL_WRPLL1;
880 case DPLL_ID_WRPLL2:
881 return PORT_CLK_SEL_WRPLL2;
882 case DPLL_ID_SPLL:
883 return PORT_CLK_SEL_SPLL;
884 case DPLL_ID_LCPLL_810:
885 return PORT_CLK_SEL_LCPLL_810;
886 case DPLL_ID_LCPLL_1350:
887 return PORT_CLK_SEL_LCPLL_1350;
888 case DPLL_ID_LCPLL_2700:
889 return PORT_CLK_SEL_LCPLL_2700;
890 default:
891 MISSING_CASE(pll->id);
892 return PORT_CLK_SEL_NONE;
893 }
894}
895
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300896/* Starting with Haswell, different DDI ports can work in FDI mode for
897 * connection to the PCH-located connectors. For this, it is necessary to train
898 * both the DDI port and PCH receiver for the desired DDI buffer settings.
899 *
900 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
901 * please note that when FDI mode is active on DDI E, it shares 2 lines with
902 * DDI A (which is used for eDP)
903 */
904
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200905void hsw_fdi_link_train(struct intel_crtc *crtc,
906 const struct intel_crtc_state *crtc_state)
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300907{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +0200908 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100909 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200910 struct intel_encoder *encoder;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700911 u32 temp, i, rx_ctl_val, ddi_pll_sel;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300912
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +0200913 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200914 WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
Ville Syrjälä3a6d84e2017-10-19 16:37:13 +0300915 intel_prepare_dp_ddi_buffers(encoder, crtc_state);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200916 }
917
Paulo Zanoni04945642012-11-01 21:00:59 -0200918 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
919 * mode set "sequence for CRT port" document:
920 * - TP1 to TP2 time with the default value
921 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100922 *
923 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200924 */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300925 I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200926 FDI_RX_PWRDN_LANE0_VAL(2) |
927 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
928
929 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000930 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100931 FDI_RX_PLL_ENABLE |
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200932 FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300933 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
934 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200935 udelay(220);
936
937 /* Switch from Rawclk to PCDclk */
938 rx_ctl_val |= FDI_PCDCLK;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300939 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
Paulo Zanoni04945642012-11-01 21:00:59 -0200940
941 /* Configure Port Clock Select */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200942 ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700943 I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
944 WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200945
946 /* Start the training iterating through available voltages and emphasis,
947 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300948 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300949 /* Configure DP_TP_CTL with auto-training */
950 I915_WRITE(DP_TP_CTL(PORT_E),
951 DP_TP_CTL_FDI_AUTOTRAIN |
952 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
953 DP_TP_CTL_LINK_TRAIN_PAT1 |
954 DP_TP_CTL_ENABLE);
955
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000956 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
957 * DDI E does not support port reversal, the functionality is
958 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
959 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300960 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200961 DDI_BUF_CTL_ENABLE |
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +0200962 ((crtc_state->fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530963 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200964 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300965
966 udelay(600);
967
Paulo Zanoni04945642012-11-01 21:00:59 -0200968 /* Program PCH FDI Receiver TU */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300969 I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300970
Paulo Zanoni04945642012-11-01 21:00:59 -0200971 /* Enable PCH FDI Receiver with auto-training */
972 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300973 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
974 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200975
976 /* Wait for FDI receiver lane calibration */
977 udelay(30);
978
979 /* Unset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300980 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200981 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300982 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
983 POSTING_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200984
985 /* Wait for FDI auto training time */
986 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300987
988 temp = I915_READ(DP_TP_STATUS(PORT_E));
989 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200990 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200991 break;
992 }
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300993
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200994 /*
995 * Leave things enabled even if we failed to train FDI.
996 * Results in less fireworks from the state checker.
997 */
998 if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
999 DRM_ERROR("FDI link training failed!\n");
1000 break;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -03001001 }
Paulo Zanoni04945642012-11-01 21:00:59 -02001002
Ville Syrjälä5b421c52016-03-01 16:16:23 +02001003 rx_ctl_val &= ~FDI_RX_ENABLE;
1004 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
1005 POSTING_READ(FDI_RX_CTL(PIPE_A));
1006
Paulo Zanoni248138b2012-11-29 11:29:31 -02001007 temp = I915_READ(DDI_BUF_CTL(PORT_E));
1008 temp &= ~DDI_BUF_CTL_ENABLE;
1009 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
1010 POSTING_READ(DDI_BUF_CTL(PORT_E));
1011
Paulo Zanoni04945642012-11-01 21:00:59 -02001012 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -02001013 temp = I915_READ(DP_TP_CTL(PORT_E));
1014 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1015 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
1016 I915_WRITE(DP_TP_CTL(PORT_E), temp);
1017 POSTING_READ(DP_TP_CTL(PORT_E));
1018
1019 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -02001020
Paulo Zanoni04945642012-11-01 21:00:59 -02001021 /* Reset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001022 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -02001023 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1024 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001025 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
1026 POSTING_READ(FDI_RX_MISC(PIPE_A));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -03001027 }
1028
Ville Syrjäläa308ccb2015-12-04 22:22:50 +02001029 /* Enable normal pixel sending for FDI */
1030 I915_WRITE(DP_TP_CTL(PORT_E),
1031 DP_TP_CTL_FDI_AUTOTRAIN |
1032 DP_TP_CTL_LINK_TRAIN_NORMAL |
1033 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
1034 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -03001035}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -03001036
Paulo Zanonid7c530b2017-03-30 17:57:52 -03001037static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
Dave Airlie44905a272014-05-02 13:36:43 +10001038{
1039 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1040 struct intel_digital_port *intel_dig_port =
1041 enc_to_dig_port(&encoder->base);
1042
1043 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +05301044 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001045 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Dave Airlie44905a272014-05-02 13:36:43 +10001046}
1047
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001048static struct intel_encoder *
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001049intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001050{
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001051 struct drm_device *dev = crtc->base.dev;
Shashank Sharma1524e932017-03-09 19:13:41 +05301052 struct intel_encoder *encoder, *ret = NULL;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001053 int num_encoders = 0;
1054
Shashank Sharma1524e932017-03-09 19:13:41 +05301055 for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
1056 ret = encoder;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001057 num_encoders++;
1058 }
1059
1060 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001061 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001062 pipe_name(crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001063
1064 BUG_ON(ret == NULL);
1065 return ret;
1066}
1067
Paulo Zanoni44a126b2017-03-22 15:58:45 -03001068/* Finds the only possible encoder associated with the given CRTC. */
1069struct intel_encoder *
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001070intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001071{
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001072 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1073 struct intel_encoder *ret = NULL;
1074 struct drm_atomic_state *state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001075 struct drm_connector *connector;
1076 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001077 int num_encoders = 0;
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001078 int i;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001079
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001080 state = crtc_state->base.state;
1081
Maarten Lankhorstb77c7a92017-03-09 15:52:01 +01001082 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001083 if (connector_state->crtc != crtc_state->base.crtc)
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001084 continue;
1085
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001086 ret = to_intel_encoder(connector_state->best_encoder);
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001087 num_encoders++;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001088 }
1089
1090 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
1091 pipe_name(crtc->pipe));
1092
1093 BUG_ON(ret == NULL);
1094 return ret;
1095}
1096
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001097#define LC_FREQ 2700
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001098
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001099static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
1100 i915_reg_t reg)
Jesse Barnes11578552014-01-21 12:42:10 -08001101{
1102 int refclk = LC_FREQ;
1103 int n, p, r;
1104 u32 wrpll;
1105
1106 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +03001107 switch (wrpll & WRPLL_PLL_REF_MASK) {
1108 case WRPLL_PLL_SSC:
1109 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -08001110 /*
1111 * We could calculate spread here, but our checking
1112 * code only cares about 5% accuracy, and spread is a max of
1113 * 0.5% downspread.
1114 */
1115 refclk = 135;
1116 break;
Daniel Vetter114fe482014-06-25 22:01:48 +03001117 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -08001118 refclk = LC_FREQ;
1119 break;
1120 default:
1121 WARN(1, "bad wrpll refclk\n");
1122 return 0;
1123 }
1124
1125 r = wrpll & WRPLL_DIVIDER_REF_MASK;
1126 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
1127 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
1128
Jesse Barnes20f0ec12014-01-22 12:58:04 -08001129 /* Convert to KHz, p & r have a fixed point portion */
1130 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -08001131}
1132
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001133static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001134 enum intel_dpll_id pll_id)
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001135{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001136 i915_reg_t cfgcr1_reg, cfgcr2_reg;
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001137 uint32_t cfgcr1_val, cfgcr2_val;
1138 uint32_t p0, p1, p2, dco_freq;
1139
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001140 cfgcr1_reg = DPLL_CFGCR1(pll_id);
1141 cfgcr2_reg = DPLL_CFGCR2(pll_id);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001142
1143 cfgcr1_val = I915_READ(cfgcr1_reg);
1144 cfgcr2_val = I915_READ(cfgcr2_reg);
1145
1146 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
1147 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
1148
1149 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
1150 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
1151 else
1152 p1 = 1;
1153
1154
1155 switch (p0) {
1156 case DPLL_CFGCR2_PDIV_1:
1157 p0 = 1;
1158 break;
1159 case DPLL_CFGCR2_PDIV_2:
1160 p0 = 2;
1161 break;
1162 case DPLL_CFGCR2_PDIV_3:
1163 p0 = 3;
1164 break;
1165 case DPLL_CFGCR2_PDIV_7:
1166 p0 = 7;
1167 break;
1168 }
1169
1170 switch (p2) {
1171 case DPLL_CFGCR2_KDIV_5:
1172 p2 = 5;
1173 break;
1174 case DPLL_CFGCR2_KDIV_2:
1175 p2 = 2;
1176 break;
1177 case DPLL_CFGCR2_KDIV_3:
1178 p2 = 3;
1179 break;
1180 case DPLL_CFGCR2_KDIV_1:
1181 p2 = 1;
1182 break;
1183 }
1184
1185 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
1186
1187 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
1188 1000) / 0x8000;
1189
1190 return dco_freq / (p0 * p1 * p2 * 5);
1191}
1192
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001193static int cnl_calc_wrpll_link(struct drm_i915_private *dev_priv,
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001194 enum intel_dpll_id pll_id)
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001195{
1196 uint32_t cfgcr0, cfgcr1;
1197 uint32_t p0, p1, p2, dco_freq, ref_clock;
1198
1199 cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
1200 cfgcr1 = I915_READ(CNL_DPLL_CFGCR1(pll_id));
1201
1202 p0 = cfgcr1 & DPLL_CFGCR1_PDIV_MASK;
1203 p2 = cfgcr1 & DPLL_CFGCR1_KDIV_MASK;
1204
1205 if (cfgcr1 & DPLL_CFGCR1_QDIV_MODE(1))
1206 p1 = (cfgcr1 & DPLL_CFGCR1_QDIV_RATIO_MASK) >>
1207 DPLL_CFGCR1_QDIV_RATIO_SHIFT;
1208 else
1209 p1 = 1;
1210
1211
1212 switch (p0) {
1213 case DPLL_CFGCR1_PDIV_2:
1214 p0 = 2;
1215 break;
1216 case DPLL_CFGCR1_PDIV_3:
1217 p0 = 3;
1218 break;
1219 case DPLL_CFGCR1_PDIV_5:
1220 p0 = 5;
1221 break;
1222 case DPLL_CFGCR1_PDIV_7:
1223 p0 = 7;
1224 break;
1225 }
1226
1227 switch (p2) {
1228 case DPLL_CFGCR1_KDIV_1:
1229 p2 = 1;
1230 break;
1231 case DPLL_CFGCR1_KDIV_2:
1232 p2 = 2;
1233 break;
1234 case DPLL_CFGCR1_KDIV_4:
1235 p2 = 4;
1236 break;
1237 }
1238
1239 ref_clock = dev_priv->cdclk.hw.ref;
1240
1241 dco_freq = (cfgcr0 & DPLL_CFGCR0_DCO_INTEGER_MASK) * ref_clock;
1242
1243 dco_freq += (((cfgcr0 & DPLL_CFGCR0_DCO_FRACTION_MASK) >>
Manasi Navare442aa272017-09-14 11:31:39 -07001244 DPLL_CFGCR0_DCO_FRACTION_SHIFT) * ref_clock) / 0x8000;
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001245
Paulo Zanoni0e005882017-10-05 18:38:42 -03001246 if (WARN_ON(p0 == 0 || p1 == 0 || p2 == 0))
1247 return 0;
1248
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001249 return dco_freq / (p0 * p1 * p2 * 5);
1250}
1251
Ville Syrjälä398a0172015-06-30 15:33:51 +03001252static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
1253{
1254 int dotclock;
1255
1256 if (pipe_config->has_pch_encoder)
1257 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1258 &pipe_config->fdi_m_n);
Ville Syrjälä37a56502016-06-22 21:57:04 +03001259 else if (intel_crtc_has_dp_encoder(pipe_config))
Ville Syrjälä398a0172015-06-30 15:33:51 +03001260 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
1261 &pipe_config->dp_m_n);
1262 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
1263 dotclock = pipe_config->port_clock * 2 / 3;
1264 else
1265 dotclock = pipe_config->port_clock;
1266
Shashank Sharmab22ca992017-07-24 19:19:32 +05301267 if (pipe_config->ycbcr420)
1268 dotclock *= 2;
1269
Ville Syrjälä398a0172015-06-30 15:33:51 +03001270 if (pipe_config->pixel_multiplier)
1271 dotclock /= pipe_config->pixel_multiplier;
1272
1273 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
1274}
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001275
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001276static void cnl_ddi_clock_get(struct intel_encoder *encoder,
1277 struct intel_crtc_state *pipe_config)
1278{
1279 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1280 int link_clock = 0;
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001281 uint32_t cfgcr0;
1282 enum intel_dpll_id pll_id;
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001283
1284 pll_id = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
1285
1286 cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
1287
1288 if (cfgcr0 & DPLL_CFGCR0_HDMI_MODE) {
1289 link_clock = cnl_calc_wrpll_link(dev_priv, pll_id);
1290 } else {
1291 link_clock = cfgcr0 & DPLL_CFGCR0_LINK_RATE_MASK;
1292
1293 switch (link_clock) {
1294 case DPLL_CFGCR0_LINK_RATE_810:
1295 link_clock = 81000;
1296 break;
1297 case DPLL_CFGCR0_LINK_RATE_1080:
1298 link_clock = 108000;
1299 break;
1300 case DPLL_CFGCR0_LINK_RATE_1350:
1301 link_clock = 135000;
1302 break;
1303 case DPLL_CFGCR0_LINK_RATE_1620:
1304 link_clock = 162000;
1305 break;
1306 case DPLL_CFGCR0_LINK_RATE_2160:
1307 link_clock = 216000;
1308 break;
1309 case DPLL_CFGCR0_LINK_RATE_2700:
1310 link_clock = 270000;
1311 break;
1312 case DPLL_CFGCR0_LINK_RATE_3240:
1313 link_clock = 324000;
1314 break;
1315 case DPLL_CFGCR0_LINK_RATE_4050:
1316 link_clock = 405000;
1317 break;
1318 default:
1319 WARN(1, "Unsupported link rate\n");
1320 break;
1321 }
1322 link_clock *= 2;
1323 }
1324
1325 pipe_config->port_clock = link_clock;
1326
1327 ddi_dotclock_get(pipe_config);
1328}
1329
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001330static void skl_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001331 struct intel_crtc_state *pipe_config)
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001332{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001333 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001334 int link_clock = 0;
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001335 uint32_t dpll_ctl1;
1336 enum intel_dpll_id pll_id;
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001337
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001338 pll_id = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001339
1340 dpll_ctl1 = I915_READ(DPLL_CTRL1);
1341
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001342 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(pll_id)) {
1343 link_clock = skl_calc_wrpll_link(dev_priv, pll_id);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001344 } else {
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001345 link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(pll_id);
1346 link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(pll_id);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001347
1348 switch (link_clock) {
Damien Lespiau71cd8422015-04-30 16:39:17 +01001349 case DPLL_CTRL1_LINK_RATE_810:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001350 link_clock = 81000;
1351 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001352 case DPLL_CTRL1_LINK_RATE_1080:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301353 link_clock = 108000;
1354 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001355 case DPLL_CTRL1_LINK_RATE_1350:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001356 link_clock = 135000;
1357 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001358 case DPLL_CTRL1_LINK_RATE_1620:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301359 link_clock = 162000;
1360 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001361 case DPLL_CTRL1_LINK_RATE_2160:
Sonika Jindala8f3ef62015-03-05 10:02:30 +05301362 link_clock = 216000;
1363 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +01001364 case DPLL_CTRL1_LINK_RATE_2700:
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001365 link_clock = 270000;
1366 break;
1367 default:
1368 WARN(1, "Unsupported link rate\n");
1369 break;
1370 }
1371 link_clock *= 2;
1372 }
1373
1374 pipe_config->port_clock = link_clock;
1375
Ville Syrjälä398a0172015-06-30 15:33:51 +03001376 ddi_dotclock_get(pipe_config);
Satheeshakrishna M540e7322014-11-13 14:55:16 +00001377}
1378
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001379static void hsw_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001380 struct intel_crtc_state *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -08001381{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001382 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes11578552014-01-21 12:42:10 -08001383 int link_clock = 0;
1384 u32 val, pll;
1385
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001386 val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
Jesse Barnes11578552014-01-21 12:42:10 -08001387 switch (val & PORT_CLK_SEL_MASK) {
1388 case PORT_CLK_SEL_LCPLL_810:
1389 link_clock = 81000;
1390 break;
1391 case PORT_CLK_SEL_LCPLL_1350:
1392 link_clock = 135000;
1393 break;
1394 case PORT_CLK_SEL_LCPLL_2700:
1395 link_clock = 270000;
1396 break;
1397 case PORT_CLK_SEL_WRPLL1:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001398 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
Jesse Barnes11578552014-01-21 12:42:10 -08001399 break;
1400 case PORT_CLK_SEL_WRPLL2:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001401 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
Jesse Barnes11578552014-01-21 12:42:10 -08001402 break;
1403 case PORT_CLK_SEL_SPLL:
1404 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
1405 if (pll == SPLL_PLL_FREQ_810MHz)
1406 link_clock = 81000;
1407 else if (pll == SPLL_PLL_FREQ_1350MHz)
1408 link_clock = 135000;
1409 else if (pll == SPLL_PLL_FREQ_2700MHz)
1410 link_clock = 270000;
1411 else {
1412 WARN(1, "bad spll freq\n");
1413 return;
1414 }
1415 break;
1416 default:
1417 WARN(1, "bad port clock sel\n");
1418 return;
1419 }
1420
1421 pipe_config->port_clock = link_clock * 2;
1422
Ville Syrjälä398a0172015-06-30 15:33:51 +03001423 ddi_dotclock_get(pipe_config);
Jesse Barnes11578552014-01-21 12:42:10 -08001424}
1425
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301426static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001427 enum intel_dpll_id pll_id)
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301428{
Imre Deakaa610dc2015-06-22 23:35:52 +03001429 struct intel_shared_dpll *pll;
1430 struct intel_dpll_hw_state *state;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03001431 struct dpll clock;
Imre Deakaa610dc2015-06-22 23:35:52 +03001432
1433 /* For DDI ports we always use a shared PLL. */
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001434 if (WARN_ON(pll_id == DPLL_ID_PRIVATE))
Imre Deakaa610dc2015-06-22 23:35:52 +03001435 return 0;
1436
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001437 pll = &dev_priv->shared_dplls[pll_id];
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02001438 state = &pll->state.hw_state;
Imre Deakaa610dc2015-06-22 23:35:52 +03001439
1440 clock.m1 = 2;
1441 clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
1442 if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
1443 clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
1444 clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
1445 clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
1446 clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
1447
1448 return chv_calc_dpll_params(100000, &clock);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301449}
1450
1451static void bxt_ddi_clock_get(struct intel_encoder *encoder,
1452 struct intel_crtc_state *pipe_config)
1453{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001454 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03001455 enum port port = encoder->port;
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001456 enum intel_dpll_id pll_id = port;
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301457
Rodrigo Vivi2952cd62017-10-18 12:54:06 -07001458 pipe_config->port_clock = bxt_calc_pll_link(dev_priv, pll_id);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301459
Ville Syrjälä398a0172015-06-30 15:33:51 +03001460 ddi_dotclock_get(pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301461}
1462
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001463void intel_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001464 struct intel_crtc_state *pipe_config)
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001465{
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001466 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Damien Lespiau22606a12014-12-12 14:26:57 +00001467
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001468 if (INTEL_GEN(dev_priv) <= 8)
Damien Lespiau22606a12014-12-12 14:26:57 +00001469 hsw_ddi_clock_get(encoder, pipe_config);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001470 else if (IS_GEN9_BC(dev_priv))
Damien Lespiau22606a12014-12-12 14:26:57 +00001471 skl_ddi_clock_get(encoder, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001472 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301473 bxt_ddi_clock_get(encoder, pipe_config);
Rodrigo Vivia9701a82017-07-06 13:52:01 -07001474 else if (IS_CANNONLAKE(dev_priv))
1475 cnl_ddi_clock_get(encoder, pipe_config);
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001476}
1477
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001478void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
Paulo Zanonidae84792012-10-15 15:51:30 -03001479{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001480 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001481 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001482 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Ville Syrjälä5448f532017-10-19 16:37:12 +03001483 u32 temp;
Paulo Zanonidae84792012-10-15 15:51:30 -03001484
Ville Syrjälä5448f532017-10-19 16:37:12 +03001485 if (!intel_crtc_has_dp_encoder(crtc_state))
1486 return;
Jani Nikula4d1de972016-03-18 17:05:42 +02001487
Ville Syrjälä5448f532017-10-19 16:37:12 +03001488 WARN_ON(transcoder_is_dsi(cpu_transcoder));
1489
1490 temp = TRANS_MSA_SYNC_CLK;
1491 switch (crtc_state->pipe_bpp) {
1492 case 18:
1493 temp |= TRANS_MSA_6_BPC;
1494 break;
1495 case 24:
1496 temp |= TRANS_MSA_8_BPC;
1497 break;
1498 case 30:
1499 temp |= TRANS_MSA_10_BPC;
1500 break;
1501 case 36:
1502 temp |= TRANS_MSA_12_BPC;
1503 break;
1504 default:
1505 MISSING_CASE(crtc_state->pipe_bpp);
1506 break;
Paulo Zanonidae84792012-10-15 15:51:30 -03001507 }
Ville Syrjälä5448f532017-10-19 16:37:12 +03001508
1509 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -03001510}
1511
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001512void intel_ddi_set_vc_payload_alloc(const struct intel_crtc_state *crtc_state,
1513 bool state)
Dave Airlie0e32b392014-05-02 14:02:48 +10001514{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001515 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001517 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +10001518 uint32_t temp;
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03001519
Dave Airlie0e32b392014-05-02 14:02:48 +10001520 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1521 if (state == true)
1522 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1523 else
1524 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1525 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1526}
1527
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001528void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001529{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001530 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Shashank Sharma1524e932017-03-09 19:13:41 +05301531 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001532 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1533 enum pipe pipe = crtc->pipe;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001534 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03001535 enum port port = encoder->port;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001536 uint32_t temp;
1537
Paulo Zanoniad80a812012-10-24 16:06:19 -02001538 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1539 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001540 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001541
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001542 switch (crtc_state->pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001543 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001544 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001545 break;
1546 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001547 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001548 break;
1549 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001550 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001551 break;
1552 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001553 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001554 break;
1555 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001556 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001557 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001558
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001559 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001560 temp |= TRANS_DDI_PVSYNC;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001561 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001562 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -03001563
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001564 if (cpu_transcoder == TRANSCODER_EDP) {
1565 switch (pipe) {
1566 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001567 /* On Haswell, can only use the always-on power well for
1568 * eDP when not using the panel fitter, and when not
1569 * using motion blur mitigation (which we don't
1570 * support). */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01001571 if (IS_HASWELL(dev_priv) &&
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001572 (crtc_state->pch_pfit.enabled ||
1573 crtc_state->pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001574 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1575 else
1576 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001577 break;
1578 case PIPE_B:
1579 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1580 break;
1581 case PIPE_C:
1582 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1583 break;
1584 default:
1585 BUG();
1586 break;
1587 }
1588 }
1589
Ville Syrjälä742745f2017-10-19 16:37:15 +03001590 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001591 if (crtc_state->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001592 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001593 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001594 temp |= TRANS_DDI_MODE_SELECT_DVI;
Shashank Sharma15953632017-03-13 16:54:03 +05301595
1596 if (crtc_state->hdmi_scrambling)
1597 temp |= TRANS_DDI_HDMI_SCRAMBLING_MASK;
1598 if (crtc_state->hdmi_high_tmds_clock_ratio)
1599 temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
Ville Syrjälä742745f2017-10-19 16:37:15 +03001600 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001601 temp |= TRANS_DDI_MODE_SELECT_FDI;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001602 temp |= (crtc_state->fdi_lanes - 1) << 1;
Ville Syrjälä742745f2017-10-19 16:37:15 +03001603 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) {
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001604 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001605 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001606 } else {
Ville Syrjälä742745f2017-10-19 16:37:15 +03001607 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
1608 temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001609 }
1610
Paulo Zanoniad80a812012-10-24 16:06:19 -02001611 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001612}
1613
Paulo Zanoniad80a812012-10-24 16:06:19 -02001614void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1615 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001616{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001617 i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001618 uint32_t val = I915_READ(reg);
1619
Dave Airlie0e32b392014-05-02 14:02:48 +10001620 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -02001621 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001622 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001623}
1624
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001625bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1626{
1627 struct drm_device *dev = intel_connector->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001628 struct drm_i915_private *dev_priv = to_i915(dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301629 struct intel_encoder *encoder = intel_connector->encoder;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001630 int type = intel_connector->base.connector_type;
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03001631 enum port port = encoder->port;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001632 enum pipe pipe = 0;
1633 enum transcoder cpu_transcoder;
1634 uint32_t tmp;
Imre Deake27daab2016-02-12 18:55:16 +02001635 bool ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001636
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001637 if (!intel_display_power_get_if_enabled(dev_priv,
Shashank Sharma1524e932017-03-09 19:13:41 +05301638 encoder->power_domain))
Paulo Zanoni882244a2014-04-01 14:55:12 -03001639 return false;
1640
Shashank Sharma1524e932017-03-09 19:13:41 +05301641 if (!encoder->get_hw_state(encoder, &pipe)) {
Imre Deake27daab2016-02-12 18:55:16 +02001642 ret = false;
1643 goto out;
1644 }
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001645
1646 if (port == PORT_A)
1647 cpu_transcoder = TRANSCODER_EDP;
1648 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001649 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001650
1651 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1652
1653 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1654 case TRANS_DDI_MODE_SELECT_HDMI:
1655 case TRANS_DDI_MODE_SELECT_DVI:
Imre Deake27daab2016-02-12 18:55:16 +02001656 ret = type == DRM_MODE_CONNECTOR_HDMIA;
1657 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001658
1659 case TRANS_DDI_MODE_SELECT_DP_SST:
Imre Deake27daab2016-02-12 18:55:16 +02001660 ret = type == DRM_MODE_CONNECTOR_eDP ||
1661 type == DRM_MODE_CONNECTOR_DisplayPort;
1662 break;
1663
Dave Airlie0e32b392014-05-02 14:02:48 +10001664 case TRANS_DDI_MODE_SELECT_DP_MST:
1665 /* if the transcoder is in MST state then
1666 * connector isn't connected */
Imre Deake27daab2016-02-12 18:55:16 +02001667 ret = false;
1668 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001669
1670 case TRANS_DDI_MODE_SELECT_FDI:
Imre Deake27daab2016-02-12 18:55:16 +02001671 ret = type == DRM_MODE_CONNECTOR_VGA;
1672 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001673
1674 default:
Imre Deake27daab2016-02-12 18:55:16 +02001675 ret = false;
1676 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001677 }
Imre Deake27daab2016-02-12 18:55:16 +02001678
1679out:
Shashank Sharma1524e932017-03-09 19:13:41 +05301680 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deake27daab2016-02-12 18:55:16 +02001681
1682 return ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001683}
1684
Daniel Vetter85234cd2012-07-02 13:27:29 +02001685bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1686 enum pipe *pipe)
1687{
1688 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001689 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03001690 enum port port = encoder->port;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001691 u32 tmp;
1692 int i;
Imre Deake27daab2016-02-12 18:55:16 +02001693 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001694
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001695 if (!intel_display_power_get_if_enabled(dev_priv,
1696 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001697 return false;
1698
Imre Deake27daab2016-02-12 18:55:16 +02001699 ret = false;
1700
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001701 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001702
1703 if (!(tmp & DDI_BUF_CTL_ENABLE))
Imre Deake27daab2016-02-12 18:55:16 +02001704 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001705
Paulo Zanoniad80a812012-10-24 16:06:19 -02001706 if (port == PORT_A) {
1707 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001708
Paulo Zanoniad80a812012-10-24 16:06:19 -02001709 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1710 case TRANS_DDI_EDP_INPUT_A_ON:
1711 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1712 *pipe = PIPE_A;
1713 break;
1714 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1715 *pipe = PIPE_B;
1716 break;
1717 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1718 *pipe = PIPE_C;
1719 break;
1720 }
1721
Imre Deake27daab2016-02-12 18:55:16 +02001722 ret = true;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001723
Imre Deake27daab2016-02-12 18:55:16 +02001724 goto out;
1725 }
Dave Airlie0e32b392014-05-02 14:02:48 +10001726
Imre Deake27daab2016-02-12 18:55:16 +02001727 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1728 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1729
1730 if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
1731 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
1732 TRANS_DDI_MODE_SELECT_DP_MST)
1733 goto out;
1734
1735 *pipe = i;
1736 ret = true;
1737
1738 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001739 }
1740 }
1741
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001742 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001743
Imre Deake27daab2016-02-12 18:55:16 +02001744out:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001745 if (ret && IS_GEN9_LP(dev_priv)) {
Imre Deake93da0a2016-06-13 16:44:37 +03001746 tmp = I915_READ(BXT_PHY_CTL(port));
Imre Deake19c1eb2017-10-02 16:53:07 +03001747 if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK |
1748 BXT_PHY_LANE_POWERDOWN_ACK |
Imre Deake93da0a2016-06-13 16:44:37 +03001749 BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
1750 DRM_ERROR("Port %c enabled but PHY powered down? "
1751 "(PHY_CTL %08x)\n", port_name(port), tmp);
1752 }
1753
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02001754 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deake27daab2016-02-12 18:55:16 +02001755
1756 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001757}
1758
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02001759static u64 intel_ddi_get_power_domains(struct intel_encoder *encoder)
1760{
1761 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
1762 enum pipe pipe;
1763
1764 if (intel_ddi_get_hw_state(encoder, &pipe))
1765 return BIT_ULL(dig_port->ddi_io_power_domain);
1766
1767 return 0;
1768}
1769
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001770void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state)
Paulo Zanonifc914632012-10-05 12:05:54 -03001771{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001772 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveirae9ce1a62017-03-02 14:58:55 +02001773 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Shashank Sharma1524e932017-03-09 19:13:41 +05301774 struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03001775 enum port port = encoder->port;
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001776 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001777
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001778 if (cpu_transcoder != TRANSCODER_EDP)
1779 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1780 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001781}
1782
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001783void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
Paulo Zanonifc914632012-10-05 12:05:54 -03001784{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02001785 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1786 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001787
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001788 if (cpu_transcoder != TRANSCODER_EDP)
1789 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1790 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001791}
1792
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001793static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1794 enum port port, uint8_t iboost)
David Weinehallf8896f52015-06-25 11:11:03 +03001795{
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001796 u32 tmp;
1797
1798 tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
1799 tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
1800 if (iboost)
1801 tmp |= iboost << BALANCE_LEG_SHIFT(port);
1802 else
1803 tmp |= BALANCE_LEG_DISABLE(port);
1804 I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
1805}
1806
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001807static void skl_ddi_set_iboost(struct intel_encoder *encoder,
1808 int level, enum intel_output_type type)
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001809{
1810 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
1811 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
1812 enum port port = intel_dig_port->port;
David Weinehallf8896f52015-06-25 11:11:03 +03001813 uint8_t iboost;
David Weinehallf8896f52015-06-25 11:11:03 +03001814
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001815 if (type == INTEL_OUTPUT_HDMI)
1816 iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
1817 else
1818 iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001819
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001820 if (iboost == 0) {
1821 const struct ddi_buf_trans *ddi_translations;
1822 int n_entries;
Ville Syrjälä10afa0b2015-12-08 19:59:43 +02001823
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001824 if (type == INTEL_OUTPUT_HDMI)
Ville Syrjälä975786e2017-10-16 17:56:57 +03001825 ddi_translations = intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries);
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001826 else if (type == INTEL_OUTPUT_EDP)
Ville Syrjäläedba48f2017-10-16 17:57:03 +03001827 ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv, port, &n_entries);
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001828 else
Ville Syrjäläedba48f2017-10-16 17:57:03 +03001829 ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv, port, &n_entries);
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001830
Ville Syrjälä21b39d22017-10-18 21:19:34 +03001831 if (WARN_ON_ONCE(!ddi_translations))
1832 return;
1833 if (WARN_ON_ONCE(level >= n_entries))
1834 level = n_entries - 1;
1835
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03001836 iboost = ddi_translations[level].i_boost;
David Weinehallf8896f52015-06-25 11:11:03 +03001837 }
1838
1839 /* Make sure that the requested I_boost is valid */
1840 if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
1841 DRM_ERROR("Invalid I_boost value %u\n", iboost);
1842 return;
1843 }
1844
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001845 _skl_ddi_set_iboost(dev_priv, port, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001846
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001847 if (port == PORT_A && intel_dig_port->max_lanes == 4)
1848 _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001849}
1850
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03001851static void bxt_ddi_vswing_sequence(struct intel_encoder *encoder,
1852 int level, enum intel_output_type type)
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301853{
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03001854 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301855 const struct bxt_ddi_buf_trans *ddi_translations;
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03001856 enum port port = encoder->port;
Ville Syrjälä043eaf32017-10-16 17:57:02 +03001857 int n_entries;
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301858
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03001859 if (type == INTEL_OUTPUT_HDMI)
1860 ddi_translations = bxt_get_buf_trans_hdmi(dev_priv, &n_entries);
1861 else if (type == INTEL_OUTPUT_EDP)
1862 ddi_translations = bxt_get_buf_trans_edp(dev_priv, &n_entries);
1863 else
1864 ddi_translations = bxt_get_buf_trans_dp(dev_priv, &n_entries);
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301865
Ville Syrjälä21b39d22017-10-18 21:19:34 +03001866 if (WARN_ON_ONCE(!ddi_translations))
1867 return;
1868 if (WARN_ON_ONCE(level >= n_entries))
1869 level = n_entries - 1;
1870
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +03001871 bxt_ddi_phy_set_signal_level(dev_priv, port,
1872 ddi_translations[level].margin,
1873 ddi_translations[level].scale,
1874 ddi_translations[level].enable,
1875 ddi_translations[level].deemphasis);
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301876}
1877
Ville Syrjäläffe51112017-02-23 19:49:01 +02001878u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder)
1879{
1880 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjäläedba48f2017-10-16 17:57:03 +03001881 enum port port = encoder->port;
Ville Syrjäläffe51112017-02-23 19:49:01 +02001882 int n_entries;
1883
Rodrigo Vivi5fcf34b2017-08-31 07:53:56 -07001884 if (IS_CANNONLAKE(dev_priv)) {
1885 if (encoder->type == INTEL_OUTPUT_EDP)
1886 cnl_get_buf_trans_edp(dev_priv, &n_entries);
1887 else
1888 cnl_get_buf_trans_dp(dev_priv, &n_entries);
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03001889 } else if (IS_GEN9_LP(dev_priv)) {
1890 if (encoder->type == INTEL_OUTPUT_EDP)
1891 bxt_get_buf_trans_edp(dev_priv, &n_entries);
1892 else
1893 bxt_get_buf_trans_dp(dev_priv, &n_entries);
Rodrigo Vivi5fcf34b2017-08-31 07:53:56 -07001894 } else {
1895 if (encoder->type == INTEL_OUTPUT_EDP)
Ville Syrjäläedba48f2017-10-16 17:57:03 +03001896 intel_ddi_get_buf_trans_edp(dev_priv, port, &n_entries);
Rodrigo Vivi5fcf34b2017-08-31 07:53:56 -07001897 else
Ville Syrjäläedba48f2017-10-16 17:57:03 +03001898 intel_ddi_get_buf_trans_dp(dev_priv, port, &n_entries);
Rodrigo Vivi5fcf34b2017-08-31 07:53:56 -07001899 }
Ville Syrjäläffe51112017-02-23 19:49:01 +02001900
1901 if (WARN_ON(n_entries < 1))
1902 n_entries = 1;
1903 if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
1904 n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
1905
1906 return index_to_dp_signal_levels[n_entries - 1] &
1907 DP_TRAIN_VOLTAGE_SWING_MASK;
1908}
1909
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001910static void cnl_ddi_vswing_program(struct intel_encoder *encoder,
1911 int level, enum intel_output_type type)
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001912{
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001913 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001914 const struct cnl_ddi_buf_trans *ddi_translations;
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03001915 enum port port = encoder->port;
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001916 int n_entries, ln;
1917 u32 val;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001918
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001919 if (type == INTEL_OUTPUT_HDMI)
Rodrigo Vivicc9cabf2017-08-29 16:22:27 -07001920 ddi_translations = cnl_get_buf_trans_hdmi(dev_priv, &n_entries);
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001921 else if (type == INTEL_OUTPUT_EDP)
Rodrigo Vivicc9cabf2017-08-29 16:22:27 -07001922 ddi_translations = cnl_get_buf_trans_edp(dev_priv, &n_entries);
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001923 else
1924 ddi_translations = cnl_get_buf_trans_dp(dev_priv, &n_entries);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001925
Ville Syrjälä21b39d22017-10-18 21:19:34 +03001926 if (WARN_ON_ONCE(!ddi_translations))
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001927 return;
Ville Syrjälä21b39d22017-10-18 21:19:34 +03001928 if (WARN_ON_ONCE(level >= n_entries))
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001929 level = n_entries - 1;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001930
1931 /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */
1932 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001933 val &= ~SCALING_MODE_SEL_MASK;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001934 val |= SCALING_MODE_SEL(2);
1935 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
1936
1937 /* Program PORT_TX_DW2 */
1938 val = I915_READ(CNL_PORT_TX_DW2_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001939 val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
1940 RCOMP_SCALAR_MASK);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001941 val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
1942 val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
1943 /* Rcomp scalar is fixed as 0x98 for every table entry */
1944 val |= RCOMP_SCALAR(0x98);
1945 I915_WRITE(CNL_PORT_TX_DW2_GRP(port), val);
1946
Ville Syrjälä20303eb2017-09-18 21:25:36 +03001947 /* Program PORT_TX_DW4 */
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001948 /* We cannot write to GRP. It would overrite individual loadgen */
1949 for (ln = 0; ln < 4; ln++) {
1950 val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001951 val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
1952 CURSOR_COEFF_MASK);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001953 val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
1954 val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
1955 val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
1956 I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
1957 }
1958
Ville Syrjälä20303eb2017-09-18 21:25:36 +03001959 /* Program PORT_TX_DW5 */
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001960 /* All DW5 values are fixed for every table entry */
1961 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001962 val &= ~RTERM_SELECT_MASK;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001963 val |= RTERM_SELECT(6);
1964 val |= TAP3_DISABLE;
1965 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
1966
Ville Syrjälä20303eb2017-09-18 21:25:36 +03001967 /* Program PORT_TX_DW7 */
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001968 val = I915_READ(CNL_PORT_TX_DW7_LN0(port));
Rodrigo Vivi1f588ae2017-06-19 11:39:32 -07001969 val &= ~N_SCALAR_MASK;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001970 val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
1971 I915_WRITE(CNL_PORT_TX_DW7_GRP(port), val);
1972}
1973
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001974static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder,
1975 int level, enum intel_output_type type)
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001976{
Clint Taylor0091abc2017-06-09 15:26:09 -07001977 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03001978 enum port port = encoder->port;
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001979 int width, rate, ln;
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001980 u32 val;
Clint Taylor0091abc2017-06-09 15:26:09 -07001981
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001982 if (type == INTEL_OUTPUT_HDMI) {
1983 width = 4;
1984 rate = 0; /* Rate is always < than 6GHz for HDMI */
1985 } else {
1986 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1987
Clint Taylor0091abc2017-06-09 15:26:09 -07001988 width = intel_dp->lane_count;
1989 rate = intel_dp->link_rate;
Clint Taylor0091abc2017-06-09 15:26:09 -07001990 }
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001991
1992 /*
1993 * 1. If port type is eDP or DP,
1994 * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
1995 * else clear to 0b.
1996 */
1997 val = I915_READ(CNL_PORT_PCS_DW1_LN0(port));
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03001998 if (type != INTEL_OUTPUT_HDMI)
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07001999 val |= COMMON_KEEPER_EN;
2000 else
2001 val &= ~COMMON_KEEPER_EN;
2002 I915_WRITE(CNL_PORT_PCS_DW1_GRP(port), val);
2003
2004 /* 2. Program loadgen select */
2005 /*
Clint Taylor0091abc2017-06-09 15:26:09 -07002006 * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
2007 * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
2008 * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
2009 * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07002010 */
Clint Taylor0091abc2017-06-09 15:26:09 -07002011 for (ln = 0; ln <= 3; ln++) {
2012 val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
2013 val &= ~LOADGEN_SELECT;
2014
Navare, Manasi Da8e45a12017-07-17 15:05:22 -07002015 if ((rate <= 600000 && width == 4 && ln >= 1) ||
2016 (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
Clint Taylor0091abc2017-06-09 15:26:09 -07002017 val |= LOADGEN_SELECT;
2018 }
2019 I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
2020 }
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07002021
2022 /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
2023 val = I915_READ(CNL_PORT_CL1CM_DW5);
2024 val |= SUS_CLOCK_CONFIG;
2025 I915_WRITE(CNL_PORT_CL1CM_DW5, val);
2026
2027 /* 4. Clear training enable to change swing values */
2028 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
2029 val &= ~TX_TRAINING_EN;
2030 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
2031
2032 /* 5. Program swing and de-emphasis */
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03002033 cnl_ddi_vswing_program(encoder, level, type);
Rodrigo Vivicf54ca82017-06-09 15:26:08 -07002034
2035 /* 6. Set training enable to trigger update */
2036 val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
2037 val |= TX_TRAINING_EN;
2038 I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
2039}
2040
David Weinehallf8896f52015-06-25 11:11:03 +03002041static uint32_t translate_signal_level(int signal_levels)
2042{
Ville Syrjälä97eeb872017-02-23 19:35:06 +02002043 int i;
David Weinehallf8896f52015-06-25 11:11:03 +03002044
Ville Syrjälä97eeb872017-02-23 19:35:06 +02002045 for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
2046 if (index_to_dp_signal_levels[i] == signal_levels)
2047 return i;
David Weinehallf8896f52015-06-25 11:11:03 +03002048 }
2049
Ville Syrjälä97eeb872017-02-23 19:35:06 +02002050 WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
2051 signal_levels);
2052
2053 return 0;
David Weinehallf8896f52015-06-25 11:11:03 +03002054}
2055
Rodrigo Vivi1b6e2fd2017-08-29 16:22:23 -07002056static uint32_t intel_ddi_dp_level(struct intel_dp *intel_dp)
2057{
2058 uint8_t train_set = intel_dp->train_set[0];
2059 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
2060 DP_TRAIN_PRE_EMPHASIS_MASK);
2061
2062 return translate_signal_level(signal_levels);
2063}
2064
Rodrigo Vivid509af62017-08-29 16:22:24 -07002065u32 bxt_signal_levels(struct intel_dp *intel_dp)
David Weinehallf8896f52015-06-25 11:11:03 +03002066{
2067 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02002068 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
David Weinehallf8896f52015-06-25 11:11:03 +03002069 struct intel_encoder *encoder = &dport->base;
Ville Syrjäläd02ace82017-10-18 21:19:58 +03002070 int level = intel_ddi_dp_level(intel_dp);
Rodrigo Vivid509af62017-08-29 16:22:24 -07002071
2072 if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03002073 cnl_ddi_vswing_sequence(encoder, level, encoder->type);
Rodrigo Vivid509af62017-08-29 16:22:24 -07002074 else
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03002075 bxt_ddi_vswing_sequence(encoder, level, encoder->type);
Rodrigo Vivid509af62017-08-29 16:22:24 -07002076
2077 return 0;
2078}
2079
2080uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
2081{
2082 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
2083 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
2084 struct intel_encoder *encoder = &dport->base;
Ville Syrjäläd02ace82017-10-18 21:19:58 +03002085 int level = intel_ddi_dp_level(intel_dp);
David Weinehallf8896f52015-06-25 11:11:03 +03002086
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002087 if (IS_GEN9_BC(dev_priv))
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03002088 skl_ddi_set_iboost(encoder, level, encoder->type);
Rodrigo Vivid509af62017-08-29 16:22:24 -07002089
David Weinehallf8896f52015-06-25 11:11:03 +03002090 return DDI_BUF_TRANS_SELECT(level);
2091}
2092
Paulo Zanonid7c530b2017-03-30 17:57:52 -03002093static void intel_ddi_clk_select(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002094 const struct intel_shared_dpll *pll)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002095{
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002096 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002097 enum port port = encoder->port;
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002098 uint32_t val;
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02002099
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07002100 if (WARN_ON(!pll))
2101 return;
2102
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002103 if (IS_CANNONLAKE(dev_priv)) {
2104 /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */
2105 val = I915_READ(DPCLKA_CFGCR0);
2106 val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->id, port);
2107 I915_WRITE(DPCLKA_CFGCR0, val);
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002108
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002109 /*
2110 * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI.
2111 * This step and the step before must be done with separate
2112 * register writes.
2113 */
2114 val = I915_READ(DPCLKA_CFGCR0);
Rodrigo Vivi87145d92017-10-03 15:08:58 -07002115 val &= ~DPCLKA_CFGCR0_DDI_CLK_OFF(port);
Rodrigo Vivi555e38d2017-06-09 15:26:02 -07002116 I915_WRITE(DPCLKA_CFGCR0, val);
2117 } else if (IS_GEN9_BC(dev_priv)) {
Damien Lespiau5416d872014-11-14 17:24:33 +00002118 /* DDI -> PLL mapping */
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002119 val = I915_READ(DPLL_CTRL2);
2120
2121 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
2122 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07002123 val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002124 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
2125
2126 I915_WRITE(DPLL_CTRL2, val);
Damien Lespiau5416d872014-11-14 17:24:33 +00002127
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002128 } else if (INTEL_INFO(dev_priv)->gen < 9) {
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07002129 I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00002130 }
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002131}
2132
Ville Syrjälä6b8506d2017-10-10 15:12:00 +03002133static void intel_ddi_clk_disable(struct intel_encoder *encoder)
2134{
2135 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002136 enum port port = encoder->port;
Ville Syrjälä6b8506d2017-10-10 15:12:00 +03002137
2138 if (IS_CANNONLAKE(dev_priv))
2139 I915_WRITE(DPCLKA_CFGCR0, I915_READ(DPCLKA_CFGCR0) |
2140 DPCLKA_CFGCR0_DDI_CLK_OFF(port));
2141 else if (IS_GEN9_BC(dev_priv))
2142 I915_WRITE(DPLL_CTRL2, I915_READ(DPLL_CTRL2) |
2143 DPLL_CTRL2_DDI_CLK_OFF(port));
2144 else if (INTEL_GEN(dev_priv) < 9)
2145 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
2146}
2147
Manasi Navareba88d152016-09-01 15:08:08 -07002148static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
Ville Syrjälä45e03272017-10-10 15:12:06 +03002149 const struct intel_crtc_state *crtc_state,
2150 const struct drm_connector_state *conn_state)
Manasi Navareba88d152016-09-01 15:08:08 -07002151{
2152 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2153 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002154 enum port port = encoder->port;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002155 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
Ville Syrjälä45e03272017-10-10 15:12:06 +03002156 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST);
Ville Syrjäläd02ace82017-10-18 21:19:58 +03002157 int level = intel_ddi_dp_level(intel_dp);
Manasi Navareba88d152016-09-01 15:08:08 -07002158
Ville Syrjälä45e03272017-10-10 15:12:06 +03002159 WARN_ON(is_mst && (port == PORT_A || port == PORT_E));
Ander Conselvan de Oliveirae081c842017-03-02 14:58:57 +02002160
Ville Syrjälä45e03272017-10-10 15:12:06 +03002161 intel_dp_set_link_params(intel_dp, crtc_state->port_clock,
2162 crtc_state->lane_count, is_mst);
Ville Syrjälä680b71c2017-10-10 15:12:04 +03002163
2164 intel_edp_panel_on(intel_dp);
Manasi Navareba88d152016-09-01 15:08:08 -07002165
Ville Syrjälä45e03272017-10-10 15:12:06 +03002166 intel_ddi_clk_select(encoder, crtc_state->shared_dpll);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002167
2168 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
2169
Rodrigo Vivi381f9572017-08-29 16:22:26 -07002170 if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03002171 cnl_ddi_vswing_sequence(encoder, level, encoder->type);
Rodrigo Vivi381f9572017-08-29 16:22:26 -07002172 else if (IS_GEN9_LP(dev_priv))
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03002173 bxt_ddi_vswing_sequence(encoder, level, encoder->type);
Rodrigo Vivi381f9572017-08-29 16:22:26 -07002174 else
Ville Syrjälä3a6d84e2017-10-19 16:37:13 +03002175 intel_prepare_dp_ddi_buffers(encoder, crtc_state);
Rodrigo Vivi2f7460a2017-08-29 16:22:25 -07002176
Manasi Navareba88d152016-09-01 15:08:08 -07002177 intel_ddi_init_dp_buf_reg(encoder);
Ville Syrjälä45e03272017-10-10 15:12:06 +03002178 if (!is_mst)
Dhinakaran Pandiyan5ea23552017-10-03 17:22:11 +03002179 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
Manasi Navareba88d152016-09-01 15:08:08 -07002180 intel_dp_start_link_train(intel_dp);
2181 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
2182 intel_dp_stop_link_train(intel_dp);
2183}
2184
2185static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +01002186 const struct intel_crtc_state *crtc_state,
Ville Syrjälä45e03272017-10-10 15:12:06 +03002187 const struct drm_connector_state *conn_state)
Manasi Navareba88d152016-09-01 15:08:08 -07002188{
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002189 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
2190 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Manasi Navareba88d152016-09-01 15:08:08 -07002191 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002192 enum port port = encoder->port;
Manasi Navareba88d152016-09-01 15:08:08 -07002193 int level = intel_ddi_hdmi_level(dev_priv, port);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002194 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
Manasi Navareba88d152016-09-01 15:08:08 -07002195
2196 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
Ville Syrjälä45e03272017-10-10 15:12:06 +03002197 intel_ddi_clk_select(encoder, crtc_state->shared_dpll);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002198
2199 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
2200
Rodrigo Vivi2f7460a2017-08-29 16:22:25 -07002201 if (IS_CANNONLAKE(dev_priv))
Ville Syrjäläf3cf4ba2017-10-16 17:57:01 +03002202 cnl_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002203 else if (IS_GEN9_LP(dev_priv))
Ville Syrjälä7d4f37b2017-10-16 17:57:00 +03002204 bxt_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI);
Rodrigo Vivi2f7460a2017-08-29 16:22:25 -07002205 else
Ville Syrjälä7ea79332017-10-16 17:56:59 +03002206 intel_prepare_hdmi_ddi_buffers(encoder, level);
Rodrigo Vivi2f7460a2017-08-29 16:22:25 -07002207
2208 if (IS_GEN9_BC(dev_priv))
Ville Syrjälä081dfcf2017-10-16 17:56:58 +03002209 skl_ddi_set_iboost(encoder, level, INTEL_OUTPUT_HDMI);
Manasi Navareba88d152016-09-01 15:08:08 -07002210
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002211 intel_dig_port->set_infoframes(&encoder->base,
Ville Syrjälä45e03272017-10-10 15:12:06 +03002212 crtc_state->has_infoframe,
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002213 crtc_state, conn_state);
Manasi Navareba88d152016-09-01 15:08:08 -07002214}
2215
Shashank Sharma1524e932017-03-09 19:13:41 +05302216static void intel_ddi_pre_enable(struct intel_encoder *encoder,
Ville Syrjälä45e03272017-10-10 15:12:06 +03002217 const struct intel_crtc_state *crtc_state,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002218 const struct drm_connector_state *conn_state)
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03002219{
Ville Syrjälä45e03272017-10-10 15:12:06 +03002220 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
2221 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2222 enum pipe pipe = crtc->pipe;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +02002223
Ville Syrjälä45e03272017-10-10 15:12:06 +03002224 WARN_ON(crtc_state->has_pch_encoder);
Jani Nikula364a3fe2017-10-05 13:52:12 +03002225
2226 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2227
Ville Syrjälä45e03272017-10-10 15:12:06 +03002228 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2229 intel_ddi_pre_enable_hdmi(encoder, crtc_state, conn_state);
2230 else
2231 intel_ddi_pre_enable_dp(encoder, crtc_state, conn_state);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002232}
2233
Ville Syrjäläe725f642017-10-10 15:12:01 +03002234static void intel_disable_ddi_buf(struct intel_encoder *encoder)
2235{
2236 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002237 enum port port = encoder->port;
Ville Syrjäläe725f642017-10-10 15:12:01 +03002238 bool wait = false;
2239 u32 val;
2240
2241 val = I915_READ(DDI_BUF_CTL(port));
2242 if (val & DDI_BUF_CTL_ENABLE) {
2243 val &= ~DDI_BUF_CTL_ENABLE;
2244 I915_WRITE(DDI_BUF_CTL(port), val);
2245 wait = true;
2246 }
2247
2248 val = I915_READ(DP_TP_CTL(port));
2249 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2250 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2251 I915_WRITE(DP_TP_CTL(port), val);
2252
2253 if (wait)
2254 intel_wait_ddi_buf_idle(dev_priv, port);
2255}
2256
Ville Syrjäläf45f3da2017-10-10 15:12:03 +03002257static void intel_ddi_post_disable_dp(struct intel_encoder *encoder,
2258 const struct intel_crtc_state *old_crtc_state,
2259 const struct drm_connector_state *old_conn_state)
2260{
2261 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2262 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
2263 struct intel_dp *intel_dp = &dig_port->dp;
2264 /*
2265 * old_crtc_state and old_conn_state are NULL when called from
2266 * DP_MST. The main connector associated with this port is never
2267 * bound to a crtc for MST.
2268 */
2269 bool is_mst = !old_crtc_state;
2270
2271 /*
2272 * Power down sink before disabling the port, otherwise we end
2273 * up getting interrupts from the sink on detecting link loss.
2274 */
2275 if (!is_mst)
2276 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2277
2278 intel_disable_ddi_buf(encoder);
2279
2280 intel_edp_panel_vdd_on(intel_dp);
2281 intel_edp_panel_off(intel_dp);
2282
2283 intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
2284
2285 intel_ddi_clk_disable(encoder);
2286}
2287
2288static void intel_ddi_post_disable_hdmi(struct intel_encoder *encoder,
2289 const struct intel_crtc_state *old_crtc_state,
2290 const struct drm_connector_state *old_conn_state)
2291{
2292 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2293 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
2294 struct intel_hdmi *intel_hdmi = &dig_port->hdmi;
2295
2296 intel_disable_ddi_buf(encoder);
2297
2298 dig_port->set_infoframes(&encoder->base, false,
2299 old_crtc_state, old_conn_state);
2300
2301 intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
2302
2303 intel_ddi_clk_disable(encoder);
2304
2305 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
2306}
2307
2308static void intel_ddi_post_disable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002309 const struct intel_crtc_state *old_crtc_state,
2310 const struct drm_connector_state *old_conn_state)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002311{
Ville Syrjäläf45f3da2017-10-10 15:12:03 +03002312 /*
2313 * old_crtc_state and old_conn_state are NULL when called from
2314 * DP_MST. The main connector associated with this port is never
2315 * bound to a crtc for MST.
2316 */
2317 if (old_crtc_state &&
2318 intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
2319 intel_ddi_post_disable_hdmi(encoder,
2320 old_crtc_state, old_conn_state);
2321 else
2322 intel_ddi_post_disable_dp(encoder,
2323 old_crtc_state, old_conn_state);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03002324}
2325
Shashank Sharma1524e932017-03-09 19:13:41 +05302326void intel_ddi_fdi_post_disable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002327 const struct intel_crtc_state *old_crtc_state,
2328 const struct drm_connector_state *old_conn_state)
Maarten Lankhorstb7076542016-08-23 16:18:08 +02002329{
Shashank Sharma1524e932017-03-09 19:13:41 +05302330 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Maarten Lankhorstb7076542016-08-23 16:18:08 +02002331 uint32_t val;
2332
2333 /*
2334 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
2335 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
2336 * step 13 is the correct place for it. Step 18 is where it was
2337 * originally before the BUN.
2338 */
2339 val = I915_READ(FDI_RX_CTL(PIPE_A));
2340 val &= ~FDI_RX_ENABLE;
2341 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2342
Ville Syrjäläfb0bd3b2017-10-10 15:12:02 +03002343 intel_disable_ddi_buf(encoder);
2344 intel_ddi_clk_disable(encoder);
Maarten Lankhorstb7076542016-08-23 16:18:08 +02002345
2346 val = I915_READ(FDI_RX_MISC(PIPE_A));
2347 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
2348 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
2349 I915_WRITE(FDI_RX_MISC(PIPE_A), val);
2350
2351 val = I915_READ(FDI_RX_CTL(PIPE_A));
2352 val &= ~FDI_PCDCLK;
2353 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2354
2355 val = I915_READ(FDI_RX_CTL(PIPE_A));
2356 val &= ~FDI_RX_PLL_ENABLE;
2357 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
2358}
2359
Ville Syrjälä15d05f02017-10-10 15:12:07 +03002360static void intel_enable_ddi_dp(struct intel_encoder *encoder,
2361 const struct intel_crtc_state *crtc_state,
2362 const struct drm_connector_state *conn_state)
2363{
2364 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2365 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002366 enum port port = encoder->port;
Ville Syrjälä15d05f02017-10-10 15:12:07 +03002367
2368 if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
2369 intel_dp_stop_link_train(intel_dp);
2370
2371 intel_edp_backlight_on(crtc_state, conn_state);
2372 intel_psr_enable(intel_dp, crtc_state);
2373 intel_edp_drrs_enable(intel_dp, crtc_state);
2374
2375 if (crtc_state->has_audio)
2376 intel_audio_codec_enable(encoder, crtc_state, conn_state);
2377}
2378
2379static void intel_enable_ddi_hdmi(struct intel_encoder *encoder,
2380 const struct intel_crtc_state *crtc_state,
2381 const struct drm_connector_state *conn_state)
2382{
2383 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2384 struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002385 enum port port = encoder->port;
Ville Syrjälä15d05f02017-10-10 15:12:07 +03002386
2387 intel_hdmi_handle_sink_scrambling(encoder,
2388 conn_state->connector,
2389 crtc_state->hdmi_high_tmds_clock_ratio,
2390 crtc_state->hdmi_scrambling);
2391
2392 /* In HDMI/DVI mode, the port width, and swing/emphasis values
2393 * are ignored so nothing special needs to be done besides
2394 * enabling the port.
2395 */
2396 I915_WRITE(DDI_BUF_CTL(port),
2397 dig_port->saved_port_bits | DDI_BUF_CTL_ENABLE);
2398
2399 if (crtc_state->has_audio)
2400 intel_audio_codec_enable(encoder, crtc_state, conn_state);
2401}
2402
2403static void intel_enable_ddi(struct intel_encoder *encoder,
2404 const struct intel_crtc_state *crtc_state,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002405 const struct drm_connector_state *conn_state)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002406{
Ville Syrjälä15d05f02017-10-10 15:12:07 +03002407 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
2408 intel_enable_ddi_hdmi(encoder, crtc_state, conn_state);
2409 else
2410 intel_enable_ddi_dp(encoder, crtc_state, conn_state);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002411}
2412
Ville Syrjälä33f083f2017-10-10 15:12:05 +03002413static void intel_disable_ddi_dp(struct intel_encoder *encoder,
2414 const struct intel_crtc_state *old_crtc_state,
2415 const struct drm_connector_state *old_conn_state)
2416{
2417 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2418
2419 if (old_crtc_state->has_audio)
2420 intel_audio_codec_disable(encoder);
2421
2422 intel_edp_drrs_disable(intel_dp, old_crtc_state);
2423 intel_psr_disable(intel_dp, old_crtc_state);
2424 intel_edp_backlight_off(old_conn_state);
2425}
2426
2427static void intel_disable_ddi_hdmi(struct intel_encoder *encoder,
2428 const struct intel_crtc_state *old_crtc_state,
2429 const struct drm_connector_state *old_conn_state)
2430{
2431 if (old_crtc_state->has_audio)
2432 intel_audio_codec_disable(encoder);
2433
2434 intel_hdmi_handle_sink_scrambling(encoder,
2435 old_conn_state->connector,
2436 false, false);
2437}
2438
2439static void intel_disable_ddi(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002440 const struct intel_crtc_state *old_crtc_state,
2441 const struct drm_connector_state *old_conn_state)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002442{
Ville Syrjälä33f083f2017-10-10 15:12:05 +03002443 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI))
2444 intel_disable_ddi_hdmi(encoder, old_crtc_state, old_conn_state);
2445 else
2446 intel_disable_ddi_dp(encoder, old_crtc_state, old_conn_state);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002447}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002448
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02002449static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
Ville Syrjälä5f88a9c2017-08-18 16:49:58 +03002450 const struct intel_crtc_state *pipe_config,
2451 const struct drm_connector_state *conn_state)
Imre Deak95a7a2a2016-06-13 16:44:35 +03002452{
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02002453 uint8_t mask = pipe_config->lane_lat_optim_mask;
Imre Deak95a7a2a2016-06-13 16:44:35 +03002454
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +03002455 bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002456}
2457
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03002458void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
Paulo Zanonic19b0662012-10-15 15:51:41 -03002459{
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03002460 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2461 struct drm_i915_private *dev_priv =
2462 to_i915(intel_dig_port->base.base.dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02002463 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002464 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05302465 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002466
2467 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
2468 val = I915_READ(DDI_BUF_CTL(port));
2469 if (val & DDI_BUF_CTL_ENABLE) {
2470 val &= ~DDI_BUF_CTL_ENABLE;
2471 I915_WRITE(DDI_BUF_CTL(port), val);
2472 wait = true;
2473 }
2474
2475 val = I915_READ(DP_TP_CTL(port));
2476 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2477 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2478 I915_WRITE(DP_TP_CTL(port), val);
2479 POSTING_READ(DP_TP_CTL(port));
2480
2481 if (wait)
2482 intel_wait_ddi_buf_idle(dev_priv, port);
2483 }
2484
Dave Airlie0e32b392014-05-02 14:02:48 +10002485 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03002486 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03002487 if (intel_dp->link_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10002488 val |= DP_TP_CTL_MODE_MST;
2489 else {
2490 val |= DP_TP_CTL_MODE_SST;
2491 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2492 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
2493 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03002494 I915_WRITE(DP_TP_CTL(port), val);
2495 POSTING_READ(DP_TP_CTL(port));
2496
2497 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
2498 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
2499 POSTING_READ(DDI_BUF_CTL(port));
2500
2501 udelay(600);
2502}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002503
Libin Yang9935f7f2016-11-28 20:07:06 +08002504bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
2505 struct intel_crtc *intel_crtc)
2506{
2507 u32 temp;
2508
2509 if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
2510 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
2511 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
2512 return true;
2513 }
2514 return false;
2515}
2516
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03002517void intel_ddi_compute_min_voltage_level(struct drm_i915_private *dev_priv,
2518 struct intel_crtc_state *crtc_state)
2519{
2520 if (IS_CANNONLAKE(dev_priv) && crtc_state->port_clock > 594000)
2521 crtc_state->min_voltage_level = 2;
2522}
2523
Ville Syrjälä6801c182013-09-24 14:24:05 +03002524void intel_ddi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002525 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002526{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002527 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002528 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +02002529 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002530 struct intel_digital_port *intel_dig_port;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002531 u32 temp, flags = 0;
2532
Jani Nikula4d1de972016-03-18 17:05:42 +02002533 /* XXX: DSI transcoder paranoia */
2534 if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
2535 return;
2536
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002537 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
2538 if (temp & TRANS_DDI_PHSYNC)
2539 flags |= DRM_MODE_FLAG_PHSYNC;
2540 else
2541 flags |= DRM_MODE_FLAG_NHSYNC;
2542 if (temp & TRANS_DDI_PVSYNC)
2543 flags |= DRM_MODE_FLAG_PVSYNC;
2544 else
2545 flags |= DRM_MODE_FLAG_NVSYNC;
2546
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002547 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03002548
2549 switch (temp & TRANS_DDI_BPC_MASK) {
2550 case TRANS_DDI_BPC_6:
2551 pipe_config->pipe_bpp = 18;
2552 break;
2553 case TRANS_DDI_BPC_8:
2554 pipe_config->pipe_bpp = 24;
2555 break;
2556 case TRANS_DDI_BPC_10:
2557 pipe_config->pipe_bpp = 30;
2558 break;
2559 case TRANS_DDI_BPC_12:
2560 pipe_config->pipe_bpp = 36;
2561 break;
2562 default:
2563 break;
2564 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002565
2566 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
2567 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02002568 pipe_config->has_hdmi_sink = true;
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002569 intel_dig_port = enc_to_dig_port(&encoder->base);
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002570
Ville Syrjäläf99be1b2017-08-18 16:49:54 +03002571 if (intel_dig_port->infoframe_enabled(&encoder->base, pipe_config))
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002572 pipe_config->has_infoframe = true;
Shashank Sharma15953632017-03-13 16:54:03 +05302573
2574 if ((temp & TRANS_DDI_HDMI_SCRAMBLING_MASK) ==
2575 TRANS_DDI_HDMI_SCRAMBLING_MASK)
2576 pipe_config->hdmi_scrambling = true;
2577 if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
2578 pipe_config->hdmi_high_tmds_clock_ratio = true;
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002579 /* fall through */
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002580 case TRANS_DDI_MODE_SELECT_DVI:
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002581 pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI);
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002582 pipe_config->lane_count = 4;
2583 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002584 case TRANS_DDI_MODE_SELECT_FDI:
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002585 pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002586 break;
2587 case TRANS_DDI_MODE_SELECT_DP_SST:
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002588 if (encoder->type == INTEL_OUTPUT_EDP)
2589 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2590 else
2591 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
2592 pipe_config->lane_count =
2593 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
2594 intel_dp_get_m_n(intel_crtc, pipe_config);
2595 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002596 case TRANS_DDI_MODE_SELECT_DP_MST:
Ville Syrjäläe1214b92017-10-27 22:31:23 +03002597 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST);
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002598 pipe_config->lane_count =
2599 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002600 intel_dp_get_m_n(intel_crtc, pipe_config);
2601 break;
2602 default:
2603 break;
2604 }
Daniel Vetter10214422013-11-18 07:38:16 +01002605
Libin Yang9935f7f2016-11-28 20:07:06 +08002606 pipe_config->has_audio =
2607 intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002608
Jani Nikula6aa23e62016-03-24 17:50:20 +02002609 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
2610 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Daniel Vetter10214422013-11-18 07:38:16 +01002611 /*
2612 * This is a big fat ugly hack.
2613 *
2614 * Some machines in UEFI boot mode provide us a VBT that has 18
2615 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2616 * unknown we fail to light up. Yet the same BIOS boots up with
2617 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2618 * max, not what it tells us to use.
2619 *
2620 * Note: This will still be broken if the eDP panel is not lit
2621 * up by the BIOS, and thus we can't get the mode at module
2622 * load.
2623 */
2624 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002625 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2626 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Daniel Vetter10214422013-11-18 07:38:16 +01002627 }
Jesse Barnes11578552014-01-21 12:42:10 -08002628
Damien Lespiau22606a12014-12-12 14:26:57 +00002629 intel_ddi_clock_get(encoder, pipe_config);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002630
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002631 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002632 pipe_config->lane_lat_optim_mask =
2633 bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03002634
2635 intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002636}
2637
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03002638static enum intel_output_type
2639intel_ddi_compute_output_type(struct intel_encoder *encoder,
2640 struct intel_crtc_state *crtc_state,
2641 struct drm_connector_state *conn_state)
2642{
2643 switch (conn_state->connector->connector_type) {
2644 case DRM_MODE_CONNECTOR_HDMIA:
2645 return INTEL_OUTPUT_HDMI;
2646 case DRM_MODE_CONNECTOR_eDP:
2647 return INTEL_OUTPUT_EDP;
2648 case DRM_MODE_CONNECTOR_DisplayPort:
2649 return INTEL_OUTPUT_DP;
2650 default:
2651 MISSING_CASE(conn_state->connector->connector_type);
2652 return INTEL_OUTPUT_UNUSED;
2653 }
2654}
2655
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002656static bool intel_ddi_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002657 struct intel_crtc_state *pipe_config,
2658 struct drm_connector_state *conn_state)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002659{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002660 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ville Syrjälä0fce04c2017-10-27 22:31:25 +03002661 enum port port = encoder->port;
Imre Deak95a7a2a2016-06-13 16:44:35 +03002662 int ret;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002663
Daniel Vettereccb1402013-05-22 00:50:22 +02002664 if (port == PORT_A)
2665 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2666
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03002667 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002668 ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002669 else
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002670 ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002671
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002672 if (IS_GEN9_LP(dev_priv) && ret)
Imre Deak95a7a2a2016-06-13 16:44:35 +03002673 pipe_config->lane_lat_optim_mask =
Ville Syrjälä5161d052017-10-27 16:43:48 +03002674 bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002675
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03002676 intel_ddi_compute_min_voltage_level(dev_priv, pipe_config);
2677
Imre Deak95a7a2a2016-06-13 16:44:35 +03002678 return ret;
2679
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002680}
2681
2682static const struct drm_encoder_funcs intel_ddi_funcs = {
Imre Deakbf93ba62016-04-18 10:04:21 +03002683 .reset = intel_dp_encoder_reset,
2684 .destroy = intel_dp_encoder_destroy,
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002685};
2686
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002687static struct intel_connector *
2688intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2689{
2690 struct intel_connector *connector;
2691 enum port port = intel_dig_port->port;
2692
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002693 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002694 if (!connector)
2695 return NULL;
2696
2697 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2698 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2699 kfree(connector);
2700 return NULL;
2701 }
2702
2703 return connector;
2704}
2705
2706static struct intel_connector *
2707intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2708{
2709 struct intel_connector *connector;
2710 enum port port = intel_dig_port->port;
2711
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002712 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002713 if (!connector)
2714 return NULL;
2715
2716 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2717 intel_hdmi_init_connector(intel_dig_port, connector);
2718
2719 return connector;
2720}
2721
Rodrigo Vivi436009b2017-10-23 10:39:20 -07002722static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dport)
2723{
2724 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
2725
2726 if (dport->port != PORT_A)
2727 return false;
2728
2729 if (dport->saved_port_bits & DDI_A_4_LANES)
2730 return false;
2731
2732 /* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only
2733 * supported configuration
2734 */
2735 if (IS_GEN9_LP(dev_priv))
2736 return true;
2737
2738 /* Cannonlake: Most of SKUs don't support DDI_E, and the only
2739 * one who does also have a full A/E split called
2740 * DDI_F what makes DDI_E useless. However for this
2741 * case let's trust VBT info.
2742 */
2743 if (IS_CANNONLAKE(dev_priv) &&
2744 !intel_bios_is_port_present(dev_priv, PORT_E))
2745 return true;
2746
2747 return false;
2748}
2749
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002750void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002751{
2752 struct intel_digital_port *intel_dig_port;
2753 struct intel_encoder *intel_encoder;
2754 struct drm_encoder *encoder;
Shashank Sharmaff662122016-10-14 19:56:51 +05302755 bool init_hdmi, init_dp, init_lspcon = false;
Ville Syrjälä10e7bec2015-12-08 19:59:37 +02002756 int max_lanes;
2757
2758 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
2759 switch (port) {
2760 case PORT_A:
2761 max_lanes = 4;
2762 break;
2763 case PORT_E:
2764 max_lanes = 0;
2765 break;
2766 default:
2767 max_lanes = 4;
2768 break;
2769 }
2770 } else {
2771 switch (port) {
2772 case PORT_A:
2773 max_lanes = 2;
2774 break;
2775 case PORT_E:
2776 max_lanes = 2;
2777 break;
2778 default:
2779 max_lanes = 4;
2780 break;
2781 }
2782 }
Paulo Zanoni311a2092013-09-12 17:12:18 -03002783
2784 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2785 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2786 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
Shashank Sharmaff662122016-10-14 19:56:51 +05302787
2788 if (intel_bios_is_lspcon_present(dev_priv, port)) {
2789 /*
2790 * Lspcon device needs to be driven with DP connector
2791 * with special detection sequence. So make sure DP
2792 * is initialized before lspcon.
2793 */
2794 init_dp = true;
2795 init_lspcon = true;
2796 init_hdmi = false;
2797 DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
2798 }
2799
Paulo Zanoni311a2092013-09-12 17:12:18 -03002800 if (!init_dp && !init_hdmi) {
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002801 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03002802 port_name(port));
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002803 return;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002804 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002805
Daniel Vetterb14c5672013-09-19 12:18:32 +02002806 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002807 if (!intel_dig_port)
2808 return;
2809
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002810 intel_encoder = &intel_dig_port->base;
2811 encoder = &intel_encoder->base;
2812
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002813 drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03002814 DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002815
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03002816 intel_encoder->compute_output_type = intel_ddi_compute_output_type;
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002817 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002818 intel_encoder->enable = intel_enable_ddi;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002819 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002820 intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002821 intel_encoder->pre_enable = intel_ddi_pre_enable;
2822 intel_encoder->disable = intel_disable_ddi;
2823 intel_encoder->post_disable = intel_ddi_post_disable;
2824 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002825 intel_encoder->get_config = intel_ddi_get_config;
Imre Deakbf93ba62016-04-18 10:04:21 +03002826 intel_encoder->suspend = intel_dp_encoder_suspend;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002827 intel_encoder->get_power_domains = intel_ddi_get_power_domains;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002828
2829 intel_dig_port->port = port;
Stéphane Marchesinbcf53de42013-07-12 13:54:41 -07002830 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2831 (DDI_BUF_PORT_REVERSAL |
2832 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002833
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +02002834 switch (port) {
2835 case PORT_A:
2836 intel_dig_port->ddi_io_power_domain =
2837 POWER_DOMAIN_PORT_DDI_A_IO;
2838 break;
2839 case PORT_B:
2840 intel_dig_port->ddi_io_power_domain =
2841 POWER_DOMAIN_PORT_DDI_B_IO;
2842 break;
2843 case PORT_C:
2844 intel_dig_port->ddi_io_power_domain =
2845 POWER_DOMAIN_PORT_DDI_C_IO;
2846 break;
2847 case PORT_D:
2848 intel_dig_port->ddi_io_power_domain =
2849 POWER_DOMAIN_PORT_DDI_D_IO;
2850 break;
2851 case PORT_E:
2852 intel_dig_port->ddi_io_power_domain =
2853 POWER_DOMAIN_PORT_DDI_E_IO;
2854 break;
2855 default:
2856 MISSING_CASE(port);
2857 }
2858
Matt Roper6c566dc2015-11-05 14:53:32 -08002859 /*
Rodrigo Vivi436009b2017-10-23 10:39:20 -07002860 * Some BIOS might fail to set this bit on port A if eDP
2861 * wasn't lit up at boot. Force this bit set when needed
2862 * so we use the proper lane count for our calculations.
Matt Roper6c566dc2015-11-05 14:53:32 -08002863 */
Rodrigo Vivi436009b2017-10-23 10:39:20 -07002864 if (intel_ddi_a_force_4_lanes(intel_dig_port)) {
2865 DRM_DEBUG_KMS("Forcing DDI_A_4_LANES for port A\n");
2866 intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
2867 max_lanes = 4;
Matt Roper6c566dc2015-11-05 14:53:32 -08002868 }
2869
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03002870 intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
Matt Ropered8d60f2016-01-28 15:09:37 -08002871 intel_dig_port->max_lanes = max_lanes;
2872
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03002873 intel_encoder->type = INTEL_OUTPUT_DDI;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002874 intel_encoder->power_domain = intel_port_to_power_domain(port);
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07002875 intel_encoder->port = port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002876 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02002877 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002878
Ville Syrjälä385e4de2017-08-18 16:49:55 +03002879 intel_infoframe_init(intel_dig_port);
2880
Chris Wilsonf68d6972014-08-04 07:15:09 +01002881 if (init_dp) {
2882 if (!intel_ddi_init_dp_connector(intel_dig_port))
2883 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10002884
Chris Wilsonf68d6972014-08-04 07:15:09 +01002885 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Ander Conselvan de Oliveiraca4c3892017-02-03 16:03:13 +02002886 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002887 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002888
Paulo Zanoni311a2092013-09-12 17:12:18 -03002889 /* In theory we don't need the encoder->type check, but leave it just in
2890 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01002891 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2892 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2893 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002894 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01002895
Shashank Sharmaff662122016-10-14 19:56:51 +05302896 if (init_lspcon) {
2897 if (lspcon_init(intel_dig_port))
2898 /* TODO: handle hdmi info frame part */
2899 DRM_DEBUG_KMS("LSPCON init success on port %c\n",
2900 port_name(port));
2901 else
2902 /*
2903 * LSPCON init faied, but DP init was success, so
2904 * lets try to drive as DP++ port.
2905 */
2906 DRM_ERROR("LSPCON init failed on port %c\n",
2907 port_name(port));
2908 }
2909
Chris Wilsonf68d6972014-08-04 07:15:09 +01002910 return;
2911
2912err:
2913 drm_encoder_cleanup(encoder);
2914 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002915}