blob: cd65dd04ba20f8385417971f4f7a2b200e393bda [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,
79 0x00FFFFFF, 0x00020011,
80 0x00DB6FFF, 0x0005000F,
81 0x00BEEFFF, 0x000A000C,
82 0x00FFFFFF, 0x0005000F,
83 0x00DB6FFF, 0x000A000C,
84 0x00FFFFFF, 0x000A000C,
85 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,
92 0x00FFFFFF, 0x000E000A,
93 0x00D75FFF, 0x00180004,
94 0x80CB2FFF, 0x001B0002,
95 0x00F7DFFF, 0x00180004,
96 0x80D75FFF, 0x001B0002,
97 0x80FFFFFF, 0x001B0002,
98 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 */
280 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->ddi_pll_sel);
281
282 /* Start the training iterating through available voltages and emphasis,
283 * testing each value twice. */
284 for (i = 0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300285 /* Configure DP_TP_CTL with auto-training */
286 I915_WRITE(DP_TP_CTL(PORT_E),
287 DP_TP_CTL_FDI_AUTOTRAIN |
288 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
289 DP_TP_CTL_LINK_TRAIN_PAT1 |
290 DP_TP_CTL_ENABLE);
291
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000292 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
293 * DDI E does not support port reversal, the functionality is
294 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
295 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300296 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200297 DDI_BUF_CTL_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100298 ((intel_crtc->config.fdi_lanes - 1) << 1) |
Paulo Zanoni04945642012-11-01 21:00:59 -0200299 hsw_ddi_buf_ctl_values[i / 2]);
300 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300301
302 udelay(600);
303
Paulo Zanoni04945642012-11-01 21:00:59 -0200304 /* Program PCH FDI Receiver TU */
305 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300306
Paulo Zanoni04945642012-11-01 21:00:59 -0200307 /* Enable PCH FDI Receiver with auto-training */
308 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
309 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
310 POSTING_READ(_FDI_RXA_CTL);
311
312 /* Wait for FDI receiver lane calibration */
313 udelay(30);
314
315 /* Unset FDI_RX_MISC pwrdn lanes */
316 temp = I915_READ(_FDI_RXA_MISC);
317 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
318 I915_WRITE(_FDI_RXA_MISC, temp);
319 POSTING_READ(_FDI_RXA_MISC);
320
321 /* Wait for FDI auto training time */
322 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300323
324 temp = I915_READ(DP_TP_STATUS(PORT_E));
325 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200326 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300327
328 /* Enable normal pixel sending for FDI */
329 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200330 DP_TP_CTL_FDI_AUTOTRAIN |
331 DP_TP_CTL_LINK_TRAIN_NORMAL |
332 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
333 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300334
Paulo Zanoni04945642012-11-01 21:00:59 -0200335 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300336 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200337
Paulo Zanoni248138b2012-11-29 11:29:31 -0200338 temp = I915_READ(DDI_BUF_CTL(PORT_E));
339 temp &= ~DDI_BUF_CTL_ENABLE;
340 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
341 POSTING_READ(DDI_BUF_CTL(PORT_E));
342
Paulo Zanoni04945642012-11-01 21:00:59 -0200343 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200344 temp = I915_READ(DP_TP_CTL(PORT_E));
345 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
346 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
347 I915_WRITE(DP_TP_CTL(PORT_E), temp);
348 POSTING_READ(DP_TP_CTL(PORT_E));
349
350 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200351
352 rx_ctl_val &= ~FDI_RX_ENABLE;
353 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200354 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200355
356 /* Reset FDI_RX_MISC pwrdn lanes */
357 temp = I915_READ(_FDI_RXA_MISC);
358 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
359 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
360 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200361 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300362 }
363
Paulo Zanoni04945642012-11-01 21:00:59 -0200364 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300365}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300366
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200367static void intel_ddi_mode_set(struct intel_encoder *encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300368{
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200369 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
370 int port = intel_ddi_get_encoder_port(encoder);
371 int pipe = crtc->pipe;
372 int type = encoder->type;
373 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300374
Damien Lespiaubf98a722013-04-19 14:27:31 +0100375 DRM_DEBUG_KMS("Preparing DDI mode on port %c, pipe %c\n",
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300376 port_name(port), pipe_name(pipe));
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300377
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200378 crtc->eld_vld = false;
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300379 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200380 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000381 struct intel_digital_port *intel_dig_port =
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200382 enc_to_dig_port(&encoder->base);
Wang Xingchao4f078542012-08-09 16:52:16 +0800383
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -0700384 intel_dp->DP = intel_dig_port->saved_port_bits |
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000385 DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200386 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300387
Takashi Iwai8fed6192012-11-19 18:06:51 +0100388 if (intel_dp->has_audio) {
389 DRM_DEBUG_DRIVER("DP audio on pipe %c on DDI\n",
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200390 pipe_name(crtc->pipe));
Takashi Iwai8fed6192012-11-19 18:06:51 +0100391
392 /* write eld */
393 DRM_DEBUG_DRIVER("DP audio: write eld information\n");
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200394 intel_write_eld(&encoder->base, adjusted_mode);
Takashi Iwai8fed6192012-11-19 18:06:51 +0100395 }
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300396 } else if (type == INTEL_OUTPUT_HDMI) {
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200397 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300398
399 if (intel_hdmi->has_audio) {
400 /* Proper support for digital audio needs a new logic
401 * and a new set of registers, so we leave it for future
402 * patch bombing.
403 */
404 DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200405 pipe_name(crtc->pipe));
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300406
407 /* write eld */
408 DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200409 intel_write_eld(&encoder->base, adjusted_mode);
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300410 }
411
Daniel Vetterc7d8be32013-07-21 21:37:07 +0200412 intel_hdmi->set_infoframes(&encoder->base, adjusted_mode);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300413 }
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300414}
415
416static struct intel_encoder *
417intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
418{
419 struct drm_device *dev = crtc->dev;
420 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
421 struct intel_encoder *intel_encoder, *ret = NULL;
422 int num_encoders = 0;
423
424 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
425 ret = intel_encoder;
426 num_encoders++;
427 }
428
429 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300430 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
431 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300432
433 BUG_ON(ret == NULL);
434 return ret;
435}
436
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300437void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
438{
439 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
440 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
441 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
442 uint32_t val;
443
444 switch (intel_crtc->ddi_pll_sel) {
445 case PORT_CLK_SEL_SPLL:
446 plls->spll_refcount--;
447 if (plls->spll_refcount == 0) {
448 DRM_DEBUG_KMS("Disabling SPLL\n");
449 val = I915_READ(SPLL_CTL);
450 WARN_ON(!(val & SPLL_PLL_ENABLE));
451 I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
452 POSTING_READ(SPLL_CTL);
453 }
454 break;
455 case PORT_CLK_SEL_WRPLL1:
456 plls->wrpll1_refcount--;
457 if (plls->wrpll1_refcount == 0) {
458 DRM_DEBUG_KMS("Disabling WRPLL 1\n");
459 val = I915_READ(WRPLL_CTL1);
460 WARN_ON(!(val & WRPLL_PLL_ENABLE));
461 I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
462 POSTING_READ(WRPLL_CTL1);
463 }
464 break;
465 case PORT_CLK_SEL_WRPLL2:
466 plls->wrpll2_refcount--;
467 if (plls->wrpll2_refcount == 0) {
468 DRM_DEBUG_KMS("Disabling WRPLL 2\n");
469 val = I915_READ(WRPLL_CTL2);
470 WARN_ON(!(val & WRPLL_PLL_ENABLE));
471 I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
472 POSTING_READ(WRPLL_CTL2);
473 }
474 break;
475 }
476
477 WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
478 WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
479 WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
480
481 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
482}
483
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100484#define LC_FREQ 2700
485#define LC_FREQ_2K (LC_FREQ * 2000)
486
487#define P_MIN 2
488#define P_MAX 64
489#define P_INC 2
490
491/* Constraints for PLL good behavior */
492#define REF_MIN 48
493#define REF_MAX 400
494#define VCO_MIN 2400
495#define VCO_MAX 4800
496
497#define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
498
499struct wrpll_rnp {
500 unsigned p, n2, r2;
501};
502
503static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300504{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100505 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300506
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100507 switch (clock) {
508 case 25175000:
509 case 25200000:
510 case 27000000:
511 case 27027000:
512 case 37762500:
513 case 37800000:
514 case 40500000:
515 case 40541000:
516 case 54000000:
517 case 54054000:
518 case 59341000:
519 case 59400000:
520 case 72000000:
521 case 74176000:
522 case 74250000:
523 case 81000000:
524 case 81081000:
525 case 89012000:
526 case 89100000:
527 case 108000000:
528 case 108108000:
529 case 111264000:
530 case 111375000:
531 case 148352000:
532 case 148500000:
533 case 162000000:
534 case 162162000:
535 case 222525000:
536 case 222750000:
537 case 296703000:
538 case 297000000:
539 budget = 0;
540 break;
541 case 233500000:
542 case 245250000:
543 case 247750000:
544 case 253250000:
545 case 298000000:
546 budget = 1500;
547 break;
548 case 169128000:
549 case 169500000:
550 case 179500000:
551 case 202000000:
552 budget = 2000;
553 break;
554 case 256250000:
555 case 262500000:
556 case 270000000:
557 case 272500000:
558 case 273750000:
559 case 280750000:
560 case 281250000:
561 case 286000000:
562 case 291750000:
563 budget = 4000;
564 break;
565 case 267250000:
566 case 268500000:
567 budget = 5000;
568 break;
569 default:
570 budget = 1000;
571 break;
572 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300573
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100574 return budget;
575}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300576
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100577static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
578 unsigned r2, unsigned n2, unsigned p,
579 struct wrpll_rnp *best)
580{
581 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300582
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100583 /* No best (r,n,p) yet */
584 if (best->p == 0) {
585 best->p = p;
586 best->n2 = n2;
587 best->r2 = r2;
588 return;
589 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300590
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100591 /*
592 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
593 * freq2k.
594 *
595 * delta = 1e6 *
596 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
597 * freq2k;
598 *
599 * and we would like delta <= budget.
600 *
601 * If the discrepancy is above the PPM-based budget, always prefer to
602 * improve upon the previous solution. However, if you're within the
603 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
604 */
605 a = freq2k * budget * p * r2;
606 b = freq2k * budget * best->p * best->r2;
607 diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
608 diff_best = ABS_DIFF((freq2k * best->p * best->r2),
609 (LC_FREQ_2K * best->n2));
610 c = 1000000 * diff;
611 d = 1000000 * diff_best;
612
613 if (a < c && b < d) {
614 /* If both are above the budget, pick the closer */
615 if (best->p * best->r2 * diff < p * r2 * diff_best) {
616 best->p = p;
617 best->n2 = n2;
618 best->r2 = r2;
619 }
620 } else if (a >= c && b < d) {
621 /* If A is below the threshold but B is above it? Update. */
622 best->p = p;
623 best->n2 = n2;
624 best->r2 = r2;
625 } else if (a >= c && b >= d) {
626 /* Both are below the limit, so pick the higher n2/(r2*r2) */
627 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
628 best->p = p;
629 best->n2 = n2;
630 best->r2 = r2;
631 }
632 }
633 /* Otherwise a < c && b >= d, do nothing */
634}
635
Jesse Barnes11578552014-01-21 12:42:10 -0800636static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
637 int reg)
638{
639 int refclk = LC_FREQ;
640 int n, p, r;
641 u32 wrpll;
642
643 wrpll = I915_READ(reg);
644 switch (wrpll & SPLL_PLL_REF_MASK) {
645 case SPLL_PLL_SSC:
646 case SPLL_PLL_NON_SSC:
647 /*
648 * We could calculate spread here, but our checking
649 * code only cares about 5% accuracy, and spread is a max of
650 * 0.5% downspread.
651 */
652 refclk = 135;
653 break;
654 case SPLL_PLL_LCPLL:
655 refclk = LC_FREQ;
656 break;
657 default:
658 WARN(1, "bad wrpll refclk\n");
659 return 0;
660 }
661
662 r = wrpll & WRPLL_DIVIDER_REF_MASK;
663 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
664 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
665
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800666 /* Convert to KHz, p & r have a fixed point portion */
667 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800668}
669
670static void intel_ddi_clock_get(struct intel_encoder *encoder,
671 struct intel_crtc_config *pipe_config)
672{
673 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
674 enum port port = intel_ddi_get_encoder_port(encoder);
675 int link_clock = 0;
676 u32 val, pll;
677
678 val = I915_READ(PORT_CLK_SEL(port));
679 switch (val & PORT_CLK_SEL_MASK) {
680 case PORT_CLK_SEL_LCPLL_810:
681 link_clock = 81000;
682 break;
683 case PORT_CLK_SEL_LCPLL_1350:
684 link_clock = 135000;
685 break;
686 case PORT_CLK_SEL_LCPLL_2700:
687 link_clock = 270000;
688 break;
689 case PORT_CLK_SEL_WRPLL1:
690 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
691 break;
692 case PORT_CLK_SEL_WRPLL2:
693 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
694 break;
695 case PORT_CLK_SEL_SPLL:
696 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
697 if (pll == SPLL_PLL_FREQ_810MHz)
698 link_clock = 81000;
699 else if (pll == SPLL_PLL_FREQ_1350MHz)
700 link_clock = 135000;
701 else if (pll == SPLL_PLL_FREQ_2700MHz)
702 link_clock = 270000;
703 else {
704 WARN(1, "bad spll freq\n");
705 return;
706 }
707 break;
708 default:
709 WARN(1, "bad port clock sel\n");
710 return;
711 }
712
713 pipe_config->port_clock = link_clock * 2;
714
715 if (pipe_config->has_pch_encoder)
716 pipe_config->adjusted_mode.crtc_clock =
717 intel_dotclock_calculate(pipe_config->port_clock,
718 &pipe_config->fdi_m_n);
719 else if (pipe_config->has_dp_encoder)
720 pipe_config->adjusted_mode.crtc_clock =
721 intel_dotclock_calculate(pipe_config->port_clock,
722 &pipe_config->dp_m_n);
723 else
724 pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
725}
726
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100727static void
728intel_ddi_calculate_wrpll(int clock /* in Hz */,
729 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
730{
731 uint64_t freq2k;
732 unsigned p, n2, r2;
733 struct wrpll_rnp best = { 0, 0, 0 };
734 unsigned budget;
735
736 freq2k = clock / 100;
737
738 budget = wrpll_get_budget_for_freq(clock);
739
740 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
741 * and directly pass the LC PLL to it. */
742 if (freq2k == 5400000) {
743 *n2_out = 2;
744 *p_out = 1;
745 *r2_out = 2;
746 return;
747 }
748
749 /*
750 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
751 * the WR PLL.
752 *
753 * We want R so that REF_MIN <= Ref <= REF_MAX.
754 * Injecting R2 = 2 * R gives:
755 * REF_MAX * r2 > LC_FREQ * 2 and
756 * REF_MIN * r2 < LC_FREQ * 2
757 *
758 * Which means the desired boundaries for r2 are:
759 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
760 *
761 */
762 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
763 r2 <= LC_FREQ * 2 / REF_MIN;
764 r2++) {
765
766 /*
767 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
768 *
769 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
770 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
771 * VCO_MAX * r2 > n2 * LC_FREQ and
772 * VCO_MIN * r2 < n2 * LC_FREQ)
773 *
774 * Which means the desired boundaries for n2 are:
775 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
776 */
777 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
778 n2 <= VCO_MAX * r2 / LC_FREQ;
779 n2++) {
780
781 for (p = P_MIN; p <= P_MAX; p += P_INC)
782 wrpll_update_rnp(freq2k, budget,
783 r2, n2, p, &best);
784 }
785 }
786
787 *n2_out = best.n2;
788 *p_out = best.p;
789 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300790}
791
Paulo Zanoni566b7342013-11-25 15:27:08 -0200792/*
793 * Tries to find a PLL for the CRTC. If it finds, it increases the refcount and
794 * stores it in intel_crtc->ddi_pll_sel, so other mode sets won't be able to
795 * steal the selected PLL. You need to call intel_ddi_pll_enable to actually
796 * enable the PLL.
797 */
798bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300799{
Paulo Zanoni566b7342013-11-25 15:27:08 -0200800 struct drm_crtc *crtc = &intel_crtc->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300801 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni068759b2012-10-15 15:51:31 -0300802 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300803 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
804 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
805 int type = intel_encoder->type;
806 enum pipe pipe = intel_crtc->pipe;
Daniel Vetterff9a6752013-06-01 17:16:21 +0200807 int clock = intel_crtc->config.port_clock;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300808
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300809 intel_ddi_put_crtc_pll(crtc);
810
Paulo Zanoni068759b2012-10-15 15:51:31 -0300811 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
812 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
813
814 switch (intel_dp->link_bw) {
815 case DP_LINK_BW_1_62:
816 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
817 break;
818 case DP_LINK_BW_2_7:
819 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
820 break;
821 case DP_LINK_BW_5_4:
822 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
823 break;
824 default:
825 DRM_ERROR("Link bandwidth %d unsupported\n",
826 intel_dp->link_bw);
827 return false;
828 }
829
Paulo Zanoni068759b2012-10-15 15:51:31 -0300830 } else if (type == INTEL_OUTPUT_HDMI) {
Paulo Zanoni566b7342013-11-25 15:27:08 -0200831 uint32_t reg, val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100832 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300833
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100834 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300835
836 val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
837 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
838 WRPLL_DIVIDER_POST(p);
839
Paulo Zanoni06940012013-10-30 18:27:43 -0200840 if (val == I915_READ(WRPLL_CTL1)) {
841 DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n",
842 pipe_name(pipe));
843 reg = WRPLL_CTL1;
844 } else if (val == I915_READ(WRPLL_CTL2)) {
845 DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n",
846 pipe_name(pipe));
847 reg = WRPLL_CTL2;
848 } else if (plls->wrpll1_refcount == 0) {
849 DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
850 pipe_name(pipe));
851 reg = WRPLL_CTL1;
852 } else if (plls->wrpll2_refcount == 0) {
853 DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
854 pipe_name(pipe));
855 reg = WRPLL_CTL2;
856 } else {
857 DRM_ERROR("No WRPLLs available!\n");
858 return false;
859 }
860
Paulo Zanoni566b7342013-11-25 15:27:08 -0200861 DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
862 clock, p, n2, r2);
863
Paulo Zanoni06940012013-10-30 18:27:43 -0200864 if (reg == WRPLL_CTL1) {
865 plls->wrpll1_refcount++;
866 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
867 } else {
868 plls->wrpll2_refcount++;
869 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
870 }
871
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300872 } else if (type == INTEL_OUTPUT_ANALOG) {
873 if (plls->spll_refcount == 0) {
874 DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
875 pipe_name(pipe));
876 plls->spll_refcount++;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300877 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
Damien Lespiau00037c22013-03-07 15:30:25 +0000878 } else {
879 DRM_ERROR("SPLL already in use\n");
880 return false;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300881 }
882
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300883 } else {
884 WARN(1, "Invalid DDI encoder type %d\n", type);
885 return false;
886 }
887
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300888 return true;
889}
890
Paulo Zanoni566b7342013-11-25 15:27:08 -0200891/*
892 * To be called after intel_ddi_pll_select(). That one selects the PLL to be
893 * used, this one actually enables the PLL.
894 */
895void intel_ddi_pll_enable(struct intel_crtc *crtc)
896{
897 struct drm_device *dev = crtc->base.dev;
898 struct drm_i915_private *dev_priv = dev->dev_private;
899 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
900 int clock = crtc->config.port_clock;
901 uint32_t reg, cur_val, new_val;
902 int refcount;
903 const char *pll_name;
904 uint32_t enable_bit = (1 << 31);
905 unsigned int p, n2, r2;
906
907 BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE);
908 BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE);
909
910 switch (crtc->ddi_pll_sel) {
911 case PORT_CLK_SEL_LCPLL_2700:
912 case PORT_CLK_SEL_LCPLL_1350:
913 case PORT_CLK_SEL_LCPLL_810:
914 /*
915 * LCPLL should always be enabled at this point of the mode set
916 * sequence, so nothing to do.
917 */
918 return;
919
920 case PORT_CLK_SEL_SPLL:
921 pll_name = "SPLL";
922 reg = SPLL_CTL;
923 refcount = plls->spll_refcount;
924 new_val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz |
925 SPLL_PLL_SSC;
926 break;
927
928 case PORT_CLK_SEL_WRPLL1:
929 case PORT_CLK_SEL_WRPLL2:
930 if (crtc->ddi_pll_sel == PORT_CLK_SEL_WRPLL1) {
931 pll_name = "WRPLL1";
932 reg = WRPLL_CTL1;
933 refcount = plls->wrpll1_refcount;
934 } else {
935 pll_name = "WRPLL2";
936 reg = WRPLL_CTL2;
937 refcount = plls->wrpll2_refcount;
938 }
939
940 intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
941
942 new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
943 WRPLL_DIVIDER_REFERENCE(r2) |
944 WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p);
945
946 break;
947
948 case PORT_CLK_SEL_NONE:
949 WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n");
950 return;
951 default:
952 WARN(1, "Bad selected pll: 0x%08x\n", crtc->ddi_pll_sel);
953 return;
954 }
955
956 cur_val = I915_READ(reg);
957
958 WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount);
959 if (refcount == 1) {
960 WARN(cur_val & enable_bit, "%s already enabled\n", pll_name);
961 I915_WRITE(reg, new_val);
962 POSTING_READ(reg);
963 udelay(20);
964 } else {
965 WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name);
966 }
967}
968
Paulo Zanonidae84792012-10-15 15:51:30 -0300969void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
970{
971 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
972 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
973 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200974 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300975 int type = intel_encoder->type;
976 uint32_t temp;
977
978 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
979
Paulo Zanonic9809792012-10-23 18:30:00 -0200980 temp = TRANS_MSA_SYNC_CLK;
Daniel Vetter965e0c42013-03-27 00:44:57 +0100981 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -0300982 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200983 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300984 break;
985 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200986 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300987 break;
988 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200989 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300990 break;
991 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200992 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300993 break;
994 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100995 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -0300996 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200997 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300998 }
999}
1000
Damien Lespiau8228c252013-03-07 15:30:27 +00001001void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001002{
1003 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1004 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001005 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -07001006 struct drm_device *dev = crtc->dev;
1007 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001008 enum pipe pipe = intel_crtc->pipe;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001009 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001010 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001011 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001012 uint32_t temp;
1013
Paulo Zanoniad80a812012-10-24 16:06:19 -02001014 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1015 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001016 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001017
Daniel Vetter965e0c42013-03-27 00:44:57 +01001018 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001019 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001020 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001021 break;
1022 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001023 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001024 break;
1025 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001026 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001027 break;
1028 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001029 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001030 break;
1031 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001032 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001033 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001034
Ville Syrjäläa6662832013-09-10 17:03:41 +03001035 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001036 temp |= TRANS_DDI_PVSYNC;
Ville Syrjäläa6662832013-09-10 17:03:41 +03001037 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001038 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -03001039
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001040 if (cpu_transcoder == TRANSCODER_EDP) {
1041 switch (pipe) {
1042 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001043 /* On Haswell, can only use the always-on power well for
1044 * eDP when not using the panel fitter, and when not
1045 * using motion blur mitigation (which we don't
1046 * support). */
1047 if (IS_HASWELL(dev) && intel_crtc->config.pch_pfit.enabled)
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001048 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1049 else
1050 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001051 break;
1052 case PIPE_B:
1053 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1054 break;
1055 case PIPE_C:
1056 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1057 break;
1058 default:
1059 BUG();
1060 break;
1061 }
1062 }
1063
Paulo Zanoni7739c332012-10-15 15:51:29 -03001064 if (type == INTEL_OUTPUT_HDMI) {
1065 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001066
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001067 if (intel_hdmi->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001068 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001069 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001070 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001071
Paulo Zanoni7739c332012-10-15 15:51:29 -03001072 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001073 temp |= TRANS_DDI_MODE_SELECT_FDI;
Daniel Vetter33d29b12013-02-13 18:04:45 +01001074 temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001075
1076 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
1077 type == INTEL_OUTPUT_EDP) {
1078 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1079
Paulo Zanoniad80a812012-10-24 16:06:19 -02001080 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001081
Daniel Vetter17aa6be2013-04-30 14:01:40 +02001082 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001083 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001084 WARN(1, "Invalid encoder type %d for pipe %c\n",
1085 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001086 }
1087
Paulo Zanoniad80a812012-10-24 16:06:19 -02001088 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001089}
1090
Paulo Zanoniad80a812012-10-24 16:06:19 -02001091void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1092 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001093{
Paulo Zanoniad80a812012-10-24 16:06:19 -02001094 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001095 uint32_t val = I915_READ(reg);
1096
Paulo Zanoniad80a812012-10-24 16:06:19 -02001097 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
1098 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001099 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001100}
1101
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001102bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1103{
1104 struct drm_device *dev = intel_connector->base.dev;
1105 struct drm_i915_private *dev_priv = dev->dev_private;
1106 struct intel_encoder *intel_encoder = intel_connector->encoder;
1107 int type = intel_connector->base.connector_type;
1108 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1109 enum pipe pipe = 0;
1110 enum transcoder cpu_transcoder;
1111 uint32_t tmp;
1112
1113 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
1114 return false;
1115
1116 if (port == PORT_A)
1117 cpu_transcoder = TRANSCODER_EDP;
1118 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001119 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001120
1121 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1122
1123 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1124 case TRANS_DDI_MODE_SELECT_HDMI:
1125 case TRANS_DDI_MODE_SELECT_DVI:
1126 return (type == DRM_MODE_CONNECTOR_HDMIA);
1127
1128 case TRANS_DDI_MODE_SELECT_DP_SST:
1129 if (type == DRM_MODE_CONNECTOR_eDP)
1130 return true;
1131 case TRANS_DDI_MODE_SELECT_DP_MST:
1132 return (type == DRM_MODE_CONNECTOR_DisplayPort);
1133
1134 case TRANS_DDI_MODE_SELECT_FDI:
1135 return (type == DRM_MODE_CONNECTOR_VGA);
1136
1137 default:
1138 return false;
1139 }
1140}
1141
Daniel Vetter85234cd2012-07-02 13:27:29 +02001142bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1143 enum pipe *pipe)
1144{
1145 struct drm_device *dev = encoder->base.dev;
1146 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001147 enum port port = intel_ddi_get_encoder_port(encoder);
Daniel Vetter85234cd2012-07-02 13:27:29 +02001148 u32 tmp;
1149 int i;
1150
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001151 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001152
1153 if (!(tmp & DDI_BUF_CTL_ENABLE))
1154 return false;
1155
Paulo Zanoniad80a812012-10-24 16:06:19 -02001156 if (port == PORT_A) {
1157 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001158
Paulo Zanoniad80a812012-10-24 16:06:19 -02001159 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1160 case TRANS_DDI_EDP_INPUT_A_ON:
1161 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1162 *pipe = PIPE_A;
1163 break;
1164 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1165 *pipe = PIPE_B;
1166 break;
1167 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1168 *pipe = PIPE_C;
1169 break;
1170 }
1171
1172 return true;
1173 } else {
1174 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1175 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1176
1177 if ((tmp & TRANS_DDI_PORT_MASK)
1178 == TRANS_DDI_SELECT_PORT(port)) {
1179 *pipe = i;
1180 return true;
1181 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001182 }
1183 }
1184
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001185 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001186
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001187 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001188}
1189
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001190static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
1191 enum pipe pipe)
1192{
1193 uint32_t temp, ret;
Damien Lespiaua42f7042013-03-25 15:16:14 +00001194 enum port port = I915_MAX_PORTS;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001195 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1196 pipe);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001197 int i;
1198
Paulo Zanoniad80a812012-10-24 16:06:19 -02001199 if (cpu_transcoder == TRANSCODER_EDP) {
1200 port = PORT_A;
1201 } else {
1202 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1203 temp &= TRANS_DDI_PORT_MASK;
1204
1205 for (i = PORT_B; i <= PORT_E; i++)
1206 if (temp == TRANS_DDI_SELECT_PORT(i))
1207 port = i;
1208 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001209
Damien Lespiaua42f7042013-03-25 15:16:14 +00001210 if (port == I915_MAX_PORTS) {
1211 WARN(1, "Pipe %c enabled on an unknown port\n",
1212 pipe_name(pipe));
1213 ret = PORT_CLK_SEL_NONE;
1214 } else {
1215 ret = I915_READ(PORT_CLK_SEL(port));
1216 DRM_DEBUG_KMS("Pipe %c connected to port %c using clock "
1217 "0x%08x\n", pipe_name(pipe), port_name(port),
1218 ret);
1219 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001220
1221 return ret;
1222}
1223
1224void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
1225{
1226 struct drm_i915_private *dev_priv = dev->dev_private;
1227 enum pipe pipe;
1228 struct intel_crtc *intel_crtc;
1229
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001230 dev_priv->ddi_plls.spll_refcount = 0;
1231 dev_priv->ddi_plls.wrpll1_refcount = 0;
1232 dev_priv->ddi_plls.wrpll2_refcount = 0;
1233
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001234 for_each_pipe(pipe) {
1235 intel_crtc =
1236 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1237
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001238 if (!intel_crtc->active) {
1239 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001240 continue;
Paulo Zanoni0882dae2014-01-08 11:12:27 -02001241 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001242
1243 intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
1244 pipe);
1245
1246 switch (intel_crtc->ddi_pll_sel) {
1247 case PORT_CLK_SEL_SPLL:
1248 dev_priv->ddi_plls.spll_refcount++;
1249 break;
1250 case PORT_CLK_SEL_WRPLL1:
1251 dev_priv->ddi_plls.wrpll1_refcount++;
1252 break;
1253 case PORT_CLK_SEL_WRPLL2:
1254 dev_priv->ddi_plls.wrpll2_refcount++;
1255 break;
1256 }
1257 }
1258}
1259
Paulo Zanonifc914632012-10-05 12:05:54 -03001260void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1261{
1262 struct drm_crtc *crtc = &intel_crtc->base;
1263 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1264 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1265 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +02001266 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001267
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001268 if (cpu_transcoder != TRANSCODER_EDP)
1269 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1270 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001271}
1272
1273void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1274{
1275 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001276 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001277
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001278 if (cpu_transcoder != TRANSCODER_EDP)
1279 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1280 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001281}
1282
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001283static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001284{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001285 struct drm_encoder *encoder = &intel_encoder->base;
1286 struct drm_crtc *crtc = encoder->crtc;
1287 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001288 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1289 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001290 int type = intel_encoder->type;
1291
1292 if (type == INTEL_OUTPUT_EDP) {
1293 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001294 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001295 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001296
1297 WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001298 I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001299
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001300 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001301 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1302
1303 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1304 intel_dp_start_link_train(intel_dp);
1305 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001306 if (port != PORT_A)
1307 intel_dp_stop_link_train(intel_dp);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001308 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001309}
1310
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001311static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001312{
1313 struct drm_encoder *encoder = &intel_encoder->base;
1314 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1315 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001316 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001317 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001318 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001319
1320 val = I915_READ(DDI_BUF_CTL(port));
1321 if (val & DDI_BUF_CTL_ENABLE) {
1322 val &= ~DDI_BUF_CTL_ENABLE;
1323 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001324 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001325 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001326
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001327 val = I915_READ(DP_TP_CTL(port));
1328 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1329 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1330 I915_WRITE(DP_TP_CTL(port), val);
1331
1332 if (wait)
1333 intel_wait_ddi_buf_idle(dev_priv, port);
1334
Jani Nikula76bb80e2013-11-15 15:29:57 +02001335 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001336 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001337 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Daniel Vetter4be73782014-01-17 14:39:48 +01001338 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001339 }
1340
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001341 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1342}
1343
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001344static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001345{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001346 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001347 struct drm_crtc *crtc = encoder->crtc;
1348 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1349 int pipe = intel_crtc->pipe;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001350 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001351 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001352 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1353 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001354 uint32_t tmp;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001355
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001356 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001357 struct intel_digital_port *intel_dig_port =
1358 enc_to_dig_port(encoder);
1359
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001360 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1361 * are ignored so nothing special needs to be done besides
1362 * enabling the port.
1363 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001364 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001365 intel_dig_port->saved_port_bits |
1366 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001367 } else if (type == INTEL_OUTPUT_EDP) {
1368 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1369
Imre Deak3ab9c632013-05-03 12:57:41 +03001370 if (port == PORT_A)
1371 intel_dp_stop_link_train(intel_dp);
1372
Daniel Vetter4be73782014-01-17 14:39:48 +01001373 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi49065572013-07-11 18:45:05 -03001374 intel_edp_psr_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001375 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001376
Paulo Zanonic77bf562013-05-03 12:15:40 -03001377 if (intel_crtc->eld_vld && type != INTEL_OUTPUT_EDP) {
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001378 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1379 tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1380 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1381 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001382}
1383
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001384static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001385{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001386 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001387 struct drm_crtc *crtc = encoder->crtc;
1388 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1389 int pipe = intel_crtc->pipe;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001390 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001391 struct drm_device *dev = encoder->dev;
1392 struct drm_i915_private *dev_priv = dev->dev_private;
1393 uint32_t tmp;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001394
Paulo Zanonic77bf562013-05-03 12:15:40 -03001395 if (intel_crtc->eld_vld && type != INTEL_OUTPUT_EDP) {
1396 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1397 tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1398 (pipe * 4));
1399 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1400 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001401
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001402 if (type == INTEL_OUTPUT_EDP) {
1403 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1404
Rodrigo Vivi49065572013-07-11 18:45:05 -03001405 intel_edp_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001406 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001407 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001408}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001409
Paulo Zanonib8fc2f62012-10-23 18:30:05 -02001410int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001411{
Paulo Zanonie39bf982013-11-02 21:07:36 -07001412 struct drm_device *dev = dev_priv->dev;
Paulo Zanonia4006642013-08-06 18:57:11 -03001413 uint32_t lcpll = I915_READ(LCPLL_CTL);
Paulo Zanonie39bf982013-11-02 21:07:36 -07001414 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Paulo Zanonia4006642013-08-06 18:57:11 -03001415
Paulo Zanonie39bf982013-11-02 21:07:36 -07001416 if (lcpll & LCPLL_CD_SOURCE_FCLK) {
Paulo Zanonia4006642013-08-06 18:57:11 -03001417 return 800000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001418 } else if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001419 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001420 } else if (freq == LCPLL_CLK_FREQ_450) {
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001421 return 450000;
Paulo Zanonie39bf982013-11-02 21:07:36 -07001422 } else if (IS_HASWELL(dev)) {
1423 if (IS_ULT(dev))
1424 return 337500;
1425 else
1426 return 540000;
1427 } else {
1428 if (freq == LCPLL_CLK_FREQ_54O_BDW)
1429 return 540000;
1430 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
1431 return 337500;
1432 else
1433 return 675000;
1434 }
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001435}
1436
1437void intel_ddi_pll_init(struct drm_device *dev)
1438{
1439 struct drm_i915_private *dev_priv = dev->dev_private;
1440 uint32_t val = I915_READ(LCPLL_CTL);
1441
1442 /* The LCPLL register should be turned on by the BIOS. For now let's
1443 * just check its state and print errors in case something is wrong.
1444 * Don't even try to turn it on.
1445 */
1446
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001447 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001448 intel_ddi_get_cdclk_freq(dev_priv));
1449
1450 if (val & LCPLL_CD_SOURCE_FCLK)
1451 DRM_ERROR("CDCLK source is not LCPLL\n");
1452
1453 if (val & LCPLL_PLL_DISABLE)
1454 DRM_ERROR("LCPLL is disabled\n");
1455}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001456
1457void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1458{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001459 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1460 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001461 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001462 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001463 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301464 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001465
1466 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1467 val = I915_READ(DDI_BUF_CTL(port));
1468 if (val & DDI_BUF_CTL_ENABLE) {
1469 val &= ~DDI_BUF_CTL_ENABLE;
1470 I915_WRITE(DDI_BUF_CTL(port), val);
1471 wait = true;
1472 }
1473
1474 val = I915_READ(DP_TP_CTL(port));
1475 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1476 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1477 I915_WRITE(DP_TP_CTL(port), val);
1478 POSTING_READ(DP_TP_CTL(port));
1479
1480 if (wait)
1481 intel_wait_ddi_buf_idle(dev_priv, port);
1482 }
1483
1484 val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
1485 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Jani Nikula6aba5b62013-10-04 15:08:10 +03001486 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
Paulo Zanonic19b0662012-10-15 15:51:41 -03001487 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1488 I915_WRITE(DP_TP_CTL(port), val);
1489 POSTING_READ(DP_TP_CTL(port));
1490
1491 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1492 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1493 POSTING_READ(DDI_BUF_CTL(port));
1494
1495 udelay(600);
1496}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001497
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001498void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1499{
1500 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1501 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1502 uint32_t val;
1503
1504 intel_ddi_post_disable(intel_encoder);
1505
1506 val = I915_READ(_FDI_RXA_CTL);
1507 val &= ~FDI_RX_ENABLE;
1508 I915_WRITE(_FDI_RXA_CTL, val);
1509
1510 val = I915_READ(_FDI_RXA_MISC);
1511 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1512 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1513 I915_WRITE(_FDI_RXA_MISC, val);
1514
1515 val = I915_READ(_FDI_RXA_CTL);
1516 val &= ~FDI_PCDCLK;
1517 I915_WRITE(_FDI_RXA_CTL, val);
1518
1519 val = I915_READ(_FDI_RXA_CTL);
1520 val &= ~FDI_RX_PLL_ENABLE;
1521 I915_WRITE(_FDI_RXA_CTL, val);
1522}
1523
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001524static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1525{
1526 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
1527 int type = intel_encoder->type;
1528
1529 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
1530 intel_dp_check_link_status(intel_dp);
1531}
1532
Ville Syrjälä6801c182013-09-24 14:24:05 +03001533void intel_ddi_get_config(struct intel_encoder *encoder,
1534 struct intel_crtc_config *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001535{
1536 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1537 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1538 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
1539 u32 temp, flags = 0;
1540
1541 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1542 if (temp & TRANS_DDI_PHSYNC)
1543 flags |= DRM_MODE_FLAG_PHSYNC;
1544 else
1545 flags |= DRM_MODE_FLAG_NHSYNC;
1546 if (temp & TRANS_DDI_PVSYNC)
1547 flags |= DRM_MODE_FLAG_PVSYNC;
1548 else
1549 flags |= DRM_MODE_FLAG_NVSYNC;
1550
1551 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001552
1553 switch (temp & TRANS_DDI_BPC_MASK) {
1554 case TRANS_DDI_BPC_6:
1555 pipe_config->pipe_bpp = 18;
1556 break;
1557 case TRANS_DDI_BPC_8:
1558 pipe_config->pipe_bpp = 24;
1559 break;
1560 case TRANS_DDI_BPC_10:
1561 pipe_config->pipe_bpp = 30;
1562 break;
1563 case TRANS_DDI_BPC_12:
1564 pipe_config->pipe_bpp = 36;
1565 break;
1566 default:
1567 break;
1568 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001569
1570 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1571 case TRANS_DDI_MODE_SELECT_HDMI:
1572 case TRANS_DDI_MODE_SELECT_DVI:
1573 case TRANS_DDI_MODE_SELECT_FDI:
1574 break;
1575 case TRANS_DDI_MODE_SELECT_DP_SST:
1576 case TRANS_DDI_MODE_SELECT_DP_MST:
1577 pipe_config->has_dp_encoder = true;
1578 intel_dp_get_m_n(intel_crtc, pipe_config);
1579 break;
1580 default:
1581 break;
1582 }
Daniel Vetter10214422013-11-18 07:38:16 +01001583
1584 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1585 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1586 /*
1587 * This is a big fat ugly hack.
1588 *
1589 * Some machines in UEFI boot mode provide us a VBT that has 18
1590 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1591 * unknown we fail to light up. Yet the same BIOS boots up with
1592 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1593 * max, not what it tells us to use.
1594 *
1595 * Note: This will still be broken if the eDP panel is not lit
1596 * up by the BIOS, and thus we can't get the mode at module
1597 * load.
1598 */
1599 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1600 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1601 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1602 }
Jesse Barnes11578552014-01-21 12:42:10 -08001603
1604 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001605}
1606
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001607static void intel_ddi_destroy(struct drm_encoder *encoder)
1608{
1609 /* HDMI has nothing special to destroy, so we can go with this. */
1610 intel_dp_encoder_destroy(encoder);
1611}
1612
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001613static bool intel_ddi_compute_config(struct intel_encoder *encoder,
1614 struct intel_crtc_config *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001615{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001616 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02001617 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001618
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001619 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001620
Daniel Vettereccb1402013-05-22 00:50:22 +02001621 if (port == PORT_A)
1622 pipe_config->cpu_transcoder = TRANSCODER_EDP;
1623
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001624 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001625 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001626 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001627 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001628}
1629
1630static const struct drm_encoder_funcs intel_ddi_funcs = {
1631 .destroy = intel_ddi_destroy,
1632};
1633
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001634static struct intel_connector *
1635intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
1636{
1637 struct intel_connector *connector;
1638 enum port port = intel_dig_port->port;
1639
1640 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1641 if (!connector)
1642 return NULL;
1643
1644 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1645 if (!intel_dp_init_connector(intel_dig_port, connector)) {
1646 kfree(connector);
1647 return NULL;
1648 }
1649
1650 return connector;
1651}
1652
1653static struct intel_connector *
1654intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
1655{
1656 struct intel_connector *connector;
1657 enum port port = intel_dig_port->port;
1658
1659 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1660 if (!connector)
1661 return NULL;
1662
1663 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
1664 intel_hdmi_init_connector(intel_dig_port, connector);
1665
1666 return connector;
1667}
1668
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001669void intel_ddi_init(struct drm_device *dev, enum port port)
1670{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001671 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001672 struct intel_digital_port *intel_dig_port;
1673 struct intel_encoder *intel_encoder;
1674 struct drm_encoder *encoder;
1675 struct intel_connector *hdmi_connector = NULL;
1676 struct intel_connector *dp_connector = NULL;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001677 bool init_hdmi, init_dp;
1678
1679 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1680 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1681 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1682 if (!init_dp && !init_hdmi) {
1683 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n",
1684 port_name(port));
1685 init_hdmi = true;
1686 init_dp = true;
1687 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001688
Daniel Vetterb14c5672013-09-19 12:18:32 +02001689 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001690 if (!intel_dig_port)
1691 return;
1692
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001693 intel_encoder = &intel_dig_port->base;
1694 encoder = &intel_encoder->base;
1695
1696 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1697 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001698
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001699 intel_encoder->compute_config = intel_ddi_compute_config;
Daniel Vetterc7d8be32013-07-21 21:37:07 +02001700 intel_encoder->mode_set = intel_ddi_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001701 intel_encoder->enable = intel_enable_ddi;
1702 intel_encoder->pre_enable = intel_ddi_pre_enable;
1703 intel_encoder->disable = intel_disable_ddi;
1704 intel_encoder->post_disable = intel_ddi_post_disable;
1705 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001706 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001707
1708 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001709 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
1710 (DDI_BUF_PORT_REVERSAL |
1711 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001712
1713 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
1714 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1715 intel_encoder->cloneable = false;
1716 intel_encoder->hot_plug = intel_ddi_hot_plug;
1717
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001718 if (init_dp)
1719 dp_connector = intel_ddi_init_dp_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001720
Paulo Zanoni311a2092013-09-12 17:12:18 -03001721 /* In theory we don't need the encoder->type check, but leave it just in
1722 * case we have some really bad VBTs... */
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001723 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi)
1724 hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001725
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001726 if (!dp_connector && !hdmi_connector) {
1727 drm_encoder_cleanup(encoder);
1728 kfree(intel_dig_port);
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001729 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001730}