blob: b263302f35091d2d7d135835821ad8351d8f41aa [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,
45 0x00FFFFFF, 0x00040006 /* HDMI parameters */
46};
47
48static const u32 hsw_ddi_translations_fdi[] = {
49 0x00FFFFFF, 0x0007000E, /* FDI parameters */
50 0x00D75FFF, 0x000F000A,
51 0x00C30FFF, 0x00060006,
52 0x00AAAFFF, 0x001E0000,
53 0x00FFFFFF, 0x000F000A,
54 0x00D75FFF, 0x00160004,
55 0x00C30FFF, 0x001E0000,
56 0x00FFFFFF, 0x00060006,
57 0x00D75FFF, 0x001E0000,
58 0x00FFFFFF, 0x00040006 /* HDMI parameters */
59};
60
Paulo Zanonifc914632012-10-05 12:05:54 -030061static enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
62{
Paulo Zanoni0bdee302012-10-15 15:51:38 -030063 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonifc914632012-10-05 12:05:54 -030064 int type = intel_encoder->type;
65
Paulo Zanoni0bdee302012-10-15 15:51:38 -030066 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
67 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
68 return intel_dp->port;
69
70 } else if (type == INTEL_OUTPUT_HDMI) {
71 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Paulo Zanonifc914632012-10-05 12:05:54 -030072 return intel_hdmi->ddi_port;
Paulo Zanoni0bdee302012-10-15 15:51:38 -030073
Paulo Zanonifc914632012-10-05 12:05:54 -030074 } else if (type == INTEL_OUTPUT_ANALOG) {
75 return PORT_E;
Paulo Zanoni0bdee302012-10-15 15:51:38 -030076
Paulo Zanonifc914632012-10-05 12:05:54 -030077 } else {
78 DRM_ERROR("Invalid DDI encoder type %d\n", type);
79 BUG();
80 }
81}
82
Eugeni Dodonov45244b82012-05-09 15:37:20 -030083/* On Haswell, DDI port buffers must be programmed with correct values
84 * in advance. The buffer values are different for FDI and DP modes,
85 * but the HDMI/DVI fields are shared among those. So we program the DDI
86 * in either FDI or DP modes only, as HDMI connections will work with both
87 * of those
88 */
89void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port, bool use_fdi_mode)
90{
91 struct drm_i915_private *dev_priv = dev->dev_private;
92 u32 reg;
93 int i;
94 const u32 *ddi_translations = ((use_fdi_mode) ?
95 hsw_ddi_translations_fdi :
96 hsw_ddi_translations_dp);
97
98 DRM_DEBUG_DRIVER("Initializing DDI buffers for port %c in %s mode\n",
99 port_name(port),
100 use_fdi_mode ? "FDI" : "DP");
101
102 WARN((use_fdi_mode && (port != PORT_E)),
103 "Programming port %c in FDI mode, this probably will not work.\n",
104 port_name(port));
105
106 for (i=0, reg=DDI_BUF_TRANS(port); i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
107 I915_WRITE(reg, ddi_translations[i]);
108 reg += 4;
109 }
110}
111
112/* Program DDI buffers translations for DP. By default, program ports A-D in DP
113 * mode and port E for FDI.
114 */
115void intel_prepare_ddi(struct drm_device *dev)
116{
117 int port;
118
119 if (IS_HASWELL(dev)) {
120 for (port = PORT_A; port < PORT_E; port++)
121 intel_prepare_ddi_buffers(dev, port, false);
122
123 /* DDI E is the suggested one to work in FDI mode, so program is as such by
124 * default. It will have to be re-programmed in case a digital DP output
125 * will be detected on it
126 */
127 intel_prepare_ddi_buffers(dev, PORT_E, true);
128 }
129}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300130
131static const long hsw_ddi_buf_ctl_values[] = {
132 DDI_BUF_EMP_400MV_0DB_HSW,
133 DDI_BUF_EMP_400MV_3_5DB_HSW,
134 DDI_BUF_EMP_400MV_6DB_HSW,
135 DDI_BUF_EMP_400MV_9_5DB_HSW,
136 DDI_BUF_EMP_600MV_0DB_HSW,
137 DDI_BUF_EMP_600MV_3_5DB_HSW,
138 DDI_BUF_EMP_600MV_6DB_HSW,
139 DDI_BUF_EMP_800MV_0DB_HSW,
140 DDI_BUF_EMP_800MV_3_5DB_HSW
141};
142
143
144/* Starting with Haswell, different DDI ports can work in FDI mode for
145 * connection to the PCH-located connectors. For this, it is necessary to train
146 * both the DDI port and PCH receiver for the desired DDI buffer settings.
147 *
148 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
149 * please note that when FDI mode is active on DDI E, it shares 2 lines with
150 * DDI A (which is used for eDP)
151 */
152
153void hsw_fdi_link_train(struct drm_crtc *crtc)
154{
155 struct drm_device *dev = crtc->dev;
156 struct drm_i915_private *dev_priv = dev->dev_private;
157 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
158 int pipe = intel_crtc->pipe;
159 u32 reg, temp, i;
160
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300161 /* Start the training iterating through available voltages and emphasis */
162 for (i=0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values); i++) {
163 /* Configure DP_TP_CTL with auto-training */
164 I915_WRITE(DP_TP_CTL(PORT_E),
165 DP_TP_CTL_FDI_AUTOTRAIN |
166 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
167 DP_TP_CTL_LINK_TRAIN_PAT1 |
168 DP_TP_CTL_ENABLE);
169
170 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage */
171 temp = I915_READ(DDI_BUF_CTL(PORT_E));
172 temp = (temp & ~DDI_BUF_EMP_MASK);
173 I915_WRITE(DDI_BUF_CTL(PORT_E),
174 temp |
175 DDI_BUF_CTL_ENABLE |
176 DDI_PORT_WIDTH_X2 |
177 hsw_ddi_buf_ctl_values[i]);
178
179 udelay(600);
180
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300181 /* We need to program FDI_RX_MISC with the default TP1 to TP2
182 * values before enabling the receiver, and configure the delay
183 * for the FDI timing generator to 90h. Luckily, all the other
184 * bits are supposed to be zeroed, so we can write those values
185 * directly.
186 */
187 I915_WRITE(FDI_RX_MISC(pipe), FDI_RX_TP1_TO_TP2_48 |
188 FDI_RX_FDI_DELAY_90);
189
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300190 /* Enable CPU FDI Receiver with auto-training */
191 reg = FDI_RX_CTL(pipe);
192 I915_WRITE(reg,
193 I915_READ(reg) |
194 FDI_LINK_TRAIN_AUTO |
195 FDI_RX_ENABLE |
196 FDI_LINK_TRAIN_PATTERN_1_CPT |
197 FDI_RX_ENHANCE_FRAME_ENABLE |
198 FDI_PORT_WIDTH_2X_LPT |
199 FDI_RX_PLL_ENABLE);
200 POSTING_READ(reg);
201 udelay(100);
202
203 temp = I915_READ(DP_TP_STATUS(PORT_E));
204 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
205 DRM_DEBUG_DRIVER("BUF_CTL training done on %d step\n", i);
206
207 /* Enable normal pixel sending for FDI */
208 I915_WRITE(DP_TP_CTL(PORT_E),
209 DP_TP_CTL_FDI_AUTOTRAIN |
210 DP_TP_CTL_LINK_TRAIN_NORMAL |
211 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
212 DP_TP_CTL_ENABLE);
213
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300214 break;
215 } else {
216 DRM_ERROR("Error training BUF_CTL %d\n", i);
217
218 /* Disable DP_TP_CTL and FDI_RX_CTL) and retry */
219 I915_WRITE(DP_TP_CTL(PORT_E),
220 I915_READ(DP_TP_CTL(PORT_E)) &
221 ~DP_TP_CTL_ENABLE);
222 I915_WRITE(FDI_RX_CTL(pipe),
223 I915_READ(FDI_RX_CTL(pipe)) &
224 ~FDI_RX_PLL_ENABLE);
225 continue;
226 }
227 }
228
229 DRM_DEBUG_KMS("FDI train done.\n");
230}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300231
232/* For DDI connections, it is possible to support different outputs over the
233 * same DDI port, such as HDMI or DP or even VGA via FDI. So we don't know by
234 * the time the output is detected what exactly is on the other end of it. This
235 * function aims at providing support for this detection and proper output
236 * configuration.
237 */
238void intel_ddi_init(struct drm_device *dev, enum port port)
239{
240 /* For now, we don't do any proper output detection and assume that we
241 * handle HDMI only */
242
243 switch(port){
244 case PORT_A:
245 /* We don't handle eDP and DP yet */
246 DRM_DEBUG_DRIVER("Found digital output on DDI port A\n");
247 break;
248 /* Assume that the ports B, C and D are working in HDMI mode for now */
249 case PORT_B:
250 case PORT_C:
251 case PORT_D:
Daniel Vetter08d644a2012-07-12 20:19:59 +0200252 intel_hdmi_init(dev, DDI_BUF_CTL(port), port);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300253 break;
254 default:
255 DRM_DEBUG_DRIVER("No handlers defined for port %d, skipping DDI initialization\n",
256 port);
257 break;
258 }
259}
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300260
261/* WRPLL clock dividers */
262struct wrpll_tmds_clock {
263 u32 clock;
264 u16 p; /* Post divider */
265 u16 n2; /* Feedback divider */
266 u16 r2; /* Reference divider */
267};
268
Paulo Zanoni126e9be2012-08-10 10:03:03 -0300269/* Table of matching values for WRPLL clocks programming for each frequency.
270 * The code assumes this table is sorted. */
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300271static const struct wrpll_tmds_clock wrpll_tmds_clock_table[] = {
272 {19750, 38, 25, 18},
273 {20000, 48, 32, 18},
274 {21000, 36, 21, 15},
275 {21912, 42, 29, 17},
276 {22000, 36, 22, 15},
277 {23000, 36, 23, 15},
278 {23500, 40, 40, 23},
279 {23750, 26, 16, 14},
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300280 {24000, 36, 24, 15},
281 {25000, 36, 25, 15},
282 {25175, 26, 40, 33},
283 {25200, 30, 21, 15},
284 {26000, 36, 26, 15},
285 {27000, 30, 21, 14},
286 {27027, 18, 100, 111},
287 {27500, 30, 29, 19},
288 {28000, 34, 30, 17},
289 {28320, 26, 30, 22},
290 {28322, 32, 42, 25},
291 {28750, 24, 23, 18},
292 {29000, 30, 29, 18},
293 {29750, 32, 30, 17},
294 {30000, 30, 25, 15},
295 {30750, 30, 41, 24},
296 {31000, 30, 31, 18},
297 {31500, 30, 28, 16},
298 {32000, 30, 32, 18},
299 {32500, 28, 32, 19},
300 {33000, 24, 22, 15},
301 {34000, 28, 30, 17},
302 {35000, 26, 32, 19},
303 {35500, 24, 30, 19},
304 {36000, 26, 26, 15},
305 {36750, 26, 46, 26},
306 {37000, 24, 23, 14},
307 {37762, 22, 40, 26},
308 {37800, 20, 21, 15},
309 {38000, 24, 27, 16},
310 {38250, 24, 34, 20},
311 {39000, 24, 26, 15},
312 {40000, 24, 32, 18},
313 {40500, 20, 21, 14},
314 {40541, 22, 147, 89},
315 {40750, 18, 19, 14},
316 {41000, 16, 17, 14},
317 {41500, 22, 44, 26},
318 {41540, 22, 44, 26},
319 {42000, 18, 21, 15},
320 {42500, 22, 45, 26},
321 {43000, 20, 43, 27},
322 {43163, 20, 24, 15},
323 {44000, 18, 22, 15},
324 {44900, 20, 108, 65},
325 {45000, 20, 25, 15},
326 {45250, 20, 52, 31},
327 {46000, 18, 23, 15},
328 {46750, 20, 45, 26},
329 {47000, 20, 40, 23},
330 {48000, 18, 24, 15},
331 {49000, 18, 49, 30},
332 {49500, 16, 22, 15},
333 {50000, 18, 25, 15},
334 {50500, 18, 32, 19},
335 {51000, 18, 34, 20},
336 {52000, 18, 26, 15},
337 {52406, 14, 34, 25},
338 {53000, 16, 22, 14},
339 {54000, 16, 24, 15},
340 {54054, 16, 173, 108},
341 {54500, 14, 24, 17},
342 {55000, 12, 22, 18},
343 {56000, 14, 45, 31},
344 {56250, 16, 25, 15},
345 {56750, 14, 25, 17},
346 {57000, 16, 27, 16},
347 {58000, 16, 43, 25},
348 {58250, 16, 38, 22},
349 {58750, 16, 40, 23},
350 {59000, 14, 26, 17},
351 {59341, 14, 40, 26},
352 {59400, 16, 44, 25},
353 {60000, 16, 32, 18},
354 {60500, 12, 39, 29},
355 {61000, 14, 49, 31},
356 {62000, 14, 37, 23},
357 {62250, 14, 42, 26},
358 {63000, 12, 21, 15},
359 {63500, 14, 28, 17},
360 {64000, 12, 27, 19},
361 {65000, 14, 32, 19},
362 {65250, 12, 29, 20},
363 {65500, 12, 32, 22},
364 {66000, 12, 22, 15},
365 {66667, 14, 38, 22},
366 {66750, 10, 21, 17},
367 {67000, 14, 33, 19},
368 {67750, 14, 58, 33},
369 {68000, 14, 30, 17},
370 {68179, 14, 46, 26},
371 {68250, 14, 46, 26},
372 {69000, 12, 23, 15},
373 {70000, 12, 28, 18},
374 {71000, 12, 30, 19},
375 {72000, 12, 24, 15},
376 {73000, 10, 23, 17},
377 {74000, 12, 23, 14},
378 {74176, 8, 100, 91},
379 {74250, 10, 22, 16},
380 {74481, 12, 43, 26},
381 {74500, 10, 29, 21},
382 {75000, 12, 25, 15},
383 {75250, 10, 39, 28},
384 {76000, 12, 27, 16},
385 {77000, 12, 53, 31},
386 {78000, 12, 26, 15},
387 {78750, 12, 28, 16},
388 {79000, 10, 38, 26},
389 {79500, 10, 28, 19},
390 {80000, 12, 32, 18},
391 {81000, 10, 21, 14},
392 {81081, 6, 100, 111},
393 {81624, 8, 29, 24},
394 {82000, 8, 17, 14},
395 {83000, 10, 40, 26},
396 {83950, 10, 28, 18},
397 {84000, 10, 28, 18},
398 {84750, 6, 16, 17},
399 {85000, 6, 17, 18},
400 {85250, 10, 30, 19},
401 {85750, 10, 27, 17},
402 {86000, 10, 43, 27},
403 {87000, 10, 29, 18},
404 {88000, 10, 44, 27},
405 {88500, 10, 41, 25},
406 {89000, 10, 28, 17},
407 {89012, 6, 90, 91},
408 {89100, 10, 33, 20},
409 {90000, 10, 25, 15},
410 {91000, 10, 32, 19},
411 {92000, 10, 46, 27},
412 {93000, 10, 31, 18},
413 {94000, 10, 40, 23},
414 {94500, 10, 28, 16},
415 {95000, 10, 44, 25},
416 {95654, 10, 39, 22},
417 {95750, 10, 39, 22},
418 {96000, 10, 32, 18},
419 {97000, 8, 23, 16},
420 {97750, 8, 42, 29},
421 {98000, 8, 45, 31},
422 {99000, 8, 22, 15},
423 {99750, 8, 34, 23},
424 {100000, 6, 20, 18},
425 {100500, 6, 19, 17},
426 {101000, 6, 37, 33},
427 {101250, 8, 21, 14},
428 {102000, 6, 17, 15},
429 {102250, 6, 25, 22},
430 {103000, 8, 29, 19},
431 {104000, 8, 37, 24},
432 {105000, 8, 28, 18},
433 {106000, 8, 22, 14},
434 {107000, 8, 46, 29},
435 {107214, 8, 27, 17},
436 {108000, 8, 24, 15},
437 {108108, 8, 173, 108},
438 {109000, 6, 23, 19},
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300439 {110000, 6, 22, 18},
440 {110013, 6, 22, 18},
441 {110250, 8, 49, 30},
442 {110500, 8, 36, 22},
443 {111000, 8, 23, 14},
444 {111264, 8, 150, 91},
445 {111375, 8, 33, 20},
446 {112000, 8, 63, 38},
447 {112500, 8, 25, 15},
448 {113100, 8, 57, 34},
449 {113309, 8, 42, 25},
450 {114000, 8, 27, 16},
451 {115000, 6, 23, 18},
452 {116000, 8, 43, 25},
453 {117000, 8, 26, 15},
454 {117500, 8, 40, 23},
455 {118000, 6, 38, 29},
456 {119000, 8, 30, 17},
457 {119500, 8, 46, 26},
458 {119651, 8, 39, 22},
459 {120000, 8, 32, 18},
460 {121000, 6, 39, 29},
461 {121250, 6, 31, 23},
462 {121750, 6, 23, 17},
463 {122000, 6, 42, 31},
464 {122614, 6, 30, 22},
465 {123000, 6, 41, 30},
466 {123379, 6, 37, 27},
467 {124000, 6, 51, 37},
468 {125000, 6, 25, 18},
469 {125250, 4, 13, 14},
470 {125750, 4, 27, 29},
471 {126000, 6, 21, 15},
472 {127000, 6, 24, 17},
473 {127250, 6, 41, 29},
474 {128000, 6, 27, 19},
475 {129000, 6, 43, 30},
476 {129859, 4, 25, 26},
477 {130000, 6, 26, 18},
478 {130250, 6, 42, 29},
479 {131000, 6, 32, 22},
480 {131500, 6, 38, 26},
481 {131850, 6, 41, 28},
482 {132000, 6, 22, 15},
483 {132750, 6, 28, 19},
484 {133000, 6, 34, 23},
485 {133330, 6, 37, 25},
486 {134000, 6, 61, 41},
487 {135000, 6, 21, 14},
488 {135250, 6, 167, 111},
489 {136000, 6, 62, 41},
490 {137000, 6, 35, 23},
491 {138000, 6, 23, 15},
492 {138500, 6, 40, 26},
493 {138750, 6, 37, 24},
494 {139000, 6, 34, 22},
495 {139050, 6, 34, 22},
496 {139054, 6, 34, 22},
497 {140000, 6, 28, 18},
498 {141000, 6, 36, 23},
499 {141500, 6, 22, 14},
500 {142000, 6, 30, 19},
501 {143000, 6, 27, 17},
502 {143472, 4, 17, 16},
503 {144000, 6, 24, 15},
504 {145000, 6, 29, 18},
505 {146000, 6, 47, 29},
506 {146250, 6, 26, 16},
507 {147000, 6, 49, 30},
508 {147891, 6, 23, 14},
509 {148000, 6, 23, 14},
510 {148250, 6, 28, 17},
511 {148352, 4, 100, 91},
512 {148500, 6, 33, 20},
513 {149000, 6, 48, 29},
514 {150000, 6, 25, 15},
515 {151000, 4, 19, 17},
516 {152000, 6, 27, 16},
517 {152280, 6, 44, 26},
518 {153000, 6, 34, 20},
519 {154000, 6, 53, 31},
520 {155000, 6, 31, 18},
521 {155250, 6, 50, 29},
522 {155750, 6, 45, 26},
523 {156000, 6, 26, 15},
524 {157000, 6, 61, 35},
525 {157500, 6, 28, 16},
526 {158000, 6, 65, 37},
527 {158250, 6, 44, 25},
528 {159000, 6, 53, 30},
529 {159500, 6, 39, 22},
530 {160000, 6, 32, 18},
531 {161000, 4, 31, 26},
532 {162000, 4, 18, 15},
533 {162162, 4, 131, 109},
534 {162500, 4, 53, 44},
535 {163000, 4, 29, 24},
536 {164000, 4, 17, 14},
537 {165000, 4, 22, 18},
538 {166000, 4, 32, 26},
539 {167000, 4, 26, 21},
540 {168000, 4, 46, 37},
541 {169000, 4, 104, 83},
542 {169128, 4, 64, 51},
543 {169500, 4, 39, 31},
544 {170000, 4, 34, 27},
545 {171000, 4, 19, 15},
546 {172000, 4, 51, 40},
547 {172750, 4, 32, 25},
548 {172800, 4, 32, 25},
549 {173000, 4, 41, 32},
550 {174000, 4, 49, 38},
551 {174787, 4, 22, 17},
552 {175000, 4, 35, 27},
553 {176000, 4, 30, 23},
554 {177000, 4, 38, 29},
555 {178000, 4, 29, 22},
556 {178500, 4, 37, 28},
557 {179000, 4, 53, 40},
558 {179500, 4, 73, 55},
559 {180000, 4, 20, 15},
560 {181000, 4, 55, 41},
561 {182000, 4, 31, 23},
562 {183000, 4, 42, 31},
563 {184000, 4, 30, 22},
564 {184750, 4, 26, 19},
565 {185000, 4, 37, 27},
566 {186000, 4, 51, 37},
567 {187000, 4, 36, 26},
568 {188000, 4, 32, 23},
569 {189000, 4, 21, 15},
570 {190000, 4, 38, 27},
571 {190960, 4, 41, 29},
572 {191000, 4, 41, 29},
573 {192000, 4, 27, 19},
574 {192250, 4, 37, 26},
575 {193000, 4, 20, 14},
576 {193250, 4, 53, 37},
577 {194000, 4, 23, 16},
578 {194208, 4, 23, 16},
579 {195000, 4, 26, 18},
580 {196000, 4, 45, 31},
581 {197000, 4, 35, 24},
582 {197750, 4, 41, 28},
583 {198000, 4, 22, 15},
584 {198500, 4, 25, 17},
585 {199000, 4, 28, 19},
586 {200000, 4, 37, 25},
587 {201000, 4, 61, 41},
588 {202000, 4, 112, 75},
589 {202500, 4, 21, 14},
590 {203000, 4, 146, 97},
591 {204000, 4, 62, 41},
592 {204750, 4, 44, 29},
593 {205000, 4, 38, 25},
594 {206000, 4, 29, 19},
595 {207000, 4, 23, 15},
596 {207500, 4, 40, 26},
597 {208000, 4, 37, 24},
598 {208900, 4, 48, 31},
599 {209000, 4, 48, 31},
600 {209250, 4, 31, 20},
601 {210000, 4, 28, 18},
602 {211000, 4, 25, 16},
603 {212000, 4, 22, 14},
604 {213000, 4, 30, 19},
605 {213750, 4, 38, 24},
606 {214000, 4, 46, 29},
607 {214750, 4, 35, 22},
608 {215000, 4, 43, 27},
609 {216000, 4, 24, 15},
610 {217000, 4, 37, 23},
611 {218000, 4, 42, 26},
612 {218250, 4, 42, 26},
613 {218750, 4, 34, 21},
614 {219000, 4, 47, 29},
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300615 {220000, 4, 44, 27},
616 {220640, 4, 49, 30},
617 {220750, 4, 36, 22},
618 {221000, 4, 36, 22},
619 {222000, 4, 23, 14},
620 {222525, 4, 28, 17},
621 {222750, 4, 33, 20},
622 {227000, 4, 37, 22},
623 {230250, 4, 29, 17},
624 {233500, 4, 38, 22},
625 {235000, 4, 40, 23},
626 {238000, 4, 30, 17},
627 {241500, 2, 17, 19},
628 {245250, 2, 20, 22},
629 {247750, 2, 22, 24},
630 {253250, 2, 15, 16},
631 {256250, 2, 18, 19},
632 {262500, 2, 31, 32},
633 {267250, 2, 66, 67},
634 {268500, 2, 94, 95},
635 {270000, 2, 14, 14},
636 {272500, 2, 77, 76},
637 {273750, 2, 57, 56},
638 {280750, 2, 24, 23},
639 {281250, 2, 23, 22},
640 {286000, 2, 17, 16},
641 {291750, 2, 26, 24},
642 {296703, 2, 56, 51},
643 {297000, 2, 22, 20},
644 {298000, 2, 21, 19},
645};
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300646
647void intel_ddi_mode_set(struct drm_encoder *encoder,
648 struct drm_display_mode *mode,
649 struct drm_display_mode *adjusted_mode)
650{
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300651 struct drm_crtc *crtc = encoder->crtc;
652 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300653 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
654 int port = intel_ddi_get_encoder_port(intel_encoder);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300655 int pipe = intel_crtc->pipe;
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300656 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300657
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300658 DRM_DEBUG_KMS("Preparing DDI mode for Haswell on port %c, pipe %c\n",
659 port_name(port), pipe_name(pipe));
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300660
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300661 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
662 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Wang Xingchao4f078542012-08-09 16:52:16 +0800663
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300664 intel_dp->DP = DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
665 switch (intel_dp->lane_count) {
666 case 1:
667 intel_dp->DP |= DDI_PORT_WIDTH_X1;
668 break;
669 case 2:
670 intel_dp->DP |= DDI_PORT_WIDTH_X2;
671 break;
672 case 4:
673 intel_dp->DP |= DDI_PORT_WIDTH_X4;
674 break;
675 default:
676 intel_dp->DP |= DDI_PORT_WIDTH_X4;
677 WARN(1, "Unexpected DP lane count %d\n",
678 intel_dp->lane_count);
679 break;
680 }
681
682 intel_dp_init_link_config(intel_dp);
683
684 } else if (type == INTEL_OUTPUT_HDMI) {
685 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
686
687 if (intel_hdmi->has_audio) {
688 /* Proper support for digital audio needs a new logic
689 * and a new set of registers, so we leave it for future
690 * patch bombing.
691 */
692 DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
693 pipe_name(intel_crtc->pipe));
694
695 /* write eld */
696 DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
697 intel_write_eld(encoder, adjusted_mode);
698 }
699
700 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300701 }
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300702}
703
704static struct intel_encoder *
705intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
706{
707 struct drm_device *dev = crtc->dev;
708 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
709 struct intel_encoder *intel_encoder, *ret = NULL;
710 int num_encoders = 0;
711
712 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
713 ret = intel_encoder;
714 num_encoders++;
715 }
716
717 if (num_encoders != 1)
718 WARN(1, "%d encoders on crtc for pipe %d\n", num_encoders,
719 intel_crtc->pipe);
720
721 BUG_ON(ret == NULL);
722 return ret;
723}
724
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300725void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
726{
727 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
728 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
729 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
730 uint32_t val;
731
732 switch (intel_crtc->ddi_pll_sel) {
733 case PORT_CLK_SEL_SPLL:
734 plls->spll_refcount--;
735 if (plls->spll_refcount == 0) {
736 DRM_DEBUG_KMS("Disabling SPLL\n");
737 val = I915_READ(SPLL_CTL);
738 WARN_ON(!(val & SPLL_PLL_ENABLE));
739 I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
740 POSTING_READ(SPLL_CTL);
741 }
742 break;
743 case PORT_CLK_SEL_WRPLL1:
744 plls->wrpll1_refcount--;
745 if (plls->wrpll1_refcount == 0) {
746 DRM_DEBUG_KMS("Disabling WRPLL 1\n");
747 val = I915_READ(WRPLL_CTL1);
748 WARN_ON(!(val & WRPLL_PLL_ENABLE));
749 I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
750 POSTING_READ(WRPLL_CTL1);
751 }
752 break;
753 case PORT_CLK_SEL_WRPLL2:
754 plls->wrpll2_refcount--;
755 if (plls->wrpll2_refcount == 0) {
756 DRM_DEBUG_KMS("Disabling WRPLL 2\n");
757 val = I915_READ(WRPLL_CTL2);
758 WARN_ON(!(val & WRPLL_PLL_ENABLE));
759 I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
760 POSTING_READ(WRPLL_CTL2);
761 }
762 break;
763 }
764
765 WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
766 WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
767 WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
768
769 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
770}
771
772static void intel_ddi_calculate_wrpll(int clock, int *p, int *n2, int *r2)
773{
774 u32 i;
775
776 for (i = 0; i < ARRAY_SIZE(wrpll_tmds_clock_table); i++)
777 if (clock <= wrpll_tmds_clock_table[i].clock)
778 break;
779
780 if (i == ARRAY_SIZE(wrpll_tmds_clock_table))
781 i--;
782
783 *p = wrpll_tmds_clock_table[i].p;
784 *n2 = wrpll_tmds_clock_table[i].n2;
785 *r2 = wrpll_tmds_clock_table[i].r2;
786
787 if (wrpll_tmds_clock_table[i].clock != clock)
788 DRM_INFO("WRPLL: using settings for %dKHz on %dKHz mode\n",
789 wrpll_tmds_clock_table[i].clock, clock);
790
791 DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
792 clock, *p, *n2, *r2);
793}
794
795bool intel_ddi_pll_mode_set(struct drm_crtc *crtc, int clock)
796{
797 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
798 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni068759b2012-10-15 15:51:31 -0300799 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300800 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
801 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
802 int type = intel_encoder->type;
803 enum pipe pipe = intel_crtc->pipe;
804 uint32_t reg, val;
805
806 /* TODO: reuse PLLs when possible (compare values) */
807
808 intel_ddi_put_crtc_pll(crtc);
809
Paulo Zanoni068759b2012-10-15 15:51:31 -0300810 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
811 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
812
813 switch (intel_dp->link_bw) {
814 case DP_LINK_BW_1_62:
815 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
816 break;
817 case DP_LINK_BW_2_7:
818 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
819 break;
820 case DP_LINK_BW_5_4:
821 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
822 break;
823 default:
824 DRM_ERROR("Link bandwidth %d unsupported\n",
825 intel_dp->link_bw);
826 return false;
827 }
828
829 /* We don't need to turn any PLL on because we'll use LCPLL. */
830 return true;
831
832 } else if (type == INTEL_OUTPUT_HDMI) {
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300833 int p, n2, r2;
834
835 if (plls->wrpll1_refcount == 0) {
836 DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
837 pipe_name(pipe));
838 plls->wrpll1_refcount++;
839 reg = WRPLL_CTL1;
840 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
841 } else if (plls->wrpll2_refcount == 0) {
842 DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
843 pipe_name(pipe));
844 plls->wrpll2_refcount++;
845 reg = WRPLL_CTL2;
846 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
847 } else {
848 DRM_ERROR("No WRPLLs available!\n");
849 return false;
850 }
851
852 WARN(I915_READ(reg) & WRPLL_PLL_ENABLE,
853 "WRPLL already enabled\n");
854
855 intel_ddi_calculate_wrpll(clock, &p, &n2, &r2);
856
857 val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
858 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
859 WRPLL_DIVIDER_POST(p);
860
861 } else if (type == INTEL_OUTPUT_ANALOG) {
862 if (plls->spll_refcount == 0) {
863 DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
864 pipe_name(pipe));
865 plls->spll_refcount++;
866 reg = SPLL_CTL;
867 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
868 }
869
870 WARN(I915_READ(reg) & SPLL_PLL_ENABLE,
871 "SPLL already enabled\n");
872
Damien Lespiau39bc66c2012-10-11 15:24:04 +0100873 val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz | SPLL_PLL_SSC;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300874
875 } else {
876 WARN(1, "Invalid DDI encoder type %d\n", type);
877 return false;
878 }
879
880 I915_WRITE(reg, val);
881 udelay(20);
882
883 return true;
884}
885
Paulo Zanonidae84792012-10-15 15:51:30 -0300886void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
887{
888 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
889 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
890 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanonic9809792012-10-23 18:30:00 -0200891 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300892 int type = intel_encoder->type;
893 uint32_t temp;
894
895 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
896
Paulo Zanonic9809792012-10-23 18:30:00 -0200897 temp = TRANS_MSA_SYNC_CLK;
Paulo Zanonidae84792012-10-15 15:51:30 -0300898 switch (intel_crtc->bpp) {
899 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200900 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300901 break;
902 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200903 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300904 break;
905 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200906 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300907 break;
908 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200909 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300910 break;
911 default:
Paulo Zanonic9809792012-10-23 18:30:00 -0200912 temp |= TRANS_MSA_8_BPC;
913 WARN(1, "%d bpp unsupported by DDI function\n",
Paulo Zanonidae84792012-10-15 15:51:30 -0300914 intel_crtc->bpp);
915 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200916 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300917 }
918}
919
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300920void intel_ddi_enable_pipe_func(struct drm_crtc *crtc)
921{
922 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
923 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300924 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300925 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
926 enum pipe pipe = intel_crtc->pipe;
Paulo Zanoniad80a812012-10-24 16:06:19 -0200927 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300928 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300929 uint32_t temp;
930
Paulo Zanoniad80a812012-10-24 16:06:19 -0200931 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
932 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300933
934 switch (intel_crtc->bpp) {
935 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200936 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300937 break;
938 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200939 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300940 break;
941 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200942 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300943 break;
944 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200945 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300946 break;
947 default:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200948 WARN(1, "%d bpp unsupported by transcoder DDI function\n",
Paulo Zanonidfcef252012-08-08 14:15:29 -0300949 intel_crtc->bpp);
950 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300951
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300952 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200953 temp |= TRANS_DDI_PVSYNC;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300954 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200955 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -0300956
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200957 if (cpu_transcoder == TRANSCODER_EDP) {
958 switch (pipe) {
959 case PIPE_A:
960 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
961 break;
962 case PIPE_B:
963 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
964 break;
965 case PIPE_C:
966 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
967 break;
968 default:
969 BUG();
970 break;
971 }
972 }
973
Paulo Zanoni7739c332012-10-15 15:51:29 -0300974 if (type == INTEL_OUTPUT_HDMI) {
975 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300976
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300977 if (intel_hdmi->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200978 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300979 else
Paulo Zanoniad80a812012-10-24 16:06:19 -0200980 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300981
Paulo Zanoniad80a812012-10-24 16:06:19 -0200982 temp |= TRANS_DDI_SELECT_PORT(intel_hdmi->ddi_port);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300983
984 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -0200985 temp |= TRANS_DDI_MODE_SELECT_FDI;
986 temp |= TRANS_DDI_SELECT_PORT(PORT_E);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300987
988 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
989 type == INTEL_OUTPUT_EDP) {
990 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
991
Paulo Zanoniad80a812012-10-24 16:06:19 -0200992 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
993 temp |= TRANS_DDI_SELECT_PORT(intel_dp->port);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300994
995 switch (intel_dp->lane_count) {
996 case 1:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200997 temp |= TRANS_DDI_PORT_WIDTH_X1;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300998 break;
999 case 2:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001000 temp |= TRANS_DDI_PORT_WIDTH_X2;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001001 break;
1002 case 4:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001003 temp |= TRANS_DDI_PORT_WIDTH_X4;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001004 break;
1005 default:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001006 temp |= TRANS_DDI_PORT_WIDTH_X4;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001007 WARN(1, "Unsupported lane count %d\n",
1008 intel_dp->lane_count);
1009 }
1010
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001011 } else {
1012 WARN(1, "Invalid encoder type %d for pipe %d\n",
1013 intel_encoder->type, pipe);
1014 }
1015
Paulo Zanoniad80a812012-10-24 16:06:19 -02001016 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001017}
1018
Paulo Zanoniad80a812012-10-24 16:06:19 -02001019void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1020 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001021{
Paulo Zanoniad80a812012-10-24 16:06:19 -02001022 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001023 uint32_t val = I915_READ(reg);
1024
Paulo Zanoniad80a812012-10-24 16:06:19 -02001025 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
1026 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001027 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001028}
1029
Daniel Vetter85234cd2012-07-02 13:27:29 +02001030bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1031 enum pipe *pipe)
1032{
1033 struct drm_device *dev = encoder->base.dev;
1034 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001035 enum port port = intel_ddi_get_encoder_port(encoder);
Daniel Vetter85234cd2012-07-02 13:27:29 +02001036 u32 tmp;
1037 int i;
1038
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001039 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001040
1041 if (!(tmp & DDI_BUF_CTL_ENABLE))
1042 return false;
1043
Paulo Zanoniad80a812012-10-24 16:06:19 -02001044 if (port == PORT_A) {
1045 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001046
Paulo Zanoniad80a812012-10-24 16:06:19 -02001047 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1048 case TRANS_DDI_EDP_INPUT_A_ON:
1049 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1050 *pipe = PIPE_A;
1051 break;
1052 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1053 *pipe = PIPE_B;
1054 break;
1055 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1056 *pipe = PIPE_C;
1057 break;
1058 }
1059
1060 return true;
1061 } else {
1062 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1063 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1064
1065 if ((tmp & TRANS_DDI_PORT_MASK)
1066 == TRANS_DDI_SELECT_PORT(port)) {
1067 *pipe = i;
1068 return true;
1069 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001070 }
1071 }
1072
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001073 DRM_DEBUG_KMS("No pipe for ddi port %i found\n", port);
Daniel Vetter85234cd2012-07-02 13:27:29 +02001074
1075 return true;
1076}
1077
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001078static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
1079 enum pipe pipe)
1080{
1081 uint32_t temp, ret;
1082 enum port port;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001083 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1084 pipe);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001085 int i;
1086
Paulo Zanoniad80a812012-10-24 16:06:19 -02001087 if (cpu_transcoder == TRANSCODER_EDP) {
1088 port = PORT_A;
1089 } else {
1090 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1091 temp &= TRANS_DDI_PORT_MASK;
1092
1093 for (i = PORT_B; i <= PORT_E; i++)
1094 if (temp == TRANS_DDI_SELECT_PORT(i))
1095 port = i;
1096 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001097
1098 ret = I915_READ(PORT_CLK_SEL(port));
1099
1100 DRM_DEBUG_KMS("Pipe %c connected to port %c using clock 0x%08x\n",
1101 pipe_name(pipe), port_name(port), ret);
1102
1103 return ret;
1104}
1105
1106void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
1107{
1108 struct drm_i915_private *dev_priv = dev->dev_private;
1109 enum pipe pipe;
1110 struct intel_crtc *intel_crtc;
1111
1112 for_each_pipe(pipe) {
1113 intel_crtc =
1114 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1115
1116 if (!intel_crtc->active)
1117 continue;
1118
1119 intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
1120 pipe);
1121
1122 switch (intel_crtc->ddi_pll_sel) {
1123 case PORT_CLK_SEL_SPLL:
1124 dev_priv->ddi_plls.spll_refcount++;
1125 break;
1126 case PORT_CLK_SEL_WRPLL1:
1127 dev_priv->ddi_plls.wrpll1_refcount++;
1128 break;
1129 case PORT_CLK_SEL_WRPLL2:
1130 dev_priv->ddi_plls.wrpll2_refcount++;
1131 break;
1132 }
1133 }
1134}
1135
Paulo Zanonifc914632012-10-05 12:05:54 -03001136void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1137{
1138 struct drm_crtc *crtc = &intel_crtc->base;
1139 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1140 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1141 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001142 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001143
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001144 if (cpu_transcoder != TRANSCODER_EDP)
1145 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1146 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001147}
1148
1149void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1150{
1151 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001152 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001153
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001154 if (cpu_transcoder != TRANSCODER_EDP)
1155 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1156 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001157}
1158
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001159void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
1160{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001161 struct drm_encoder *encoder = &intel_encoder->base;
1162 struct drm_crtc *crtc = encoder->crtc;
1163 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001164 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1165 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001166 int type = intel_encoder->type;
1167
1168 if (type == INTEL_OUTPUT_EDP) {
1169 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1170 ironlake_edp_panel_vdd_on(intel_dp);
1171 ironlake_edp_panel_on(intel_dp);
1172 ironlake_edp_panel_vdd_off(intel_dp, true);
1173 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001174
1175 WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001176 I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001177
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001178 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001179 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1180
1181 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1182 intel_dp_start_link_train(intel_dp);
1183 intel_dp_complete_link_train(intel_dp);
1184 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001185}
1186
Paulo Zanoni2886e932012-10-05 12:06:00 -03001187static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
1188 enum port port)
1189{
1190 uint32_t reg = DDI_BUF_CTL(port);
1191 int i;
1192
1193 for (i = 0; i < 8; i++) {
1194 udelay(1);
1195 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
1196 return;
1197 }
1198 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
1199}
1200
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001201void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
1202{
1203 struct drm_encoder *encoder = &intel_encoder->base;
1204 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1205 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001206 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001207 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001208 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001209
1210 val = I915_READ(DDI_BUF_CTL(port));
1211 if (val & DDI_BUF_CTL_ENABLE) {
1212 val &= ~DDI_BUF_CTL_ENABLE;
1213 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001214 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001215 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001216
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001217 val = I915_READ(DP_TP_CTL(port));
1218 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1219 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1220 I915_WRITE(DP_TP_CTL(port), val);
1221
1222 if (wait)
1223 intel_wait_ddi_buf_idle(dev_priv, port);
1224
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001225 if (type == INTEL_OUTPUT_EDP) {
1226 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1227 ironlake_edp_panel_vdd_on(intel_dp);
1228 ironlake_edp_panel_off(intel_dp);
1229 }
1230
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001231 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1232}
1233
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001234void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001235{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001236 struct drm_encoder *encoder = &intel_encoder->base;
1237 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001238 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001239 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1240 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001241
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001242 if (type == INTEL_OUTPUT_HDMI) {
1243 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1244 * are ignored so nothing special needs to be done besides
1245 * enabling the port.
1246 */
1247 I915_WRITE(DDI_BUF_CTL(port), DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001248 } else if (type == INTEL_OUTPUT_EDP) {
1249 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1250
1251 ironlake_edp_backlight_on(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001252 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001253}
1254
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001255void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001256{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001257 struct drm_encoder *encoder = &intel_encoder->base;
1258 int type = intel_encoder->type;
1259
1260 if (type == INTEL_OUTPUT_EDP) {
1261 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1262
1263 ironlake_edp_backlight_off(intel_dp);
1264 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001265}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001266
Paulo Zanonib8fc2f62012-10-23 18:30:05 -02001267int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001268{
1269 if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT)
1270 return 450;
1271 else if ((I915_READ(LCPLL_CTL) & LCPLL_CLK_FREQ_MASK) ==
1272 LCPLL_CLK_FREQ_450)
1273 return 450;
1274 else
1275 return 540;
1276}
1277
1278void intel_ddi_pll_init(struct drm_device *dev)
1279{
1280 struct drm_i915_private *dev_priv = dev->dev_private;
1281 uint32_t val = I915_READ(LCPLL_CTL);
1282
1283 /* The LCPLL register should be turned on by the BIOS. For now let's
1284 * just check its state and print errors in case something is wrong.
1285 * Don't even try to turn it on.
1286 */
1287
1288 DRM_DEBUG_KMS("CDCLK running at %dMHz\n",
1289 intel_ddi_get_cdclk_freq(dev_priv));
1290
1291 if (val & LCPLL_CD_SOURCE_FCLK)
1292 DRM_ERROR("CDCLK source is not LCPLL\n");
1293
1294 if (val & LCPLL_PLL_DISABLE)
1295 DRM_ERROR("LCPLL is disabled\n");
1296}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001297
1298void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1299{
1300 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1301 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1302 enum port port = intel_dp->port;
1303 bool wait;
1304 uint32_t val;
1305
1306 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1307 val = I915_READ(DDI_BUF_CTL(port));
1308 if (val & DDI_BUF_CTL_ENABLE) {
1309 val &= ~DDI_BUF_CTL_ENABLE;
1310 I915_WRITE(DDI_BUF_CTL(port), val);
1311 wait = true;
1312 }
1313
1314 val = I915_READ(DP_TP_CTL(port));
1315 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1316 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1317 I915_WRITE(DP_TP_CTL(port), val);
1318 POSTING_READ(DP_TP_CTL(port));
1319
1320 if (wait)
1321 intel_wait_ddi_buf_idle(dev_priv, port);
1322 }
1323
1324 val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
1325 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
1326 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
1327 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1328 I915_WRITE(DP_TP_CTL(port), val);
1329 POSTING_READ(DP_TP_CTL(port));
1330
1331 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1332 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1333 POSTING_READ(DDI_BUF_CTL(port));
1334
1335 udelay(600);
1336}