blob: d957211c76ad71d2b3784136b1a4a90377f823d8 [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 },
Ville Syrjälä5ac90562016-08-02 15:21:57 +0300148 { 0x80007011, 0x000000CD, 0x1 },
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 },
Ville Syrjälä5ac90562016-08-02 15:21:57 +0300161 { 0x80007011, 0x000000CD, 0x3 },
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
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700170/* Kabylake H and S */
171static const struct ddi_buf_trans kbl_ddi_translations_dp[] = {
172 { 0x00002016, 0x000000A0, 0x0 },
173 { 0x00005012, 0x0000009B, 0x0 },
174 { 0x00007011, 0x00000088, 0x0 },
175 { 0x80009010, 0x000000C0, 0x1 },
176 { 0x00002016, 0x0000009B, 0x0 },
177 { 0x00005012, 0x00000088, 0x0 },
178 { 0x80007011, 0x000000C0, 0x1 },
179 { 0x00002016, 0x00000097, 0x0 },
180 { 0x80005012, 0x000000C0, 0x1 },
181};
182
183/* Kabylake U */
184static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = {
185 { 0x0000201B, 0x000000A1, 0x0 },
186 { 0x00005012, 0x00000088, 0x0 },
187 { 0x80007011, 0x000000CD, 0x3 },
188 { 0x80009010, 0x000000C0, 0x3 },
189 { 0x0000201B, 0x0000009D, 0x0 },
190 { 0x80005012, 0x000000C0, 0x3 },
191 { 0x80007011, 0x000000C0, 0x3 },
192 { 0x00002016, 0x0000004F, 0x0 },
193 { 0x80005012, 0x000000C0, 0x3 },
194};
195
196/* Kabylake Y */
197static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = {
198 { 0x00001017, 0x000000A1, 0x0 },
199 { 0x00005012, 0x00000088, 0x0 },
200 { 0x80007011, 0x000000CD, 0x3 },
201 { 0x8000800F, 0x000000C0, 0x3 },
202 { 0x00001017, 0x0000009D, 0x0 },
203 { 0x80005012, 0x000000C0, 0x3 },
204 { 0x80007011, 0x000000C0, 0x3 },
205 { 0x00001017, 0x0000004C, 0x0 },
206 { 0x80005012, 0x000000C0, 0x3 },
207};
208
David Weinehallf8896f52015-06-25 11:11:03 +0300209/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700210 * Skylake/Kabylake H and S
David Weinehallf8896f52015-06-25 11:11:03 +0300211 * eDP 1.4 low vswing translation parameters
212 */
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530213static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300214 { 0x00000018, 0x000000A8, 0x0 },
215 { 0x00004013, 0x000000A9, 0x0 },
216 { 0x00007011, 0x000000A2, 0x0 },
217 { 0x00009010, 0x0000009C, 0x0 },
218 { 0x00000018, 0x000000A9, 0x0 },
219 { 0x00006013, 0x000000A2, 0x0 },
220 { 0x00007011, 0x000000A6, 0x0 },
221 { 0x00000018, 0x000000AB, 0x0 },
222 { 0x00007013, 0x0000009F, 0x0 },
223 { 0x00000018, 0x000000DF, 0x0 },
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530224};
225
David Weinehallf8896f52015-06-25 11:11:03 +0300226/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700227 * Skylake/Kabylake U
David Weinehallf8896f52015-06-25 11:11:03 +0300228 * eDP 1.4 low vswing translation parameters
229 */
230static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
231 { 0x00000018, 0x000000A8, 0x0 },
232 { 0x00004013, 0x000000A9, 0x0 },
233 { 0x00007011, 0x000000A2, 0x0 },
234 { 0x00009010, 0x0000009C, 0x0 },
235 { 0x00000018, 0x000000A9, 0x0 },
236 { 0x00006013, 0x000000A2, 0x0 },
237 { 0x00007011, 0x000000A6, 0x0 },
238 { 0x00002016, 0x000000AB, 0x0 },
239 { 0x00005013, 0x0000009F, 0x0 },
240 { 0x00000018, 0x000000DF, 0x0 },
241};
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530242
David Weinehallf8896f52015-06-25 11:11:03 +0300243/*
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700244 * Skylake/Kabylake Y
David Weinehallf8896f52015-06-25 11:11:03 +0300245 * eDP 1.4 low vswing translation parameters
246 */
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700247static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300248 { 0x00000018, 0x000000A8, 0x0 },
249 { 0x00004013, 0x000000AB, 0x0 },
250 { 0x00007011, 0x000000A4, 0x0 },
251 { 0x00009010, 0x000000DF, 0x0 },
252 { 0x00000018, 0x000000AA, 0x0 },
253 { 0x00006013, 0x000000A4, 0x0 },
254 { 0x00007011, 0x0000009D, 0x0 },
255 { 0x00000018, 0x000000A0, 0x0 },
256 { 0x00006012, 0x000000DF, 0x0 },
257 { 0x00000018, 0x0000008A, 0x0 },
258};
259
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700260/* Skylake/Kabylake U, H and S */
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000261static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300262 { 0x00000018, 0x000000AC, 0x0 },
263 { 0x00005012, 0x0000009D, 0x0 },
264 { 0x00007011, 0x00000088, 0x0 },
265 { 0x00000018, 0x000000A1, 0x0 },
266 { 0x00000018, 0x00000098, 0x0 },
267 { 0x00004013, 0x00000088, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800268 { 0x80006012, 0x000000CD, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300269 { 0x00000018, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800270 { 0x80003015, 0x000000CD, 0x1 }, /* Default */
271 { 0x80003015, 0x000000C0, 0x1 },
272 { 0x80000018, 0x000000C0, 0x1 },
David Weinehallf8896f52015-06-25 11:11:03 +0300273};
274
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700275/* Skylake/Kabylake Y */
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700276static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
David Weinehallf8896f52015-06-25 11:11:03 +0300277 { 0x00000018, 0x000000A1, 0x0 },
278 { 0x00005012, 0x000000DF, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800279 { 0x80007011, 0x000000CB, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300280 { 0x00000018, 0x000000A4, 0x0 },
281 { 0x00000018, 0x0000009D, 0x0 },
282 { 0x00004013, 0x00000080, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800283 { 0x80006013, 0x000000C0, 0x3 },
David Weinehallf8896f52015-06-25 11:11:03 +0300284 { 0x00000018, 0x0000008A, 0x0 },
Rodrigo Vivi2e784162016-01-05 11:11:27 -0800285 { 0x80003015, 0x000000C0, 0x3 }, /* Default */
286 { 0x80003015, 0x000000C0, 0x3 },
287 { 0x80000018, 0x000000C0, 0x3 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000288};
289
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530290struct bxt_ddi_buf_trans {
291 u32 margin; /* swing value */
292 u32 scale; /* scale value */
293 u32 enable; /* scale enable */
294 u32 deemphasis;
295 bool default_index; /* true if the entry represents default value */
296};
297
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530298static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
299 /* Idx NT mV diff db */
Imre Deakfe4c63c2015-06-04 18:01:35 +0300300 { 52, 0x9A, 0, 128, true }, /* 0: 400 0 */
301 { 78, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
302 { 104, 0x9A, 0, 64, false }, /* 2: 400 6 */
303 { 154, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
304 { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
305 { 116, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
306 { 154, 0x9A, 0, 64, false }, /* 6: 600 6 */
307 { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
308 { 154, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
David Weinehallf8896f52015-06-25 11:11:03 +0300309 { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530310};
311
Sonika Jindald9d70002015-09-24 10:24:56 +0530312static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
313 /* Idx NT mV diff db */
314 { 26, 0, 0, 128, false }, /* 0: 200 0 */
315 { 38, 0, 0, 112, false }, /* 1: 200 1.5 */
316 { 48, 0, 0, 96, false }, /* 2: 200 4 */
317 { 54, 0, 0, 69, false }, /* 3: 200 6 */
318 { 32, 0, 0, 128, false }, /* 4: 250 0 */
319 { 48, 0, 0, 104, false }, /* 5: 250 1.5 */
320 { 54, 0, 0, 85, false }, /* 6: 250 4 */
321 { 43, 0, 0, 128, false }, /* 7: 300 0 */
322 { 54, 0, 0, 101, false }, /* 8: 300 1.5 */
323 { 48, 0, 0, 128, false }, /* 9: 300 0 */
324};
325
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530326/* BSpec has 2 recommended values - entries 0 and 8.
327 * Using the entry with higher vswing.
328 */
329static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
330 /* Idx NT mV diff db */
Imre Deakfe4c63c2015-06-04 18:01:35 +0300331 { 52, 0x9A, 0, 128, false }, /* 0: 400 0 */
332 { 52, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
333 { 52, 0x9A, 0, 64, false }, /* 2: 400 6 */
334 { 42, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
335 { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
336 { 77, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
337 { 77, 0x9A, 0, 64, false }, /* 6: 600 6 */
338 { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
339 { 102, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530340 { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
341};
342
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300343enum port intel_ddi_get_encoder_port(struct intel_encoder *encoder)
Paulo Zanonifc914632012-10-05 12:05:54 -0300344{
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300345 switch (encoder->type) {
Jani Nikula8cd21b72015-09-29 10:24:26 +0300346 case INTEL_OUTPUT_DP_MST:
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300347 return enc_to_mst(&encoder->base)->primary->port;
Ville Syrjäläcca05022016-06-22 21:57:06 +0300348 case INTEL_OUTPUT_DP:
Jani Nikula8cd21b72015-09-29 10:24:26 +0300349 case INTEL_OUTPUT_EDP:
350 case INTEL_OUTPUT_HDMI:
351 case INTEL_OUTPUT_UNKNOWN:
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300352 return enc_to_dig_port(&encoder->base)->port;
Jani Nikula8cd21b72015-09-29 10:24:26 +0300353 case INTEL_OUTPUT_ANALOG:
Ville Syrjälä5a5d24d2016-07-12 15:59:35 +0300354 return PORT_E;
355 default:
356 MISSING_CASE(encoder->type);
357 return PORT_A;
Paulo Zanonifc914632012-10-05 12:05:54 -0300358 }
359}
360
Ville Syrjäläacee2992015-12-08 19:59:39 +0200361static const struct ddi_buf_trans *
Ville Syrjäläa930acd2016-07-12 15:59:36 +0300362bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
363{
364 if (dev_priv->vbt.edp.low_vswing) {
365 *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
366 return bdw_ddi_translations_edp;
367 } else {
368 *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
369 return bdw_ddi_translations_dp;
370 }
371}
372
373static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200374skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300375{
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700376 if (IS_SKL_ULX(dev_priv)) {
Rodrigo Vivi5f8b2532015-08-24 16:48:44 -0700377 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200378 return skl_y_ddi_translations_dp;
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700379 } else if (IS_SKL_ULT(dev_priv)) {
David Weinehallf8896f52015-06-25 11:11:03 +0300380 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200381 return skl_u_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300382 } else {
David Weinehallf8896f52015-06-25 11:11:03 +0300383 *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200384 return skl_ddi_translations_dp;
David Weinehallf8896f52015-06-25 11:11:03 +0300385 }
David Weinehallf8896f52015-06-25 11:11:03 +0300386}
387
388static const struct ddi_buf_trans *
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700389kbl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
390{
391 if (IS_KBL_ULX(dev_priv)) {
392 *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp);
393 return kbl_y_ddi_translations_dp;
394 } else if (IS_KBL_ULT(dev_priv)) {
395 *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
396 return kbl_u_ddi_translations_dp;
397 } else {
398 *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
399 return kbl_ddi_translations_dp;
400 }
401}
402
403static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200404skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
David Weinehallf8896f52015-06-25 11:11:03 +0300405{
Jani Nikula06411f02016-03-24 17:50:21 +0200406 if (dev_priv->vbt.edp.low_vswing) {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200407 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200408 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
409 return skl_y_ddi_translations_edp;
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200410 } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200411 *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
412 return skl_u_ddi_translations_edp;
413 } else {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200414 *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
415 return skl_ddi_translations_edp;
Ville Syrjäläacee2992015-12-08 19:59:39 +0200416 }
David Weinehallf8896f52015-06-25 11:11:03 +0300417 }
Ville Syrjäläcd1101c2015-12-08 19:59:40 +0200418
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700419 if (IS_KABYLAKE(dev_priv))
420 return kbl_get_buf_trans_dp(dev_priv, n_entries);
421 else
422 return skl_get_buf_trans_dp(dev_priv, n_entries);
Ville Syrjäläacee2992015-12-08 19:59:39 +0200423}
David Weinehallf8896f52015-06-25 11:11:03 +0300424
Ville Syrjäläacee2992015-12-08 19:59:39 +0200425static const struct ddi_buf_trans *
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200426skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
Ville Syrjäläacee2992015-12-08 19:59:39 +0200427{
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200428 if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
Ville Syrjäläacee2992015-12-08 19:59:39 +0200429 *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
430 return skl_y_ddi_translations_hdmi;
431 } else {
432 *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
433 return skl_ddi_translations_hdmi;
434 }
David Weinehallf8896f52015-06-25 11:11:03 +0300435}
436
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300437static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
438{
439 int n_hdmi_entries;
440 int hdmi_level;
441 int hdmi_default_entry;
442
443 hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
444
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200445 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300446 return hdmi_level;
447
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800448 if (IS_GEN9_BC(dev_priv)) {
Ville Syrjälä8d8bb852016-07-12 15:59:30 +0300449 skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
450 hdmi_default_entry = 8;
451 } else if (IS_BROADWELL(dev_priv)) {
452 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
453 hdmi_default_entry = 7;
454 } else if (IS_HASWELL(dev_priv)) {
455 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
456 hdmi_default_entry = 6;
457 } else {
458 WARN(1, "ddi translation table missing\n");
459 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
460 hdmi_default_entry = 7;
461 }
462
463 /* Choose a good default if VBT is badly populated */
464 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
465 hdmi_level >= n_hdmi_entries)
466 hdmi_level = hdmi_default_entry;
467
468 return hdmi_level;
469}
470
Art Runyane58623c2013-11-02 21:07:41 -0700471/*
472 * Starting with Haswell, DDI port buffers must be programmed with correct
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300473 * values in advance. This function programs the correct values for
474 * DP/eDP/FDI use cases.
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300475 */
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300476void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300477{
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200478 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300479 u32 iboost_bit = 0;
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300480 int i, n_dp_entries, n_edp_entries, size;
481 enum port port = intel_ddi_get_encoder_port(encoder);
Jani Nikula10122052014-08-27 16:27:30 +0300482 const struct ddi_buf_trans *ddi_translations_fdi;
483 const struct ddi_buf_trans *ddi_translations_dp;
484 const struct ddi_buf_trans *ddi_translations_edp;
Jani Nikula10122052014-08-27 16:27:30 +0300485 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700486
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200487 if (IS_GEN9_LP(dev_priv))
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530488 return;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200489
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -0700490 if (IS_KABYLAKE(dev_priv)) {
491 ddi_translations_fdi = NULL;
492 ddi_translations_dp =
493 kbl_get_buf_trans_dp(dev_priv, &n_dp_entries);
494 ddi_translations_edp =
495 skl_get_buf_trans_edp(dev_priv, &n_edp_entries);
496 } else if (IS_SKYLAKE(dev_priv)) {
Paulo Zanonic30400f2015-07-03 12:31:30 -0300497 ddi_translations_fdi = NULL;
David Weinehallf8896f52015-06-25 11:11:03 +0300498 ddi_translations_dp =
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200499 skl_get_buf_trans_dp(dev_priv, &n_dp_entries);
David Weinehallf8896f52015-06-25 11:11:03 +0300500 ddi_translations_edp =
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200501 skl_get_buf_trans_edp(dev_priv, &n_edp_entries);
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200502 } else if (IS_BROADWELL(dev_priv)) {
Art Runyane58623c2013-11-02 21:07:41 -0700503 ddi_translations_fdi = bdw_ddi_translations_fdi;
504 ddi_translations_dp = bdw_ddi_translations_dp;
Ville Syrjäläa930acd2016-07-12 15:59:36 +0300505 ddi_translations_edp = bdw_get_buf_trans_edp(dev_priv, &n_edp_entries);
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530506 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +0200507 } else if (IS_HASWELL(dev_priv)) {
Art Runyane58623c2013-11-02 21:07:41 -0700508 ddi_translations_fdi = hsw_ddi_translations_fdi;
509 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700510 ddi_translations_edp = hsw_ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530511 n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
Art Runyane58623c2013-11-02 21:07:41 -0700512 } else {
513 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700514 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700515 ddi_translations_fdi = bdw_ddi_translations_fdi;
516 ddi_translations_dp = bdw_ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530517 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
518 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Art Runyane58623c2013-11-02 21:07:41 -0700519 }
520
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800521 if (IS_GEN9_BC(dev_priv)) {
Rodrigo Vivi0a918772016-09-30 11:05:56 -0700522 /* If we're boosting the current, set bit 31 of trans1 */
523 if (dev_priv->vbt.ddi_port_info[port].dp_boost_level)
524 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
525
526 if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
527 port != PORT_A && port != PORT_E &&
528 n_edp_entries > 9))
529 n_edp_entries = 9;
530 }
531
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200532 switch (encoder->type) {
533 case INTEL_OUTPUT_EDP:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700534 ddi_translations = ddi_translations_edp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530535 size = n_edp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700536 break;
Ville Syrjäläcca05022016-06-22 21:57:06 +0300537 case INTEL_OUTPUT_DP:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700538 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530539 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700540 break;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200541 case INTEL_OUTPUT_ANALOG:
542 ddi_translations = ddi_translations_fdi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530543 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700544 break;
545 default:
546 BUG();
547 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300548
Ville Syrjälä9712e682015-09-18 20:03:22 +0300549 for (i = 0; i < size; i++) {
550 I915_WRITE(DDI_BUF_TRANS_LO(port, i),
551 ddi_translations[i].trans1 | iboost_bit);
552 I915_WRITE(DDI_BUF_TRANS_HI(port, i),
553 ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300554 }
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300555}
Damien Lespiauce4dd492014-08-01 11:07:54 +0100556
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300557/*
558 * Starting with Haswell, DDI port buffers must be programmed with correct
559 * values in advance. This function programs the correct values for
560 * HDMI/DVI use cases.
561 */
562static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder)
563{
564 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
565 u32 iboost_bit = 0;
566 int n_hdmi_entries, hdmi_level;
567 enum port port = intel_ddi_get_encoder_port(encoder);
568 const struct ddi_buf_trans *ddi_translations_hdmi;
569
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200570 if (IS_GEN9_LP(dev_priv))
Damien Lespiauce3b7e92014-08-04 15:04:43 +0100571 return;
572
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300573 hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
574
Rodrigo Vivib976dc52017-01-23 10:32:37 -0800575 if (IS_GEN9_BC(dev_priv)) {
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300576 ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
Ville Syrjälä1edaaa22016-07-12 15:59:34 +0300577
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300578 /* If we're boosting the current, set bit 31 of trans1 */
Ville Syrjälä1edaaa22016-07-12 15:59:34 +0300579 if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300580 iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
581 } else if (IS_BROADWELL(dev_priv)) {
582 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
583 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
584 } else if (IS_HASWELL(dev_priv)) {
585 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
586 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
587 } else {
588 WARN(1, "ddi translation table missing\n");
589 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
590 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
591 }
592
Paulo Zanoni6acab152013-09-12 17:06:24 -0300593 /* Entry 9 is for HDMI: */
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300594 I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
Ville Syrjälä9712e682015-09-18 20:03:22 +0300595 ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
Ville Syrjäläed9c77d2016-07-12 15:59:32 +0300596 I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
Ville Syrjälä9712e682015-09-18 20:03:22 +0300597 ddi_translations_hdmi[hdmi_level].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300598}
599
Paulo Zanoni248138b2012-11-29 11:29:31 -0200600static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
601 enum port port)
602{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200603 i915_reg_t reg = DDI_BUF_CTL(port);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200604 int i;
605
Vandana Kannan3449ca82015-03-27 14:19:09 +0200606 for (i = 0; i < 16; i++) {
Paulo Zanoni248138b2012-11-29 11:29:31 -0200607 udelay(1);
608 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
609 return;
610 }
611 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
612}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300613
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700614static uint32_t hsw_pll_to_ddi_pll_sel(struct intel_shared_dpll *pll)
615{
616 switch (pll->id) {
617 case DPLL_ID_WRPLL1:
618 return PORT_CLK_SEL_WRPLL1;
619 case DPLL_ID_WRPLL2:
620 return PORT_CLK_SEL_WRPLL2;
621 case DPLL_ID_SPLL:
622 return PORT_CLK_SEL_SPLL;
623 case DPLL_ID_LCPLL_810:
624 return PORT_CLK_SEL_LCPLL_810;
625 case DPLL_ID_LCPLL_1350:
626 return PORT_CLK_SEL_LCPLL_1350;
627 case DPLL_ID_LCPLL_2700:
628 return PORT_CLK_SEL_LCPLL_2700;
629 default:
630 MISSING_CASE(pll->id);
631 return PORT_CLK_SEL_NONE;
632 }
633}
634
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300635/* Starting with Haswell, different DDI ports can work in FDI mode for
636 * connection to the PCH-located connectors. For this, it is necessary to train
637 * both the DDI port and PCH receiver for the desired DDI buffer settings.
638 *
639 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
640 * please note that when FDI mode is active on DDI E, it shares 2 lines with
641 * DDI A (which is used for eDP)
642 */
643
644void hsw_fdi_link_train(struct drm_crtc *crtc)
645{
646 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100647 struct drm_i915_private *dev_priv = to_i915(dev);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300648 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200649 struct intel_encoder *encoder;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700650 u32 temp, i, rx_ctl_val, ddi_pll_sel;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300651
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200652 for_each_encoder_on_crtc(dev, crtc, encoder) {
653 WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
Ville Syrjälä32bdc402016-07-12 15:59:33 +0300654 intel_prepare_dp_ddi_buffers(encoder);
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +0200655 }
656
Paulo Zanoni04945642012-11-01 21:00:59 -0200657 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
658 * mode set "sequence for CRT port" document:
659 * - TP1 to TP2 time with the default value
660 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100661 *
662 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200663 */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300664 I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200665 FDI_RX_PWRDN_LANE0_VAL(2) |
666 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
667
668 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000669 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100670 FDI_RX_PLL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200671 FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300672 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
673 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200674 udelay(220);
675
676 /* Switch from Rawclk to PCDclk */
677 rx_ctl_val |= FDI_PCDCLK;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300678 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
Paulo Zanoni04945642012-11-01 21:00:59 -0200679
680 /* Configure Port Clock Select */
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700681 ddi_pll_sel = hsw_pll_to_ddi_pll_sel(intel_crtc->config->shared_dpll);
682 I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
683 WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200684
685 /* Start the training iterating through available voltages and emphasis,
686 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300687 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300688 /* Configure DP_TP_CTL with auto-training */
689 I915_WRITE(DP_TP_CTL(PORT_E),
690 DP_TP_CTL_FDI_AUTOTRAIN |
691 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
692 DP_TP_CTL_LINK_TRAIN_PAT1 |
693 DP_TP_CTL_ENABLE);
694
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000695 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
696 * DDI E does not support port reversal, the functionality is
697 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
698 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300699 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200700 DDI_BUF_CTL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200701 ((intel_crtc->config->fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530702 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200703 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300704
705 udelay(600);
706
Paulo Zanoni04945642012-11-01 21:00:59 -0200707 /* Program PCH FDI Receiver TU */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300708 I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300709
Paulo Zanoni04945642012-11-01 21:00:59 -0200710 /* Enable PCH FDI Receiver with auto-training */
711 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300712 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
713 POSTING_READ(FDI_RX_CTL(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200714
715 /* Wait for FDI receiver lane calibration */
716 udelay(30);
717
718 /* Unset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300719 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200720 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300721 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
722 POSTING_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200723
724 /* Wait for FDI auto training time */
725 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300726
727 temp = I915_READ(DP_TP_STATUS(PORT_E));
728 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200729 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200730 break;
731 }
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300732
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200733 /*
734 * Leave things enabled even if we failed to train FDI.
735 * Results in less fireworks from the state checker.
736 */
737 if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
738 DRM_ERROR("FDI link training failed!\n");
739 break;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300740 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200741
Ville Syrjälä5b421c52016-03-01 16:16:23 +0200742 rx_ctl_val &= ~FDI_RX_ENABLE;
743 I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
744 POSTING_READ(FDI_RX_CTL(PIPE_A));
745
Paulo Zanoni248138b2012-11-29 11:29:31 -0200746 temp = I915_READ(DDI_BUF_CTL(PORT_E));
747 temp &= ~DDI_BUF_CTL_ENABLE;
748 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
749 POSTING_READ(DDI_BUF_CTL(PORT_E));
750
Paulo Zanoni04945642012-11-01 21:00:59 -0200751 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200752 temp = I915_READ(DP_TP_CTL(PORT_E));
753 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
754 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
755 I915_WRITE(DP_TP_CTL(PORT_E), temp);
756 POSTING_READ(DP_TP_CTL(PORT_E));
757
758 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200759
Paulo Zanoni04945642012-11-01 21:00:59 -0200760 /* Reset FDI_RX_MISC pwrdn lanes */
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300761 temp = I915_READ(FDI_RX_MISC(PIPE_A));
Paulo Zanoni04945642012-11-01 21:00:59 -0200762 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
763 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
Ville Syrjäläeede3b52015-09-18 20:03:30 +0300764 I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
765 POSTING_READ(FDI_RX_MISC(PIPE_A));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300766 }
767
Ville Syrjäläa308ccb2015-12-04 22:22:50 +0200768 /* Enable normal pixel sending for FDI */
769 I915_WRITE(DP_TP_CTL(PORT_E),
770 DP_TP_CTL_FDI_AUTOTRAIN |
771 DP_TP_CTL_LINK_TRAIN_NORMAL |
772 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
773 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300774}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300775
Dave Airlie44905a272014-05-02 13:36:43 +1000776void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
777{
778 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
779 struct intel_digital_port *intel_dig_port =
780 enc_to_dig_port(&encoder->base);
781
782 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530783 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Ville Syrjälä901c2da2015-08-17 18:05:12 +0300784 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Dave Airlie44905a272014-05-02 13:36:43 +1000785}
786
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300787static struct intel_encoder *
788intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
789{
790 struct drm_device *dev = crtc->dev;
791 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
792 struct intel_encoder *intel_encoder, *ret = NULL;
793 int num_encoders = 0;
794
795 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
796 ret = intel_encoder;
797 num_encoders++;
798 }
799
800 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300801 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
802 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300803
804 BUG_ON(ret == NULL);
805 return ret;
806}
807
Satheeshakrishna Mbcddf612014-08-22 09:49:10 +0530808struct intel_encoder *
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200809intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200810{
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200811 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
812 struct intel_encoder *ret = NULL;
813 struct drm_atomic_state *state;
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300814 struct drm_connector *connector;
815 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200816 int num_encoders = 0;
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200817 int i;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200818
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200819 state = crtc_state->base.state;
820
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300821 for_each_connector_in_state(state, connector, connector_state, i) {
822 if (connector_state->crtc != crtc_state->base.crtc)
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200823 continue;
824
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300825 ret = to_intel_encoder(connector_state->best_encoder);
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200826 num_encoders++;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200827 }
828
829 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
830 pipe_name(crtc->pipe));
831
832 BUG_ON(ret == NULL);
833 return ret;
834}
835
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100836#define LC_FREQ 2700
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100837
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200838static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
839 i915_reg_t reg)
Jesse Barnes11578552014-01-21 12:42:10 -0800840{
841 int refclk = LC_FREQ;
842 int n, p, r;
843 u32 wrpll;
844
845 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300846 switch (wrpll & WRPLL_PLL_REF_MASK) {
847 case WRPLL_PLL_SSC:
848 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800849 /*
850 * We could calculate spread here, but our checking
851 * code only cares about 5% accuracy, and spread is a max of
852 * 0.5% downspread.
853 */
854 refclk = 135;
855 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300856 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800857 refclk = LC_FREQ;
858 break;
859 default:
860 WARN(1, "bad wrpll refclk\n");
861 return 0;
862 }
863
864 r = wrpll & WRPLL_DIVIDER_REF_MASK;
865 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
866 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
867
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800868 /* Convert to KHz, p & r have a fixed point portion */
869 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800870}
871
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000872static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
873 uint32_t dpll)
874{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200875 i915_reg_t cfgcr1_reg, cfgcr2_reg;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000876 uint32_t cfgcr1_val, cfgcr2_val;
877 uint32_t p0, p1, p2, dco_freq;
878
Ville Syrjälä923c12412015-09-30 17:06:43 +0300879 cfgcr1_reg = DPLL_CFGCR1(dpll);
880 cfgcr2_reg = DPLL_CFGCR2(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000881
882 cfgcr1_val = I915_READ(cfgcr1_reg);
883 cfgcr2_val = I915_READ(cfgcr2_reg);
884
885 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
886 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
887
888 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
889 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
890 else
891 p1 = 1;
892
893
894 switch (p0) {
895 case DPLL_CFGCR2_PDIV_1:
896 p0 = 1;
897 break;
898 case DPLL_CFGCR2_PDIV_2:
899 p0 = 2;
900 break;
901 case DPLL_CFGCR2_PDIV_3:
902 p0 = 3;
903 break;
904 case DPLL_CFGCR2_PDIV_7:
905 p0 = 7;
906 break;
907 }
908
909 switch (p2) {
910 case DPLL_CFGCR2_KDIV_5:
911 p2 = 5;
912 break;
913 case DPLL_CFGCR2_KDIV_2:
914 p2 = 2;
915 break;
916 case DPLL_CFGCR2_KDIV_3:
917 p2 = 3;
918 break;
919 case DPLL_CFGCR2_KDIV_1:
920 p2 = 1;
921 break;
922 }
923
924 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
925
926 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
927 1000) / 0x8000;
928
929 return dco_freq / (p0 * p1 * p2 * 5);
930}
931
Ville Syrjälä398a0172015-06-30 15:33:51 +0300932static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
933{
934 int dotclock;
935
936 if (pipe_config->has_pch_encoder)
937 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
938 &pipe_config->fdi_m_n);
Ville Syrjälä37a56502016-06-22 21:57:04 +0300939 else if (intel_crtc_has_dp_encoder(pipe_config))
Ville Syrjälä398a0172015-06-30 15:33:51 +0300940 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
941 &pipe_config->dp_m_n);
942 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
943 dotclock = pipe_config->port_clock * 2 / 3;
944 else
945 dotclock = pipe_config->port_clock;
946
947 if (pipe_config->pixel_multiplier)
948 dotclock /= pipe_config->pixel_multiplier;
949
950 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
951}
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000952
953static void skl_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200954 struct intel_crtc_state *pipe_config)
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000955{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100956 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000957 int link_clock = 0;
958 uint32_t dpll_ctl1, dpll;
959
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -0700960 dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000961
962 dpll_ctl1 = I915_READ(DPLL_CTRL1);
963
964 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
965 link_clock = skl_calc_wrpll_link(dev_priv, dpll);
966 } else {
Damien Lespiau71cd8422015-04-30 16:39:17 +0100967 link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
968 link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000969
970 switch (link_clock) {
Damien Lespiau71cd8422015-04-30 16:39:17 +0100971 case DPLL_CTRL1_LINK_RATE_810:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000972 link_clock = 81000;
973 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100974 case DPLL_CTRL1_LINK_RATE_1080:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530975 link_clock = 108000;
976 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100977 case DPLL_CTRL1_LINK_RATE_1350:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000978 link_clock = 135000;
979 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100980 case DPLL_CTRL1_LINK_RATE_1620:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530981 link_clock = 162000;
982 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100983 case DPLL_CTRL1_LINK_RATE_2160:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530984 link_clock = 216000;
985 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100986 case DPLL_CTRL1_LINK_RATE_2700:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000987 link_clock = 270000;
988 break;
989 default:
990 WARN(1, "Unsupported link rate\n");
991 break;
992 }
993 link_clock *= 2;
994 }
995
996 pipe_config->port_clock = link_clock;
997
Ville Syrjälä398a0172015-06-30 15:33:51 +0300998 ddi_dotclock_get(pipe_config);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000999}
1000
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001001static void hsw_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001002 struct intel_crtc_state *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -08001003{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001004 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes11578552014-01-21 12:42:10 -08001005 int link_clock = 0;
1006 u32 val, pll;
1007
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001008 val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
Jesse Barnes11578552014-01-21 12:42:10 -08001009 switch (val & PORT_CLK_SEL_MASK) {
1010 case PORT_CLK_SEL_LCPLL_810:
1011 link_clock = 81000;
1012 break;
1013 case PORT_CLK_SEL_LCPLL_1350:
1014 link_clock = 135000;
1015 break;
1016 case PORT_CLK_SEL_LCPLL_2700:
1017 link_clock = 270000;
1018 break;
1019 case PORT_CLK_SEL_WRPLL1:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001020 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
Jesse Barnes11578552014-01-21 12:42:10 -08001021 break;
1022 case PORT_CLK_SEL_WRPLL2:
Ville Syrjälä01403de2015-09-18 20:03:33 +03001023 link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
Jesse Barnes11578552014-01-21 12:42:10 -08001024 break;
1025 case PORT_CLK_SEL_SPLL:
1026 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
1027 if (pll == SPLL_PLL_FREQ_810MHz)
1028 link_clock = 81000;
1029 else if (pll == SPLL_PLL_FREQ_1350MHz)
1030 link_clock = 135000;
1031 else if (pll == SPLL_PLL_FREQ_2700MHz)
1032 link_clock = 270000;
1033 else {
1034 WARN(1, "bad spll freq\n");
1035 return;
1036 }
1037 break;
1038 default:
1039 WARN(1, "bad port clock sel\n");
1040 return;
1041 }
1042
1043 pipe_config->port_clock = link_clock * 2;
1044
Ville Syrjälä398a0172015-06-30 15:33:51 +03001045 ddi_dotclock_get(pipe_config);
Jesse Barnes11578552014-01-21 12:42:10 -08001046}
1047
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301048static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
1049 enum intel_dpll_id dpll)
1050{
Imre Deakaa610dc2015-06-22 23:35:52 +03001051 struct intel_shared_dpll *pll;
1052 struct intel_dpll_hw_state *state;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03001053 struct dpll clock;
Imre Deakaa610dc2015-06-22 23:35:52 +03001054
1055 /* For DDI ports we always use a shared PLL. */
1056 if (WARN_ON(dpll == DPLL_ID_PRIVATE))
1057 return 0;
1058
1059 pll = &dev_priv->shared_dplls[dpll];
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02001060 state = &pll->state.hw_state;
Imre Deakaa610dc2015-06-22 23:35:52 +03001061
1062 clock.m1 = 2;
1063 clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
1064 if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
1065 clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
1066 clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
1067 clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
1068 clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
1069
1070 return chv_calc_dpll_params(100000, &clock);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301071}
1072
1073static void bxt_ddi_clock_get(struct intel_encoder *encoder,
1074 struct intel_crtc_state *pipe_config)
1075{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001076 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301077 enum port port = intel_ddi_get_encoder_port(encoder);
1078 uint32_t dpll = port;
1079
Ville Syrjälä398a0172015-06-30 15:33:51 +03001080 pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301081
Ville Syrjälä398a0172015-06-30 15:33:51 +03001082 ddi_dotclock_get(pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301083}
1084
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001085void intel_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001086 struct intel_crtc_state *pipe_config)
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001087{
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001088 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Damien Lespiau22606a12014-12-12 14:26:57 +00001089
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001090 if (INTEL_GEN(dev_priv) <= 8)
Damien Lespiau22606a12014-12-12 14:26:57 +00001091 hsw_ddi_clock_get(encoder, pipe_config);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001092 else if (IS_GEN9_BC(dev_priv))
Damien Lespiau22606a12014-12-12 14:26:57 +00001093 skl_ddi_clock_get(encoder, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001094 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301095 bxt_ddi_clock_get(encoder, pipe_config);
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001096}
1097
Damien Lespiau0220ab62014-07-29 18:06:22 +01001098static bool
Damien Lespiaud664c0c2014-07-29 18:06:23 +01001099hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001100 struct intel_crtc_state *crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001101 struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001102{
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +02001103 struct intel_shared_dpll *pll;
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001104
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02001105 pll = intel_get_shared_dpll(intel_crtc, crtc_state,
1106 intel_encoder);
1107 if (!pll)
1108 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1109 pipe_name(intel_crtc->pipe));
1110
1111 return pll;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001112}
1113
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001114static bool
1115skl_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001116 struct intel_crtc_state *crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001117 struct intel_encoder *intel_encoder)
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001118{
1119 struct intel_shared_dpll *pll;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001120
Ander Conselvan de Oliveiradaedf202016-03-08 17:46:23 +02001121 pll = intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001122 if (pll == NULL) {
1123 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1124 pipe_name(intel_crtc->pipe));
1125 return false;
1126 }
1127
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001128 return true;
1129}
Damien Lespiau0220ab62014-07-29 18:06:22 +01001130
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301131static bool
1132bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
1133 struct intel_crtc_state *crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001134 struct intel_encoder *intel_encoder)
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301135{
Ander Conselvan de Oliveira34177c22016-03-08 17:46:25 +02001136 return !!intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301137}
1138
Damien Lespiau0220ab62014-07-29 18:06:22 +01001139/*
1140 * Tries to find a *shared* PLL for the CRTC and store it in
1141 * intel_crtc->ddi_pll_sel.
1142 *
1143 * For private DPLLs, compute_config() should do the selection for us. This
1144 * function should be folded into compute_config() eventually.
1145 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001146bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
1147 struct intel_crtc_state *crtc_state)
Damien Lespiau0220ab62014-07-29 18:06:22 +01001148{
Tvrtko Ursulin08537232016-10-13 11:03:02 +01001149 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001150 struct intel_encoder *intel_encoder =
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001151 intel_ddi_get_crtc_new_encoder(crtc_state);
Damien Lespiau0220ab62014-07-29 18:06:22 +01001152
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001153 if (IS_GEN9_BC(dev_priv))
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001154 return skl_ddi_pll_select(intel_crtc, crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001155 intel_encoder);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001156 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301157 return bxt_ddi_pll_select(intel_crtc, crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001158 intel_encoder);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001159 else
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001160 return hsw_ddi_pll_select(intel_crtc, crtc_state,
Ville Syrjälä96f3f1f2015-07-06 15:10:02 +03001161 intel_encoder);
Damien Lespiau0220ab62014-07-29 18:06:22 +01001162}
1163
Paulo Zanonidae84792012-10-15 15:51:30 -03001164void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
1165{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001166 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanonidae84792012-10-15 15:51:30 -03001167 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1168 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001169 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -03001170 int type = intel_encoder->type;
1171 uint32_t temp;
1172
Ville Syrjäläcca05022016-06-22 21:57:06 +03001173 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Jani Nikula4d1de972016-03-18 17:05:42 +02001174 WARN_ON(transcoder_is_dsi(cpu_transcoder));
1175
Paulo Zanonic9809792012-10-23 18:30:00 -02001176 temp = TRANS_MSA_SYNC_CLK;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001177 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -03001178 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -02001179 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001180 break;
1181 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -02001182 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001183 break;
1184 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -02001185 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001186 break;
1187 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -02001188 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001189 break;
1190 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001191 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -03001192 }
Paulo Zanonic9809792012-10-23 18:30:00 -02001193 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -03001194 }
1195}
1196
Dave Airlie0e32b392014-05-02 14:02:48 +10001197void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
1198{
1199 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1200 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001201 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001202 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +10001203 uint32_t temp;
1204 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1205 if (state == true)
1206 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1207 else
1208 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1209 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1210}
1211
Damien Lespiau8228c252013-03-07 15:30:27 +00001212void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001213{
1214 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1215 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanonic7670b12013-11-02 21:07:37 -07001216 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001217 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001218 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001219 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001220 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001221 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001222 uint32_t temp;
1223
Paulo Zanoniad80a812012-10-24 16:06:19 -02001224 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1225 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001226 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001227
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001228 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001229 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001230 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001231 break;
1232 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001233 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001234 break;
1235 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001236 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001237 break;
1238 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001239 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001240 break;
1241 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001242 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001243 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001244
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001245 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001246 temp |= TRANS_DDI_PVSYNC;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001247 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001248 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -03001249
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001250 if (cpu_transcoder == TRANSCODER_EDP) {
1251 switch (pipe) {
1252 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001253 /* On Haswell, can only use the always-on power well for
1254 * eDP when not using the panel fitter, and when not
1255 * using motion blur mitigation (which we don't
1256 * support). */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01001257 if (IS_HASWELL(dev_priv) &&
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001258 (intel_crtc->config->pch_pfit.enabled ||
1259 intel_crtc->config->pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001260 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1261 else
1262 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001263 break;
1264 case PIPE_B:
1265 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1266 break;
1267 case PIPE_C:
1268 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1269 break;
1270 default:
1271 BUG();
1272 break;
1273 }
1274 }
1275
Paulo Zanoni7739c332012-10-15 15:51:29 -03001276 if (type == INTEL_OUTPUT_HDMI) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001277 if (intel_crtc->config->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001278 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001279 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001280 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001281 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001282 temp |= TRANS_DDI_MODE_SELECT_FDI;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001283 temp |= (intel_crtc->config->fdi_lanes - 1) << 1;
Ville Syrjäläcca05022016-06-22 21:57:06 +03001284 } else if (type == INTEL_OUTPUT_DP ||
Paulo Zanoni7739c332012-10-15 15:51:29 -03001285 type == INTEL_OUTPUT_EDP) {
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001286 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001287 temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
Dave Airlie0e32b392014-05-02 14:02:48 +10001288 } else if (type == INTEL_OUTPUT_DP_MST) {
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001289 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03001290 temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001291 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001292 WARN(1, "Invalid encoder type %d for pipe %c\n",
1293 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001294 }
1295
Paulo Zanoniad80a812012-10-24 16:06:19 -02001296 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001297}
1298
Paulo Zanoniad80a812012-10-24 16:06:19 -02001299void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1300 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001301{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001302 i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001303 uint32_t val = I915_READ(reg);
1304
Dave Airlie0e32b392014-05-02 14:02:48 +10001305 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -02001306 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001307 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001308}
1309
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001310bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1311{
1312 struct drm_device *dev = intel_connector->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001313 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001314 struct intel_encoder *intel_encoder = intel_connector->encoder;
1315 int type = intel_connector->base.connector_type;
1316 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1317 enum pipe pipe = 0;
1318 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -03001319 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001320 uint32_t tmp;
Imre Deake27daab2016-02-12 18:55:16 +02001321 bool ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001322
Paulo Zanoni882244a2014-04-01 14:55:12 -03001323 power_domain = intel_display_port_power_domain(intel_encoder);
Imre Deake27daab2016-02-12 18:55:16 +02001324 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Paulo Zanoni882244a2014-04-01 14:55:12 -03001325 return false;
1326
Imre Deake27daab2016-02-12 18:55:16 +02001327 if (!intel_encoder->get_hw_state(intel_encoder, &pipe)) {
1328 ret = false;
1329 goto out;
1330 }
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001331
1332 if (port == PORT_A)
1333 cpu_transcoder = TRANSCODER_EDP;
1334 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001335 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001336
1337 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1338
1339 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1340 case TRANS_DDI_MODE_SELECT_HDMI:
1341 case TRANS_DDI_MODE_SELECT_DVI:
Imre Deake27daab2016-02-12 18:55:16 +02001342 ret = type == DRM_MODE_CONNECTOR_HDMIA;
1343 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001344
1345 case TRANS_DDI_MODE_SELECT_DP_SST:
Imre Deake27daab2016-02-12 18:55:16 +02001346 ret = type == DRM_MODE_CONNECTOR_eDP ||
1347 type == DRM_MODE_CONNECTOR_DisplayPort;
1348 break;
1349
Dave Airlie0e32b392014-05-02 14:02:48 +10001350 case TRANS_DDI_MODE_SELECT_DP_MST:
1351 /* if the transcoder is in MST state then
1352 * connector isn't connected */
Imre Deake27daab2016-02-12 18:55:16 +02001353 ret = false;
1354 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001355
1356 case TRANS_DDI_MODE_SELECT_FDI:
Imre Deake27daab2016-02-12 18:55:16 +02001357 ret = type == DRM_MODE_CONNECTOR_VGA;
1358 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001359
1360 default:
Imre Deake27daab2016-02-12 18:55:16 +02001361 ret = false;
1362 break;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001363 }
Imre Deake27daab2016-02-12 18:55:16 +02001364
1365out:
1366 intel_display_power_put(dev_priv, power_domain);
1367
1368 return ret;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001369}
1370
Daniel Vetter85234cd2012-07-02 13:27:29 +02001371bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1372 enum pipe *pipe)
1373{
1374 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001375 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001376 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001377 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001378 u32 tmp;
1379 int i;
Imre Deake27daab2016-02-12 18:55:16 +02001380 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001381
Imre Deak6d129be2014-03-05 16:20:54 +02001382 power_domain = intel_display_port_power_domain(encoder);
Imre Deake27daab2016-02-12 18:55:16 +02001383 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001384 return false;
1385
Imre Deake27daab2016-02-12 18:55:16 +02001386 ret = false;
1387
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001388 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001389
1390 if (!(tmp & DDI_BUF_CTL_ENABLE))
Imre Deake27daab2016-02-12 18:55:16 +02001391 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001392
Paulo Zanoniad80a812012-10-24 16:06:19 -02001393 if (port == PORT_A) {
1394 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001395
Paulo Zanoniad80a812012-10-24 16:06:19 -02001396 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1397 case TRANS_DDI_EDP_INPUT_A_ON:
1398 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1399 *pipe = PIPE_A;
1400 break;
1401 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1402 *pipe = PIPE_B;
1403 break;
1404 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1405 *pipe = PIPE_C;
1406 break;
1407 }
1408
Imre Deake27daab2016-02-12 18:55:16 +02001409 ret = true;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001410
Imre Deake27daab2016-02-12 18:55:16 +02001411 goto out;
1412 }
Dave Airlie0e32b392014-05-02 14:02:48 +10001413
Imre Deake27daab2016-02-12 18:55:16 +02001414 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1415 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1416
1417 if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
1418 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
1419 TRANS_DDI_MODE_SELECT_DP_MST)
1420 goto out;
1421
1422 *pipe = i;
1423 ret = true;
1424
1425 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001426 }
1427 }
1428
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001429 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001430
Imre Deake27daab2016-02-12 18:55:16 +02001431out:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001432 if (ret && IS_GEN9_LP(dev_priv)) {
Imre Deake93da0a2016-06-13 16:44:37 +03001433 tmp = I915_READ(BXT_PHY_CTL(port));
1434 if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK |
1435 BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
1436 DRM_ERROR("Port %c enabled but PHY powered down? "
1437 "(PHY_CTL %08x)\n", port_name(port), tmp);
1438 }
1439
Imre Deake27daab2016-02-12 18:55:16 +02001440 intel_display_power_put(dev_priv, power_domain);
1441
1442 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001443}
1444
Paulo Zanonifc914632012-10-05 12:05:54 -03001445void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1446{
1447 struct drm_crtc *crtc = &intel_crtc->base;
Shashank Sharma7d4aefd2015-10-01 22:23:49 +05301448 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001449 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonifc914632012-10-05 12:05:54 -03001450 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1451 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001452 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001453
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001454 if (cpu_transcoder != TRANSCODER_EDP)
1455 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1456 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001457}
1458
1459void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1460{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001461 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001462 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001463
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001464 if (cpu_transcoder != TRANSCODER_EDP)
1465 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1466 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001467}
1468
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001469static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
1470 enum port port, uint8_t iboost)
David Weinehallf8896f52015-06-25 11:11:03 +03001471{
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001472 u32 tmp;
1473
1474 tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
1475 tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
1476 if (iboost)
1477 tmp |= iboost << BALANCE_LEG_SHIFT(port);
1478 else
1479 tmp |= BALANCE_LEG_DISABLE(port);
1480 I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
1481}
1482
1483static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
1484{
1485 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
1486 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
1487 enum port port = intel_dig_port->port;
1488 int type = encoder->type;
David Weinehallf8896f52015-06-25 11:11:03 +03001489 const struct ddi_buf_trans *ddi_translations;
1490 uint8_t iboost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001491 uint8_t dp_iboost, hdmi_iboost;
David Weinehallf8896f52015-06-25 11:11:03 +03001492 int n_entries;
David Weinehallf8896f52015-06-25 11:11:03 +03001493
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001494 /* VBT may override standard boost values */
1495 dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
1496 hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
1497
Ville Syrjäläcca05022016-06-22 21:57:06 +03001498 if (type == INTEL_OUTPUT_DP) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001499 if (dp_iboost) {
1500 iboost = dp_iboost;
1501 } else {
Rodrigo Vivi0fdd4912016-10-18 08:57:36 -07001502 if (IS_KABYLAKE(dev_priv))
1503 ddi_translations = kbl_get_buf_trans_dp(dev_priv,
1504 &n_entries);
1505 else
1506 ddi_translations = skl_get_buf_trans_dp(dev_priv,
1507 &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001508 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001509 }
David Weinehallf8896f52015-06-25 11:11:03 +03001510 } else if (type == INTEL_OUTPUT_EDP) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001511 if (dp_iboost) {
1512 iboost = dp_iboost;
1513 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001514 ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
Ville Syrjälä10afa0b2015-12-08 19:59:43 +02001515
1516 if (WARN_ON(port != PORT_A &&
1517 port != PORT_E && n_entries > 9))
1518 n_entries = 9;
1519
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001520 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001521 }
David Weinehallf8896f52015-06-25 11:11:03 +03001522 } else if (type == INTEL_OUTPUT_HDMI) {
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001523 if (hdmi_iboost) {
1524 iboost = hdmi_iboost;
1525 } else {
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001526 ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
Ander Conselvan de Oliveirae4d4c052015-11-11 15:15:54 +02001527 iboost = ddi_translations[level].i_boost;
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001528 }
David Weinehallf8896f52015-06-25 11:11:03 +03001529 } else {
1530 return;
1531 }
1532
1533 /* Make sure that the requested I_boost is valid */
1534 if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
1535 DRM_ERROR("Invalid I_boost value %u\n", iboost);
1536 return;
1537 }
1538
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001539 _skl_ddi_set_iboost(dev_priv, port, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001540
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001541 if (port == PORT_A && intel_dig_port->max_lanes == 4)
1542 _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
David Weinehallf8896f52015-06-25 11:11:03 +03001543}
1544
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001545static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
1546 u32 level, enum port port, int type)
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301547{
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301548 const struct bxt_ddi_buf_trans *ddi_translations;
1549 u32 n_entries, i;
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301550
Jani Nikula06411f02016-03-24 17:50:21 +02001551 if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
Sonika Jindald9d70002015-09-24 10:24:56 +05301552 n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
1553 ddi_translations = bxt_ddi_translations_edp;
Ville Syrjäläcca05022016-06-22 21:57:06 +03001554 } else if (type == INTEL_OUTPUT_DP
Sonika Jindald9d70002015-09-24 10:24:56 +05301555 || type == INTEL_OUTPUT_EDP) {
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301556 n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
1557 ddi_translations = bxt_ddi_translations_dp;
1558 } else if (type == INTEL_OUTPUT_HDMI) {
1559 n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
1560 ddi_translations = bxt_ddi_translations_hdmi;
1561 } else {
1562 DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
1563 type);
1564 return;
1565 }
1566
1567 /* Check if default value has to be used */
1568 if (level >= n_entries ||
1569 (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
1570 for (i = 0; i < n_entries; i++) {
1571 if (ddi_translations[i].default_index) {
1572 level = i;
1573 break;
1574 }
1575 }
1576 }
1577
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +03001578 bxt_ddi_phy_set_signal_level(dev_priv, port,
1579 ddi_translations[level].margin,
1580 ddi_translations[level].scale,
1581 ddi_translations[level].enable,
1582 ddi_translations[level].deemphasis);
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301583}
1584
David Weinehallf8896f52015-06-25 11:11:03 +03001585static uint32_t translate_signal_level(int signal_levels)
1586{
1587 uint32_t level;
1588
1589 switch (signal_levels) {
1590 default:
1591 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level: 0x%x\n",
1592 signal_levels);
1593 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1594 level = 0;
1595 break;
1596 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
1597 level = 1;
1598 break;
1599 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
1600 level = 2;
1601 break;
1602 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3:
1603 level = 3;
1604 break;
1605
1606 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1607 level = 4;
1608 break;
1609 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
1610 level = 5;
1611 break;
1612 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
1613 level = 6;
1614 break;
1615
1616 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1617 level = 7;
1618 break;
1619 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
1620 level = 8;
1621 break;
1622
1623 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
1624 level = 9;
1625 break;
1626 }
1627
1628 return level;
1629}
1630
1631uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
1632{
1633 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001634 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
David Weinehallf8896f52015-06-25 11:11:03 +03001635 struct intel_encoder *encoder = &dport->base;
1636 uint8_t train_set = intel_dp->train_set[0];
1637 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
1638 DP_TRAIN_PRE_EMPHASIS_MASK);
1639 enum port port = dport->port;
1640 uint32_t level;
1641
1642 level = translate_signal_level(signal_levels);
1643
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001644 if (IS_GEN9_BC(dev_priv))
Ville Syrjäläa7d8dbc2016-07-12 15:59:28 +03001645 skl_ddi_set_iboost(encoder, level);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001646 else if (IS_GEN9_LP(dev_priv))
Ville Syrjälä78ab0ba2015-12-08 19:59:41 +02001647 bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
David Weinehallf8896f52015-06-25 11:11:03 +03001648
1649 return DDI_BUF_TRANS_SELECT(level);
1650}
1651
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001652void intel_ddi_clk_select(struct intel_encoder *encoder,
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001653 struct intel_shared_dpll *pll)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001654{
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001655 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1656 enum port port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001657
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001658 if (WARN_ON(!pll))
1659 return;
1660
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001661 if (IS_GEN9_BC(dev_priv)) {
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001662 uint32_t val;
1663
Damien Lespiau5416d872014-11-14 17:24:33 +00001664 /* DDI -> PLL mapping */
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001665 val = I915_READ(DPLL_CTRL2);
1666
1667 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
1668 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001669 val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001670 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
1671
1672 I915_WRITE(DPLL_CTRL2, val);
Damien Lespiau5416d872014-11-14 17:24:33 +00001673
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001674 } else if (INTEL_INFO(dev_priv)->gen < 9) {
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07001675 I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001676 }
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001677}
1678
Manasi Navareba88d152016-09-01 15:08:08 -07001679static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
1680 int link_rate, uint32_t lane_count,
1681 struct intel_shared_dpll *pll,
1682 bool link_mst)
1683{
1684 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1685 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1686 enum port port = intel_ddi_get_encoder_port(encoder);
1687
1688 intel_dp_set_link_params(intel_dp, link_rate, lane_count,
1689 link_mst);
1690 if (encoder->type == INTEL_OUTPUT_EDP)
1691 intel_edp_panel_on(intel_dp);
1692
1693 intel_ddi_clk_select(encoder, pll);
1694 intel_prepare_dp_ddi_buffers(encoder);
1695 intel_ddi_init_dp_buf_reg(encoder);
1696 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1697 intel_dp_start_link_train(intel_dp);
1698 if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
1699 intel_dp_stop_link_train(intel_dp);
1700}
1701
1702static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
1703 bool has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001704 const struct intel_crtc_state *crtc_state,
1705 const struct drm_connector_state *conn_state,
Manasi Navareba88d152016-09-01 15:08:08 -07001706 struct intel_shared_dpll *pll)
1707{
1708 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1709 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1710 struct drm_encoder *drm_encoder = &encoder->base;
1711 enum port port = intel_ddi_get_encoder_port(encoder);
1712 int level = intel_ddi_hdmi_level(dev_priv, port);
1713
1714 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
1715 intel_ddi_clk_select(encoder, pll);
1716 intel_prepare_hdmi_ddi_buffers(encoder);
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001717 if (IS_GEN9_BC(dev_priv))
Manasi Navareba88d152016-09-01 15:08:08 -07001718 skl_ddi_set_iboost(encoder, level);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001719 else if (IS_GEN9_LP(dev_priv))
Manasi Navareba88d152016-09-01 15:08:08 -07001720 bxt_ddi_vswing_sequence(dev_priv, level, port,
1721 INTEL_OUTPUT_HDMI);
1722
1723 intel_hdmi->set_infoframes(drm_encoder,
1724 has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001725 crtc_state, conn_state);
Manasi Navareba88d152016-09-01 15:08:08 -07001726}
1727
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001728static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder,
1729 struct intel_crtc_state *pipe_config,
1730 struct drm_connector_state *conn_state)
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001731{
1732 struct drm_encoder *encoder = &intel_encoder->base;
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001733 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Ville Syrjäläe404ba8d2015-08-17 18:46:20 +03001734 int type = intel_encoder->type;
Ville Syrjälä6a7e4f92015-12-08 19:59:44 +02001735
Ville Syrjäläcca05022016-06-22 21:57:06 +03001736 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
Manasi Navareba88d152016-09-01 15:08:08 -07001737 intel_ddi_pre_enable_dp(intel_encoder,
1738 crtc->config->port_clock,
1739 crtc->config->lane_count,
1740 crtc->config->shared_dpll,
1741 intel_crtc_has_type(crtc->config,
1742 INTEL_OUTPUT_DP_MST));
1743 }
1744 if (type == INTEL_OUTPUT_HDMI) {
1745 intel_ddi_pre_enable_hdmi(intel_encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001746 pipe_config->has_hdmi_sink,
1747 pipe_config, conn_state,
Manasi Navareba88d152016-09-01 15:08:08 -07001748 crtc->config->shared_dpll);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001749 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001750}
1751
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001752static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
1753 struct intel_crtc_state *old_crtc_state,
1754 struct drm_connector_state *old_conn_state)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001755{
1756 struct drm_encoder *encoder = &intel_encoder->base;
Tvrtko Ursulin66478472016-11-16 08:55:40 +00001757 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001758 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001759 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001760 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001761 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001762
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001763 /* old_crtc_state and old_conn_state are NULL when called from DP_MST */
1764
Paulo Zanoni2886e932012-10-05 12:06:00 -03001765 val = I915_READ(DDI_BUF_CTL(port));
1766 if (val & DDI_BUF_CTL_ENABLE) {
1767 val &= ~DDI_BUF_CTL_ENABLE;
1768 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001769 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001770 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001771
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001772 val = I915_READ(DP_TP_CTL(port));
1773 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1774 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1775 I915_WRITE(DP_TP_CTL(port), val);
1776
1777 if (wait)
1778 intel_wait_ddi_buf_idle(dev_priv, port);
1779
Ville Syrjäläcca05022016-06-22 21:57:06 +03001780 if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001781 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001782 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001783 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001784 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001785 }
1786
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001787 if (IS_GEN9_BC(dev_priv))
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001788 I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
1789 DPLL_CTRL2_DDI_CLK_OFF(port)));
Tvrtko Ursulin66478472016-11-16 08:55:40 +00001790 else if (INTEL_GEN(dev_priv) < 9)
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001791 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
Ville Syrjäläb2ccb822016-05-02 22:08:24 +03001792
1793 if (type == INTEL_OUTPUT_HDMI) {
1794 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1795
1796 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
1797 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001798}
1799
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001800void intel_ddi_fdi_post_disable(struct intel_encoder *intel_encoder,
1801 struct intel_crtc_state *old_crtc_state,
1802 struct drm_connector_state *old_conn_state)
1803{
1804 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
1805 uint32_t val;
1806
1807 /*
1808 * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
1809 * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
1810 * step 13 is the correct place for it. Step 18 is where it was
1811 * originally before the BUN.
1812 */
1813 val = I915_READ(FDI_RX_CTL(PIPE_A));
1814 val &= ~FDI_RX_ENABLE;
1815 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
1816
1817 intel_ddi_post_disable(intel_encoder, old_crtc_state, old_conn_state);
1818
1819 val = I915_READ(FDI_RX_MISC(PIPE_A));
1820 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1821 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1822 I915_WRITE(FDI_RX_MISC(PIPE_A), val);
1823
1824 val = I915_READ(FDI_RX_CTL(PIPE_A));
1825 val &= ~FDI_PCDCLK;
1826 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
1827
1828 val = I915_READ(FDI_RX_CTL(PIPE_A));
1829 val &= ~FDI_RX_PLL_ENABLE;
1830 I915_WRITE(FDI_RX_CTL(PIPE_A), val);
1831}
1832
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001833static void intel_enable_ddi(struct intel_encoder *intel_encoder,
1834 struct intel_crtc_state *pipe_config,
1835 struct drm_connector_state *conn_state)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001836{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001837 struct drm_encoder *encoder = &intel_encoder->base;
Tvrtko Ursulin66478472016-11-16 08:55:40 +00001838 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001839 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1840 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001841
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001842 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001843 struct intel_digital_port *intel_dig_port =
1844 enc_to_dig_port(encoder);
1845
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001846 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1847 * are ignored so nothing special needs to be done besides
1848 * enabling the port.
1849 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001850 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001851 intel_dig_port->saved_port_bits |
1852 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001853 } else if (type == INTEL_OUTPUT_EDP) {
1854 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1855
Tvrtko Ursulin66478472016-11-16 08:55:40 +00001856 if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03001857 intel_dp_stop_link_train(intel_dp);
1858
Daniel Vetter4be73782014-01-17 14:39:48 +01001859 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08001860 intel_psr_enable(intel_dp);
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001861 intel_edp_drrs_enable(intel_dp, pipe_config);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001862 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001863
Maarten Lankhorst37255d82016-12-15 15:29:43 +01001864 if (pipe_config->has_audio)
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +01001865 intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001866}
1867
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001868static void intel_disable_ddi(struct intel_encoder *intel_encoder,
1869 struct intel_crtc_state *old_crtc_state,
1870 struct drm_connector_state *old_conn_state)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001871{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001872 struct drm_encoder *encoder = &intel_encoder->base;
1873 int type = intel_encoder->type;
1874
Maarten Lankhorst37255d82016-12-15 15:29:43 +01001875 if (old_crtc_state->has_audio)
Jani Nikula69bfe1a2014-10-27 16:26:50 +02001876 intel_audio_codec_disable(intel_encoder);
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001877
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001878 if (type == INTEL_OUTPUT_EDP) {
1879 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1880
Maarten Lankhorst85cb48a2016-08-09 17:04:13 +02001881 intel_edp_drrs_disable(intel_dp, old_crtc_state);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08001882 intel_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001883 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001884 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001885}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001886
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001887static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
1888 struct intel_crtc_state *pipe_config,
1889 struct drm_connector_state *conn_state)
Imre Deak95a7a2a2016-06-13 16:44:35 +03001890{
Imre Deak95a7a2a2016-06-13 16:44:35 +03001891 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +03001892 uint8_t mask = intel_crtc->config->lane_lat_optim_mask;
Imre Deak95a7a2a2016-06-13 16:44:35 +03001893
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +03001894 bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
Imre Deak95a7a2a2016-06-13 16:44:35 +03001895}
1896
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03001897void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
Paulo Zanonic19b0662012-10-15 15:51:41 -03001898{
Ander Conselvan de Oliveiraad642172015-10-23 13:01:49 +03001899 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1900 struct drm_i915_private *dev_priv =
1901 to_i915(intel_dig_port->base.base.dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02001902 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001903 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301904 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001905
1906 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1907 val = I915_READ(DDI_BUF_CTL(port));
1908 if (val & DDI_BUF_CTL_ENABLE) {
1909 val &= ~DDI_BUF_CTL_ENABLE;
1910 I915_WRITE(DDI_BUF_CTL(port), val);
1911 wait = true;
1912 }
1913
1914 val = I915_READ(DP_TP_CTL(port));
1915 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1916 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1917 I915_WRITE(DP_TP_CTL(port), val);
1918 POSTING_READ(DP_TP_CTL(port));
1919
1920 if (wait)
1921 intel_wait_ddi_buf_idle(dev_priv, port);
1922 }
1923
Dave Airlie0e32b392014-05-02 14:02:48 +10001924 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03001925 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Ville Syrjälä64ee2fd2016-07-28 17:50:39 +03001926 if (intel_dp->link_mst)
Dave Airlie0e32b392014-05-02 14:02:48 +10001927 val |= DP_TP_CTL_MODE_MST;
1928 else {
1929 val |= DP_TP_CTL_MODE_SST;
1930 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1931 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1932 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03001933 I915_WRITE(DP_TP_CTL(port), val);
1934 POSTING_READ(DP_TP_CTL(port));
1935
1936 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1937 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1938 POSTING_READ(DDI_BUF_CTL(port));
1939
1940 udelay(600);
1941}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001942
Libin Yang9935f7f2016-11-28 20:07:06 +08001943bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
1944 struct intel_crtc *intel_crtc)
1945{
1946 u32 temp;
1947
1948 if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
1949 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1950 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
1951 return true;
1952 }
1953 return false;
1954}
1955
Ville Syrjälä6801c182013-09-24 14:24:05 +03001956void intel_ddi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001957 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001958{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001959 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001960 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +02001961 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01001962 struct intel_hdmi *intel_hdmi;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001963 u32 temp, flags = 0;
1964
Jani Nikula4d1de972016-03-18 17:05:42 +02001965 /* XXX: DSI transcoder paranoia */
1966 if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
1967 return;
1968
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001969 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1970 if (temp & TRANS_DDI_PHSYNC)
1971 flags |= DRM_MODE_FLAG_PHSYNC;
1972 else
1973 flags |= DRM_MODE_FLAG_NHSYNC;
1974 if (temp & TRANS_DDI_PVSYNC)
1975 flags |= DRM_MODE_FLAG_PVSYNC;
1976 else
1977 flags |= DRM_MODE_FLAG_NVSYNC;
1978
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001979 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001980
1981 switch (temp & TRANS_DDI_BPC_MASK) {
1982 case TRANS_DDI_BPC_6:
1983 pipe_config->pipe_bpp = 18;
1984 break;
1985 case TRANS_DDI_BPC_8:
1986 pipe_config->pipe_bpp = 24;
1987 break;
1988 case TRANS_DDI_BPC_10:
1989 pipe_config->pipe_bpp = 30;
1990 break;
1991 case TRANS_DDI_BPC_12:
1992 pipe_config->pipe_bpp = 36;
1993 break;
1994 default:
1995 break;
1996 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001997
1998 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1999 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02002000 pipe_config->has_hdmi_sink = true;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002001 intel_hdmi = enc_to_intel_hdmi(&encoder->base);
2002
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +02002003 if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002004 pipe_config->has_infoframe = true;
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002005 /* fall through */
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002006 case TRANS_DDI_MODE_SELECT_DVI:
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03002007 pipe_config->lane_count = 4;
2008 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002009 case TRANS_DDI_MODE_SELECT_FDI:
2010 break;
2011 case TRANS_DDI_MODE_SELECT_DP_SST:
2012 case TRANS_DDI_MODE_SELECT_DP_MST:
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +03002013 pipe_config->lane_count =
2014 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002015 intel_dp_get_m_n(intel_crtc, pipe_config);
2016 break;
2017 default:
2018 break;
2019 }
Daniel Vetter10214422013-11-18 07:38:16 +01002020
Libin Yang9935f7f2016-11-28 20:07:06 +08002021 pipe_config->has_audio =
2022 intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002023
Jani Nikula6aa23e62016-03-24 17:50:20 +02002024 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
2025 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
Daniel Vetter10214422013-11-18 07:38:16 +01002026 /*
2027 * This is a big fat ugly hack.
2028 *
2029 * Some machines in UEFI boot mode provide us a VBT that has 18
2030 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2031 * unknown we fail to light up. Yet the same BIOS boots up with
2032 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2033 * max, not what it tells us to use.
2034 *
2035 * Note: This will still be broken if the eDP panel is not lit
2036 * up by the BIOS, and thus we can't get the mode at module
2037 * load.
2038 */
2039 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
Jani Nikula6aa23e62016-03-24 17:50:20 +02002040 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2041 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
Daniel Vetter10214422013-11-18 07:38:16 +01002042 }
Jesse Barnes11578552014-01-21 12:42:10 -08002043
Damien Lespiau22606a12014-12-12 14:26:57 +00002044 intel_ddi_clock_get(encoder, pipe_config);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002045
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002046 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002047 pipe_config->lane_lat_optim_mask =
2048 bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002049}
2050
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002051static bool intel_ddi_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002052 struct intel_crtc_state *pipe_config,
2053 struct drm_connector_state *conn_state)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002054{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002055 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002056 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02002057 int port = intel_ddi_get_encoder_port(encoder);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002058 int ret;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002059
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002060 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002061
Daniel Vettereccb1402013-05-22 00:50:22 +02002062 if (port == PORT_A)
2063 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2064
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002065 if (type == INTEL_OUTPUT_HDMI)
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002066 ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002067 else
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02002068 ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002069
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002070 if (IS_GEN9_LP(dev_priv) && ret)
Imre Deak95a7a2a2016-06-13 16:44:35 +03002071 pipe_config->lane_lat_optim_mask =
2072 bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
Ander Conselvan de Oliveirab284eed2016-10-06 19:22:16 +03002073 pipe_config->lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +03002074
2075 return ret;
2076
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002077}
2078
2079static const struct drm_encoder_funcs intel_ddi_funcs = {
Imre Deakbf93ba62016-04-18 10:04:21 +03002080 .reset = intel_dp_encoder_reset,
2081 .destroy = intel_dp_encoder_destroy,
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002082};
2083
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002084static struct intel_connector *
2085intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2086{
2087 struct intel_connector *connector;
2088 enum port port = intel_dig_port->port;
2089
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002090 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002091 if (!connector)
2092 return NULL;
2093
2094 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2095 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2096 kfree(connector);
2097 return NULL;
2098 }
2099
2100 return connector;
2101}
2102
2103static struct intel_connector *
2104intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2105{
2106 struct intel_connector *connector;
2107 enum port port = intel_dig_port->port;
2108
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002109 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002110 if (!connector)
2111 return NULL;
2112
2113 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2114 intel_hdmi_init_connector(intel_dig_port, connector);
2115
2116 return connector;
2117}
2118
Jim Bridef1696602016-09-07 15:47:34 -07002119struct intel_shared_dpll *
2120intel_ddi_get_link_dpll(struct intel_dp *intel_dp, int clock)
2121{
2122 struct intel_connector *connector = intel_dp->attached_connector;
2123 struct intel_encoder *encoder = connector->encoder;
2124 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2125 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2126 struct intel_shared_dpll *pll = NULL;
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02002127 struct intel_shared_dpll_state tmp_pll_state;
Jim Bridef1696602016-09-07 15:47:34 -07002128 enum intel_dpll_id dpll_id;
2129
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002130 if (IS_GEN9_LP(dev_priv)) {
Jim Bridef1696602016-09-07 15:47:34 -07002131 dpll_id = (enum intel_dpll_id)dig_port->port;
2132 /*
2133 * Select the required PLL. This works for platforms where
2134 * there is no shared DPLL.
2135 */
2136 pll = &dev_priv->shared_dplls[dpll_id];
2137 if (WARN_ON(pll->active_mask)) {
2138
2139 DRM_ERROR("Shared DPLL in use. active_mask:%x\n",
2140 pll->active_mask);
2141 return NULL;
2142 }
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02002143 tmp_pll_state = pll->state;
Jim Bridef1696602016-09-07 15:47:34 -07002144 if (!bxt_ddi_dp_set_dpll_hw_state(clock,
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02002145 &pll->state.hw_state)) {
Jim Bridef1696602016-09-07 15:47:34 -07002146 DRM_ERROR("Could not setup DPLL\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02002147 pll->state = tmp_pll_state;
Jim Bridef1696602016-09-07 15:47:34 -07002148 return NULL;
2149 }
Rodrigo Vivib976dc52017-01-23 10:32:37 -08002150 } else if (IS_GEN9_BC(dev_priv)) {
Jim Bridef1696602016-09-07 15:47:34 -07002151 pll = skl_find_link_pll(dev_priv, clock);
2152 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
2153 pll = hsw_ddi_dp_get_dpll(encoder, clock);
2154 }
2155 return pll;
2156}
2157
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002158void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002159{
2160 struct intel_digital_port *intel_dig_port;
2161 struct intel_encoder *intel_encoder;
2162 struct drm_encoder *encoder;
Shashank Sharmaff662122016-10-14 19:56:51 +05302163 bool init_hdmi, init_dp, init_lspcon = false;
Ville Syrjälä10e7bec2015-12-08 19:59:37 +02002164 int max_lanes;
2165
2166 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
2167 switch (port) {
2168 case PORT_A:
2169 max_lanes = 4;
2170 break;
2171 case PORT_E:
2172 max_lanes = 0;
2173 break;
2174 default:
2175 max_lanes = 4;
2176 break;
2177 }
2178 } else {
2179 switch (port) {
2180 case PORT_A:
2181 max_lanes = 2;
2182 break;
2183 case PORT_E:
2184 max_lanes = 2;
2185 break;
2186 default:
2187 max_lanes = 4;
2188 break;
2189 }
2190 }
Paulo Zanoni311a2092013-09-12 17:12:18 -03002191
2192 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2193 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2194 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
Shashank Sharmaff662122016-10-14 19:56:51 +05302195
2196 if (intel_bios_is_lspcon_present(dev_priv, port)) {
2197 /*
2198 * Lspcon device needs to be driven with DP connector
2199 * with special detection sequence. So make sure DP
2200 * is initialized before lspcon.
2201 */
2202 init_dp = true;
2203 init_lspcon = true;
2204 init_hdmi = false;
2205 DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
2206 }
2207
Paulo Zanoni311a2092013-09-12 17:12:18 -03002208 if (!init_dp && !init_hdmi) {
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002209 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03002210 port_name(port));
Rodrigo Vivi500ea702015-08-07 17:01:16 -07002211 return;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002212 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002213
Daniel Vetterb14c5672013-09-19 12:18:32 +02002214 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002215 if (!intel_dig_port)
2216 return;
2217
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002218 intel_encoder = &intel_dig_port->base;
2219 encoder = &intel_encoder->base;
2220
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002221 drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
Ville Syrjälä580d8ed2016-05-27 20:59:24 +03002222 DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002223
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002224 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002225 intel_encoder->enable = intel_enable_ddi;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002226 if (IS_GEN9_LP(dev_priv))
Imre Deak95a7a2a2016-06-13 16:44:35 +03002227 intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002228 intel_encoder->pre_enable = intel_ddi_pre_enable;
2229 intel_encoder->disable = intel_disable_ddi;
2230 intel_encoder->post_disable = intel_ddi_post_disable;
2231 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002232 intel_encoder->get_config = intel_ddi_get_config;
Imre Deakbf93ba62016-04-18 10:04:21 +03002233 intel_encoder->suspend = intel_dp_encoder_suspend;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002234
2235 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07002236 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2237 (DDI_BUF_PORT_REVERSAL |
2238 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002239
Matt Roper6c566dc2015-11-05 14:53:32 -08002240 /*
2241 * Bspec says that DDI_A_4_LANES is the only supported configuration
2242 * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
2243 * wasn't lit up at boot. Force this bit on in our internal
2244 * configuration so that we use the proper lane count for our
2245 * calculations.
2246 */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002247 if (IS_GEN9_LP(dev_priv) && port == PORT_A) {
Matt Roper6c566dc2015-11-05 14:53:32 -08002248 if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
2249 DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
2250 intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
Matt Ropered8d60f2016-01-28 15:09:37 -08002251 max_lanes = 4;
Matt Roper6c566dc2015-11-05 14:53:32 -08002252 }
2253 }
2254
Matt Ropered8d60f2016-01-28 15:09:37 -08002255 intel_dig_port->max_lanes = max_lanes;
2256
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002257 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07002258 intel_encoder->port = port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002259 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02002260 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002261
Chris Wilsonf68d6972014-08-04 07:15:09 +01002262 if (init_dp) {
2263 if (!intel_ddi_init_dp_connector(intel_dig_port))
2264 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10002265
Chris Wilsonf68d6972014-08-04 07:15:09 +01002266 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Sonika Jindalcf1d5882015-08-10 10:35:36 +05302267 /*
2268 * On BXT A0/A1, sw needs to activate DDIA HPD logic and
2269 * interrupts to check the external panel connection.
2270 */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01002271 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1) && port == PORT_B)
Sonika Jindalcf1d5882015-08-10 10:35:36 +05302272 dev_priv->hotplug.irq_port[PORT_A] = intel_dig_port;
2273 else
2274 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002275 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002276
Paulo Zanoni311a2092013-09-12 17:12:18 -03002277 /* In theory we don't need the encoder->type check, but leave it just in
2278 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01002279 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2280 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2281 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002282 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01002283
Shashank Sharmaff662122016-10-14 19:56:51 +05302284 if (init_lspcon) {
2285 if (lspcon_init(intel_dig_port))
2286 /* TODO: handle hdmi info frame part */
2287 DRM_DEBUG_KMS("LSPCON init success on port %c\n",
2288 port_name(port));
2289 else
2290 /*
2291 * LSPCON init faied, but DP init was success, so
2292 * lets try to drive as DP++ port.
2293 */
2294 DRM_ERROR("LSPCON init failed on port %c\n",
2295 port_name(port));
2296 }
2297
Chris Wilsonf68d6972014-08-04 07:15:09 +01002298 return;
2299
2300err:
2301 drm_encoder_cleanup(encoder);
2302 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002303}