blob: 67bd6ba64a35920a4ac8356b89c9da4829fce01f [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 Zanoni174edf12012-10-26 19:05:50 -020066 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
Paulo Zanoni00c09d72012-10-26 19:05:52 -020067 type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
Paulo Zanoni174edf12012-10-26 19:05:50 -020068 struct intel_digital_port *intel_dig_port =
69 enc_to_dig_port(encoder);
70 return intel_dig_port->port;
Paulo Zanoni0bdee302012-10-15 15:51:38 -030071
Paulo Zanonifc914632012-10-05 12:05:54 -030072 } else if (type == INTEL_OUTPUT_ANALOG) {
73 return PORT_E;
Paulo Zanoni0bdee302012-10-15 15:51:38 -030074
Paulo Zanonifc914632012-10-05 12:05:54 -030075 } else {
76 DRM_ERROR("Invalid DDI encoder type %d\n", type);
77 BUG();
78 }
79}
80
Eugeni Dodonov45244b82012-05-09 15:37:20 -030081/* On Haswell, DDI port buffers must be programmed with correct values
82 * in advance. The buffer values are different for FDI and DP modes,
83 * but the HDMI/DVI fields are shared among those. So we program the DDI
84 * in either FDI or DP modes only, as HDMI connections will work with both
85 * of those
86 */
87void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port, bool use_fdi_mode)
88{
89 struct drm_i915_private *dev_priv = dev->dev_private;
90 u32 reg;
91 int i;
92 const u32 *ddi_translations = ((use_fdi_mode) ?
93 hsw_ddi_translations_fdi :
94 hsw_ddi_translations_dp);
95
96 DRM_DEBUG_DRIVER("Initializing DDI buffers for port %c in %s mode\n",
97 port_name(port),
98 use_fdi_mode ? "FDI" : "DP");
99
100 WARN((use_fdi_mode && (port != PORT_E)),
101 "Programming port %c in FDI mode, this probably will not work.\n",
102 port_name(port));
103
104 for (i=0, reg=DDI_BUF_TRANS(port); i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
105 I915_WRITE(reg, ddi_translations[i]);
106 reg += 4;
107 }
108}
109
110/* Program DDI buffers translations for DP. By default, program ports A-D in DP
111 * mode and port E for FDI.
112 */
113void intel_prepare_ddi(struct drm_device *dev)
114{
115 int port;
116
117 if (IS_HASWELL(dev)) {
118 for (port = PORT_A; port < PORT_E; port++)
119 intel_prepare_ddi_buffers(dev, port, false);
120
121 /* DDI E is the suggested one to work in FDI mode, so program is as such by
122 * default. It will have to be re-programmed in case a digital DP output
123 * will be detected on it
124 */
125 intel_prepare_ddi_buffers(dev, PORT_E, true);
126 }
127}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300128
129static const long hsw_ddi_buf_ctl_values[] = {
130 DDI_BUF_EMP_400MV_0DB_HSW,
131 DDI_BUF_EMP_400MV_3_5DB_HSW,
132 DDI_BUF_EMP_400MV_6DB_HSW,
133 DDI_BUF_EMP_400MV_9_5DB_HSW,
134 DDI_BUF_EMP_600MV_0DB_HSW,
135 DDI_BUF_EMP_600MV_3_5DB_HSW,
136 DDI_BUF_EMP_600MV_6DB_HSW,
137 DDI_BUF_EMP_800MV_0DB_HSW,
138 DDI_BUF_EMP_800MV_3_5DB_HSW
139};
140
141
142/* Starting with Haswell, different DDI ports can work in FDI mode for
143 * connection to the PCH-located connectors. For this, it is necessary to train
144 * both the DDI port and PCH receiver for the desired DDI buffer settings.
145 *
146 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
147 * please note that when FDI mode is active on DDI E, it shares 2 lines with
148 * DDI A (which is used for eDP)
149 */
150
151void hsw_fdi_link_train(struct drm_crtc *crtc)
152{
153 struct drm_device *dev = crtc->dev;
154 struct drm_i915_private *dev_priv = dev->dev_private;
155 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
156 int pipe = intel_crtc->pipe;
157 u32 reg, temp, i;
158
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300159 /* Start the training iterating through available voltages and emphasis */
160 for (i=0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values); i++) {
161 /* Configure DP_TP_CTL with auto-training */
162 I915_WRITE(DP_TP_CTL(PORT_E),
163 DP_TP_CTL_FDI_AUTOTRAIN |
164 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
165 DP_TP_CTL_LINK_TRAIN_PAT1 |
166 DP_TP_CTL_ENABLE);
167
168 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage */
169 temp = I915_READ(DDI_BUF_CTL(PORT_E));
170 temp = (temp & ~DDI_BUF_EMP_MASK);
171 I915_WRITE(DDI_BUF_CTL(PORT_E),
172 temp |
173 DDI_BUF_CTL_ENABLE |
174 DDI_PORT_WIDTH_X2 |
175 hsw_ddi_buf_ctl_values[i]);
176
177 udelay(600);
178
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300179 /* We need to program FDI_RX_MISC with the default TP1 to TP2
180 * values before enabling the receiver, and configure the delay
181 * for the FDI timing generator to 90h. Luckily, all the other
182 * bits are supposed to be zeroed, so we can write those values
183 * directly.
184 */
185 I915_WRITE(FDI_RX_MISC(pipe), FDI_RX_TP1_TO_TP2_48 |
186 FDI_RX_FDI_DELAY_90);
187
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300188 /* Enable CPU FDI Receiver with auto-training */
189 reg = FDI_RX_CTL(pipe);
190 I915_WRITE(reg,
191 I915_READ(reg) |
192 FDI_LINK_TRAIN_AUTO |
193 FDI_RX_ENABLE |
194 FDI_LINK_TRAIN_PATTERN_1_CPT |
195 FDI_RX_ENHANCE_FRAME_ENABLE |
196 FDI_PORT_WIDTH_2X_LPT |
197 FDI_RX_PLL_ENABLE);
198 POSTING_READ(reg);
199 udelay(100);
200
201 temp = I915_READ(DP_TP_STATUS(PORT_E));
202 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
203 DRM_DEBUG_DRIVER("BUF_CTL training done on %d step\n", i);
204
205 /* Enable normal pixel sending for FDI */
206 I915_WRITE(DP_TP_CTL(PORT_E),
207 DP_TP_CTL_FDI_AUTOTRAIN |
208 DP_TP_CTL_LINK_TRAIN_NORMAL |
209 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
210 DP_TP_CTL_ENABLE);
211
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300212 break;
213 } else {
214 DRM_ERROR("Error training BUF_CTL %d\n", i);
215
216 /* Disable DP_TP_CTL and FDI_RX_CTL) and retry */
217 I915_WRITE(DP_TP_CTL(PORT_E),
218 I915_READ(DP_TP_CTL(PORT_E)) &
219 ~DP_TP_CTL_ENABLE);
220 I915_WRITE(FDI_RX_CTL(pipe),
221 I915_READ(FDI_RX_CTL(pipe)) &
222 ~FDI_RX_PLL_ENABLE);
223 continue;
224 }
225 }
226
227 DRM_DEBUG_KMS("FDI train done.\n");
228}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300229
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300230/* WRPLL clock dividers */
231struct wrpll_tmds_clock {
232 u32 clock;
233 u16 p; /* Post divider */
234 u16 n2; /* Feedback divider */
235 u16 r2; /* Reference divider */
236};
237
Paulo Zanoni126e9be2012-08-10 10:03:03 -0300238/* Table of matching values for WRPLL clocks programming for each frequency.
239 * The code assumes this table is sorted. */
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300240static const struct wrpll_tmds_clock wrpll_tmds_clock_table[] = {
241 {19750, 38, 25, 18},
242 {20000, 48, 32, 18},
243 {21000, 36, 21, 15},
244 {21912, 42, 29, 17},
245 {22000, 36, 22, 15},
246 {23000, 36, 23, 15},
247 {23500, 40, 40, 23},
248 {23750, 26, 16, 14},
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300249 {24000, 36, 24, 15},
250 {25000, 36, 25, 15},
251 {25175, 26, 40, 33},
252 {25200, 30, 21, 15},
253 {26000, 36, 26, 15},
254 {27000, 30, 21, 14},
255 {27027, 18, 100, 111},
256 {27500, 30, 29, 19},
257 {28000, 34, 30, 17},
258 {28320, 26, 30, 22},
259 {28322, 32, 42, 25},
260 {28750, 24, 23, 18},
261 {29000, 30, 29, 18},
262 {29750, 32, 30, 17},
263 {30000, 30, 25, 15},
264 {30750, 30, 41, 24},
265 {31000, 30, 31, 18},
266 {31500, 30, 28, 16},
267 {32000, 30, 32, 18},
268 {32500, 28, 32, 19},
269 {33000, 24, 22, 15},
270 {34000, 28, 30, 17},
271 {35000, 26, 32, 19},
272 {35500, 24, 30, 19},
273 {36000, 26, 26, 15},
274 {36750, 26, 46, 26},
275 {37000, 24, 23, 14},
276 {37762, 22, 40, 26},
277 {37800, 20, 21, 15},
278 {38000, 24, 27, 16},
279 {38250, 24, 34, 20},
280 {39000, 24, 26, 15},
281 {40000, 24, 32, 18},
282 {40500, 20, 21, 14},
283 {40541, 22, 147, 89},
284 {40750, 18, 19, 14},
285 {41000, 16, 17, 14},
286 {41500, 22, 44, 26},
287 {41540, 22, 44, 26},
288 {42000, 18, 21, 15},
289 {42500, 22, 45, 26},
290 {43000, 20, 43, 27},
291 {43163, 20, 24, 15},
292 {44000, 18, 22, 15},
293 {44900, 20, 108, 65},
294 {45000, 20, 25, 15},
295 {45250, 20, 52, 31},
296 {46000, 18, 23, 15},
297 {46750, 20, 45, 26},
298 {47000, 20, 40, 23},
299 {48000, 18, 24, 15},
300 {49000, 18, 49, 30},
301 {49500, 16, 22, 15},
302 {50000, 18, 25, 15},
303 {50500, 18, 32, 19},
304 {51000, 18, 34, 20},
305 {52000, 18, 26, 15},
306 {52406, 14, 34, 25},
307 {53000, 16, 22, 14},
308 {54000, 16, 24, 15},
309 {54054, 16, 173, 108},
310 {54500, 14, 24, 17},
311 {55000, 12, 22, 18},
312 {56000, 14, 45, 31},
313 {56250, 16, 25, 15},
314 {56750, 14, 25, 17},
315 {57000, 16, 27, 16},
316 {58000, 16, 43, 25},
317 {58250, 16, 38, 22},
318 {58750, 16, 40, 23},
319 {59000, 14, 26, 17},
320 {59341, 14, 40, 26},
321 {59400, 16, 44, 25},
322 {60000, 16, 32, 18},
323 {60500, 12, 39, 29},
324 {61000, 14, 49, 31},
325 {62000, 14, 37, 23},
326 {62250, 14, 42, 26},
327 {63000, 12, 21, 15},
328 {63500, 14, 28, 17},
329 {64000, 12, 27, 19},
330 {65000, 14, 32, 19},
331 {65250, 12, 29, 20},
332 {65500, 12, 32, 22},
333 {66000, 12, 22, 15},
334 {66667, 14, 38, 22},
335 {66750, 10, 21, 17},
336 {67000, 14, 33, 19},
337 {67750, 14, 58, 33},
338 {68000, 14, 30, 17},
339 {68179, 14, 46, 26},
340 {68250, 14, 46, 26},
341 {69000, 12, 23, 15},
342 {70000, 12, 28, 18},
343 {71000, 12, 30, 19},
344 {72000, 12, 24, 15},
345 {73000, 10, 23, 17},
346 {74000, 12, 23, 14},
347 {74176, 8, 100, 91},
348 {74250, 10, 22, 16},
349 {74481, 12, 43, 26},
350 {74500, 10, 29, 21},
351 {75000, 12, 25, 15},
352 {75250, 10, 39, 28},
353 {76000, 12, 27, 16},
354 {77000, 12, 53, 31},
355 {78000, 12, 26, 15},
356 {78750, 12, 28, 16},
357 {79000, 10, 38, 26},
358 {79500, 10, 28, 19},
359 {80000, 12, 32, 18},
360 {81000, 10, 21, 14},
361 {81081, 6, 100, 111},
362 {81624, 8, 29, 24},
363 {82000, 8, 17, 14},
364 {83000, 10, 40, 26},
365 {83950, 10, 28, 18},
366 {84000, 10, 28, 18},
367 {84750, 6, 16, 17},
368 {85000, 6, 17, 18},
369 {85250, 10, 30, 19},
370 {85750, 10, 27, 17},
371 {86000, 10, 43, 27},
372 {87000, 10, 29, 18},
373 {88000, 10, 44, 27},
374 {88500, 10, 41, 25},
375 {89000, 10, 28, 17},
376 {89012, 6, 90, 91},
377 {89100, 10, 33, 20},
378 {90000, 10, 25, 15},
379 {91000, 10, 32, 19},
380 {92000, 10, 46, 27},
381 {93000, 10, 31, 18},
382 {94000, 10, 40, 23},
383 {94500, 10, 28, 16},
384 {95000, 10, 44, 25},
385 {95654, 10, 39, 22},
386 {95750, 10, 39, 22},
387 {96000, 10, 32, 18},
388 {97000, 8, 23, 16},
389 {97750, 8, 42, 29},
390 {98000, 8, 45, 31},
391 {99000, 8, 22, 15},
392 {99750, 8, 34, 23},
393 {100000, 6, 20, 18},
394 {100500, 6, 19, 17},
395 {101000, 6, 37, 33},
396 {101250, 8, 21, 14},
397 {102000, 6, 17, 15},
398 {102250, 6, 25, 22},
399 {103000, 8, 29, 19},
400 {104000, 8, 37, 24},
401 {105000, 8, 28, 18},
402 {106000, 8, 22, 14},
403 {107000, 8, 46, 29},
404 {107214, 8, 27, 17},
405 {108000, 8, 24, 15},
406 {108108, 8, 173, 108},
407 {109000, 6, 23, 19},
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300408 {110000, 6, 22, 18},
409 {110013, 6, 22, 18},
410 {110250, 8, 49, 30},
411 {110500, 8, 36, 22},
412 {111000, 8, 23, 14},
413 {111264, 8, 150, 91},
414 {111375, 8, 33, 20},
415 {112000, 8, 63, 38},
416 {112500, 8, 25, 15},
417 {113100, 8, 57, 34},
418 {113309, 8, 42, 25},
419 {114000, 8, 27, 16},
420 {115000, 6, 23, 18},
421 {116000, 8, 43, 25},
422 {117000, 8, 26, 15},
423 {117500, 8, 40, 23},
424 {118000, 6, 38, 29},
425 {119000, 8, 30, 17},
426 {119500, 8, 46, 26},
427 {119651, 8, 39, 22},
428 {120000, 8, 32, 18},
429 {121000, 6, 39, 29},
430 {121250, 6, 31, 23},
431 {121750, 6, 23, 17},
432 {122000, 6, 42, 31},
433 {122614, 6, 30, 22},
434 {123000, 6, 41, 30},
435 {123379, 6, 37, 27},
436 {124000, 6, 51, 37},
437 {125000, 6, 25, 18},
438 {125250, 4, 13, 14},
439 {125750, 4, 27, 29},
440 {126000, 6, 21, 15},
441 {127000, 6, 24, 17},
442 {127250, 6, 41, 29},
443 {128000, 6, 27, 19},
444 {129000, 6, 43, 30},
445 {129859, 4, 25, 26},
446 {130000, 6, 26, 18},
447 {130250, 6, 42, 29},
448 {131000, 6, 32, 22},
449 {131500, 6, 38, 26},
450 {131850, 6, 41, 28},
451 {132000, 6, 22, 15},
452 {132750, 6, 28, 19},
453 {133000, 6, 34, 23},
454 {133330, 6, 37, 25},
455 {134000, 6, 61, 41},
456 {135000, 6, 21, 14},
457 {135250, 6, 167, 111},
458 {136000, 6, 62, 41},
459 {137000, 6, 35, 23},
460 {138000, 6, 23, 15},
461 {138500, 6, 40, 26},
462 {138750, 6, 37, 24},
463 {139000, 6, 34, 22},
464 {139050, 6, 34, 22},
465 {139054, 6, 34, 22},
466 {140000, 6, 28, 18},
467 {141000, 6, 36, 23},
468 {141500, 6, 22, 14},
469 {142000, 6, 30, 19},
470 {143000, 6, 27, 17},
471 {143472, 4, 17, 16},
472 {144000, 6, 24, 15},
473 {145000, 6, 29, 18},
474 {146000, 6, 47, 29},
475 {146250, 6, 26, 16},
476 {147000, 6, 49, 30},
477 {147891, 6, 23, 14},
478 {148000, 6, 23, 14},
479 {148250, 6, 28, 17},
480 {148352, 4, 100, 91},
481 {148500, 6, 33, 20},
482 {149000, 6, 48, 29},
483 {150000, 6, 25, 15},
484 {151000, 4, 19, 17},
485 {152000, 6, 27, 16},
486 {152280, 6, 44, 26},
487 {153000, 6, 34, 20},
488 {154000, 6, 53, 31},
489 {155000, 6, 31, 18},
490 {155250, 6, 50, 29},
491 {155750, 6, 45, 26},
492 {156000, 6, 26, 15},
493 {157000, 6, 61, 35},
494 {157500, 6, 28, 16},
495 {158000, 6, 65, 37},
496 {158250, 6, 44, 25},
497 {159000, 6, 53, 30},
498 {159500, 6, 39, 22},
499 {160000, 6, 32, 18},
500 {161000, 4, 31, 26},
501 {162000, 4, 18, 15},
502 {162162, 4, 131, 109},
503 {162500, 4, 53, 44},
504 {163000, 4, 29, 24},
505 {164000, 4, 17, 14},
506 {165000, 4, 22, 18},
507 {166000, 4, 32, 26},
508 {167000, 4, 26, 21},
509 {168000, 4, 46, 37},
510 {169000, 4, 104, 83},
511 {169128, 4, 64, 51},
512 {169500, 4, 39, 31},
513 {170000, 4, 34, 27},
514 {171000, 4, 19, 15},
515 {172000, 4, 51, 40},
516 {172750, 4, 32, 25},
517 {172800, 4, 32, 25},
518 {173000, 4, 41, 32},
519 {174000, 4, 49, 38},
520 {174787, 4, 22, 17},
521 {175000, 4, 35, 27},
522 {176000, 4, 30, 23},
523 {177000, 4, 38, 29},
524 {178000, 4, 29, 22},
525 {178500, 4, 37, 28},
526 {179000, 4, 53, 40},
527 {179500, 4, 73, 55},
528 {180000, 4, 20, 15},
529 {181000, 4, 55, 41},
530 {182000, 4, 31, 23},
531 {183000, 4, 42, 31},
532 {184000, 4, 30, 22},
533 {184750, 4, 26, 19},
534 {185000, 4, 37, 27},
535 {186000, 4, 51, 37},
536 {187000, 4, 36, 26},
537 {188000, 4, 32, 23},
538 {189000, 4, 21, 15},
539 {190000, 4, 38, 27},
540 {190960, 4, 41, 29},
541 {191000, 4, 41, 29},
542 {192000, 4, 27, 19},
543 {192250, 4, 37, 26},
544 {193000, 4, 20, 14},
545 {193250, 4, 53, 37},
546 {194000, 4, 23, 16},
547 {194208, 4, 23, 16},
548 {195000, 4, 26, 18},
549 {196000, 4, 45, 31},
550 {197000, 4, 35, 24},
551 {197750, 4, 41, 28},
552 {198000, 4, 22, 15},
553 {198500, 4, 25, 17},
554 {199000, 4, 28, 19},
555 {200000, 4, 37, 25},
556 {201000, 4, 61, 41},
557 {202000, 4, 112, 75},
558 {202500, 4, 21, 14},
559 {203000, 4, 146, 97},
560 {204000, 4, 62, 41},
561 {204750, 4, 44, 29},
562 {205000, 4, 38, 25},
563 {206000, 4, 29, 19},
564 {207000, 4, 23, 15},
565 {207500, 4, 40, 26},
566 {208000, 4, 37, 24},
567 {208900, 4, 48, 31},
568 {209000, 4, 48, 31},
569 {209250, 4, 31, 20},
570 {210000, 4, 28, 18},
571 {211000, 4, 25, 16},
572 {212000, 4, 22, 14},
573 {213000, 4, 30, 19},
574 {213750, 4, 38, 24},
575 {214000, 4, 46, 29},
576 {214750, 4, 35, 22},
577 {215000, 4, 43, 27},
578 {216000, 4, 24, 15},
579 {217000, 4, 37, 23},
580 {218000, 4, 42, 26},
581 {218250, 4, 42, 26},
582 {218750, 4, 34, 21},
583 {219000, 4, 47, 29},
Eugeni Dodonov12a13a32012-05-09 15:37:29 -0300584 {220000, 4, 44, 27},
585 {220640, 4, 49, 30},
586 {220750, 4, 36, 22},
587 {221000, 4, 36, 22},
588 {222000, 4, 23, 14},
589 {222525, 4, 28, 17},
590 {222750, 4, 33, 20},
591 {227000, 4, 37, 22},
592 {230250, 4, 29, 17},
593 {233500, 4, 38, 22},
594 {235000, 4, 40, 23},
595 {238000, 4, 30, 17},
596 {241500, 2, 17, 19},
597 {245250, 2, 20, 22},
598 {247750, 2, 22, 24},
599 {253250, 2, 15, 16},
600 {256250, 2, 18, 19},
601 {262500, 2, 31, 32},
602 {267250, 2, 66, 67},
603 {268500, 2, 94, 95},
604 {270000, 2, 14, 14},
605 {272500, 2, 77, 76},
606 {273750, 2, 57, 56},
607 {280750, 2, 24, 23},
608 {281250, 2, 23, 22},
609 {286000, 2, 17, 16},
610 {291750, 2, 26, 24},
611 {296703, 2, 56, 51},
612 {297000, 2, 22, 20},
613 {298000, 2, 21, 19},
614};
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300615
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200616static void intel_ddi_mode_set(struct drm_encoder *encoder,
617 struct drm_display_mode *mode,
618 struct drm_display_mode *adjusted_mode)
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300619{
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300620 struct drm_crtc *crtc = encoder->crtc;
621 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300622 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
623 int port = intel_ddi_get_encoder_port(intel_encoder);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300624 int pipe = intel_crtc->pipe;
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300625 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300626
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300627 DRM_DEBUG_KMS("Preparing DDI mode for Haswell on port %c, pipe %c\n",
628 port_name(port), pipe_name(pipe));
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300629
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300630 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
631 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Wang Xingchao4f078542012-08-09 16:52:16 +0800632
Paulo Zanoni247d89f2012-10-15 15:51:33 -0300633 intel_dp->DP = DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
634 switch (intel_dp->lane_count) {
635 case 1:
636 intel_dp->DP |= DDI_PORT_WIDTH_X1;
637 break;
638 case 2:
639 intel_dp->DP |= DDI_PORT_WIDTH_X2;
640 break;
641 case 4:
642 intel_dp->DP |= DDI_PORT_WIDTH_X4;
643 break;
644 default:
645 intel_dp->DP |= DDI_PORT_WIDTH_X4;
646 WARN(1, "Unexpected DP lane count %d\n",
647 intel_dp->lane_count);
648 break;
649 }
650
651 intel_dp_init_link_config(intel_dp);
652
653 } else if (type == INTEL_OUTPUT_HDMI) {
654 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
655
656 if (intel_hdmi->has_audio) {
657 /* Proper support for digital audio needs a new logic
658 * and a new set of registers, so we leave it for future
659 * patch bombing.
660 */
661 DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
662 pipe_name(intel_crtc->pipe));
663
664 /* write eld */
665 DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
666 intel_write_eld(encoder, adjusted_mode);
667 }
668
669 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300670 }
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300671}
672
673static struct intel_encoder *
674intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
675{
676 struct drm_device *dev = crtc->dev;
677 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
678 struct intel_encoder *intel_encoder, *ret = NULL;
679 int num_encoders = 0;
680
681 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
682 ret = intel_encoder;
683 num_encoders++;
684 }
685
686 if (num_encoders != 1)
687 WARN(1, "%d encoders on crtc for pipe %d\n", num_encoders,
688 intel_crtc->pipe);
689
690 BUG_ON(ret == NULL);
691 return ret;
692}
693
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300694void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
695{
696 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
697 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
698 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
699 uint32_t val;
700
701 switch (intel_crtc->ddi_pll_sel) {
702 case PORT_CLK_SEL_SPLL:
703 plls->spll_refcount--;
704 if (plls->spll_refcount == 0) {
705 DRM_DEBUG_KMS("Disabling SPLL\n");
706 val = I915_READ(SPLL_CTL);
707 WARN_ON(!(val & SPLL_PLL_ENABLE));
708 I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
709 POSTING_READ(SPLL_CTL);
710 }
711 break;
712 case PORT_CLK_SEL_WRPLL1:
713 plls->wrpll1_refcount--;
714 if (plls->wrpll1_refcount == 0) {
715 DRM_DEBUG_KMS("Disabling WRPLL 1\n");
716 val = I915_READ(WRPLL_CTL1);
717 WARN_ON(!(val & WRPLL_PLL_ENABLE));
718 I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
719 POSTING_READ(WRPLL_CTL1);
720 }
721 break;
722 case PORT_CLK_SEL_WRPLL2:
723 plls->wrpll2_refcount--;
724 if (plls->wrpll2_refcount == 0) {
725 DRM_DEBUG_KMS("Disabling WRPLL 2\n");
726 val = I915_READ(WRPLL_CTL2);
727 WARN_ON(!(val & WRPLL_PLL_ENABLE));
728 I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
729 POSTING_READ(WRPLL_CTL2);
730 }
731 break;
732 }
733
734 WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
735 WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
736 WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
737
738 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
739}
740
741static void intel_ddi_calculate_wrpll(int clock, int *p, int *n2, int *r2)
742{
743 u32 i;
744
745 for (i = 0; i < ARRAY_SIZE(wrpll_tmds_clock_table); i++)
746 if (clock <= wrpll_tmds_clock_table[i].clock)
747 break;
748
749 if (i == ARRAY_SIZE(wrpll_tmds_clock_table))
750 i--;
751
752 *p = wrpll_tmds_clock_table[i].p;
753 *n2 = wrpll_tmds_clock_table[i].n2;
754 *r2 = wrpll_tmds_clock_table[i].r2;
755
756 if (wrpll_tmds_clock_table[i].clock != clock)
757 DRM_INFO("WRPLL: using settings for %dKHz on %dKHz mode\n",
758 wrpll_tmds_clock_table[i].clock, clock);
759
760 DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
761 clock, *p, *n2, *r2);
762}
763
764bool intel_ddi_pll_mode_set(struct drm_crtc *crtc, int clock)
765{
766 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
767 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni068759b2012-10-15 15:51:31 -0300768 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300769 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
770 struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
771 int type = intel_encoder->type;
772 enum pipe pipe = intel_crtc->pipe;
773 uint32_t reg, val;
774
775 /* TODO: reuse PLLs when possible (compare values) */
776
777 intel_ddi_put_crtc_pll(crtc);
778
Paulo Zanoni068759b2012-10-15 15:51:31 -0300779 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
780 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
781
782 switch (intel_dp->link_bw) {
783 case DP_LINK_BW_1_62:
784 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
785 break;
786 case DP_LINK_BW_2_7:
787 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
788 break;
789 case DP_LINK_BW_5_4:
790 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
791 break;
792 default:
793 DRM_ERROR("Link bandwidth %d unsupported\n",
794 intel_dp->link_bw);
795 return false;
796 }
797
798 /* We don't need to turn any PLL on because we'll use LCPLL. */
799 return true;
800
801 } else if (type == INTEL_OUTPUT_HDMI) {
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300802 int p, n2, r2;
803
804 if (plls->wrpll1_refcount == 0) {
805 DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
806 pipe_name(pipe));
807 plls->wrpll1_refcount++;
808 reg = WRPLL_CTL1;
809 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
810 } else if (plls->wrpll2_refcount == 0) {
811 DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
812 pipe_name(pipe));
813 plls->wrpll2_refcount++;
814 reg = WRPLL_CTL2;
815 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
816 } else {
817 DRM_ERROR("No WRPLLs available!\n");
818 return false;
819 }
820
821 WARN(I915_READ(reg) & WRPLL_PLL_ENABLE,
822 "WRPLL already enabled\n");
823
824 intel_ddi_calculate_wrpll(clock, &p, &n2, &r2);
825
826 val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
827 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
828 WRPLL_DIVIDER_POST(p);
829
830 } else if (type == INTEL_OUTPUT_ANALOG) {
831 if (plls->spll_refcount == 0) {
832 DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
833 pipe_name(pipe));
834 plls->spll_refcount++;
835 reg = SPLL_CTL;
836 intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
837 }
838
839 WARN(I915_READ(reg) & SPLL_PLL_ENABLE,
840 "SPLL already enabled\n");
841
Damien Lespiau39bc66c2012-10-11 15:24:04 +0100842 val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz | SPLL_PLL_SSC;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300843
844 } else {
845 WARN(1, "Invalid DDI encoder type %d\n", type);
846 return false;
847 }
848
849 I915_WRITE(reg, val);
850 udelay(20);
851
852 return true;
853}
854
Paulo Zanonidae84792012-10-15 15:51:30 -0300855void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
856{
857 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
858 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
859 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanonic9809792012-10-23 18:30:00 -0200860 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -0300861 int type = intel_encoder->type;
862 uint32_t temp;
863
864 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
865
Paulo Zanonic9809792012-10-23 18:30:00 -0200866 temp = TRANS_MSA_SYNC_CLK;
Paulo Zanonidae84792012-10-15 15:51:30 -0300867 switch (intel_crtc->bpp) {
868 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -0200869 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300870 break;
871 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -0200872 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300873 break;
874 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -0200875 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300876 break;
877 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -0200878 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -0300879 break;
880 default:
Paulo Zanonic9809792012-10-23 18:30:00 -0200881 temp |= TRANS_MSA_8_BPC;
882 WARN(1, "%d bpp unsupported by DDI function\n",
Paulo Zanonidae84792012-10-15 15:51:30 -0300883 intel_crtc->bpp);
884 }
Paulo Zanonic9809792012-10-23 18:30:00 -0200885 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -0300886 }
887}
888
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300889void intel_ddi_enable_pipe_func(struct drm_crtc *crtc)
890{
891 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
892 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300893 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300894 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
895 enum pipe pipe = intel_crtc->pipe;
Paulo Zanoniad80a812012-10-24 16:06:19 -0200896 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200897 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -0300898 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300899 uint32_t temp;
900
Paulo Zanoniad80a812012-10-24 16:06:19 -0200901 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
902 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200903 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -0300904
905 switch (intel_crtc->bpp) {
906 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200907 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300908 break;
909 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200910 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300911 break;
912 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200913 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300914 break;
915 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200916 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -0300917 break;
918 default:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200919 WARN(1, "%d bpp unsupported by transcoder DDI function\n",
Paulo Zanonidfcef252012-08-08 14:15:29 -0300920 intel_crtc->bpp);
921 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300922
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300923 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200924 temp |= TRANS_DDI_PVSYNC;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300925 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200926 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c2012-08-08 14:15:28 -0300927
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -0200928 if (cpu_transcoder == TRANSCODER_EDP) {
929 switch (pipe) {
930 case PIPE_A:
931 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
932 break;
933 case PIPE_B:
934 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
935 break;
936 case PIPE_C:
937 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
938 break;
939 default:
940 BUG();
941 break;
942 }
943 }
944
Paulo Zanoni7739c332012-10-15 15:51:29 -0300945 if (type == INTEL_OUTPUT_HDMI) {
946 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300947
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300948 if (intel_hdmi->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -0200949 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300950 else
Paulo Zanoniad80a812012-10-24 16:06:19 -0200951 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300952
Paulo Zanoni7739c332012-10-15 15:51:29 -0300953 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -0200954 temp |= TRANS_DDI_MODE_SELECT_FDI;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300955
956 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
957 type == INTEL_OUTPUT_EDP) {
958 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
959
Paulo Zanoniad80a812012-10-24 16:06:19 -0200960 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300961
962 switch (intel_dp->lane_count) {
963 case 1:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200964 temp |= TRANS_DDI_PORT_WIDTH_X1;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300965 break;
966 case 2:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200967 temp |= TRANS_DDI_PORT_WIDTH_X2;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300968 break;
969 case 4:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200970 temp |= TRANS_DDI_PORT_WIDTH_X4;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300971 break;
972 default:
Paulo Zanoniad80a812012-10-24 16:06:19 -0200973 temp |= TRANS_DDI_PORT_WIDTH_X4;
Paulo Zanoni7739c332012-10-15 15:51:29 -0300974 WARN(1, "Unsupported lane count %d\n",
975 intel_dp->lane_count);
976 }
977
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300978 } else {
979 WARN(1, "Invalid encoder type %d for pipe %d\n",
980 intel_encoder->type, pipe);
981 }
982
Paulo Zanoniad80a812012-10-24 16:06:19 -0200983 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300984}
985
Paulo Zanoniad80a812012-10-24 16:06:19 -0200986void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
987 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300988{
Paulo Zanoniad80a812012-10-24 16:06:19 -0200989 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300990 uint32_t val = I915_READ(reg);
991
Paulo Zanoniad80a812012-10-24 16:06:19 -0200992 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
993 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300994 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300995}
996
Paulo Zanonibcbc8892012-10-26 19:05:51 -0200997bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
998{
999 struct drm_device *dev = intel_connector->base.dev;
1000 struct drm_i915_private *dev_priv = dev->dev_private;
1001 struct intel_encoder *intel_encoder = intel_connector->encoder;
1002 int type = intel_connector->base.connector_type;
1003 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1004 enum pipe pipe = 0;
1005 enum transcoder cpu_transcoder;
1006 uint32_t tmp;
1007
1008 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
1009 return false;
1010
1011 if (port == PORT_A)
1012 cpu_transcoder = TRANSCODER_EDP;
1013 else
1014 cpu_transcoder = pipe;
1015
1016 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1017
1018 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1019 case TRANS_DDI_MODE_SELECT_HDMI:
1020 case TRANS_DDI_MODE_SELECT_DVI:
1021 return (type == DRM_MODE_CONNECTOR_HDMIA);
1022
1023 case TRANS_DDI_MODE_SELECT_DP_SST:
1024 if (type == DRM_MODE_CONNECTOR_eDP)
1025 return true;
1026 case TRANS_DDI_MODE_SELECT_DP_MST:
1027 return (type == DRM_MODE_CONNECTOR_DisplayPort);
1028
1029 case TRANS_DDI_MODE_SELECT_FDI:
1030 return (type == DRM_MODE_CONNECTOR_VGA);
1031
1032 default:
1033 return false;
1034 }
1035}
1036
Daniel Vetter85234cd2012-07-02 13:27:29 +02001037bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1038 enum pipe *pipe)
1039{
1040 struct drm_device *dev = encoder->base.dev;
1041 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001042 enum port port = intel_ddi_get_encoder_port(encoder);
Daniel Vetter85234cd2012-07-02 13:27:29 +02001043 u32 tmp;
1044 int i;
1045
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001046 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001047
1048 if (!(tmp & DDI_BUF_CTL_ENABLE))
1049 return false;
1050
Paulo Zanoniad80a812012-10-24 16:06:19 -02001051 if (port == PORT_A) {
1052 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001053
Paulo Zanoniad80a812012-10-24 16:06:19 -02001054 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1055 case TRANS_DDI_EDP_INPUT_A_ON:
1056 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1057 *pipe = PIPE_A;
1058 break;
1059 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1060 *pipe = PIPE_B;
1061 break;
1062 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1063 *pipe = PIPE_C;
1064 break;
1065 }
1066
1067 return true;
1068 } else {
1069 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1070 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1071
1072 if ((tmp & TRANS_DDI_PORT_MASK)
1073 == TRANS_DDI_SELECT_PORT(port)) {
1074 *pipe = i;
1075 return true;
1076 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001077 }
1078 }
1079
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001080 DRM_DEBUG_KMS("No pipe for ddi port %i found\n", port);
Daniel Vetter85234cd2012-07-02 13:27:29 +02001081
1082 return true;
1083}
1084
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001085static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
1086 enum pipe pipe)
1087{
1088 uint32_t temp, ret;
1089 enum port port;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001090 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1091 pipe);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001092 int i;
1093
Paulo Zanoniad80a812012-10-24 16:06:19 -02001094 if (cpu_transcoder == TRANSCODER_EDP) {
1095 port = PORT_A;
1096 } else {
1097 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1098 temp &= TRANS_DDI_PORT_MASK;
1099
1100 for (i = PORT_B; i <= PORT_E; i++)
1101 if (temp == TRANS_DDI_SELECT_PORT(i))
1102 port = i;
1103 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001104
1105 ret = I915_READ(PORT_CLK_SEL(port));
1106
1107 DRM_DEBUG_KMS("Pipe %c connected to port %c using clock 0x%08x\n",
1108 pipe_name(pipe), port_name(port), ret);
1109
1110 return ret;
1111}
1112
1113void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
1114{
1115 struct drm_i915_private *dev_priv = dev->dev_private;
1116 enum pipe pipe;
1117 struct intel_crtc *intel_crtc;
1118
1119 for_each_pipe(pipe) {
1120 intel_crtc =
1121 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1122
1123 if (!intel_crtc->active)
1124 continue;
1125
1126 intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
1127 pipe);
1128
1129 switch (intel_crtc->ddi_pll_sel) {
1130 case PORT_CLK_SEL_SPLL:
1131 dev_priv->ddi_plls.spll_refcount++;
1132 break;
1133 case PORT_CLK_SEL_WRPLL1:
1134 dev_priv->ddi_plls.wrpll1_refcount++;
1135 break;
1136 case PORT_CLK_SEL_WRPLL2:
1137 dev_priv->ddi_plls.wrpll2_refcount++;
1138 break;
1139 }
1140 }
1141}
1142
Paulo Zanonifc914632012-10-05 12:05:54 -03001143void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1144{
1145 struct drm_crtc *crtc = &intel_crtc->base;
1146 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1147 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1148 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001149 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001150
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001151 if (cpu_transcoder != TRANSCODER_EDP)
1152 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1153 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001154}
1155
1156void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1157{
1158 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001159 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001160
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001161 if (cpu_transcoder != TRANSCODER_EDP)
1162 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1163 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001164}
1165
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001166static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001167{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001168 struct drm_encoder *encoder = &intel_encoder->base;
1169 struct drm_crtc *crtc = encoder->crtc;
1170 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001171 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1172 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001173 int type = intel_encoder->type;
1174
1175 if (type == INTEL_OUTPUT_EDP) {
1176 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1177 ironlake_edp_panel_vdd_on(intel_dp);
1178 ironlake_edp_panel_on(intel_dp);
1179 ironlake_edp_panel_vdd_off(intel_dp, true);
1180 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001181
1182 WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001183 I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001184
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001185 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001186 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1187
1188 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1189 intel_dp_start_link_train(intel_dp);
1190 intel_dp_complete_link_train(intel_dp);
1191 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001192}
1193
Paulo Zanoni2886e932012-10-05 12:06:00 -03001194static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
1195 enum port port)
1196{
1197 uint32_t reg = DDI_BUF_CTL(port);
1198 int i;
1199
1200 for (i = 0; i < 8; i++) {
1201 udelay(1);
1202 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
1203 return;
1204 }
1205 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
1206}
1207
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001208static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001209{
1210 struct drm_encoder *encoder = &intel_encoder->base;
1211 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1212 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001213 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001214 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001215 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001216
1217 val = I915_READ(DDI_BUF_CTL(port));
1218 if (val & DDI_BUF_CTL_ENABLE) {
1219 val &= ~DDI_BUF_CTL_ENABLE;
1220 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001221 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001222 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001223
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001224 val = I915_READ(DP_TP_CTL(port));
1225 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1226 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1227 I915_WRITE(DP_TP_CTL(port), val);
1228
1229 if (wait)
1230 intel_wait_ddi_buf_idle(dev_priv, port);
1231
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001232 if (type == INTEL_OUTPUT_EDP) {
1233 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1234 ironlake_edp_panel_vdd_on(intel_dp);
1235 ironlake_edp_panel_off(intel_dp);
1236 }
1237
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001238 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
1239}
1240
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001241static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001242{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001243 struct drm_encoder *encoder = &intel_encoder->base;
1244 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001245 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001246 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1247 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001248
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001249 if (type == INTEL_OUTPUT_HDMI) {
1250 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1251 * are ignored so nothing special needs to be done besides
1252 * enabling the port.
1253 */
1254 I915_WRITE(DDI_BUF_CTL(port), DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001255 } else if (type == INTEL_OUTPUT_EDP) {
1256 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1257
1258 ironlake_edp_backlight_on(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001259 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001260}
1261
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001262static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001263{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001264 struct drm_encoder *encoder = &intel_encoder->base;
1265 int type = intel_encoder->type;
1266
1267 if (type == INTEL_OUTPUT_EDP) {
1268 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1269
1270 ironlake_edp_backlight_off(intel_dp);
1271 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001272}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001273
Paulo Zanonib8fc2f62012-10-23 18:30:05 -02001274int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001275{
1276 if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT)
1277 return 450;
1278 else if ((I915_READ(LCPLL_CTL) & LCPLL_CLK_FREQ_MASK) ==
1279 LCPLL_CLK_FREQ_450)
1280 return 450;
1281 else
1282 return 540;
1283}
1284
1285void intel_ddi_pll_init(struct drm_device *dev)
1286{
1287 struct drm_i915_private *dev_priv = dev->dev_private;
1288 uint32_t val = I915_READ(LCPLL_CTL);
1289
1290 /* The LCPLL register should be turned on by the BIOS. For now let's
1291 * just check its state and print errors in case something is wrong.
1292 * Don't even try to turn it on.
1293 */
1294
1295 DRM_DEBUG_KMS("CDCLK running at %dMHz\n",
1296 intel_ddi_get_cdclk_freq(dev_priv));
1297
1298 if (val & LCPLL_CD_SOURCE_FCLK)
1299 DRM_ERROR("CDCLK source is not LCPLL\n");
1300
1301 if (val & LCPLL_PLL_DISABLE)
1302 DRM_ERROR("LCPLL is disabled\n");
1303}
Paulo Zanonic19b0662012-10-15 15:51:41 -03001304
1305void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
1306{
Paulo Zanoni174edf12012-10-26 19:05:50 -02001307 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
1308 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001309 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001310 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03001311 bool wait;
1312 uint32_t val;
1313
1314 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
1315 val = I915_READ(DDI_BUF_CTL(port));
1316 if (val & DDI_BUF_CTL_ENABLE) {
1317 val &= ~DDI_BUF_CTL_ENABLE;
1318 I915_WRITE(DDI_BUF_CTL(port), val);
1319 wait = true;
1320 }
1321
1322 val = I915_READ(DP_TP_CTL(port));
1323 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1324 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1325 I915_WRITE(DP_TP_CTL(port), val);
1326 POSTING_READ(DP_TP_CTL(port));
1327
1328 if (wait)
1329 intel_wait_ddi_buf_idle(dev_priv, port);
1330 }
1331
1332 val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
1333 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
1334 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
1335 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1336 I915_WRITE(DP_TP_CTL(port), val);
1337 POSTING_READ(DP_TP_CTL(port));
1338
1339 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
1340 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
1341 POSTING_READ(DDI_BUF_CTL(port));
1342
1343 udelay(600);
1344}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001345
1346static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1347{
1348 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
1349 int type = intel_encoder->type;
1350
1351 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
1352 intel_dp_check_link_status(intel_dp);
1353}
1354
1355static void intel_ddi_destroy(struct drm_encoder *encoder)
1356{
1357 /* HDMI has nothing special to destroy, so we can go with this. */
1358 intel_dp_encoder_destroy(encoder);
1359}
1360
1361static bool intel_ddi_mode_fixup(struct drm_encoder *encoder,
1362 const struct drm_display_mode *mode,
1363 struct drm_display_mode *adjusted_mode)
1364{
1365 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1366 int type = intel_encoder->type;
1367
1368 WARN(type == INTEL_OUTPUT_UNKNOWN, "mode_fixup() on unknown output!\n");
1369
1370 if (type == INTEL_OUTPUT_HDMI)
1371 return intel_hdmi_mode_fixup(encoder, mode, adjusted_mode);
1372 else
1373 return intel_dp_mode_fixup(encoder, mode, adjusted_mode);
1374}
1375
1376static const struct drm_encoder_funcs intel_ddi_funcs = {
1377 .destroy = intel_ddi_destroy,
1378};
1379
1380static const struct drm_encoder_helper_funcs intel_ddi_helper_funcs = {
1381 .mode_fixup = intel_ddi_mode_fixup,
1382 .mode_set = intel_ddi_mode_set,
1383 .disable = intel_encoder_noop,
1384};
1385
1386void intel_ddi_init(struct drm_device *dev, enum port port)
1387{
1388 struct intel_digital_port *intel_dig_port;
1389 struct intel_encoder *intel_encoder;
1390 struct drm_encoder *encoder;
1391 struct intel_connector *hdmi_connector = NULL;
1392 struct intel_connector *dp_connector = NULL;
1393
1394 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
1395 if (!intel_dig_port)
1396 return;
1397
1398 dp_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1399 if (!dp_connector) {
1400 kfree(intel_dig_port);
1401 return;
1402 }
1403
1404 if (port != PORT_A) {
1405 hdmi_connector = kzalloc(sizeof(struct intel_connector),
1406 GFP_KERNEL);
1407 if (!hdmi_connector) {
1408 kfree(dp_connector);
1409 kfree(intel_dig_port);
1410 return;
1411 }
1412 }
1413
1414 intel_encoder = &intel_dig_port->base;
1415 encoder = &intel_encoder->base;
1416
1417 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1418 DRM_MODE_ENCODER_TMDS);
1419 drm_encoder_helper_add(encoder, &intel_ddi_helper_funcs);
1420
1421 intel_encoder->enable = intel_enable_ddi;
1422 intel_encoder->pre_enable = intel_ddi_pre_enable;
1423 intel_encoder->disable = intel_disable_ddi;
1424 intel_encoder->post_disable = intel_ddi_post_disable;
1425 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
1426
1427 intel_dig_port->port = port;
1428 if (hdmi_connector)
1429 intel_dig_port->hdmi.sdvox_reg = DDI_BUF_CTL(port);
1430 else
1431 intel_dig_port->hdmi.sdvox_reg = 0;
1432 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
1433
1434 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
1435 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1436 intel_encoder->cloneable = false;
1437 intel_encoder->hot_plug = intel_ddi_hot_plug;
1438
1439 if (hdmi_connector)
1440 intel_hdmi_init_connector(intel_dig_port, hdmi_connector);
1441 intel_dp_init_connector(intel_dig_port, dp_connector);
1442}