blob: e6c3a80e136091d4937028762103cfb358decf53 [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
Eugeni Dodonov45244b82012-05-09 15:37:20 -030037/* HDMI/DVI modes ignore everything but the last 2 items. So we share
38 * them for both DP and FDI transports, allowing those ports to
39 * automatically adapt to HDMI connections as well
40 */
Jani Nikula10122052014-08-27 16:27:30 +030041static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030042 { 0x00FFFFFF, 0x0006000E, 0x0 },
43 { 0x00D75FFF, 0x0005000A, 0x0 },
44 { 0x00C30FFF, 0x00040006, 0x0 },
45 { 0x80AAAFFF, 0x000B0000, 0x0 },
46 { 0x00FFFFFF, 0x0005000A, 0x0 },
47 { 0x00D75FFF, 0x000C0004, 0x0 },
48 { 0x80C30FFF, 0x000B0000, 0x0 },
49 { 0x00FFFFFF, 0x00040006, 0x0 },
50 { 0x80D75FFF, 0x000B0000, 0x0 },
Eugeni Dodonov45244b82012-05-09 15:37:20 -030051};
52
Jani Nikula10122052014-08-27 16:27:30 +030053static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030054 { 0x00FFFFFF, 0x0007000E, 0x0 },
55 { 0x00D75FFF, 0x000F000A, 0x0 },
56 { 0x00C30FFF, 0x00060006, 0x0 },
57 { 0x00AAAFFF, 0x001E0000, 0x0 },
58 { 0x00FFFFFF, 0x000F000A, 0x0 },
59 { 0x00D75FFF, 0x00160004, 0x0 },
60 { 0x00C30FFF, 0x001E0000, 0x0 },
61 { 0x00FFFFFF, 0x00060006, 0x0 },
62 { 0x00D75FFF, 0x001E0000, 0x0 },
Paulo Zanoni6acab152013-09-12 17:06:24 -030063};
64
Jani Nikula10122052014-08-27 16:27:30 +030065static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
66 /* Idx NT mV d T mV d db */
David Weinehallf8896f52015-06-25 11:11:03 +030067 { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */
68 { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */
69 { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */
70 { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */
71 { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */
72 { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */
73 { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */
74 { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */
75 { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */
76 { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */
77 { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */
78 { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */
Eugeni Dodonov45244b82012-05-09 15:37:20 -030079};
80
Jani Nikula10122052014-08-27 16:27:30 +030081static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030082 { 0x00FFFFFF, 0x00000012, 0x0 },
83 { 0x00EBAFFF, 0x00020011, 0x0 },
84 { 0x00C71FFF, 0x0006000F, 0x0 },
85 { 0x00AAAFFF, 0x000E000A, 0x0 },
86 { 0x00FFFFFF, 0x00020011, 0x0 },
87 { 0x00DB6FFF, 0x0005000F, 0x0 },
88 { 0x00BEEFFF, 0x000A000C, 0x0 },
89 { 0x00FFFFFF, 0x0005000F, 0x0 },
90 { 0x00DB6FFF, 0x000A000C, 0x0 },
Paulo Zanoni300644c2013-11-02 21:07:42 -070091};
92
Jani Nikula10122052014-08-27 16:27:30 +030093static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +030094 { 0x00FFFFFF, 0x0007000E, 0x0 },
95 { 0x00D75FFF, 0x000E000A, 0x0 },
96 { 0x00BEFFFF, 0x00140006, 0x0 },
97 { 0x80B2CFFF, 0x001B0002, 0x0 },
98 { 0x00FFFFFF, 0x000E000A, 0x0 },
99 { 0x00DB6FFF, 0x00160005, 0x0 },
100 { 0x80C71FFF, 0x001A0002, 0x0 },
101 { 0x00F7DFFF, 0x00180004, 0x0 },
102 { 0x80D75FFF, 0x001B0002, 0x0 },
Art Runyane58623c2013-11-02 21:07:41 -0700103};
104
Jani Nikula10122052014-08-27 16:27:30 +0300105static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300106 { 0x00FFFFFF, 0x0001000E, 0x0 },
107 { 0x00D75FFF, 0x0004000A, 0x0 },
108 { 0x00C30FFF, 0x00070006, 0x0 },
109 { 0x00AAAFFF, 0x000C0000, 0x0 },
110 { 0x00FFFFFF, 0x0004000A, 0x0 },
111 { 0x00D75FFF, 0x00090004, 0x0 },
112 { 0x00C30FFF, 0x000C0000, 0x0 },
113 { 0x00FFFFFF, 0x00070006, 0x0 },
114 { 0x00D75FFF, 0x000C0000, 0x0 },
Art Runyane58623c2013-11-02 21:07:41 -0700115};
116
Jani Nikula10122052014-08-27 16:27:30 +0300117static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
118 /* Idx NT mV d T mV df db */
David Weinehallf8896f52015-06-25 11:11:03 +0300119 { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */
120 { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */
121 { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */
122 { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */
123 { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */
124 { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */
125 { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */
126 { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */
127 { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */
128 { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100129};
130
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700131/* Skylake H and S */
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000132static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300133 { 0x00002016, 0x000000A0, 0x0 },
134 { 0x00005012, 0x0000009B, 0x0 },
135 { 0x00007011, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800136 { 0x80009010, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300137 { 0x00002016, 0x0000009B, 0x0 },
138 { 0x00005012, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800139 { 0x80007011, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300140 { 0x00002016, 0x000000DF, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800141 { 0x80005012, 0x000000C0, 0x1 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000142};
143
David Weinehallf8896f52015-06-25 11:11:03 +0300144/* Skylake U */
145static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700146 { 0x0000201B, 0x000000A2, 0x0 },
David Weinehallf8896f52015-06-25 11:11:03 +0300147 { 0x00005012, 0x00000088, 0x0 },
Rodrigo Vivi63ebce12016-01-05 07:58:31 -0800148 { 0x80007011, 0x000000CD, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800149 { 0x80009010, 0x000000C0, 0x1 },
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700150 { 0x0000201B, 0x0000009D, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800151 { 0x80005012, 0x000000C0, 0x1 },
152 { 0x80007011, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300153 { 0x00002016, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800154 { 0x80005012, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300155};
156
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700157/* Skylake Y */
158static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300159 { 0x00000018, 0x000000A2, 0x0 },
160 { 0x00005012, 0x00000088, 0x0 },
Rodrigo Vivi63ebce12016-01-05 07:58:31 -0800161 { 0x80007011, 0x000000CD, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800162 { 0x80009010, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300163 { 0x00000018, 0x0000009D, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800164 { 0x80005012, 0x000000C0, 0x3 },
165 { 0x80007011, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300166 { 0x00000018, 0x00000088, 0x0 },
Rodrigo Vivid7097cf2016-01-05 11:18:55 -0800167 { 0x80005012, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300168};
169
170/*
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700171 * Skylake H and S
David Weinehallf8896f52015-06-25 11:11:03 +0300172 * eDP 1.4 low vswing translation parameters
173 */
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530174static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300175 { 0x00000018, 0x000000A8, 0x0 },
176 { 0x00004013, 0x000000A9, 0x0 },
177 { 0x00007011, 0x000000A2, 0x0 },
178 { 0x00009010, 0x0000009C, 0x0 },
179 { 0x00000018, 0x000000A9, 0x0 },
180 { 0x00006013, 0x000000A2, 0x0 },
181 { 0x00007011, 0x000000A6, 0x0 },
182 { 0x00000018, 0x000000AB, 0x0 },
183 { 0x00007013, 0x0000009F, 0x0 },
184 { 0x00000018, 0x000000DF, 0x0 },
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530185};
186
David Weinehallf8896f52015-06-25 11:11:03 +0300187/*
188 * Skylake U
189 * eDP 1.4 low vswing translation parameters
190 */
191static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
192 { 0x00000018, 0x000000A8, 0x0 },
193 { 0x00004013, 0x000000A9, 0x0 },
194 { 0x00007011, 0x000000A2, 0x0 },
195 { 0x00009010, 0x0000009C, 0x0 },
196 { 0x00000018, 0x000000A9, 0x0 },
197 { 0x00006013, 0x000000A2, 0x0 },
198 { 0x00007011, 0x000000A6, 0x0 },
199 { 0x00002016, 0x000000AB, 0x0 },
200 { 0x00005013, 0x0000009F, 0x0 },
201 { 0x00000018, 0x000000DF, 0x0 },
202};
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530203
David Weinehallf8896f52015-06-25 11:11:03 +0300204/*
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700205 * Skylake Y
David Weinehallf8896f52015-06-25 11:11:03 +0300206 * eDP 1.4 low vswing translation parameters
207 */
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700208static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300209 { 0x00000018, 0x000000A8, 0x0 },
210 { 0x00004013, 0x000000AB, 0x0 },
211 { 0x00007011, 0x000000A4, 0x0 },
212 { 0x00009010, 0x000000DF, 0x0 },
213 { 0x00000018, 0x000000AA, 0x0 },
214 { 0x00006013, 0x000000A4, 0x0 },
215 { 0x00007011, 0x0000009D, 0x0 },
216 { 0x00000018, 0x000000A0, 0x0 },
217 { 0x00006012, 0x000000DF, 0x0 },
218 { 0x00000018, 0x0000008A, 0x0 },
219};
220
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700221/* Skylake U, H and S */
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000222static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300223 { 0x00000018, 0x000000AC, 0x0 },
224 { 0x00005012, 0x0000009D, 0x0 },
225 { 0x00007011, 0x00000088, 0x0 },
226 { 0x00000018, 0x000000A1, 0x0 },
227 { 0x00000018, 0x00000098, 0x0 },
228 { 0x00004013, 0x00000088, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800229 { 0x80006012, 0x000000CD, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300230 { 0x00000018, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800231 { 0x80003015, 0x000000CD, 0x1 }, /* Default */
232 { 0x80003015, 0x000000C0, 0x1 },
233 { 0x80000018, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300234};
235
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700236/* Skylake Y */
237static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300238 { 0x00000018, 0x000000A1, 0x0 },
239 { 0x00005012, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800240 { 0x80007011, 0x000000CB, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300241 { 0x00000018, 0x000000A4, 0x0 },
242 { 0x00000018, 0x0000009D, 0x0 },
243 { 0x00004013, 0x00000080, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800244 { 0x80006013, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300245 { 0x00000018, 0x0000008A, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800246 { 0x80003015, 0x000000C0, 0x3 }, /* Default */
247 { 0x80003015, 0x000000C0, 0x3 },
248 { 0x80000018, 0x000000C0, 0x3 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000249};
250
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530251struct bxt_ddi_buf_trans {
252 u32 margin; /* swing value */
253 u32 scale; /* scale value */
254 u32 enable; /* scale enable */
255 u32 deemphasis;
256 bool default_index; /* true if the entry represents default value */
257};
258
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530259static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
260 /* Idx NT mV diff db */
Imre Deakfe4c63c2015-06-04 18:01:35 +0300261 { 52, 0x9A, 0, 128, true }, /* 0: 400 0 */
262 { 78, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
263 { 104, 0x9A, 0, 64, false }, /* 2: 400 6 */
264 { 154, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
265 { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
266 { 116, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
267 { 154, 0x9A, 0, 64, false }, /* 6: 600 6 */
268 { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
269 { 154, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
David Weinehallf8896f52015-06-25 11:11:03 +0300270 { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530271};
272
Sonika Jindald9d70002015-09-24 10:24:56 +0530273static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
274 /* Idx NT mV diff db */
275 { 26, 0, 0, 128, false }, /* 0: 200 0 */
276 { 38, 0, 0, 112, false }, /* 1: 200 1.5 */
277 { 48, 0, 0, 96, false }, /* 2: 200 4 */
278 { 54, 0, 0, 69, false }, /* 3: 200 6 */
279 { 32, 0, 0, 128, false }, /* 4: 250 0 */
280 { 48, 0, 0, 104, false }, /* 5: 250 1.5 */
281 { 54, 0, 0, 85, false }, /* 6: 250 4 */
282 { 43, 0, 0, 128, false }, /* 7: 300 0 */
283 { 54, 0, 0, 101, false }, /* 8: 300 1.5 */
284 { 48, 0, 0, 128, false }, /* 9: 300 0 */
285};
286
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530287/* BSpec has 2 recommended values - entries 0 and 8.
288 * Using the entry with higher vswing.
289 */
290static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
291 /* Idx NT mV diff db */
Imre Deakfe4c63c2015-06-04 18:01:35 +0300292 { 52, 0x9A, 0, 128, false }, /* 0: 400 0 */
293 { 52, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
294 { 52, 0x9A, 0, 64, false }, /* 2: 400 6 */
295 { 42, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
296 { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
297 { 77, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
298 { 77, 0x9A, 0, 64, false }, /* 6: 600 6 */
299 { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
300 { 102, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530301 { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
302};
303
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200304static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
305 u32 level, enum port port, int type);
David Weinehallf8896f52015-06-25 11:11:03 +0300306
Imre Deaka1e6ad62015-04-17 19:31:21 +0300307static void ddi_get_encoder_port(struct intel_encoder *intel_encoder,
308 struct intel_digital_port **dig_port,
309 enum port *port)
Paulo Zanonifc914632012-10-05 12:05:54 -0300310{
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300311 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonifc914632012-10-05 12:05:54 -0300312
Jani Nikula8cd21b72015-09-29 10:24:26 +0300313 switch (intel_encoder->type) {
314 case INTEL_OUTPUT_DP_MST:
Imre Deaka1e6ad62015-04-17 19:31:21 +0300315 *dig_port = enc_to_mst(encoder)->primary;
316 *port = (*dig_port)->port;
Jani Nikula8cd21b72015-09-29 10:24:26 +0300317 break;
318 case INTEL_OUTPUT_DISPLAYPORT:
319 case INTEL_OUTPUT_EDP:
320 case INTEL_OUTPUT_HDMI:
321 case INTEL_OUTPUT_UNKNOWN:
Imre Deaka1e6ad62015-04-17 19:31:21 +0300322 *dig_port = enc_to_dig_port(encoder);
323 *port = (*dig_port)->port;
Jani Nikula8cd21b72015-09-29 10:24:26 +0300324 break;
325 case INTEL_OUTPUT_ANALOG:
Imre Deaka1e6ad62015-04-17 19:31:21 +0300326 *dig_port = NULL;
327 *port = PORT_E;
Jani Nikula8cd21b72015-09-29 10:24:26 +0300328 break;
329 default:
330 WARN(1, "Invalid DDI encoder type %d\n", intel_encoder->type);
331 break;
Paulo Zanonifc914632012-10-05 12:05:54 -0300332 }
333}
334
Imre Deaka1e6ad62015-04-17 19:31:21 +0300335enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
336{
337 struct intel_digital_port *dig_port;
338 enum port port;
339
340 ddi_get_encoder_port(intel_encoder, &dig_port, &port);
341
342 return port;
343}
344
Ville Syrjäläacee2992015-12-08 19:59:39 +0200345static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200346skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300347{
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200348 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700349 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200350 return skl_y_ddi_translations_dp;
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200351 } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +0300352 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200353 return skl_u_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300354 } else {
David Weinehallf8896f52015-06-25 11:11:03 +0300355 *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200356 return skl_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300357 }
David Weinehallf8896f52015-06-25 11:11:03 +0300358}
359
360static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200361skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300362{
Ville Syrjäläcd1101c2015-12-08 19:59:40 +0200363 if (dev_priv->edp_low_vswing) {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200364 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200365 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
366 return skl_y_ddi_translations_edp;
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200367 } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200368 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
369 return skl_u_ddi_translations_edp;
370 } else {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200371 *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
372 return skl_ddi_translations_edp;
Ville Syrjäläacee2992015-12-08 19:59:39 +0200373 }
David Weinehallf8896f52015-06-25 11:11:03 +0300374 }
Ville Syrjäläcd1101c2015-12-08 19:59:40 +0200375
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200376 return skl_get_buf_trans_dp(dev_priv, n_entries);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200377}
David Weinehallf8896f52015-06-25 11:11:03 +0300378
Ville Syrjäläacee2992015-12-08 19:59:39 +0200379static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200380skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
Ville Syrjäläacee2992015-12-08 19:59:39 +0200381{
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200382 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200383 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
384 return skl_y_ddi_translations_hdmi;
385 } else {
386 *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
387 return skl_ddi_translations_hdmi;
388 }
David Weinehallf8896f52015-06-25 11:11:03 +0300389}
390
Art Runyane58623c2013-11-02 21:07:41 -0700391/*
392 * Starting with Haswell, DDI port buffers must be programmed with correct
393 * values in advance. The buffer values are different for FDI and DP modes,
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300394 * but the HDMI/DVI fields are shared among those. So we program the DDI
395 * in either FDI or DP modes only, as HDMI connections will work with both
396 * of those
397 */
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200398void intel_prepare_ddi_buffer(struct intel_encoder *encoder)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300399{
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200400 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300401 u32 iboost_bit = 0;
Damien Lespiau7ff44672015-03-02 16:19:36 +0000402 int i, n_hdmi_entries, n_dp_entries, n_edp_entries, hdmi_default_entry,
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530403 size;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200404 int hdmi_level;
405 enum port port;
Jani Nikula10122052014-08-27 16:27:30 +0300406 const struct ddi_buf_trans *ddi_translations_fdi;
407 const struct ddi_buf_trans *ddi_translations_dp;
408 const struct ddi_buf_trans *ddi_translations_edp;
409 const struct ddi_buf_trans *ddi_translations_hdmi;
410 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700411
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200412 port = intel_ddi_get_encoder_port(encoder);
413 hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
414
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200415 if (IS_BROXTON(dev_priv)) {
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200416 if (encoder->type != INTEL_OUTPUT_HDMI)
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530417 return;
418
419 /* Vswing programming for HDMI */
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200420 bxt_ddi_vswing_sequence(dev_priv, hdmi_level, port,
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530421 INTEL_OUTPUT_HDMI);
422 return;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200423 }
424
425 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
Paulo Zanonic30400f2015-07-03 12:31:30 -0300426 ddi_translations_fdi = NULL;
David Weinehallf8896f52015-06-25 11:11:03 +0300427 ddi_translations_dp =
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200428 skl_get_buf_trans_dp(dev_priv, &n_dp_entries);
David Weinehallf8896f52015-06-25 11:11:03 +0300429 ddi_translations_edp =
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200430 skl_get_buf_trans_edp(dev_priv, &n_edp_entries);
David Weinehallf8896f52015-06-25 11:11:03 +0300431 ddi_translations_hdmi =
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200432 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
David Weinehallf8896f52015-06-25 11:11:03 +0300433 hdmi_default_entry = 8;
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300434 /* If we're boosting the current, set bit 31 of trans1 */
435 if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level ||
436 dev_priv->vbt.ddi_port_info[port].dp_boost_level)
437 iboost_bit = 1<<31;
Ville Syrjälä10afa0b2015-12-08 19:59:43 +0200438
Ville Syrjäläceccad52016-01-12 17:28:16 +0200439 if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
440 port != PORT_A && port != PORT_E &&
441 n_edp_entries > 9))
Ville Syrjälä10afa0b2015-12-08 19:59:43 +0200442 n_edp_entries = 9;
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200443 } else if (IS_BROADWELL(dev_priv)) {
Art Runyane58623c2013-11-02 21:07:41 -0700444 ddi_translations_fdi = bdw_ddi_translations_fdi;
445 ddi_translations_dp = bdw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700446 ddi_translations_edp = bdw_ddi_translations_edp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100447 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530448 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
449 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300450 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000451 hdmi_default_entry = 7;
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200452 } else if (IS_HASWELL(dev_priv)) {
Art Runyane58623c2013-11-02 21:07:41 -0700453 ddi_translations_fdi = hsw_ddi_translations_fdi;
454 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700455 ddi_translations_edp = hsw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100456 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530457 n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300458 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000459 hdmi_default_entry = 6;
Art Runyane58623c2013-11-02 21:07:41 -0700460 } else {
461 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700462 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700463 ddi_translations_fdi = bdw_ddi_translations_fdi;
464 ddi_translations_dp = bdw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100465 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530466 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
467 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300468 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000469 hdmi_default_entry = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700470 }
471
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200472 switch (encoder->type) {
473 case INTEL_OUTPUT_EDP:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700474 ddi_translations = ddi_translations_edp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530475 size = n_edp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700476 break;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200477 case INTEL_OUTPUT_DISPLAYPORT:
478 case INTEL_OUTPUT_HDMI:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700479 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530480 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700481 break;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200482 case INTEL_OUTPUT_ANALOG:
483 ddi_translations = ddi_translations_fdi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530484 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700485 break;
486 default:
487 BUG();
488 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300489
Ville Syrjälä9712e682015-09-18 20:03:22 +0300490 for (i = 0; i < size; i++) {
491 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
492 ddi_translations[i].trans1 | iboost_bit);
493 I915_WRITE(DDI_BUF_TRANS_HI(port, i),
494 ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300495 }
Damien Lespiauce4dd492014-08-01 11:07:54 +0100496
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200497 if (encoder->type != INTEL_OUTPUT_HDMI)
Damien Lespiauce3b7e92014-08-04 15:04:43 +0100498 return;
499
Damien Lespiauce4dd492014-08-01 11:07:54 +0100500 /* Choose a good default if VBT is badly populated */
501 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
502 hdmi_level >= n_hdmi_entries)
Damien Lespiau7ff44672015-03-02 16:19:36 +0000503 hdmi_level = hdmi_default_entry;
Damien Lespiauce4dd492014-08-01 11:07:54 +0100504
Paulo Zanoni6acab152013-09-12 17:06:24 -0300505 /* Entry 9 is for HDMI: */
Ville Syrjälä9712e682015-09-18 20:03:22 +0300506 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
507 ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
508 I915_WRITE(DDI_BUF_TRANS_HI(port, i),
509 ddi_translations_hdmi[hdmi_level].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300510}
511
Paulo Zanoni248138b2012-11-29 11:29:31 -0200512static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
513 enum port port)
514{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200515 i915_reg_t reg = DDI_BUF_CTL(port);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200516 int i;
517
Vandana Kannan3449ca82015-03-27 14:19:09 +0200518 for (i = 0; i < 16; i++) {
Paulo Zanoni248138b2012-11-29 11:29:31 -0200519 udelay(1);
520 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
521 return;
522 }
523 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
524}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300525
526/* Starting with Haswell, different DDI ports can work in FDI mode for
527 * connection to the PCH-located connectors. For this, it is necessary to train
528 * both the DDI port and PCH receiver for the desired DDI buffer settings.
529 *
530 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
531 * please note that when FDI mode is active on DDI E, it shares 2 lines with
532 * DDI A (which is used for eDP)
533 */
534
535void hsw_fdi_link_train(struct drm_crtc *crtc)
536{
537 struct drm_device *dev = crtc->dev;
538 struct drm_i915_private *dev_priv = dev->dev_private;
539 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200540 struct intel_encoder *encoder;
Paulo Zanoni04945642012-11-01 21:00:59 -0200541 u32 temp, i, rx_ctl_val;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300542
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200543 for_each_encoder_on_crtc(dev, crtc, encoder) {
544 WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
545 intel_prepare_ddi_buffer(encoder);
546 }
547
Paulo Zanoni04945642012-11-01 21:00:59 -0200548 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
549 * mode set "sequence for CRT port" document:
550 * - TP1 to TP2 time with the default value
551 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100552 *
553 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200554 */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300555 I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200556 FDI_RX_PWRDN_LANE0_VAL(2) |
557 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
558
559 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000560 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100561 FDI_RX_PLL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200562 FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300563 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
564 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200565 udelay(220);
566
567 /* Switch from Rawclk to PCDclk */
568 rx_ctl_val |= FDI_PCDCLK;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300569 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
Paulo Zanoni04945642012-11-01 21:00:59 -0200570
571 /* Configure Port Clock Select */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200572 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config->ddi_pll_sel);
573 WARN_ON(intel_crtc->config->ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200574
575 /* Start the training iterating through available voltages and emphasis,
576 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300577 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300578 /* Configure DP_TP_CTL with auto-training */
579 I915_WRITE(DP_TP_CTL(PORT_E),
580 DP_TP_CTL_FDI_AUTOTRAIN |
581 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
582 DP_TP_CTL_LINK_TRAIN_PAT1 |
583 DP_TP_CTL_ENABLE);
584
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000585 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
586 * DDI E does not support port reversal, the functionality is
587 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
588 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300589 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200590 DDI_BUF_CTL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200591 ((intel_crtc->config->fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530592 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200593 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300594
595 udelay(600);
596
Paulo Zanoni04945642012-11-01 21:00:59 -0200597 /* Program PCH FDI Receiver TU */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300598 I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300599
Paulo Zanoni04945642012-11-01 21:00:59 -0200600 /* Enable PCH FDI Receiver with auto-training */
601 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300602 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
603 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200604
605 /* Wait for FDI receiver lane calibration */
606 udelay(30);
607
608 /* Unset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300609 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200610 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300611 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
612 POSTING_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200613
614 /* Wait for FDI auto training time */
615 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300616
617 temp = I915_READ(DP_TP_STATUS(PORT_E));
618 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200619 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200620 break;
621 }
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300622
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200623 /*
624 * Leave things enabled even if we failed to train FDI.
625 * Results in less fireworks from the state checker.
626 */
627 if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
628 DRM_ERROR("FDI link training failed!\n");
629 break;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300630 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200631
Paulo Zanoni248138b2012-11-29 11:29:31 -0200632 temp = I915_READ(DDI_BUF_CTL(PORT_E));
633 temp &= ~DDI_BUF_CTL_ENABLE;
634 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
635 POSTING_READ(DDI_BUF_CTL(PORT_E));
636
Paulo Zanoni04945642012-11-01 21:00:59 -0200637 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200638 temp = I915_READ(DP_TP_CTL(PORT_E));
639 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
640 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
641 I915_WRITE(DP_TP_CTL(PORT_E), temp);
642 POSTING_READ(DP_TP_CTL(PORT_E));
643
644 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200645
646 rx_ctl_val &= ~FDI_RX_ENABLE;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300647 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
648 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200649
650 /* Reset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300651 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200652 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
653 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300654 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
655 POSTING_READ(FDI_RX_MISC(PIPE_A));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300656 }
657
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200658 /* Enable normal pixel sending for FDI */
659 I915_WRITE(DP_TP_CTL(PORT_E),
660 DP_TP_CTL_FDI_AUTOTRAIN |
661 DP_TP_CTL_LINK_TRAIN_NORMAL |
662 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
663 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300664}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300665
Dave Airlie44905a22014-05-02 13:36:43 +1000666void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
667{
668 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
669 struct intel_digital_port *intel_dig_port =
670 enc_to_dig_port(&encoder->base);
671
672 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530673 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Ville Syrjälä901c2da2015-08-17 18:05:12 +0300674 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Dave Airlie44905a22014-05-02 13:36:43 +1000675}
676
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300677static struct intel_encoder *
678intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
679{
680 struct drm_device *dev = crtc->dev;
681 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
682 struct intel_encoder *intel_encoder, *ret = NULL;
683 int num_encoders = 0;
684
685 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
686 ret = intel_encoder;
687 num_encoders++;
688 }
689
690 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300691 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
692 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300693
694 BUG_ON(ret == NULL);
695 return ret;
696}
697
Satheeshakrishna Mbcddf612014-08-22 09:49:10 +0530698struct intel_encoder *
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200699intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200700{
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200701 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
702 struct intel_encoder *ret = NULL;
703 struct drm_atomic_state *state;
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300704 struct drm_connector *connector;
705 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200706 int num_encoders = 0;
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200707 int i;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200708
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200709 state = crtc_state->base.state;
710
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300711 for_each_connector_in_state(state, connector, connector_state, i) {
712 if (connector_state->crtc != crtc_state->base.crtc)
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200713 continue;
714
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300715 ret = to_intel_encoder(connector_state->best_encoder);
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200716 num_encoders++;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200717 }
718
719 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
720 pipe_name(crtc->pipe));
721
722 BUG_ON(ret == NULL);
723 return ret;
724}
725
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100726#define LC_FREQ 2700
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100727
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200728static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
729 i915_reg_t reg)
Jesse Barnes11578552014-01-21 12:42:10 -0800730{
731 int refclk = LC_FREQ;
732 int n, p, r;
733 u32 wrpll;
734
735 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300736 switch (wrpll & WRPLL_PLL_REF_MASK) {
737 case WRPLL_PLL_SSC:
738 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800739 /*
740 * We could calculate spread here, but our checking
741 * code only cares about 5% accuracy, and spread is a max of
742 * 0.5% downspread.
743 */
744 refclk = 135;
745 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300746 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800747 refclk = LC_FREQ;
748 break;
749 default:
750 WARN(1, "bad wrpll refclk\n");
751 return 0;
752 }
753
754 r = wrpll & WRPLL_DIVIDER_REF_MASK;
755 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
756 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
757
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800758 /* Convert to KHz, p & r have a fixed point portion */
759 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800760}
761
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000762static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
763 uint32_t dpll)
764{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200765 i915_reg_t cfgcr1_reg, cfgcr2_reg;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000766 uint32_t cfgcr1_val, cfgcr2_val;
767 uint32_t p0, p1, p2, dco_freq;
768
Ville Syrjälä923c12412015-09-30 17:06:43 +0300769 cfgcr1_reg = DPLL_CFGCR1(dpll);
770 cfgcr2_reg = DPLL_CFGCR2(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000771
772 cfgcr1_val = I915_READ(cfgcr1_reg);
773 cfgcr2_val = I915_READ(cfgcr2_reg);
774
775 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
776 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
777
778 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
779 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
780 else
781 p1 = 1;
782
783
784 switch (p0) {
785 case DPLL_CFGCR2_PDIV_1:
786 p0 = 1;
787 break;
788 case DPLL_CFGCR2_PDIV_2:
789 p0 = 2;
790 break;
791 case DPLL_CFGCR2_PDIV_3:
792 p0 = 3;
793 break;
794 case DPLL_CFGCR2_PDIV_7:
795 p0 = 7;
796 break;
797 }
798
799 switch (p2) {
800 case DPLL_CFGCR2_KDIV_5:
801 p2 = 5;
802 break;
803 case DPLL_CFGCR2_KDIV_2:
804 p2 = 2;
805 break;
806 case DPLL_CFGCR2_KDIV_3:
807 p2 = 3;
808 break;
809 case DPLL_CFGCR2_KDIV_1:
810 p2 = 1;
811 break;
812 }
813
814 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
815
816 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
817 1000) / 0x8000;
818
819 return dco_freq / (p0 * p1 * p2 * 5);
820}
821
Ville Syrjälä398a0172015-06-30 15:33:51 +0300822static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
823{
824 int dotclock;
825
826 if (pipe_config->has_pch_encoder)
827 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
828 &pipe_config->fdi_m_n);
829 else if (pipe_config->has_dp_encoder)
830 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
831 &pipe_config->dp_m_n);
832 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
833 dotclock = pipe_config->port_clock * 2 / 3;
834 else
835 dotclock = pipe_config->port_clock;
836
837 if (pipe_config->pixel_multiplier)
838 dotclock /= pipe_config->pixel_multiplier;
839
840 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
841}
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000842
843static void skl_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200844 struct intel_crtc_state *pipe_config)
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000845{
846 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000847 int link_clock = 0;
848 uint32_t dpll_ctl1, dpll;
849
Damien Lespiau134ffa42014-11-14 17:24:34 +0000850 dpll = pipe_config->ddi_pll_sel;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000851
852 dpll_ctl1 = I915_READ(DPLL_CTRL1);
853
854 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
855 link_clock = skl_calc_wrpll_link(dev_priv, dpll);
856 } else {
Damien Lespiau71cd8422015-04-30 16:39:17 +0100857 link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
858 link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000859
860 switch (link_clock) {
Damien Lespiau71cd8422015-04-30 16:39:17 +0100861 case DPLL_CTRL1_LINK_RATE_810:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000862 link_clock = 81000;
863 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100864 case DPLL_CTRL1_LINK_RATE_1080:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530865 link_clock = 108000;
866 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100867 case DPLL_CTRL1_LINK_RATE_1350:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000868 link_clock = 135000;
869 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100870 case DPLL_CTRL1_LINK_RATE_1620:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530871 link_clock = 162000;
872 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100873 case DPLL_CTRL1_LINK_RATE_2160:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530874 link_clock = 216000;
875 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100876 case DPLL_CTRL1_LINK_RATE_2700:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000877 link_clock = 270000;
878 break;
879 default:
880 WARN(1, "Unsupported link rate\n");
881 break;
882 }
883 link_clock *= 2;
884 }
885
886 pipe_config->port_clock = link_clock;
887
Ville Syrjälä398a0172015-06-30 15:33:51 +0300888 ddi_dotclock_get(pipe_config);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000889}
890
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200891static void hsw_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200892 struct intel_crtc_state *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -0800893{
894 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jesse Barnes11578552014-01-21 12:42:10 -0800895 int link_clock = 0;
896 u32 val, pll;
897
Daniel Vetter26804af2014-06-25 22:01:55 +0300898 val = pipe_config->ddi_pll_sel;
Jesse Barnes11578552014-01-21 12:42:10 -0800899 switch (val & PORT_CLK_SEL_MASK) {
900 case PORT_CLK_SEL_LCPLL_810:
901 link_clock = 81000;
902 break;
903 case PORT_CLK_SEL_LCPLL_1350:
904 link_clock = 135000;
905 break;
906 case PORT_CLK_SEL_LCPLL_2700:
907 link_clock = 270000;
908 break;
909 case PORT_CLK_SEL_WRPLL1:
Ville Syrjälä01403de2015-09-18 20:03:33 +0300910 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
Jesse Barnes11578552014-01-21 12:42:10 -0800911 break;
912 case PORT_CLK_SEL_WRPLL2:
Ville Syrjälä01403de2015-09-18 20:03:33 +0300913 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
Jesse Barnes11578552014-01-21 12:42:10 -0800914 break;
915 case PORT_CLK_SEL_SPLL:
916 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
917 if (pll == SPLL_PLL_FREQ_810MHz)
918 link_clock = 81000;
919 else if (pll == SPLL_PLL_FREQ_1350MHz)
920 link_clock = 135000;
921 else if (pll == SPLL_PLL_FREQ_2700MHz)
922 link_clock = 270000;
923 else {
924 WARN(1, "bad spll freq\n");
925 return;
926 }
927 break;
928 default:
929 WARN(1, "bad port clock sel\n");
930 return;
931 }
932
933 pipe_config->port_clock = link_clock * 2;
934
Ville Syrjälä398a0172015-06-30 15:33:51 +0300935 ddi_dotclock_get(pipe_config);
Jesse Barnes11578552014-01-21 12:42:10 -0800936}
937
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530938static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
939 enum intel_dpll_id dpll)
940{
Imre Deakaa610dc2015-06-22 23:35:52 +0300941 struct intel_shared_dpll *pll;
942 struct intel_dpll_hw_state *state;
943 intel_clock_t clock;
944
945 /* For DDI ports we always use a shared PLL. */
946 if (WARN_ON(dpll == DPLL_ID_PRIVATE))
947 return 0;
948
949 pll = &dev_priv->shared_dplls[dpll];
950 state = &pll->config.hw_state;
951
952 clock.m1 = 2;
953 clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
954 if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
955 clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
956 clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
957 clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
958 clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
959
960 return chv_calc_dpll_params(100000, &clock);
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530961}
962
963static void bxt_ddi_clock_get(struct intel_encoder *encoder,
964 struct intel_crtc_state *pipe_config)
965{
966 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
967 enum port port = intel_ddi_get_encoder_port(encoder);
968 uint32_t dpll = port;
969
Ville Syrjälä398a0172015-06-30 15:33:51 +0300970 pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530971
Ville Syrjälä398a0172015-06-30 15:33:51 +0300972 ddi_dotclock_get(pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530973}
974
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200975void intel_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200976 struct intel_crtc_state *pipe_config)
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200977{
Damien Lespiau22606a12014-12-12 14:26:57 +0000978 struct drm_device *dev = encoder->base.dev;
979
980 if (INTEL_INFO(dev)->gen <= 8)
981 hsw_ddi_clock_get(encoder, pipe_config);
Rodrigo Vivief11bdb2015-10-28 04:16:45 -0700982 else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Damien Lespiau22606a12014-12-12 14:26:57 +0000983 skl_ddi_clock_get(encoder, pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530984 else if (IS_BROXTON(dev))
985 bxt_ddi_clock_get(encoder, pipe_config);
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200986}
987
Damien Lespiau0220ab62014-07-29 18:06:22 +0100988static bool
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100989hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +0200990 struct intel_crtc_state *crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +0300991 struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300992{
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +0200993 struct intel_shared_dpll *pll;
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +0300994
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +0200995 pll = intel_get_shared_dpll(intel_crtc, crtc_state,
996 intel_encoder);
997 if (!pll)
998 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
999 pipe_name(intel_crtc->pipe));
1000
1001 return pll;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001002}
1003
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001004static bool
1005skl_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001006 struct intel_crtc_state *crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001007 struct intel_encoder *intel_encoder)
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001008{
1009 struct intel_shared_dpll *pll;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001010
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +02001011 pll = intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001012 if (pll == NULL) {
1013 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1014 pipe_name(intel_crtc->pipe));
1015 return false;
1016 }
1017
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001018 return true;
1019}
Damien Lespiau0220ab62014-07-29 18:06:22 +01001020
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301021static bool
1022bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
1023 struct intel_crtc_state *crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001024 struct intel_encoder *intel_encoder)
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301025{
Ander Conselvan de Oliveira34177c22016-03-08 17:46:25 +02001026 return !!intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301027}
1028
Damien Lespiau0220ab62014-07-29 18:06:22 +01001029/*
1030 * Tries to find a *shared* PLL for the CRTC and store it in
1031 * intel_crtc->ddi_pll_sel.
1032 *
1033 * For private DPLLs, compute_config() should do the selection for us. This
1034 * function should be folded into compute_config() eventually.
1035 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001036bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
1037 struct intel_crtc_state *crtc_state)
Damien Lespiau0220ab62014-07-29 18:06:22 +01001038{
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001039 struct drm_device *dev = intel_crtc->base.dev;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001040 struct intel_encoder *intel_encoder =
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001041 intel_ddi_get_crtc_new_encoder(crtc_state);
Damien Lespiau0220ab62014-07-29 18:06:22 +01001042
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001043 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001044 return skl_ddi_pll_select(intel_crtc, crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001045 intel_encoder);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301046 else if (IS_BROXTON(dev))
1047 return bxt_ddi_pll_select(intel_crtc, crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001048 intel_encoder);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001049 else
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001050 return hsw_ddi_pll_select(intel_crtc, crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001051 intel_encoder);
Damien Lespiau0220ab62014-07-29 18:06:22 +01001052}
1053
Paulo Zanonidae84792012-10-15 15:51:30 -03001054void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
1055{
1056 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1057 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1058 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001059 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -03001060 int type = intel_encoder->type;
1061 uint32_t temp;
1062
Dave Airlie0e32b392014-05-02 14:02:48 +10001063 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Jani Nikula4d1de972016-03-18 17:05:42 +02001064 WARN_ON(transcoder_is_dsi(cpu_transcoder));
1065
Paulo Zanonic9809792012-10-23 18:30:00 -02001066 temp = TRANS_MSA_SYNC_CLK;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001067 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -03001068 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -02001069 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001070 break;
1071 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -02001072 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001073 break;
1074 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -02001075 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001076 break;
1077 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -02001078 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001079 break;
1080 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001081 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -03001082 }
Paulo Zanonic9809792012-10-23 18:30:00 -02001083 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -03001084 }
1085}
1086
Dave Airlie0e32b392014-05-02 14:02:48 +10001087void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
1088{
1089 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1090 struct drm_device *dev = crtc->dev;
1091 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001092 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +10001093 uint32_t temp;
1094 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1095 if (state == true)
1096 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1097 else
1098 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1099 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1100}
1101
Damien Lespiau8228c252013-03-07 15:30:27 +00001102void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001103{
1104 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1105 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001106 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -07001107 struct drm_device *dev = crtc->dev;
1108 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001109 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001110 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001111 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001112 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001113 uint32_t temp;
1114
Paulo Zanoniad80a812012-10-24 16:06:19 -02001115 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1116 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001117 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001118
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001119 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001120 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001121 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001122 break;
1123 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001124 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001125 break;
1126 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001127 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001128 break;
1129 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001130 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001131 break;
1132 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001133 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001134 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001135
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001136 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001137 temp |= TRANS_DDI_PVSYNC;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001138 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001139 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c2012-08-08 14:15:28 -03001140
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001141 if (cpu_transcoder == TRANSCODER_EDP) {
1142 switch (pipe) {
1143 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001144 /* On Haswell, can only use the always-on power well for
1145 * eDP when not using the panel fitter, and when not
1146 * using motion blur mitigation (which we don't
1147 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +02001148 if (IS_HASWELL(dev) &&
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001149 (intel_crtc->config->pch_pfit.enabled ||
1150 intel_crtc->config->pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001151 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1152 else
1153 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001154 break;
1155 case PIPE_B:
1156 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1157 break;
1158 case PIPE_C:
1159 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1160 break;
1161 default:
1162 BUG();
1163 break;
1164 }
1165 }
1166
Paulo Zanoni7739c332012-10-15 15:51:29 -03001167 if (type == INTEL_OUTPUT_HDMI) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001168 if (intel_crtc->config->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001169 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001170 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001171 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001172
Paulo Zanoni7739c332012-10-15 15:51:29 -03001173 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001174 temp |= TRANS_DDI_MODE_SELECT_FDI;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001175 temp |= (intel_crtc->config->fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001176
1177 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
1178 type == INTEL_OUTPUT_EDP) {
1179 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1180
Dave Airlie0e32b392014-05-02 14:02:48 +10001181 if (intel_dp->is_mst) {
1182 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
1183 } else
1184 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
1185
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001186 temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
Dave Airlie0e32b392014-05-02 14:02:48 +10001187 } else if (type == INTEL_OUTPUT_DP_MST) {
1188 struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
1189
1190 if (intel_dp->is_mst) {
1191 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
1192 } else
1193 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001194
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001195 temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001196 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001197 WARN(1, "Invalid encoder type %d for pipe %c\n",
1198 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001199 }
1200
Paulo Zanoniad80a812012-10-24 16:06:19 -02001201 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001202}
1203
Paulo Zanoniad80a812012-10-24 16:06:19 -02001204void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1205 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001206{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001207 i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001208 uint32_t val = I915_READ(reg);
1209
Dave Airlie0e32b392014-05-02 14:02:48 +10001210 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -02001211 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001212 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001213}
1214
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001215bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1216{
1217 struct drm_device *dev = intel_connector->base.dev;
1218 struct drm_i915_private *dev_priv = dev->dev_private;
1219 struct intel_encoder *intel_encoder = intel_connector->encoder;
1220 int type = intel_connector->base.connector_type;
1221 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1222 enum pipe pipe = 0;
1223 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -03001224 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001225 uint32_t tmp;
Imre Deake27daab2016-02-12 18:55:16 +02001226 bool ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001227
Paulo Zanoni882244a2014-04-01 14:55:12 -03001228 power_domain = intel_display_port_power_domain(intel_encoder);
Imre Deake27daab2016-02-12 18:55:16 +02001229 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Paulo Zanoni882244a2014-04-01 14:55:12 -03001230 return false;
1231
Imre Deake27daab2016-02-12 18:55:16 +02001232 if (!intel_encoder->get_hw_state(intel_encoder, &pipe)) {
1233 ret = false;
1234 goto out;
1235 }
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001236
1237 if (port == PORT_A)
1238 cpu_transcoder = TRANSCODER_EDP;
1239 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001240 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001241
1242 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1243
1244 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1245 case TRANS_DDI_MODE_SELECT_HDMI:
1246 case TRANS_DDI_MODE_SELECT_DVI:
Imre Deake27daab2016-02-12 18:55:16 +02001247 ret = type == DRM_MODE_CONNECTOR_HDMIA;
1248 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001249
1250 case TRANS_DDI_MODE_SELECT_DP_SST:
Imre Deake27daab2016-02-12 18:55:16 +02001251 ret = type == DRM_MODE_CONNECTOR_eDP ||
1252 type == DRM_MODE_CONNECTOR_DisplayPort;
1253 break;
1254
Dave Airlie0e32b392014-05-02 14:02:48 +10001255 case TRANS_DDI_MODE_SELECT_DP_MST:
1256 /* if the transcoder is in MST state then
1257 * connector isn't connected */
Imre Deake27daab2016-02-12 18:55:16 +02001258 ret = false;
1259 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001260
1261 case TRANS_DDI_MODE_SELECT_FDI:
Imre Deake27daab2016-02-12 18:55:16 +02001262 ret = type == DRM_MODE_CONNECTOR_VGA;
1263 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001264
1265 default:
Imre Deake27daab2016-02-12 18:55:16 +02001266 ret = false;
1267 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001268 }
Imre Deake27daab2016-02-12 18:55:16 +02001269
1270out:
1271 intel_display_power_put(dev_priv, power_domain);
1272
1273 return ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001274}
1275
Daniel Vetter85234cd2012-07-02 13:27:29 +02001276bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1277 enum pipe *pipe)
1278{
1279 struct drm_device *dev = encoder->base.dev;
1280 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001281 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001282 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001283 u32 tmp;
1284 int i;
Imre Deake27daab2016-02-12 18:55:16 +02001285 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001286
Imre Deak6d129be2014-03-05 16:20:54 +02001287 power_domain = intel_display_port_power_domain(encoder);
Imre Deake27daab2016-02-12 18:55:16 +02001288 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001289 return false;
1290
Imre Deake27daab2016-02-12 18:55:16 +02001291 ret = false;
1292
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001293 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001294
1295 if (!(tmp & DDI_BUF_CTL_ENABLE))
Imre Deake27daab2016-02-12 18:55:16 +02001296 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001297
Paulo Zanoniad80a812012-10-24 16:06:19 -02001298 if (port == PORT_A) {
1299 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001300
Paulo Zanoniad80a812012-10-24 16:06:19 -02001301 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1302 case TRANS_DDI_EDP_INPUT_A_ON:
1303 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1304 *pipe = PIPE_A;
1305 break;
1306 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1307 *pipe = PIPE_B;
1308 break;
1309 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1310 *pipe = PIPE_C;
1311 break;
1312 }
1313
Imre Deake27daab2016-02-12 18:55:16 +02001314 ret = true;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001315
Imre Deake27daab2016-02-12 18:55:16 +02001316 goto out;
1317 }
Dave Airlie0e32b392014-05-02 14:02:48 +10001318
Imre Deake27daab2016-02-12 18:55:16 +02001319 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1320 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1321
1322 if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
1323 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
1324 TRANS_DDI_MODE_SELECT_DP_MST)
1325 goto out;
1326
1327 *pipe = i;
1328 ret = true;
1329
1330 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001331 }
1332 }
1333
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001334 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001335
Imre Deake27daab2016-02-12 18:55:16 +02001336out:
1337 intel_display_power_put(dev_priv, power_domain);
1338
1339 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001340}
1341
Paulo Zanonifc914632012-10-05 12:05:54 -03001342void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1343{
1344 struct drm_crtc *crtc = &intel_crtc->base;
Shashank Sharma7d4aefd2015-10-01 22:23:49 +05301345 struct drm_device *dev = crtc->dev;
1346 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonifc914632012-10-05 12:05:54 -03001347 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1348 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001349 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001350
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001351 if (cpu_transcoder != TRANSCODER_EDP)
1352 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1353 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001354}
1355
1356void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1357{
1358 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001359 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001360
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001361 if (cpu_transcoder != TRANSCODER_EDP)
1362 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1363 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001364}
1365
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001366static void skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1367 u32 level, enum port port, int type)
David Weinehallf8896f52015-06-25 11:11:03 +03001368{
David Weinehallf8896f52015-06-25 11:11:03 +03001369 const struct ddi_buf_trans *ddi_translations;
1370 uint8_t iboost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001371 uint8_t dp_iboost, hdmi_iboost;
David Weinehallf8896f52015-06-25 11:11:03 +03001372 int n_entries;
1373 u32 reg;
1374
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001375 /* VBT may override standard boost values */
1376 dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
1377 hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
1378
David Weinehallf8896f52015-06-25 11:11:03 +03001379 if (type == INTEL_OUTPUT_DISPLAYPORT) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001380 if (dp_iboost) {
1381 iboost = dp_iboost;
1382 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001383 ddi_translations = skl_get_buf_trans_dp(dev_priv, &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001384 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001385 }
David Weinehallf8896f52015-06-25 11:11:03 +03001386 } else if (type == INTEL_OUTPUT_EDP) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001387 if (dp_iboost) {
1388 iboost = dp_iboost;
1389 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001390 ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
Ville Syrjälä10afa0b2015-12-08 19:59:43 +02001391
1392 if (WARN_ON(port != PORT_A &&
1393 port != PORT_E && n_entries > 9))
1394 n_entries = 9;
1395
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001396 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001397 }
David Weinehallf8896f52015-06-25 11:11:03 +03001398 } else if (type == INTEL_OUTPUT_HDMI) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001399 if (hdmi_iboost) {
1400 iboost = hdmi_iboost;
1401 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001402 ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001403 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001404 }
David Weinehallf8896f52015-06-25 11:11:03 +03001405 } else {
1406 return;
1407 }
1408
1409 /* Make sure that the requested I_boost is valid */
1410 if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
1411 DRM_ERROR("Invalid I_boost value %u\n", iboost);
1412 return;
1413 }
1414
1415 reg = I915_READ(DISPIO_CR_TX_BMU_CR0);
1416 reg &= ~BALANCE_LEG_MASK(port);
1417 reg &= ~(1 << (BALANCE_LEG_DISABLE_SHIFT + port));
1418
1419 if (iboost)
1420 reg |= iboost << BALANCE_LEG_SHIFT(port);
1421 else
1422 reg |= 1 << (BALANCE_LEG_DISABLE_SHIFT + port);
1423
1424 I915_WRITE(DISPIO_CR_TX_BMU_CR0, reg);
1425}
1426
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001427static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
1428 u32 level, enum port port, int type)
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301429{
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301430 const struct bxt_ddi_buf_trans *ddi_translations;
1431 u32 n_entries, i;
1432 uint32_t val;
1433
Sonika Jindald9d70002015-09-24 10:24:56 +05301434 if (type == INTEL_OUTPUT_EDP && dev_priv->edp_low_vswing) {
1435 n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
1436 ddi_translations = bxt_ddi_translations_edp;
1437 } else if (type == INTEL_OUTPUT_DISPLAYPORT
1438 || type == INTEL_OUTPUT_EDP) {
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301439 n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
1440 ddi_translations = bxt_ddi_translations_dp;
1441 } else if (type == INTEL_OUTPUT_HDMI) {
1442 n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
1443 ddi_translations = bxt_ddi_translations_hdmi;
1444 } else {
1445 DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
1446 type);
1447 return;
1448 }
1449
1450 /* Check if default value has to be used */
1451 if (level >= n_entries ||
1452 (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
1453 for (i = 0; i < n_entries; i++) {
1454 if (ddi_translations[i].default_index) {
1455 level = i;
1456 break;
1457 }
1458 }
1459 }
1460
1461 /*
1462 * While we write to the group register to program all lanes at once we
1463 * can read only lane registers and we pick lanes 0/1 for that.
1464 */
1465 val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
1466 val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
1467 I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
1468
1469 val = I915_READ(BXT_PORT_TX_DW2_LN0(port));
1470 val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
1471 val |= ddi_translations[level].margin << MARGIN_000_SHIFT |
1472 ddi_translations[level].scale << UNIQ_TRANS_SCALE_SHIFT;
1473 I915_WRITE(BXT_PORT_TX_DW2_GRP(port), val);
1474
1475 val = I915_READ(BXT_PORT_TX_DW3_LN0(port));
Sonika Jindal9c58a042015-09-24 10:22:54 +05301476 val &= ~SCALE_DCOMP_METHOD;
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301477 if (ddi_translations[level].enable)
Sonika Jindal9c58a042015-09-24 10:22:54 +05301478 val |= SCALE_DCOMP_METHOD;
1479
1480 if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
1481 DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set");
1482
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301483 I915_WRITE(BXT_PORT_TX_DW3_GRP(port), val);
1484
1485 val = I915_READ(BXT_PORT_TX_DW4_LN0(port));
1486 val &= ~DE_EMPHASIS;
1487 val |= ddi_translations[level].deemphasis << DEEMPH_SHIFT;
1488 I915_WRITE(BXT_PORT_TX_DW4_GRP(port), val);
1489
1490 val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
1491 val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
1492 I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
1493}
1494
David Weinehallf8896f52015-06-25 11:11:03 +03001495static uint32_t translate_signal_level(int signal_levels)
1496{
1497 uint32_t level;
1498
1499 switch (signal_levels) {
1500 default:
1501 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level: 0x%x\n",
1502 signal_levels);
1503 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1504 level = 0;
1505 break;
1506 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
1507 level = 1;
1508 break;
1509 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
1510 level = 2;
1511 break;
1512 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3:
1513 level = 3;
1514 break;
1515
1516 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1517 level = 4;
1518 break;
1519 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
1520 level = 5;
1521 break;
1522 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
1523 level = 6;
1524 break;
1525
1526 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1527 level = 7;
1528 break;
1529 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
1530 level = 8;
1531 break;
1532
1533 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1534 level = 9;
1535 break;
1536 }
1537
1538 return level;
1539}
1540
1541uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
1542{
1543 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001544 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
David Weinehallf8896f52015-06-25 11:11:03 +03001545 struct intel_encoder *encoder = &dport->base;
1546 uint8_t train_set = intel_dp->train_set[0];
1547 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1548 DP_TRAIN_PRE_EMPHASIS_MASK);
1549 enum port port = dport->port;
1550 uint32_t level;
1551
1552 level = translate_signal_level(signal_levels);
1553
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001554 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
1555 skl_ddi_set_iboost(dev_priv, level, port, encoder->type);
1556 else if (IS_BROXTON(dev_priv))
1557 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
David Weinehallf8896f52015-06-25 11:11:03 +03001558
1559 return DDI_BUF_TRANS_SELECT(level);
1560}
1561
Ville Syrjäläe404ba82015-08-17 18:46:20 +03001562void intel_ddi_clk_select(struct intel_encoder *encoder,
1563 const struct intel_crtc_state *pipe_config)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001564{
Ville Syrjäläe404ba82015-08-17 18:46:20 +03001565 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1566 enum port port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001567
Ville Syrjäläe404ba82015-08-17 18:46:20 +03001568 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
1569 uint32_t dpll = pipe_config->ddi_pll_sel;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001570 uint32_t val;
1571
Damien Lespiau5416d872014-11-14 17:24:33 +00001572 /* DDI -> PLL mapping */
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001573 val = I915_READ(DPLL_CTRL2);
1574
1575 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
1576 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
1577 val |= (DPLL_CTRL2_DDI_CLK_SEL(dpll, port) |
1578 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
1579
1580 I915_WRITE(DPLL_CTRL2, val);
Damien Lespiau5416d872014-11-14 17:24:33 +00001581
Ville Syrjäläe404ba82015-08-17 18:46:20 +03001582 } else if (INTEL_INFO(dev_priv)->gen < 9) {
1583 WARN_ON(pipe_config->ddi_pll_sel == PORT_CLK_SEL_NONE);
1584 I915_WRITE(PORT_CLK_SEL(port), pipe_config->ddi_pll_sel);
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001585 }
Ville Syrjäläe404ba82015-08-17 18:46:20 +03001586}
1587
1588static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
1589{
1590 struct drm_encoder *encoder = &intel_encoder->base;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +02001591 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Ville Syrjäläe404ba82015-08-17 18:46:20 +03001592 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
1593 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1594 int type = intel_encoder->type;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +02001595
1596 intel_prepare_ddi_buffer(intel_encoder);
Ville Syrjäläe404ba82015-08-17 18:46:20 +03001597
1598 if (type == INTEL_OUTPUT_EDP) {
1599 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1600 intel_edp_panel_on(intel_dp);
1601 }
1602
1603 intel_ddi_clk_select(intel_encoder, crtc->config);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001604
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001605 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001606 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001607
Ville Syrjälä901c2da2015-08-17 18:05:12 +03001608 intel_dp_set_link_params(intel_dp, crtc->config);
1609
Dave Airlie44905a22014-05-02 13:36:43 +10001610 intel_ddi_init_dp_buf_reg(intel_encoder);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001611
1612 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1613 intel_dp_start_link_train(intel_dp);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +02001614 if (port != PORT_A || INTEL_INFO(dev_priv)->gen >= 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03001615 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001616 } else if (type == INTEL_OUTPUT_HDMI) {
1617 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1618
1619 intel_hdmi->set_infoframes(encoder,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001620 crtc->config->has_hdmi_sink,
1621 &crtc->config->base.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001622 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001623}
1624
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001625static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001626{
1627 struct drm_encoder *encoder = &intel_encoder->base;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001628 struct drm_device *dev = encoder->dev;
1629 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001630 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001631 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001632 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001633 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001634
1635 val = I915_READ(DDI_BUF_CTL(port));
1636 if (val & DDI_BUF_CTL_ENABLE) {
1637 val &= ~DDI_BUF_CTL_ENABLE;
1638 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001639 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001640 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001641
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001642 val = I915_READ(DP_TP_CTL(port));
1643 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1644 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1645 I915_WRITE(DP_TP_CTL(port), val);
1646
1647 if (wait)
1648 intel_wait_ddi_buf_idle(dev_priv, port);
1649
Jani Nikula76bb80e2013-11-15 15:29:57 +02001650 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001651 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001652 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001653 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001654 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001655 }
1656
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001657 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001658 I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
1659 DPLL_CTRL2_DDI_CLK_OFF(port)));
Satheeshakrishna M1ab23382014-08-22 09:49:06 +05301660 else if (INTEL_INFO(dev)->gen < 9)
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001661 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001662}
1663
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001664static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001665{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001666 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001667 struct drm_crtc *crtc = encoder->crtc;
1668 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001669 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001670 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001671 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1672 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001673
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001674 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001675 struct intel_digital_port *intel_dig_port =
1676 enc_to_dig_port(encoder);
1677
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001678 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1679 * are ignored so nothing special needs to be done besides
1680 * enabling the port.
1681 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001682 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001683 intel_dig_port->saved_port_bits |
1684 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001685 } else if (type == INTEL_OUTPUT_EDP) {
1686 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1687
Vandana Kannan23f08d82014-11-13 14:55:22 +00001688 if (port == PORT_A && INTEL_INFO(dev)->gen < 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03001689 intel_dp_stop_link_train(intel_dp);
1690
Daniel Vetter4be73782014-01-17 14:39:48 +01001691 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08001692 intel_psr_enable(intel_dp);
Vandana Kannanc3955782015-01-22 15:17:40 +05301693 intel_edp_drrs_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001694 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001695
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001696 if (intel_crtc->config->has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001697 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Jani Nikula69bfe1a2014-10-27 16:26:50 +02001698 intel_audio_codec_enable(intel_encoder);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001699 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001700}
1701
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001702static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001703{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001704 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001705 struct drm_crtc *crtc = encoder->crtc;
1706 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001707 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001708 struct drm_device *dev = encoder->dev;
1709 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001710
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001711 if (intel_crtc->config->has_audio) {
Jani Nikula69bfe1a2014-10-27 16:26:50 +02001712 intel_audio_codec_disable(intel_encoder);
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001713 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1714 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001715
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001716 if (type == INTEL_OUTPUT_EDP) {
1717 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1718
Vandana Kannanc3955782015-01-22 15:17:40 +05301719 intel_edp_drrs_disable(intel_dp);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08001720 intel_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001721 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001722 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001723}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001724
Vandana Kannan5c6706e2014-11-24 13:37:39 +05301725static void broxton_phy_init(struct drm_i915_private *dev_priv,
1726 enum dpio_phy phy)
1727{
1728 enum port port;
1729 uint32_t val;
1730
1731 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
1732 val |= GT_DISPLAY_POWER_ON(phy);
1733 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
1734
1735 /* Considering 10ms timeout until BSpec is updated */
1736 if (wait_for(I915_READ(BXT_PORT_CL1CM_DW0(phy)) & PHY_POWER_GOOD, 10))
1737 DRM_ERROR("timeout during PHY%d power on\n", phy);
1738
1739 for (port = (phy == DPIO_PHY0 ? PORT_B : PORT_A);
1740 port <= (phy == DPIO_PHY0 ? PORT_C : PORT_A); port++) {
1741 int lane;
1742
1743 for (lane = 0; lane < 4; lane++) {
1744 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
1745 /*
1746 * Note that on CHV this flag is called UPAR, but has
1747 * the same function.
1748 */
1749 val &= ~LATENCY_OPTIM;
1750 if (lane != 1)
1751 val |= LATENCY_OPTIM;
1752
1753 I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val);
1754 }
1755 }
1756
1757 /* Program PLL Rcomp code offset */
1758 val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
1759 val &= ~IREF0RC_OFFSET_MASK;
1760 val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
1761 I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
1762
1763 val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
1764 val &= ~IREF1RC_OFFSET_MASK;
1765 val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
1766 I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
1767
1768 /* Program power gating */
1769 val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
1770 val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
1771 SUS_CLK_CONFIG;
1772 I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
1773
1774 if (phy == DPIO_PHY0) {
1775 val = I915_READ(BXT_PORT_CL2CM_DW6_BC);
1776 val |= DW6_OLDO_DYN_PWR_DOWN_EN;
1777 I915_WRITE(BXT_PORT_CL2CM_DW6_BC, val);
1778 }
1779
1780 val = I915_READ(BXT_PORT_CL1CM_DW30(phy));
1781 val &= ~OCL2_LDOFUSE_PWR_DIS;
1782 /*
1783 * On PHY1 disable power on the second channel, since no port is
1784 * connected there. On PHY0 both channels have a port, so leave it
1785 * enabled.
1786 * TODO: port C is only connected on BXT-P, so on BXT0/1 we should
1787 * power down the second channel on PHY0 as well.
1788 */
1789 if (phy == DPIO_PHY1)
1790 val |= OCL2_LDOFUSE_PWR_DIS;
1791 I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val);
1792
1793 if (phy == DPIO_PHY0) {
1794 uint32_t grc_code;
1795 /*
1796 * PHY0 isn't connected to an RCOMP resistor so copy over
1797 * the corresponding calibrated value from PHY1, and disable
1798 * the automatic calibration on PHY0.
1799 */
1800 if (wait_for(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE,
1801 10))
1802 DRM_ERROR("timeout waiting for PHY1 GRC\n");
1803
1804 val = I915_READ(BXT_PORT_REF_DW6(DPIO_PHY1));
1805 val = (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
1806 grc_code = val << GRC_CODE_FAST_SHIFT |
1807 val << GRC_CODE_SLOW_SHIFT |
1808 val;
1809 I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code);
1810
1811 val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0));
1812 val |= GRC_DIS | GRC_RDY_OVRD;
1813 I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val);
1814 }
1815
1816 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
1817 val |= COMMON_RESET_DIS;
1818 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
1819}
1820
1821void broxton_ddi_phy_init(struct drm_device *dev)
1822{
1823 /* Enable PHY1 first since it provides Rcomp for PHY0 */
1824 broxton_phy_init(dev->dev_private, DPIO_PHY1);
1825 broxton_phy_init(dev->dev_private, DPIO_PHY0);
1826}
1827
1828static void broxton_phy_uninit(struct drm_i915_private *dev_priv,
1829 enum dpio_phy phy)
1830{
1831 uint32_t val;
1832
1833 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
1834 val &= ~COMMON_RESET_DIS;
1835 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
1836}
1837
1838void broxton_ddi_phy_uninit(struct drm_device *dev)
1839{
1840 struct drm_i915_private *dev_priv = dev->dev_private;
1841
1842 broxton_phy_uninit(dev_priv, DPIO_PHY1);
1843 broxton_phy_uninit(dev_priv, DPIO_PHY0);
1844
1845 /* FIXME: do this in broxton_phy_uninit per phy */
1846 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, 0);
1847}
1848
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03001849void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
Paulo Zanonic19b0662012-10-15 15:51:41 -03001850{
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03001851 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1852 struct drm_i915_private *dev_priv =
1853 to_i915(intel_dig_port->base.base.dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02001854 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001855 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301856 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001857
1858 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1859 val = I915_READ(DDI_BUF_CTL(port));
1860 if (val & DDI_BUF_CTL_ENABLE) {
1861 val &= ~DDI_BUF_CTL_ENABLE;
1862 I915_WRITE(DDI_BUF_CTL(port), val);
1863 wait = true;
1864 }
1865
1866 val = I915_READ(DP_TP_CTL(port));
1867 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1868 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1869 I915_WRITE(DP_TP_CTL(port), val);
1870 POSTING_READ(DP_TP_CTL(port));
1871
1872 if (wait)
1873 intel_wait_ddi_buf_idle(dev_priv, port);
1874 }
1875
Dave Airlie0e32b392014-05-02 14:02:48 +10001876 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03001877 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Dave Airlie0e32b392014-05-02 14:02:48 +10001878 if (intel_dp->is_mst)
1879 val |= DP_TP_CTL_MODE_MST;
1880 else {
1881 val |= DP_TP_CTL_MODE_SST;
1882 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1883 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1884 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03001885 I915_WRITE(DP_TP_CTL(port), val);
1886 POSTING_READ(DP_TP_CTL(port));
1887
1888 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1889 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1890 POSTING_READ(DDI_BUF_CTL(port));
1891
1892 udelay(600);
1893}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001894
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001895void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1896{
1897 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1898 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1899 uint32_t val;
1900
1901 intel_ddi_post_disable(intel_encoder);
1902
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001903 val = I915_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001904 val &= ~FDI_RX_ENABLE;
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001905 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001906
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001907 val = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001908 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1909 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001910 I915_WRITE(FDI_RX_MISC(PIPE_A), val);
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001911
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001912 val = I915_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001913 val &= ~FDI_PCDCLK;
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001914 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001915
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001916 val = I915_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001917 val &= ~FDI_RX_PLL_ENABLE;
Ville Syrjäläeede3b52015-09-18 20:03:30 +03001918 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001919}
1920
Libin Yang3d52ccf2015-12-02 14:09:44 +08001921bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
1922 struct intel_crtc *intel_crtc)
1923{
1924 u32 temp;
1925
Imre Deake27daab2016-02-12 18:55:16 +02001926 if (intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
Libin Yang3d52ccf2015-12-02 14:09:44 +08001927 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
Imre Deake27daab2016-02-12 18:55:16 +02001928
1929 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1930
Libin Yang3d52ccf2015-12-02 14:09:44 +08001931 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
1932 return true;
1933 }
Imre Deake27daab2016-02-12 18:55:16 +02001934
Libin Yang3d52ccf2015-12-02 14:09:44 +08001935 return false;
1936}
1937
Ville Syrjälä6801c182013-09-24 14:24:05 +03001938void intel_ddi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001939 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001940{
1941 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1942 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +02001943 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01001944 struct intel_hdmi *intel_hdmi;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001945 u32 temp, flags = 0;
1946
Jani Nikula4d1de972016-03-18 17:05:42 +02001947 /* XXX: DSI transcoder paranoia */
1948 if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
1949 return;
1950
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001951 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1952 if (temp & TRANS_DDI_PHSYNC)
1953 flags |= DRM_MODE_FLAG_PHSYNC;
1954 else
1955 flags |= DRM_MODE_FLAG_NHSYNC;
1956 if (temp & TRANS_DDI_PVSYNC)
1957 flags |= DRM_MODE_FLAG_PVSYNC;
1958 else
1959 flags |= DRM_MODE_FLAG_NVSYNC;
1960
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001961 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001962
1963 switch (temp & TRANS_DDI_BPC_MASK) {
1964 case TRANS_DDI_BPC_6:
1965 pipe_config->pipe_bpp = 18;
1966 break;
1967 case TRANS_DDI_BPC_8:
1968 pipe_config->pipe_bpp = 24;
1969 break;
1970 case TRANS_DDI_BPC_10:
1971 pipe_config->pipe_bpp = 30;
1972 break;
1973 case TRANS_DDI_BPC_12:
1974 pipe_config->pipe_bpp = 36;
1975 break;
1976 default:
1977 break;
1978 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001979
1980 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1981 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001982 pipe_config->has_hdmi_sink = true;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01001983 intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1984
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +02001985 if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
Daniel Vetterbbd440f2014-11-20 22:33:59 +01001986 pipe_config->has_infoframe = true;
Jesse Barnescbc572a2014-11-17 13:08:47 -08001987 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001988 case TRANS_DDI_MODE_SELECT_DVI:
1989 case TRANS_DDI_MODE_SELECT_FDI:
1990 break;
1991 case TRANS_DDI_MODE_SELECT_DP_SST:
1992 case TRANS_DDI_MODE_SELECT_DP_MST:
1993 pipe_config->has_dp_encoder = true;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001994 pipe_config->lane_count =
1995 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001996 intel_dp_get_m_n(intel_crtc, pipe_config);
1997 break;
1998 default:
1999 break;
2000 }
Daniel Vetter10214422013-11-18 07:38:16 +01002001
Libin Yang3d52ccf2015-12-02 14:09:44 +08002002 pipe_config->has_audio =
2003 intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002004
Daniel Vetter10214422013-11-18 07:38:16 +01002005 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
2006 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
2007 /*
2008 * This is a big fat ugly hack.
2009 *
2010 * Some machines in UEFI boot mode provide us a VBT that has 18
2011 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2012 * unknown we fail to light up. Yet the same BIOS boots up with
2013 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2014 * max, not what it tells us to use.
2015 *
2016 * Note: This will still be broken if the eDP panel is not lit
2017 * up by the BIOS, and thus we can't get the mode at module
2018 * load.
2019 */
2020 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2021 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
2022 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
2023 }
Jesse Barnes11578552014-01-21 12:42:10 -08002024
Damien Lespiau22606a12014-12-12 14:26:57 +00002025 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002026}
2027
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002028static void intel_ddi_destroy(struct drm_encoder *encoder)
2029{
2030 /* HDMI has nothing special to destroy, so we can go with this. */
2031 intel_dp_encoder_destroy(encoder);
2032}
2033
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002034static bool intel_ddi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002035 struct intel_crtc_state *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002036{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002037 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02002038 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002039
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002040 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002041
Daniel Vettereccb1402013-05-22 00:50:22 +02002042 if (port == PORT_A)
2043 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2044
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002045 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002046 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002047 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002048 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002049}
2050
2051static const struct drm_encoder_funcs intel_ddi_funcs = {
2052 .destroy = intel_ddi_destroy,
2053};
2054
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002055static struct intel_connector *
2056intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2057{
2058 struct intel_connector *connector;
2059 enum port port = intel_dig_port->port;
2060
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002061 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002062 if (!connector)
2063 return NULL;
2064
2065 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2066 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2067 kfree(connector);
2068 return NULL;
2069 }
2070
2071 return connector;
2072}
2073
2074static struct intel_connector *
2075intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2076{
2077 struct intel_connector *connector;
2078 enum port port = intel_dig_port->port;
2079
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002080 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002081 if (!connector)
2082 return NULL;
2083
2084 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2085 intel_hdmi_init_connector(intel_dig_port, connector);
2086
2087 return connector;
2088}
2089
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002090void intel_ddi_init(struct drm_device *dev, enum port port)
2091{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002092 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002093 struct intel_digital_port *intel_dig_port;
2094 struct intel_encoder *intel_encoder;
2095 struct drm_encoder *encoder;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002096 bool init_hdmi, init_dp;
Ville Syrjälä10e7bec2015-12-08 19:59:37 +02002097 int max_lanes;
2098
2099 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
2100 switch (port) {
2101 case PORT_A:
2102 max_lanes = 4;
2103 break;
2104 case PORT_E:
2105 max_lanes = 0;
2106 break;
2107 default:
2108 max_lanes = 4;
2109 break;
2110 }
2111 } else {
2112 switch (port) {
2113 case PORT_A:
2114 max_lanes = 2;
2115 break;
2116 case PORT_E:
2117 max_lanes = 2;
2118 break;
2119 default:
2120 max_lanes = 4;
2121 break;
2122 }
2123 }
Paulo Zanoni311a2092013-09-12 17:12:18 -03002124
2125 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2126 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2127 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
2128 if (!init_dp && !init_hdmi) {
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002129 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03002130 port_name(port));
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002131 return;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002132 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002133
Daniel Vetterb14c5672013-09-19 12:18:32 +02002134 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002135 if (!intel_dig_port)
2136 return;
2137
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002138 intel_encoder = &intel_dig_port->base;
2139 encoder = &intel_encoder->base;
2140
2141 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002142 DRM_MODE_ENCODER_TMDS, NULL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002143
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002144 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002145 intel_encoder->enable = intel_enable_ddi;
2146 intel_encoder->pre_enable = intel_ddi_pre_enable;
2147 intel_encoder->disable = intel_disable_ddi;
2148 intel_encoder->post_disable = intel_ddi_post_disable;
2149 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002150 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002151
2152 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07002153 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2154 (DDI_BUF_PORT_REVERSAL |
2155 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002156
Matt Roper6c566dc2015-11-05 14:53:32 -08002157 /*
2158 * Bspec says that DDI_A_4_LANES is the only supported configuration
2159 * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
2160 * wasn't lit up at boot. Force this bit on in our internal
2161 * configuration so that we use the proper lane count for our
2162 * calculations.
2163 */
2164 if (IS_BROXTON(dev) && port == PORT_A) {
2165 if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
2166 DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
2167 intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
Matt Ropered8d60f2016-01-28 15:09:37 -08002168 max_lanes = 4;
Matt Roper6c566dc2015-11-05 14:53:32 -08002169 }
2170 }
2171
Matt Ropered8d60f2016-01-28 15:09:37 -08002172 intel_dig_port->max_lanes = max_lanes;
2173
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002174 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002175 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02002176 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002177
Chris Wilsonf68d6972014-08-04 07:15:09 +01002178 if (init_dp) {
2179 if (!intel_ddi_init_dp_connector(intel_dig_port))
2180 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10002181
Chris Wilsonf68d6972014-08-04 07:15:09 +01002182 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Sonika Jindalcf1d5882015-08-10 10:35:36 +05302183 /*
2184 * On BXT A0/A1, sw needs to activate DDIA HPD logic and
2185 * interrupts to check the external panel connection.
2186 */
Jani Nikulae87a0052015-10-20 15:22:02 +03002187 if (IS_BXT_REVID(dev, 0, BXT_REVID_A1) && port == PORT_B)
Sonika Jindalcf1d5882015-08-10 10:35:36 +05302188 dev_priv->hotplug.irq_port[PORT_A] = intel_dig_port;
2189 else
2190 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002191 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002192
Paulo Zanoni311a2092013-09-12 17:12:18 -03002193 /* In theory we don't need the encoder->type check, but leave it just in
2194 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01002195 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2196 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2197 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002198 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01002199
2200 return;
2201
2202err:
2203 drm_encoder_cleanup(encoder);
2204 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002205}