blob: ca1f9a8a7d03bf7c41e403e2cbb305b3e91ec327 [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
31/* HDMI/DVI modes ignore everything but the last 2 items. So we share
32 * them for both DP and FDI transports, allowing those ports to
33 * automatically adapt to HDMI connections as well
34 */
35static const u32 hsw_ddi_translations_dp[] = {
Damien Lespiauac921bd2014-08-01 11:07:57 +010036 0x00FFFFFF, 0x0006000E,
Eugeni Dodonov45244b82012-05-09 15:37:20 -030037 0x00D75FFF, 0x0005000A,
38 0x00C30FFF, 0x00040006,
39 0x80AAAFFF, 0x000B0000,
40 0x00FFFFFF, 0x0005000A,
41 0x00D75FFF, 0x000C0004,
42 0x80C30FFF, 0x000B0000,
43 0x00FFFFFF, 0x00040006,
44 0x80D75FFF, 0x000B0000,
Eugeni Dodonov45244b82012-05-09 15:37:20 -030045};
46
47static const u32 hsw_ddi_translations_fdi[] = {
Damien Lespiauac921bd2014-08-01 11:07:57 +010048 0x00FFFFFF, 0x0007000E,
Eugeni Dodonov45244b82012-05-09 15:37:20 -030049 0x00D75FFF, 0x000F000A,
50 0x00C30FFF, 0x00060006,
51 0x00AAAFFF, 0x001E0000,
52 0x00FFFFFF, 0x000F000A,
53 0x00D75FFF, 0x00160004,
54 0x00C30FFF, 0x001E0000,
55 0x00FFFFFF, 0x00060006,
56 0x00D75FFF, 0x001E0000,
Paulo Zanoni6acab152013-09-12 17:06:24 -030057};
58
59static const u32 hsw_ddi_translations_hdmi[] = {
60 /* Idx NT mV diff T mV diff db */
61 0x00FFFFFF, 0x0006000E, /* 0: 400 400 0 */
62 0x00E79FFF, 0x000E000C, /* 1: 400 500 2 */
63 0x00D75FFF, 0x0005000A, /* 2: 400 600 3.5 */
64 0x00FFFFFF, 0x0005000A, /* 3: 600 600 0 */
65 0x00E79FFF, 0x001D0007, /* 4: 600 750 2 */
66 0x00D75FFF, 0x000C0004, /* 5: 600 900 3.5 */
67 0x00FFFFFF, 0x00040006, /* 6: 800 800 0 */
68 0x80E79FFF, 0x00030002, /* 7: 800 1000 2 */
69 0x00FFFFFF, 0x00140005, /* 8: 850 850 0 */
70 0x00FFFFFF, 0x000C0004, /* 9: 900 900 0 */
71 0x00FFFFFF, 0x001C0003, /* 10: 950 950 0 */
72 0x80FFFFFF, 0x00030002, /* 11: 1000 1000 0 */
Eugeni Dodonov45244b82012-05-09 15:37:20 -030073};
74
Paulo Zanoni300644c2013-11-02 21:07:42 -070075static const u32 bdw_ddi_translations_edp[] = {
Damien Lespiauac921bd2014-08-01 11:07:57 +010076 0x00FFFFFF, 0x00000012,
Paulo Zanoni300644c2013-11-02 21:07:42 -070077 0x00EBAFFF, 0x00020011,
78 0x00C71FFF, 0x0006000F,
Paulo Zanoni9576c272014-06-13 18:45:40 -030079 0x00AAAFFF, 0x000E000A,
Paulo Zanoni300644c2013-11-02 21:07:42 -070080 0x00FFFFFF, 0x00020011,
81 0x00DB6FFF, 0x0005000F,
82 0x00BEEFFF, 0x000A000C,
83 0x00FFFFFF, 0x0005000F,
84 0x00DB6FFF, 0x000A000C,
Paulo Zanoni300644c2013-11-02 21:07:42 -070085};
86
Art Runyane58623c2013-11-02 21:07:41 -070087static const u32 bdw_ddi_translations_dp[] = {
Damien Lespiauac921bd2014-08-01 11:07:57 +010088 0x00FFFFFF, 0x0007000E,
Art Runyane58623c2013-11-02 21:07:41 -070089 0x00D75FFF, 0x000E000A,
90 0x00BEFFFF, 0x00140006,
Paulo Zanoni9576c272014-06-13 18:45:40 -030091 0x80B2CFFF, 0x001B0002,
Art Runyane58623c2013-11-02 21:07:41 -070092 0x00FFFFFF, 0x000E000A,
93 0x00D75FFF, 0x00180004,
94 0x80CB2FFF, 0x001B0002,
95 0x00F7DFFF, 0x00180004,
96 0x80D75FFF, 0x001B0002,
Art Runyane58623c2013-11-02 21:07:41 -070097};
98
99static const u32 bdw_ddi_translations_fdi[] = {
Damien Lespiauac921bd2014-08-01 11:07:57 +0100100 0x00FFFFFF, 0x0001000E,
Art Runyane58623c2013-11-02 21:07:41 -0700101 0x00D75FFF, 0x0004000A,
102 0x00C30FFF, 0x00070006,
103 0x00AAAFFF, 0x000C0000,
104 0x00FFFFFF, 0x0004000A,
105 0x00D75FFF, 0x00090004,
106 0x00C30FFF, 0x000C0000,
107 0x00FFFFFF, 0x00070006,
108 0x00D75FFF, 0x000C0000,
Art Runyane58623c2013-11-02 21:07:41 -0700109};
110
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100111static const u32 bdw_ddi_translations_hdmi[] = {
112 /* Idx NT mV diff T mV diff db */
113 0x00FFFFFF, 0x0007000E, /* 0: 400 400 0 */
114 0x00D75FFF, 0x000E000A, /* 1: 400 600 3.5 */
115 0x00BEFFFF, 0x00140006, /* 2: 400 800 6 */
116 0x00FFFFFF, 0x0009000D, /* 3: 450 450 0 */
117 0x00FFFFFF, 0x000E000A, /* 4: 600 600 0 */
118 0x00D7FFFF, 0x00140006, /* 5: 600 800 2.5 */
119 0x80CB2FFF, 0x001B0002, /* 6: 600 1000 4.5 */
120 0x00FFFFFF, 0x00140006, /* 7: 800 800 0 */
121 0x80E79FFF, 0x001B0002, /* 8: 800 1000 2 */
122 0x80FFFFFF, 0x001B0002, /* 9: 1000 1000 0 */
123};
124
Jani Nikula20f4dbe2013-08-30 19:40:28 +0300125enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
Paulo Zanonifc914632012-10-05 12:05:54 -0300126{
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300127 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonifc914632012-10-05 12:05:54 -0300128 int type = intel_encoder->type;
129
Dave Airlie0e32b392014-05-02 14:02:48 +1000130 if (type == INTEL_OUTPUT_DP_MST) {
131 struct intel_digital_port *intel_dig_port = enc_to_mst(encoder)->primary;
132 return intel_dig_port->port;
133 } else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200134 type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
Paulo Zanoni174edf12012-10-26 19:05:50 -0200135 struct intel_digital_port *intel_dig_port =
136 enc_to_dig_port(encoder);
137 return intel_dig_port->port;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300138
Paulo Zanonifc914632012-10-05 12:05:54 -0300139 } else if (type == INTEL_OUTPUT_ANALOG) {
140 return PORT_E;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300141
Paulo Zanonifc914632012-10-05 12:05:54 -0300142 } else {
143 DRM_ERROR("Invalid DDI encoder type %d\n", type);
144 BUG();
145 }
146}
147
Art Runyane58623c2013-11-02 21:07:41 -0700148/*
149 * Starting with Haswell, DDI port buffers must be programmed with correct
150 * values in advance. The buffer values are different for FDI and DP modes,
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300151 * but the HDMI/DVI fields are shared among those. So we program the DDI
152 * in either FDI or DP modes only, as HDMI connections will work with both
153 * of those
154 */
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300155static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300156{
157 struct drm_i915_private *dev_priv = dev->dev_private;
158 u32 reg;
Damien Lespiauce4dd492014-08-01 11:07:54 +0100159 int i, n_hdmi_entries, hdmi_800mV_0dB;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300160 int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
Art Runyane58623c2013-11-02 21:07:41 -0700161 const u32 *ddi_translations_fdi;
162 const u32 *ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700163 const u32 *ddi_translations_edp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100164 const u32 *ddi_translations_hdmi;
Art Runyane58623c2013-11-02 21:07:41 -0700165 const u32 *ddi_translations;
166
167 if (IS_BROADWELL(dev)) {
168 ddi_translations_fdi = bdw_ddi_translations_fdi;
169 ddi_translations_dp = bdw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700170 ddi_translations_edp = bdw_ddi_translations_edp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100171 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
172 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
173 hdmi_800mV_0dB = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700174 } else if (IS_HASWELL(dev)) {
175 ddi_translations_fdi = hsw_ddi_translations_fdi;
176 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700177 ddi_translations_edp = hsw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100178 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
Damien Lespiauce4dd492014-08-01 11:07:54 +0100179 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
180 hdmi_800mV_0dB = 6;
Art Runyane58623c2013-11-02 21:07:41 -0700181 } else {
182 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700183 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700184 ddi_translations_fdi = bdw_ddi_translations_fdi;
185 ddi_translations_dp = bdw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100186 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
187 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
188 hdmi_800mV_0dB = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700189 }
190
Paulo Zanoni300644c2013-11-02 21:07:42 -0700191 switch (port) {
192 case PORT_A:
193 ddi_translations = ddi_translations_edp;
194 break;
195 case PORT_B:
196 case PORT_C:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700197 ddi_translations = ddi_translations_dp;
198 break;
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700199 case PORT_D:
Ville Syrjälä5d8a7752013-11-01 18:22:39 +0200200 if (intel_dp_is_edp(dev, PORT_D))
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700201 ddi_translations = ddi_translations_edp;
202 else
203 ddi_translations = ddi_translations_dp;
204 break;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700205 case PORT_E:
206 ddi_translations = ddi_translations_fdi;
207 break;
208 default:
209 BUG();
210 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300211
Paulo Zanonif72d19f2013-08-05 17:25:55 -0300212 for (i = 0, reg = DDI_BUF_TRANS(port);
213 i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300214 I915_WRITE(reg, ddi_translations[i]);
215 reg += 4;
216 }
Damien Lespiauce4dd492014-08-01 11:07:54 +0100217
218 /* Choose a good default if VBT is badly populated */
219 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
220 hdmi_level >= n_hdmi_entries)
221 hdmi_level = hdmi_800mV_0dB;
222
Paulo Zanoni6acab152013-09-12 17:06:24 -0300223 /* Entry 9 is for HDMI: */
224 for (i = 0; i < 2; i++) {
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100225 I915_WRITE(reg, ddi_translations_hdmi[hdmi_level * 2 + i]);
Paulo Zanoni6acab152013-09-12 17:06:24 -0300226 reg += 4;
227 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300228}
229
230/* Program DDI buffers translations for DP. By default, program ports A-D in DP
231 * mode and port E for FDI.
232 */
233void intel_prepare_ddi(struct drm_device *dev)
234{
235 int port;
236
Paulo Zanoni0d536cb2012-11-23 16:46:41 -0200237 if (!HAS_DDI(dev))
238 return;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300239
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300240 for (port = PORT_A; port <= PORT_E; port++)
241 intel_prepare_ddi_buffers(dev, port);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300242}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300243
244static const long hsw_ddi_buf_ctl_values[] = {
245 DDI_BUF_EMP_400MV_0DB_HSW,
246 DDI_BUF_EMP_400MV_3_5DB_HSW,
247 DDI_BUF_EMP_400MV_6DB_HSW,
248 DDI_BUF_EMP_400MV_9_5DB_HSW,
249 DDI_BUF_EMP_600MV_0DB_HSW,
250 DDI_BUF_EMP_600MV_3_5DB_HSW,
251 DDI_BUF_EMP_600MV_6DB_HSW,
252 DDI_BUF_EMP_800MV_0DB_HSW,
253 DDI_BUF_EMP_800MV_3_5DB_HSW
254};
255
Paulo Zanoni248138b2012-11-29 11:29:31 -0200256static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
257 enum port port)
258{
259 uint32_t reg = DDI_BUF_CTL(port);
260 int i;
261
262 for (i = 0; i < 8; i++) {
263 udelay(1);
264 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
265 return;
266 }
267 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
268}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300269
270/* Starting with Haswell, different DDI ports can work in FDI mode for
271 * connection to the PCH-located connectors. For this, it is necessary to train
272 * both the DDI port and PCH receiver for the desired DDI buffer settings.
273 *
274 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
275 * please note that when FDI mode is active on DDI E, it shares 2 lines with
276 * DDI A (which is used for eDP)
277 */
278
279void hsw_fdi_link_train(struct drm_crtc *crtc)
280{
281 struct drm_device *dev = crtc->dev;
282 struct drm_i915_private *dev_priv = dev->dev_private;
283 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni04945642012-11-01 21:00:59 -0200284 u32 temp, i, rx_ctl_val;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300285
Paulo Zanoni04945642012-11-01 21:00:59 -0200286 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
287 * mode set "sequence for CRT port" document:
288 * - TP1 to TP2 time with the default value
289 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100290 *
291 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200292 */
293 I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) |
294 FDI_RX_PWRDN_LANE0_VAL(2) |
295 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
296
297 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000298 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100299 FDI_RX_PLL_ENABLE |
Daniel Vetter627eb5a2013-04-29 19:33:42 +0200300 FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
Paulo Zanoni04945642012-11-01 21:00:59 -0200301 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
302 POSTING_READ(_FDI_RXA_CTL);
303 udelay(220);
304
305 /* Switch from Rawclk to PCDclk */
306 rx_ctl_val |= FDI_PCDCLK;
307 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
308
309 /* Configure Port Clock Select */
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300310 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config.ddi_pll_sel);
311 WARN_ON(intel_crtc->config.ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200312
313 /* Start the training iterating through available voltages and emphasis,
314 * testing each value twice. */
315 for (i = 0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300316 /* Configure DP_TP_CTL with auto-training */
317 I915_WRITE(DP_TP_CTL(PORT_E),
318 DP_TP_CTL_FDI_AUTOTRAIN |
319 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
320 DP_TP_CTL_LINK_TRAIN_PAT1 |
321 DP_TP_CTL_ENABLE);
322
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000323 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
324 * DDI E does not support port reversal, the functionality is
325 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
326 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300327 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200328 DDI_BUF_CTL_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100329 ((intel_crtc->config.fdi_lanes - 1) << 1) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200330 hsw_ddi_buf_ctl_values[i / 2]);
331 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300332
333 udelay(600);
334
Paulo Zanoni04945642012-11-01 21:00:59 -0200335 /* Program PCH FDI Receiver TU */
336 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300337
Paulo Zanoni04945642012-11-01 21:00:59 -0200338 /* Enable PCH FDI Receiver with auto-training */
339 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
340 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
341 POSTING_READ(_FDI_RXA_CTL);
342
343 /* Wait for FDI receiver lane calibration */
344 udelay(30);
345
346 /* Unset FDI_RX_MISC pwrdn lanes */
347 temp = I915_READ(_FDI_RXA_MISC);
348 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
349 I915_WRITE(_FDI_RXA_MISC, temp);
350 POSTING_READ(_FDI_RXA_MISC);
351
352 /* Wait for FDI auto training time */
353 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300354
355 temp = I915_READ(DP_TP_STATUS(PORT_E));
356 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200357 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300358
359 /* Enable normal pixel sending for FDI */
360 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200361 DP_TP_CTL_FDI_AUTOTRAIN |
362 DP_TP_CTL_LINK_TRAIN_NORMAL |
363 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
364 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300365
Paulo Zanoni04945642012-11-01 21:00:59 -0200366 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300367 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200368
Paulo Zanoni248138b2012-11-29 11:29:31 -0200369 temp = I915_READ(DDI_BUF_CTL(PORT_E));
370 temp &= ~DDI_BUF_CTL_ENABLE;
371 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
372 POSTING_READ(DDI_BUF_CTL(PORT_E));
373
Paulo Zanoni04945642012-11-01 21:00:59 -0200374 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200375 temp = I915_READ(DP_TP_CTL(PORT_E));
376 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
377 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
378 I915_WRITE(DP_TP_CTL(PORT_E), temp);
379 POSTING_READ(DP_TP_CTL(PORT_E));
380
381 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200382
383 rx_ctl_val &= ~FDI_RX_ENABLE;
384 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200385 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200386
387 /* Reset FDI_RX_MISC pwrdn lanes */
388 temp = I915_READ(_FDI_RXA_MISC);
389 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
390 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
391 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200392 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300393 }
394
Paulo Zanoni04945642012-11-01 21:00:59 -0200395 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300396}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300397
Dave Airlie44905a22014-05-02 13:36:43 +1000398void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
399{
400 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
401 struct intel_digital_port *intel_dig_port =
402 enc_to_dig_port(&encoder->base);
403
404 intel_dp->DP = intel_dig_port->saved_port_bits |
405 DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
406 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
407
408}
409
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300410static struct intel_encoder *
411intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
412{
413 struct drm_device *dev = crtc->dev;
414 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
415 struct intel_encoder *intel_encoder, *ret = NULL;
416 int num_encoders = 0;
417
418 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
419 ret = intel_encoder;
420 num_encoders++;
421 }
422
423 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300424 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
425 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300426
427 BUG_ON(ret == NULL);
428 return ret;
429}
430
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100431#define LC_FREQ 2700
432#define LC_FREQ_2K (LC_FREQ * 2000)
433
434#define P_MIN 2
435#define P_MAX 64
436#define P_INC 2
437
438/* Constraints for PLL good behavior */
439#define REF_MIN 48
440#define REF_MAX 400
441#define VCO_MIN 2400
442#define VCO_MAX 4800
443
444#define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
445
446struct wrpll_rnp {
447 unsigned p, n2, r2;
448};
449
450static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300451{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100452 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300453
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100454 switch (clock) {
455 case 25175000:
456 case 25200000:
457 case 27000000:
458 case 27027000:
459 case 37762500:
460 case 37800000:
461 case 40500000:
462 case 40541000:
463 case 54000000:
464 case 54054000:
465 case 59341000:
466 case 59400000:
467 case 72000000:
468 case 74176000:
469 case 74250000:
470 case 81000000:
471 case 81081000:
472 case 89012000:
473 case 89100000:
474 case 108000000:
475 case 108108000:
476 case 111264000:
477 case 111375000:
478 case 148352000:
479 case 148500000:
480 case 162000000:
481 case 162162000:
482 case 222525000:
483 case 222750000:
484 case 296703000:
485 case 297000000:
486 budget = 0;
487 break;
488 case 233500000:
489 case 245250000:
490 case 247750000:
491 case 253250000:
492 case 298000000:
493 budget = 1500;
494 break;
495 case 169128000:
496 case 169500000:
497 case 179500000:
498 case 202000000:
499 budget = 2000;
500 break;
501 case 256250000:
502 case 262500000:
503 case 270000000:
504 case 272500000:
505 case 273750000:
506 case 280750000:
507 case 281250000:
508 case 286000000:
509 case 291750000:
510 budget = 4000;
511 break;
512 case 267250000:
513 case 268500000:
514 budget = 5000;
515 break;
516 default:
517 budget = 1000;
518 break;
519 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300520
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100521 return budget;
522}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300523
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100524static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
525 unsigned r2, unsigned n2, unsigned p,
526 struct wrpll_rnp *best)
527{
528 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300529
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100530 /* No best (r,n,p) yet */
531 if (best->p == 0) {
532 best->p = p;
533 best->n2 = n2;
534 best->r2 = r2;
535 return;
536 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300537
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100538 /*
539 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
540 * freq2k.
541 *
542 * delta = 1e6 *
543 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
544 * freq2k;
545 *
546 * and we would like delta <= budget.
547 *
548 * If the discrepancy is above the PPM-based budget, always prefer to
549 * improve upon the previous solution. However, if you're within the
550 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
551 */
552 a = freq2k * budget * p * r2;
553 b = freq2k * budget * best->p * best->r2;
554 diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
555 diff_best = ABS_DIFF((freq2k * best->p * best->r2),
556 (LC_FREQ_2K * best->n2));
557 c = 1000000 * diff;
558 d = 1000000 * diff_best;
559
560 if (a < c && b < d) {
561 /* If both are above the budget, pick the closer */
562 if (best->p * best->r2 * diff < p * r2 * diff_best) {
563 best->p = p;
564 best->n2 = n2;
565 best->r2 = r2;
566 }
567 } else if (a >= c && b < d) {
568 /* If A is below the threshold but B is above it? Update. */
569 best->p = p;
570 best->n2 = n2;
571 best->r2 = r2;
572 } else if (a >= c && b >= d) {
573 /* Both are below the limit, so pick the higher n2/(r2*r2) */
574 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
575 best->p = p;
576 best->n2 = n2;
577 best->r2 = r2;
578 }
579 }
580 /* Otherwise a < c && b >= d, do nothing */
581}
582
Jesse Barnes11578552014-01-21 12:42:10 -0800583static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
584 int reg)
585{
586 int refclk = LC_FREQ;
587 int n, p, r;
588 u32 wrpll;
589
590 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300591 switch (wrpll & WRPLL_PLL_REF_MASK) {
592 case WRPLL_PLL_SSC:
593 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800594 /*
595 * We could calculate spread here, but our checking
596 * code only cares about 5% accuracy, and spread is a max of
597 * 0.5% downspread.
598 */
599 refclk = 135;
600 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300601 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800602 refclk = LC_FREQ;
603 break;
604 default:
605 WARN(1, "bad wrpll refclk\n");
606 return 0;
607 }
608
609 r = wrpll & WRPLL_DIVIDER_REF_MASK;
610 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
611 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
612
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800613 /* Convert to KHz, p & r have a fixed point portion */
614 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800615}
616
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200617static void hsw_ddi_clock_get(struct intel_encoder *encoder,
618 struct intel_crtc_config *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -0800619{
620 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jesse Barnes11578552014-01-21 12:42:10 -0800621 int link_clock = 0;
622 u32 val, pll;
623
Daniel Vetter26804af2014-06-25 22:01:55 +0300624 val = pipe_config->ddi_pll_sel;
Jesse Barnes11578552014-01-21 12:42:10 -0800625 switch (val & PORT_CLK_SEL_MASK) {
626 case PORT_CLK_SEL_LCPLL_810:
627 link_clock = 81000;
628 break;
629 case PORT_CLK_SEL_LCPLL_1350:
630 link_clock = 135000;
631 break;
632 case PORT_CLK_SEL_LCPLL_2700:
633 link_clock = 270000;
634 break;
635 case PORT_CLK_SEL_WRPLL1:
636 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
637 break;
638 case PORT_CLK_SEL_WRPLL2:
639 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
640 break;
641 case PORT_CLK_SEL_SPLL:
642 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
643 if (pll == SPLL_PLL_FREQ_810MHz)
644 link_clock = 81000;
645 else if (pll == SPLL_PLL_FREQ_1350MHz)
646 link_clock = 135000;
647 else if (pll == SPLL_PLL_FREQ_2700MHz)
648 link_clock = 270000;
649 else {
650 WARN(1, "bad spll freq\n");
651 return;
652 }
653 break;
654 default:
655 WARN(1, "bad port clock sel\n");
656 return;
657 }
658
659 pipe_config->port_clock = link_clock * 2;
660
661 if (pipe_config->has_pch_encoder)
662 pipe_config->adjusted_mode.crtc_clock =
663 intel_dotclock_calculate(pipe_config->port_clock,
664 &pipe_config->fdi_m_n);
665 else if (pipe_config->has_dp_encoder)
666 pipe_config->adjusted_mode.crtc_clock =
667 intel_dotclock_calculate(pipe_config->port_clock,
668 &pipe_config->dp_m_n);
669 else
670 pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
671}
672
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200673void intel_ddi_clock_get(struct intel_encoder *encoder,
674 struct intel_crtc_config *pipe_config)
675{
676 hsw_ddi_clock_get(encoder, pipe_config);
677}
678
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100679static void
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100680hsw_ddi_calculate_wrpll(int clock /* in Hz */,
681 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100682{
683 uint64_t freq2k;
684 unsigned p, n2, r2;
685 struct wrpll_rnp best = { 0, 0, 0 };
686 unsigned budget;
687
688 freq2k = clock / 100;
689
690 budget = wrpll_get_budget_for_freq(clock);
691
692 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
693 * and directly pass the LC PLL to it. */
694 if (freq2k == 5400000) {
695 *n2_out = 2;
696 *p_out = 1;
697 *r2_out = 2;
698 return;
699 }
700
701 /*
702 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
703 * the WR PLL.
704 *
705 * We want R so that REF_MIN <= Ref <= REF_MAX.
706 * Injecting R2 = 2 * R gives:
707 * REF_MAX * r2 > LC_FREQ * 2 and
708 * REF_MIN * r2 < LC_FREQ * 2
709 *
710 * Which means the desired boundaries for r2 are:
711 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
712 *
713 */
714 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
715 r2 <= LC_FREQ * 2 / REF_MIN;
716 r2++) {
717
718 /*
719 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
720 *
721 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
722 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
723 * VCO_MAX * r2 > n2 * LC_FREQ and
724 * VCO_MIN * r2 < n2 * LC_FREQ)
725 *
726 * Which means the desired boundaries for n2 are:
727 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
728 */
729 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
730 n2 <= VCO_MAX * r2 / LC_FREQ;
731 n2++) {
732
733 for (p = P_MIN; p <= P_MAX; p += P_INC)
734 wrpll_update_rnp(freq2k, budget,
735 r2, n2, p, &best);
736 }
737 }
738
739 *n2_out = best.n2;
740 *p_out = best.p;
741 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300742}
743
Damien Lespiau0220ab62014-07-29 18:06:22 +0100744static bool
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100745hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
746 struct intel_encoder *intel_encoder,
747 int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300748{
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100749 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
Daniel Vettere0b01be2014-06-25 22:02:01 +0300750 struct intel_shared_dpll *pll;
Daniel Vetter716c2e52014-06-25 22:02:02 +0300751 uint32_t val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100752 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300753
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100754 hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300755
Daniel Vetter114fe482014-06-25 22:01:48 +0300756 val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300757 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
758 WRPLL_DIVIDER_POST(p);
759
Daniel Vetter716c2e52014-06-25 22:02:02 +0300760 intel_crtc->config.dpll_hw_state.wrpll = val;
761
762 pll = intel_get_shared_dpll(intel_crtc);
763 if (pll == NULL) {
764 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
765 pipe_name(intel_crtc->pipe));
Paulo Zanoni06940012013-10-30 18:27:43 -0200766 return false;
767 }
768
Daniel Vetter716c2e52014-06-25 22:02:02 +0300769 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300770 }
771
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300772 return true;
773}
774
Damien Lespiau0220ab62014-07-29 18:06:22 +0100775
776/*
777 * Tries to find a *shared* PLL for the CRTC and store it in
778 * intel_crtc->ddi_pll_sel.
779 *
780 * For private DPLLs, compute_config() should do the selection for us. This
781 * function should be folded into compute_config() eventually.
782 */
783bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
784{
785 struct drm_crtc *crtc = &intel_crtc->base;
786 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Damien Lespiau0220ab62014-07-29 18:06:22 +0100787 int clock = intel_crtc->config.port_clock;
788
789 intel_put_shared_dpll(intel_crtc);
790
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100791 return hsw_ddi_pll_select(intel_crtc, intel_encoder, clock);
Damien Lespiau0220ab62014-07-29 18:06:22 +0100792}
793
Paulo Zanonidae84792012-10-15 15:51:30 -0300794void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
795{
796 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
797 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
798 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200799 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300800 int type = intel_encoder->type;
801 uint32_t temp;
802
Dave Airlie0e32b392014-05-02 14:02:48 +1000803 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Paulo Zanonic9809792012-10-23 18:30:00 -0200804 temp = TRANS_MSA_SYNC_CLK;
Daniel Vetter965e0c42013-03-27 00:44:57 +0100805 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -0300806 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200807 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300808 break;
809 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200810 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300811 break;
812 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200813 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300814 break;
815 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200816 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300817 break;
818 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100819 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -0300820 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200821 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300822 }
823}
824
Dave Airlie0e32b392014-05-02 14:02:48 +1000825void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
826{
827 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
828 struct drm_device *dev = crtc->dev;
829 struct drm_i915_private *dev_priv = dev->dev_private;
830 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
831 uint32_t temp;
832 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
833 if (state == true)
834 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
835 else
836 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
837 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
838}
839
Damien Lespiau8228c252013-03-07 15:30:27 +0000840void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300841{
842 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
843 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300844 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -0700845 struct drm_device *dev = crtc->dev;
846 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300847 enum pipe pipe = intel_crtc->pipe;
Daniel Vetter3b117c82013-04-17 20:15:07 +0200848 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200849 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300850 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300851 uint32_t temp;
852
Paulo Zanoniad80a812012-10-24 16:06:19 -0200853 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
854 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200855 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -0300856
Daniel Vetter965e0c42013-03-27 00:44:57 +0100857 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -0300858 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200859 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300860 break;
861 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200862 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300863 break;
864 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200865 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300866 break;
867 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200868 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300869 break;
870 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100871 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -0300872 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300873
Ville Syrjäläa6662832013-09-10 17:03:41 +0300874 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200875 temp |= TRANS_DDI_PVSYNC;
Ville Syrjäläa6662832013-09-10 17:03:41 +0300876 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200877 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c2012-08-08 14:15:28 -0300878
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200879 if (cpu_transcoder == TRANSCODER_EDP) {
880 switch (pipe) {
881 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -0700882 /* On Haswell, can only use the always-on power well for
883 * eDP when not using the panel fitter, and when not
884 * using motion blur mitigation (which we don't
885 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +0200886 if (IS_HASWELL(dev) &&
887 (intel_crtc->config.pch_pfit.enabled ||
888 intel_crtc->config.pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -0200889 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
890 else
891 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200892 break;
893 case PIPE_B:
894 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
895 break;
896 case PIPE_C:
897 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
898 break;
899 default:
900 BUG();
901 break;
902 }
903 }
904
Paulo Zanoni7739c332012-10-15 15:51:29 -0300905 if (type == INTEL_OUTPUT_HDMI) {
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200906 if (intel_crtc->config.has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200907 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300908 else
Paulo Zanoniad80a812012-10-24 16:06:19 -0200909 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300910
Paulo Zanoni7739c332012-10-15 15:51:29 -0300911 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -0200912 temp |= TRANS_DDI_MODE_SELECT_FDI;
Daniel Vetter33d29b12013-02-13 18:04:45 +0100913 temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300914
915 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
916 type == INTEL_OUTPUT_EDP) {
917 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
918
Dave Airlie0e32b392014-05-02 14:02:48 +1000919 if (intel_dp->is_mst) {
920 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
921 } else
922 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
923
924 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
925 } else if (type == INTEL_OUTPUT_DP_MST) {
926 struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
927
928 if (intel_dp->is_mst) {
929 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
930 } else
931 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300932
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200933 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300934 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300935 WARN(1, "Invalid encoder type %d for pipe %c\n",
936 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300937 }
938
Paulo Zanoniad80a812012-10-24 16:06:19 -0200939 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300940}
941
Paulo Zanoniad80a812012-10-24 16:06:19 -0200942void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
943 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300944{
Paulo Zanoniad80a812012-10-24 16:06:19 -0200945 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300946 uint32_t val = I915_READ(reg);
947
Dave Airlie0e32b392014-05-02 14:02:48 +1000948 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -0200949 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300950 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300951}
952
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200953bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
954{
955 struct drm_device *dev = intel_connector->base.dev;
956 struct drm_i915_private *dev_priv = dev->dev_private;
957 struct intel_encoder *intel_encoder = intel_connector->encoder;
958 int type = intel_connector->base.connector_type;
959 enum port port = intel_ddi_get_encoder_port(intel_encoder);
960 enum pipe pipe = 0;
961 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -0300962 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200963 uint32_t tmp;
964
Paulo Zanoni882244a2014-04-01 14:55:12 -0300965 power_domain = intel_display_port_power_domain(intel_encoder);
966 if (!intel_display_power_enabled(dev_priv, power_domain))
967 return false;
968
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200969 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
970 return false;
971
972 if (port == PORT_A)
973 cpu_transcoder = TRANSCODER_EDP;
974 else
Daniel Vetter1a240d42012-11-29 22:18:51 +0100975 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200976
977 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
978
979 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
980 case TRANS_DDI_MODE_SELECT_HDMI:
981 case TRANS_DDI_MODE_SELECT_DVI:
982 return (type == DRM_MODE_CONNECTOR_HDMIA);
983
984 case TRANS_DDI_MODE_SELECT_DP_SST:
985 if (type == DRM_MODE_CONNECTOR_eDP)
986 return true;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200987 return (type == DRM_MODE_CONNECTOR_DisplayPort);
Dave Airlie0e32b392014-05-02 14:02:48 +1000988 case TRANS_DDI_MODE_SELECT_DP_MST:
989 /* if the transcoder is in MST state then
990 * connector isn't connected */
991 return false;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200992
993 case TRANS_DDI_MODE_SELECT_FDI:
994 return (type == DRM_MODE_CONNECTOR_VGA);
995
996 default:
997 return false;
998 }
999}
1000
Daniel Vetter85234cd2012-07-02 13:27:29 +02001001bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1002 enum pipe *pipe)
1003{
1004 struct drm_device *dev = encoder->base.dev;
1005 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001006 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001007 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001008 u32 tmp;
1009 int i;
1010
Imre Deak6d129be2014-03-05 16:20:54 +02001011 power_domain = intel_display_port_power_domain(encoder);
1012 if (!intel_display_power_enabled(dev_priv, power_domain))
1013 return false;
1014
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001015 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001016
1017 if (!(tmp & DDI_BUF_CTL_ENABLE))
1018 return false;
1019
Paulo Zanoniad80a812012-10-24 16:06:19 -02001020 if (port == PORT_A) {
1021 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001022
Paulo Zanoniad80a812012-10-24 16:06:19 -02001023 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1024 case TRANS_DDI_EDP_INPUT_A_ON:
1025 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1026 *pipe = PIPE_A;
1027 break;
1028 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1029 *pipe = PIPE_B;
1030 break;
1031 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1032 *pipe = PIPE_C;
1033 break;
1034 }
1035
1036 return true;
1037 } else {
1038 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1039 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1040
1041 if ((tmp & TRANS_DDI_PORT_MASK)
1042 == TRANS_DDI_SELECT_PORT(port)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10001043 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST)
1044 return false;
1045
Paulo Zanoniad80a812012-10-24 16:06:19 -02001046 *pipe = i;
1047 return true;
1048 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001049 }
1050 }
1051
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001052 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001053
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001054 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001055}
1056
Paulo Zanonifc914632012-10-05 12:05:54 -03001057void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1058{
1059 struct drm_crtc *crtc = &intel_crtc->base;
1060 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1061 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1062 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +02001063 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001064
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001065 if (cpu_transcoder != TRANSCODER_EDP)
1066 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1067 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001068}
1069
1070void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1071{
1072 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001073 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001074
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001075 if (cpu_transcoder != TRANSCODER_EDP)
1076 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1077 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001078}
1079
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001080static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001081{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001082 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001083 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001084 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001085 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001086 int type = intel_encoder->type;
1087
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001088 if (crtc->config.has_audio) {
1089 DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
1090 pipe_name(crtc->pipe));
1091
1092 /* write eld */
1093 DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
1094 intel_write_eld(encoder, &crtc->config.adjusted_mode);
1095 }
1096
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001097 if (type == INTEL_OUTPUT_EDP) {
1098 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001099 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001100 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001101
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001102 WARN_ON(crtc->config.ddi_pll_sel == PORT_CLK_SEL_NONE);
1103 I915_WRITE(PORT_CLK_SEL(port), crtc->config.ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001104
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001105 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001106 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001107
Dave Airlie44905a22014-05-02 13:36:43 +10001108 intel_ddi_init_dp_buf_reg(intel_encoder);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001109
1110 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1111 intel_dp_start_link_train(intel_dp);
1112 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001113 if (port != PORT_A)
1114 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001115 } else if (type == INTEL_OUTPUT_HDMI) {
1116 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1117
1118 intel_hdmi->set_infoframes(encoder,
1119 crtc->config.has_hdmi_sink,
1120 &crtc->config.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001121 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001122}
1123
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001124static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001125{
1126 struct drm_encoder *encoder = &intel_encoder->base;
1127 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1128 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001129 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001130 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001131 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001132
1133 val = I915_READ(DDI_BUF_CTL(port));
1134 if (val & DDI_BUF_CTL_ENABLE) {
1135 val &= ~DDI_BUF_CTL_ENABLE;
1136 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001137 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001138 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001139
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001140 val = I915_READ(DP_TP_CTL(port));
1141 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1142 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1143 I915_WRITE(DP_TP_CTL(port), val);
1144
1145 if (wait)
1146 intel_wait_ddi_buf_idle(dev_priv, port);
1147
Jani Nikula76bb80e2013-11-15 15:29:57 +02001148 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001149 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001150 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001151 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001152 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001153 }
1154
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001155 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1156}
1157
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001158static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001159{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001160 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001161 struct drm_crtc *crtc = encoder->crtc;
1162 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1163 int pipe = intel_crtc->pipe;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001164 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001165 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001166 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1167 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001168 uint32_t tmp;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001169
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001170 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001171 struct intel_digital_port *intel_dig_port =
1172 enc_to_dig_port(encoder);
1173
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001174 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1175 * are ignored so nothing special needs to be done besides
1176 * enabling the port.
1177 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001178 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001179 intel_dig_port->saved_port_bits |
1180 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001181 } else if (type == INTEL_OUTPUT_EDP) {
1182 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1183
Imre Deak3ab9c632013-05-03 12:57:41 +03001184 if (port == PORT_A)
1185 intel_dp_stop_link_train(intel_dp);
1186
Daniel Vetter4be73782014-01-17 14:39:48 +01001187 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi49065572013-07-11 18:45:05 -03001188 intel_edp_psr_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001189 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001190
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001191 if (intel_crtc->config.has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001192 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001193 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1194 tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1195 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1196 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001197}
1198
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001199static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001200{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001201 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001202 struct drm_crtc *crtc = encoder->crtc;
1203 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1204 int pipe = intel_crtc->pipe;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001205 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001206 struct drm_device *dev = encoder->dev;
1207 struct drm_i915_private *dev_priv = dev->dev_private;
1208 uint32_t tmp;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001209
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001210 /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
1211 * register is part of the power well on Haswell. */
1212 if (intel_crtc->config.has_audio) {
1213 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1214 tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1215 (pipe * 4));
1216 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1217 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1218 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001219
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001220 if (type == INTEL_OUTPUT_EDP) {
1221 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1222
Rodrigo Vivi49065572013-07-11 18:45:05 -03001223 intel_edp_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001224 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001225 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001226}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001227
Damien Lespiauad13d602014-07-29 18:06:24 +01001228static int bdw_get_cdclk_freq(struct drm_i915_private *dev_priv)
1229{
1230 uint32_t lcpll = I915_READ(LCPLL_CTL);
1231 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
1232
1233 if (lcpll & LCPLL_CD_SOURCE_FCLK)
1234 return 800000;
1235 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
1236 return 450000;
1237 else if (freq == LCPLL_CLK_FREQ_450)
1238 return 450000;
1239 else if (freq == LCPLL_CLK_FREQ_54O_BDW)
1240 return 540000;
1241 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
1242 return 337500;
1243 else
1244 return 675000;
1245}
1246
1247static int hsw_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001248{
Paulo Zanonie39bf982013-11-02 21:07:36 -07001249 struct drm_device *dev = dev_priv->dev;
Paulo Zanonia4006642013-08-06 18:57:11 -03001250 uint32_t lcpll = I915_READ(LCPLL_CTL);
Paulo Zanonie39bf982013-11-02 21:07:36 -07001251 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Paulo Zanonia4006642013-08-06 18:57:11 -03001252
Damien Lespiauad13d602014-07-29 18:06:24 +01001253 if (lcpll & LCPLL_CD_SOURCE_FCLK)
Paulo Zanonia4006642013-08-06 18:57:11 -03001254 return 800000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001255 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001256 return 450000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001257 else if (freq == LCPLL_CLK_FREQ_450)
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001258 return 450000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001259 else if (IS_ULT(dev))
1260 return 337500;
1261 else
1262 return 540000;
1263}
1264
1265int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
1266{
1267 struct drm_device *dev = dev_priv->dev;
1268
1269 if (IS_BROADWELL(dev))
1270 return bdw_get_cdclk_freq(dev_priv);
1271
1272 /* Haswell */
1273 return hsw_get_cdclk_freq(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001274}
1275
Daniel Vettere0b01be2014-06-25 22:02:01 +03001276static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv,
1277 struct intel_shared_dpll *pll)
1278{
Daniel Vettere0b01be2014-06-25 22:02:01 +03001279 I915_WRITE(WRPLL_CTL(pll->id), pll->hw_state.wrpll);
1280 POSTING_READ(WRPLL_CTL(pll->id));
1281 udelay(20);
1282}
1283
Daniel Vetter12030432014-06-25 22:02:00 +03001284static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv,
1285 struct intel_shared_dpll *pll)
1286{
1287 uint32_t val;
1288
1289 val = I915_READ(WRPLL_CTL(pll->id));
Daniel Vetter12030432014-06-25 22:02:00 +03001290 I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
1291 POSTING_READ(WRPLL_CTL(pll->id));
1292}
1293
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001294static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
1295 struct intel_shared_dpll *pll,
1296 struct intel_dpll_hw_state *hw_state)
1297{
1298 uint32_t val;
1299
1300 if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
1301 return false;
1302
1303 val = I915_READ(WRPLL_CTL(pll->id));
1304 hw_state->wrpll = val;
1305
1306 return val & WRPLL_PLL_ENABLE;
1307}
1308
Damien Lespiauca1381b2014-07-15 15:05:33 +01001309static const char * const hsw_ddi_pll_names[] = {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001310 "WRPLL 1",
1311 "WRPLL 2",
1312};
1313
Damien Lespiau143b3072014-07-29 18:06:19 +01001314static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001315{
Daniel Vetter9cd86932014-06-25 22:01:57 +03001316 int i;
1317
Daniel Vetter716c2e52014-06-25 22:02:02 +03001318 dev_priv->num_shared_dpll = 2;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001319
Daniel Vetter716c2e52014-06-25 22:02:02 +03001320 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001321 dev_priv->shared_dplls[i].id = i;
1322 dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
Daniel Vetter12030432014-06-25 22:02:00 +03001323 dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable;
Daniel Vettere0b01be2014-06-25 22:02:01 +03001324 dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable;
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001325 dev_priv->shared_dplls[i].get_hw_state =
1326 hsw_ddi_pll_get_hw_state;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001327 }
Damien Lespiau143b3072014-07-29 18:06:19 +01001328}
1329
1330void intel_ddi_pll_init(struct drm_device *dev)
1331{
1332 struct drm_i915_private *dev_priv = dev->dev_private;
1333 uint32_t val = I915_READ(LCPLL_CTL);
1334
1335 hsw_shared_dplls_init(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001336
1337 /* The LCPLL register should be turned on by the BIOS. For now let's
1338 * just check its state and print errors in case something is wrong.
1339 * Don't even try to turn it on.
1340 */
1341
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001342 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001343 intel_ddi_get_cdclk_freq(dev_priv));
1344
1345 if (val & LCPLL_CD_SOURCE_FCLK)
1346 DRM_ERROR("CDCLK source is not LCPLL\n");
1347
1348 if (val & LCPLL_PLL_DISABLE)
1349 DRM_ERROR("LCPLL is disabled\n");
1350}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001351
1352void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1353{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001354 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1355 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001356 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001357 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001358 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301359 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001360
1361 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1362 val = I915_READ(DDI_BUF_CTL(port));
1363 if (val & DDI_BUF_CTL_ENABLE) {
1364 val &= ~DDI_BUF_CTL_ENABLE;
1365 I915_WRITE(DDI_BUF_CTL(port), val);
1366 wait = true;
1367 }
1368
1369 val = I915_READ(DP_TP_CTL(port));
1370 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1371 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1372 I915_WRITE(DP_TP_CTL(port), val);
1373 POSTING_READ(DP_TP_CTL(port));
1374
1375 if (wait)
1376 intel_wait_ddi_buf_idle(dev_priv, port);
1377 }
1378
Dave Airlie0e32b392014-05-02 14:02:48 +10001379 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03001380 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Dave Airlie0e32b392014-05-02 14:02:48 +10001381 if (intel_dp->is_mst)
1382 val |= DP_TP_CTL_MODE_MST;
1383 else {
1384 val |= DP_TP_CTL_MODE_SST;
1385 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1386 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1387 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03001388 I915_WRITE(DP_TP_CTL(port), val);
1389 POSTING_READ(DP_TP_CTL(port));
1390
1391 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1392 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1393 POSTING_READ(DDI_BUF_CTL(port));
1394
1395 udelay(600);
1396}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001397
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001398void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1399{
1400 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1401 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1402 uint32_t val;
1403
1404 intel_ddi_post_disable(intel_encoder);
1405
1406 val = I915_READ(_FDI_RXA_CTL);
1407 val &= ~FDI_RX_ENABLE;
1408 I915_WRITE(_FDI_RXA_CTL, val);
1409
1410 val = I915_READ(_FDI_RXA_MISC);
1411 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1412 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1413 I915_WRITE(_FDI_RXA_MISC, val);
1414
1415 val = I915_READ(_FDI_RXA_CTL);
1416 val &= ~FDI_PCDCLK;
1417 I915_WRITE(_FDI_RXA_CTL, val);
1418
1419 val = I915_READ(_FDI_RXA_CTL);
1420 val &= ~FDI_RX_PLL_ENABLE;
1421 I915_WRITE(_FDI_RXA_CTL, val);
1422}
1423
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001424static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1425{
Dave Airlie0e32b392014-05-02 14:02:48 +10001426 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&intel_encoder->base);
1427 int type = intel_dig_port->base.type;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001428
Dave Airlie0e32b392014-05-02 14:02:48 +10001429 if (type != INTEL_OUTPUT_DISPLAYPORT &&
1430 type != INTEL_OUTPUT_EDP &&
1431 type != INTEL_OUTPUT_UNKNOWN) {
1432 return;
1433 }
1434
1435 intel_dp_hot_plug(intel_encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001436}
1437
Ville Syrjälä6801c182013-09-24 14:24:05 +03001438void intel_ddi_get_config(struct intel_encoder *encoder,
1439 struct intel_crtc_config *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001440{
1441 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1442 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1443 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
1444 u32 temp, flags = 0;
1445
1446 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1447 if (temp & TRANS_DDI_PHSYNC)
1448 flags |= DRM_MODE_FLAG_PHSYNC;
1449 else
1450 flags |= DRM_MODE_FLAG_NHSYNC;
1451 if (temp & TRANS_DDI_PVSYNC)
1452 flags |= DRM_MODE_FLAG_PVSYNC;
1453 else
1454 flags |= DRM_MODE_FLAG_NVSYNC;
1455
1456 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001457
1458 switch (temp & TRANS_DDI_BPC_MASK) {
1459 case TRANS_DDI_BPC_6:
1460 pipe_config->pipe_bpp = 18;
1461 break;
1462 case TRANS_DDI_BPC_8:
1463 pipe_config->pipe_bpp = 24;
1464 break;
1465 case TRANS_DDI_BPC_10:
1466 pipe_config->pipe_bpp = 30;
1467 break;
1468 case TRANS_DDI_BPC_12:
1469 pipe_config->pipe_bpp = 36;
1470 break;
1471 default:
1472 break;
1473 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001474
1475 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1476 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001477 pipe_config->has_hdmi_sink = true;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001478 case TRANS_DDI_MODE_SELECT_DVI:
1479 case TRANS_DDI_MODE_SELECT_FDI:
1480 break;
1481 case TRANS_DDI_MODE_SELECT_DP_SST:
1482 case TRANS_DDI_MODE_SELECT_DP_MST:
1483 pipe_config->has_dp_encoder = true;
1484 intel_dp_get_m_n(intel_crtc, pipe_config);
1485 break;
1486 default:
1487 break;
1488 }
Daniel Vetter10214422013-11-18 07:38:16 +01001489
Paulo Zanonia60551b2014-05-21 16:23:20 -03001490 if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
1491 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1492 if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
1493 pipe_config->has_audio = true;
1494 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001495
Daniel Vetter10214422013-11-18 07:38:16 +01001496 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1497 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1498 /*
1499 * This is a big fat ugly hack.
1500 *
1501 * Some machines in UEFI boot mode provide us a VBT that has 18
1502 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1503 * unknown we fail to light up. Yet the same BIOS boots up with
1504 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1505 * max, not what it tells us to use.
1506 *
1507 * Note: This will still be broken if the eDP panel is not lit
1508 * up by the BIOS, and thus we can't get the mode at module
1509 * load.
1510 */
1511 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1512 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1513 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1514 }
Jesse Barnes11578552014-01-21 12:42:10 -08001515
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001516 hsw_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001517}
1518
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001519static void intel_ddi_destroy(struct drm_encoder *encoder)
1520{
1521 /* HDMI has nothing special to destroy, so we can go with this. */
1522 intel_dp_encoder_destroy(encoder);
1523}
1524
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001525static bool intel_ddi_compute_config(struct intel_encoder *encoder,
1526 struct intel_crtc_config *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001527{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001528 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02001529 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001530
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001531 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001532
Daniel Vettereccb1402013-05-22 00:50:22 +02001533 if (port == PORT_A)
1534 pipe_config->cpu_transcoder = TRANSCODER_EDP;
1535
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001536 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001537 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001538 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001539 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001540}
1541
1542static const struct drm_encoder_funcs intel_ddi_funcs = {
1543 .destroy = intel_ddi_destroy,
1544};
1545
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001546static struct intel_connector *
1547intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
1548{
1549 struct intel_connector *connector;
1550 enum port port = intel_dig_port->port;
1551
1552 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1553 if (!connector)
1554 return NULL;
1555
1556 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1557 if (!intel_dp_init_connector(intel_dig_port, connector)) {
1558 kfree(connector);
1559 return NULL;
1560 }
1561
1562 return connector;
1563}
1564
1565static struct intel_connector *
1566intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
1567{
1568 struct intel_connector *connector;
1569 enum port port = intel_dig_port->port;
1570
1571 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1572 if (!connector)
1573 return NULL;
1574
1575 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
1576 intel_hdmi_init_connector(intel_dig_port, connector);
1577
1578 return connector;
1579}
1580
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001581void intel_ddi_init(struct drm_device *dev, enum port port)
1582{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001583 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001584 struct intel_digital_port *intel_dig_port;
1585 struct intel_encoder *intel_encoder;
1586 struct drm_encoder *encoder;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001587 bool init_hdmi, init_dp;
1588
1589 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1590 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1591 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1592 if (!init_dp && !init_hdmi) {
Chris Wilsonf68d6972014-08-04 07:15:09 +01001593 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, assuming it is\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03001594 port_name(port));
1595 init_hdmi = true;
1596 init_dp = true;
1597 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001598
Daniel Vetterb14c5672013-09-19 12:18:32 +02001599 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001600 if (!intel_dig_port)
1601 return;
1602
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001603 intel_encoder = &intel_dig_port->base;
1604 encoder = &intel_encoder->base;
1605
1606 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1607 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001608
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001609 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001610 intel_encoder->enable = intel_enable_ddi;
1611 intel_encoder->pre_enable = intel_ddi_pre_enable;
1612 intel_encoder->disable = intel_disable_ddi;
1613 intel_encoder->post_disable = intel_ddi_post_disable;
1614 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001615 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001616
1617 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001618 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
1619 (DDI_BUF_PORT_REVERSAL |
1620 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001621
1622 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Chris Wilsonf68d6972014-08-04 07:15:09 +01001623 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001624 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001625 intel_encoder->hot_plug = intel_ddi_hot_plug;
1626
Chris Wilsonf68d6972014-08-04 07:15:09 +01001627 if (init_dp) {
1628 if (!intel_ddi_init_dp_connector(intel_dig_port))
1629 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10001630
Chris Wilsonf68d6972014-08-04 07:15:09 +01001631 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
1632 dev_priv->hpd_irq_port[port] = intel_dig_port;
1633 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001634
Paulo Zanoni311a2092013-09-12 17:12:18 -03001635 /* In theory we don't need the encoder->type check, but leave it just in
1636 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01001637 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
1638 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
1639 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001640 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01001641
1642 return;
1643
1644err:
1645 drm_encoder_cleanup(encoder);
1646 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001647}