blob: 416f8fbea34ea1d0470a1fdca88c8fa42e64c74d [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 */
34};
35
Eugeni Dodonov45244b82012-05-09 15:37:20 -030036/* HDMI/DVI modes ignore everything but the last 2 items. So we share
37 * them for both DP and FDI transports, allowing those ports to
38 * automatically adapt to HDMI connections as well
39 */
Jani Nikula10122052014-08-27 16:27:30 +030040static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
41 { 0x00FFFFFF, 0x0006000E },
42 { 0x00D75FFF, 0x0005000A },
43 { 0x00C30FFF, 0x00040006 },
44 { 0x80AAAFFF, 0x000B0000 },
45 { 0x00FFFFFF, 0x0005000A },
46 { 0x00D75FFF, 0x000C0004 },
47 { 0x80C30FFF, 0x000B0000 },
48 { 0x00FFFFFF, 0x00040006 },
49 { 0x80D75FFF, 0x000B0000 },
Eugeni Dodonov45244b82012-05-09 15:37:20 -030050};
51
Jani Nikula10122052014-08-27 16:27:30 +030052static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
53 { 0x00FFFFFF, 0x0007000E },
54 { 0x00D75FFF, 0x000F000A },
55 { 0x00C30FFF, 0x00060006 },
56 { 0x00AAAFFF, 0x001E0000 },
57 { 0x00FFFFFF, 0x000F000A },
58 { 0x00D75FFF, 0x00160004 },
59 { 0x00C30FFF, 0x001E0000 },
60 { 0x00FFFFFF, 0x00060006 },
61 { 0x00D75FFF, 0x001E0000 },
Paulo Zanoni6acab152013-09-12 17:06:24 -030062};
63
Jani Nikula10122052014-08-27 16:27:30 +030064static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
65 /* Idx NT mV d T mV d db */
66 { 0x00FFFFFF, 0x0006000E }, /* 0: 400 400 0 */
67 { 0x00E79FFF, 0x000E000C }, /* 1: 400 500 2 */
68 { 0x00D75FFF, 0x0005000A }, /* 2: 400 600 3.5 */
69 { 0x00FFFFFF, 0x0005000A }, /* 3: 600 600 0 */
70 { 0x00E79FFF, 0x001D0007 }, /* 4: 600 750 2 */
71 { 0x00D75FFF, 0x000C0004 }, /* 5: 600 900 3.5 */
72 { 0x00FFFFFF, 0x00040006 }, /* 6: 800 800 0 */
73 { 0x80E79FFF, 0x00030002 }, /* 7: 800 1000 2 */
74 { 0x00FFFFFF, 0x00140005 }, /* 8: 850 850 0 */
75 { 0x00FFFFFF, 0x000C0004 }, /* 9: 900 900 0 */
76 { 0x00FFFFFF, 0x001C0003 }, /* 10: 950 950 0 */
77 { 0x80FFFFFF, 0x00030002 }, /* 11: 1000 1000 0 */
Eugeni Dodonov45244b82012-05-09 15:37:20 -030078};
79
Jani Nikula10122052014-08-27 16:27:30 +030080static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
81 { 0x00FFFFFF, 0x00000012 },
82 { 0x00EBAFFF, 0x00020011 },
83 { 0x00C71FFF, 0x0006000F },
84 { 0x00AAAFFF, 0x000E000A },
85 { 0x00FFFFFF, 0x00020011 },
86 { 0x00DB6FFF, 0x0005000F },
87 { 0x00BEEFFF, 0x000A000C },
88 { 0x00FFFFFF, 0x0005000F },
89 { 0x00DB6FFF, 0x000A000C },
Paulo Zanoni300644c2013-11-02 21:07:42 -070090};
91
Jani Nikula10122052014-08-27 16:27:30 +030092static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
93 { 0x00FFFFFF, 0x0007000E },
94 { 0x00D75FFF, 0x000E000A },
95 { 0x00BEFFFF, 0x00140006 },
96 { 0x80B2CFFF, 0x001B0002 },
97 { 0x00FFFFFF, 0x000E000A },
Rodrigo Vivi17b523b2014-09-24 20:32:43 -040098 { 0x00DB6FFF, 0x00160005 },
Rodrigo Vivi6805b2a2014-09-25 12:28:32 -040099 { 0x80C71FFF, 0x001A0002 },
Jani Nikula10122052014-08-27 16:27:30 +0300100 { 0x00F7DFFF, 0x00180004 },
101 { 0x80D75FFF, 0x001B0002 },
Art Runyane58623c2013-11-02 21:07:41 -0700102};
103
Jani Nikula10122052014-08-27 16:27:30 +0300104static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
105 { 0x00FFFFFF, 0x0001000E },
106 { 0x00D75FFF, 0x0004000A },
107 { 0x00C30FFF, 0x00070006 },
108 { 0x00AAAFFF, 0x000C0000 },
109 { 0x00FFFFFF, 0x0004000A },
110 { 0x00D75FFF, 0x00090004 },
111 { 0x00C30FFF, 0x000C0000 },
112 { 0x00FFFFFF, 0x00070006 },
113 { 0x00D75FFF, 0x000C0000 },
Art Runyane58623c2013-11-02 21:07:41 -0700114};
115
Jani Nikula10122052014-08-27 16:27:30 +0300116static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
117 /* Idx NT mV d T mV df db */
118 { 0x00FFFFFF, 0x0007000E }, /* 0: 400 400 0 */
119 { 0x00D75FFF, 0x000E000A }, /* 1: 400 600 3.5 */
120 { 0x00BEFFFF, 0x00140006 }, /* 2: 400 800 6 */
121 { 0x00FFFFFF, 0x0009000D }, /* 3: 450 450 0 */
122 { 0x00FFFFFF, 0x000E000A }, /* 4: 600 600 0 */
123 { 0x00D7FFFF, 0x00140006 }, /* 5: 600 800 2.5 */
124 { 0x80CB2FFF, 0x001B0002 }, /* 6: 600 1000 4.5 */
125 { 0x00FFFFFF, 0x00140006 }, /* 7: 800 800 0 */
126 { 0x80E79FFF, 0x001B0002 }, /* 8: 800 1000 2 */
127 { 0x80FFFFFF, 0x001B0002 }, /* 9: 1000 1000 0 */
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100128};
129
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000130static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
Damien Lespiau6c930682014-11-26 13:37:26 +0000131 { 0x00000018, 0x000000a2 },
132 { 0x00004014, 0x0000009B },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000133 { 0x00006012, 0x00000088 },
Damien Lespiau6c930682014-11-26 13:37:26 +0000134 { 0x00008010, 0x00000087 },
135 { 0x00000018, 0x0000009B },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000136 { 0x00004014, 0x00000088 },
Damien Lespiau6c930682014-11-26 13:37:26 +0000137 { 0x00006012, 0x00000087 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000138 { 0x00000018, 0x00000088 },
Damien Lespiau6c930682014-11-26 13:37:26 +0000139 { 0x00004014, 0x00000087 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000140};
141
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530142/* eDP 1.4 low vswing translation parameters */
143static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
144 { 0x00000018, 0x000000a8 },
145 { 0x00002016, 0x000000ab },
146 { 0x00006012, 0x000000a2 },
147 { 0x00008010, 0x00000088 },
148 { 0x00000018, 0x000000ab },
149 { 0x00004014, 0x000000a2 },
150 { 0x00006012, 0x000000a6 },
151 { 0x00000018, 0x000000a2 },
152 { 0x00005013, 0x0000009c },
153 { 0x00000018, 0x00000088 },
154};
155
156
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000157static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
Sonika Jindalb7192a52015-04-15 11:02:33 +0530158 { 0x00000018, 0x000000ac },
159 { 0x00005012, 0x0000009d },
160 { 0x00007011, 0x00000088 },
161 { 0x00000018, 0x000000a1 },
162 { 0x00000018, 0x00000098 },
163 { 0x00004013, 0x00000088 },
164 { 0x00006012, 0x00000087 },
165 { 0x00000018, 0x000000df },
166 { 0x00003015, 0x00000087 },
167 { 0x00003015, 0x000000c7 },
168 { 0x00000018, 0x000000c7 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000169};
170
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530171struct bxt_ddi_buf_trans {
172 u32 margin; /* swing value */
173 u32 scale; /* scale value */
174 u32 enable; /* scale enable */
175 u32 deemphasis;
176 bool default_index; /* true if the entry represents default value */
177};
178
179/* BSpec does not define separate vswing/pre-emphasis values for eDP.
180 * Using DP values for eDP as well.
181 */
182static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
183 /* Idx NT mV diff db */
184 { 52, 0, 0, 128, true }, /* 0: 400 0 */
185 { 78, 0, 0, 85, false }, /* 1: 400 3.5 */
186 { 104, 0, 0, 64, false }, /* 2: 400 6 */
187 { 154, 0, 0, 43, false }, /* 3: 400 9.5 */
188 { 77, 0, 0, 128, false }, /* 4: 600 0 */
189 { 116, 0, 0, 85, false }, /* 5: 600 3.5 */
190 { 154, 0, 0, 64, false }, /* 6: 600 6 */
191 { 102, 0, 0, 128, false }, /* 7: 800 0 */
192 { 154, 0, 0, 85, false }, /* 8: 800 3.5 */
193 { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
194};
195
196/* BSpec has 2 recommended values - entries 0 and 8.
197 * Using the entry with higher vswing.
198 */
199static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
200 /* Idx NT mV diff db */
201 { 52, 0, 0, 128, false }, /* 0: 400 0 */
202 { 52, 0, 0, 85, false }, /* 1: 400 3.5 */
203 { 52, 0, 0, 64, false }, /* 2: 400 6 */
204 { 42, 0, 0, 43, false }, /* 3: 400 9.5 */
205 { 77, 0, 0, 128, false }, /* 4: 600 0 */
206 { 77, 0, 0, 85, false }, /* 5: 600 3.5 */
207 { 77, 0, 0, 64, false }, /* 6: 600 6 */
208 { 102, 0, 0, 128, false }, /* 7: 800 0 */
209 { 102, 0, 0, 85, false }, /* 8: 800 3.5 */
210 { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
211};
212
Imre Deaka1e6ad62015-04-17 19:31:21 +0300213static void ddi_get_encoder_port(struct intel_encoder *intel_encoder,
214 struct intel_digital_port **dig_port,
215 enum port *port)
Paulo Zanonifc914632012-10-05 12:05:54 -0300216{
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300217 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonifc914632012-10-05 12:05:54 -0300218 int type = intel_encoder->type;
219
Dave Airlie0e32b392014-05-02 14:02:48 +1000220 if (type == INTEL_OUTPUT_DP_MST) {
Imre Deaka1e6ad62015-04-17 19:31:21 +0300221 *dig_port = enc_to_mst(encoder)->primary;
222 *port = (*dig_port)->port;
Dave Airlie0e32b392014-05-02 14:02:48 +1000223 } else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200224 type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
Imre Deaka1e6ad62015-04-17 19:31:21 +0300225 *dig_port = enc_to_dig_port(encoder);
226 *port = (*dig_port)->port;
Paulo Zanonifc914632012-10-05 12:05:54 -0300227 } else if (type == INTEL_OUTPUT_ANALOG) {
Imre Deaka1e6ad62015-04-17 19:31:21 +0300228 *dig_port = NULL;
229 *port = PORT_E;
Paulo Zanonifc914632012-10-05 12:05:54 -0300230 } else {
231 DRM_ERROR("Invalid DDI encoder type %d\n", type);
232 BUG();
233 }
234}
235
Imre Deaka1e6ad62015-04-17 19:31:21 +0300236enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
237{
238 struct intel_digital_port *dig_port;
239 enum port port;
240
241 ddi_get_encoder_port(intel_encoder, &dig_port, &port);
242
243 return port;
244}
245
Damien Lespiauce3b7e92014-08-04 15:04:43 +0100246static bool
247intel_dig_port_supports_hdmi(const struct intel_digital_port *intel_dig_port)
248{
249 return intel_dig_port->hdmi.hdmi_reg;
250}
251
Art Runyane58623c2013-11-02 21:07:41 -0700252/*
253 * Starting with Haswell, DDI port buffers must be programmed with correct
254 * values in advance. The buffer values are different for FDI and DP modes,
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300255 * but the HDMI/DVI fields are shared among those. So we program the DDI
256 * in either FDI or DP modes only, as HDMI connections will work with both
257 * of those
258 */
Imre Deakfaa0cdb2015-04-17 19:31:22 +0300259static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port,
260 bool supports_hdmi)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300261{
262 struct drm_i915_private *dev_priv = dev->dev_private;
263 u32 reg;
Damien Lespiau7ff44672015-03-02 16:19:36 +0000264 int i, n_hdmi_entries, n_dp_entries, n_edp_entries, hdmi_default_entry,
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530265 size;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300266 int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
Jani Nikula10122052014-08-27 16:27:30 +0300267 const struct ddi_buf_trans *ddi_translations_fdi;
268 const struct ddi_buf_trans *ddi_translations_dp;
269 const struct ddi_buf_trans *ddi_translations_edp;
270 const struct ddi_buf_trans *ddi_translations_hdmi;
271 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700272
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530273 if (IS_BROXTON(dev)) {
Imre Deakfaa0cdb2015-04-17 19:31:22 +0300274 if (!supports_hdmi)
Vandana Kannan96fb9f92014-11-18 15:45:27 +0530275 return;
276
277 /* Vswing programming for HDMI */
278 bxt_ddi_vswing_sequence(dev, hdmi_level, port,
279 INTEL_OUTPUT_HDMI);
280 return;
281 } else if (IS_SKYLAKE(dev)) {
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000282 ddi_translations_fdi = NULL;
283 ddi_translations_dp = skl_ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530284 n_dp_entries = ARRAY_SIZE(skl_ddi_translations_dp);
Sonika Jindal9e458032015-05-06 17:35:48 +0530285 if (dev_priv->edp_low_vswing) {
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530286 ddi_translations_edp = skl_ddi_translations_edp;
287 n_edp_entries = ARRAY_SIZE(skl_ddi_translations_edp);
288 } else {
289 ddi_translations_edp = skl_ddi_translations_dp;
290 n_edp_entries = ARRAY_SIZE(skl_ddi_translations_dp);
291 }
292
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000293 ddi_translations_hdmi = skl_ddi_translations_hdmi;
294 n_hdmi_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
Sonika Jindalb7192a52015-04-15 11:02:33 +0530295 hdmi_default_entry = 7;
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000296 } else if (IS_BROADWELL(dev)) {
Art Runyane58623c2013-11-02 21:07:41 -0700297 ddi_translations_fdi = bdw_ddi_translations_fdi;
298 ddi_translations_dp = bdw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700299 ddi_translations_edp = bdw_ddi_translations_edp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100300 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530301 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
302 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300303 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000304 hdmi_default_entry = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700305 } else if (IS_HASWELL(dev)) {
306 ddi_translations_fdi = hsw_ddi_translations_fdi;
307 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700308 ddi_translations_edp = hsw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100309 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530310 n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300311 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000312 hdmi_default_entry = 6;
Art Runyane58623c2013-11-02 21:07:41 -0700313 } else {
314 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700315 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700316 ddi_translations_fdi = bdw_ddi_translations_fdi;
317 ddi_translations_dp = bdw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100318 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530319 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
320 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300321 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000322 hdmi_default_entry = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700323 }
324
Paulo Zanoni300644c2013-11-02 21:07:42 -0700325 switch (port) {
326 case PORT_A:
327 ddi_translations = ddi_translations_edp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530328 size = n_edp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700329 break;
330 case PORT_B:
331 case PORT_C:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700332 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530333 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700334 break;
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700335 case PORT_D:
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530336 if (intel_dp_is_edp(dev, PORT_D)) {
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700337 ddi_translations = ddi_translations_edp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530338 size = n_edp_entries;
339 } else {
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700340 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530341 size = n_dp_entries;
342 }
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700343 break;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700344 case PORT_E:
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000345 if (ddi_translations_fdi)
346 ddi_translations = ddi_translations_fdi;
347 else
348 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530349 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700350 break;
351 default:
352 BUG();
353 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300354
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530355 for (i = 0, reg = DDI_BUF_TRANS(port); i < size; i++) {
Jani Nikula10122052014-08-27 16:27:30 +0300356 I915_WRITE(reg, ddi_translations[i].trans1);
357 reg += 4;
358 I915_WRITE(reg, ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300359 reg += 4;
360 }
Damien Lespiauce4dd492014-08-01 11:07:54 +0100361
Imre Deakfaa0cdb2015-04-17 19:31:22 +0300362 if (!supports_hdmi)
Damien Lespiauce3b7e92014-08-04 15:04:43 +0100363 return;
364
Damien Lespiauce4dd492014-08-01 11:07:54 +0100365 /* Choose a good default if VBT is badly populated */
366 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
367 hdmi_level >= n_hdmi_entries)
Damien Lespiau7ff44672015-03-02 16:19:36 +0000368 hdmi_level = hdmi_default_entry;
Damien Lespiauce4dd492014-08-01 11:07:54 +0100369
Paulo Zanoni6acab152013-09-12 17:06:24 -0300370 /* Entry 9 is for HDMI: */
Jani Nikula10122052014-08-27 16:27:30 +0300371 I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans1);
372 reg += 4;
373 I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans2);
374 reg += 4;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300375}
376
377/* Program DDI buffers translations for DP. By default, program ports A-D in DP
378 * mode and port E for FDI.
379 */
380void intel_prepare_ddi(struct drm_device *dev)
381{
Imre Deakfaa0cdb2015-04-17 19:31:22 +0300382 struct intel_encoder *intel_encoder;
Damien Lespiaub4037452014-08-04 22:01:33 +0100383 bool visited[I915_MAX_PORTS] = { 0, };
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300384
Paulo Zanoni0d536cb2012-11-23 16:46:41 -0200385 if (!HAS_DDI(dev))
386 return;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300387
Imre Deakfaa0cdb2015-04-17 19:31:22 +0300388 for_each_intel_encoder(dev, intel_encoder) {
389 struct intel_digital_port *intel_dig_port;
390 enum port port;
391 bool supports_hdmi;
392
393 ddi_get_encoder_port(intel_encoder, &intel_dig_port, &port);
394
395 if (visited[port])
Damien Lespiaub4037452014-08-04 22:01:33 +0100396 continue;
397
Imre Deakfaa0cdb2015-04-17 19:31:22 +0300398 supports_hdmi = intel_dig_port &&
399 intel_dig_port_supports_hdmi(intel_dig_port);
400
401 intel_prepare_ddi_buffers(dev, port, supports_hdmi);
402 visited[port] = true;
Damien Lespiaub4037452014-08-04 22:01:33 +0100403 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300404}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300405
Paulo Zanoni248138b2012-11-29 11:29:31 -0200406static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
407 enum port port)
408{
409 uint32_t reg = DDI_BUF_CTL(port);
410 int i;
411
Vandana Kannan3449ca82015-03-27 14:19:09 +0200412 for (i = 0; i < 16; i++) {
Paulo Zanoni248138b2012-11-29 11:29:31 -0200413 udelay(1);
414 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
415 return;
416 }
417 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
418}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300419
420/* Starting with Haswell, different DDI ports can work in FDI mode for
421 * connection to the PCH-located connectors. For this, it is necessary to train
422 * both the DDI port and PCH receiver for the desired DDI buffer settings.
423 *
424 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
425 * please note that when FDI mode is active on DDI E, it shares 2 lines with
426 * DDI A (which is used for eDP)
427 */
428
429void hsw_fdi_link_train(struct drm_crtc *crtc)
430{
431 struct drm_device *dev = crtc->dev;
432 struct drm_i915_private *dev_priv = dev->dev_private;
433 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni04945642012-11-01 21:00:59 -0200434 u32 temp, i, rx_ctl_val;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300435
Paulo Zanoni04945642012-11-01 21:00:59 -0200436 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
437 * mode set "sequence for CRT port" document:
438 * - TP1 to TP2 time with the default value
439 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100440 *
441 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200442 */
443 I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) |
444 FDI_RX_PWRDN_LANE0_VAL(2) |
445 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
446
447 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000448 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100449 FDI_RX_PLL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200450 FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
Paulo Zanoni04945642012-11-01 21:00:59 -0200451 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
452 POSTING_READ(_FDI_RXA_CTL);
453 udelay(220);
454
455 /* Switch from Rawclk to PCDclk */
456 rx_ctl_val |= FDI_PCDCLK;
457 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
458
459 /* Configure Port Clock Select */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200460 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config->ddi_pll_sel);
461 WARN_ON(intel_crtc->config->ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200462
463 /* Start the training iterating through available voltages and emphasis,
464 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300465 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300466 /* Configure DP_TP_CTL with auto-training */
467 I915_WRITE(DP_TP_CTL(PORT_E),
468 DP_TP_CTL_FDI_AUTOTRAIN |
469 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
470 DP_TP_CTL_LINK_TRAIN_PAT1 |
471 DP_TP_CTL_ENABLE);
472
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000473 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
474 * DDI E does not support port reversal, the functionality is
475 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
476 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300477 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200478 DDI_BUF_CTL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200479 ((intel_crtc->config->fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530480 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200481 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300482
483 udelay(600);
484
Paulo Zanoni04945642012-11-01 21:00:59 -0200485 /* Program PCH FDI Receiver TU */
486 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300487
Paulo Zanoni04945642012-11-01 21:00:59 -0200488 /* Enable PCH FDI Receiver with auto-training */
489 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
490 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
491 POSTING_READ(_FDI_RXA_CTL);
492
493 /* Wait for FDI receiver lane calibration */
494 udelay(30);
495
496 /* Unset FDI_RX_MISC pwrdn lanes */
497 temp = I915_READ(_FDI_RXA_MISC);
498 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
499 I915_WRITE(_FDI_RXA_MISC, temp);
500 POSTING_READ(_FDI_RXA_MISC);
501
502 /* Wait for FDI auto training time */
503 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300504
505 temp = I915_READ(DP_TP_STATUS(PORT_E));
506 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200507 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300508
509 /* Enable normal pixel sending for FDI */
510 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200511 DP_TP_CTL_FDI_AUTOTRAIN |
512 DP_TP_CTL_LINK_TRAIN_NORMAL |
513 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
514 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300515
Paulo Zanoni04945642012-11-01 21:00:59 -0200516 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300517 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200518
Paulo Zanoni248138b2012-11-29 11:29:31 -0200519 temp = I915_READ(DDI_BUF_CTL(PORT_E));
520 temp &= ~DDI_BUF_CTL_ENABLE;
521 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
522 POSTING_READ(DDI_BUF_CTL(PORT_E));
523
Paulo Zanoni04945642012-11-01 21:00:59 -0200524 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200525 temp = I915_READ(DP_TP_CTL(PORT_E));
526 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
527 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
528 I915_WRITE(DP_TP_CTL(PORT_E), temp);
529 POSTING_READ(DP_TP_CTL(PORT_E));
530
531 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200532
533 rx_ctl_val &= ~FDI_RX_ENABLE;
534 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200535 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200536
537 /* Reset FDI_RX_MISC pwrdn lanes */
538 temp = I915_READ(_FDI_RXA_MISC);
539 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
540 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
541 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200542 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300543 }
544
Paulo Zanoni04945642012-11-01 21:00:59 -0200545 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300546}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300547
Dave Airlie44905a22014-05-02 13:36:43 +1000548void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
549{
550 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
551 struct intel_digital_port *intel_dig_port =
552 enc_to_dig_port(&encoder->base);
553
554 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530555 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Dave Airlie44905a22014-05-02 13:36:43 +1000556 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
557
558}
559
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300560static struct intel_encoder *
561intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
562{
563 struct drm_device *dev = crtc->dev;
564 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
565 struct intel_encoder *intel_encoder, *ret = NULL;
566 int num_encoders = 0;
567
568 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
569 ret = intel_encoder;
570 num_encoders++;
571 }
572
573 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300574 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
575 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300576
577 BUG_ON(ret == NULL);
578 return ret;
579}
580
Satheeshakrishna Mbcddf612014-08-22 09:49:10 +0530581struct intel_encoder *
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200582intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200583{
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200584 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
585 struct intel_encoder *ret = NULL;
586 struct drm_atomic_state *state;
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300587 struct drm_connector *connector;
588 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200589 int num_encoders = 0;
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200590 int i;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200591
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200592 state = crtc_state->base.state;
593
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300594 for_each_connector_in_state(state, connector, connector_state, i) {
595 if (connector_state->crtc != crtc_state->base.crtc)
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200596 continue;
597
Ander Conselvan de Oliveirada3ced22015-04-21 17:12:59 +0300598 ret = to_intel_encoder(connector_state->best_encoder);
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200599 num_encoders++;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200600 }
601
602 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
603 pipe_name(crtc->pipe));
604
605 BUG_ON(ret == NULL);
606 return ret;
607}
608
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100609#define LC_FREQ 2700
Damien Lespiau27893392014-09-04 12:27:23 +0100610#define LC_FREQ_2K U64_C(LC_FREQ * 2000)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100611
612#define P_MIN 2
613#define P_MAX 64
614#define P_INC 2
615
616/* Constraints for PLL good behavior */
617#define REF_MIN 48
618#define REF_MAX 400
619#define VCO_MIN 2400
620#define VCO_MAX 4800
621
Damien Lespiau27893392014-09-04 12:27:23 +0100622#define abs_diff(a, b) ({ \
623 typeof(a) __a = (a); \
624 typeof(b) __b = (b); \
625 (void) (&__a == &__b); \
626 __a > __b ? (__a - __b) : (__b - __a); })
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100627
628struct wrpll_rnp {
629 unsigned p, n2, r2;
630};
631
632static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300633{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100634 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300635
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100636 switch (clock) {
637 case 25175000:
638 case 25200000:
639 case 27000000:
640 case 27027000:
641 case 37762500:
642 case 37800000:
643 case 40500000:
644 case 40541000:
645 case 54000000:
646 case 54054000:
647 case 59341000:
648 case 59400000:
649 case 72000000:
650 case 74176000:
651 case 74250000:
652 case 81000000:
653 case 81081000:
654 case 89012000:
655 case 89100000:
656 case 108000000:
657 case 108108000:
658 case 111264000:
659 case 111375000:
660 case 148352000:
661 case 148500000:
662 case 162000000:
663 case 162162000:
664 case 222525000:
665 case 222750000:
666 case 296703000:
667 case 297000000:
668 budget = 0;
669 break;
670 case 233500000:
671 case 245250000:
672 case 247750000:
673 case 253250000:
674 case 298000000:
675 budget = 1500;
676 break;
677 case 169128000:
678 case 169500000:
679 case 179500000:
680 case 202000000:
681 budget = 2000;
682 break;
683 case 256250000:
684 case 262500000:
685 case 270000000:
686 case 272500000:
687 case 273750000:
688 case 280750000:
689 case 281250000:
690 case 286000000:
691 case 291750000:
692 budget = 4000;
693 break;
694 case 267250000:
695 case 268500000:
696 budget = 5000;
697 break;
698 default:
699 budget = 1000;
700 break;
701 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300702
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100703 return budget;
704}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300705
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100706static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
707 unsigned r2, unsigned n2, unsigned p,
708 struct wrpll_rnp *best)
709{
710 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300711
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100712 /* No best (r,n,p) yet */
713 if (best->p == 0) {
714 best->p = p;
715 best->n2 = n2;
716 best->r2 = r2;
717 return;
718 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300719
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100720 /*
721 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
722 * freq2k.
723 *
724 * delta = 1e6 *
725 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
726 * freq2k;
727 *
728 * and we would like delta <= budget.
729 *
730 * If the discrepancy is above the PPM-based budget, always prefer to
731 * improve upon the previous solution. However, if you're within the
732 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
733 */
734 a = freq2k * budget * p * r2;
735 b = freq2k * budget * best->p * best->r2;
Damien Lespiau27893392014-09-04 12:27:23 +0100736 diff = abs_diff(freq2k * p * r2, LC_FREQ_2K * n2);
737 diff_best = abs_diff(freq2k * best->p * best->r2,
738 LC_FREQ_2K * best->n2);
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100739 c = 1000000 * diff;
740 d = 1000000 * diff_best;
741
742 if (a < c && b < d) {
743 /* If both are above the budget, pick the closer */
744 if (best->p * best->r2 * diff < p * r2 * diff_best) {
745 best->p = p;
746 best->n2 = n2;
747 best->r2 = r2;
748 }
749 } else if (a >= c && b < d) {
750 /* If A is below the threshold but B is above it? Update. */
751 best->p = p;
752 best->n2 = n2;
753 best->r2 = r2;
754 } else if (a >= c && b >= d) {
755 /* Both are below the limit, so pick the higher n2/(r2*r2) */
756 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
757 best->p = p;
758 best->n2 = n2;
759 best->r2 = r2;
760 }
761 }
762 /* Otherwise a < c && b >= d, do nothing */
763}
764
Jesse Barnes11578552014-01-21 12:42:10 -0800765static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
766 int reg)
767{
768 int refclk = LC_FREQ;
769 int n, p, r;
770 u32 wrpll;
771
772 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300773 switch (wrpll & WRPLL_PLL_REF_MASK) {
774 case WRPLL_PLL_SSC:
775 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800776 /*
777 * We could calculate spread here, but our checking
778 * code only cares about 5% accuracy, and spread is a max of
779 * 0.5% downspread.
780 */
781 refclk = 135;
782 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300783 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800784 refclk = LC_FREQ;
785 break;
786 default:
787 WARN(1, "bad wrpll refclk\n");
788 return 0;
789 }
790
791 r = wrpll & WRPLL_DIVIDER_REF_MASK;
792 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
793 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
794
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800795 /* Convert to KHz, p & r have a fixed point portion */
796 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800797}
798
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000799static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
800 uint32_t dpll)
801{
802 uint32_t cfgcr1_reg, cfgcr2_reg;
803 uint32_t cfgcr1_val, cfgcr2_val;
804 uint32_t p0, p1, p2, dco_freq;
805
806 cfgcr1_reg = GET_CFG_CR1_REG(dpll);
807 cfgcr2_reg = GET_CFG_CR2_REG(dpll);
808
809 cfgcr1_val = I915_READ(cfgcr1_reg);
810 cfgcr2_val = I915_READ(cfgcr2_reg);
811
812 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
813 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
814
815 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
816 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
817 else
818 p1 = 1;
819
820
821 switch (p0) {
822 case DPLL_CFGCR2_PDIV_1:
823 p0 = 1;
824 break;
825 case DPLL_CFGCR2_PDIV_2:
826 p0 = 2;
827 break;
828 case DPLL_CFGCR2_PDIV_3:
829 p0 = 3;
830 break;
831 case DPLL_CFGCR2_PDIV_7:
832 p0 = 7;
833 break;
834 }
835
836 switch (p2) {
837 case DPLL_CFGCR2_KDIV_5:
838 p2 = 5;
839 break;
840 case DPLL_CFGCR2_KDIV_2:
841 p2 = 2;
842 break;
843 case DPLL_CFGCR2_KDIV_3:
844 p2 = 3;
845 break;
846 case DPLL_CFGCR2_KDIV_1:
847 p2 = 1;
848 break;
849 }
850
851 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
852
853 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
854 1000) / 0x8000;
855
856 return dco_freq / (p0 * p1 * p2 * 5);
857}
858
859
860static void skl_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200861 struct intel_crtc_state *pipe_config)
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000862{
863 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000864 int link_clock = 0;
865 uint32_t dpll_ctl1, dpll;
866
Damien Lespiau134ffa42014-11-14 17:24:34 +0000867 dpll = pipe_config->ddi_pll_sel;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000868
869 dpll_ctl1 = I915_READ(DPLL_CTRL1);
870
871 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
872 link_clock = skl_calc_wrpll_link(dev_priv, dpll);
873 } else {
Damien Lespiau71cd8422015-04-30 16:39:17 +0100874 link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
875 link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000876
877 switch (link_clock) {
Damien Lespiau71cd8422015-04-30 16:39:17 +0100878 case DPLL_CTRL1_LINK_RATE_810:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000879 link_clock = 81000;
880 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100881 case DPLL_CTRL1_LINK_RATE_1080:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530882 link_clock = 108000;
883 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100884 case DPLL_CTRL1_LINK_RATE_1350:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000885 link_clock = 135000;
886 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100887 case DPLL_CTRL1_LINK_RATE_1620:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530888 link_clock = 162000;
889 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100890 case DPLL_CTRL1_LINK_RATE_2160:
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530891 link_clock = 216000;
892 break;
Damien Lespiau71cd8422015-04-30 16:39:17 +0100893 case DPLL_CTRL1_LINK_RATE_2700:
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000894 link_clock = 270000;
895 break;
896 default:
897 WARN(1, "Unsupported link rate\n");
898 break;
899 }
900 link_clock *= 2;
901 }
902
903 pipe_config->port_clock = link_clock;
904
905 if (pipe_config->has_dp_encoder)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200906 pipe_config->base.adjusted_mode.crtc_clock =
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000907 intel_dotclock_calculate(pipe_config->port_clock,
908 &pipe_config->dp_m_n);
909 else
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200910 pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000911}
912
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200913static void hsw_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200914 struct intel_crtc_state *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -0800915{
916 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jesse Barnes11578552014-01-21 12:42:10 -0800917 int link_clock = 0;
918 u32 val, pll;
919
Daniel Vetter26804af2014-06-25 22:01:55 +0300920 val = pipe_config->ddi_pll_sel;
Jesse Barnes11578552014-01-21 12:42:10 -0800921 switch (val & PORT_CLK_SEL_MASK) {
922 case PORT_CLK_SEL_LCPLL_810:
923 link_clock = 81000;
924 break;
925 case PORT_CLK_SEL_LCPLL_1350:
926 link_clock = 135000;
927 break;
928 case PORT_CLK_SEL_LCPLL_2700:
929 link_clock = 270000;
930 break;
931 case PORT_CLK_SEL_WRPLL1:
932 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
933 break;
934 case PORT_CLK_SEL_WRPLL2:
935 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
936 break;
937 case PORT_CLK_SEL_SPLL:
938 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
939 if (pll == SPLL_PLL_FREQ_810MHz)
940 link_clock = 81000;
941 else if (pll == SPLL_PLL_FREQ_1350MHz)
942 link_clock = 135000;
943 else if (pll == SPLL_PLL_FREQ_2700MHz)
944 link_clock = 270000;
945 else {
946 WARN(1, "bad spll freq\n");
947 return;
948 }
949 break;
950 default:
951 WARN(1, "bad port clock sel\n");
952 return;
953 }
954
955 pipe_config->port_clock = link_clock * 2;
956
957 if (pipe_config->has_pch_encoder)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200958 pipe_config->base.adjusted_mode.crtc_clock =
Jesse Barnes11578552014-01-21 12:42:10 -0800959 intel_dotclock_calculate(pipe_config->port_clock,
960 &pipe_config->fdi_m_n);
961 else if (pipe_config->has_dp_encoder)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200962 pipe_config->base.adjusted_mode.crtc_clock =
Jesse Barnes11578552014-01-21 12:42:10 -0800963 intel_dotclock_calculate(pipe_config->port_clock,
964 &pipe_config->dp_m_n);
965 else
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200966 pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
Jesse Barnes11578552014-01-21 12:42:10 -0800967}
968
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530969static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
970 enum intel_dpll_id dpll)
971{
972 /* FIXME formula not available in bspec */
973 return 0;
974}
975
976static void bxt_ddi_clock_get(struct intel_encoder *encoder,
977 struct intel_crtc_state *pipe_config)
978{
979 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
980 enum port port = intel_ddi_get_encoder_port(encoder);
981 uint32_t dpll = port;
982
983 pipe_config->port_clock =
984 bxt_calc_pll_link(dev_priv, dpll);
985
986 if (pipe_config->has_dp_encoder)
987 pipe_config->base.adjusted_mode.crtc_clock =
988 intel_dotclock_calculate(pipe_config->port_clock,
989 &pipe_config->dp_m_n);
990 else
991 pipe_config->base.adjusted_mode.crtc_clock =
992 pipe_config->port_clock;
993}
994
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200995void intel_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200996 struct intel_crtc_state *pipe_config)
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200997{
Damien Lespiau22606a12014-12-12 14:26:57 +0000998 struct drm_device *dev = encoder->base.dev;
999
1000 if (INTEL_INFO(dev)->gen <= 8)
1001 hsw_ddi_clock_get(encoder, pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301002 else if (IS_SKYLAKE(dev))
Damien Lespiau22606a12014-12-12 14:26:57 +00001003 skl_ddi_clock_get(encoder, pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +05301004 else if (IS_BROXTON(dev))
1005 bxt_ddi_clock_get(encoder, pipe_config);
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001006}
1007
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001008static void
Damien Lespiaud664c0c2014-07-29 18:06:23 +01001009hsw_ddi_calculate_wrpll(int clock /* in Hz */,
1010 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001011{
1012 uint64_t freq2k;
1013 unsigned p, n2, r2;
1014 struct wrpll_rnp best = { 0, 0, 0 };
1015 unsigned budget;
1016
1017 freq2k = clock / 100;
1018
1019 budget = wrpll_get_budget_for_freq(clock);
1020
1021 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
1022 * and directly pass the LC PLL to it. */
1023 if (freq2k == 5400000) {
1024 *n2_out = 2;
1025 *p_out = 1;
1026 *r2_out = 2;
1027 return;
1028 }
1029
1030 /*
1031 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
1032 * the WR PLL.
1033 *
1034 * We want R so that REF_MIN <= Ref <= REF_MAX.
1035 * Injecting R2 = 2 * R gives:
1036 * REF_MAX * r2 > LC_FREQ * 2 and
1037 * REF_MIN * r2 < LC_FREQ * 2
1038 *
1039 * Which means the desired boundaries for r2 are:
1040 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
1041 *
1042 */
1043 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
1044 r2 <= LC_FREQ * 2 / REF_MIN;
1045 r2++) {
1046
1047 /*
1048 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
1049 *
1050 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
1051 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
1052 * VCO_MAX * r2 > n2 * LC_FREQ and
1053 * VCO_MIN * r2 < n2 * LC_FREQ)
1054 *
1055 * Which means the desired boundaries for n2 are:
1056 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
1057 */
1058 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
1059 n2 <= VCO_MAX * r2 / LC_FREQ;
1060 n2++) {
1061
1062 for (p = P_MIN; p <= P_MAX; p += P_INC)
1063 wrpll_update_rnp(freq2k, budget,
1064 r2, n2, p, &best);
1065 }
1066 }
1067
1068 *n2_out = best.n2;
1069 *p_out = best.p;
1070 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001071}
1072
Damien Lespiau0220ab62014-07-29 18:06:22 +01001073static bool
Damien Lespiaud664c0c2014-07-29 18:06:23 +01001074hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001075 struct intel_crtc_state *crtc_state,
Damien Lespiaud664c0c2014-07-29 18:06:23 +01001076 struct intel_encoder *intel_encoder,
1077 int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001078{
Damien Lespiaud664c0c2014-07-29 18:06:23 +01001079 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
Daniel Vettere0b01be2014-06-25 22:02:01 +03001080 struct intel_shared_dpll *pll;
Daniel Vetter716c2e52014-06-25 22:02:02 +03001081 uint32_t val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +01001082 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001083
Damien Lespiaud664c0c2014-07-29 18:06:23 +01001084 hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001085
Daniel Vetter114fe482014-06-25 22:01:48 +03001086 val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001087 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
1088 WRPLL_DIVIDER_POST(p);
1089
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03001090 memset(&crtc_state->dpll_hw_state, 0,
1091 sizeof(crtc_state->dpll_hw_state));
1092
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001093 crtc_state->dpll_hw_state.wrpll = val;
Daniel Vetter716c2e52014-06-25 22:02:02 +03001094
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001095 pll = intel_get_shared_dpll(intel_crtc, crtc_state);
Daniel Vetter716c2e52014-06-25 22:02:02 +03001096 if (pll == NULL) {
1097 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1098 pipe_name(intel_crtc->pipe));
Paulo Zanoni06940012013-10-30 18:27:43 -02001099 return false;
1100 }
1101
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001102 crtc_state->ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001103 }
1104
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001105 return true;
1106}
1107
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001108struct skl_wrpll_params {
1109 uint32_t dco_fraction;
1110 uint32_t dco_integer;
1111 uint32_t qdiv_ratio;
1112 uint32_t qdiv_mode;
1113 uint32_t kdiv;
1114 uint32_t pdiv;
1115 uint32_t central_freq;
1116};
1117
Damien Lespiau76516fb2015-05-07 18:38:42 +01001118static void skl_wrpll_params_populate(struct skl_wrpll_params *params,
1119 uint64_t afe_clock,
1120 uint64_t central_freq,
1121 uint32_t p0, uint32_t p1, uint32_t p2)
1122{
1123 uint64_t dco_freq;
1124
1125 params->central_freq = central_freq;
1126
1127 switch (central_freq) {
1128 case 9600000000ULL:
1129 params->central_freq = 0;
1130 break;
1131 case 9000000000ULL:
1132 params->central_freq = 1;
1133 break;
1134 case 8400000000ULL:
1135 params->central_freq = 3;
1136 }
1137
1138 switch (p0) {
1139 case 1:
1140 params->pdiv = 0;
1141 break;
1142 case 2:
1143 params->pdiv = 1;
1144 break;
1145 case 3:
1146 params->pdiv = 2;
1147 break;
1148 case 7:
1149 params->pdiv = 4;
1150 break;
1151 default:
1152 WARN(1, "Incorrect PDiv\n");
1153 }
1154
1155 switch (p2) {
1156 case 5:
1157 params->kdiv = 0;
1158 break;
1159 case 2:
1160 params->kdiv = 1;
1161 break;
1162 case 3:
1163 params->kdiv = 2;
1164 break;
1165 case 1:
1166 params->kdiv = 3;
1167 break;
1168 default:
1169 WARN(1, "Incorrect KDiv\n");
1170 }
1171
1172 params->qdiv_ratio = p1;
1173 params->qdiv_mode = (params->qdiv_ratio == 1) ? 0 : 1;
1174
1175 dco_freq = p0 * p1 * p2 * afe_clock;
1176
1177 /*
1178 * Intermediate values are in Hz.
1179 * Divide by MHz to match bsepc
1180 */
Damien Lespiau30a78622015-05-07 18:38:43 +01001181 params->dco_integer = div_u64(dco_freq, 24 * MHz(1));
Damien Lespiau76516fb2015-05-07 18:38:42 +01001182 params->dco_fraction =
Damien Lespiau30a78622015-05-07 18:38:43 +01001183 div_u64((div_u64(dco_freq, 24) -
1184 params->dco_integer * MHz(1)) * 0x8000, MHz(1));
Damien Lespiau76516fb2015-05-07 18:38:42 +01001185}
1186
Damien Lespiau318bd822015-05-07 18:38:40 +01001187static bool
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001188skl_ddi_calculate_wrpll(int clock /* in Hz */,
1189 struct skl_wrpll_params *wrpll_params)
1190{
1191 uint64_t afe_clock = clock * 5; /* AFE Clock is 5x Pixel clock */
Damien Lespiau21318cc2014-11-14 14:20:27 +00001192 uint64_t dco_central_freq[3] = {8400000000ULL,
1193 9000000000ULL,
1194 9600000000ULL};
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001195 uint32_t min_dco_deviation = 400;
1196 uint32_t min_dco_index = 3;
1197 uint32_t P0[4] = {1, 2, 3, 7};
1198 uint32_t P2[4] = {1, 2, 3, 5};
1199 bool found = false;
1200 uint32_t candidate_p = 0;
1201 uint32_t candidate_p0[3] = {0}, candidate_p1[3] = {0};
1202 uint32_t candidate_p2[3] = {0};
1203 uint32_t dco_central_freq_deviation[3];
1204 uint32_t i, P1, k, dco_count;
1205 bool retry_with_odd = false;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001206
1207 /* Determine P0, P1 or P2 */
1208 for (dco_count = 0; dco_count < 3; dco_count++) {
1209 found = false;
1210 candidate_p =
1211 div64_u64(dco_central_freq[dco_count], afe_clock);
1212 if (retry_with_odd == false)
1213 candidate_p = (candidate_p % 2 == 0 ?
1214 candidate_p : candidate_p + 1);
1215
1216 for (P1 = 1; P1 < candidate_p; P1++) {
1217 for (i = 0; i < 4; i++) {
1218 if (!(P0[i] != 1 || P1 == 1))
1219 continue;
1220
1221 for (k = 0; k < 4; k++) {
1222 if (P1 != 1 && P2[k] != 2)
1223 continue;
1224
1225 if (candidate_p == P0[i] * P1 * P2[k]) {
1226 /* Found possible P0, P1, P2 */
1227 found = true;
1228 candidate_p0[dco_count] = P0[i];
1229 candidate_p1[dco_count] = P1;
1230 candidate_p2[dco_count] = P2[k];
1231 goto found;
1232 }
1233
1234 }
1235 }
1236 }
1237
1238found:
1239 if (found) {
1240 dco_central_freq_deviation[dco_count] =
1241 div64_u64(10000 *
1242 abs_diff((candidate_p * afe_clock),
1243 dco_central_freq[dco_count]),
1244 dco_central_freq[dco_count]);
1245
1246 if (dco_central_freq_deviation[dco_count] <
1247 min_dco_deviation) {
1248 min_dco_deviation =
1249 dco_central_freq_deviation[dco_count];
1250 min_dco_index = dco_count;
1251 }
1252 }
1253
1254 if (min_dco_index > 2 && dco_count == 2) {
Damien Lespiau6cf75172015-05-07 18:38:38 +01001255 /* oh well, we tried... */
1256 if (retry_with_odd)
1257 break;
1258
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001259 retry_with_odd = true;
1260 dco_count = 0;
1261 }
1262 }
1263
Damien Lespiau9c236752015-05-07 18:38:41 +01001264 if (WARN(min_dco_index > 2,
1265 "No valid parameters found for pixel clock: %dHz\n", clock))
Damien Lespiau318bd822015-05-07 18:38:40 +01001266 return false;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001267
Damien Lespiau76516fb2015-05-07 18:38:42 +01001268 skl_wrpll_params_populate(wrpll_params,
1269 afe_clock,
1270 dco_central_freq[min_dco_index],
1271 candidate_p0[min_dco_index],
1272 candidate_p1[min_dco_index],
1273 candidate_p2[min_dco_index]);
Damien Lespiau9c236752015-05-07 18:38:41 +01001274
Damien Lespiau318bd822015-05-07 18:38:40 +01001275 return true;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001276}
1277
1278
1279static bool
1280skl_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001281 struct intel_crtc_state *crtc_state,
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001282 struct intel_encoder *intel_encoder,
1283 int clock)
1284{
1285 struct intel_shared_dpll *pll;
1286 uint32_t ctrl1, cfgcr1, cfgcr2;
1287
1288 /*
1289 * See comment in intel_dpll_hw_state to understand why we always use 0
1290 * as the DPLL id in this function.
1291 */
1292
1293 ctrl1 = DPLL_CTRL1_OVERRIDE(0);
1294
1295 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
1296 struct skl_wrpll_params wrpll_params = { 0, };
1297
1298 ctrl1 |= DPLL_CTRL1_HDMI_MODE(0);
1299
Damien Lespiau318bd822015-05-07 18:38:40 +01001300 if (!skl_ddi_calculate_wrpll(clock * 1000, &wrpll_params))
1301 return false;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001302
1303 cfgcr1 = DPLL_CFGCR1_FREQ_ENABLE |
1304 DPLL_CFGCR1_DCO_FRACTION(wrpll_params.dco_fraction) |
1305 wrpll_params.dco_integer;
1306
1307 cfgcr2 = DPLL_CFGCR2_QDIV_RATIO(wrpll_params.qdiv_ratio) |
1308 DPLL_CFGCR2_QDIV_MODE(wrpll_params.qdiv_mode) |
1309 DPLL_CFGCR2_KDIV(wrpll_params.kdiv) |
1310 DPLL_CFGCR2_PDIV(wrpll_params.pdiv) |
1311 wrpll_params.central_freq;
1312 } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) {
1313 struct drm_encoder *encoder = &intel_encoder->base;
1314 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1315
1316 switch (intel_dp->link_bw) {
1317 case DP_LINK_BW_1_62:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001318 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, 0);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001319 break;
1320 case DP_LINK_BW_2_7:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001321 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350, 0);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001322 break;
1323 case DP_LINK_BW_5_4:
Damien Lespiau71cd8422015-04-30 16:39:17 +01001324 ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700, 0);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001325 break;
1326 }
1327
1328 cfgcr1 = cfgcr2 = 0;
1329 } else /* eDP */
1330 return true;
1331
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03001332 memset(&crtc_state->dpll_hw_state, 0,
1333 sizeof(crtc_state->dpll_hw_state));
1334
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001335 crtc_state->dpll_hw_state.ctrl1 = ctrl1;
1336 crtc_state->dpll_hw_state.cfgcr1 = cfgcr1;
1337 crtc_state->dpll_hw_state.cfgcr2 = cfgcr2;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001338
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001339 pll = intel_get_shared_dpll(intel_crtc, crtc_state);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001340 if (pll == NULL) {
1341 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1342 pipe_name(intel_crtc->pipe));
1343 return false;
1344 }
1345
1346 /* shared DPLL id 0 is DPLL 1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001347 crtc_state->ddi_pll_sel = pll->id + 1;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001348
1349 return true;
1350}
Damien Lespiau0220ab62014-07-29 18:06:22 +01001351
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301352/* bxt clock parameters */
1353struct bxt_clk_div {
1354 uint32_t p1;
1355 uint32_t p2;
1356 uint32_t m2_int;
1357 uint32_t m2_frac;
1358 bool m2_frac_en;
1359 uint32_t n;
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301360};
1361
1362/* pre-calculated values for DP linkrates */
1363static struct bxt_clk_div bxt_dp_clk_val[7] = {
Vandana Kannane0681e32015-05-13 12:20:35 +05301364 /* 162 */ {4, 2, 32, 1677722, 1, 1},
1365 /* 270 */ {4, 1, 27, 0, 0, 1},
1366 /* 540 */ {2, 1, 27, 0, 0, 1},
1367 /* 216 */ {3, 2, 32, 1677722, 1, 1},
1368 /* 243 */ {4, 1, 24, 1258291, 1, 1},
1369 /* 324 */ {4, 1, 32, 1677722, 1, 1},
1370 /* 432 */ {3, 1, 32, 1677722, 1, 1}
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301371};
1372
1373static bool
1374bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
1375 struct intel_crtc_state *crtc_state,
1376 struct intel_encoder *intel_encoder,
1377 int clock)
1378{
1379 struct intel_shared_dpll *pll;
1380 struct bxt_clk_div clk_div = {0};
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05301381 int vco = 0;
1382 uint32_t prop_coef, int_coef, gain_ctl, targ_cnt;
Vandana Kannane0681e32015-05-13 12:20:35 +05301383 uint32_t dcoampovr_en_h, dco_amp, lanestagger;
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301384
1385 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
1386 intel_clock_t best_clock;
1387
1388 /* Calculate HDMI div */
1389 /*
1390 * FIXME: tie the following calculation into
1391 * i9xx_crtc_compute_clock
1392 */
1393 if (!bxt_find_best_dpll(crtc_state, clock, &best_clock)) {
1394 DRM_DEBUG_DRIVER("no PLL dividers found for clock %d pipe %c\n",
1395 clock, pipe_name(intel_crtc->pipe));
1396 return false;
1397 }
1398
1399 clk_div.p1 = best_clock.p1;
1400 clk_div.p2 = best_clock.p2;
1401 WARN_ON(best_clock.m1 != 2);
1402 clk_div.n = best_clock.n;
1403 clk_div.m2_int = best_clock.m2 >> 22;
1404 clk_div.m2_frac = best_clock.m2 & ((1 << 22) - 1);
1405 clk_div.m2_frac_en = clk_div.m2_frac != 0;
1406
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05301407 vco = best_clock.vco;
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301408 } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
1409 intel_encoder->type == INTEL_OUTPUT_EDP) {
1410 struct drm_encoder *encoder = &intel_encoder->base;
1411 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1412
1413 switch (intel_dp->link_bw) {
1414 case DP_LINK_BW_1_62:
1415 clk_div = bxt_dp_clk_val[0];
1416 break;
1417 case DP_LINK_BW_2_7:
1418 clk_div = bxt_dp_clk_val[1];
1419 break;
1420 case DP_LINK_BW_5_4:
1421 clk_div = bxt_dp_clk_val[2];
1422 break;
1423 default:
1424 clk_div = bxt_dp_clk_val[0];
1425 DRM_ERROR("Unknown link rate\n");
1426 }
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05301427 vco = clock * 10 / 2 * clk_div.p1 * clk_div.p2;
1428 }
1429
1430 dco_amp = 15;
1431 dcoampovr_en_h = 0;
1432 if (vco >= 6200000 && vco <= 6480000) {
1433 prop_coef = 4;
1434 int_coef = 9;
1435 gain_ctl = 3;
1436 targ_cnt = 8;
1437 } else if ((vco > 5400000 && vco < 6200000) ||
1438 (vco >= 4800000 && vco < 5400000)) {
1439 prop_coef = 5;
1440 int_coef = 11;
1441 gain_ctl = 3;
1442 targ_cnt = 9;
1443 if (vco >= 4800000 && vco < 5400000)
1444 dcoampovr_en_h = 1;
1445 } else if (vco == 5400000) {
1446 prop_coef = 3;
1447 int_coef = 8;
1448 gain_ctl = 1;
1449 targ_cnt = 9;
1450 } else {
1451 DRM_ERROR("Invalid VCO\n");
1452 return false;
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301453 }
1454
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03001455 memset(&crtc_state->dpll_hw_state, 0,
1456 sizeof(crtc_state->dpll_hw_state));
1457
Vandana Kannane0681e32015-05-13 12:20:35 +05301458 if (clock > 270000)
1459 lanestagger = 0x18;
1460 else if (clock > 135000)
1461 lanestagger = 0x0d;
1462 else if (clock > 67000)
1463 lanestagger = 0x07;
1464 else if (clock > 33000)
1465 lanestagger = 0x04;
1466 else
1467 lanestagger = 0x02;
1468
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301469 crtc_state->dpll_hw_state.ebb0 =
1470 PORT_PLL_P1(clk_div.p1) | PORT_PLL_P2(clk_div.p2);
1471 crtc_state->dpll_hw_state.pll0 = clk_div.m2_int;
1472 crtc_state->dpll_hw_state.pll1 = PORT_PLL_N(clk_div.n);
1473 crtc_state->dpll_hw_state.pll2 = clk_div.m2_frac;
1474
1475 if (clk_div.m2_frac_en)
1476 crtc_state->dpll_hw_state.pll3 =
1477 PORT_PLL_M2_FRAC_ENABLE;
1478
1479 crtc_state->dpll_hw_state.pll6 =
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05301480 prop_coef | PORT_PLL_INT_COEFF(int_coef);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301481 crtc_state->dpll_hw_state.pll6 |=
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05301482 PORT_PLL_GAIN_CTL(gain_ctl);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301483
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05301484 crtc_state->dpll_hw_state.pll8 = targ_cnt;
1485
1486 if (dcoampovr_en_h)
1487 crtc_state->dpll_hw_state.pll10 = PORT_PLL_DCO_AMP_OVR_EN_H;
1488
1489 crtc_state->dpll_hw_state.pll10 |= PORT_PLL_DCO_AMP(dco_amp);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301490
1491 crtc_state->dpll_hw_state.pcsdw12 =
Vandana Kannane0681e32015-05-13 12:20:35 +05301492 LANESTAGGER_STRAP_OVRD | lanestagger;
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301493
1494 pll = intel_get_shared_dpll(intel_crtc, crtc_state);
1495 if (pll == NULL) {
1496 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1497 pipe_name(intel_crtc->pipe));
1498 return false;
1499 }
1500
1501 /* shared DPLL id 0 is DPLL A */
1502 crtc_state->ddi_pll_sel = pll->id;
1503
1504 return true;
1505}
1506
Damien Lespiau0220ab62014-07-29 18:06:22 +01001507/*
1508 * Tries to find a *shared* PLL for the CRTC and store it in
1509 * intel_crtc->ddi_pll_sel.
1510 *
1511 * For private DPLLs, compute_config() should do the selection for us. This
1512 * function should be folded into compute_config() eventually.
1513 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001514bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
1515 struct intel_crtc_state *crtc_state)
Damien Lespiau0220ab62014-07-29 18:06:22 +01001516{
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001517 struct drm_device *dev = intel_crtc->base.dev;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001518 struct intel_encoder *intel_encoder =
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001519 intel_ddi_get_crtc_new_encoder(crtc_state);
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001520 int clock = crtc_state->port_clock;
Damien Lespiau0220ab62014-07-29 18:06:22 +01001521
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001522 if (IS_SKYLAKE(dev))
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001523 return skl_ddi_pll_select(intel_crtc, crtc_state,
1524 intel_encoder, clock);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301525 else if (IS_BROXTON(dev))
1526 return bxt_ddi_pll_select(intel_crtc, crtc_state,
1527 intel_encoder, clock);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001528 else
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001529 return hsw_ddi_pll_select(intel_crtc, crtc_state,
1530 intel_encoder, clock);
Damien Lespiau0220ab62014-07-29 18:06:22 +01001531}
1532
Paulo Zanonidae84792012-10-15 15:51:30 -03001533void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
1534{
1535 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1536 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1537 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001538 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -03001539 int type = intel_encoder->type;
1540 uint32_t temp;
1541
Dave Airlie0e32b392014-05-02 14:02:48 +10001542 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Paulo Zanonic9809792012-10-23 18:30:00 -02001543 temp = TRANS_MSA_SYNC_CLK;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001544 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -03001545 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -02001546 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001547 break;
1548 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -02001549 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001550 break;
1551 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -02001552 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001553 break;
1554 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -02001555 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001556 break;
1557 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001558 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -03001559 }
Paulo Zanonic9809792012-10-23 18:30:00 -02001560 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -03001561 }
1562}
1563
Dave Airlie0e32b392014-05-02 14:02:48 +10001564void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
1565{
1566 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1567 struct drm_device *dev = crtc->dev;
1568 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001569 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +10001570 uint32_t temp;
1571 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1572 if (state == true)
1573 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1574 else
1575 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1576 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1577}
1578
Damien Lespiau8228c252013-03-07 15:30:27 +00001579void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001580{
1581 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1582 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001583 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -07001584 struct drm_device *dev = crtc->dev;
1585 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001586 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001587 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001588 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001589 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001590 uint32_t temp;
1591
Paulo Zanoniad80a812012-10-24 16:06:19 -02001592 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1593 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001594 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001595
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001596 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001597 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001598 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001599 break;
1600 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001601 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001602 break;
1603 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001604 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001605 break;
1606 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001607 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001608 break;
1609 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001610 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001611 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001612
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001613 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001614 temp |= TRANS_DDI_PVSYNC;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001615 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001616 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c2012-08-08 14:15:28 -03001617
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001618 if (cpu_transcoder == TRANSCODER_EDP) {
1619 switch (pipe) {
1620 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001621 /* On Haswell, can only use the always-on power well for
1622 * eDP when not using the panel fitter, and when not
1623 * using motion blur mitigation (which we don't
1624 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +02001625 if (IS_HASWELL(dev) &&
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001626 (intel_crtc->config->pch_pfit.enabled ||
1627 intel_crtc->config->pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001628 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1629 else
1630 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001631 break;
1632 case PIPE_B:
1633 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1634 break;
1635 case PIPE_C:
1636 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1637 break;
1638 default:
1639 BUG();
1640 break;
1641 }
1642 }
1643
Paulo Zanoni7739c332012-10-15 15:51:29 -03001644 if (type == INTEL_OUTPUT_HDMI) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001645 if (intel_crtc->config->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001646 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001647 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001648 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001649
Paulo Zanoni7739c332012-10-15 15:51:29 -03001650 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001651 temp |= TRANS_DDI_MODE_SELECT_FDI;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001652 temp |= (intel_crtc->config->fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001653
1654 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
1655 type == INTEL_OUTPUT_EDP) {
1656 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1657
Dave Airlie0e32b392014-05-02 14:02:48 +10001658 if (intel_dp->is_mst) {
1659 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
1660 } else
1661 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
1662
1663 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
1664 } else if (type == INTEL_OUTPUT_DP_MST) {
1665 struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
1666
1667 if (intel_dp->is_mst) {
1668 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
1669 } else
1670 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001671
Daniel Vetter17aa6be2013-04-30 14:01:40 +02001672 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001673 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001674 WARN(1, "Invalid encoder type %d for pipe %c\n",
1675 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001676 }
1677
Paulo Zanoniad80a812012-10-24 16:06:19 -02001678 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001679}
1680
Paulo Zanoniad80a812012-10-24 16:06:19 -02001681void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1682 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001683{
Paulo Zanoniad80a812012-10-24 16:06:19 -02001684 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001685 uint32_t val = I915_READ(reg);
1686
Dave Airlie0e32b392014-05-02 14:02:48 +10001687 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -02001688 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001689 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001690}
1691
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001692bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1693{
1694 struct drm_device *dev = intel_connector->base.dev;
1695 struct drm_i915_private *dev_priv = dev->dev_private;
1696 struct intel_encoder *intel_encoder = intel_connector->encoder;
1697 int type = intel_connector->base.connector_type;
1698 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1699 enum pipe pipe = 0;
1700 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -03001701 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001702 uint32_t tmp;
1703
Paulo Zanoni882244a2014-04-01 14:55:12 -03001704 power_domain = intel_display_port_power_domain(intel_encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001705 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Paulo Zanoni882244a2014-04-01 14:55:12 -03001706 return false;
1707
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001708 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
1709 return false;
1710
1711 if (port == PORT_A)
1712 cpu_transcoder = TRANSCODER_EDP;
1713 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001714 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001715
1716 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1717
1718 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1719 case TRANS_DDI_MODE_SELECT_HDMI:
1720 case TRANS_DDI_MODE_SELECT_DVI:
1721 return (type == DRM_MODE_CONNECTOR_HDMIA);
1722
1723 case TRANS_DDI_MODE_SELECT_DP_SST:
1724 if (type == DRM_MODE_CONNECTOR_eDP)
1725 return true;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001726 return (type == DRM_MODE_CONNECTOR_DisplayPort);
Dave Airlie0e32b392014-05-02 14:02:48 +10001727 case TRANS_DDI_MODE_SELECT_DP_MST:
1728 /* if the transcoder is in MST state then
1729 * connector isn't connected */
1730 return false;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001731
1732 case TRANS_DDI_MODE_SELECT_FDI:
1733 return (type == DRM_MODE_CONNECTOR_VGA);
1734
1735 default:
1736 return false;
1737 }
1738}
1739
Daniel Vetter85234cd2012-07-02 13:27:29 +02001740bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1741 enum pipe *pipe)
1742{
1743 struct drm_device *dev = encoder->base.dev;
1744 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001745 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001746 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001747 u32 tmp;
1748 int i;
1749
Imre Deak6d129be2014-03-05 16:20:54 +02001750 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001751 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001752 return false;
1753
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001754 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001755
1756 if (!(tmp & DDI_BUF_CTL_ENABLE))
1757 return false;
1758
Paulo Zanoniad80a812012-10-24 16:06:19 -02001759 if (port == PORT_A) {
1760 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001761
Paulo Zanoniad80a812012-10-24 16:06:19 -02001762 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1763 case TRANS_DDI_EDP_INPUT_A_ON:
1764 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1765 *pipe = PIPE_A;
1766 break;
1767 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1768 *pipe = PIPE_B;
1769 break;
1770 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1771 *pipe = PIPE_C;
1772 break;
1773 }
1774
1775 return true;
1776 } else {
1777 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1778 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1779
1780 if ((tmp & TRANS_DDI_PORT_MASK)
1781 == TRANS_DDI_SELECT_PORT(port)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10001782 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST)
1783 return false;
1784
Paulo Zanoniad80a812012-10-24 16:06:19 -02001785 *pipe = i;
1786 return true;
1787 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001788 }
1789 }
1790
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001791 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001792
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001793 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001794}
1795
Paulo Zanonifc914632012-10-05 12:05:54 -03001796void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1797{
1798 struct drm_crtc *crtc = &intel_crtc->base;
1799 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1800 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1801 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001802 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001803
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001804 if (cpu_transcoder != TRANSCODER_EDP)
1805 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1806 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001807}
1808
1809void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1810{
1811 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001812 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001813
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001814 if (cpu_transcoder != TRANSCODER_EDP)
1815 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1816 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001817}
1818
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301819void bxt_ddi_vswing_sequence(struct drm_device *dev, u32 level,
1820 enum port port, int type)
1821{
1822 struct drm_i915_private *dev_priv = dev->dev_private;
1823 const struct bxt_ddi_buf_trans *ddi_translations;
1824 u32 n_entries, i;
1825 uint32_t val;
1826
1827 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
1828 n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
1829 ddi_translations = bxt_ddi_translations_dp;
1830 } else if (type == INTEL_OUTPUT_HDMI) {
1831 n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
1832 ddi_translations = bxt_ddi_translations_hdmi;
1833 } else {
1834 DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
1835 type);
1836 return;
1837 }
1838
1839 /* Check if default value has to be used */
1840 if (level >= n_entries ||
1841 (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
1842 for (i = 0; i < n_entries; i++) {
1843 if (ddi_translations[i].default_index) {
1844 level = i;
1845 break;
1846 }
1847 }
1848 }
1849
1850 /*
1851 * While we write to the group register to program all lanes at once we
1852 * can read only lane registers and we pick lanes 0/1 for that.
1853 */
1854 val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
1855 val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
1856 I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
1857
1858 val = I915_READ(BXT_PORT_TX_DW2_LN0(port));
1859 val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
1860 val |= ddi_translations[level].margin << MARGIN_000_SHIFT |
1861 ddi_translations[level].scale << UNIQ_TRANS_SCALE_SHIFT;
1862 I915_WRITE(BXT_PORT_TX_DW2_GRP(port), val);
1863
1864 val = I915_READ(BXT_PORT_TX_DW3_LN0(port));
1865 val &= ~UNIQE_TRANGE_EN_METHOD;
1866 if (ddi_translations[level].enable)
1867 val |= UNIQE_TRANGE_EN_METHOD;
1868 I915_WRITE(BXT_PORT_TX_DW3_GRP(port), val);
1869
1870 val = I915_READ(BXT_PORT_TX_DW4_LN0(port));
1871 val &= ~DE_EMPHASIS;
1872 val |= ddi_translations[level].deemphasis << DEEMPH_SHIFT;
1873 I915_WRITE(BXT_PORT_TX_DW4_GRP(port), val);
1874
1875 val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
1876 val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
1877 I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
1878}
1879
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001880static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001881{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001882 struct drm_encoder *encoder = &intel_encoder->base;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001883 struct drm_device *dev = encoder->dev;
1884 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001885 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001886 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001887 int type = intel_encoder->type;
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301888 int hdmi_level;
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001889
1890 if (type == INTEL_OUTPUT_EDP) {
1891 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001892 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001893 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001894
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001895 if (IS_SKYLAKE(dev)) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001896 uint32_t dpll = crtc->config->ddi_pll_sel;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001897 uint32_t val;
1898
Damien Lespiau5416d872014-11-14 17:24:33 +00001899 /*
1900 * DPLL0 is used for eDP and is the only "private" DPLL (as
1901 * opposed to shared) on SKL
1902 */
1903 if (type == INTEL_OUTPUT_EDP) {
1904 WARN_ON(dpll != SKL_DPLL0);
1905
1906 val = I915_READ(DPLL_CTRL1);
1907
1908 val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) |
1909 DPLL_CTRL1_SSC(dpll) |
Damien Lespiau71cd8422015-04-30 16:39:17 +01001910 DPLL_CTRL1_LINK_RATE_MASK(dpll));
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001911 val |= crtc->config->dpll_hw_state.ctrl1 << (dpll * 6);
Damien Lespiau5416d872014-11-14 17:24:33 +00001912
1913 I915_WRITE(DPLL_CTRL1, val);
1914 POSTING_READ(DPLL_CTRL1);
1915 }
1916
1917 /* DDI -> PLL mapping */
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001918 val = I915_READ(DPLL_CTRL2);
1919
1920 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
1921 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
1922 val |= (DPLL_CTRL2_DDI_CLK_SEL(dpll, port) |
1923 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
1924
1925 I915_WRITE(DPLL_CTRL2, val);
Damien Lespiau5416d872014-11-14 17:24:33 +00001926
Satheeshakrishna M1ab23382014-08-22 09:49:06 +05301927 } else if (INTEL_INFO(dev)->gen < 9) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001928 WARN_ON(crtc->config->ddi_pll_sel == PORT_CLK_SEL_NONE);
1929 I915_WRITE(PORT_CLK_SEL(port), crtc->config->ddi_pll_sel);
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001930 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03001931
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001932 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001933 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001934
Dave Airlie44905a22014-05-02 13:36:43 +10001935 intel_ddi_init_dp_buf_reg(intel_encoder);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001936
1937 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1938 intel_dp_start_link_train(intel_dp);
1939 intel_dp_complete_link_train(intel_dp);
Vandana Kannan23f08d82014-11-13 14:55:22 +00001940 if (port != PORT_A || INTEL_INFO(dev)->gen >= 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03001941 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001942 } else if (type == INTEL_OUTPUT_HDMI) {
1943 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1944
Vandana Kannan96fb9f92014-11-18 15:45:27 +05301945 if (IS_BROXTON(dev)) {
1946 hdmi_level = dev_priv->vbt.
1947 ddi_port_info[port].hdmi_level_shift;
1948 bxt_ddi_vswing_sequence(dev, hdmi_level, port,
1949 INTEL_OUTPUT_HDMI);
1950 }
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001951 intel_hdmi->set_infoframes(encoder,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001952 crtc->config->has_hdmi_sink,
1953 &crtc->config->base.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001954 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001955}
1956
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001957static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001958{
1959 struct drm_encoder *encoder = &intel_encoder->base;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001960 struct drm_device *dev = encoder->dev;
1961 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001962 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001963 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001964 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001965 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001966
1967 val = I915_READ(DDI_BUF_CTL(port));
1968 if (val & DDI_BUF_CTL_ENABLE) {
1969 val &= ~DDI_BUF_CTL_ENABLE;
1970 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001971 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001972 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001973
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001974 val = I915_READ(DP_TP_CTL(port));
1975 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1976 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1977 I915_WRITE(DP_TP_CTL(port), val);
1978
1979 if (wait)
1980 intel_wait_ddi_buf_idle(dev_priv, port);
1981
Jani Nikula76bb80e2013-11-15 15:29:57 +02001982 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001983 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001984 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001985 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001986 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001987 }
1988
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001989 if (IS_SKYLAKE(dev))
1990 I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
1991 DPLL_CTRL2_DDI_CLK_OFF(port)));
Satheeshakrishna M1ab23382014-08-22 09:49:06 +05301992 else if (INTEL_INFO(dev)->gen < 9)
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001993 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001994}
1995
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001996static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001997{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001998 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001999 struct drm_crtc *crtc = encoder->crtc;
2000 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002001 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002002 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002003 enum port port = intel_ddi_get_encoder_port(intel_encoder);
2004 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002005
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002006 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002007 struct intel_digital_port *intel_dig_port =
2008 enc_to_dig_port(encoder);
2009
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002010 /* In HDMI/DVI mode, the port width, and swing/emphasis values
2011 * are ignored so nothing special needs to be done besides
2012 * enabling the port.
2013 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002014 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07002015 intel_dig_port->saved_port_bits |
2016 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002017 } else if (type == INTEL_OUTPUT_EDP) {
2018 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2019
Vandana Kannan23f08d82014-11-13 14:55:22 +00002020 if (port == PORT_A && INTEL_INFO(dev)->gen < 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03002021 intel_dp_stop_link_train(intel_dp);
2022
Daniel Vetter4be73782014-01-17 14:39:48 +01002023 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08002024 intel_psr_enable(intel_dp);
Vandana Kannanc3955782015-01-22 15:17:40 +05302025 intel_edp_drrs_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03002026 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08002027
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002028 if (intel_crtc->config->has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03002029 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Jani Nikula69bfe1a2014-10-27 16:26:50 +02002030 intel_audio_codec_enable(intel_encoder);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08002031 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002032}
2033
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002034static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002035{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002036 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08002037 struct drm_crtc *crtc = encoder->crtc;
2038 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002039 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08002040 struct drm_device *dev = encoder->dev;
2041 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002042
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002043 if (intel_crtc->config->has_audio) {
Jani Nikula69bfe1a2014-10-27 16:26:50 +02002044 intel_audio_codec_disable(intel_encoder);
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03002045 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
2046 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03002047
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002048 if (type == INTEL_OUTPUT_EDP) {
2049 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2050
Vandana Kannanc3955782015-01-22 15:17:40 +05302051 intel_edp_drrs_disable(intel_dp);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08002052 intel_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01002053 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02002054 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03002055}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002056
Daniel Vettere0b01be2014-06-25 22:02:01 +03002057static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv,
2058 struct intel_shared_dpll *pll)
2059{
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002060 I915_WRITE(WRPLL_CTL(pll->id), pll->config.hw_state.wrpll);
Daniel Vettere0b01be2014-06-25 22:02:01 +03002061 POSTING_READ(WRPLL_CTL(pll->id));
2062 udelay(20);
2063}
2064
Daniel Vetter12030432014-06-25 22:02:00 +03002065static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv,
2066 struct intel_shared_dpll *pll)
2067{
2068 uint32_t val;
2069
2070 val = I915_READ(WRPLL_CTL(pll->id));
Daniel Vetter12030432014-06-25 22:02:00 +03002071 I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
2072 POSTING_READ(WRPLL_CTL(pll->id));
2073}
2074
Daniel Vetterd452c5b2014-07-04 11:27:39 -03002075static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
2076 struct intel_shared_dpll *pll,
2077 struct intel_dpll_hw_state *hw_state)
2078{
2079 uint32_t val;
2080
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002081 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
Daniel Vetterd452c5b2014-07-04 11:27:39 -03002082 return false;
2083
2084 val = I915_READ(WRPLL_CTL(pll->id));
2085 hw_state->wrpll = val;
2086
2087 return val & WRPLL_PLL_ENABLE;
2088}
2089
Damien Lespiauca1381b2014-07-15 15:05:33 +01002090static const char * const hsw_ddi_pll_names[] = {
Daniel Vetter9cd86932014-06-25 22:01:57 +03002091 "WRPLL 1",
2092 "WRPLL 2",
2093};
2094
Damien Lespiau143b3072014-07-29 18:06:19 +01002095static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002096{
Daniel Vetter9cd86932014-06-25 22:01:57 +03002097 int i;
2098
Daniel Vetter716c2e52014-06-25 22:02:02 +03002099 dev_priv->num_shared_dpll = 2;
Daniel Vetter9cd86932014-06-25 22:01:57 +03002100
Daniel Vetter716c2e52014-06-25 22:02:02 +03002101 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
Daniel Vetter9cd86932014-06-25 22:01:57 +03002102 dev_priv->shared_dplls[i].id = i;
2103 dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
Daniel Vetter12030432014-06-25 22:02:00 +03002104 dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable;
Daniel Vettere0b01be2014-06-25 22:02:01 +03002105 dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable;
Daniel Vetterd452c5b2014-07-04 11:27:39 -03002106 dev_priv->shared_dplls[i].get_hw_state =
2107 hsw_ddi_pll_get_hw_state;
Daniel Vetter9cd86932014-06-25 22:01:57 +03002108 }
Damien Lespiau143b3072014-07-29 18:06:19 +01002109}
2110
Satheeshakrishna Md1a2dc72014-11-13 14:55:18 +00002111static const char * const skl_ddi_pll_names[] = {
2112 "DPLL 1",
2113 "DPLL 2",
2114 "DPLL 3",
2115};
2116
2117struct skl_dpll_regs {
2118 u32 ctl, cfgcr1, cfgcr2;
2119};
2120
2121/* this array is indexed by the *shared* pll id */
2122static const struct skl_dpll_regs skl_dpll_regs[3] = {
2123 {
2124 /* DPLL 1 */
2125 .ctl = LCPLL2_CTL,
2126 .cfgcr1 = DPLL1_CFGCR1,
2127 .cfgcr2 = DPLL1_CFGCR2,
2128 },
2129 {
2130 /* DPLL 2 */
2131 .ctl = WRPLL_CTL1,
2132 .cfgcr1 = DPLL2_CFGCR1,
2133 .cfgcr2 = DPLL2_CFGCR2,
2134 },
2135 {
2136 /* DPLL 3 */
2137 .ctl = WRPLL_CTL2,
2138 .cfgcr1 = DPLL3_CFGCR1,
2139 .cfgcr2 = DPLL3_CFGCR2,
2140 },
2141};
2142
2143static void skl_ddi_pll_enable(struct drm_i915_private *dev_priv,
2144 struct intel_shared_dpll *pll)
2145{
2146 uint32_t val;
2147 unsigned int dpll;
2148 const struct skl_dpll_regs *regs = skl_dpll_regs;
2149
2150 /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */
2151 dpll = pll->id + 1;
2152
2153 val = I915_READ(DPLL_CTRL1);
2154
2155 val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) | DPLL_CTRL1_SSC(dpll) |
Damien Lespiau71cd8422015-04-30 16:39:17 +01002156 DPLL_CTRL1_LINK_RATE_MASK(dpll));
Satheeshakrishna Md1a2dc72014-11-13 14:55:18 +00002157 val |= pll->config.hw_state.ctrl1 << (dpll * 6);
2158
2159 I915_WRITE(DPLL_CTRL1, val);
2160 POSTING_READ(DPLL_CTRL1);
2161
2162 I915_WRITE(regs[pll->id].cfgcr1, pll->config.hw_state.cfgcr1);
2163 I915_WRITE(regs[pll->id].cfgcr2, pll->config.hw_state.cfgcr2);
2164 POSTING_READ(regs[pll->id].cfgcr1);
2165 POSTING_READ(regs[pll->id].cfgcr2);
2166
2167 /* the enable bit is always bit 31 */
2168 I915_WRITE(regs[pll->id].ctl,
2169 I915_READ(regs[pll->id].ctl) | LCPLL_PLL_ENABLE);
2170
2171 if (wait_for(I915_READ(DPLL_STATUS) & DPLL_LOCK(dpll), 5))
2172 DRM_ERROR("DPLL %d not locked\n", dpll);
2173}
2174
2175static void skl_ddi_pll_disable(struct drm_i915_private *dev_priv,
2176 struct intel_shared_dpll *pll)
2177{
2178 const struct skl_dpll_regs *regs = skl_dpll_regs;
2179
2180 /* the enable bit is always bit 31 */
2181 I915_WRITE(regs[pll->id].ctl,
2182 I915_READ(regs[pll->id].ctl) & ~LCPLL_PLL_ENABLE);
2183 POSTING_READ(regs[pll->id].ctl);
2184}
2185
2186static bool skl_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
2187 struct intel_shared_dpll *pll,
2188 struct intel_dpll_hw_state *hw_state)
2189{
2190 uint32_t val;
2191 unsigned int dpll;
2192 const struct skl_dpll_regs *regs = skl_dpll_regs;
2193
2194 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
2195 return false;
2196
2197 /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */
2198 dpll = pll->id + 1;
2199
2200 val = I915_READ(regs[pll->id].ctl);
2201 if (!(val & LCPLL_PLL_ENABLE))
2202 return false;
2203
2204 val = I915_READ(DPLL_CTRL1);
2205 hw_state->ctrl1 = (val >> (dpll * 6)) & 0x3f;
2206
2207 /* avoid reading back stale values if HDMI mode is not enabled */
2208 if (val & DPLL_CTRL1_HDMI_MODE(dpll)) {
2209 hw_state->cfgcr1 = I915_READ(regs[pll->id].cfgcr1);
2210 hw_state->cfgcr2 = I915_READ(regs[pll->id].cfgcr2);
2211 }
2212
2213 return true;
2214}
2215
2216static void skl_shared_dplls_init(struct drm_i915_private *dev_priv)
2217{
2218 int i;
2219
2220 dev_priv->num_shared_dpll = 3;
2221
2222 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2223 dev_priv->shared_dplls[i].id = i;
2224 dev_priv->shared_dplls[i].name = skl_ddi_pll_names[i];
2225 dev_priv->shared_dplls[i].disable = skl_ddi_pll_disable;
2226 dev_priv->shared_dplls[i].enable = skl_ddi_pll_enable;
2227 dev_priv->shared_dplls[i].get_hw_state =
2228 skl_ddi_pll_get_hw_state;
2229 }
2230}
2231
Vandana Kannan5c6706e2014-11-24 13:37:39 +05302232static void broxton_phy_init(struct drm_i915_private *dev_priv,
2233 enum dpio_phy phy)
2234{
2235 enum port port;
2236 uint32_t val;
2237
2238 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
2239 val |= GT_DISPLAY_POWER_ON(phy);
2240 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
2241
2242 /* Considering 10ms timeout until BSpec is updated */
2243 if (wait_for(I915_READ(BXT_PORT_CL1CM_DW0(phy)) & PHY_POWER_GOOD, 10))
2244 DRM_ERROR("timeout during PHY%d power on\n", phy);
2245
2246 for (port = (phy == DPIO_PHY0 ? PORT_B : PORT_A);
2247 port <= (phy == DPIO_PHY0 ? PORT_C : PORT_A); port++) {
2248 int lane;
2249
2250 for (lane = 0; lane < 4; lane++) {
2251 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
2252 /*
2253 * Note that on CHV this flag is called UPAR, but has
2254 * the same function.
2255 */
2256 val &= ~LATENCY_OPTIM;
2257 if (lane != 1)
2258 val |= LATENCY_OPTIM;
2259
2260 I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val);
2261 }
2262 }
2263
2264 /* Program PLL Rcomp code offset */
2265 val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
2266 val &= ~IREF0RC_OFFSET_MASK;
2267 val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
2268 I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
2269
2270 val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
2271 val &= ~IREF1RC_OFFSET_MASK;
2272 val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
2273 I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
2274
2275 /* Program power gating */
2276 val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
2277 val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
2278 SUS_CLK_CONFIG;
2279 I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
2280
2281 if (phy == DPIO_PHY0) {
2282 val = I915_READ(BXT_PORT_CL2CM_DW6_BC);
2283 val |= DW6_OLDO_DYN_PWR_DOWN_EN;
2284 I915_WRITE(BXT_PORT_CL2CM_DW6_BC, val);
2285 }
2286
2287 val = I915_READ(BXT_PORT_CL1CM_DW30(phy));
2288 val &= ~OCL2_LDOFUSE_PWR_DIS;
2289 /*
2290 * On PHY1 disable power on the second channel, since no port is
2291 * connected there. On PHY0 both channels have a port, so leave it
2292 * enabled.
2293 * TODO: port C is only connected on BXT-P, so on BXT0/1 we should
2294 * power down the second channel on PHY0 as well.
2295 */
2296 if (phy == DPIO_PHY1)
2297 val |= OCL2_LDOFUSE_PWR_DIS;
2298 I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val);
2299
2300 if (phy == DPIO_PHY0) {
2301 uint32_t grc_code;
2302 /*
2303 * PHY0 isn't connected to an RCOMP resistor so copy over
2304 * the corresponding calibrated value from PHY1, and disable
2305 * the automatic calibration on PHY0.
2306 */
2307 if (wait_for(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE,
2308 10))
2309 DRM_ERROR("timeout waiting for PHY1 GRC\n");
2310
2311 val = I915_READ(BXT_PORT_REF_DW6(DPIO_PHY1));
2312 val = (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
2313 grc_code = val << GRC_CODE_FAST_SHIFT |
2314 val << GRC_CODE_SLOW_SHIFT |
2315 val;
2316 I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code);
2317
2318 val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0));
2319 val |= GRC_DIS | GRC_RDY_OVRD;
2320 I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val);
2321 }
2322
2323 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
2324 val |= COMMON_RESET_DIS;
2325 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
2326}
2327
2328void broxton_ddi_phy_init(struct drm_device *dev)
2329{
2330 /* Enable PHY1 first since it provides Rcomp for PHY0 */
2331 broxton_phy_init(dev->dev_private, DPIO_PHY1);
2332 broxton_phy_init(dev->dev_private, DPIO_PHY0);
2333}
2334
2335static void broxton_phy_uninit(struct drm_i915_private *dev_priv,
2336 enum dpio_phy phy)
2337{
2338 uint32_t val;
2339
2340 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
2341 val &= ~COMMON_RESET_DIS;
2342 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
2343}
2344
2345void broxton_ddi_phy_uninit(struct drm_device *dev)
2346{
2347 struct drm_i915_private *dev_priv = dev->dev_private;
2348
2349 broxton_phy_uninit(dev_priv, DPIO_PHY1);
2350 broxton_phy_uninit(dev_priv, DPIO_PHY0);
2351
2352 /* FIXME: do this in broxton_phy_uninit per phy */
2353 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, 0);
2354}
2355
Satheeshakrishna Mdfb82402014-08-22 09:49:09 +05302356static const char * const bxt_ddi_pll_names[] = {
2357 "PORT PLL A",
2358 "PORT PLL B",
2359 "PORT PLL C",
2360};
2361
2362static void bxt_ddi_pll_enable(struct drm_i915_private *dev_priv,
2363 struct intel_shared_dpll *pll)
2364{
2365 uint32_t temp;
2366 enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
2367
2368 temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
2369 temp &= ~PORT_PLL_REF_SEL;
2370 /* Non-SSC reference */
2371 I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
2372
2373 /* Disable 10 bit clock */
2374 temp = I915_READ(BXT_PORT_PLL_EBB_4(port));
2375 temp &= ~PORT_PLL_10BIT_CLK_ENABLE;
2376 I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
2377
2378 /* Write P1 & P2 */
2379 temp = I915_READ(BXT_PORT_PLL_EBB_0(port));
2380 temp &= ~(PORT_PLL_P1_MASK | PORT_PLL_P2_MASK);
2381 temp |= pll->config.hw_state.ebb0;
2382 I915_WRITE(BXT_PORT_PLL_EBB_0(port), temp);
2383
2384 /* Write M2 integer */
2385 temp = I915_READ(BXT_PORT_PLL(port, 0));
2386 temp &= ~PORT_PLL_M2_MASK;
2387 temp |= pll->config.hw_state.pll0;
2388 I915_WRITE(BXT_PORT_PLL(port, 0), temp);
2389
2390 /* Write N */
2391 temp = I915_READ(BXT_PORT_PLL(port, 1));
2392 temp &= ~PORT_PLL_N_MASK;
2393 temp |= pll->config.hw_state.pll1;
2394 I915_WRITE(BXT_PORT_PLL(port, 1), temp);
2395
2396 /* Write M2 fraction */
2397 temp = I915_READ(BXT_PORT_PLL(port, 2));
2398 temp &= ~PORT_PLL_M2_FRAC_MASK;
2399 temp |= pll->config.hw_state.pll2;
2400 I915_WRITE(BXT_PORT_PLL(port, 2), temp);
2401
2402 /* Write M2 fraction enable */
2403 temp = I915_READ(BXT_PORT_PLL(port, 3));
2404 temp &= ~PORT_PLL_M2_FRAC_ENABLE;
2405 temp |= pll->config.hw_state.pll3;
2406 I915_WRITE(BXT_PORT_PLL(port, 3), temp);
2407
2408 /* Write coeff */
2409 temp = I915_READ(BXT_PORT_PLL(port, 6));
2410 temp &= ~PORT_PLL_PROP_COEFF_MASK;
2411 temp &= ~PORT_PLL_INT_COEFF_MASK;
2412 temp &= ~PORT_PLL_GAIN_CTL_MASK;
2413 temp |= pll->config.hw_state.pll6;
2414 I915_WRITE(BXT_PORT_PLL(port, 6), temp);
2415
2416 /* Write calibration val */
2417 temp = I915_READ(BXT_PORT_PLL(port, 8));
2418 temp &= ~PORT_PLL_TARGET_CNT_MASK;
2419 temp |= pll->config.hw_state.pll8;
2420 I915_WRITE(BXT_PORT_PLL(port, 8), temp);
2421
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05302422 temp = I915_READ(BXT_PORT_PLL(port, 9));
2423 temp &= ~PORT_PLL_LOCK_THRESHOLD_MASK;
2424 temp |= (5 << 1);
2425 I915_WRITE(BXT_PORT_PLL(port, 9), temp);
2426
2427 temp = I915_READ(BXT_PORT_PLL(port, 10));
2428 temp &= ~PORT_PLL_DCO_AMP_OVR_EN_H;
2429 temp &= ~PORT_PLL_DCO_AMP_MASK;
2430 temp |= pll->config.hw_state.pll10;
2431 I915_WRITE(BXT_PORT_PLL(port, 10), temp);
Satheeshakrishna Mdfb82402014-08-22 09:49:09 +05302432
2433 /* Recalibrate with new settings */
2434 temp = I915_READ(BXT_PORT_PLL_EBB_4(port));
2435 temp |= PORT_PLL_RECALIBRATE;
2436 I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
2437 /* Enable 10 bit clock */
2438 temp |= PORT_PLL_10BIT_CLK_ENABLE;
2439 I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
2440
2441 /* Enable PLL */
2442 temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
2443 temp |= PORT_PLL_ENABLE;
2444 I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
2445 POSTING_READ(BXT_PORT_PLL_ENABLE(port));
2446
2447 if (wait_for_atomic_us((I915_READ(BXT_PORT_PLL_ENABLE(port)) &
2448 PORT_PLL_LOCK), 200))
2449 DRM_ERROR("PLL %d not locked\n", port);
2450
2451 /*
2452 * While we write to the group register to program all lanes at once we
2453 * can read only lane registers and we pick lanes 0/1 for that.
2454 */
2455 temp = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
2456 temp &= ~LANE_STAGGER_MASK;
2457 temp &= ~LANESTAGGER_STRAP_OVRD;
2458 temp |= pll->config.hw_state.pcsdw12;
2459 I915_WRITE(BXT_PORT_PCS_DW12_GRP(port), temp);
2460}
2461
2462static void bxt_ddi_pll_disable(struct drm_i915_private *dev_priv,
2463 struct intel_shared_dpll *pll)
2464{
2465 enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
2466 uint32_t temp;
2467
2468 temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
2469 temp &= ~PORT_PLL_ENABLE;
2470 I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
2471 POSTING_READ(BXT_PORT_PLL_ENABLE(port));
2472}
2473
2474static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
2475 struct intel_shared_dpll *pll,
2476 struct intel_dpll_hw_state *hw_state)
2477{
2478 enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
2479 uint32_t val;
2480
2481 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
2482 return false;
2483
2484 val = I915_READ(BXT_PORT_PLL_ENABLE(port));
2485 if (!(val & PORT_PLL_ENABLE))
2486 return false;
2487
2488 hw_state->ebb0 = I915_READ(BXT_PORT_PLL_EBB_0(port));
2489 hw_state->pll0 = I915_READ(BXT_PORT_PLL(port, 0));
2490 hw_state->pll1 = I915_READ(BXT_PORT_PLL(port, 1));
2491 hw_state->pll2 = I915_READ(BXT_PORT_PLL(port, 2));
2492 hw_state->pll3 = I915_READ(BXT_PORT_PLL(port, 3));
2493 hw_state->pll6 = I915_READ(BXT_PORT_PLL(port, 6));
2494 hw_state->pll8 = I915_READ(BXT_PORT_PLL(port, 8));
Vandana Kannanb6dc71f2015-05-13 12:18:52 +05302495 hw_state->pll10 = I915_READ(BXT_PORT_PLL(port, 10));
Satheeshakrishna Mdfb82402014-08-22 09:49:09 +05302496 /*
2497 * While we write to the group register to program all lanes at once we
2498 * can read only lane registers. We configure all lanes the same way, so
2499 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
2500 */
2501 hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
2502 if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
2503 DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
2504 hw_state->pcsdw12,
2505 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));
2506
2507 return true;
2508}
2509
2510static void bxt_shared_dplls_init(struct drm_i915_private *dev_priv)
2511{
2512 int i;
2513
2514 dev_priv->num_shared_dpll = 3;
2515
2516 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2517 dev_priv->shared_dplls[i].id = i;
2518 dev_priv->shared_dplls[i].name = bxt_ddi_pll_names[i];
2519 dev_priv->shared_dplls[i].disable = bxt_ddi_pll_disable;
2520 dev_priv->shared_dplls[i].enable = bxt_ddi_pll_enable;
2521 dev_priv->shared_dplls[i].get_hw_state =
2522 bxt_ddi_pll_get_hw_state;
2523 }
2524}
2525
Damien Lespiau143b3072014-07-29 18:06:19 +01002526void intel_ddi_pll_init(struct drm_device *dev)
2527{
2528 struct drm_i915_private *dev_priv = dev->dev_private;
2529 uint32_t val = I915_READ(LCPLL_CTL);
Damien Lespiau5d96d8a2015-05-21 16:37:48 +01002530 int cdclk_freq;
Damien Lespiau143b3072014-07-29 18:06:19 +01002531
Satheeshakrishna Md1a2dc72014-11-13 14:55:18 +00002532 if (IS_SKYLAKE(dev))
2533 skl_shared_dplls_init(dev_priv);
Satheeshakrishna Mdfb82402014-08-22 09:49:09 +05302534 else if (IS_BROXTON(dev))
2535 bxt_shared_dplls_init(dev_priv);
Satheeshakrishna Md1a2dc72014-11-13 14:55:18 +00002536 else
2537 hsw_shared_dplls_init(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002538
Damien Lespiau5d96d8a2015-05-21 16:37:48 +01002539 cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
2540 DRM_DEBUG_KMS("CDCLK running at %dKHz\n", cdclk_freq);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002541
Satheeshakrishna M121643c2014-11-13 14:55:15 +00002542 if (IS_SKYLAKE(dev)) {
Damien Lespiau5d96d8a2015-05-21 16:37:48 +01002543 dev_priv->skl_boot_cdclk = cdclk_freq;
Satheeshakrishna M121643c2014-11-13 14:55:15 +00002544 if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE))
2545 DRM_ERROR("LCPLL1 is disabled\n");
Damien Lespiau5d96d8a2015-05-21 16:37:48 +01002546 else
2547 intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
Vandana Kannanf8437dd12014-11-24 13:37:39 +05302548 } else if (IS_BROXTON(dev)) {
2549 broxton_init_cdclk(dev);
Vandana Kannan5c6706e2014-11-24 13:37:39 +05302550 broxton_ddi_phy_init(dev);
Satheeshakrishna M121643c2014-11-13 14:55:15 +00002551 } else {
2552 /*
2553 * The LCPLL register should be turned on by the BIOS. For now
2554 * let's just check its state and print errors in case
2555 * something is wrong. Don't even try to turn it on.
2556 */
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002557
Satheeshakrishna M121643c2014-11-13 14:55:15 +00002558 if (val & LCPLL_CD_SOURCE_FCLK)
2559 DRM_ERROR("CDCLK source is not LCPLL\n");
2560
2561 if (val & LCPLL_PLL_DISABLE)
2562 DRM_ERROR("LCPLL is disabled\n");
2563 }
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002564}
Paulo Zanonic19b0662012-10-15 15:51:41 -03002565
2566void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
2567{
Paulo Zanoni174edf12012-10-26 19:05:50 -02002568 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
2569 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002570 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02002571 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002572 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05302573 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002574
2575 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
2576 val = I915_READ(DDI_BUF_CTL(port));
2577 if (val & DDI_BUF_CTL_ENABLE) {
2578 val &= ~DDI_BUF_CTL_ENABLE;
2579 I915_WRITE(DDI_BUF_CTL(port), val);
2580 wait = true;
2581 }
2582
2583 val = I915_READ(DP_TP_CTL(port));
2584 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2585 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2586 I915_WRITE(DP_TP_CTL(port), val);
2587 POSTING_READ(DP_TP_CTL(port));
2588
2589 if (wait)
2590 intel_wait_ddi_buf_idle(dev_priv, port);
2591 }
2592
Dave Airlie0e32b392014-05-02 14:02:48 +10002593 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03002594 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Dave Airlie0e32b392014-05-02 14:02:48 +10002595 if (intel_dp->is_mst)
2596 val |= DP_TP_CTL_MODE_MST;
2597 else {
2598 val |= DP_TP_CTL_MODE_SST;
2599 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2600 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
2601 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03002602 I915_WRITE(DP_TP_CTL(port), val);
2603 POSTING_READ(DP_TP_CTL(port));
2604
2605 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
2606 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
2607 POSTING_READ(DDI_BUF_CTL(port));
2608
2609 udelay(600);
2610}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002611
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02002612void intel_ddi_fdi_disable(struct drm_crtc *crtc)
2613{
2614 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
2615 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
2616 uint32_t val;
2617
2618 intel_ddi_post_disable(intel_encoder);
2619
2620 val = I915_READ(_FDI_RXA_CTL);
2621 val &= ~FDI_RX_ENABLE;
2622 I915_WRITE(_FDI_RXA_CTL, val);
2623
2624 val = I915_READ(_FDI_RXA_MISC);
2625 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
2626 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
2627 I915_WRITE(_FDI_RXA_MISC, val);
2628
2629 val = I915_READ(_FDI_RXA_CTL);
2630 val &= ~FDI_PCDCLK;
2631 I915_WRITE(_FDI_RXA_CTL, val);
2632
2633 val = I915_READ(_FDI_RXA_CTL);
2634 val &= ~FDI_RX_PLL_ENABLE;
2635 I915_WRITE(_FDI_RXA_CTL, val);
2636}
2637
Ville Syrjälä6801c182013-09-24 14:24:05 +03002638void intel_ddi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002639 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002640{
2641 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
2642 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +02002643 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002644 struct intel_hdmi *intel_hdmi;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002645 u32 temp, flags = 0;
2646
2647 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
2648 if (temp & TRANS_DDI_PHSYNC)
2649 flags |= DRM_MODE_FLAG_PHSYNC;
2650 else
2651 flags |= DRM_MODE_FLAG_NHSYNC;
2652 if (temp & TRANS_DDI_PVSYNC)
2653 flags |= DRM_MODE_FLAG_PVSYNC;
2654 else
2655 flags |= DRM_MODE_FLAG_NVSYNC;
2656
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002657 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03002658
2659 switch (temp & TRANS_DDI_BPC_MASK) {
2660 case TRANS_DDI_BPC_6:
2661 pipe_config->pipe_bpp = 18;
2662 break;
2663 case TRANS_DDI_BPC_8:
2664 pipe_config->pipe_bpp = 24;
2665 break;
2666 case TRANS_DDI_BPC_10:
2667 pipe_config->pipe_bpp = 30;
2668 break;
2669 case TRANS_DDI_BPC_12:
2670 pipe_config->pipe_bpp = 36;
2671 break;
2672 default:
2673 break;
2674 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002675
2676 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
2677 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02002678 pipe_config->has_hdmi_sink = true;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002679 intel_hdmi = enc_to_intel_hdmi(&encoder->base);
2680
2681 if (intel_hdmi->infoframe_enabled(&encoder->base))
2682 pipe_config->has_infoframe = true;
Jesse Barnescbc572a2014-11-17 13:08:47 -08002683 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002684 case TRANS_DDI_MODE_SELECT_DVI:
2685 case TRANS_DDI_MODE_SELECT_FDI:
2686 break;
2687 case TRANS_DDI_MODE_SELECT_DP_SST:
2688 case TRANS_DDI_MODE_SELECT_DP_MST:
2689 pipe_config->has_dp_encoder = true;
2690 intel_dp_get_m_n(intel_crtc, pipe_config);
2691 break;
2692 default:
2693 break;
2694 }
Daniel Vetter10214422013-11-18 07:38:16 +01002695
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002696 if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
Paulo Zanonia60551b2014-05-21 16:23:20 -03002697 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
Jani Nikula82910ac2014-10-27 16:26:59 +02002698 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
Paulo Zanonia60551b2014-05-21 16:23:20 -03002699 pipe_config->has_audio = true;
2700 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002701
Daniel Vetter10214422013-11-18 07:38:16 +01002702 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
2703 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
2704 /*
2705 * This is a big fat ugly hack.
2706 *
2707 * Some machines in UEFI boot mode provide us a VBT that has 18
2708 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2709 * unknown we fail to light up. Yet the same BIOS boots up with
2710 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2711 * max, not what it tells us to use.
2712 *
2713 * Note: This will still be broken if the eDP panel is not lit
2714 * up by the BIOS, and thus we can't get the mode at module
2715 * load.
2716 */
2717 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2718 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
2719 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
2720 }
Jesse Barnes11578552014-01-21 12:42:10 -08002721
Damien Lespiau22606a12014-12-12 14:26:57 +00002722 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002723}
2724
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002725static void intel_ddi_destroy(struct drm_encoder *encoder)
2726{
2727 /* HDMI has nothing special to destroy, so we can go with this. */
2728 intel_dp_encoder_destroy(encoder);
2729}
2730
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002731static bool intel_ddi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002732 struct intel_crtc_state *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002733{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002734 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02002735 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002736
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002737 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002738
Daniel Vettereccb1402013-05-22 00:50:22 +02002739 if (port == PORT_A)
2740 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2741
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002742 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002743 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002744 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002745 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002746}
2747
2748static const struct drm_encoder_funcs intel_ddi_funcs = {
2749 .destroy = intel_ddi_destroy,
2750};
2751
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002752static struct intel_connector *
2753intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2754{
2755 struct intel_connector *connector;
2756 enum port port = intel_dig_port->port;
2757
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002758 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002759 if (!connector)
2760 return NULL;
2761
2762 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2763 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2764 kfree(connector);
2765 return NULL;
2766 }
2767
2768 return connector;
2769}
2770
2771static struct intel_connector *
2772intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2773{
2774 struct intel_connector *connector;
2775 enum port port = intel_dig_port->port;
2776
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002777 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002778 if (!connector)
2779 return NULL;
2780
2781 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2782 intel_hdmi_init_connector(intel_dig_port, connector);
2783
2784 return connector;
2785}
2786
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002787void intel_ddi_init(struct drm_device *dev, enum port port)
2788{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002789 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002790 struct intel_digital_port *intel_dig_port;
2791 struct intel_encoder *intel_encoder;
2792 struct drm_encoder *encoder;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002793 bool init_hdmi, init_dp;
2794
2795 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2796 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2797 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
2798 if (!init_dp && !init_hdmi) {
Chris Wilsonf68d6972014-08-04 07:15:09 +01002799 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, assuming it is\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03002800 port_name(port));
2801 init_hdmi = true;
2802 init_dp = true;
2803 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002804
Daniel Vetterb14c5672013-09-19 12:18:32 +02002805 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002806 if (!intel_dig_port)
2807 return;
2808
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002809 intel_encoder = &intel_dig_port->base;
2810 encoder = &intel_encoder->base;
2811
2812 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
2813 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002814
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002815 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002816 intel_encoder->enable = intel_enable_ddi;
2817 intel_encoder->pre_enable = intel_ddi_pre_enable;
2818 intel_encoder->disable = intel_disable_ddi;
2819 intel_encoder->post_disable = intel_ddi_post_disable;
2820 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002821 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002822
2823 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07002824 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2825 (DDI_BUF_PORT_REVERSAL |
2826 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002827
2828 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002829 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02002830 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002831
Chris Wilsonf68d6972014-08-04 07:15:09 +01002832 if (init_dp) {
2833 if (!intel_ddi_init_dp_connector(intel_dig_port))
2834 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10002835
Chris Wilsonf68d6972014-08-04 07:15:09 +01002836 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Jani Nikula5fcece82015-05-27 15:03:42 +03002837 dev_priv->hotplug.irq_port[port] = intel_dig_port;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002838 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002839
Paulo Zanoni311a2092013-09-12 17:12:18 -03002840 /* In theory we don't need the encoder->type check, but leave it just in
2841 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01002842 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2843 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2844 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002845 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01002846
2847 return;
2848
2849err:
2850 drm_encoder_cleanup(encoder);
2851 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002852}