blob: b63d4fa204a32b540529b9e49d72cb7108839190 [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
Jani Nikula10122052014-08-27 16:27:30 +030031struct ddi_buf_trans {
32 u32 trans1; /* balance leg enable, de-emph level */
33 u32 trans2; /* vref sel, vswing */
34};
35
Eugeni Dodonov45244b82012-05-09 15:37:20 -030036/* HDMI/DVI modes ignore everything but the last 2 items. So we share
37 * them for both DP and FDI transports, allowing those ports to
38 * automatically adapt to HDMI connections as well
39 */
Jani Nikula10122052014-08-27 16:27:30 +030040static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
41 { 0x00FFFFFF, 0x0006000E },
42 { 0x00D75FFF, 0x0005000A },
43 { 0x00C30FFF, 0x00040006 },
44 { 0x80AAAFFF, 0x000B0000 },
45 { 0x00FFFFFF, 0x0005000A },
46 { 0x00D75FFF, 0x000C0004 },
47 { 0x80C30FFF, 0x000B0000 },
48 { 0x00FFFFFF, 0x00040006 },
49 { 0x80D75FFF, 0x000B0000 },
Eugeni Dodonov45244b82012-05-09 15:37:20 -030050};
51
Jani Nikula10122052014-08-27 16:27:30 +030052static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
53 { 0x00FFFFFF, 0x0007000E },
54 { 0x00D75FFF, 0x000F000A },
55 { 0x00C30FFF, 0x00060006 },
56 { 0x00AAAFFF, 0x001E0000 },
57 { 0x00FFFFFF, 0x000F000A },
58 { 0x00D75FFF, 0x00160004 },
59 { 0x00C30FFF, 0x001E0000 },
60 { 0x00FFFFFF, 0x00060006 },
61 { 0x00D75FFF, 0x001E0000 },
Paulo Zanoni6acab152013-09-12 17:06:24 -030062};
63
Jani Nikula10122052014-08-27 16:27:30 +030064static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
65 /* Idx NT mV d T mV d db */
66 { 0x00FFFFFF, 0x0006000E }, /* 0: 400 400 0 */
67 { 0x00E79FFF, 0x000E000C }, /* 1: 400 500 2 */
68 { 0x00D75FFF, 0x0005000A }, /* 2: 400 600 3.5 */
69 { 0x00FFFFFF, 0x0005000A }, /* 3: 600 600 0 */
70 { 0x00E79FFF, 0x001D0007 }, /* 4: 600 750 2 */
71 { 0x00D75FFF, 0x000C0004 }, /* 5: 600 900 3.5 */
72 { 0x00FFFFFF, 0x00040006 }, /* 6: 800 800 0 */
73 { 0x80E79FFF, 0x00030002 }, /* 7: 800 1000 2 */
74 { 0x00FFFFFF, 0x00140005 }, /* 8: 850 850 0 */
75 { 0x00FFFFFF, 0x000C0004 }, /* 9: 900 900 0 */
76 { 0x00FFFFFF, 0x001C0003 }, /* 10: 950 950 0 */
77 { 0x80FFFFFF, 0x00030002 }, /* 11: 1000 1000 0 */
Eugeni Dodonov45244b82012-05-09 15:37:20 -030078};
79
Jani Nikula10122052014-08-27 16:27:30 +030080static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
81 { 0x00FFFFFF, 0x00000012 },
82 { 0x00EBAFFF, 0x00020011 },
83 { 0x00C71FFF, 0x0006000F },
84 { 0x00AAAFFF, 0x000E000A },
85 { 0x00FFFFFF, 0x00020011 },
86 { 0x00DB6FFF, 0x0005000F },
87 { 0x00BEEFFF, 0x000A000C },
88 { 0x00FFFFFF, 0x0005000F },
89 { 0x00DB6FFF, 0x000A000C },
Paulo Zanoni300644c2013-11-02 21:07:42 -070090};
91
Jani Nikula10122052014-08-27 16:27:30 +030092static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
93 { 0x00FFFFFF, 0x0007000E },
94 { 0x00D75FFF, 0x000E000A },
95 { 0x00BEFFFF, 0x00140006 },
96 { 0x80B2CFFF, 0x001B0002 },
97 { 0x00FFFFFF, 0x000E000A },
98 { 0x00D75FFF, 0x00180004 },
99 { 0x80CB2FFF, 0x001B0002 },
100 { 0x00F7DFFF, 0x00180004 },
101 { 0x80D75FFF, 0x001B0002 },
Art Runyane58623c2013-11-02 21:07:41 -0700102};
103
Jani Nikula10122052014-08-27 16:27:30 +0300104static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
105 { 0x00FFFFFF, 0x0001000E },
106 { 0x00D75FFF, 0x0004000A },
107 { 0x00C30FFF, 0x00070006 },
108 { 0x00AAAFFF, 0x000C0000 },
109 { 0x00FFFFFF, 0x0004000A },
110 { 0x00D75FFF, 0x00090004 },
111 { 0x00C30FFF, 0x000C0000 },
112 { 0x00FFFFFF, 0x00070006 },
113 { 0x00D75FFF, 0x000C0000 },
Art Runyane58623c2013-11-02 21:07:41 -0700114};
115
Jani Nikula10122052014-08-27 16:27:30 +0300116static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
117 /* Idx NT mV d T mV df db */
118 { 0x00FFFFFF, 0x0007000E }, /* 0: 400 400 0 */
119 { 0x00D75FFF, 0x000E000A }, /* 1: 400 600 3.5 */
120 { 0x00BEFFFF, 0x00140006 }, /* 2: 400 800 6 */
121 { 0x00FFFFFF, 0x0009000D }, /* 3: 450 450 0 */
122 { 0x00FFFFFF, 0x000E000A }, /* 4: 600 600 0 */
123 { 0x00D7FFFF, 0x00140006 }, /* 5: 600 800 2.5 */
124 { 0x80CB2FFF, 0x001B0002 }, /* 6: 600 1000 4.5 */
125 { 0x00FFFFFF, 0x00140006 }, /* 7: 800 800 0 */
126 { 0x80E79FFF, 0x001B0002 }, /* 8: 800 1000 2 */
127 { 0x80FFFFFF, 0x001B0002 }, /* 9: 1000 1000 0 */
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100128};
129
Jani Nikula20f4dbe2013-08-30 19:40:28 +0300130enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
Paulo Zanonifc914632012-10-05 12:05:54 -0300131{
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300132 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonifc914632012-10-05 12:05:54 -0300133 int type = intel_encoder->type;
134
Dave Airlie0e32b392014-05-02 14:02:48 +1000135 if (type == INTEL_OUTPUT_DP_MST) {
136 struct intel_digital_port *intel_dig_port = enc_to_mst(encoder)->primary;
137 return intel_dig_port->port;
138 } else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200139 type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
Paulo Zanoni174edf12012-10-26 19:05:50 -0200140 struct intel_digital_port *intel_dig_port =
141 enc_to_dig_port(encoder);
142 return intel_dig_port->port;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300143
Paulo Zanonifc914632012-10-05 12:05:54 -0300144 } else if (type == INTEL_OUTPUT_ANALOG) {
145 return PORT_E;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300146
Paulo Zanonifc914632012-10-05 12:05:54 -0300147 } else {
148 DRM_ERROR("Invalid DDI encoder type %d\n", type);
149 BUG();
150 }
151}
152
Art Runyane58623c2013-11-02 21:07:41 -0700153/*
154 * Starting with Haswell, DDI port buffers must be programmed with correct
155 * values in advance. The buffer values are different for FDI and DP modes,
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300156 * but the HDMI/DVI fields are shared among those. So we program the DDI
157 * in either FDI or DP modes only, as HDMI connections will work with both
158 * of those
159 */
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300160static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300161{
162 struct drm_i915_private *dev_priv = dev->dev_private;
163 u32 reg;
Damien Lespiauce4dd492014-08-01 11:07:54 +0100164 int i, n_hdmi_entries, hdmi_800mV_0dB;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300165 int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
Jani Nikula10122052014-08-27 16:27:30 +0300166 const struct ddi_buf_trans *ddi_translations_fdi;
167 const struct ddi_buf_trans *ddi_translations_dp;
168 const struct ddi_buf_trans *ddi_translations_edp;
169 const struct ddi_buf_trans *ddi_translations_hdmi;
170 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700171
172 if (IS_BROADWELL(dev)) {
173 ddi_translations_fdi = bdw_ddi_translations_fdi;
174 ddi_translations_dp = bdw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700175 ddi_translations_edp = bdw_ddi_translations_edp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100176 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Jani Nikula10122052014-08-27 16:27:30 +0300177 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100178 hdmi_800mV_0dB = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700179 } else if (IS_HASWELL(dev)) {
180 ddi_translations_fdi = hsw_ddi_translations_fdi;
181 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700182 ddi_translations_edp = hsw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100183 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
Jani Nikula10122052014-08-27 16:27:30 +0300184 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
Damien Lespiauce4dd492014-08-01 11:07:54 +0100185 hdmi_800mV_0dB = 6;
Art Runyane58623c2013-11-02 21:07:41 -0700186 } else {
187 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700188 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700189 ddi_translations_fdi = bdw_ddi_translations_fdi;
190 ddi_translations_dp = bdw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100191 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Jani Nikula10122052014-08-27 16:27:30 +0300192 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100193 hdmi_800mV_0dB = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700194 }
195
Paulo Zanoni300644c2013-11-02 21:07:42 -0700196 switch (port) {
197 case PORT_A:
198 ddi_translations = ddi_translations_edp;
199 break;
200 case PORT_B:
201 case PORT_C:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700202 ddi_translations = ddi_translations_dp;
203 break;
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700204 case PORT_D:
Ville Syrjälä5d8a7752013-11-01 18:22:39 +0200205 if (intel_dp_is_edp(dev, PORT_D))
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700206 ddi_translations = ddi_translations_edp;
207 else
208 ddi_translations = ddi_translations_dp;
209 break;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700210 case PORT_E:
211 ddi_translations = ddi_translations_fdi;
212 break;
213 default:
214 BUG();
215 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300216
Paulo Zanonif72d19f2013-08-05 17:25:55 -0300217 for (i = 0, reg = DDI_BUF_TRANS(port);
218 i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
Jani Nikula10122052014-08-27 16:27:30 +0300219 I915_WRITE(reg, ddi_translations[i].trans1);
220 reg += 4;
221 I915_WRITE(reg, ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300222 reg += 4;
223 }
Damien Lespiauce4dd492014-08-01 11:07:54 +0100224
225 /* Choose a good default if VBT is badly populated */
226 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
227 hdmi_level >= n_hdmi_entries)
228 hdmi_level = hdmi_800mV_0dB;
229
Paulo Zanoni6acab152013-09-12 17:06:24 -0300230 /* Entry 9 is for HDMI: */
Jani Nikula10122052014-08-27 16:27:30 +0300231 I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans1);
232 reg += 4;
233 I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans2);
234 reg += 4;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300235}
236
237/* Program DDI buffers translations for DP. By default, program ports A-D in DP
238 * mode and port E for FDI.
239 */
240void intel_prepare_ddi(struct drm_device *dev)
241{
242 int port;
243
Paulo Zanoni0d536cb2012-11-23 16:46:41 -0200244 if (!HAS_DDI(dev))
245 return;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300246
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300247 for (port = PORT_A; port <= PORT_E; port++)
248 intel_prepare_ddi_buffers(dev, port);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300249}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300250
Paulo Zanoni248138b2012-11-29 11:29:31 -0200251static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
252 enum port port)
253{
254 uint32_t reg = DDI_BUF_CTL(port);
255 int i;
256
257 for (i = 0; i < 8; i++) {
258 udelay(1);
259 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
260 return;
261 }
262 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
263}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300264
265/* Starting with Haswell, different DDI ports can work in FDI mode for
266 * connection to the PCH-located connectors. For this, it is necessary to train
267 * both the DDI port and PCH receiver for the desired DDI buffer settings.
268 *
269 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
270 * please note that when FDI mode is active on DDI E, it shares 2 lines with
271 * DDI A (which is used for eDP)
272 */
273
274void hsw_fdi_link_train(struct drm_crtc *crtc)
275{
276 struct drm_device *dev = crtc->dev;
277 struct drm_i915_private *dev_priv = dev->dev_private;
278 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni04945642012-11-01 21:00:59 -0200279 u32 temp, i, rx_ctl_val;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300280
Paulo Zanoni04945642012-11-01 21:00:59 -0200281 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
282 * mode set "sequence for CRT port" document:
283 * - TP1 to TP2 time with the default value
284 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100285 *
286 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200287 */
288 I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) |
289 FDI_RX_PWRDN_LANE0_VAL(2) |
290 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
291
292 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000293 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100294 FDI_RX_PLL_ENABLE |
Daniel Vetter627eb5a2013-04-29 19:33:42 +0200295 FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
Paulo Zanoni04945642012-11-01 21:00:59 -0200296 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
297 POSTING_READ(_FDI_RXA_CTL);
298 udelay(220);
299
300 /* Switch from Rawclk to PCDclk */
301 rx_ctl_val |= FDI_PCDCLK;
302 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
303
304 /* Configure Port Clock Select */
Daniel Vetterde7cfc62014-06-25 22:01:54 +0300305 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config.ddi_pll_sel);
306 WARN_ON(intel_crtc->config.ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200307
308 /* Start the training iterating through available voltages and emphasis,
309 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300310 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300311 /* Configure DP_TP_CTL with auto-training */
312 I915_WRITE(DP_TP_CTL(PORT_E),
313 DP_TP_CTL_FDI_AUTOTRAIN |
314 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
315 DP_TP_CTL_LINK_TRAIN_PAT1 |
316 DP_TP_CTL_ENABLE);
317
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000318 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
319 * DDI E does not support port reversal, the functionality is
320 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
321 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300322 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200323 DDI_BUF_CTL_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100324 ((intel_crtc->config.fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530325 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200326 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300327
328 udelay(600);
329
Paulo Zanoni04945642012-11-01 21:00:59 -0200330 /* Program PCH FDI Receiver TU */
331 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300332
Paulo Zanoni04945642012-11-01 21:00:59 -0200333 /* Enable PCH FDI Receiver with auto-training */
334 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
335 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
336 POSTING_READ(_FDI_RXA_CTL);
337
338 /* Wait for FDI receiver lane calibration */
339 udelay(30);
340
341 /* Unset FDI_RX_MISC pwrdn lanes */
342 temp = I915_READ(_FDI_RXA_MISC);
343 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
344 I915_WRITE(_FDI_RXA_MISC, temp);
345 POSTING_READ(_FDI_RXA_MISC);
346
347 /* Wait for FDI auto training time */
348 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300349
350 temp = I915_READ(DP_TP_STATUS(PORT_E));
351 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200352 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300353
354 /* Enable normal pixel sending for FDI */
355 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200356 DP_TP_CTL_FDI_AUTOTRAIN |
357 DP_TP_CTL_LINK_TRAIN_NORMAL |
358 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
359 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300360
Paulo Zanoni04945642012-11-01 21:00:59 -0200361 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300362 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200363
Paulo Zanoni248138b2012-11-29 11:29:31 -0200364 temp = I915_READ(DDI_BUF_CTL(PORT_E));
365 temp &= ~DDI_BUF_CTL_ENABLE;
366 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
367 POSTING_READ(DDI_BUF_CTL(PORT_E));
368
Paulo Zanoni04945642012-11-01 21:00:59 -0200369 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200370 temp = I915_READ(DP_TP_CTL(PORT_E));
371 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
372 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
373 I915_WRITE(DP_TP_CTL(PORT_E), temp);
374 POSTING_READ(DP_TP_CTL(PORT_E));
375
376 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200377
378 rx_ctl_val &= ~FDI_RX_ENABLE;
379 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200380 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200381
382 /* Reset FDI_RX_MISC pwrdn lanes */
383 temp = I915_READ(_FDI_RXA_MISC);
384 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
385 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
386 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200387 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300388 }
389
Paulo Zanoni04945642012-11-01 21:00:59 -0200390 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300391}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300392
Dave Airlie44905a22014-05-02 13:36:43 +1000393void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
394{
395 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
396 struct intel_digital_port *intel_dig_port =
397 enc_to_dig_port(&encoder->base);
398
399 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530400 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Dave Airlie44905a22014-05-02 13:36:43 +1000401 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
402
403}
404
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300405static struct intel_encoder *
406intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
407{
408 struct drm_device *dev = crtc->dev;
409 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
410 struct intel_encoder *intel_encoder, *ret = NULL;
411 int num_encoders = 0;
412
413 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
414 ret = intel_encoder;
415 num_encoders++;
416 }
417
418 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300419 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
420 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300421
422 BUG_ON(ret == NULL);
423 return ret;
424}
425
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100426#define LC_FREQ 2700
Damien Lespiau27893392014-09-04 12:27:23 +0100427#define LC_FREQ_2K U64_C(LC_FREQ * 2000)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100428
429#define P_MIN 2
430#define P_MAX 64
431#define P_INC 2
432
433/* Constraints for PLL good behavior */
434#define REF_MIN 48
435#define REF_MAX 400
436#define VCO_MIN 2400
437#define VCO_MAX 4800
438
Damien Lespiau27893392014-09-04 12:27:23 +0100439#define abs_diff(a, b) ({ \
440 typeof(a) __a = (a); \
441 typeof(b) __b = (b); \
442 (void) (&__a == &__b); \
443 __a > __b ? (__a - __b) : (__b - __a); })
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100444
445struct wrpll_rnp {
446 unsigned p, n2, r2;
447};
448
449static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300450{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100451 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300452
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100453 switch (clock) {
454 case 25175000:
455 case 25200000:
456 case 27000000:
457 case 27027000:
458 case 37762500:
459 case 37800000:
460 case 40500000:
461 case 40541000:
462 case 54000000:
463 case 54054000:
464 case 59341000:
465 case 59400000:
466 case 72000000:
467 case 74176000:
468 case 74250000:
469 case 81000000:
470 case 81081000:
471 case 89012000:
472 case 89100000:
473 case 108000000:
474 case 108108000:
475 case 111264000:
476 case 111375000:
477 case 148352000:
478 case 148500000:
479 case 162000000:
480 case 162162000:
481 case 222525000:
482 case 222750000:
483 case 296703000:
484 case 297000000:
485 budget = 0;
486 break;
487 case 233500000:
488 case 245250000:
489 case 247750000:
490 case 253250000:
491 case 298000000:
492 budget = 1500;
493 break;
494 case 169128000:
495 case 169500000:
496 case 179500000:
497 case 202000000:
498 budget = 2000;
499 break;
500 case 256250000:
501 case 262500000:
502 case 270000000:
503 case 272500000:
504 case 273750000:
505 case 280750000:
506 case 281250000:
507 case 286000000:
508 case 291750000:
509 budget = 4000;
510 break;
511 case 267250000:
512 case 268500000:
513 budget = 5000;
514 break;
515 default:
516 budget = 1000;
517 break;
518 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300519
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100520 return budget;
521}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300522
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100523static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
524 unsigned r2, unsigned n2, unsigned p,
525 struct wrpll_rnp *best)
526{
527 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300528
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100529 /* No best (r,n,p) yet */
530 if (best->p == 0) {
531 best->p = p;
532 best->n2 = n2;
533 best->r2 = r2;
534 return;
535 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300536
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100537 /*
538 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
539 * freq2k.
540 *
541 * delta = 1e6 *
542 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
543 * freq2k;
544 *
545 * and we would like delta <= budget.
546 *
547 * If the discrepancy is above the PPM-based budget, always prefer to
548 * improve upon the previous solution. However, if you're within the
549 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
550 */
551 a = freq2k * budget * p * r2;
552 b = freq2k * budget * best->p * best->r2;
Damien Lespiau27893392014-09-04 12:27:23 +0100553 diff = abs_diff(freq2k * p * r2, LC_FREQ_2K * n2);
554 diff_best = abs_diff(freq2k * best->p * best->r2,
555 LC_FREQ_2K * best->n2);
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100556 c = 1000000 * diff;
557 d = 1000000 * diff_best;
558
559 if (a < c && b < d) {
560 /* If both are above the budget, pick the closer */
561 if (best->p * best->r2 * diff < p * r2 * diff_best) {
562 best->p = p;
563 best->n2 = n2;
564 best->r2 = r2;
565 }
566 } else if (a >= c && b < d) {
567 /* If A is below the threshold but B is above it? Update. */
568 best->p = p;
569 best->n2 = n2;
570 best->r2 = r2;
571 } else if (a >= c && b >= d) {
572 /* Both are below the limit, so pick the higher n2/(r2*r2) */
573 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
574 best->p = p;
575 best->n2 = n2;
576 best->r2 = r2;
577 }
578 }
579 /* Otherwise a < c && b >= d, do nothing */
580}
581
Jesse Barnes11578552014-01-21 12:42:10 -0800582static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
583 int reg)
584{
585 int refclk = LC_FREQ;
586 int n, p, r;
587 u32 wrpll;
588
589 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300590 switch (wrpll & WRPLL_PLL_REF_MASK) {
591 case WRPLL_PLL_SSC:
592 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800593 /*
594 * We could calculate spread here, but our checking
595 * code only cares about 5% accuracy, and spread is a max of
596 * 0.5% downspread.
597 */
598 refclk = 135;
599 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300600 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800601 refclk = LC_FREQ;
602 break;
603 default:
604 WARN(1, "bad wrpll refclk\n");
605 return 0;
606 }
607
608 r = wrpll & WRPLL_DIVIDER_REF_MASK;
609 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
610 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
611
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800612 /* Convert to KHz, p & r have a fixed point portion */
613 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800614}
615
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200616static void hsw_ddi_clock_get(struct intel_encoder *encoder,
617 struct intel_crtc_config *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -0800618{
619 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jesse Barnes11578552014-01-21 12:42:10 -0800620 int link_clock = 0;
621 u32 val, pll;
622
Daniel Vetter26804af2014-06-25 22:01:55 +0300623 val = pipe_config->ddi_pll_sel;
Jesse Barnes11578552014-01-21 12:42:10 -0800624 switch (val & PORT_CLK_SEL_MASK) {
625 case PORT_CLK_SEL_LCPLL_810:
626 link_clock = 81000;
627 break;
628 case PORT_CLK_SEL_LCPLL_1350:
629 link_clock = 135000;
630 break;
631 case PORT_CLK_SEL_LCPLL_2700:
632 link_clock = 270000;
633 break;
634 case PORT_CLK_SEL_WRPLL1:
635 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
636 break;
637 case PORT_CLK_SEL_WRPLL2:
638 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
639 break;
640 case PORT_CLK_SEL_SPLL:
641 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
642 if (pll == SPLL_PLL_FREQ_810MHz)
643 link_clock = 81000;
644 else if (pll == SPLL_PLL_FREQ_1350MHz)
645 link_clock = 135000;
646 else if (pll == SPLL_PLL_FREQ_2700MHz)
647 link_clock = 270000;
648 else {
649 WARN(1, "bad spll freq\n");
650 return;
651 }
652 break;
653 default:
654 WARN(1, "bad port clock sel\n");
655 return;
656 }
657
658 pipe_config->port_clock = link_clock * 2;
659
660 if (pipe_config->has_pch_encoder)
661 pipe_config->adjusted_mode.crtc_clock =
662 intel_dotclock_calculate(pipe_config->port_clock,
663 &pipe_config->fdi_m_n);
664 else if (pipe_config->has_dp_encoder)
665 pipe_config->adjusted_mode.crtc_clock =
666 intel_dotclock_calculate(pipe_config->port_clock,
667 &pipe_config->dp_m_n);
668 else
669 pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
670}
671
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200672void intel_ddi_clock_get(struct intel_encoder *encoder,
673 struct intel_crtc_config *pipe_config)
674{
675 hsw_ddi_clock_get(encoder, pipe_config);
676}
677
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100678static void
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100679hsw_ddi_calculate_wrpll(int clock /* in Hz */,
680 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100681{
682 uint64_t freq2k;
683 unsigned p, n2, r2;
684 struct wrpll_rnp best = { 0, 0, 0 };
685 unsigned budget;
686
687 freq2k = clock / 100;
688
689 budget = wrpll_get_budget_for_freq(clock);
690
691 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
692 * and directly pass the LC PLL to it. */
693 if (freq2k == 5400000) {
694 *n2_out = 2;
695 *p_out = 1;
696 *r2_out = 2;
697 return;
698 }
699
700 /*
701 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
702 * the WR PLL.
703 *
704 * We want R so that REF_MIN <= Ref <= REF_MAX.
705 * Injecting R2 = 2 * R gives:
706 * REF_MAX * r2 > LC_FREQ * 2 and
707 * REF_MIN * r2 < LC_FREQ * 2
708 *
709 * Which means the desired boundaries for r2 are:
710 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
711 *
712 */
713 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
714 r2 <= LC_FREQ * 2 / REF_MIN;
715 r2++) {
716
717 /*
718 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
719 *
720 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
721 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
722 * VCO_MAX * r2 > n2 * LC_FREQ and
723 * VCO_MIN * r2 < n2 * LC_FREQ)
724 *
725 * Which means the desired boundaries for n2 are:
726 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
727 */
728 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
729 n2 <= VCO_MAX * r2 / LC_FREQ;
730 n2++) {
731
732 for (p = P_MIN; p <= P_MAX; p += P_INC)
733 wrpll_update_rnp(freq2k, budget,
734 r2, n2, p, &best);
735 }
736 }
737
738 *n2_out = best.n2;
739 *p_out = best.p;
740 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300741}
742
Damien Lespiau0220ab62014-07-29 18:06:22 +0100743static bool
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100744hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
745 struct intel_encoder *intel_encoder,
746 int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300747{
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100748 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
Daniel Vettere0b01be2014-06-25 22:02:01 +0300749 struct intel_shared_dpll *pll;
Daniel Vetter716c2e52014-06-25 22:02:02 +0300750 uint32_t val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100751 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300752
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100753 hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300754
Daniel Vetter114fe482014-06-25 22:01:48 +0300755 val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300756 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
757 WRPLL_DIVIDER_POST(p);
758
Daniel Vetter716c2e52014-06-25 22:02:02 +0300759 intel_crtc->config.dpll_hw_state.wrpll = val;
760
761 pll = intel_get_shared_dpll(intel_crtc);
762 if (pll == NULL) {
763 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
764 pipe_name(intel_crtc->pipe));
Paulo Zanoni06940012013-10-30 18:27:43 -0200765 return false;
766 }
767
Daniel Vetter716c2e52014-06-25 22:02:02 +0300768 intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300769 }
770
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300771 return true;
772}
773
Damien Lespiau0220ab62014-07-29 18:06:22 +0100774
775/*
776 * Tries to find a *shared* PLL for the CRTC and store it in
777 * intel_crtc->ddi_pll_sel.
778 *
779 * For private DPLLs, compute_config() should do the selection for us. This
780 * function should be folded into compute_config() eventually.
781 */
782bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
783{
784 struct drm_crtc *crtc = &intel_crtc->base;
785 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Damien Lespiau0220ab62014-07-29 18:06:22 +0100786 int clock = intel_crtc->config.port_clock;
787
788 intel_put_shared_dpll(intel_crtc);
789
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100790 return hsw_ddi_pll_select(intel_crtc, intel_encoder, clock);
Damien Lespiau0220ab62014-07-29 18:06:22 +0100791}
792
Paulo Zanonidae84792012-10-15 15:51:30 -0300793void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
794{
795 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
796 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
797 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200798 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300799 int type = intel_encoder->type;
800 uint32_t temp;
801
Dave Airlie0e32b392014-05-02 14:02:48 +1000802 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Paulo Zanonic9809792012-10-23 18:30:00 -0200803 temp = TRANS_MSA_SYNC_CLK;
Daniel Vetter965e0c42013-03-27 00:44:57 +0100804 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -0300805 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200806 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300807 break;
808 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200809 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300810 break;
811 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200812 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300813 break;
814 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200815 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300816 break;
817 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100818 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -0300819 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200820 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300821 }
822}
823
Dave Airlie0e32b392014-05-02 14:02:48 +1000824void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
825{
826 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
827 struct drm_device *dev = crtc->dev;
828 struct drm_i915_private *dev_priv = dev->dev_private;
829 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
830 uint32_t temp;
831 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
832 if (state == true)
833 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
834 else
835 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
836 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
837}
838
Damien Lespiau8228c252013-03-07 15:30:27 +0000839void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300840{
841 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
842 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300843 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -0700844 struct drm_device *dev = crtc->dev;
845 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300846 enum pipe pipe = intel_crtc->pipe;
Daniel Vetter3b117c82013-04-17 20:15:07 +0200847 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200848 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300849 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300850 uint32_t temp;
851
Paulo Zanoniad80a812012-10-24 16:06:19 -0200852 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
853 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200854 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -0300855
Daniel Vetter965e0c42013-03-27 00:44:57 +0100856 switch (intel_crtc->config.pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -0300857 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200858 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300859 break;
860 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200861 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300862 break;
863 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200864 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300865 break;
866 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200867 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300868 break;
869 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100870 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -0300871 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300872
Ville Syrjäläa6662832013-09-10 17:03:41 +0300873 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200874 temp |= TRANS_DDI_PVSYNC;
Ville Syrjäläa6662832013-09-10 17:03:41 +0300875 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200876 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c2012-08-08 14:15:28 -0300877
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200878 if (cpu_transcoder == TRANSCODER_EDP) {
879 switch (pipe) {
880 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -0700881 /* On Haswell, can only use the always-on power well for
882 * eDP when not using the panel fitter, and when not
883 * using motion blur mitigation (which we don't
884 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +0200885 if (IS_HASWELL(dev) &&
886 (intel_crtc->config.pch_pfit.enabled ||
887 intel_crtc->config.pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -0200888 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
889 else
890 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200891 break;
892 case PIPE_B:
893 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
894 break;
895 case PIPE_C:
896 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
897 break;
898 default:
899 BUG();
900 break;
901 }
902 }
903
Paulo Zanoni7739c332012-10-15 15:51:29 -0300904 if (type == INTEL_OUTPUT_HDMI) {
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200905 if (intel_crtc->config.has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200906 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300907 else
Paulo Zanoniad80a812012-10-24 16:06:19 -0200908 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300909
Paulo Zanoni7739c332012-10-15 15:51:29 -0300910 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -0200911 temp |= TRANS_DDI_MODE_SELECT_FDI;
Daniel Vetter33d29b12013-02-13 18:04:45 +0100912 temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300913
914 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
915 type == INTEL_OUTPUT_EDP) {
916 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
917
Dave Airlie0e32b392014-05-02 14:02:48 +1000918 if (intel_dp->is_mst) {
919 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
920 } else
921 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
922
923 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
924 } else if (type == INTEL_OUTPUT_DP_MST) {
925 struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
926
927 if (intel_dp->is_mst) {
928 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
929 } else
930 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300931
Daniel Vetter17aa6be2013-04-30 14:01:40 +0200932 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300933 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300934 WARN(1, "Invalid encoder type %d for pipe %c\n",
935 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300936 }
937
Paulo Zanoniad80a812012-10-24 16:06:19 -0200938 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300939}
940
Paulo Zanoniad80a812012-10-24 16:06:19 -0200941void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
942 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300943{
Paulo Zanoniad80a812012-10-24 16:06:19 -0200944 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300945 uint32_t val = I915_READ(reg);
946
Dave Airlie0e32b392014-05-02 14:02:48 +1000947 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -0200948 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300949 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300950}
951
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200952bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
953{
954 struct drm_device *dev = intel_connector->base.dev;
955 struct drm_i915_private *dev_priv = dev->dev_private;
956 struct intel_encoder *intel_encoder = intel_connector->encoder;
957 int type = intel_connector->base.connector_type;
958 enum port port = intel_ddi_get_encoder_port(intel_encoder);
959 enum pipe pipe = 0;
960 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -0300961 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200962 uint32_t tmp;
963
Paulo Zanoni882244a2014-04-01 14:55:12 -0300964 power_domain = intel_display_port_power_domain(intel_encoder);
965 if (!intel_display_power_enabled(dev_priv, power_domain))
966 return false;
967
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200968 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
969 return false;
970
971 if (port == PORT_A)
972 cpu_transcoder = TRANSCODER_EDP;
973 else
Daniel Vetter1a240d42012-11-29 22:18:51 +0100974 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200975
976 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
977
978 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
979 case TRANS_DDI_MODE_SELECT_HDMI:
980 case TRANS_DDI_MODE_SELECT_DVI:
981 return (type == DRM_MODE_CONNECTOR_HDMIA);
982
983 case TRANS_DDI_MODE_SELECT_DP_SST:
984 if (type == DRM_MODE_CONNECTOR_eDP)
985 return true;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200986 return (type == DRM_MODE_CONNECTOR_DisplayPort);
Dave Airlie0e32b392014-05-02 14:02:48 +1000987 case TRANS_DDI_MODE_SELECT_DP_MST:
988 /* if the transcoder is in MST state then
989 * connector isn't connected */
990 return false;
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200991
992 case TRANS_DDI_MODE_SELECT_FDI:
993 return (type == DRM_MODE_CONNECTOR_VGA);
994
995 default:
996 return false;
997 }
998}
999
Daniel Vetter85234cd2012-07-02 13:27:29 +02001000bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1001 enum pipe *pipe)
1002{
1003 struct drm_device *dev = encoder->base.dev;
1004 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001005 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001006 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001007 u32 tmp;
1008 int i;
1009
Imre Deak6d129be2014-03-05 16:20:54 +02001010 power_domain = intel_display_port_power_domain(encoder);
1011 if (!intel_display_power_enabled(dev_priv, power_domain))
1012 return false;
1013
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001014 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001015
1016 if (!(tmp & DDI_BUF_CTL_ENABLE))
1017 return false;
1018
Paulo Zanoniad80a812012-10-24 16:06:19 -02001019 if (port == PORT_A) {
1020 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001021
Paulo Zanoniad80a812012-10-24 16:06:19 -02001022 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1023 case TRANS_DDI_EDP_INPUT_A_ON:
1024 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1025 *pipe = PIPE_A;
1026 break;
1027 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1028 *pipe = PIPE_B;
1029 break;
1030 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1031 *pipe = PIPE_C;
1032 break;
1033 }
1034
1035 return true;
1036 } else {
1037 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1038 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1039
1040 if ((tmp & TRANS_DDI_PORT_MASK)
1041 == TRANS_DDI_SELECT_PORT(port)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10001042 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST)
1043 return false;
1044
Paulo Zanoniad80a812012-10-24 16:06:19 -02001045 *pipe = i;
1046 return true;
1047 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001048 }
1049 }
1050
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001051 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001052
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001053 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001054}
1055
Paulo Zanonifc914632012-10-05 12:05:54 -03001056void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1057{
1058 struct drm_crtc *crtc = &intel_crtc->base;
1059 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1060 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1061 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +02001062 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001063
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001064 if (cpu_transcoder != TRANSCODER_EDP)
1065 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1066 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001067}
1068
1069void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1070{
1071 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Daniel Vetter3b117c82013-04-17 20:15:07 +02001072 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001073
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001074 if (cpu_transcoder != TRANSCODER_EDP)
1075 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1076 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001077}
1078
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001079static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001080{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001081 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001082 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001083 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001084 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001085 int type = intel_encoder->type;
1086
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001087 if (crtc->config.has_audio) {
1088 DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
1089 pipe_name(crtc->pipe));
1090
1091 /* write eld */
1092 DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
1093 intel_write_eld(encoder, &crtc->config.adjusted_mode);
1094 }
1095
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001096 if (type == INTEL_OUTPUT_EDP) {
1097 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001098 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001099 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001100
Daniel Vetterde7cfc62014-06-25 22:01:54 +03001101 WARN_ON(crtc->config.ddi_pll_sel == PORT_CLK_SEL_NONE);
1102 I915_WRITE(PORT_CLK_SEL(port), crtc->config.ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001103
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001104 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001105 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001106
Dave Airlie44905a22014-05-02 13:36:43 +10001107 intel_ddi_init_dp_buf_reg(intel_encoder);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001108
1109 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1110 intel_dp_start_link_train(intel_dp);
1111 intel_dp_complete_link_train(intel_dp);
Imre Deak3ab9c632013-05-03 12:57:41 +03001112 if (port != PORT_A)
1113 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001114 } else if (type == INTEL_OUTPUT_HDMI) {
1115 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1116
1117 intel_hdmi->set_infoframes(encoder,
1118 crtc->config.has_hdmi_sink,
1119 &crtc->config.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001120 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001121}
1122
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001123static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001124{
1125 struct drm_encoder *encoder = &intel_encoder->base;
1126 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1127 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001128 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001129 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001130 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001131
1132 val = I915_READ(DDI_BUF_CTL(port));
1133 if (val & DDI_BUF_CTL_ENABLE) {
1134 val &= ~DDI_BUF_CTL_ENABLE;
1135 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001136 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001137 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001138
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001139 val = I915_READ(DP_TP_CTL(port));
1140 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1141 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1142 I915_WRITE(DP_TP_CTL(port), val);
1143
1144 if (wait)
1145 intel_wait_ddi_buf_idle(dev_priv, port);
1146
Jani Nikula76bb80e2013-11-15 15:29:57 +02001147 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001148 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001149 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001150 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001151 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001152 }
1153
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001154 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1155}
1156
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001157static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001158{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001159 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001160 struct drm_crtc *crtc = encoder->crtc;
1161 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1162 int pipe = intel_crtc->pipe;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001163 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001164 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001165 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1166 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001167 uint32_t tmp;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001168
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001169 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001170 struct intel_digital_port *intel_dig_port =
1171 enc_to_dig_port(encoder);
1172
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001173 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1174 * are ignored so nothing special needs to be done besides
1175 * enabling the port.
1176 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001177 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001178 intel_dig_port->saved_port_bits |
1179 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001180 } else if (type == INTEL_OUTPUT_EDP) {
1181 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1182
Imre Deak3ab9c632013-05-03 12:57:41 +03001183 if (port == PORT_A)
1184 intel_dp_stop_link_train(intel_dp);
1185
Daniel Vetter4be73782014-01-17 14:39:48 +01001186 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi49065572013-07-11 18:45:05 -03001187 intel_edp_psr_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001188 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001189
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001190 if (intel_crtc->config.has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001191 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001192 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1193 tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1194 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1195 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001196}
1197
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001198static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001199{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001200 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001201 struct drm_crtc *crtc = encoder->crtc;
1202 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1203 int pipe = intel_crtc->pipe;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001204 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001205 struct drm_device *dev = encoder->dev;
1206 struct drm_i915_private *dev_priv = dev->dev_private;
1207 uint32_t tmp;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001208
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001209 /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
1210 * register is part of the power well on Haswell. */
1211 if (intel_crtc->config.has_audio) {
1212 tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1213 tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1214 (pipe * 4));
1215 I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1216 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1217 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001218
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001219 if (type == INTEL_OUTPUT_EDP) {
1220 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1221
Rodrigo Vivi49065572013-07-11 18:45:05 -03001222 intel_edp_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001223 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001224 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001225}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001226
Damien Lespiauad13d602014-07-29 18:06:24 +01001227static int bdw_get_cdclk_freq(struct drm_i915_private *dev_priv)
1228{
1229 uint32_t lcpll = I915_READ(LCPLL_CTL);
1230 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
1231
1232 if (lcpll & LCPLL_CD_SOURCE_FCLK)
1233 return 800000;
1234 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
1235 return 450000;
1236 else if (freq == LCPLL_CLK_FREQ_450)
1237 return 450000;
1238 else if (freq == LCPLL_CLK_FREQ_54O_BDW)
1239 return 540000;
1240 else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
1241 return 337500;
1242 else
1243 return 675000;
1244}
1245
1246static int hsw_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001247{
Paulo Zanonie39bf982013-11-02 21:07:36 -07001248 struct drm_device *dev = dev_priv->dev;
Paulo Zanonia4006642013-08-06 18:57:11 -03001249 uint32_t lcpll = I915_READ(LCPLL_CTL);
Paulo Zanonie39bf982013-11-02 21:07:36 -07001250 uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Paulo Zanonia4006642013-08-06 18:57:11 -03001251
Damien Lespiauad13d602014-07-29 18:06:24 +01001252 if (lcpll & LCPLL_CD_SOURCE_FCLK)
Paulo Zanonia4006642013-08-06 18:57:11 -03001253 return 800000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001254 else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT)
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001255 return 450000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001256 else if (freq == LCPLL_CLK_FREQ_450)
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001257 return 450000;
Damien Lespiauad13d602014-07-29 18:06:24 +01001258 else if (IS_ULT(dev))
1259 return 337500;
1260 else
1261 return 540000;
1262}
1263
1264int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
1265{
1266 struct drm_device *dev = dev_priv->dev;
1267
1268 if (IS_BROADWELL(dev))
1269 return bdw_get_cdclk_freq(dev_priv);
1270
1271 /* Haswell */
1272 return hsw_get_cdclk_freq(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001273}
1274
Daniel Vettere0b01be2014-06-25 22:02:01 +03001275static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv,
1276 struct intel_shared_dpll *pll)
1277{
Daniel Vettere0b01be2014-06-25 22:02:01 +03001278 I915_WRITE(WRPLL_CTL(pll->id), pll->hw_state.wrpll);
1279 POSTING_READ(WRPLL_CTL(pll->id));
1280 udelay(20);
1281}
1282
Daniel Vetter12030432014-06-25 22:02:00 +03001283static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv,
1284 struct intel_shared_dpll *pll)
1285{
1286 uint32_t val;
1287
1288 val = I915_READ(WRPLL_CTL(pll->id));
Daniel Vetter12030432014-06-25 22:02:00 +03001289 I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
1290 POSTING_READ(WRPLL_CTL(pll->id));
1291}
1292
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001293static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
1294 struct intel_shared_dpll *pll,
1295 struct intel_dpll_hw_state *hw_state)
1296{
1297 uint32_t val;
1298
1299 if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
1300 return false;
1301
1302 val = I915_READ(WRPLL_CTL(pll->id));
1303 hw_state->wrpll = val;
1304
1305 return val & WRPLL_PLL_ENABLE;
1306}
1307
Damien Lespiauca1381b2014-07-15 15:05:33 +01001308static const char * const hsw_ddi_pll_names[] = {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001309 "WRPLL 1",
1310 "WRPLL 2",
1311};
1312
Damien Lespiau143b3072014-07-29 18:06:19 +01001313static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001314{
Daniel Vetter9cd86932014-06-25 22:01:57 +03001315 int i;
1316
Daniel Vetter716c2e52014-06-25 22:02:02 +03001317 dev_priv->num_shared_dpll = 2;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001318
Daniel Vetter716c2e52014-06-25 22:02:02 +03001319 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001320 dev_priv->shared_dplls[i].id = i;
1321 dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
Daniel Vetter12030432014-06-25 22:02:00 +03001322 dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable;
Daniel Vettere0b01be2014-06-25 22:02:01 +03001323 dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable;
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001324 dev_priv->shared_dplls[i].get_hw_state =
1325 hsw_ddi_pll_get_hw_state;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001326 }
Damien Lespiau143b3072014-07-29 18:06:19 +01001327}
1328
1329void intel_ddi_pll_init(struct drm_device *dev)
1330{
1331 struct drm_i915_private *dev_priv = dev->dev_private;
1332 uint32_t val = I915_READ(LCPLL_CTL);
1333
1334 hsw_shared_dplls_init(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001335
1336 /* The LCPLL register should be turned on by the BIOS. For now let's
1337 * just check its state and print errors in case something is wrong.
1338 * Don't even try to turn it on.
1339 */
1340
Paulo Zanonib2b877f2013-05-03 17:23:42 -03001341 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001342 intel_ddi_get_cdclk_freq(dev_priv));
1343
1344 if (val & LCPLL_CD_SOURCE_FCLK)
1345 DRM_ERROR("CDCLK source is not LCPLL\n");
1346
1347 if (val & LCPLL_PLL_DISABLE)
1348 DRM_ERROR("LCPLL is disabled\n");
1349}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001350
1351void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1352{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001353 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1354 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001355 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001356 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001357 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05301358 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001359
1360 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1361 val = I915_READ(DDI_BUF_CTL(port));
1362 if (val & DDI_BUF_CTL_ENABLE) {
1363 val &= ~DDI_BUF_CTL_ENABLE;
1364 I915_WRITE(DDI_BUF_CTL(port), val);
1365 wait = true;
1366 }
1367
1368 val = I915_READ(DP_TP_CTL(port));
1369 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1370 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1371 I915_WRITE(DP_TP_CTL(port), val);
1372 POSTING_READ(DP_TP_CTL(port));
1373
1374 if (wait)
1375 intel_wait_ddi_buf_idle(dev_priv, port);
1376 }
1377
Dave Airlie0e32b392014-05-02 14:02:48 +10001378 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03001379 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Dave Airlie0e32b392014-05-02 14:02:48 +10001380 if (intel_dp->is_mst)
1381 val |= DP_TP_CTL_MODE_MST;
1382 else {
1383 val |= DP_TP_CTL_MODE_SST;
1384 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1385 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1386 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03001387 I915_WRITE(DP_TP_CTL(port), val);
1388 POSTING_READ(DP_TP_CTL(port));
1389
1390 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1391 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1392 POSTING_READ(DDI_BUF_CTL(port));
1393
1394 udelay(600);
1395}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001396
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02001397void intel_ddi_fdi_disable(struct drm_crtc *crtc)
1398{
1399 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1400 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1401 uint32_t val;
1402
1403 intel_ddi_post_disable(intel_encoder);
1404
1405 val = I915_READ(_FDI_RXA_CTL);
1406 val &= ~FDI_RX_ENABLE;
1407 I915_WRITE(_FDI_RXA_CTL, val);
1408
1409 val = I915_READ(_FDI_RXA_MISC);
1410 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
1411 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1412 I915_WRITE(_FDI_RXA_MISC, val);
1413
1414 val = I915_READ(_FDI_RXA_CTL);
1415 val &= ~FDI_PCDCLK;
1416 I915_WRITE(_FDI_RXA_CTL, val);
1417
1418 val = I915_READ(_FDI_RXA_CTL);
1419 val &= ~FDI_RX_PLL_ENABLE;
1420 I915_WRITE(_FDI_RXA_CTL, val);
1421}
1422
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001423static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1424{
Dave Airlie0e32b392014-05-02 14:02:48 +10001425 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&intel_encoder->base);
1426 int type = intel_dig_port->base.type;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001427
Dave Airlie0e32b392014-05-02 14:02:48 +10001428 if (type != INTEL_OUTPUT_DISPLAYPORT &&
1429 type != INTEL_OUTPUT_EDP &&
1430 type != INTEL_OUTPUT_UNKNOWN) {
1431 return;
1432 }
1433
1434 intel_dp_hot_plug(intel_encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001435}
1436
Ville Syrjälä6801c182013-09-24 14:24:05 +03001437void intel_ddi_get_config(struct intel_encoder *encoder,
1438 struct intel_crtc_config *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001439{
1440 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1441 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1442 enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
1443 u32 temp, flags = 0;
1444
1445 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1446 if (temp & TRANS_DDI_PHSYNC)
1447 flags |= DRM_MODE_FLAG_PHSYNC;
1448 else
1449 flags |= DRM_MODE_FLAG_NHSYNC;
1450 if (temp & TRANS_DDI_PVSYNC)
1451 flags |= DRM_MODE_FLAG_PVSYNC;
1452 else
1453 flags |= DRM_MODE_FLAG_NVSYNC;
1454
1455 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03001456
1457 switch (temp & TRANS_DDI_BPC_MASK) {
1458 case TRANS_DDI_BPC_6:
1459 pipe_config->pipe_bpp = 18;
1460 break;
1461 case TRANS_DDI_BPC_8:
1462 pipe_config->pipe_bpp = 24;
1463 break;
1464 case TRANS_DDI_BPC_10:
1465 pipe_config->pipe_bpp = 30;
1466 break;
1467 case TRANS_DDI_BPC_12:
1468 pipe_config->pipe_bpp = 36;
1469 break;
1470 default:
1471 break;
1472 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001473
1474 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1475 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001476 pipe_config->has_hdmi_sink = true;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03001477 case TRANS_DDI_MODE_SELECT_DVI:
1478 case TRANS_DDI_MODE_SELECT_FDI:
1479 break;
1480 case TRANS_DDI_MODE_SELECT_DP_SST:
1481 case TRANS_DDI_MODE_SELECT_DP_MST:
1482 pipe_config->has_dp_encoder = true;
1483 intel_dp_get_m_n(intel_crtc, pipe_config);
1484 break;
1485 default:
1486 break;
1487 }
Daniel Vetter10214422013-11-18 07:38:16 +01001488
Paulo Zanonia60551b2014-05-21 16:23:20 -03001489 if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
1490 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1491 if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
1492 pipe_config->has_audio = true;
1493 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001494
Daniel Vetter10214422013-11-18 07:38:16 +01001495 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1496 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1497 /*
1498 * This is a big fat ugly hack.
1499 *
1500 * Some machines in UEFI boot mode provide us a VBT that has 18
1501 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1502 * unknown we fail to light up. Yet the same BIOS boots up with
1503 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1504 * max, not what it tells us to use.
1505 *
1506 * Note: This will still be broken if the eDP panel is not lit
1507 * up by the BIOS, and thus we can't get the mode at module
1508 * load.
1509 */
1510 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1511 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1512 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1513 }
Jesse Barnes11578552014-01-21 12:42:10 -08001514
Daniel Vetter3d51278a2014-07-29 20:57:08 +02001515 hsw_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001516}
1517
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001518static void intel_ddi_destroy(struct drm_encoder *encoder)
1519{
1520 /* HDMI has nothing special to destroy, so we can go with this. */
1521 intel_dp_encoder_destroy(encoder);
1522}
1523
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001524static bool intel_ddi_compute_config(struct intel_encoder *encoder,
1525 struct intel_crtc_config *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001526{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001527 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02001528 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001529
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001530 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001531
Daniel Vettereccb1402013-05-22 00:50:22 +02001532 if (port == PORT_A)
1533 pipe_config->cpu_transcoder = TRANSCODER_EDP;
1534
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001535 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001536 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001537 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001538 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001539}
1540
1541static const struct drm_encoder_funcs intel_ddi_funcs = {
1542 .destroy = intel_ddi_destroy,
1543};
1544
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03001545static struct intel_connector *
1546intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
1547{
1548 struct intel_connector *connector;
1549 enum port port = intel_dig_port->port;
1550
1551 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1552 if (!connector)
1553 return NULL;
1554
1555 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1556 if (!intel_dp_init_connector(intel_dig_port, connector)) {
1557 kfree(connector);
1558 return NULL;
1559 }
1560
1561 return connector;
1562}
1563
1564static struct intel_connector *
1565intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
1566{
1567 struct intel_connector *connector;
1568 enum port port = intel_dig_port->port;
1569
1570 connector = kzalloc(sizeof(*connector), GFP_KERNEL);
1571 if (!connector)
1572 return NULL;
1573
1574 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
1575 intel_hdmi_init_connector(intel_dig_port, connector);
1576
1577 return connector;
1578}
1579
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001580void intel_ddi_init(struct drm_device *dev, enum port port)
1581{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001582 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001583 struct intel_digital_port *intel_dig_port;
1584 struct intel_encoder *intel_encoder;
1585 struct drm_encoder *encoder;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001586 bool init_hdmi, init_dp;
1587
1588 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1589 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1590 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1591 if (!init_dp && !init_hdmi) {
Chris Wilsonf68d6972014-08-04 07:15:09 +01001592 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, assuming it is\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03001593 port_name(port));
1594 init_hdmi = true;
1595 init_dp = true;
1596 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001597
Daniel Vetterb14c5672013-09-19 12:18:32 +02001598 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001599 if (!intel_dig_port)
1600 return;
1601
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001602 intel_encoder = &intel_dig_port->base;
1603 encoder = &intel_encoder->base;
1604
1605 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1606 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001607
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001608 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001609 intel_encoder->enable = intel_enable_ddi;
1610 intel_encoder->pre_enable = intel_ddi_pre_enable;
1611 intel_encoder->disable = intel_disable_ddi;
1612 intel_encoder->post_disable = intel_ddi_post_disable;
1613 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001614 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001615
1616 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001617 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
1618 (DDI_BUF_PORT_REVERSAL |
1619 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001620
1621 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Chris Wilsonf68d6972014-08-04 07:15:09 +01001622 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001623 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001624 intel_encoder->hot_plug = intel_ddi_hot_plug;
1625
Chris Wilsonf68d6972014-08-04 07:15:09 +01001626 if (init_dp) {
1627 if (!intel_ddi_init_dp_connector(intel_dig_port))
1628 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10001629
Chris Wilsonf68d6972014-08-04 07:15:09 +01001630 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
1631 dev_priv->hpd_irq_port[port] = intel_dig_port;
1632 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001633
Paulo Zanoni311a2092013-09-12 17:12:18 -03001634 /* In theory we don't need the encoder->type check, but leave it just in
1635 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01001636 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
1637 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
1638 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02001639 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01001640
1641 return;
1642
1643err:
1644 drm_encoder_cleanup(encoder);
1645 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001646}