blob: 7c6e8d549467f2a6f0964fc1e9481b2ed2736015 [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);
Daniel Vetter12030432014-06-25 22:02:00 +0300394 struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(intel_crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300395
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) {
Daniel Vetter12030432014-06-25 22:02:00 +0300400 pll->disable(dev_priv, pll);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300401 }
Daniel Vetter0e503382014-07-04 11:26:04 -0300402 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300403 break;
404 case PORT_CLK_SEL_WRPLL2:
405 plls->wrpll2_refcount--;
406 if (plls->wrpll2_refcount == 0) {
Daniel Vetter12030432014-06-25 22:02:00 +0300407 pll->disable(dev_priv, pll);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300408 }
Daniel Vetter0e503382014-07-04 11:26:04 -0300409 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300410 break;
411 }
412
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300413 WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
414 WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300415}
416
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100417#define LC_FREQ 2700
418#define LC_FREQ_2K (LC_FREQ * 2000)
419
420#define P_MIN 2
421#define P_MAX 64
422#define P_INC 2
423
424/* Constraints for PLL good behavior */
425#define REF_MIN 48
426#define REF_MAX 400
427#define VCO_MIN 2400
428#define VCO_MAX 4800
429
430#define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
431
432struct wrpll_rnp {
433 unsigned p, n2, r2;
434};
435
436static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300437{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100438 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300439
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100440 switch (clock) {
441 case 25175000:
442 case 25200000:
443 case 27000000:
444 case 27027000:
445 case 37762500:
446 case 37800000:
447 case 40500000:
448 case 40541000:
449 case 54000000:
450 case 54054000:
451 case 59341000:
452 case 59400000:
453 case 72000000:
454 case 74176000:
455 case 74250000:
456 case 81000000:
457 case 81081000:
458 case 89012000:
459 case 89100000:
460 case 108000000:
461 case 108108000:
462 case 111264000:
463 case 111375000:
464 case 148352000:
465 case 148500000:
466 case 162000000:
467 case 162162000:
468 case 222525000:
469 case 222750000:
470 case 296703000:
471 case 297000000:
472 budget = 0;
473 break;
474 case 233500000:
475 case 245250000:
476 case 247750000:
477 case 253250000:
478 case 298000000:
479 budget = 1500;
480 break;
481 case 169128000:
482 case 169500000:
483 case 179500000:
484 case 202000000:
485 budget = 2000;
486 break;
487 case 256250000:
488 case 262500000:
489 case 270000000:
490 case 272500000:
491 case 273750000:
492 case 280750000:
493 case 281250000:
494 case 286000000:
495 case 291750000:
496 budget = 4000;
497 break;
498 case 267250000:
499 case 268500000:
500 budget = 5000;
501 break;
502 default:
503 budget = 1000;
504 break;
505 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300506
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100507 return budget;
508}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300509
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100510static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
511 unsigned r2, unsigned n2, unsigned p,
512 struct wrpll_rnp *best)
513{
514 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300515
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100516 /* No best (r,n,p) yet */
517 if (best->p == 0) {
518 best->p = p;
519 best->n2 = n2;
520 best->r2 = r2;
521 return;
522 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300523
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100524 /*
525 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
526 * freq2k.
527 *
528 * delta = 1e6 *
529 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
530 * freq2k;
531 *
532 * and we would like delta <= budget.
533 *
534 * If the discrepancy is above the PPM-based budget, always prefer to
535 * improve upon the previous solution. However, if you're within the
536 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
537 */
538 a = freq2k * budget * p * r2;
539 b = freq2k * budget * best->p * best->r2;
540 diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
541 diff_best = ABS_DIFF((freq2k * best->p * best->r2),
542 (LC_FREQ_2K * best->n2));
543 c = 1000000 * diff;
544 d = 1000000 * diff_best;
545
546 if (a < c && b < d) {
547 /* If both are above the budget, pick the closer */
548 if (best->p * best->r2 * diff < p * r2 * diff_best) {
549 best->p = p;
550 best->n2 = n2;
551 best->r2 = r2;
552 }
553 } else if (a >= c && b < d) {
554 /* If A is below the threshold but B is above it? Update. */
555 best->p = p;
556 best->n2 = n2;
557 best->r2 = r2;
558 } else if (a >= c && b >= d) {
559 /* Both are below the limit, so pick the higher n2/(r2*r2) */
560 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
561 best->p = p;
562 best->n2 = n2;
563 best->r2 = r2;
564 }
565 }
566 /* Otherwise a < c && b >= d, do nothing */
567}
568
Jesse Barnes11578552014-01-21 12:42:10 -0800569static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
570 int reg)
571{
572 int refclk = LC_FREQ;
573 int n, p, r;
574 u32 wrpll;
575
576 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300577 switch (wrpll & WRPLL_PLL_REF_MASK) {
578 case WRPLL_PLL_SSC:
579 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800580 /*
581 * We could calculate spread here, but our checking
582 * code only cares about 5% accuracy, and spread is a max of
583 * 0.5% downspread.
584 */
585 refclk = 135;
586 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300587 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800588 refclk = LC_FREQ;
589 break;
590 default:
591 WARN(1, "bad wrpll refclk\n");
592 return 0;
593 }
594
595 r = wrpll & WRPLL_DIVIDER_REF_MASK;
596 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
597 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
598
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800599 /* Convert to KHz, p & r have a fixed point portion */
600 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800601}
602
603static void intel_ddi_clock_get(struct intel_encoder *encoder,
604 struct intel_crtc_config *pipe_config)
605{
606 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jesse Barnes11578552014-01-21 12:42:10 -0800607 int link_clock = 0;
608 u32 val, pll;
609
Daniel Vetter26804af2014-06-25 22:01:55 +0300610 val = pipe_config->ddi_pll_sel;
Jesse Barnes11578552014-01-21 12:42:10 -0800611 switch (val & PORT_CLK_SEL_MASK) {
612 case PORT_CLK_SEL_LCPLL_810:
613 link_clock = 81000;
614 break;
615 case PORT_CLK_SEL_LCPLL_1350:
616 link_clock = 135000;
617 break;
618 case PORT_CLK_SEL_LCPLL_2700:
619 link_clock = 270000;
620 break;
621 case PORT_CLK_SEL_WRPLL1:
622 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
623 break;
624 case PORT_CLK_SEL_WRPLL2:
625 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
626 break;
627 case PORT_CLK_SEL_SPLL:
628 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
629 if (pll == SPLL_PLL_FREQ_810MHz)
630 link_clock = 81000;
631 else if (pll == SPLL_PLL_FREQ_1350MHz)
632 link_clock = 135000;
633 else if (pll == SPLL_PLL_FREQ_2700MHz)
634 link_clock = 270000;
635 else {
636 WARN(1, "bad spll freq\n");
637 return;
638 }
639 break;
640 default:
641 WARN(1, "bad port clock sel\n");
642 return;
643 }
644
645 pipe_config->port_clock = link_clock * 2;
646
647 if (pipe_config->has_pch_encoder)
648 pipe_config->adjusted_mode.crtc_clock =
649 intel_dotclock_calculate(pipe_config->port_clock,
650 &pipe_config->fdi_m_n);
651 else if (pipe_config->has_dp_encoder)
652 pipe_config->adjusted_mode.crtc_clock =
653 intel_dotclock_calculate(pipe_config->port_clock,
654 &pipe_config->dp_m_n);
655 else
656 pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
657}
658
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100659static void
660intel_ddi_calculate_wrpll(int clock /* in Hz */,
661 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
662{
663 uint64_t freq2k;
664 unsigned p, n2, r2;
665 struct wrpll_rnp best = { 0, 0, 0 };
666 unsigned budget;
667
668 freq2k = clock / 100;
669
670 budget = wrpll_get_budget_for_freq(clock);
671
672 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
673 * and directly pass the LC PLL to it. */
674 if (freq2k == 5400000) {
675 *n2_out = 2;
676 *p_out = 1;
677 *r2_out = 2;
678 return;
679 }
680
681 /*
682 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
683 * the WR PLL.
684 *
685 * We want R so that REF_MIN <= Ref <= REF_MAX.
686 * Injecting R2 = 2 * R gives:
687 * REF_MAX * r2 > LC_FREQ * 2 and
688 * REF_MIN * r2 < LC_FREQ * 2
689 *
690 * Which means the desired boundaries for r2 are:
691 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
692 *
693 */
694 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
695 r2 <= LC_FREQ * 2 / REF_MIN;
696 r2++) {
697
698 /*
699 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
700 *
701 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
702 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
703 * VCO_MAX * r2 > n2 * LC_FREQ and
704 * VCO_MIN * r2 < n2 * LC_FREQ)
705 *
706 * Which means the desired boundaries for n2 are:
707 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
708 */
709 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
710 n2 <= VCO_MAX * r2 / LC_FREQ;
711 n2++) {
712
713 for (p = P_MIN; p <= P_MAX; p += P_INC)
714 wrpll_update_rnp(freq2k, budget,
715 r2, n2, p, &best);
716 }
717 }
718
719 *n2_out = best.n2;
720 *p_out = best.p;
721 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300722}
723
Paulo Zanoni566b7342013-11-25 15:27:08 -0200724/*
725 * Tries to find a PLL for the CRTC. If it finds, it increases the refcount and
726 * stores it in intel_crtc->ddi_pll_sel, so other mode sets won't be able to
727 * steal the selected PLL. You need to call intel_ddi_pll_enable to actually
728 * enable the PLL.
729 */
730bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300731{
Paulo Zanoni566b7342013-11-25 15:27:08 -0200732 struct drm_crtc *crtc = &intel_crtc->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300733 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
734 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
735 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
736 int type = intel_encoder->type;
737 enum pipe pipe = intel_crtc->pipe;
Daniel Vetterff9a6752013-06-01 17:16:21 +0200738 int clock = intel_crtc->config.port_clock;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300739
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300740 intel_ddi_put_crtc_pll(crtc);
741
Daniel Vetter0e503382014-07-04 11:26:04 -0300742 if (type == INTEL_OUTPUT_HDMI) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200743 uint32_t reg, val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100744 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300745
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100746 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300747
Daniel Vetter114fe482014-06-25 22:01:48 +0300748 val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300749 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
750 WRPLL_DIVIDER_POST(p);
751
Paulo Zanoni06940012013-10-30 18:27:43 -0200752 if (val == I915_READ(WRPLL_CTL1)) {
753 DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n",
754 pipe_name(pipe));
755 reg = WRPLL_CTL1;
756 } else if (val == I915_READ(WRPLL_CTL2)) {
757 DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n",
758 pipe_name(pipe));
759 reg = WRPLL_CTL2;
760 } else if (plls->wrpll1_refcount == 0) {
761 DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
762 pipe_name(pipe));
763 reg = WRPLL_CTL1;
764 } else if (plls->wrpll2_refcount == 0) {
765 DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
766 pipe_name(pipe));
767 reg = WRPLL_CTL2;
768 } else {
769 DRM_ERROR("No WRPLLs available!\n");
770 return false;
771 }
772
Paulo Zanoni566b7342013-11-25 15:27:08 -0200773 DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
774 clock, p, n2, r2);
775
Paulo Zanoni06940012013-10-30 18:27:43 -0200776 if (reg == WRPLL_CTL1) {
777 plls->wrpll1_refcount++;
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300778 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
Daniel Vetter9cd86932014-06-25 22:01:57 +0300779 intel_crtc->config.shared_dpll = DPLL_ID_WRPLL1;
Paulo Zanoni06940012013-10-30 18:27:43 -0200780 } else {
781 plls->wrpll2_refcount++;
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300782 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
Daniel Vetter9cd86932014-06-25 22:01:57 +0300783 intel_crtc->config.shared_dpll = DPLL_ID_WRPLL2;
Paulo Zanoni06940012013-10-30 18:27:43 -0200784 }
Daniel Vetterd452c5b2014-07-04 11:27:39 -0300785
786 intel_crtc->config.dpll_hw_state.wrpll = val;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300787 }
788
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300789 return true;
790}
791
Paulo Zanoni566b7342013-11-25 15:27:08 -0200792/*
793 * To be called after intel_ddi_pll_select(). That one selects the PLL to be
794 * used, this one actually enables the PLL.
795 */
796void intel_ddi_pll_enable(struct intel_crtc *crtc)
797{
798 struct drm_device *dev = crtc->base.dev;
799 struct drm_i915_private *dev_priv = dev->dev_private;
800 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
801 int clock = crtc->config.port_clock;
802 uint32_t reg, cur_val, new_val;
803 int refcount;
804 const char *pll_name;
805 uint32_t enable_bit = (1 << 31);
806 unsigned int p, n2, r2;
807
808 BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE);
809 BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE);
810
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300811 switch (crtc->config.ddi_pll_sel) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200812 case PORT_CLK_SEL_WRPLL1:
813 case PORT_CLK_SEL_WRPLL2:
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300814 if (crtc->config.ddi_pll_sel == PORT_CLK_SEL_WRPLL1) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200815 pll_name = "WRPLL1";
816 reg = WRPLL_CTL1;
817 refcount = plls->wrpll1_refcount;
818 } else {
819 pll_name = "WRPLL2";
820 reg = WRPLL_CTL2;
821 refcount = plls->wrpll2_refcount;
822 }
823
824 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
825
Daniel Vetter114fe482014-06-25 22:01:48 +0300826 new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni566b7342013-11-25 15:27:08 -0200827 WRPLL_DIVIDER_REFERENCE(r2) |
828 WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p);
829
830 break;
831
832 case PORT_CLK_SEL_NONE:
833 WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n");
834 return;
835 default:
Paulo Zanoni566b7342013-11-25 15:27:08 -0200836 return;
837 }
838
839 cur_val = I915_READ(reg);
840
841 WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount);
842 if (refcount == 1) {
843 WARN(cur_val & enable_bit, "%s already enabled\n", pll_name);
844 I915_WRITE(reg, new_val);
845 POSTING_READ(reg);
846 udelay(20);
847 } else {
848 WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name);
849 }
850}
851
Paulo Zanonidae84792012-10-15 15:51:30 -0300852void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
853{
854 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
855 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
856 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200857 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300858 int type = intel_encoder->type;
859 uint32_t temp;
860
861 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
862
Paulo Zanonic9809792012-10-23 18:30:00 -0200863 temp = TRANS_MSA_SYNC_CLK;
Daniel Vetter965e0c42013-03-27 00:44:57 +0100864 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -0300865 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200866 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300867 break;
868 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200869 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300870 break;
871 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200872 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300873 break;
874 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200875 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300876 break;
877 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100878 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -0300879 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200880 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300881 }
882}
883
Damien Lespiau8228c252013-03-07 15:30:27 +0000884void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300885{
886 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
887 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300888 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -0700889 struct drm_device *dev = crtc->dev;
890 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300891 enum pipe pipe = intel_crtc->pipe;
Daniel Vetter3b117c82013-04-17 20:15:07 +0200892 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200893 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300894 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300895 uint32_t temp;
896
Paulo Zanoniad80a812012-10-24 16:06:19 -0200897 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
898 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200899 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -0300900
Daniel Vetter965e0c42013-03-27 00:44:57 +0100901 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -0300902 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200903 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300904 break;
905 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200906 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300907 break;
908 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200909 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300910 break;
911 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200912 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300913 break;
914 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100915 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -0300916 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300917
Ville Syrjäläa6662832013-09-10 17:03:41 +0300918 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200919 temp |= TRANS_DDI_PVSYNC;
Ville Syrjäläa6662832013-09-10 17:03:41 +0300920 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200921 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -0300922
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200923 if (cpu_transcoder == TRANSCODER_EDP) {
924 switch (pipe) {
925 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -0700926 /* On Haswell, can only use the always-on power well for
927 * eDP when not using the panel fitter, and when not
928 * using motion blur mitigation (which we don't
929 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +0200930 if (IS_HASWELL(dev) &&
931 (intel_crtc->config.pch_pfit.enabled ||
932 intel_crtc->config.pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -0200933 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
934 else
935 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200936 break;
937 case PIPE_B:
938 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
939 break;
940 case PIPE_C:
941 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
942 break;
943 default:
944 BUG();
945 break;
946 }
947 }
948
Paulo Zanoni7739c332012-10-15 15:51:29 -0300949 if (type == INTEL_OUTPUT_HDMI) {
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200950 if (intel_crtc->config.has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200951 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300952 else
Paulo Zanoniad80a812012-10-24 16:06:19 -0200953 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300954
Paulo Zanoni7739c332012-10-15 15:51:29 -0300955 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -0200956 temp |= TRANS_DDI_MODE_SELECT_FDI;
Daniel Vetter33d29b12013-02-13 18:04:45 +0100957 temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300958
959 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
960 type == INTEL_OUTPUT_EDP) {
961 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
962
Paulo Zanoniad80a812012-10-24 16:06:19 -0200963 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300964
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200965 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300966 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300967 WARN(1, "Invalid encoder type %d for pipe %c\n",
968 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300969 }
970
Paulo Zanoniad80a812012-10-24 16:06:19 -0200971 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300972}
973
Paulo Zanoniad80a812012-10-24 16:06:19 -0200974void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
975 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300976{
Paulo Zanoniad80a812012-10-24 16:06:19 -0200977 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300978 uint32_t val = I915_READ(reg);
979
Paulo Zanoniad80a812012-10-24 16:06:19 -0200980 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
981 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300982 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300983}
984
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200985bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
986{
987 struct drm_device *dev = intel_connector->base.dev;
988 struct drm_i915_private *dev_priv = dev->dev_private;
989 struct intel_encoder *intel_encoder = intel_connector->encoder;
990 int type = intel_connector->base.connector_type;
991 enum port port = intel_ddi_get_encoder_port(intel_encoder);
992 enum pipe pipe = 0;
993 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -0300994 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200995 uint32_t tmp;
996
Paulo Zanoni882244a2014-04-01 14:55:12 -0300997 power_domain = intel_display_port_power_domain(intel_encoder);
998 if (!intel_display_power_enabled(dev_priv, power_domain))
999 return false;
1000
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001001 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
1002 return false;
1003
1004 if (port == PORT_A)
1005 cpu_transcoder = TRANSCODER_EDP;
1006 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001007 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001008
1009 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1010
1011 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1012 case TRANS_DDI_MODE_SELECT_HDMI:
1013 case TRANS_DDI_MODE_SELECT_DVI:
1014 return (type == DRM_MODE_CONNECTOR_HDMIA);
1015
1016 case TRANS_DDI_MODE_SELECT_DP_SST:
1017 if (type == DRM_MODE_CONNECTOR_eDP)
1018 return true;
1019 case TRANS_DDI_MODE_SELECT_DP_MST:
1020 return (type == DRM_MODE_CONNECTOR_DisplayPort);
1021
1022 case TRANS_DDI_MODE_SELECT_FDI:
1023 return (type == DRM_MODE_CONNECTOR_VGA);
1024
1025 default:
1026 return false;
1027 }
1028}
1029
Daniel Vetter85234cd2012-07-02 13:27:29 +02001030bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1031 enum pipe *pipe)
1032{
1033 struct drm_device *dev = encoder->base.dev;
1034 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001035 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001036 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001037 u32 tmp;
1038 int i;
1039
Imre Deak6d129be2014-03-05 16:20:54 +02001040 power_domain = intel_display_port_power_domain(encoder);
1041 if (!intel_display_power_enabled(dev_priv, power_domain))
1042 return false;
1043
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001044 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001045
1046 if (!(tmp & DDI_BUF_CTL_ENABLE))
1047 return false;
1048
Paulo Zanoniad80a812012-10-24 16:06:19 -02001049 if (port == PORT_A) {
1050 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001051
Paulo Zanoniad80a812012-10-24 16:06:19 -02001052 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1053 case TRANS_DDI_EDP_INPUT_A_ON:
1054 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1055 *pipe = PIPE_A;
1056 break;
1057 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1058 *pipe = PIPE_B;
1059 break;
1060 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1061 *pipe = PIPE_C;
1062 break;
1063 }
1064
1065 return true;
1066 } else {
1067 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1068 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1069
1070 if ((tmp & TRANS_DDI_PORT_MASK)
1071 == TRANS_DDI_SELECT_PORT(port)) {
1072 *pipe = i;
1073 return true;
1074 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001075 }
1076 }
1077
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001078 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001079
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001080 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001081}
1082
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001083void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
1084{
1085 struct drm_i915_private *dev_priv = dev->dev_private;
1086 enum pipe pipe;
1087 struct intel_crtc *intel_crtc;
1088
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001089 dev_priv->ddi_plls.wrpll1_refcount = 0;
1090 dev_priv->ddi_plls.wrpll2_refcount = 0;
1091
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001092 for_each_pipe(pipe) {
1093 intel_crtc =
1094 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1095
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001096 if (!intel_crtc->active) {
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001097 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001098 continue;
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001099 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001100
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001101 switch (intel_crtc->config.ddi_pll_sel) {
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001102 case PORT_CLK_SEL_WRPLL1:
1103 dev_priv->ddi_plls.wrpll1_refcount++;
1104 break;
1105 case PORT_CLK_SEL_WRPLL2:
1106 dev_priv->ddi_plls.wrpll2_refcount++;
1107 break;
1108 }
1109 }
1110}
1111
Paulo Zanonifc914632012-10-05 12:05:54 -03001112void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1113{
1114 struct drm_crtc *crtc = &intel_crtc->base;
1115 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1116 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1117 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +02001118 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001119
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001120 if (cpu_transcoder != TRANSCODER_EDP)
1121 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1122 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001123}
1124
1125void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1126{
1127 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001128 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001129
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001130 if (cpu_transcoder != TRANSCODER_EDP)
1131 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1132 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001133}
1134
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001135static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001136{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001137 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001138 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001139 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001140 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001141 int type = intel_encoder->type;
1142
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001143 if (crtc->config.has_audio) {
1144 DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
1145 pipe_name(crtc->pipe));
1146
1147 /* write eld */
1148 DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
1149 intel_write_eld(encoder, &crtc->config.adjusted_mode);
1150 }
1151
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001152 if (type == INTEL_OUTPUT_EDP) {
1153 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001154 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001155 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001156
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001157 WARN_ON(crtc->config.ddi_pll_sel == PORT_CLK_SEL_NONE);
1158 I915_WRITE(PORT_CLK_SEL(port), crtc->config.ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001159
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001160 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001161 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001162 struct intel_digital_port *intel_dig_port =
1163 enc_to_dig_port(encoder);
1164
1165 intel_dp->DP = intel_dig_port->saved_port_bits |
1166 DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
1167 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001168
1169 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1170 intel_dp_start_link_train(intel_dp);
1171 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001172 if (port != PORT_A)
1173 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001174 } else if (type == INTEL_OUTPUT_HDMI) {
1175 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1176
1177 intel_hdmi->set_infoframes(encoder,
1178 crtc->config.has_hdmi_sink,
1179 &crtc->config.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001180 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001181}
1182
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001183static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001184{
1185 struct drm_encoder *encoder = &intel_encoder->base;
1186 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1187 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001188 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001189 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001190 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001191
1192 val = I915_READ(DDI_BUF_CTL(port));
1193 if (val & DDI_BUF_CTL_ENABLE) {
1194 val &= ~DDI_BUF_CTL_ENABLE;
1195 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001196 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001197 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001198
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001199 val = I915_READ(DP_TP_CTL(port));
1200 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1201 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1202 I915_WRITE(DP_TP_CTL(port), val);
1203
1204 if (wait)
1205 intel_wait_ddi_buf_idle(dev_priv, port);
1206
Jani Nikula76bb80e2013-11-15 15:29:57 +02001207 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001208 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001209 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001210 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001211 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001212 }
1213
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001214 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1215}
1216
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001217static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001218{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001219 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001220 struct drm_crtc *crtc = encoder->crtc;
1221 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1222 int pipe = intel_crtc->pipe;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001223 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001224 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001225 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1226 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001227 uint32_t tmp;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001228
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001229 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001230 struct intel_digital_port *intel_dig_port =
1231 enc_to_dig_port(encoder);
1232
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001233 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1234 * are ignored so nothing special needs to be done besides
1235 * enabling the port.
1236 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001237 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001238 intel_dig_port->saved_port_bits |
1239 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001240 } else if (type == INTEL_OUTPUT_EDP) {
1241 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1242
Imre Deak3ab9c632013-05-03 12:57:41 +03001243 if (port == PORT_A)
1244 intel_dp_stop_link_train(intel_dp);
1245
Daniel Vetter4be73782014-01-17 14:39:48 +01001246 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi49065572013-07-11 18:45:05 -03001247 intel_edp_psr_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001248 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001249
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001250 if (intel_crtc->config.has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001251 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001252 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1253 tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1254 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1255 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001256}
1257
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001258static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001259{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001260 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001261 struct drm_crtc *crtc = encoder->crtc;
1262 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1263 int pipe = intel_crtc->pipe;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001264 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001265 struct drm_device *dev = encoder->dev;
1266 struct drm_i915_private *dev_priv = dev->dev_private;
1267 uint32_t tmp;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001268
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001269 /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
1270 * register is part of the power well on Haswell. */
1271 if (intel_crtc->config.has_audio) {
1272 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1273 tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1274 (pipe * 4));
1275 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1276 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1277 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001278
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001279 if (type == INTEL_OUTPUT_EDP) {
1280 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1281
Rodrigo Vivi49065572013-07-11 18:45:05 -03001282 intel_edp_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001283 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001284 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001285}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001286
Paulo Zanonib8fc2f62012-10-23 18:30:05 -02001287int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001288{
Paulo Zanonie39bf982013-11-02 21:07:36 -07001289 struct drm_device *dev = dev_priv->dev;
Paulo Zanonia4006642013-08-06 18:57:11 -03001290 uint32_t lcpll = I915_READ(LCPLL_CTL);
Paulo Zanonie39bf982013-11-02 21:07:36 -07001291 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Paulo Zanonia4006642013-08-06 18:57:11 -03001292
Paulo Zanonie39bf982013-11-02 21:07:36 -07001293 if (lcpll & LCPLL_CD_SOURCE_FCLK) {
Paulo Zanonia4006642013-08-06 18:57:11 -03001294 return 800000;
Damien Lespiaue3589902014-02-07 19:12:50 +00001295 } else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001296 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001297 } else if (freq == LCPLL_CLK_FREQ_450) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001298 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001299 } else if (IS_HASWELL(dev)) {
1300 if (IS_ULT(dev))
1301 return 337500;
1302 else
1303 return 540000;
1304 } else {
1305 if (freq == LCPLL_CLK_FREQ_54O_BDW)
1306 return 540000;
1307 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
1308 return 337500;
1309 else
1310 return 675000;
1311 }
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001312}
1313
Daniel Vetter12030432014-06-25 22:02:00 +03001314static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv,
1315 struct intel_shared_dpll *pll)
1316{
1317 uint32_t val;
1318
1319 val = I915_READ(WRPLL_CTL(pll->id));
1320 WARN_ON(!(val & WRPLL_PLL_ENABLE));
1321 I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
1322 POSTING_READ(WRPLL_CTL(pll->id));
1323}
1324
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001325static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
1326 struct intel_shared_dpll *pll,
1327 struct intel_dpll_hw_state *hw_state)
1328{
1329 uint32_t val;
1330
1331 if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
1332 return false;
1333
1334 val = I915_READ(WRPLL_CTL(pll->id));
1335 hw_state->wrpll = val;
1336
1337 return val & WRPLL_PLL_ENABLE;
1338}
1339
Daniel Vetter9cd86932014-06-25 22:01:57 +03001340static char *hsw_ddi_pll_names[] = {
1341 "WRPLL 1",
1342 "WRPLL 2",
1343};
1344
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001345void intel_ddi_pll_init(struct drm_device *dev)
1346{
1347 struct drm_i915_private *dev_priv = dev->dev_private;
1348 uint32_t val = I915_READ(LCPLL_CTL);
Daniel Vetter9cd86932014-06-25 22:01:57 +03001349 int i;
1350
1351 /* Dummy setup until everything is moved over to avoid upsetting the hw
1352 * state cross checker. */
1353 dev_priv->num_shared_dpll = 0;
1354
1355 for (i = 0; i < 2; i++) {
1356 dev_priv->shared_dplls[i].id = i;
1357 dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
Daniel Vetter12030432014-06-25 22:02:00 +03001358 dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable;
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001359 dev_priv->shared_dplls[i].get_hw_state =
1360 hsw_ddi_pll_get_hw_state;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001361 }
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001362
1363 /* The LCPLL register should be turned on by the BIOS. For now let's
1364 * just check its state and print errors in case something is wrong.
1365 * Don't even try to turn it on.
1366 */
1367
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001368 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001369 intel_ddi_get_cdclk_freq(dev_priv));
1370
1371 if (val & LCPLL_CD_SOURCE_FCLK)
1372 DRM_ERROR("CDCLK source is not LCPLL\n");
1373
1374 if (val & LCPLL_PLL_DISABLE)
1375 DRM_ERROR("LCPLL is disabled\n");
1376}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001377
1378void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1379{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001380 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1381 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001382 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001383 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001384 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301385 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001386
1387 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1388 val = I915_READ(DDI_BUF_CTL(port));
1389 if (val & DDI_BUF_CTL_ENABLE) {
1390 val &= ~DDI_BUF_CTL_ENABLE;
1391 I915_WRITE(DDI_BUF_CTL(port), val);
1392 wait = true;
1393 }
1394
1395 val = I915_READ(DP_TP_CTL(port));
1396 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1397 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1398 I915_WRITE(DP_TP_CTL(port), val);
1399 POSTING_READ(DP_TP_CTL(port));
1400
1401 if (wait)
1402 intel_wait_ddi_buf_idle(dev_priv, port);
1403 }
1404
1405 val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
1406 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Jani Nikula6aba5b62013-10-04 15:08:10 +03001407 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Paulo Zanonic19b0662012-10-15 15:51:41 -03001408 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1409 I915_WRITE(DP_TP_CTL(port), val);
1410 POSTING_READ(DP_TP_CTL(port));
1411
1412 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1413 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1414 POSTING_READ(DDI_BUF_CTL(port));
1415
1416 udelay(600);
1417}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001418
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001419void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1420{
1421 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1422 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1423 uint32_t val;
1424
1425 intel_ddi_post_disable(intel_encoder);
1426
1427 val = I915_READ(_FDI_RXA_CTL);
1428 val &= ~FDI_RX_ENABLE;
1429 I915_WRITE(_FDI_RXA_CTL, val);
1430
1431 val = I915_READ(_FDI_RXA_MISC);
1432 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1433 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1434 I915_WRITE(_FDI_RXA_MISC, val);
1435
1436 val = I915_READ(_FDI_RXA_CTL);
1437 val &= ~FDI_PCDCLK;
1438 I915_WRITE(_FDI_RXA_CTL, val);
1439
1440 val = I915_READ(_FDI_RXA_CTL);
1441 val &= ~FDI_RX_PLL_ENABLE;
1442 I915_WRITE(_FDI_RXA_CTL, val);
1443}
1444
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001445static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1446{
1447 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
1448 int type = intel_encoder->type;
1449
1450 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
1451 intel_dp_check_link_status(intel_dp);
1452}
1453
Ville Syrjälä6801c182013-09-24 14:24:05 +03001454void intel_ddi_get_config(struct intel_encoder *encoder,
1455 struct intel_crtc_config *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001456{
1457 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1458 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1459 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
1460 u32 temp, flags = 0;
1461
1462 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1463 if (temp & TRANS_DDI_PHSYNC)
1464 flags |= DRM_MODE_FLAG_PHSYNC;
1465 else
1466 flags |= DRM_MODE_FLAG_NHSYNC;
1467 if (temp & TRANS_DDI_PVSYNC)
1468 flags |= DRM_MODE_FLAG_PVSYNC;
1469 else
1470 flags |= DRM_MODE_FLAG_NVSYNC;
1471
1472 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001473
1474 switch (temp & TRANS_DDI_BPC_MASK) {
1475 case TRANS_DDI_BPC_6:
1476 pipe_config->pipe_bpp = 18;
1477 break;
1478 case TRANS_DDI_BPC_8:
1479 pipe_config->pipe_bpp = 24;
1480 break;
1481 case TRANS_DDI_BPC_10:
1482 pipe_config->pipe_bpp = 30;
1483 break;
1484 case TRANS_DDI_BPC_12:
1485 pipe_config->pipe_bpp = 36;
1486 break;
1487 default:
1488 break;
1489 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001490
1491 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1492 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001493 pipe_config->has_hdmi_sink = true;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001494 case TRANS_DDI_MODE_SELECT_DVI:
1495 case TRANS_DDI_MODE_SELECT_FDI:
1496 break;
1497 case TRANS_DDI_MODE_SELECT_DP_SST:
1498 case TRANS_DDI_MODE_SELECT_DP_MST:
1499 pipe_config->has_dp_encoder = true;
1500 intel_dp_get_m_n(intel_crtc, pipe_config);
1501 break;
1502 default:
1503 break;
1504 }
Daniel Vetter10214422013-11-18 07:38:16 +01001505
Paulo Zanonia60551b2014-05-21 16:23:20 -03001506 if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
1507 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1508 if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
1509 pipe_config->has_audio = true;
1510 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001511
Daniel Vetter10214422013-11-18 07:38:16 +01001512 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1513 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1514 /*
1515 * This is a big fat ugly hack.
1516 *
1517 * Some machines in UEFI boot mode provide us a VBT that has 18
1518 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1519 * unknown we fail to light up. Yet the same BIOS boots up with
1520 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1521 * max, not what it tells us to use.
1522 *
1523 * Note: This will still be broken if the eDP panel is not lit
1524 * up by the BIOS, and thus we can't get the mode at module
1525 * load.
1526 */
1527 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1528 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1529 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1530 }
Jesse Barnes11578552014-01-21 12:42:10 -08001531
1532 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001533}
1534
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001535static void intel_ddi_destroy(struct drm_encoder *encoder)
1536{
1537 /* HDMI has nothing special to destroy, so we can go with this. */
1538 intel_dp_encoder_destroy(encoder);
1539}
1540
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001541static bool intel_ddi_compute_config(struct intel_encoder *encoder,
1542 struct intel_crtc_config *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001543{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001544 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02001545 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001546
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001547 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001548
Daniel Vettereccb1402013-05-22 00:50:22 +02001549 if (port == PORT_A)
1550 pipe_config->cpu_transcoder = TRANSCODER_EDP;
1551
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001552 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001553 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001554 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001555 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001556}
1557
1558static const struct drm_encoder_funcs intel_ddi_funcs = {
1559 .destroy = intel_ddi_destroy,
1560};
1561
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001562static struct intel_connector *
1563intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
1564{
1565 struct intel_connector *connector;
1566 enum port port = intel_dig_port->port;
1567
1568 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1569 if (!connector)
1570 return NULL;
1571
1572 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1573 if (!intel_dp_init_connector(intel_dig_port, connector)) {
1574 kfree(connector);
1575 return NULL;
1576 }
1577
1578 return connector;
1579}
1580
1581static struct intel_connector *
1582intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
1583{
1584 struct intel_connector *connector;
1585 enum port port = intel_dig_port->port;
1586
1587 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1588 if (!connector)
1589 return NULL;
1590
1591 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
1592 intel_hdmi_init_connector(intel_dig_port, connector);
1593
1594 return connector;
1595}
1596
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001597void intel_ddi_init(struct drm_device *dev, enum port port)
1598{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001599 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001600 struct intel_digital_port *intel_dig_port;
1601 struct intel_encoder *intel_encoder;
1602 struct drm_encoder *encoder;
1603 struct intel_connector *hdmi_connector = NULL;
1604 struct intel_connector *dp_connector = NULL;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001605 bool init_hdmi, init_dp;
1606
1607 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1608 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1609 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1610 if (!init_dp && !init_hdmi) {
1611 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n",
1612 port_name(port));
1613 init_hdmi = true;
1614 init_dp = true;
1615 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001616
Daniel Vetterb14c5672013-09-19 12:18:32 +02001617 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001618 if (!intel_dig_port)
1619 return;
1620
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001621 intel_encoder = &intel_dig_port->base;
1622 encoder = &intel_encoder->base;
1623
1624 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1625 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001626
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001627 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001628 intel_encoder->enable = intel_enable_ddi;
1629 intel_encoder->pre_enable = intel_ddi_pre_enable;
1630 intel_encoder->disable = intel_disable_ddi;
1631 intel_encoder->post_disable = intel_ddi_post_disable;
1632 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001633 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001634
1635 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001636 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
1637 (DDI_BUF_PORT_REVERSAL |
1638 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001639
1640 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
1641 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001642 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001643 intel_encoder->hot_plug = intel_ddi_hot_plug;
1644
Dave Airlie13cf5502014-06-18 11:29:35 +10001645 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
1646 dev_priv->hpd_irq_port[port] = intel_dig_port;
1647
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001648 if (init_dp)
1649 dp_connector = intel_ddi_init_dp_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001650
Paulo Zanoni311a2092013-09-12 17:12:18 -03001651 /* In theory we don't need the encoder->type check, but leave it just in
1652 * case we have some really bad VBTs... */
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001653 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi)
1654 hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001655
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001656 if (!dp_connector && !hdmi_connector) {
1657 drm_encoder_cleanup(encoder);
1658 kfree(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001659 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001660}