blob: b5870fd920ff7021b838e2448dc725bd5af2799b [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[] = {
36 0x00FFFFFF, 0x0006000E, /* DP parameters */
37 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[] = {
48 0x00FFFFFF, 0x0007000E, /* FDI parameters */
49 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 Lespiaue1b22732013-12-03 13:46:58 +000076 0x00FFFFFF, 0x00000012, /* eDP parameters */
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 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/
86};
87
Art Runyane58623c2013-11-02 21:07:41 -070088static const u32 bdw_ddi_translations_dp[] = {
89 0x00FFFFFF, 0x0007000E, /* DP parameters */
90 0x00D75FFF, 0x000E000A,
91 0x00BEFFFF, 0x00140006,
Paulo Zanoni9576c272014-06-13 18:45:40 -030092 0x80B2CFFF, 0x001B0002,
Art Runyane58623c2013-11-02 21:07:41 -070093 0x00FFFFFF, 0x000E000A,
94 0x00D75FFF, 0x00180004,
95 0x80CB2FFF, 0x001B0002,
96 0x00F7DFFF, 0x00180004,
97 0x80D75FFF, 0x001B0002,
Art Runyane58623c2013-11-02 21:07:41 -070098 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/
99};
100
101static const u32 bdw_ddi_translations_fdi[] = {
102 0x00FFFFFF, 0x0001000E, /* FDI parameters */
103 0x00D75FFF, 0x0004000A,
104 0x00C30FFF, 0x00070006,
105 0x00AAAFFF, 0x000C0000,
106 0x00FFFFFF, 0x0004000A,
107 0x00D75FFF, 0x00090004,
108 0x00C30FFF, 0x000C0000,
109 0x00FFFFFF, 0x00070006,
110 0x00D75FFF, 0x000C0000,
111 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/
112};
113
Jani Nikula20f4dbe2013-08-30 19:40:28 +0300114enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
Paulo Zanonifc914632012-10-05 12:05:54 -0300115{
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300116 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonifc914632012-10-05 12:05:54 -0300117 int type = intel_encoder->type;
118
Dave Airlie0e32b392014-05-02 14:02:48 +1000119 if (type == INTEL_OUTPUT_DP_MST) {
120 struct intel_digital_port *intel_dig_port = enc_to_mst(encoder)->primary;
121 return intel_dig_port->port;
122 } else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200123 type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
Paulo Zanoni174edf12012-10-26 19:05:50 -0200124 struct intel_digital_port *intel_dig_port =
125 enc_to_dig_port(encoder);
126 return intel_dig_port->port;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300127
Paulo Zanonifc914632012-10-05 12:05:54 -0300128 } else if (type == INTEL_OUTPUT_ANALOG) {
129 return PORT_E;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300130
Paulo Zanonifc914632012-10-05 12:05:54 -0300131 } else {
132 DRM_ERROR("Invalid DDI encoder type %d\n", type);
133 BUG();
134 }
135}
136
Art Runyane58623c2013-11-02 21:07:41 -0700137/*
138 * Starting with Haswell, DDI port buffers must be programmed with correct
139 * values in advance. The buffer values are different for FDI and DP modes,
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300140 * but the HDMI/DVI fields are shared among those. So we program the DDI
141 * in either FDI or DP modes only, as HDMI connections will work with both
142 * of those
143 */
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300144static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300145{
146 struct drm_i915_private *dev_priv = dev->dev_private;
147 u32 reg;
148 int i;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300149 int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
Art Runyane58623c2013-11-02 21:07:41 -0700150 const u32 *ddi_translations_fdi;
151 const u32 *ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700152 const u32 *ddi_translations_edp;
Art Runyane58623c2013-11-02 21:07:41 -0700153 const u32 *ddi_translations;
154
155 if (IS_BROADWELL(dev)) {
156 ddi_translations_fdi = bdw_ddi_translations_fdi;
157 ddi_translations_dp = bdw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700158 ddi_translations_edp = bdw_ddi_translations_edp;
Art Runyane58623c2013-11-02 21:07:41 -0700159 } else if (IS_HASWELL(dev)) {
160 ddi_translations_fdi = hsw_ddi_translations_fdi;
161 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700162 ddi_translations_edp = hsw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700163 } else {
164 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700165 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700166 ddi_translations_fdi = bdw_ddi_translations_fdi;
167 ddi_translations_dp = bdw_ddi_translations_dp;
168 }
169
Paulo Zanoni300644c2013-11-02 21:07:42 -0700170 switch (port) {
171 case PORT_A:
172 ddi_translations = ddi_translations_edp;
173 break;
174 case PORT_B:
175 case PORT_C:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700176 ddi_translations = ddi_translations_dp;
177 break;
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700178 case PORT_D:
Ville Syrjälä5d8a7752013-11-01 18:22:39 +0200179 if (intel_dp_is_edp(dev, PORT_D))
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700180 ddi_translations = ddi_translations_edp;
181 else
182 ddi_translations = ddi_translations_dp;
183 break;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700184 case PORT_E:
185 ddi_translations = ddi_translations_fdi;
186 break;
187 default:
188 BUG();
189 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300190
Paulo Zanonif72d19f2013-08-05 17:25:55 -0300191 for (i = 0, reg = DDI_BUF_TRANS(port);
192 i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300193 I915_WRITE(reg, ddi_translations[i]);
194 reg += 4;
195 }
Paulo Zanoni6acab152013-09-12 17:06:24 -0300196 /* Entry 9 is for HDMI: */
197 for (i = 0; i < 2; i++) {
198 I915_WRITE(reg, hsw_ddi_translations_hdmi[hdmi_level * 2 + i]);
199 reg += 4;
200 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300201}
202
203/* Program DDI buffers translations for DP. By default, program ports A-D in DP
204 * mode and port E for FDI.
205 */
206void intel_prepare_ddi(struct drm_device *dev)
207{
208 int port;
209
Paulo Zanoni0d536cb2012-11-23 16:46:41 -0200210 if (!HAS_DDI(dev))
211 return;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300212
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300213 for (port = PORT_A; port <= PORT_E; port++)
214 intel_prepare_ddi_buffers(dev, port);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300215}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300216
217static const long hsw_ddi_buf_ctl_values[] = {
218 DDI_BUF_EMP_400MV_0DB_HSW,
219 DDI_BUF_EMP_400MV_3_5DB_HSW,
220 DDI_BUF_EMP_400MV_6DB_HSW,
221 DDI_BUF_EMP_400MV_9_5DB_HSW,
222 DDI_BUF_EMP_600MV_0DB_HSW,
223 DDI_BUF_EMP_600MV_3_5DB_HSW,
224 DDI_BUF_EMP_600MV_6DB_HSW,
225 DDI_BUF_EMP_800MV_0DB_HSW,
226 DDI_BUF_EMP_800MV_3_5DB_HSW
227};
228
Paulo Zanoni248138b2012-11-29 11:29:31 -0200229static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
230 enum port port)
231{
232 uint32_t reg = DDI_BUF_CTL(port);
233 int i;
234
235 for (i = 0; i < 8; i++) {
236 udelay(1);
237 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
238 return;
239 }
240 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
241}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300242
243/* Starting with Haswell, different DDI ports can work in FDI mode for
244 * connection to the PCH-located connectors. For this, it is necessary to train
245 * both the DDI port and PCH receiver for the desired DDI buffer settings.
246 *
247 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
248 * please note that when FDI mode is active on DDI E, it shares 2 lines with
249 * DDI A (which is used for eDP)
250 */
251
252void hsw_fdi_link_train(struct drm_crtc *crtc)
253{
254 struct drm_device *dev = crtc->dev;
255 struct drm_i915_private *dev_priv = dev->dev_private;
256 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni04945642012-11-01 21:00:59 -0200257 u32 temp, i, rx_ctl_val;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300258
Paulo Zanoni04945642012-11-01 21:00:59 -0200259 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
260 * mode set "sequence for CRT port" document:
261 * - TP1 to TP2 time with the default value
262 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100263 *
264 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200265 */
266 I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) |
267 FDI_RX_PWRDN_LANE0_VAL(2) |
268 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
269
270 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000271 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100272 FDI_RX_PLL_ENABLE |
Daniel Vetter627eb5a2013-04-29 19:33:42 +0200273 FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
Paulo Zanoni04945642012-11-01 21:00:59 -0200274 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
275 POSTING_READ(_FDI_RXA_CTL);
276 udelay(220);
277
278 /* Switch from Rawclk to PCDclk */
279 rx_ctl_val |= FDI_PCDCLK;
280 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
281
282 /* Configure Port Clock Select */
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300283 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config.ddi_pll_sel);
284 WARN_ON(intel_crtc->config.ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200285
286 /* Start the training iterating through available voltages and emphasis,
287 * testing each value twice. */
288 for (i = 0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300289 /* Configure DP_TP_CTL with auto-training */
290 I915_WRITE(DP_TP_CTL(PORT_E),
291 DP_TP_CTL_FDI_AUTOTRAIN |
292 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
293 DP_TP_CTL_LINK_TRAIN_PAT1 |
294 DP_TP_CTL_ENABLE);
295
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000296 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
297 * DDI E does not support port reversal, the functionality is
298 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
299 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300300 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200301 DDI_BUF_CTL_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100302 ((intel_crtc->config.fdi_lanes - 1) << 1) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200303 hsw_ddi_buf_ctl_values[i / 2]);
304 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300305
306 udelay(600);
307
Paulo Zanoni04945642012-11-01 21:00:59 -0200308 /* Program PCH FDI Receiver TU */
309 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300310
Paulo Zanoni04945642012-11-01 21:00:59 -0200311 /* Enable PCH FDI Receiver with auto-training */
312 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
313 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
314 POSTING_READ(_FDI_RXA_CTL);
315
316 /* Wait for FDI receiver lane calibration */
317 udelay(30);
318
319 /* Unset FDI_RX_MISC pwrdn lanes */
320 temp = I915_READ(_FDI_RXA_MISC);
321 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
322 I915_WRITE(_FDI_RXA_MISC, temp);
323 POSTING_READ(_FDI_RXA_MISC);
324
325 /* Wait for FDI auto training time */
326 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300327
328 temp = I915_READ(DP_TP_STATUS(PORT_E));
329 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200330 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300331
332 /* Enable normal pixel sending for FDI */
333 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200334 DP_TP_CTL_FDI_AUTOTRAIN |
335 DP_TP_CTL_LINK_TRAIN_NORMAL |
336 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
337 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300338
Paulo Zanoni04945642012-11-01 21:00:59 -0200339 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300340 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200341
Paulo Zanoni248138b2012-11-29 11:29:31 -0200342 temp = I915_READ(DDI_BUF_CTL(PORT_E));
343 temp &= ~DDI_BUF_CTL_ENABLE;
344 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
345 POSTING_READ(DDI_BUF_CTL(PORT_E));
346
Paulo Zanoni04945642012-11-01 21:00:59 -0200347 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200348 temp = I915_READ(DP_TP_CTL(PORT_E));
349 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
350 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
351 I915_WRITE(DP_TP_CTL(PORT_E), temp);
352 POSTING_READ(DP_TP_CTL(PORT_E));
353
354 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200355
356 rx_ctl_val &= ~FDI_RX_ENABLE;
357 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200358 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200359
360 /* Reset FDI_RX_MISC pwrdn lanes */
361 temp = I915_READ(_FDI_RXA_MISC);
362 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
363 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
364 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200365 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300366 }
367
Paulo Zanoni04945642012-11-01 21:00:59 -0200368 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300369}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300370
Dave Airlie44905a22014-05-02 13:36:43 +1000371void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
372{
373 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
374 struct intel_digital_port *intel_dig_port =
375 enc_to_dig_port(&encoder->base);
376
377 intel_dp->DP = intel_dig_port->saved_port_bits |
378 DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
379 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
380
381}
382
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300383static struct intel_encoder *
384intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
385{
386 struct drm_device *dev = crtc->dev;
387 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
388 struct intel_encoder *intel_encoder, *ret = NULL;
389 int num_encoders = 0;
390
391 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
392 ret = intel_encoder;
393 num_encoders++;
394 }
395
396 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300397 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
398 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300399
400 BUG_ON(ret == NULL);
401 return ret;
402}
403
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100404#define LC_FREQ 2700
405#define LC_FREQ_2K (LC_FREQ * 2000)
406
407#define P_MIN 2
408#define P_MAX 64
409#define P_INC 2
410
411/* Constraints for PLL good behavior */
412#define REF_MIN 48
413#define REF_MAX 400
414#define VCO_MIN 2400
415#define VCO_MAX 4800
416
417#define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
418
419struct wrpll_rnp {
420 unsigned p, n2, r2;
421};
422
423static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300424{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100425 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300426
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100427 switch (clock) {
428 case 25175000:
429 case 25200000:
430 case 27000000:
431 case 27027000:
432 case 37762500:
433 case 37800000:
434 case 40500000:
435 case 40541000:
436 case 54000000:
437 case 54054000:
438 case 59341000:
439 case 59400000:
440 case 72000000:
441 case 74176000:
442 case 74250000:
443 case 81000000:
444 case 81081000:
445 case 89012000:
446 case 89100000:
447 case 108000000:
448 case 108108000:
449 case 111264000:
450 case 111375000:
451 case 148352000:
452 case 148500000:
453 case 162000000:
454 case 162162000:
455 case 222525000:
456 case 222750000:
457 case 296703000:
458 case 297000000:
459 budget = 0;
460 break;
461 case 233500000:
462 case 245250000:
463 case 247750000:
464 case 253250000:
465 case 298000000:
466 budget = 1500;
467 break;
468 case 169128000:
469 case 169500000:
470 case 179500000:
471 case 202000000:
472 budget = 2000;
473 break;
474 case 256250000:
475 case 262500000:
476 case 270000000:
477 case 272500000:
478 case 273750000:
479 case 280750000:
480 case 281250000:
481 case 286000000:
482 case 291750000:
483 budget = 4000;
484 break;
485 case 267250000:
486 case 268500000:
487 budget = 5000;
488 break;
489 default:
490 budget = 1000;
491 break;
492 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300493
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100494 return budget;
495}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300496
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100497static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
498 unsigned r2, unsigned n2, unsigned p,
499 struct wrpll_rnp *best)
500{
501 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300502
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100503 /* No best (r,n,p) yet */
504 if (best->p == 0) {
505 best->p = p;
506 best->n2 = n2;
507 best->r2 = r2;
508 return;
509 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300510
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100511 /*
512 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
513 * freq2k.
514 *
515 * delta = 1e6 *
516 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
517 * freq2k;
518 *
519 * and we would like delta <= budget.
520 *
521 * If the discrepancy is above the PPM-based budget, always prefer to
522 * improve upon the previous solution. However, if you're within the
523 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
524 */
525 a = freq2k * budget * p * r2;
526 b = freq2k * budget * best->p * best->r2;
527 diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
528 diff_best = ABS_DIFF((freq2k * best->p * best->r2),
529 (LC_FREQ_2K * best->n2));
530 c = 1000000 * diff;
531 d = 1000000 * diff_best;
532
533 if (a < c && b < d) {
534 /* If both are above the budget, pick the closer */
535 if (best->p * best->r2 * diff < p * r2 * diff_best) {
536 best->p = p;
537 best->n2 = n2;
538 best->r2 = r2;
539 }
540 } else if (a >= c && b < d) {
541 /* If A is below the threshold but B is above it? Update. */
542 best->p = p;
543 best->n2 = n2;
544 best->r2 = r2;
545 } else if (a >= c && b >= d) {
546 /* Both are below the limit, so pick the higher n2/(r2*r2) */
547 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
548 best->p = p;
549 best->n2 = n2;
550 best->r2 = r2;
551 }
552 }
553 /* Otherwise a < c && b >= d, do nothing */
554}
555
Jesse Barnes11578552014-01-21 12:42:10 -0800556static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
557 int reg)
558{
559 int refclk = LC_FREQ;
560 int n, p, r;
561 u32 wrpll;
562
563 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300564 switch (wrpll & WRPLL_PLL_REF_MASK) {
565 case WRPLL_PLL_SSC:
566 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800567 /*
568 * We could calculate spread here, but our checking
569 * code only cares about 5% accuracy, and spread is a max of
570 * 0.5% downspread.
571 */
572 refclk = 135;
573 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300574 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800575 refclk = LC_FREQ;
576 break;
577 default:
578 WARN(1, "bad wrpll refclk\n");
579 return 0;
580 }
581
582 r = wrpll & WRPLL_DIVIDER_REF_MASK;
583 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
584 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
585
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800586 /* Convert to KHz, p & r have a fixed point portion */
587 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800588}
589
Dave Airlie0e32b392014-05-02 14:02:48 +1000590void intel_ddi_clock_get(struct intel_encoder *encoder,
591 struct intel_crtc_config *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -0800592{
593 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jesse Barnes11578552014-01-21 12:42:10 -0800594 int link_clock = 0;
595 u32 val, pll;
596
Daniel Vetter26804af2014-06-25 22:01:55 +0300597 val = pipe_config->ddi_pll_sel;
Jesse Barnes11578552014-01-21 12:42:10 -0800598 switch (val & PORT_CLK_SEL_MASK) {
599 case PORT_CLK_SEL_LCPLL_810:
600 link_clock = 81000;
601 break;
602 case PORT_CLK_SEL_LCPLL_1350:
603 link_clock = 135000;
604 break;
605 case PORT_CLK_SEL_LCPLL_2700:
606 link_clock = 270000;
607 break;
608 case PORT_CLK_SEL_WRPLL1:
609 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
610 break;
611 case PORT_CLK_SEL_WRPLL2:
612 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
613 break;
614 case PORT_CLK_SEL_SPLL:
615 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
616 if (pll == SPLL_PLL_FREQ_810MHz)
617 link_clock = 81000;
618 else if (pll == SPLL_PLL_FREQ_1350MHz)
619 link_clock = 135000;
620 else if (pll == SPLL_PLL_FREQ_2700MHz)
621 link_clock = 270000;
622 else {
623 WARN(1, "bad spll freq\n");
624 return;
625 }
626 break;
627 default:
628 WARN(1, "bad port clock sel\n");
629 return;
630 }
631
632 pipe_config->port_clock = link_clock * 2;
633
634 if (pipe_config->has_pch_encoder)
635 pipe_config->adjusted_mode.crtc_clock =
636 intel_dotclock_calculate(pipe_config->port_clock,
637 &pipe_config->fdi_m_n);
638 else if (pipe_config->has_dp_encoder)
639 pipe_config->adjusted_mode.crtc_clock =
640 intel_dotclock_calculate(pipe_config->port_clock,
641 &pipe_config->dp_m_n);
642 else
643 pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
644}
645
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100646static void
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100647hsw_ddi_calculate_wrpll(int clock /* in Hz */,
648 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100649{
650 uint64_t freq2k;
651 unsigned p, n2, r2;
652 struct wrpll_rnp best = { 0, 0, 0 };
653 unsigned budget;
654
655 freq2k = clock / 100;
656
657 budget = wrpll_get_budget_for_freq(clock);
658
659 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
660 * and directly pass the LC PLL to it. */
661 if (freq2k == 5400000) {
662 *n2_out = 2;
663 *p_out = 1;
664 *r2_out = 2;
665 return;
666 }
667
668 /*
669 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
670 * the WR PLL.
671 *
672 * We want R so that REF_MIN <= Ref <= REF_MAX.
673 * Injecting R2 = 2 * R gives:
674 * REF_MAX * r2 > LC_FREQ * 2 and
675 * REF_MIN * r2 < LC_FREQ * 2
676 *
677 * Which means the desired boundaries for r2 are:
678 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
679 *
680 */
681 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
682 r2 <= LC_FREQ * 2 / REF_MIN;
683 r2++) {
684
685 /*
686 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
687 *
688 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
689 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
690 * VCO_MAX * r2 > n2 * LC_FREQ and
691 * VCO_MIN * r2 < n2 * LC_FREQ)
692 *
693 * Which means the desired boundaries for n2 are:
694 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
695 */
696 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
697 n2 <= VCO_MAX * r2 / LC_FREQ;
698 n2++) {
699
700 for (p = P_MIN; p <= P_MAX; p += P_INC)
701 wrpll_update_rnp(freq2k, budget,
702 r2, n2, p, &best);
703 }
704 }
705
706 *n2_out = best.n2;
707 *p_out = best.p;
708 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300709}
710
Damien Lespiau0220ab62014-07-29 18:06:22 +0100711static bool
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100712hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
713 struct intel_encoder *intel_encoder,
714 int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300715{
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100716 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
Daniel Vettere0b01be2014-06-25 22:02:01 +0300717 struct intel_shared_dpll *pll;
Daniel Vetter716c2e52014-06-25 22:02:02 +0300718 uint32_t val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100719 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300720
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100721 hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300722
Daniel Vetter114fe482014-06-25 22:01:48 +0300723 val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300724 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
725 WRPLL_DIVIDER_POST(p);
726
Daniel Vetter716c2e52014-06-25 22:02:02 +0300727 intel_crtc->config.dpll_hw_state.wrpll = val;
728
729 pll = intel_get_shared_dpll(intel_crtc);
730 if (pll == NULL) {
731 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
732 pipe_name(intel_crtc->pipe));
Paulo Zanoni06940012013-10-30 18:27:43 -0200733 return false;
734 }
735
Daniel Vetter716c2e52014-06-25 22:02:02 +0300736 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300737 }
738
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300739 return true;
740}
741
Damien Lespiau0220ab62014-07-29 18:06:22 +0100742
743/*
744 * Tries to find a *shared* PLL for the CRTC and store it in
745 * intel_crtc->ddi_pll_sel.
746 *
747 * For private DPLLs, compute_config() should do the selection for us. This
748 * function should be folded into compute_config() eventually.
749 */
750bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
751{
752 struct drm_crtc *crtc = &intel_crtc->base;
753 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Damien Lespiau0220ab62014-07-29 18:06:22 +0100754 int clock = intel_crtc->config.port_clock;
755
756 intel_put_shared_dpll(intel_crtc);
757
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100758 return hsw_ddi_pll_select(intel_crtc, intel_encoder, clock);
Damien Lespiau0220ab62014-07-29 18:06:22 +0100759}
760
Paulo Zanonidae84792012-10-15 15:51:30 -0300761void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
762{
763 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
764 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
765 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200766 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300767 int type = intel_encoder->type;
768 uint32_t temp;
769
Dave Airlie0e32b392014-05-02 14:02:48 +1000770 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Paulo Zanonic9809792012-10-23 18:30:00 -0200771 temp = TRANS_MSA_SYNC_CLK;
Daniel Vetter965e0c42013-03-27 00:44:57 +0100772 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -0300773 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200774 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300775 break;
776 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200777 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300778 break;
779 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200780 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300781 break;
782 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200783 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300784 break;
785 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100786 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -0300787 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200788 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300789 }
790}
791
Dave Airlie0e32b392014-05-02 14:02:48 +1000792void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
793{
794 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
795 struct drm_device *dev = crtc->dev;
796 struct drm_i915_private *dev_priv = dev->dev_private;
797 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
798 uint32_t temp;
799 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
800 if (state == true)
801 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
802 else
803 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
804 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
805}
806
Damien Lespiau8228c252013-03-07 15:30:27 +0000807void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300808{
809 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
810 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300811 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -0700812 struct drm_device *dev = crtc->dev;
813 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300814 enum pipe pipe = intel_crtc->pipe;
Daniel Vetter3b117c82013-04-17 20:15:07 +0200815 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200816 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300817 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300818 uint32_t temp;
819
Paulo Zanoniad80a812012-10-24 16:06:19 -0200820 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
821 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200822 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -0300823
Daniel Vetter965e0c42013-03-27 00:44:57 +0100824 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -0300825 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200826 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300827 break;
828 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200829 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300830 break;
831 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200832 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300833 break;
834 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200835 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300836 break;
837 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100838 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -0300839 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300840
Ville Syrjäläa6662832013-09-10 17:03:41 +0300841 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200842 temp |= TRANS_DDI_PVSYNC;
Ville Syrjäläa6662832013-09-10 17:03:41 +0300843 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200844 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c2012-08-08 14:15:28 -0300845
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200846 if (cpu_transcoder == TRANSCODER_EDP) {
847 switch (pipe) {
848 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -0700849 /* On Haswell, can only use the always-on power well for
850 * eDP when not using the panel fitter, and when not
851 * using motion blur mitigation (which we don't
852 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +0200853 if (IS_HASWELL(dev) &&
854 (intel_crtc->config.pch_pfit.enabled ||
855 intel_crtc->config.pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -0200856 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
857 else
858 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200859 break;
860 case PIPE_B:
861 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
862 break;
863 case PIPE_C:
864 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
865 break;
866 default:
867 BUG();
868 break;
869 }
870 }
871
Paulo Zanoni7739c332012-10-15 15:51:29 -0300872 if (type == INTEL_OUTPUT_HDMI) {
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200873 if (intel_crtc->config.has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200874 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300875 else
Paulo Zanoniad80a812012-10-24 16:06:19 -0200876 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300877
Paulo Zanoni7739c332012-10-15 15:51:29 -0300878 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -0200879 temp |= TRANS_DDI_MODE_SELECT_FDI;
Daniel Vetter33d29b12013-02-13 18:04:45 +0100880 temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300881
882 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
883 type == INTEL_OUTPUT_EDP) {
884 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
885
Dave Airlie0e32b392014-05-02 14:02:48 +1000886 if (intel_dp->is_mst) {
887 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
888 } else
889 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
890
891 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
892 } else if (type == INTEL_OUTPUT_DP_MST) {
893 struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
894
895 if (intel_dp->is_mst) {
896 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
897 } else
898 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300899
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200900 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300901 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300902 WARN(1, "Invalid encoder type %d for pipe %c\n",
903 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300904 }
905
Paulo Zanoniad80a812012-10-24 16:06:19 -0200906 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300907}
908
Paulo Zanoniad80a812012-10-24 16:06:19 -0200909void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
910 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300911{
Paulo Zanoniad80a812012-10-24 16:06:19 -0200912 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300913 uint32_t val = I915_READ(reg);
914
Dave Airlie0e32b392014-05-02 14:02:48 +1000915 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -0200916 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300917 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300918}
919
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200920bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
921{
922 struct drm_device *dev = intel_connector->base.dev;
923 struct drm_i915_private *dev_priv = dev->dev_private;
924 struct intel_encoder *intel_encoder = intel_connector->encoder;
925 int type = intel_connector->base.connector_type;
926 enum port port = intel_ddi_get_encoder_port(intel_encoder);
927 enum pipe pipe = 0;
928 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -0300929 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200930 uint32_t tmp;
931
Paulo Zanoni882244a2014-04-01 14:55:12 -0300932 power_domain = intel_display_port_power_domain(intel_encoder);
933 if (!intel_display_power_enabled(dev_priv, power_domain))
934 return false;
935
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200936 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
937 return false;
938
939 if (port == PORT_A)
940 cpu_transcoder = TRANSCODER_EDP;
941 else
Daniel Vetter1a240d42012-11-29 22:18:51 +0100942 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200943
944 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
945
946 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
947 case TRANS_DDI_MODE_SELECT_HDMI:
948 case TRANS_DDI_MODE_SELECT_DVI:
949 return (type == DRM_MODE_CONNECTOR_HDMIA);
950
951 case TRANS_DDI_MODE_SELECT_DP_SST:
952 if (type == DRM_MODE_CONNECTOR_eDP)
953 return true;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200954 return (type == DRM_MODE_CONNECTOR_DisplayPort);
Dave Airlie0e32b392014-05-02 14:02:48 +1000955 case TRANS_DDI_MODE_SELECT_DP_MST:
956 /* if the transcoder is in MST state then
957 * connector isn't connected */
958 return false;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200959
960 case TRANS_DDI_MODE_SELECT_FDI:
961 return (type == DRM_MODE_CONNECTOR_VGA);
962
963 default:
964 return false;
965 }
966}
967
Daniel Vetter85234cd2012-07-02 13:27:29 +0200968bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
969 enum pipe *pipe)
970{
971 struct drm_device *dev = encoder->base.dev;
972 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -0300973 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +0200974 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200975 u32 tmp;
976 int i;
977
Imre Deak6d129be2014-03-05 16:20:54 +0200978 power_domain = intel_display_port_power_domain(encoder);
979 if (!intel_display_power_enabled(dev_priv, power_domain))
980 return false;
981
Paulo Zanonife43d3f2012-10-15 15:51:39 -0300982 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +0200983
984 if (!(tmp & DDI_BUF_CTL_ENABLE))
985 return false;
986
Paulo Zanoniad80a812012-10-24 16:06:19 -0200987 if (port == PORT_A) {
988 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +0200989
Paulo Zanoniad80a812012-10-24 16:06:19 -0200990 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
991 case TRANS_DDI_EDP_INPUT_A_ON:
992 case TRANS_DDI_EDP_INPUT_A_ONOFF:
993 *pipe = PIPE_A;
994 break;
995 case TRANS_DDI_EDP_INPUT_B_ONOFF:
996 *pipe = PIPE_B;
997 break;
998 case TRANS_DDI_EDP_INPUT_C_ONOFF:
999 *pipe = PIPE_C;
1000 break;
1001 }
1002
1003 return true;
1004 } else {
1005 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1006 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1007
1008 if ((tmp & TRANS_DDI_PORT_MASK)
1009 == TRANS_DDI_SELECT_PORT(port)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10001010 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST)
1011 return false;
1012
Paulo Zanoniad80a812012-10-24 16:06:19 -02001013 *pipe = i;
1014 return true;
1015 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001016 }
1017 }
1018
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001019 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001020
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001021 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001022}
1023
Paulo Zanonifc914632012-10-05 12:05:54 -03001024void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1025{
1026 struct drm_crtc *crtc = &intel_crtc->base;
1027 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1028 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1029 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +02001030 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001031
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001032 if (cpu_transcoder != TRANSCODER_EDP)
1033 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1034 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001035}
1036
1037void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1038{
1039 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001040 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001041
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001042 if (cpu_transcoder != TRANSCODER_EDP)
1043 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1044 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001045}
1046
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001047static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001048{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001049 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001050 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001051 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001052 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001053 int type = intel_encoder->type;
1054
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001055 if (crtc->config.has_audio) {
1056 DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
1057 pipe_name(crtc->pipe));
1058
1059 /* write eld */
1060 DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
1061 intel_write_eld(encoder, &crtc->config.adjusted_mode);
1062 }
1063
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001064 if (type == INTEL_OUTPUT_EDP) {
1065 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001066 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001067 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001068
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001069 WARN_ON(crtc->config.ddi_pll_sel == PORT_CLK_SEL_NONE);
1070 I915_WRITE(PORT_CLK_SEL(port), crtc->config.ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001071
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001072 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001073 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001074
Dave Airlie44905a22014-05-02 13:36:43 +10001075 intel_ddi_init_dp_buf_reg(intel_encoder);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001076
1077 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1078 intel_dp_start_link_train(intel_dp);
1079 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001080 if (port != PORT_A)
1081 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001082 } else if (type == INTEL_OUTPUT_HDMI) {
1083 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1084
1085 intel_hdmi->set_infoframes(encoder,
1086 crtc->config.has_hdmi_sink,
1087 &crtc->config.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001088 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001089}
1090
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001091static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001092{
1093 struct drm_encoder *encoder = &intel_encoder->base;
1094 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1095 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001096 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001097 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001098 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001099
1100 val = I915_READ(DDI_BUF_CTL(port));
1101 if (val & DDI_BUF_CTL_ENABLE) {
1102 val &= ~DDI_BUF_CTL_ENABLE;
1103 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001104 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001105 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001106
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001107 val = I915_READ(DP_TP_CTL(port));
1108 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1109 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1110 I915_WRITE(DP_TP_CTL(port), val);
1111
1112 if (wait)
1113 intel_wait_ddi_buf_idle(dev_priv, port);
1114
Jani Nikula76bb80e2013-11-15 15:29:57 +02001115 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001116 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001117 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001118 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001119 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001120 }
1121
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001122 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1123}
1124
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001125static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001126{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001127 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001128 struct drm_crtc *crtc = encoder->crtc;
1129 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1130 int pipe = intel_crtc->pipe;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001131 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001132 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001133 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1134 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001135 uint32_t tmp;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001136
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001137 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001138 struct intel_digital_port *intel_dig_port =
1139 enc_to_dig_port(encoder);
1140
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001141 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1142 * are ignored so nothing special needs to be done besides
1143 * enabling the port.
1144 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001145 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001146 intel_dig_port->saved_port_bits |
1147 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001148 } else if (type == INTEL_OUTPUT_EDP) {
1149 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1150
Imre Deak3ab9c632013-05-03 12:57:41 +03001151 if (port == PORT_A)
1152 intel_dp_stop_link_train(intel_dp);
1153
Daniel Vetter4be73782014-01-17 14:39:48 +01001154 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi49065572013-07-11 18:45:05 -03001155 intel_edp_psr_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001156 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001157
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001158 if (intel_crtc->config.has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001159 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001160 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1161 tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1162 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1163 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001164}
1165
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001166static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001167{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001168 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001169 struct drm_crtc *crtc = encoder->crtc;
1170 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1171 int pipe = intel_crtc->pipe;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001172 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001173 struct drm_device *dev = encoder->dev;
1174 struct drm_i915_private *dev_priv = dev->dev_private;
1175 uint32_t tmp;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001176
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001177 /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
1178 * register is part of the power well on Haswell. */
1179 if (intel_crtc->config.has_audio) {
1180 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1181 tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1182 (pipe * 4));
1183 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1184 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1185 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001186
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001187 if (type == INTEL_OUTPUT_EDP) {
1188 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1189
Rodrigo Vivi49065572013-07-11 18:45:05 -03001190 intel_edp_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001191 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001192 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001193}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001194
Damien Lespiauad13d602014-07-29 18:06:24 +01001195static int bdw_get_cdclk_freq(struct drm_i915_private *dev_priv)
1196{
1197 uint32_t lcpll = I915_READ(LCPLL_CTL);
1198 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
1199
1200 if (lcpll & LCPLL_CD_SOURCE_FCLK)
1201 return 800000;
1202 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
1203 return 450000;
1204 else if (freq == LCPLL_CLK_FREQ_450)
1205 return 450000;
1206 else if (freq == LCPLL_CLK_FREQ_54O_BDW)
1207 return 540000;
1208 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
1209 return 337500;
1210 else
1211 return 675000;
1212}
1213
1214static int hsw_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001215{
Paulo Zanonie39bf982013-11-02 21:07:36 -07001216 struct drm_device *dev = dev_priv->dev;
Paulo Zanonia4006642013-08-06 18:57:11 -03001217 uint32_t lcpll = I915_READ(LCPLL_CTL);
Paulo Zanonie39bf982013-11-02 21:07:36 -07001218 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Paulo Zanonia4006642013-08-06 18:57:11 -03001219
Damien Lespiauad13d602014-07-29 18:06:24 +01001220 if (lcpll & LCPLL_CD_SOURCE_FCLK)
Paulo Zanonia4006642013-08-06 18:57:11 -03001221 return 800000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001222 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001223 return 450000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001224 else if (freq == LCPLL_CLK_FREQ_450)
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001225 return 450000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001226 else if (IS_ULT(dev))
1227 return 337500;
1228 else
1229 return 540000;
1230}
1231
1232int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
1233{
1234 struct drm_device *dev = dev_priv->dev;
1235
1236 if (IS_BROADWELL(dev))
1237 return bdw_get_cdclk_freq(dev_priv);
1238
1239 /* Haswell */
1240 return hsw_get_cdclk_freq(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001241}
1242
Daniel Vettere0b01be2014-06-25 22:02:01 +03001243static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv,
1244 struct intel_shared_dpll *pll)
1245{
Daniel Vettere0b01be2014-06-25 22:02:01 +03001246 I915_WRITE(WRPLL_CTL(pll->id), pll->hw_state.wrpll);
1247 POSTING_READ(WRPLL_CTL(pll->id));
1248 udelay(20);
1249}
1250
Daniel Vetter12030432014-06-25 22:02:00 +03001251static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv,
1252 struct intel_shared_dpll *pll)
1253{
1254 uint32_t val;
1255
1256 val = I915_READ(WRPLL_CTL(pll->id));
Daniel Vetter12030432014-06-25 22:02:00 +03001257 I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
1258 POSTING_READ(WRPLL_CTL(pll->id));
1259}
1260
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001261static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
1262 struct intel_shared_dpll *pll,
1263 struct intel_dpll_hw_state *hw_state)
1264{
1265 uint32_t val;
1266
1267 if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
1268 return false;
1269
1270 val = I915_READ(WRPLL_CTL(pll->id));
1271 hw_state->wrpll = val;
1272
1273 return val & WRPLL_PLL_ENABLE;
1274}
1275
Damien Lespiauca1381b2014-07-15 15:05:33 +01001276static const char * const hsw_ddi_pll_names[] = {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001277 "WRPLL 1",
1278 "WRPLL 2",
1279};
1280
Damien Lespiau143b3072014-07-29 18:06:19 +01001281static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001282{
Daniel Vetter9cd86932014-06-25 22:01:57 +03001283 int i;
1284
Daniel Vetter716c2e52014-06-25 22:02:02 +03001285 dev_priv->num_shared_dpll = 2;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001286
Daniel Vetter716c2e52014-06-25 22:02:02 +03001287 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001288 dev_priv->shared_dplls[i].id = i;
1289 dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
Daniel Vetter12030432014-06-25 22:02:00 +03001290 dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable;
Daniel Vettere0b01be2014-06-25 22:02:01 +03001291 dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable;
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001292 dev_priv->shared_dplls[i].get_hw_state =
1293 hsw_ddi_pll_get_hw_state;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001294 }
Damien Lespiau143b3072014-07-29 18:06:19 +01001295}
1296
1297void intel_ddi_pll_init(struct drm_device *dev)
1298{
1299 struct drm_i915_private *dev_priv = dev->dev_private;
1300 uint32_t val = I915_READ(LCPLL_CTL);
1301
1302 hsw_shared_dplls_init(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001303
1304 /* The LCPLL register should be turned on by the BIOS. For now let's
1305 * just check its state and print errors in case something is wrong.
1306 * Don't even try to turn it on.
1307 */
1308
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001309 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001310 intel_ddi_get_cdclk_freq(dev_priv));
1311
1312 if (val & LCPLL_CD_SOURCE_FCLK)
1313 DRM_ERROR("CDCLK source is not LCPLL\n");
1314
1315 if (val & LCPLL_PLL_DISABLE)
1316 DRM_ERROR("LCPLL is disabled\n");
1317}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001318
1319void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1320{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001321 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1322 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001323 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001324 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001325 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301326 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001327
1328 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1329 val = I915_READ(DDI_BUF_CTL(port));
1330 if (val & DDI_BUF_CTL_ENABLE) {
1331 val &= ~DDI_BUF_CTL_ENABLE;
1332 I915_WRITE(DDI_BUF_CTL(port), val);
1333 wait = true;
1334 }
1335
1336 val = I915_READ(DP_TP_CTL(port));
1337 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1338 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1339 I915_WRITE(DP_TP_CTL(port), val);
1340 POSTING_READ(DP_TP_CTL(port));
1341
1342 if (wait)
1343 intel_wait_ddi_buf_idle(dev_priv, port);
1344 }
1345
Dave Airlie0e32b392014-05-02 14:02:48 +10001346 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03001347 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Dave Airlie0e32b392014-05-02 14:02:48 +10001348 if (intel_dp->is_mst)
1349 val |= DP_TP_CTL_MODE_MST;
1350 else {
1351 val |= DP_TP_CTL_MODE_SST;
1352 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1353 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1354 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03001355 I915_WRITE(DP_TP_CTL(port), val);
1356 POSTING_READ(DP_TP_CTL(port));
1357
1358 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1359 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1360 POSTING_READ(DDI_BUF_CTL(port));
1361
1362 udelay(600);
1363}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001364
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001365void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1366{
1367 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1368 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1369 uint32_t val;
1370
1371 intel_ddi_post_disable(intel_encoder);
1372
1373 val = I915_READ(_FDI_RXA_CTL);
1374 val &= ~FDI_RX_ENABLE;
1375 I915_WRITE(_FDI_RXA_CTL, val);
1376
1377 val = I915_READ(_FDI_RXA_MISC);
1378 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1379 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1380 I915_WRITE(_FDI_RXA_MISC, val);
1381
1382 val = I915_READ(_FDI_RXA_CTL);
1383 val &= ~FDI_PCDCLK;
1384 I915_WRITE(_FDI_RXA_CTL, val);
1385
1386 val = I915_READ(_FDI_RXA_CTL);
1387 val &= ~FDI_RX_PLL_ENABLE;
1388 I915_WRITE(_FDI_RXA_CTL, val);
1389}
1390
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001391static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1392{
Dave Airlie0e32b392014-05-02 14:02:48 +10001393 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&intel_encoder->base);
1394 int type = intel_dig_port->base.type;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001395
Dave Airlie0e32b392014-05-02 14:02:48 +10001396 if (type != INTEL_OUTPUT_DISPLAYPORT &&
1397 type != INTEL_OUTPUT_EDP &&
1398 type != INTEL_OUTPUT_UNKNOWN) {
1399 return;
1400 }
1401
1402 intel_dp_hot_plug(intel_encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001403}
1404
Ville Syrjälä6801c182013-09-24 14:24:05 +03001405void intel_ddi_get_config(struct intel_encoder *encoder,
1406 struct intel_crtc_config *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001407{
1408 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1409 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1410 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
1411 u32 temp, flags = 0;
1412
1413 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1414 if (temp & TRANS_DDI_PHSYNC)
1415 flags |= DRM_MODE_FLAG_PHSYNC;
1416 else
1417 flags |= DRM_MODE_FLAG_NHSYNC;
1418 if (temp & TRANS_DDI_PVSYNC)
1419 flags |= DRM_MODE_FLAG_PVSYNC;
1420 else
1421 flags |= DRM_MODE_FLAG_NVSYNC;
1422
1423 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001424
1425 switch (temp & TRANS_DDI_BPC_MASK) {
1426 case TRANS_DDI_BPC_6:
1427 pipe_config->pipe_bpp = 18;
1428 break;
1429 case TRANS_DDI_BPC_8:
1430 pipe_config->pipe_bpp = 24;
1431 break;
1432 case TRANS_DDI_BPC_10:
1433 pipe_config->pipe_bpp = 30;
1434 break;
1435 case TRANS_DDI_BPC_12:
1436 pipe_config->pipe_bpp = 36;
1437 break;
1438 default:
1439 break;
1440 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001441
1442 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1443 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001444 pipe_config->has_hdmi_sink = true;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001445 case TRANS_DDI_MODE_SELECT_DVI:
1446 case TRANS_DDI_MODE_SELECT_FDI:
1447 break;
1448 case TRANS_DDI_MODE_SELECT_DP_SST:
1449 case TRANS_DDI_MODE_SELECT_DP_MST:
1450 pipe_config->has_dp_encoder = true;
1451 intel_dp_get_m_n(intel_crtc, pipe_config);
1452 break;
1453 default:
1454 break;
1455 }
Daniel Vetter10214422013-11-18 07:38:16 +01001456
Paulo Zanonia60551b2014-05-21 16:23:20 -03001457 if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
1458 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1459 if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
1460 pipe_config->has_audio = true;
1461 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001462
Daniel Vetter10214422013-11-18 07:38:16 +01001463 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1464 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1465 /*
1466 * This is a big fat ugly hack.
1467 *
1468 * Some machines in UEFI boot mode provide us a VBT that has 18
1469 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1470 * unknown we fail to light up. Yet the same BIOS boots up with
1471 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1472 * max, not what it tells us to use.
1473 *
1474 * Note: This will still be broken if the eDP panel is not lit
1475 * up by the BIOS, and thus we can't get the mode at module
1476 * load.
1477 */
1478 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1479 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1480 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1481 }
Jesse Barnes11578552014-01-21 12:42:10 -08001482
1483 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001484}
1485
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001486static void intel_ddi_destroy(struct drm_encoder *encoder)
1487{
1488 /* HDMI has nothing special to destroy, so we can go with this. */
1489 intel_dp_encoder_destroy(encoder);
1490}
1491
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001492static bool intel_ddi_compute_config(struct intel_encoder *encoder,
1493 struct intel_crtc_config *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001494{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001495 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02001496 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001497
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001498 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001499
Daniel Vettereccb1402013-05-22 00:50:22 +02001500 if (port == PORT_A)
1501 pipe_config->cpu_transcoder = TRANSCODER_EDP;
1502
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001503 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001504 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001505 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001506 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001507}
1508
1509static const struct drm_encoder_funcs intel_ddi_funcs = {
1510 .destroy = intel_ddi_destroy,
1511};
1512
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001513static struct intel_connector *
1514intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
1515{
1516 struct intel_connector *connector;
1517 enum port port = intel_dig_port->port;
1518
1519 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1520 if (!connector)
1521 return NULL;
1522
1523 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1524 if (!intel_dp_init_connector(intel_dig_port, connector)) {
1525 kfree(connector);
1526 return NULL;
1527 }
1528
1529 return connector;
1530}
1531
1532static struct intel_connector *
1533intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
1534{
1535 struct intel_connector *connector;
1536 enum port port = intel_dig_port->port;
1537
1538 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1539 if (!connector)
1540 return NULL;
1541
1542 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
1543 intel_hdmi_init_connector(intel_dig_port, connector);
1544
1545 return connector;
1546}
1547
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001548void intel_ddi_init(struct drm_device *dev, enum port port)
1549{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001550 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001551 struct intel_digital_port *intel_dig_port;
1552 struct intel_encoder *intel_encoder;
1553 struct drm_encoder *encoder;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001554 bool init_hdmi, init_dp;
1555
1556 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1557 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1558 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1559 if (!init_dp && !init_hdmi) {
Chris Wilsonf68d6972014-08-04 07:15:09 +01001560 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, assuming it is\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03001561 port_name(port));
1562 init_hdmi = true;
1563 init_dp = true;
1564 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001565
Daniel Vetterb14c5672013-09-19 12:18:32 +02001566 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001567 if (!intel_dig_port)
1568 return;
1569
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001570 intel_encoder = &intel_dig_port->base;
1571 encoder = &intel_encoder->base;
1572
1573 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1574 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001575
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001576 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001577 intel_encoder->enable = intel_enable_ddi;
1578 intel_encoder->pre_enable = intel_ddi_pre_enable;
1579 intel_encoder->disable = intel_disable_ddi;
1580 intel_encoder->post_disable = intel_ddi_post_disable;
1581 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001582 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001583
1584 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001585 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
1586 (DDI_BUF_PORT_REVERSAL |
1587 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001588
1589 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Chris Wilsonf68d6972014-08-04 07:15:09 +01001590 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001591 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001592 intel_encoder->hot_plug = intel_ddi_hot_plug;
1593
Chris Wilsonf68d6972014-08-04 07:15:09 +01001594 if (init_dp) {
1595 if (!intel_ddi_init_dp_connector(intel_dig_port))
1596 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10001597
Chris Wilsonf68d6972014-08-04 07:15:09 +01001598 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
1599 dev_priv->hpd_irq_port[port] = intel_dig_port;
1600 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001601
Paulo Zanoni311a2092013-09-12 17:12:18 -03001602 /* In theory we don't need the encoder->type check, but leave it just in
1603 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01001604 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
1605 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
1606 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001607 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01001608
1609 return;
1610
1611err:
1612 drm_encoder_cleanup(encoder);
1613 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001614}