blob: c96bc3b6c3d041d92b98ec910ed76603fbcbc816 [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 Zanoni0d536cb2012-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 */
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300280 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config.ddi_pll_sel);
281 WARN_ON(intel_crtc->config.ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200282
283 /* Start the training iterating through available voltages and emphasis,
284 * testing each value twice. */
285 for (i = 0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300286 /* Configure DP_TP_CTL with auto-training */
287 I915_WRITE(DP_TP_CTL(PORT_E),
288 DP_TP_CTL_FDI_AUTOTRAIN |
289 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
290 DP_TP_CTL_LINK_TRAIN_PAT1 |
291 DP_TP_CTL_ENABLE);
292
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000293 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
294 * DDI E does not support port reversal, the functionality is
295 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
296 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300297 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200298 DDI_BUF_CTL_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100299 ((intel_crtc->config.fdi_lanes - 1) << 1) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200300 hsw_ddi_buf_ctl_values[i / 2]);
301 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300302
303 udelay(600);
304
Paulo Zanoni04945642012-11-01 21:00:59 -0200305 /* Program PCH FDI Receiver TU */
306 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300307
Paulo Zanoni04945642012-11-01 21:00:59 -0200308 /* Enable PCH FDI Receiver with auto-training */
309 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
310 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
311 POSTING_READ(_FDI_RXA_CTL);
312
313 /* Wait for FDI receiver lane calibration */
314 udelay(30);
315
316 /* Unset FDI_RX_MISC pwrdn lanes */
317 temp = I915_READ(_FDI_RXA_MISC);
318 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
319 I915_WRITE(_FDI_RXA_MISC, temp);
320 POSTING_READ(_FDI_RXA_MISC);
321
322 /* Wait for FDI auto training time */
323 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300324
325 temp = I915_READ(DP_TP_STATUS(PORT_E));
326 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200327 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300328
329 /* Enable normal pixel sending for FDI */
330 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200331 DP_TP_CTL_FDI_AUTOTRAIN |
332 DP_TP_CTL_LINK_TRAIN_NORMAL |
333 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
334 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300335
Paulo Zanoni04945642012-11-01 21:00:59 -0200336 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300337 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200338
Paulo Zanoni248138b2012-11-29 11:29:31 -0200339 temp = I915_READ(DDI_BUF_CTL(PORT_E));
340 temp &= ~DDI_BUF_CTL_ENABLE;
341 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
342 POSTING_READ(DDI_BUF_CTL(PORT_E));
343
Paulo Zanoni04945642012-11-01 21:00:59 -0200344 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200345 temp = I915_READ(DP_TP_CTL(PORT_E));
346 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
347 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
348 I915_WRITE(DP_TP_CTL(PORT_E), temp);
349 POSTING_READ(DP_TP_CTL(PORT_E));
350
351 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200352
353 rx_ctl_val &= ~FDI_RX_ENABLE;
354 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200355 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200356
357 /* Reset FDI_RX_MISC pwrdn lanes */
358 temp = I915_READ(_FDI_RXA_MISC);
359 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
360 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
361 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200362 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300363 }
364
Paulo Zanoni04945642012-11-01 21:00:59 -0200365 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300366}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300367
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300368static struct intel_encoder *
369intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
370{
371 struct drm_device *dev = crtc->dev;
372 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
373 struct intel_encoder *intel_encoder, *ret = NULL;
374 int num_encoders = 0;
375
376 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
377 ret = intel_encoder;
378 num_encoders++;
379 }
380
381 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300382 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
383 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300384
385 BUG_ON(ret == NULL);
386 return ret;
387}
388
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300389void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
390{
391 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
392 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
393 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
394 uint32_t val;
395
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300396 switch (intel_crtc->config.ddi_pll_sel) {
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300397 case PORT_CLK_SEL_WRPLL1:
398 plls->wrpll1_refcount--;
399 if (plls->wrpll1_refcount == 0) {
400 DRM_DEBUG_KMS("Disabling WRPLL 1\n");
401 val = I915_READ(WRPLL_CTL1);
402 WARN_ON(!(val & WRPLL_PLL_ENABLE));
403 I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
404 POSTING_READ(WRPLL_CTL1);
405 }
406 break;
407 case PORT_CLK_SEL_WRPLL2:
408 plls->wrpll2_refcount--;
409 if (plls->wrpll2_refcount == 0) {
410 DRM_DEBUG_KMS("Disabling WRPLL 2\n");
411 val = I915_READ(WRPLL_CTL2);
412 WARN_ON(!(val & WRPLL_PLL_ENABLE));
413 I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
414 POSTING_READ(WRPLL_CTL2);
415 }
416 break;
417 }
418
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300419 WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
420 WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
421
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300422 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300423}
424
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100425#define LC_FREQ 2700
426#define LC_FREQ_2K (LC_FREQ * 2000)
427
428#define P_MIN 2
429#define P_MAX 64
430#define P_INC 2
431
432/* Constraints for PLL good behavior */
433#define REF_MIN 48
434#define REF_MAX 400
435#define VCO_MIN 2400
436#define VCO_MAX 4800
437
438#define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
439
440struct wrpll_rnp {
441 unsigned p, n2, r2;
442};
443
444static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300445{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100446 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300447
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100448 switch (clock) {
449 case 25175000:
450 case 25200000:
451 case 27000000:
452 case 27027000:
453 case 37762500:
454 case 37800000:
455 case 40500000:
456 case 40541000:
457 case 54000000:
458 case 54054000:
459 case 59341000:
460 case 59400000:
461 case 72000000:
462 case 74176000:
463 case 74250000:
464 case 81000000:
465 case 81081000:
466 case 89012000:
467 case 89100000:
468 case 108000000:
469 case 108108000:
470 case 111264000:
471 case 111375000:
472 case 148352000:
473 case 148500000:
474 case 162000000:
475 case 162162000:
476 case 222525000:
477 case 222750000:
478 case 296703000:
479 case 297000000:
480 budget = 0;
481 break;
482 case 233500000:
483 case 245250000:
484 case 247750000:
485 case 253250000:
486 case 298000000:
487 budget = 1500;
488 break;
489 case 169128000:
490 case 169500000:
491 case 179500000:
492 case 202000000:
493 budget = 2000;
494 break;
495 case 256250000:
496 case 262500000:
497 case 270000000:
498 case 272500000:
499 case 273750000:
500 case 280750000:
501 case 281250000:
502 case 286000000:
503 case 291750000:
504 budget = 4000;
505 break;
506 case 267250000:
507 case 268500000:
508 budget = 5000;
509 break;
510 default:
511 budget = 1000;
512 break;
513 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300514
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100515 return budget;
516}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300517
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100518static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
519 unsigned r2, unsigned n2, unsigned p,
520 struct wrpll_rnp *best)
521{
522 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300523
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100524 /* No best (r,n,p) yet */
525 if (best->p == 0) {
526 best->p = p;
527 best->n2 = n2;
528 best->r2 = r2;
529 return;
530 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300531
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100532 /*
533 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
534 * freq2k.
535 *
536 * delta = 1e6 *
537 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
538 * freq2k;
539 *
540 * and we would like delta <= budget.
541 *
542 * If the discrepancy is above the PPM-based budget, always prefer to
543 * improve upon the previous solution. However, if you're within the
544 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
545 */
546 a = freq2k * budget * p * r2;
547 b = freq2k * budget * best->p * best->r2;
548 diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
549 diff_best = ABS_DIFF((freq2k * best->p * best->r2),
550 (LC_FREQ_2K * best->n2));
551 c = 1000000 * diff;
552 d = 1000000 * diff_best;
553
554 if (a < c && b < d) {
555 /* If both are above the budget, pick the closer */
556 if (best->p * best->r2 * diff < p * r2 * diff_best) {
557 best->p = p;
558 best->n2 = n2;
559 best->r2 = r2;
560 }
561 } else if (a >= c && b < d) {
562 /* If A is below the threshold but B is above it? Update. */
563 best->p = p;
564 best->n2 = n2;
565 best->r2 = r2;
566 } else if (a >= c && b >= d) {
567 /* Both are below the limit, so pick the higher n2/(r2*r2) */
568 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
569 best->p = p;
570 best->n2 = n2;
571 best->r2 = r2;
572 }
573 }
574 /* Otherwise a < c && b >= d, do nothing */
575}
576
Jesse Barnes11578552014-01-21 12:42:10 -0800577static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
578 int reg)
579{
580 int refclk = LC_FREQ;
581 int n, p, r;
582 u32 wrpll;
583
584 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300585 switch (wrpll & WRPLL_PLL_REF_MASK) {
586 case WRPLL_PLL_SSC:
587 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800588 /*
589 * We could calculate spread here, but our checking
590 * code only cares about 5% accuracy, and spread is a max of
591 * 0.5% downspread.
592 */
593 refclk = 135;
594 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300595 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800596 refclk = LC_FREQ;
597 break;
598 default:
599 WARN(1, "bad wrpll refclk\n");
600 return 0;
601 }
602
603 r = wrpll & WRPLL_DIVIDER_REF_MASK;
604 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
605 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
606
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800607 /* Convert to KHz, p & r have a fixed point portion */
608 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800609}
610
611static void intel_ddi_clock_get(struct intel_encoder *encoder,
612 struct intel_crtc_config *pipe_config)
613{
614 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
615 enum port port = intel_ddi_get_encoder_port(encoder);
616 int link_clock = 0;
617 u32 val, pll;
618
619 val = I915_READ(PORT_CLK_SEL(port));
620 switch (val & PORT_CLK_SEL_MASK) {
621 case PORT_CLK_SEL_LCPLL_810:
622 link_clock = 81000;
623 break;
624 case PORT_CLK_SEL_LCPLL_1350:
625 link_clock = 135000;
626 break;
627 case PORT_CLK_SEL_LCPLL_2700:
628 link_clock = 270000;
629 break;
630 case PORT_CLK_SEL_WRPLL1:
631 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
632 break;
633 case PORT_CLK_SEL_WRPLL2:
634 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
635 break;
636 case PORT_CLK_SEL_SPLL:
637 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
638 if (pll == SPLL_PLL_FREQ_810MHz)
639 link_clock = 81000;
640 else if (pll == SPLL_PLL_FREQ_1350MHz)
641 link_clock = 135000;
642 else if (pll == SPLL_PLL_FREQ_2700MHz)
643 link_clock = 270000;
644 else {
645 WARN(1, "bad spll freq\n");
646 return;
647 }
648 break;
649 default:
650 WARN(1, "bad port clock sel\n");
651 return;
652 }
653
654 pipe_config->port_clock = link_clock * 2;
655
656 if (pipe_config->has_pch_encoder)
657 pipe_config->adjusted_mode.crtc_clock =
658 intel_dotclock_calculate(pipe_config->port_clock,
659 &pipe_config->fdi_m_n);
660 else if (pipe_config->has_dp_encoder)
661 pipe_config->adjusted_mode.crtc_clock =
662 intel_dotclock_calculate(pipe_config->port_clock,
663 &pipe_config->dp_m_n);
664 else
665 pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
666}
667
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100668static void
669intel_ddi_calculate_wrpll(int clock /* in Hz */,
670 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
671{
672 uint64_t freq2k;
673 unsigned p, n2, r2;
674 struct wrpll_rnp best = { 0, 0, 0 };
675 unsigned budget;
676
677 freq2k = clock / 100;
678
679 budget = wrpll_get_budget_for_freq(clock);
680
681 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
682 * and directly pass the LC PLL to it. */
683 if (freq2k == 5400000) {
684 *n2_out = 2;
685 *p_out = 1;
686 *r2_out = 2;
687 return;
688 }
689
690 /*
691 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
692 * the WR PLL.
693 *
694 * We want R so that REF_MIN <= Ref <= REF_MAX.
695 * Injecting R2 = 2 * R gives:
696 * REF_MAX * r2 > LC_FREQ * 2 and
697 * REF_MIN * r2 < LC_FREQ * 2
698 *
699 * Which means the desired boundaries for r2 are:
700 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
701 *
702 */
703 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
704 r2 <= LC_FREQ * 2 / REF_MIN;
705 r2++) {
706
707 /*
708 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
709 *
710 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
711 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
712 * VCO_MAX * r2 > n2 * LC_FREQ and
713 * VCO_MIN * r2 < n2 * LC_FREQ)
714 *
715 * Which means the desired boundaries for n2 are:
716 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
717 */
718 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
719 n2 <= VCO_MAX * r2 / LC_FREQ;
720 n2++) {
721
722 for (p = P_MIN; p <= P_MAX; p += P_INC)
723 wrpll_update_rnp(freq2k, budget,
724 r2, n2, p, &best);
725 }
726 }
727
728 *n2_out = best.n2;
729 *p_out = best.p;
730 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300731}
732
Paulo Zanoni566b7342013-11-25 15:27:08 -0200733/*
734 * Tries to find a PLL for the CRTC. If it finds, it increases the refcount and
735 * stores it in intel_crtc->ddi_pll_sel, so other mode sets won't be able to
736 * steal the selected PLL. You need to call intel_ddi_pll_enable to actually
737 * enable the PLL.
738 */
739bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300740{
Paulo Zanoni566b7342013-11-25 15:27:08 -0200741 struct drm_crtc *crtc = &intel_crtc->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300742 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni068759b2012-10-15 15:51:31 -0300743 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300744 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
745 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
746 int type = intel_encoder->type;
747 enum pipe pipe = intel_crtc->pipe;
Daniel Vetterff9a6752013-06-01 17:16:21 +0200748 int clock = intel_crtc->config.port_clock;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300749
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300750 intel_ddi_put_crtc_pll(crtc);
751
Paulo Zanoni068759b2012-10-15 15:51:31 -0300752 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
753 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
754
755 switch (intel_dp->link_bw) {
756 case DP_LINK_BW_1_62:
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300757 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
Paulo Zanoni068759b2012-10-15 15:51:31 -0300758 break;
759 case DP_LINK_BW_2_7:
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300760 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
Paulo Zanoni068759b2012-10-15 15:51:31 -0300761 break;
762 case DP_LINK_BW_5_4:
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300763 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
Paulo Zanoni068759b2012-10-15 15:51:31 -0300764 break;
765 default:
766 DRM_ERROR("Link bandwidth %d unsupported\n",
767 intel_dp->link_bw);
768 return false;
769 }
770
Paulo Zanoni068759b2012-10-15 15:51:31 -0300771 } else if (type == INTEL_OUTPUT_HDMI) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200772 uint32_t reg, val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100773 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300774
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100775 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300776
Daniel Vetter114fe482014-06-25 22:01:48 +0300777 val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300778 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
779 WRPLL_DIVIDER_POST(p);
780
Paulo Zanoni06940012013-10-30 18:27:43 -0200781 if (val == I915_READ(WRPLL_CTL1)) {
782 DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n",
783 pipe_name(pipe));
784 reg = WRPLL_CTL1;
785 } else if (val == I915_READ(WRPLL_CTL2)) {
786 DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n",
787 pipe_name(pipe));
788 reg = WRPLL_CTL2;
789 } else if (plls->wrpll1_refcount == 0) {
790 DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
791 pipe_name(pipe));
792 reg = WRPLL_CTL1;
793 } else if (plls->wrpll2_refcount == 0) {
794 DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
795 pipe_name(pipe));
796 reg = WRPLL_CTL2;
797 } else {
798 DRM_ERROR("No WRPLLs available!\n");
799 return false;
800 }
801
Paulo Zanoni566b7342013-11-25 15:27:08 -0200802 DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
803 clock, p, n2, r2);
804
Paulo Zanoni06940012013-10-30 18:27:43 -0200805 if (reg == WRPLL_CTL1) {
806 plls->wrpll1_refcount++;
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300807 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
Paulo Zanoni06940012013-10-30 18:27:43 -0200808 } else {
809 plls->wrpll2_refcount++;
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300810 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
Paulo Zanoni06940012013-10-30 18:27:43 -0200811 }
812
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300813 } else if (type == INTEL_OUTPUT_ANALOG) {
Daniel Vetter7ca1ac12014-06-25 22:01:47 +0300814 DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
815 pipe_name(pipe));
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300816 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_SPLL;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300817 } else {
818 WARN(1, "Invalid DDI encoder type %d\n", type);
819 return false;
820 }
821
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300822 return true;
823}
824
Paulo Zanoni566b7342013-11-25 15:27:08 -0200825/*
826 * To be called after intel_ddi_pll_select(). That one selects the PLL to be
827 * used, this one actually enables the PLL.
828 */
829void intel_ddi_pll_enable(struct intel_crtc *crtc)
830{
831 struct drm_device *dev = crtc->base.dev;
832 struct drm_i915_private *dev_priv = dev->dev_private;
833 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
834 int clock = crtc->config.port_clock;
835 uint32_t reg, cur_val, new_val;
836 int refcount;
837 const char *pll_name;
838 uint32_t enable_bit = (1 << 31);
839 unsigned int p, n2, r2;
840
841 BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE);
842 BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE);
843
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300844 switch (crtc->config.ddi_pll_sel) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200845 case PORT_CLK_SEL_WRPLL1:
846 case PORT_CLK_SEL_WRPLL2:
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300847 if (crtc->config.ddi_pll_sel == PORT_CLK_SEL_WRPLL1) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200848 pll_name = "WRPLL1";
849 reg = WRPLL_CTL1;
850 refcount = plls->wrpll1_refcount;
851 } else {
852 pll_name = "WRPLL2";
853 reg = WRPLL_CTL2;
854 refcount = plls->wrpll2_refcount;
855 }
856
857 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
858
Daniel Vetter114fe482014-06-25 22:01:48 +0300859 new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni566b7342013-11-25 15:27:08 -0200860 WRPLL_DIVIDER_REFERENCE(r2) |
861 WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p);
862
863 break;
864
865 case PORT_CLK_SEL_NONE:
866 WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n");
867 return;
868 default:
Paulo Zanoni566b7342013-11-25 15:27:08 -0200869 return;
870 }
871
872 cur_val = I915_READ(reg);
873
874 WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount);
875 if (refcount == 1) {
876 WARN(cur_val & enable_bit, "%s already enabled\n", pll_name);
877 I915_WRITE(reg, new_val);
878 POSTING_READ(reg);
879 udelay(20);
880 } else {
881 WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name);
882 }
883}
884
Paulo Zanonidae84792012-10-15 15:51:30 -0300885void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
886{
887 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
888 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
889 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200890 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300891 int type = intel_encoder->type;
892 uint32_t temp;
893
894 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
895
Paulo Zanonic9809792012-10-23 18:30:00 -0200896 temp = TRANS_MSA_SYNC_CLK;
Daniel Vetter965e0c42013-03-27 00:44:57 +0100897 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -0300898 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200899 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300900 break;
901 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200902 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300903 break;
904 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200905 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300906 break;
907 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200908 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300909 break;
910 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100911 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -0300912 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200913 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300914 }
915}
916
Damien Lespiau8228c252013-03-07 15:30:27 +0000917void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300918{
919 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
920 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300921 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -0700922 struct drm_device *dev = crtc->dev;
923 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300924 enum pipe pipe = intel_crtc->pipe;
Daniel Vetter3b117c82013-04-17 20:15:07 +0200925 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200926 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300927 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300928 uint32_t temp;
929
Paulo Zanoniad80a812012-10-24 16:06:19 -0200930 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
931 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200932 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -0300933
Daniel Vetter965e0c42013-03-27 00:44:57 +0100934 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -0300935 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200936 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300937 break;
938 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200939 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300940 break;
941 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200942 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300943 break;
944 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200945 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300946 break;
947 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100948 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -0300949 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300950
Ville Syrjäläa6662832013-09-10 17:03:41 +0300951 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200952 temp |= TRANS_DDI_PVSYNC;
Ville Syrjäläa6662832013-09-10 17:03:41 +0300953 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200954 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -0300955
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200956 if (cpu_transcoder == TRANSCODER_EDP) {
957 switch (pipe) {
958 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -0700959 /* On Haswell, can only use the always-on power well for
960 * eDP when not using the panel fitter, and when not
961 * using motion blur mitigation (which we don't
962 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +0200963 if (IS_HASWELL(dev) &&
964 (intel_crtc->config.pch_pfit.enabled ||
965 intel_crtc->config.pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -0200966 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
967 else
968 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200969 break;
970 case PIPE_B:
971 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
972 break;
973 case PIPE_C:
974 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
975 break;
976 default:
977 BUG();
978 break;
979 }
980 }
981
Paulo Zanoni7739c332012-10-15 15:51:29 -0300982 if (type == INTEL_OUTPUT_HDMI) {
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200983 if (intel_crtc->config.has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200984 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300985 else
Paulo Zanoniad80a812012-10-24 16:06:19 -0200986 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300987
Paulo Zanoni7739c332012-10-15 15:51:29 -0300988 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -0200989 temp |= TRANS_DDI_MODE_SELECT_FDI;
Daniel Vetter33d29b12013-02-13 18:04:45 +0100990 temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300991
992 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
993 type == INTEL_OUTPUT_EDP) {
994 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
995
Paulo Zanoniad80a812012-10-24 16:06:19 -0200996 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300997
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200998 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300999 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001000 WARN(1, "Invalid encoder type %d for pipe %c\n",
1001 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001002 }
1003
Paulo Zanoniad80a812012-10-24 16:06:19 -02001004 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001005}
1006
Paulo Zanoniad80a812012-10-24 16:06:19 -02001007void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1008 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001009{
Paulo Zanoniad80a812012-10-24 16:06:19 -02001010 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001011 uint32_t val = I915_READ(reg);
1012
Paulo Zanoniad80a812012-10-24 16:06:19 -02001013 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
1014 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001015 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001016}
1017
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001018bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1019{
1020 struct drm_device *dev = intel_connector->base.dev;
1021 struct drm_i915_private *dev_priv = dev->dev_private;
1022 struct intel_encoder *intel_encoder = intel_connector->encoder;
1023 int type = intel_connector->base.connector_type;
1024 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1025 enum pipe pipe = 0;
1026 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -03001027 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001028 uint32_t tmp;
1029
Paulo Zanoni882244a2014-04-01 14:55:12 -03001030 power_domain = intel_display_port_power_domain(intel_encoder);
1031 if (!intel_display_power_enabled(dev_priv, power_domain))
1032 return false;
1033
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001034 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
1035 return false;
1036
1037 if (port == PORT_A)
1038 cpu_transcoder = TRANSCODER_EDP;
1039 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001040 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001041
1042 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1043
1044 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1045 case TRANS_DDI_MODE_SELECT_HDMI:
1046 case TRANS_DDI_MODE_SELECT_DVI:
1047 return (type == DRM_MODE_CONNECTOR_HDMIA);
1048
1049 case TRANS_DDI_MODE_SELECT_DP_SST:
1050 if (type == DRM_MODE_CONNECTOR_eDP)
1051 return true;
1052 case TRANS_DDI_MODE_SELECT_DP_MST:
1053 return (type == DRM_MODE_CONNECTOR_DisplayPort);
1054
1055 case TRANS_DDI_MODE_SELECT_FDI:
1056 return (type == DRM_MODE_CONNECTOR_VGA);
1057
1058 default:
1059 return false;
1060 }
1061}
1062
Daniel Vetter85234cd2012-07-02 13:27:29 +02001063bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1064 enum pipe *pipe)
1065{
1066 struct drm_device *dev = encoder->base.dev;
1067 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001068 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001069 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001070 u32 tmp;
1071 int i;
1072
Imre Deak6d129be2014-03-05 16:20:54 +02001073 power_domain = intel_display_port_power_domain(encoder);
1074 if (!intel_display_power_enabled(dev_priv, power_domain))
1075 return false;
1076
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001077 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001078
1079 if (!(tmp & DDI_BUF_CTL_ENABLE))
1080 return false;
1081
Paulo Zanoniad80a812012-10-24 16:06:19 -02001082 if (port == PORT_A) {
1083 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001084
Paulo Zanoniad80a812012-10-24 16:06:19 -02001085 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1086 case TRANS_DDI_EDP_INPUT_A_ON:
1087 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1088 *pipe = PIPE_A;
1089 break;
1090 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1091 *pipe = PIPE_B;
1092 break;
1093 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1094 *pipe = PIPE_C;
1095 break;
1096 }
1097
1098 return true;
1099 } else {
1100 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1101 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1102
1103 if ((tmp & TRANS_DDI_PORT_MASK)
1104 == TRANS_DDI_SELECT_PORT(port)) {
1105 *pipe = i;
1106 return true;
1107 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001108 }
1109 }
1110
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001111 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001112
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001113 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001114}
1115
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001116static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
1117 enum pipe pipe)
1118{
1119 uint32_t temp, ret;
Damien Lespiaua42f7042013-03-25 15:16:14 +00001120 enum port port = I915_MAX_PORTS;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001121 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1122 pipe);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001123 int i;
1124
Paulo Zanoniad80a812012-10-24 16:06:19 -02001125 if (cpu_transcoder == TRANSCODER_EDP) {
1126 port = PORT_A;
1127 } else {
1128 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1129 temp &= TRANS_DDI_PORT_MASK;
1130
1131 for (i = PORT_B; i <= PORT_E; i++)
1132 if (temp == TRANS_DDI_SELECT_PORT(i))
1133 port = i;
1134 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001135
Damien Lespiaua42f7042013-03-25 15:16:14 +00001136 if (port == I915_MAX_PORTS) {
1137 WARN(1, "Pipe %c enabled on an unknown port\n",
1138 pipe_name(pipe));
1139 ret = PORT_CLK_SEL_NONE;
1140 } else {
1141 ret = I915_READ(PORT_CLK_SEL(port));
1142 DRM_DEBUG_KMS("Pipe %c connected to port %c using clock "
1143 "0x%08x\n", pipe_name(pipe), port_name(port),
1144 ret);
1145 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001146
1147 return ret;
1148}
1149
1150void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
1151{
1152 struct drm_i915_private *dev_priv = dev->dev_private;
1153 enum pipe pipe;
1154 struct intel_crtc *intel_crtc;
1155
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001156 dev_priv->ddi_plls.wrpll1_refcount = 0;
1157 dev_priv->ddi_plls.wrpll2_refcount = 0;
1158
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001159 for_each_pipe(pipe) {
1160 intel_crtc =
1161 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1162
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001163 if (!intel_crtc->active) {
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001164 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001165 continue;
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001166 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001167
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001168 intel_crtc->config.ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001169 pipe);
1170
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001171 switch (intel_crtc->config.ddi_pll_sel) {
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001172 case PORT_CLK_SEL_WRPLL1:
1173 dev_priv->ddi_plls.wrpll1_refcount++;
1174 break;
1175 case PORT_CLK_SEL_WRPLL2:
1176 dev_priv->ddi_plls.wrpll2_refcount++;
1177 break;
1178 }
1179 }
1180}
1181
Paulo Zanonifc914632012-10-05 12:05:54 -03001182void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1183{
1184 struct drm_crtc *crtc = &intel_crtc->base;
1185 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1186 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1187 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +02001188 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001189
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001190 if (cpu_transcoder != TRANSCODER_EDP)
1191 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1192 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001193}
1194
1195void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1196{
1197 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001198 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001199
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001200 if (cpu_transcoder != TRANSCODER_EDP)
1201 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1202 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001203}
1204
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001205static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001206{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001207 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001208 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001209 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001210 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001211 int type = intel_encoder->type;
1212
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001213 if (crtc->config.has_audio) {
1214 DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
1215 pipe_name(crtc->pipe));
1216
1217 /* write eld */
1218 DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
1219 intel_write_eld(encoder, &crtc->config.adjusted_mode);
1220 }
1221
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001222 if (type == INTEL_OUTPUT_EDP) {
1223 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001224 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001225 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001226
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001227 WARN_ON(crtc->config.ddi_pll_sel == PORT_CLK_SEL_NONE);
1228 I915_WRITE(PORT_CLK_SEL(port), crtc->config.ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001229
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001230 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001231 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001232 struct intel_digital_port *intel_dig_port =
1233 enc_to_dig_port(encoder);
1234
1235 intel_dp->DP = intel_dig_port->saved_port_bits |
1236 DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
1237 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001238
1239 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1240 intel_dp_start_link_train(intel_dp);
1241 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001242 if (port != PORT_A)
1243 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001244 } else if (type == INTEL_OUTPUT_HDMI) {
1245 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1246
1247 intel_hdmi->set_infoframes(encoder,
1248 crtc->config.has_hdmi_sink,
1249 &crtc->config.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001250 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001251}
1252
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001253static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001254{
1255 struct drm_encoder *encoder = &intel_encoder->base;
1256 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1257 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001258 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001259 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001260 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001261
1262 val = I915_READ(DDI_BUF_CTL(port));
1263 if (val & DDI_BUF_CTL_ENABLE) {
1264 val &= ~DDI_BUF_CTL_ENABLE;
1265 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001266 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001267 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001268
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001269 val = I915_READ(DP_TP_CTL(port));
1270 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1271 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1272 I915_WRITE(DP_TP_CTL(port), val);
1273
1274 if (wait)
1275 intel_wait_ddi_buf_idle(dev_priv, port);
1276
Jani Nikula76bb80e2013-11-15 15:29:57 +02001277 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001278 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001279 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001280 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001281 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001282 }
1283
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001284 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1285}
1286
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001287static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001288{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001289 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001290 struct drm_crtc *crtc = encoder->crtc;
1291 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1292 int pipe = intel_crtc->pipe;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001293 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001294 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001295 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1296 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001297 uint32_t tmp;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001298
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001299 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001300 struct intel_digital_port *intel_dig_port =
1301 enc_to_dig_port(encoder);
1302
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001303 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1304 * are ignored so nothing special needs to be done besides
1305 * enabling the port.
1306 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001307 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001308 intel_dig_port->saved_port_bits |
1309 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001310 } else if (type == INTEL_OUTPUT_EDP) {
1311 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1312
Imre Deak3ab9c632013-05-03 12:57:41 +03001313 if (port == PORT_A)
1314 intel_dp_stop_link_train(intel_dp);
1315
Daniel Vetter4be73782014-01-17 14:39:48 +01001316 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi49065572013-07-11 18:45:05 -03001317 intel_edp_psr_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001318 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001319
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001320 if (intel_crtc->config.has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001321 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001322 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1323 tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1324 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1325 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001326}
1327
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001328static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001329{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001330 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001331 struct drm_crtc *crtc = encoder->crtc;
1332 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1333 int pipe = intel_crtc->pipe;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001334 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001335 struct drm_device *dev = encoder->dev;
1336 struct drm_i915_private *dev_priv = dev->dev_private;
1337 uint32_t tmp;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001338
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001339 /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
1340 * register is part of the power well on Haswell. */
1341 if (intel_crtc->config.has_audio) {
1342 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1343 tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1344 (pipe * 4));
1345 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1346 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1347 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001348
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001349 if (type == INTEL_OUTPUT_EDP) {
1350 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1351
Rodrigo Vivi49065572013-07-11 18:45:05 -03001352 intel_edp_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001353 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001354 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001355}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001356
Paulo Zanonib8fc2f62012-10-23 18:30:05 -02001357int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001358{
Paulo Zanonie39bf982013-11-02 21:07:36 -07001359 struct drm_device *dev = dev_priv->dev;
Paulo Zanonia4006642013-08-06 18:57:11 -03001360 uint32_t lcpll = I915_READ(LCPLL_CTL);
Paulo Zanonie39bf982013-11-02 21:07:36 -07001361 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Paulo Zanonia4006642013-08-06 18:57:11 -03001362
Paulo Zanonie39bf982013-11-02 21:07:36 -07001363 if (lcpll & LCPLL_CD_SOURCE_FCLK) {
Paulo Zanonia4006642013-08-06 18:57:11 -03001364 return 800000;
Damien Lespiaue3589902014-02-07 19:12:50 +00001365 } else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001366 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001367 } else if (freq == LCPLL_CLK_FREQ_450) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001368 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001369 } else if (IS_HASWELL(dev)) {
1370 if (IS_ULT(dev))
1371 return 337500;
1372 else
1373 return 540000;
1374 } else {
1375 if (freq == LCPLL_CLK_FREQ_54O_BDW)
1376 return 540000;
1377 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
1378 return 337500;
1379 else
1380 return 675000;
1381 }
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001382}
1383
1384void intel_ddi_pll_init(struct drm_device *dev)
1385{
1386 struct drm_i915_private *dev_priv = dev->dev_private;
1387 uint32_t val = I915_READ(LCPLL_CTL);
1388
1389 /* The LCPLL register should be turned on by the BIOS. For now let's
1390 * just check its state and print errors in case something is wrong.
1391 * Don't even try to turn it on.
1392 */
1393
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001394 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001395 intel_ddi_get_cdclk_freq(dev_priv));
1396
1397 if (val & LCPLL_CD_SOURCE_FCLK)
1398 DRM_ERROR("CDCLK source is not LCPLL\n");
1399
1400 if (val & LCPLL_PLL_DISABLE)
1401 DRM_ERROR("LCPLL is disabled\n");
1402}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001403
1404void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1405{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001406 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1407 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001408 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001409 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001410 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301411 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001412
1413 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1414 val = I915_READ(DDI_BUF_CTL(port));
1415 if (val & DDI_BUF_CTL_ENABLE) {
1416 val &= ~DDI_BUF_CTL_ENABLE;
1417 I915_WRITE(DDI_BUF_CTL(port), val);
1418 wait = true;
1419 }
1420
1421 val = I915_READ(DP_TP_CTL(port));
1422 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1423 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1424 I915_WRITE(DP_TP_CTL(port), val);
1425 POSTING_READ(DP_TP_CTL(port));
1426
1427 if (wait)
1428 intel_wait_ddi_buf_idle(dev_priv, port);
1429 }
1430
1431 val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
1432 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Jani Nikula6aba5b62013-10-04 15:08:10 +03001433 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Paulo Zanonic19b0662012-10-15 15:51:41 -03001434 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1435 I915_WRITE(DP_TP_CTL(port), val);
1436 POSTING_READ(DP_TP_CTL(port));
1437
1438 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1439 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1440 POSTING_READ(DDI_BUF_CTL(port));
1441
1442 udelay(600);
1443}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001444
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001445void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1446{
1447 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1448 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1449 uint32_t val;
1450
1451 intel_ddi_post_disable(intel_encoder);
1452
1453 val = I915_READ(_FDI_RXA_CTL);
1454 val &= ~FDI_RX_ENABLE;
1455 I915_WRITE(_FDI_RXA_CTL, val);
1456
1457 val = I915_READ(_FDI_RXA_MISC);
1458 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1459 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1460 I915_WRITE(_FDI_RXA_MISC, val);
1461
1462 val = I915_READ(_FDI_RXA_CTL);
1463 val &= ~FDI_PCDCLK;
1464 I915_WRITE(_FDI_RXA_CTL, val);
1465
1466 val = I915_READ(_FDI_RXA_CTL);
1467 val &= ~FDI_RX_PLL_ENABLE;
1468 I915_WRITE(_FDI_RXA_CTL, val);
1469}
1470
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001471static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1472{
1473 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
1474 int type = intel_encoder->type;
1475
1476 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
1477 intel_dp_check_link_status(intel_dp);
1478}
1479
Ville Syrjälä6801c182013-09-24 14:24:05 +03001480void intel_ddi_get_config(struct intel_encoder *encoder,
1481 struct intel_crtc_config *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001482{
1483 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1484 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1485 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
1486 u32 temp, flags = 0;
1487
1488 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1489 if (temp & TRANS_DDI_PHSYNC)
1490 flags |= DRM_MODE_FLAG_PHSYNC;
1491 else
1492 flags |= DRM_MODE_FLAG_NHSYNC;
1493 if (temp & TRANS_DDI_PVSYNC)
1494 flags |= DRM_MODE_FLAG_PVSYNC;
1495 else
1496 flags |= DRM_MODE_FLAG_NVSYNC;
1497
1498 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001499
1500 switch (temp & TRANS_DDI_BPC_MASK) {
1501 case TRANS_DDI_BPC_6:
1502 pipe_config->pipe_bpp = 18;
1503 break;
1504 case TRANS_DDI_BPC_8:
1505 pipe_config->pipe_bpp = 24;
1506 break;
1507 case TRANS_DDI_BPC_10:
1508 pipe_config->pipe_bpp = 30;
1509 break;
1510 case TRANS_DDI_BPC_12:
1511 pipe_config->pipe_bpp = 36;
1512 break;
1513 default:
1514 break;
1515 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001516
1517 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1518 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001519 pipe_config->has_hdmi_sink = true;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001520 case TRANS_DDI_MODE_SELECT_DVI:
1521 case TRANS_DDI_MODE_SELECT_FDI:
1522 break;
1523 case TRANS_DDI_MODE_SELECT_DP_SST:
1524 case TRANS_DDI_MODE_SELECT_DP_MST:
1525 pipe_config->has_dp_encoder = true;
1526 intel_dp_get_m_n(intel_crtc, pipe_config);
1527 break;
1528 default:
1529 break;
1530 }
Daniel Vetter10214422013-11-18 07:38:16 +01001531
Paulo Zanonia60551b2014-05-21 16:23:20 -03001532 if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
1533 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1534 if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
1535 pipe_config->has_audio = true;
1536 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001537
Daniel Vetter10214422013-11-18 07:38:16 +01001538 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1539 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1540 /*
1541 * This is a big fat ugly hack.
1542 *
1543 * Some machines in UEFI boot mode provide us a VBT that has 18
1544 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1545 * unknown we fail to light up. Yet the same BIOS boots up with
1546 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1547 * max, not what it tells us to use.
1548 *
1549 * Note: This will still be broken if the eDP panel is not lit
1550 * up by the BIOS, and thus we can't get the mode at module
1551 * load.
1552 */
1553 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1554 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1555 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1556 }
Jesse Barnes11578552014-01-21 12:42:10 -08001557
1558 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001559}
1560
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001561static void intel_ddi_destroy(struct drm_encoder *encoder)
1562{
1563 /* HDMI has nothing special to destroy, so we can go with this. */
1564 intel_dp_encoder_destroy(encoder);
1565}
1566
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001567static bool intel_ddi_compute_config(struct intel_encoder *encoder,
1568 struct intel_crtc_config *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001569{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001570 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02001571 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001572
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001573 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001574
Daniel Vettereccb1402013-05-22 00:50:22 +02001575 if (port == PORT_A)
1576 pipe_config->cpu_transcoder = TRANSCODER_EDP;
1577
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001578 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001579 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001580 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001581 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001582}
1583
1584static const struct drm_encoder_funcs intel_ddi_funcs = {
1585 .destroy = intel_ddi_destroy,
1586};
1587
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001588static struct intel_connector *
1589intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
1590{
1591 struct intel_connector *connector;
1592 enum port port = intel_dig_port->port;
1593
1594 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1595 if (!connector)
1596 return NULL;
1597
1598 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1599 if (!intel_dp_init_connector(intel_dig_port, connector)) {
1600 kfree(connector);
1601 return NULL;
1602 }
1603
1604 return connector;
1605}
1606
1607static struct intel_connector *
1608intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
1609{
1610 struct intel_connector *connector;
1611 enum port port = intel_dig_port->port;
1612
1613 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1614 if (!connector)
1615 return NULL;
1616
1617 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
1618 intel_hdmi_init_connector(intel_dig_port, connector);
1619
1620 return connector;
1621}
1622
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001623void intel_ddi_init(struct drm_device *dev, enum port port)
1624{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001625 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001626 struct intel_digital_port *intel_dig_port;
1627 struct intel_encoder *intel_encoder;
1628 struct drm_encoder *encoder;
1629 struct intel_connector *hdmi_connector = NULL;
1630 struct intel_connector *dp_connector = NULL;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001631 bool init_hdmi, init_dp;
1632
1633 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1634 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1635 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1636 if (!init_dp && !init_hdmi) {
1637 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n",
1638 port_name(port));
1639 init_hdmi = true;
1640 init_dp = true;
1641 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001642
Daniel Vetterb14c5672013-09-19 12:18:32 +02001643 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001644 if (!intel_dig_port)
1645 return;
1646
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001647 intel_encoder = &intel_dig_port->base;
1648 encoder = &intel_encoder->base;
1649
1650 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1651 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001652
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001653 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001654 intel_encoder->enable = intel_enable_ddi;
1655 intel_encoder->pre_enable = intel_ddi_pre_enable;
1656 intel_encoder->disable = intel_disable_ddi;
1657 intel_encoder->post_disable = intel_ddi_post_disable;
1658 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001659 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001660
1661 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001662 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
1663 (DDI_BUF_PORT_REVERSAL |
1664 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001665
1666 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
1667 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001668 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001669 intel_encoder->hot_plug = intel_ddi_hot_plug;
1670
Dave Airlie13cf5502014-06-18 11:29:35 +10001671 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
1672 dev_priv->hpd_irq_port[port] = intel_dig_port;
1673
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001674 if (init_dp)
1675 dp_connector = intel_ddi_init_dp_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001676
Paulo Zanoni311a2092013-09-12 17:12:18 -03001677 /* In theory we don't need the encoder->type check, but leave it just in
1678 * case we have some really bad VBTs... */
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001679 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi)
1680 hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001681
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001682 if (!dp_connector && !hdmi_connector) {
1683 drm_encoder_cleanup(encoder);
1684 kfree(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001685 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001686}