blob: 6cc79c83772c767ddcd245ae3f79e2c14951b240 [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
Paulo Zanoni174edf12012-10-26 19:05:50 -0200119 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200120 type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
Paulo Zanoni174edf12012-10-26 19:05:50 -0200121 struct intel_digital_port *intel_dig_port =
122 enc_to_dig_port(encoder);
123 return intel_dig_port->port;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300124
Paulo Zanonifc914632012-10-05 12:05:54 -0300125 } else if (type == INTEL_OUTPUT_ANALOG) {
126 return PORT_E;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300127
Paulo Zanonifc914632012-10-05 12:05:54 -0300128 } else {
129 DRM_ERROR("Invalid DDI encoder type %d\n", type);
130 BUG();
131 }
132}
133
Art Runyane58623c2013-11-02 21:07:41 -0700134/*
135 * Starting with Haswell, DDI port buffers must be programmed with correct
136 * values in advance. The buffer values are different for FDI and DP modes,
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300137 * but the HDMI/DVI fields are shared among those. So we program the DDI
138 * in either FDI or DP modes only, as HDMI connections will work with both
139 * of those
140 */
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300141static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300142{
143 struct drm_i915_private *dev_priv = dev->dev_private;
144 u32 reg;
145 int i;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300146 int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
Art Runyane58623c2013-11-02 21:07:41 -0700147 const u32 *ddi_translations_fdi;
148 const u32 *ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700149 const u32 *ddi_translations_edp;
Art Runyane58623c2013-11-02 21:07:41 -0700150 const u32 *ddi_translations;
151
152 if (IS_BROADWELL(dev)) {
153 ddi_translations_fdi = bdw_ddi_translations_fdi;
154 ddi_translations_dp = bdw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700155 ddi_translations_edp = bdw_ddi_translations_edp;
Art Runyane58623c2013-11-02 21:07:41 -0700156 } else if (IS_HASWELL(dev)) {
157 ddi_translations_fdi = hsw_ddi_translations_fdi;
158 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700159 ddi_translations_edp = hsw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700160 } else {
161 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700162 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700163 ddi_translations_fdi = bdw_ddi_translations_fdi;
164 ddi_translations_dp = bdw_ddi_translations_dp;
165 }
166
Paulo Zanoni300644c2013-11-02 21:07:42 -0700167 switch (port) {
168 case PORT_A:
169 ddi_translations = ddi_translations_edp;
170 break;
171 case PORT_B:
172 case PORT_C:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700173 ddi_translations = ddi_translations_dp;
174 break;
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700175 case PORT_D:
Ville Syrjälä5d8a7752013-11-01 18:22:39 +0200176 if (intel_dp_is_edp(dev, PORT_D))
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700177 ddi_translations = ddi_translations_edp;
178 else
179 ddi_translations = ddi_translations_dp;
180 break;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700181 case PORT_E:
182 ddi_translations = ddi_translations_fdi;
183 break;
184 default:
185 BUG();
186 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300187
Paulo Zanonif72d19f2013-08-05 17:25:55 -0300188 for (i = 0, reg = DDI_BUF_TRANS(port);
189 i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300190 I915_WRITE(reg, ddi_translations[i]);
191 reg += 4;
192 }
Paulo Zanoni6acab152013-09-12 17:06:24 -0300193 /* Entry 9 is for HDMI: */
194 for (i = 0; i < 2; i++) {
195 I915_WRITE(reg, hsw_ddi_translations_hdmi[hdmi_level * 2 + i]);
196 reg += 4;
197 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300198}
199
200/* Program DDI buffers translations for DP. By default, program ports A-D in DP
201 * mode and port E for FDI.
202 */
203void intel_prepare_ddi(struct drm_device *dev)
204{
205 int port;
206
Paulo Zanoni0d536cb42012-11-23 16:46:41 -0200207 if (!HAS_DDI(dev))
208 return;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300209
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300210 for (port = PORT_A; port <= PORT_E; port++)
211 intel_prepare_ddi_buffers(dev, port);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300212}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300213
214static const long hsw_ddi_buf_ctl_values[] = {
215 DDI_BUF_EMP_400MV_0DB_HSW,
216 DDI_BUF_EMP_400MV_3_5DB_HSW,
217 DDI_BUF_EMP_400MV_6DB_HSW,
218 DDI_BUF_EMP_400MV_9_5DB_HSW,
219 DDI_BUF_EMP_600MV_0DB_HSW,
220 DDI_BUF_EMP_600MV_3_5DB_HSW,
221 DDI_BUF_EMP_600MV_6DB_HSW,
222 DDI_BUF_EMP_800MV_0DB_HSW,
223 DDI_BUF_EMP_800MV_3_5DB_HSW
224};
225
Paulo Zanoni248138b2012-11-29 11:29:31 -0200226static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
227 enum port port)
228{
229 uint32_t reg = DDI_BUF_CTL(port);
230 int i;
231
232 for (i = 0; i < 8; i++) {
233 udelay(1);
234 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
235 return;
236 }
237 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
238}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300239
240/* Starting with Haswell, different DDI ports can work in FDI mode for
241 * connection to the PCH-located connectors. For this, it is necessary to train
242 * both the DDI port and PCH receiver for the desired DDI buffer settings.
243 *
244 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
245 * please note that when FDI mode is active on DDI E, it shares 2 lines with
246 * DDI A (which is used for eDP)
247 */
248
249void hsw_fdi_link_train(struct drm_crtc *crtc)
250{
251 struct drm_device *dev = crtc->dev;
252 struct drm_i915_private *dev_priv = dev->dev_private;
253 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni04945642012-11-01 21:00:59 -0200254 u32 temp, i, rx_ctl_val;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300255
Paulo Zanoni04945642012-11-01 21:00:59 -0200256 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
257 * mode set "sequence for CRT port" document:
258 * - TP1 to TP2 time with the default value
259 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100260 *
261 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200262 */
263 I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) |
264 FDI_RX_PWRDN_LANE0_VAL(2) |
265 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
266
267 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000268 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100269 FDI_RX_PLL_ENABLE |
Daniel Vetter627eb5a2013-04-29 19:33:42 +0200270 FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
Paulo Zanoni04945642012-11-01 21:00:59 -0200271 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
272 POSTING_READ(_FDI_RXA_CTL);
273 udelay(220);
274
275 /* Switch from Rawclk to PCDclk */
276 rx_ctl_val |= FDI_PCDCLK;
277 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
278
279 /* Configure Port Clock Select */
280 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->ddi_pll_sel);
281
282 /* Start the training iterating through available voltages and emphasis,
283 * testing each value twice. */
284 for (i = 0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300285 /* Configure DP_TP_CTL with auto-training */
286 I915_WRITE(DP_TP_CTL(PORT_E),
287 DP_TP_CTL_FDI_AUTOTRAIN |
288 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
289 DP_TP_CTL_LINK_TRAIN_PAT1 |
290 DP_TP_CTL_ENABLE);
291
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000292 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
293 * DDI E does not support port reversal, the functionality is
294 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
295 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300296 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200297 DDI_BUF_CTL_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100298 ((intel_crtc->config.fdi_lanes - 1) << 1) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200299 hsw_ddi_buf_ctl_values[i / 2]);
300 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300301
302 udelay(600);
303
Paulo Zanoni04945642012-11-01 21:00:59 -0200304 /* Program PCH FDI Receiver TU */
305 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300306
Paulo Zanoni04945642012-11-01 21:00:59 -0200307 /* Enable PCH FDI Receiver with auto-training */
308 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
309 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
310 POSTING_READ(_FDI_RXA_CTL);
311
312 /* Wait for FDI receiver lane calibration */
313 udelay(30);
314
315 /* Unset FDI_RX_MISC pwrdn lanes */
316 temp = I915_READ(_FDI_RXA_MISC);
317 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
318 I915_WRITE(_FDI_RXA_MISC, temp);
319 POSTING_READ(_FDI_RXA_MISC);
320
321 /* Wait for FDI auto training time */
322 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300323
324 temp = I915_READ(DP_TP_STATUS(PORT_E));
325 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200326 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300327
328 /* Enable normal pixel sending for FDI */
329 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200330 DP_TP_CTL_FDI_AUTOTRAIN |
331 DP_TP_CTL_LINK_TRAIN_NORMAL |
332 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
333 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300334
Paulo Zanoni04945642012-11-01 21:00:59 -0200335 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300336 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200337
Paulo Zanoni248138b2012-11-29 11:29:31 -0200338 temp = I915_READ(DDI_BUF_CTL(PORT_E));
339 temp &= ~DDI_BUF_CTL_ENABLE;
340 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
341 POSTING_READ(DDI_BUF_CTL(PORT_E));
342
Paulo Zanoni04945642012-11-01 21:00:59 -0200343 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200344 temp = I915_READ(DP_TP_CTL(PORT_E));
345 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
346 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
347 I915_WRITE(DP_TP_CTL(PORT_E), temp);
348 POSTING_READ(DP_TP_CTL(PORT_E));
349
350 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200351
352 rx_ctl_val &= ~FDI_RX_ENABLE;
353 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200354 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200355
356 /* Reset FDI_RX_MISC pwrdn lanes */
357 temp = I915_READ(_FDI_RXA_MISC);
358 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
359 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
360 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200361 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300362 }
363
Paulo Zanoni04945642012-11-01 21:00:59 -0200364 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300365}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300366
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300367static struct intel_encoder *
368intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
369{
370 struct drm_device *dev = crtc->dev;
371 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
372 struct intel_encoder *intel_encoder, *ret = NULL;
373 int num_encoders = 0;
374
375 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
376 ret = intel_encoder;
377 num_encoders++;
378 }
379
380 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300381 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
382 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300383
384 BUG_ON(ret == NULL);
385 return ret;
386}
387
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300388void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
389{
390 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
391 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
392 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
393 uint32_t val;
394
395 switch (intel_crtc->ddi_pll_sel) {
396 case PORT_CLK_SEL_SPLL:
397 plls->spll_refcount--;
398 if (plls->spll_refcount == 0) {
399 DRM_DEBUG_KMS("Disabling SPLL\n");
400 val = I915_READ(SPLL_CTL);
401 WARN_ON(!(val & SPLL_PLL_ENABLE));
402 I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
403 POSTING_READ(SPLL_CTL);
404 }
405 break;
406 case PORT_CLK_SEL_WRPLL1:
407 plls->wrpll1_refcount--;
408 if (plls->wrpll1_refcount == 0) {
409 DRM_DEBUG_KMS("Disabling WRPLL 1\n");
410 val = I915_READ(WRPLL_CTL1);
411 WARN_ON(!(val & WRPLL_PLL_ENABLE));
412 I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
413 POSTING_READ(WRPLL_CTL1);
414 }
415 break;
416 case PORT_CLK_SEL_WRPLL2:
417 plls->wrpll2_refcount--;
418 if (plls->wrpll2_refcount == 0) {
419 DRM_DEBUG_KMS("Disabling WRPLL 2\n");
420 val = I915_READ(WRPLL_CTL2);
421 WARN_ON(!(val & WRPLL_PLL_ENABLE));
422 I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
423 POSTING_READ(WRPLL_CTL2);
424 }
425 break;
426 }
427
428 WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
429 WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
430 WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
431
432 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
433}
434
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100435#define LC_FREQ 2700
436#define LC_FREQ_2K (LC_FREQ * 2000)
437
438#define P_MIN 2
439#define P_MAX 64
440#define P_INC 2
441
442/* Constraints for PLL good behavior */
443#define REF_MIN 48
444#define REF_MAX 400
445#define VCO_MIN 2400
446#define VCO_MAX 4800
447
448#define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
449
450struct wrpll_rnp {
451 unsigned p, n2, r2;
452};
453
454static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300455{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100456 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300457
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100458 switch (clock) {
459 case 25175000:
460 case 25200000:
461 case 27000000:
462 case 27027000:
463 case 37762500:
464 case 37800000:
465 case 40500000:
466 case 40541000:
467 case 54000000:
468 case 54054000:
469 case 59341000:
470 case 59400000:
471 case 72000000:
472 case 74176000:
473 case 74250000:
474 case 81000000:
475 case 81081000:
476 case 89012000:
477 case 89100000:
478 case 108000000:
479 case 108108000:
480 case 111264000:
481 case 111375000:
482 case 148352000:
483 case 148500000:
484 case 162000000:
485 case 162162000:
486 case 222525000:
487 case 222750000:
488 case 296703000:
489 case 297000000:
490 budget = 0;
491 break;
492 case 233500000:
493 case 245250000:
494 case 247750000:
495 case 253250000:
496 case 298000000:
497 budget = 1500;
498 break;
499 case 169128000:
500 case 169500000:
501 case 179500000:
502 case 202000000:
503 budget = 2000;
504 break;
505 case 256250000:
506 case 262500000:
507 case 270000000:
508 case 272500000:
509 case 273750000:
510 case 280750000:
511 case 281250000:
512 case 286000000:
513 case 291750000:
514 budget = 4000;
515 break;
516 case 267250000:
517 case 268500000:
518 budget = 5000;
519 break;
520 default:
521 budget = 1000;
522 break;
523 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300524
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100525 return budget;
526}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300527
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100528static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
529 unsigned r2, unsigned n2, unsigned p,
530 struct wrpll_rnp *best)
531{
532 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300533
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100534 /* No best (r,n,p) yet */
535 if (best->p == 0) {
536 best->p = p;
537 best->n2 = n2;
538 best->r2 = r2;
539 return;
540 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300541
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100542 /*
543 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
544 * freq2k.
545 *
546 * delta = 1e6 *
547 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
548 * freq2k;
549 *
550 * and we would like delta <= budget.
551 *
552 * If the discrepancy is above the PPM-based budget, always prefer to
553 * improve upon the previous solution. However, if you're within the
554 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
555 */
556 a = freq2k * budget * p * r2;
557 b = freq2k * budget * best->p * best->r2;
558 diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
559 diff_best = ABS_DIFF((freq2k * best->p * best->r2),
560 (LC_FREQ_2K * best->n2));
561 c = 1000000 * diff;
562 d = 1000000 * diff_best;
563
564 if (a < c && b < d) {
565 /* If both are above the budget, pick the closer */
566 if (best->p * best->r2 * diff < p * r2 * diff_best) {
567 best->p = p;
568 best->n2 = n2;
569 best->r2 = r2;
570 }
571 } else if (a >= c && b < d) {
572 /* If A is below the threshold but B is above it? Update. */
573 best->p = p;
574 best->n2 = n2;
575 best->r2 = r2;
576 } else if (a >= c && b >= d) {
577 /* Both are below the limit, so pick the higher n2/(r2*r2) */
578 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
579 best->p = p;
580 best->n2 = n2;
581 best->r2 = r2;
582 }
583 }
584 /* Otherwise a < c && b >= d, do nothing */
585}
586
Jesse Barnes11578552014-01-21 12:42:10 -0800587static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
588 int reg)
589{
590 int refclk = LC_FREQ;
591 int n, p, r;
592 u32 wrpll;
593
594 wrpll = I915_READ(reg);
595 switch (wrpll & SPLL_PLL_REF_MASK) {
596 case SPLL_PLL_SSC:
597 case SPLL_PLL_NON_SSC:
598 /*
599 * We could calculate spread here, but our checking
600 * code only cares about 5% accuracy, and spread is a max of
601 * 0.5% downspread.
602 */
603 refclk = 135;
604 break;
605 case SPLL_PLL_LCPLL:
606 refclk = LC_FREQ;
607 break;
608 default:
609 WARN(1, "bad wrpll refclk\n");
610 return 0;
611 }
612
613 r = wrpll & WRPLL_DIVIDER_REF_MASK;
614 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
615 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
616
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800617 /* Convert to KHz, p & r have a fixed point portion */
618 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800619}
620
621static void intel_ddi_clock_get(struct intel_encoder *encoder,
622 struct intel_crtc_config *pipe_config)
623{
624 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
625 enum port port = intel_ddi_get_encoder_port(encoder);
626 int link_clock = 0;
627 u32 val, pll;
628
629 val = I915_READ(PORT_CLK_SEL(port));
630 switch (val & PORT_CLK_SEL_MASK) {
631 case PORT_CLK_SEL_LCPLL_810:
632 link_clock = 81000;
633 break;
634 case PORT_CLK_SEL_LCPLL_1350:
635 link_clock = 135000;
636 break;
637 case PORT_CLK_SEL_LCPLL_2700:
638 link_clock = 270000;
639 break;
640 case PORT_CLK_SEL_WRPLL1:
641 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
642 break;
643 case PORT_CLK_SEL_WRPLL2:
644 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
645 break;
646 case PORT_CLK_SEL_SPLL:
647 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
648 if (pll == SPLL_PLL_FREQ_810MHz)
649 link_clock = 81000;
650 else if (pll == SPLL_PLL_FREQ_1350MHz)
651 link_clock = 135000;
652 else if (pll == SPLL_PLL_FREQ_2700MHz)
653 link_clock = 270000;
654 else {
655 WARN(1, "bad spll freq\n");
656 return;
657 }
658 break;
659 default:
660 WARN(1, "bad port clock sel\n");
661 return;
662 }
663
664 pipe_config->port_clock = link_clock * 2;
665
666 if (pipe_config->has_pch_encoder)
667 pipe_config->adjusted_mode.crtc_clock =
668 intel_dotclock_calculate(pipe_config->port_clock,
669 &pipe_config->fdi_m_n);
670 else if (pipe_config->has_dp_encoder)
671 pipe_config->adjusted_mode.crtc_clock =
672 intel_dotclock_calculate(pipe_config->port_clock,
673 &pipe_config->dp_m_n);
674 else
675 pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
676}
677
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100678static void
679intel_ddi_calculate_wrpll(int clock /* in Hz */,
680 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
681{
682 uint64_t freq2k;
683 unsigned p, n2, r2;
684 struct wrpll_rnp best = { 0, 0, 0 };
685 unsigned budget;
686
687 freq2k = clock / 100;
688
689 budget = wrpll_get_budget_for_freq(clock);
690
691 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
692 * and directly pass the LC PLL to it. */
693 if (freq2k == 5400000) {
694 *n2_out = 2;
695 *p_out = 1;
696 *r2_out = 2;
697 return;
698 }
699
700 /*
701 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
702 * the WR PLL.
703 *
704 * We want R so that REF_MIN <= Ref <= REF_MAX.
705 * Injecting R2 = 2 * R gives:
706 * REF_MAX * r2 > LC_FREQ * 2 and
707 * REF_MIN * r2 < LC_FREQ * 2
708 *
709 * Which means the desired boundaries for r2 are:
710 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
711 *
712 */
713 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
714 r2 <= LC_FREQ * 2 / REF_MIN;
715 r2++) {
716
717 /*
718 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
719 *
720 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
721 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
722 * VCO_MAX * r2 > n2 * LC_FREQ and
723 * VCO_MIN * r2 < n2 * LC_FREQ)
724 *
725 * Which means the desired boundaries for n2 are:
726 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
727 */
728 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
729 n2 <= VCO_MAX * r2 / LC_FREQ;
730 n2++) {
731
732 for (p = P_MIN; p <= P_MAX; p += P_INC)
733 wrpll_update_rnp(freq2k, budget,
734 r2, n2, p, &best);
735 }
736 }
737
738 *n2_out = best.n2;
739 *p_out = best.p;
740 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300741}
742
Paulo Zanoni566b7342013-11-25 15:27:08 -0200743/*
744 * Tries to find a PLL for the CRTC. If it finds, it increases the refcount and
745 * stores it in intel_crtc->ddi_pll_sel, so other mode sets won't be able to
746 * steal the selected PLL. You need to call intel_ddi_pll_enable to actually
747 * enable the PLL.
748 */
749bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300750{
Paulo Zanoni566b7342013-11-25 15:27:08 -0200751 struct drm_crtc *crtc = &intel_crtc->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300752 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni068759b2012-10-15 15:51:31 -0300753 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300754 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
755 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
756 int type = intel_encoder->type;
757 enum pipe pipe = intel_crtc->pipe;
Daniel Vetterff9a6752013-06-01 17:16:21 +0200758 int clock = intel_crtc->config.port_clock;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300759
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300760 intel_ddi_put_crtc_pll(crtc);
761
Paulo Zanoni068759b2012-10-15 15:51:31 -0300762 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
763 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
764
765 switch (intel_dp->link_bw) {
766 case DP_LINK_BW_1_62:
767 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
768 break;
769 case DP_LINK_BW_2_7:
770 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
771 break;
772 case DP_LINK_BW_5_4:
773 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
774 break;
775 default:
776 DRM_ERROR("Link bandwidth %d unsupported\n",
777 intel_dp->link_bw);
778 return false;
779 }
780
Paulo Zanoni068759b2012-10-15 15:51:31 -0300781 } else if (type == INTEL_OUTPUT_HDMI) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200782 uint32_t reg, val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100783 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300784
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100785 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300786
787 val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
788 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
789 WRPLL_DIVIDER_POST(p);
790
Paulo Zanoni06940012013-10-30 18:27:43 -0200791 if (val == I915_READ(WRPLL_CTL1)) {
792 DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n",
793 pipe_name(pipe));
794 reg = WRPLL_CTL1;
795 } else if (val == I915_READ(WRPLL_CTL2)) {
796 DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n",
797 pipe_name(pipe));
798 reg = WRPLL_CTL2;
799 } else if (plls->wrpll1_refcount == 0) {
800 DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
801 pipe_name(pipe));
802 reg = WRPLL_CTL1;
803 } else if (plls->wrpll2_refcount == 0) {
804 DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
805 pipe_name(pipe));
806 reg = WRPLL_CTL2;
807 } else {
808 DRM_ERROR("No WRPLLs available!\n");
809 return false;
810 }
811
Paulo Zanoni566b7342013-11-25 15:27:08 -0200812 DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
813 clock, p, n2, r2);
814
Paulo Zanoni06940012013-10-30 18:27:43 -0200815 if (reg == WRPLL_CTL1) {
816 plls->wrpll1_refcount++;
817 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
818 } else {
819 plls->wrpll2_refcount++;
820 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
821 }
822
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300823 } else if (type == INTEL_OUTPUT_ANALOG) {
824 if (plls->spll_refcount == 0) {
825 DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
826 pipe_name(pipe));
827 plls->spll_refcount++;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300828 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
Damien Lespiau00037c22013-03-07 15:30:25 +0000829 } else {
830 DRM_ERROR("SPLL already in use\n");
831 return false;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300832 }
833
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300834 } else {
835 WARN(1, "Invalid DDI encoder type %d\n", type);
836 return false;
837 }
838
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300839 return true;
840}
841
Paulo Zanoni566b7342013-11-25 15:27:08 -0200842/*
843 * To be called after intel_ddi_pll_select(). That one selects the PLL to be
844 * used, this one actually enables the PLL.
845 */
846void intel_ddi_pll_enable(struct intel_crtc *crtc)
847{
848 struct drm_device *dev = crtc->base.dev;
849 struct drm_i915_private *dev_priv = dev->dev_private;
850 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
851 int clock = crtc->config.port_clock;
852 uint32_t reg, cur_val, new_val;
853 int refcount;
854 const char *pll_name;
855 uint32_t enable_bit = (1 << 31);
856 unsigned int p, n2, r2;
857
858 BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE);
859 BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE);
860
861 switch (crtc->ddi_pll_sel) {
862 case PORT_CLK_SEL_LCPLL_2700:
863 case PORT_CLK_SEL_LCPLL_1350:
864 case PORT_CLK_SEL_LCPLL_810:
865 /*
866 * LCPLL should always be enabled at this point of the mode set
867 * sequence, so nothing to do.
868 */
869 return;
870
871 case PORT_CLK_SEL_SPLL:
872 pll_name = "SPLL";
873 reg = SPLL_CTL;
874 refcount = plls->spll_refcount;
875 new_val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz |
876 SPLL_PLL_SSC;
877 break;
878
879 case PORT_CLK_SEL_WRPLL1:
880 case PORT_CLK_SEL_WRPLL2:
881 if (crtc->ddi_pll_sel == PORT_CLK_SEL_WRPLL1) {
882 pll_name = "WRPLL1";
883 reg = WRPLL_CTL1;
884 refcount = plls->wrpll1_refcount;
885 } else {
886 pll_name = "WRPLL2";
887 reg = WRPLL_CTL2;
888 refcount = plls->wrpll2_refcount;
889 }
890
891 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
892
893 new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
894 WRPLL_DIVIDER_REFERENCE(r2) |
895 WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p);
896
897 break;
898
899 case PORT_CLK_SEL_NONE:
900 WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n");
901 return;
902 default:
903 WARN(1, "Bad selected pll: 0x%08x\n", crtc->ddi_pll_sel);
904 return;
905 }
906
907 cur_val = I915_READ(reg);
908
909 WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount);
910 if (refcount == 1) {
911 WARN(cur_val & enable_bit, "%s already enabled\n", pll_name);
912 I915_WRITE(reg, new_val);
913 POSTING_READ(reg);
914 udelay(20);
915 } else {
916 WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name);
917 }
918}
919
Paulo Zanonidae84792012-10-15 15:51:30 -0300920void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
921{
922 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
923 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
924 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200925 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300926 int type = intel_encoder->type;
927 uint32_t temp;
928
929 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
930
Paulo Zanonic9809792012-10-23 18:30:00 -0200931 temp = TRANS_MSA_SYNC_CLK;
Daniel Vetter965e0c42013-03-27 00:44:57 +0100932 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -0300933 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200934 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300935 break;
936 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200937 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300938 break;
939 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200940 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300941 break;
942 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200943 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300944 break;
945 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100946 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -0300947 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200948 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300949 }
950}
951
Damien Lespiau8228c252013-03-07 15:30:27 +0000952void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300953{
954 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
955 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300956 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -0700957 struct drm_device *dev = crtc->dev;
958 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300959 enum pipe pipe = intel_crtc->pipe;
Daniel Vetter3b117c82013-04-17 20:15:07 +0200960 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200961 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300962 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300963 uint32_t temp;
964
Paulo Zanoniad80a812012-10-24 16:06:19 -0200965 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
966 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200967 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -0300968
Daniel Vetter965e0c42013-03-27 00:44:57 +0100969 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -0300970 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200971 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300972 break;
973 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200974 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300975 break;
976 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200977 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300978 break;
979 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200980 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300981 break;
982 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100983 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -0300984 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300985
Ville Syrjäläa6662832013-09-10 17:03:41 +0300986 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200987 temp |= TRANS_DDI_PVSYNC;
Ville Syrjäläa6662832013-09-10 17:03:41 +0300988 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200989 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -0300990
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200991 if (cpu_transcoder == TRANSCODER_EDP) {
992 switch (pipe) {
993 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -0700994 /* On Haswell, can only use the always-on power well for
995 * eDP when not using the panel fitter, and when not
996 * using motion blur mitigation (which we don't
997 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +0200998 if (IS_HASWELL(dev) &&
999 (intel_crtc->config.pch_pfit.enabled ||
1000 intel_crtc->config.pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001001 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1002 else
1003 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001004 break;
1005 case PIPE_B:
1006 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1007 break;
1008 case PIPE_C:
1009 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1010 break;
1011 default:
1012 BUG();
1013 break;
1014 }
1015 }
1016
Paulo Zanoni7739c332012-10-15 15:51:29 -03001017 if (type == INTEL_OUTPUT_HDMI) {
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001018 if (intel_crtc->config.has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001019 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001020 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001021 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001022
Paulo Zanoni7739c332012-10-15 15:51:29 -03001023 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001024 temp |= TRANS_DDI_MODE_SELECT_FDI;
Daniel Vetter33d29b12013-02-13 18:04:45 +01001025 temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001026
1027 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
1028 type == INTEL_OUTPUT_EDP) {
1029 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1030
Paulo Zanoniad80a812012-10-24 16:06:19 -02001031 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001032
Daniel Vetter17aa6be2013-04-30 14:01:40 +02001033 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001034 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001035 WARN(1, "Invalid encoder type %d for pipe %c\n",
1036 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001037 }
1038
Paulo Zanoniad80a812012-10-24 16:06:19 -02001039 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001040}
1041
Paulo Zanoniad80a812012-10-24 16:06:19 -02001042void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1043 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001044{
Paulo Zanoniad80a812012-10-24 16:06:19 -02001045 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001046 uint32_t val = I915_READ(reg);
1047
Paulo Zanoniad80a812012-10-24 16:06:19 -02001048 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
1049 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001050 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001051}
1052
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001053bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1054{
1055 struct drm_device *dev = intel_connector->base.dev;
1056 struct drm_i915_private *dev_priv = dev->dev_private;
1057 struct intel_encoder *intel_encoder = intel_connector->encoder;
1058 int type = intel_connector->base.connector_type;
1059 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1060 enum pipe pipe = 0;
1061 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -03001062 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001063 uint32_t tmp;
1064
Paulo Zanoni882244a2014-04-01 14:55:12 -03001065 power_domain = intel_display_port_power_domain(intel_encoder);
1066 if (!intel_display_power_enabled(dev_priv, power_domain))
1067 return false;
1068
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001069 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
1070 return false;
1071
1072 if (port == PORT_A)
1073 cpu_transcoder = TRANSCODER_EDP;
1074 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001075 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001076
1077 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1078
1079 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1080 case TRANS_DDI_MODE_SELECT_HDMI:
1081 case TRANS_DDI_MODE_SELECT_DVI:
1082 return (type == DRM_MODE_CONNECTOR_HDMIA);
1083
1084 case TRANS_DDI_MODE_SELECT_DP_SST:
1085 if (type == DRM_MODE_CONNECTOR_eDP)
1086 return true;
1087 case TRANS_DDI_MODE_SELECT_DP_MST:
1088 return (type == DRM_MODE_CONNECTOR_DisplayPort);
1089
1090 case TRANS_DDI_MODE_SELECT_FDI:
1091 return (type == DRM_MODE_CONNECTOR_VGA);
1092
1093 default:
1094 return false;
1095 }
1096}
1097
Daniel Vetter85234cd2012-07-02 13:27:29 +02001098bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1099 enum pipe *pipe)
1100{
1101 struct drm_device *dev = encoder->base.dev;
1102 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001103 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001104 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001105 u32 tmp;
1106 int i;
1107
Imre Deak6d129be2014-03-05 16:20:54 +02001108 power_domain = intel_display_port_power_domain(encoder);
1109 if (!intel_display_power_enabled(dev_priv, power_domain))
1110 return false;
1111
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001112 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001113
1114 if (!(tmp & DDI_BUF_CTL_ENABLE))
1115 return false;
1116
Paulo Zanoniad80a812012-10-24 16:06:19 -02001117 if (port == PORT_A) {
1118 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001119
Paulo Zanoniad80a812012-10-24 16:06:19 -02001120 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1121 case TRANS_DDI_EDP_INPUT_A_ON:
1122 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1123 *pipe = PIPE_A;
1124 break;
1125 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1126 *pipe = PIPE_B;
1127 break;
1128 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1129 *pipe = PIPE_C;
1130 break;
1131 }
1132
1133 return true;
1134 } else {
1135 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1136 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1137
1138 if ((tmp & TRANS_DDI_PORT_MASK)
1139 == TRANS_DDI_SELECT_PORT(port)) {
1140 *pipe = i;
1141 return true;
1142 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001143 }
1144 }
1145
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001146 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001147
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001148 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001149}
1150
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001151static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
1152 enum pipe pipe)
1153{
1154 uint32_t temp, ret;
Damien Lespiaua42f7042013-03-25 15:16:14 +00001155 enum port port = I915_MAX_PORTS;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001156 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1157 pipe);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001158 int i;
1159
Paulo Zanoniad80a812012-10-24 16:06:19 -02001160 if (cpu_transcoder == TRANSCODER_EDP) {
1161 port = PORT_A;
1162 } else {
1163 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1164 temp &= TRANS_DDI_PORT_MASK;
1165
1166 for (i = PORT_B; i <= PORT_E; i++)
1167 if (temp == TRANS_DDI_SELECT_PORT(i))
1168 port = i;
1169 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001170
Damien Lespiaua42f7042013-03-25 15:16:14 +00001171 if (port == I915_MAX_PORTS) {
1172 WARN(1, "Pipe %c enabled on an unknown port\n",
1173 pipe_name(pipe));
1174 ret = PORT_CLK_SEL_NONE;
1175 } else {
1176 ret = I915_READ(PORT_CLK_SEL(port));
1177 DRM_DEBUG_KMS("Pipe %c connected to port %c using clock "
1178 "0x%08x\n", pipe_name(pipe), port_name(port),
1179 ret);
1180 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001181
1182 return ret;
1183}
1184
1185void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
1186{
1187 struct drm_i915_private *dev_priv = dev->dev_private;
1188 enum pipe pipe;
1189 struct intel_crtc *intel_crtc;
1190
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001191 dev_priv->ddi_plls.spll_refcount = 0;
1192 dev_priv->ddi_plls.wrpll1_refcount = 0;
1193 dev_priv->ddi_plls.wrpll2_refcount = 0;
1194
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001195 for_each_pipe(pipe) {
1196 intel_crtc =
1197 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1198
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001199 if (!intel_crtc->active) {
1200 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001201 continue;
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001202 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001203
1204 intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
1205 pipe);
1206
1207 switch (intel_crtc->ddi_pll_sel) {
1208 case PORT_CLK_SEL_SPLL:
1209 dev_priv->ddi_plls.spll_refcount++;
1210 break;
1211 case PORT_CLK_SEL_WRPLL1:
1212 dev_priv->ddi_plls.wrpll1_refcount++;
1213 break;
1214 case PORT_CLK_SEL_WRPLL2:
1215 dev_priv->ddi_plls.wrpll2_refcount++;
1216 break;
1217 }
1218 }
1219}
1220
Paulo Zanonifc914632012-10-05 12:05:54 -03001221void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1222{
1223 struct drm_crtc *crtc = &intel_crtc->base;
1224 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1225 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1226 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +02001227 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001228
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001229 if (cpu_transcoder != TRANSCODER_EDP)
1230 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1231 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001232}
1233
1234void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1235{
1236 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001237 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001238
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001239 if (cpu_transcoder != TRANSCODER_EDP)
1240 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1241 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001242}
1243
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001244static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001245{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001246 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001247 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001248 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001249 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001250 int type = intel_encoder->type;
1251
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001252 if (crtc->config.has_audio) {
1253 DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
1254 pipe_name(crtc->pipe));
1255
1256 /* write eld */
1257 DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
1258 intel_write_eld(encoder, &crtc->config.adjusted_mode);
1259 }
1260
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001261 if (type == INTEL_OUTPUT_EDP) {
1262 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001263 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001264 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001265
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001266 WARN_ON(crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
1267 I915_WRITE(PORT_CLK_SEL(port), crtc->ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001268
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001269 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001270 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001271 struct intel_digital_port *intel_dig_port =
1272 enc_to_dig_port(encoder);
1273
1274 intel_dp->DP = intel_dig_port->saved_port_bits |
1275 DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
1276 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001277
1278 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1279 intel_dp_start_link_train(intel_dp);
1280 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001281 if (port != PORT_A)
1282 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001283 } else if (type == INTEL_OUTPUT_HDMI) {
1284 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1285
1286 intel_hdmi->set_infoframes(encoder,
1287 crtc->config.has_hdmi_sink,
1288 &crtc->config.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001289 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001290}
1291
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001292static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001293{
1294 struct drm_encoder *encoder = &intel_encoder->base;
1295 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1296 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001297 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001298 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001299 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001300
1301 val = I915_READ(DDI_BUF_CTL(port));
1302 if (val & DDI_BUF_CTL_ENABLE) {
1303 val &= ~DDI_BUF_CTL_ENABLE;
1304 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001305 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001306 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001307
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001308 val = I915_READ(DP_TP_CTL(port));
1309 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1310 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1311 I915_WRITE(DP_TP_CTL(port), val);
1312
1313 if (wait)
1314 intel_wait_ddi_buf_idle(dev_priv, port);
1315
Jani Nikula76bb80e2013-11-15 15:29:57 +02001316 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001317 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001318 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001319 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001320 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001321 }
1322
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001323 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1324}
1325
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001326static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001327{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001328 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001329 struct drm_crtc *crtc = encoder->crtc;
1330 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1331 int pipe = intel_crtc->pipe;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001332 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001333 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001334 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1335 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001336 uint32_t tmp;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001337
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001338 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001339 struct intel_digital_port *intel_dig_port =
1340 enc_to_dig_port(encoder);
1341
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001342 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1343 * are ignored so nothing special needs to be done besides
1344 * enabling the port.
1345 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001346 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001347 intel_dig_port->saved_port_bits |
1348 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001349 } else if (type == INTEL_OUTPUT_EDP) {
1350 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1351
Imre Deak3ab9c632013-05-03 12:57:41 +03001352 if (port == PORT_A)
1353 intel_dp_stop_link_train(intel_dp);
1354
Daniel Vetter4be73782014-01-17 14:39:48 +01001355 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi49065572013-07-11 18:45:05 -03001356 intel_edp_psr_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001357 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001358
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001359 if (intel_crtc->config.has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001360 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001361 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1362 tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1363 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1364 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001365}
1366
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001367static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001368{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001369 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001370 struct drm_crtc *crtc = encoder->crtc;
1371 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1372 int pipe = intel_crtc->pipe;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001373 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001374 struct drm_device *dev = encoder->dev;
1375 struct drm_i915_private *dev_priv = dev->dev_private;
1376 uint32_t tmp;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001377
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001378 /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
1379 * register is part of the power well on Haswell. */
1380 if (intel_crtc->config.has_audio) {
1381 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1382 tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1383 (pipe * 4));
1384 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1385 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1386 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001387
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001388 if (type == INTEL_OUTPUT_EDP) {
1389 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1390
Rodrigo Vivi49065572013-07-11 18:45:05 -03001391 intel_edp_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001392 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001393 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001394}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001395
Paulo Zanonib8fc2f62012-10-23 18:30:05 -02001396int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001397{
Paulo Zanonie39bf982013-11-02 21:07:36 -07001398 struct drm_device *dev = dev_priv->dev;
Paulo Zanonia4006642013-08-06 18:57:11 -03001399 uint32_t lcpll = I915_READ(LCPLL_CTL);
Paulo Zanonie39bf982013-11-02 21:07:36 -07001400 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Paulo Zanonia4006642013-08-06 18:57:11 -03001401
Paulo Zanonie39bf982013-11-02 21:07:36 -07001402 if (lcpll & LCPLL_CD_SOURCE_FCLK) {
Paulo Zanonia4006642013-08-06 18:57:11 -03001403 return 800000;
Damien Lespiaue3589902014-02-07 19:12:50 +00001404 } else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001405 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001406 } else if (freq == LCPLL_CLK_FREQ_450) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001407 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001408 } else if (IS_HASWELL(dev)) {
1409 if (IS_ULT(dev))
1410 return 337500;
1411 else
1412 return 540000;
1413 } else {
1414 if (freq == LCPLL_CLK_FREQ_54O_BDW)
1415 return 540000;
1416 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
1417 return 337500;
1418 else
1419 return 675000;
1420 }
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001421}
1422
1423void intel_ddi_pll_init(struct drm_device *dev)
1424{
1425 struct drm_i915_private *dev_priv = dev->dev_private;
1426 uint32_t val = I915_READ(LCPLL_CTL);
1427
1428 /* The LCPLL register should be turned on by the BIOS. For now let's
1429 * just check its state and print errors in case something is wrong.
1430 * Don't even try to turn it on.
1431 */
1432
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001433 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001434 intel_ddi_get_cdclk_freq(dev_priv));
1435
1436 if (val & LCPLL_CD_SOURCE_FCLK)
1437 DRM_ERROR("CDCLK source is not LCPLL\n");
1438
1439 if (val & LCPLL_PLL_DISABLE)
1440 DRM_ERROR("LCPLL is disabled\n");
1441}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001442
1443void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1444{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001445 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1446 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001447 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001448 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001449 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301450 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001451
1452 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1453 val = I915_READ(DDI_BUF_CTL(port));
1454 if (val & DDI_BUF_CTL_ENABLE) {
1455 val &= ~DDI_BUF_CTL_ENABLE;
1456 I915_WRITE(DDI_BUF_CTL(port), val);
1457 wait = true;
1458 }
1459
1460 val = I915_READ(DP_TP_CTL(port));
1461 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1462 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1463 I915_WRITE(DP_TP_CTL(port), val);
1464 POSTING_READ(DP_TP_CTL(port));
1465
1466 if (wait)
1467 intel_wait_ddi_buf_idle(dev_priv, port);
1468 }
1469
1470 val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
1471 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Jani Nikula6aba5b62013-10-04 15:08:10 +03001472 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Paulo Zanonic19b0662012-10-15 15:51:41 -03001473 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1474 I915_WRITE(DP_TP_CTL(port), val);
1475 POSTING_READ(DP_TP_CTL(port));
1476
1477 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1478 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1479 POSTING_READ(DDI_BUF_CTL(port));
1480
1481 udelay(600);
1482}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001483
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001484void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1485{
1486 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1487 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1488 uint32_t val;
1489
1490 intel_ddi_post_disable(intel_encoder);
1491
1492 val = I915_READ(_FDI_RXA_CTL);
1493 val &= ~FDI_RX_ENABLE;
1494 I915_WRITE(_FDI_RXA_CTL, val);
1495
1496 val = I915_READ(_FDI_RXA_MISC);
1497 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1498 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1499 I915_WRITE(_FDI_RXA_MISC, val);
1500
1501 val = I915_READ(_FDI_RXA_CTL);
1502 val &= ~FDI_PCDCLK;
1503 I915_WRITE(_FDI_RXA_CTL, val);
1504
1505 val = I915_READ(_FDI_RXA_CTL);
1506 val &= ~FDI_RX_PLL_ENABLE;
1507 I915_WRITE(_FDI_RXA_CTL, val);
1508}
1509
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001510static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1511{
1512 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
1513 int type = intel_encoder->type;
1514
1515 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
1516 intel_dp_check_link_status(intel_dp);
1517}
1518
Ville Syrjälä6801c182013-09-24 14:24:05 +03001519void intel_ddi_get_config(struct intel_encoder *encoder,
1520 struct intel_crtc_config *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001521{
1522 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1523 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1524 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
1525 u32 temp, flags = 0;
1526
1527 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1528 if (temp & TRANS_DDI_PHSYNC)
1529 flags |= DRM_MODE_FLAG_PHSYNC;
1530 else
1531 flags |= DRM_MODE_FLAG_NHSYNC;
1532 if (temp & TRANS_DDI_PVSYNC)
1533 flags |= DRM_MODE_FLAG_PVSYNC;
1534 else
1535 flags |= DRM_MODE_FLAG_NVSYNC;
1536
1537 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001538
1539 switch (temp & TRANS_DDI_BPC_MASK) {
1540 case TRANS_DDI_BPC_6:
1541 pipe_config->pipe_bpp = 18;
1542 break;
1543 case TRANS_DDI_BPC_8:
1544 pipe_config->pipe_bpp = 24;
1545 break;
1546 case TRANS_DDI_BPC_10:
1547 pipe_config->pipe_bpp = 30;
1548 break;
1549 case TRANS_DDI_BPC_12:
1550 pipe_config->pipe_bpp = 36;
1551 break;
1552 default:
1553 break;
1554 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001555
1556 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1557 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001558 pipe_config->has_hdmi_sink = true;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001559 case TRANS_DDI_MODE_SELECT_DVI:
1560 case TRANS_DDI_MODE_SELECT_FDI:
1561 break;
1562 case TRANS_DDI_MODE_SELECT_DP_SST:
1563 case TRANS_DDI_MODE_SELECT_DP_MST:
1564 pipe_config->has_dp_encoder = true;
1565 intel_dp_get_m_n(intel_crtc, pipe_config);
1566 break;
1567 default:
1568 break;
1569 }
Daniel Vetter10214422013-11-18 07:38:16 +01001570
Paulo Zanonia60551b2014-05-21 16:23:20 -03001571 if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
1572 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1573 if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
1574 pipe_config->has_audio = true;
1575 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001576
Daniel Vetter10214422013-11-18 07:38:16 +01001577 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1578 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1579 /*
1580 * This is a big fat ugly hack.
1581 *
1582 * Some machines in UEFI boot mode provide us a VBT that has 18
1583 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1584 * unknown we fail to light up. Yet the same BIOS boots up with
1585 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1586 * max, not what it tells us to use.
1587 *
1588 * Note: This will still be broken if the eDP panel is not lit
1589 * up by the BIOS, and thus we can't get the mode at module
1590 * load.
1591 */
1592 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1593 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1594 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1595 }
Jesse Barnes11578552014-01-21 12:42:10 -08001596
1597 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001598}
1599
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001600static void intel_ddi_destroy(struct drm_encoder *encoder)
1601{
1602 /* HDMI has nothing special to destroy, so we can go with this. */
1603 intel_dp_encoder_destroy(encoder);
1604}
1605
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001606static bool intel_ddi_compute_config(struct intel_encoder *encoder,
1607 struct intel_crtc_config *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001608{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001609 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02001610 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001611
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001612 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001613
Daniel Vettereccb1402013-05-22 00:50:22 +02001614 if (port == PORT_A)
1615 pipe_config->cpu_transcoder = TRANSCODER_EDP;
1616
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001617 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001618 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001619 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001620 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001621}
1622
1623static const struct drm_encoder_funcs intel_ddi_funcs = {
1624 .destroy = intel_ddi_destroy,
1625};
1626
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001627static struct intel_connector *
1628intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
1629{
1630 struct intel_connector *connector;
1631 enum port port = intel_dig_port->port;
1632
1633 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1634 if (!connector)
1635 return NULL;
1636
1637 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1638 if (!intel_dp_init_connector(intel_dig_port, connector)) {
1639 kfree(connector);
1640 return NULL;
1641 }
1642
1643 return connector;
1644}
1645
1646static struct intel_connector *
1647intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
1648{
1649 struct intel_connector *connector;
1650 enum port port = intel_dig_port->port;
1651
1652 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1653 if (!connector)
1654 return NULL;
1655
1656 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
1657 intel_hdmi_init_connector(intel_dig_port, connector);
1658
1659 return connector;
1660}
1661
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001662void intel_ddi_init(struct drm_device *dev, enum port port)
1663{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001664 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001665 struct intel_digital_port *intel_dig_port;
1666 struct intel_encoder *intel_encoder;
1667 struct drm_encoder *encoder;
1668 struct intel_connector *hdmi_connector = NULL;
1669 struct intel_connector *dp_connector = NULL;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001670 bool init_hdmi, init_dp;
1671
1672 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1673 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1674 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1675 if (!init_dp && !init_hdmi) {
1676 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n",
1677 port_name(port));
1678 init_hdmi = true;
1679 init_dp = true;
1680 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001681
Daniel Vetterb14c5672013-09-19 12:18:32 +02001682 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001683 if (!intel_dig_port)
1684 return;
1685
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001686 intel_encoder = &intel_dig_port->base;
1687 encoder = &intel_encoder->base;
1688
1689 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1690 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001691
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001692 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001693 intel_encoder->enable = intel_enable_ddi;
1694 intel_encoder->pre_enable = intel_ddi_pre_enable;
1695 intel_encoder->disable = intel_disable_ddi;
1696 intel_encoder->post_disable = intel_ddi_post_disable;
1697 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001698 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001699
1700 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001701 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
1702 (DDI_BUF_PORT_REVERSAL |
1703 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001704
1705 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
1706 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001707 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001708 intel_encoder->hot_plug = intel_ddi_hot_plug;
1709
Dave Airlie13cf5502014-06-18 11:29:35 +10001710 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
1711 dev_priv->hpd_irq_port[port] = intel_dig_port;
1712
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001713 if (init_dp)
1714 dp_connector = intel_ddi_init_dp_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001715
Paulo Zanoni311a2092013-09-12 17:12:18 -03001716 /* In theory we don't need the encoder->type check, but leave it just in
1717 * case we have some really bad VBTs... */
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001718 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi)
1719 hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001720
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001721 if (!dp_connector && !hdmi_connector) {
1722 drm_encoder_cleanup(encoder);
1723 kfree(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001724 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001725}