drm/i915: enable and disable DDI_FUNC_CTL at the right time
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_ddi.c
CommitLineData
45244b87
ED
1/*
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
61/* On Haswell, DDI port buffers must be programmed with correct values
62 * in advance. The buffer values are different for FDI and DP modes,
63 * but the HDMI/DVI fields are shared among those. So we program the DDI
64 * in either FDI or DP modes only, as HDMI connections will work with both
65 * of those
66 */
67void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port, bool use_fdi_mode)
68{
69 struct drm_i915_private *dev_priv = dev->dev_private;
70 u32 reg;
71 int i;
72 const u32 *ddi_translations = ((use_fdi_mode) ?
73 hsw_ddi_translations_fdi :
74 hsw_ddi_translations_dp);
75
76 DRM_DEBUG_DRIVER("Initializing DDI buffers for port %c in %s mode\n",
77 port_name(port),
78 use_fdi_mode ? "FDI" : "DP");
79
80 WARN((use_fdi_mode && (port != PORT_E)),
81 "Programming port %c in FDI mode, this probably will not work.\n",
82 port_name(port));
83
84 for (i=0, reg=DDI_BUF_TRANS(port); i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
85 I915_WRITE(reg, ddi_translations[i]);
86 reg += 4;
87 }
88}
89
90/* Program DDI buffers translations for DP. By default, program ports A-D in DP
91 * mode and port E for FDI.
92 */
93void intel_prepare_ddi(struct drm_device *dev)
94{
95 int port;
96
97 if (IS_HASWELL(dev)) {
98 for (port = PORT_A; port < PORT_E; port++)
99 intel_prepare_ddi_buffers(dev, port, false);
100
101 /* DDI E is the suggested one to work in FDI mode, so program is as such by
102 * default. It will have to be re-programmed in case a digital DP output
103 * will be detected on it
104 */
105 intel_prepare_ddi_buffers(dev, PORT_E, true);
106 }
107}
c82e4d26
ED
108
109static const long hsw_ddi_buf_ctl_values[] = {
110 DDI_BUF_EMP_400MV_0DB_HSW,
111 DDI_BUF_EMP_400MV_3_5DB_HSW,
112 DDI_BUF_EMP_400MV_6DB_HSW,
113 DDI_BUF_EMP_400MV_9_5DB_HSW,
114 DDI_BUF_EMP_600MV_0DB_HSW,
115 DDI_BUF_EMP_600MV_3_5DB_HSW,
116 DDI_BUF_EMP_600MV_6DB_HSW,
117 DDI_BUF_EMP_800MV_0DB_HSW,
118 DDI_BUF_EMP_800MV_3_5DB_HSW
119};
120
121
122/* Starting with Haswell, different DDI ports can work in FDI mode for
123 * connection to the PCH-located connectors. For this, it is necessary to train
124 * both the DDI port and PCH receiver for the desired DDI buffer settings.
125 *
126 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
127 * please note that when FDI mode is active on DDI E, it shares 2 lines with
128 * DDI A (which is used for eDP)
129 */
130
131void hsw_fdi_link_train(struct drm_crtc *crtc)
132{
133 struct drm_device *dev = crtc->dev;
134 struct drm_i915_private *dev_priv = dev->dev_private;
135 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
136 int pipe = intel_crtc->pipe;
137 u32 reg, temp, i;
138
139 /* Configure CPU PLL, wait for warmup */
140 I915_WRITE(SPLL_CTL,
141 SPLL_PLL_ENABLE |
142 SPLL_PLL_FREQ_1350MHz |
143 SPLL_PLL_SCC);
144
145 /* Use SPLL to drive the output when in FDI mode */
146 I915_WRITE(PORT_CLK_SEL(PORT_E),
147 PORT_CLK_SEL_SPLL);
148 I915_WRITE(PIPE_CLK_SEL(pipe),
149 PIPE_CLK_SEL_PORT(PORT_E));
150
151 udelay(20);
152
153 /* Start the training iterating through available voltages and emphasis */
154 for (i=0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values); i++) {
155 /* Configure DP_TP_CTL with auto-training */
156 I915_WRITE(DP_TP_CTL(PORT_E),
157 DP_TP_CTL_FDI_AUTOTRAIN |
158 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
159 DP_TP_CTL_LINK_TRAIN_PAT1 |
160 DP_TP_CTL_ENABLE);
161
162 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage */
163 temp = I915_READ(DDI_BUF_CTL(PORT_E));
164 temp = (temp & ~DDI_BUF_EMP_MASK);
165 I915_WRITE(DDI_BUF_CTL(PORT_E),
166 temp |
167 DDI_BUF_CTL_ENABLE |
168 DDI_PORT_WIDTH_X2 |
169 hsw_ddi_buf_ctl_values[i]);
170
171 udelay(600);
172
4acf5186
ED
173 /* We need to program FDI_RX_MISC with the default TP1 to TP2
174 * values before enabling the receiver, and configure the delay
175 * for the FDI timing generator to 90h. Luckily, all the other
176 * bits are supposed to be zeroed, so we can write those values
177 * directly.
178 */
179 I915_WRITE(FDI_RX_MISC(pipe), FDI_RX_TP1_TO_TP2_48 |
180 FDI_RX_FDI_DELAY_90);
181
c82e4d26
ED
182 /* Enable CPU FDI Receiver with auto-training */
183 reg = FDI_RX_CTL(pipe);
184 I915_WRITE(reg,
185 I915_READ(reg) |
186 FDI_LINK_TRAIN_AUTO |
187 FDI_RX_ENABLE |
188 FDI_LINK_TRAIN_PATTERN_1_CPT |
189 FDI_RX_ENHANCE_FRAME_ENABLE |
190 FDI_PORT_WIDTH_2X_LPT |
191 FDI_RX_PLL_ENABLE);
192 POSTING_READ(reg);
193 udelay(100);
194
195 temp = I915_READ(DP_TP_STATUS(PORT_E));
196 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
197 DRM_DEBUG_DRIVER("BUF_CTL training done on %d step\n", i);
198
199 /* Enable normal pixel sending for FDI */
200 I915_WRITE(DP_TP_CTL(PORT_E),
201 DP_TP_CTL_FDI_AUTOTRAIN |
202 DP_TP_CTL_LINK_TRAIN_NORMAL |
203 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
204 DP_TP_CTL_ENABLE);
205
c82e4d26
ED
206 break;
207 } else {
208 DRM_ERROR("Error training BUF_CTL %d\n", i);
209
210 /* Disable DP_TP_CTL and FDI_RX_CTL) and retry */
211 I915_WRITE(DP_TP_CTL(PORT_E),
212 I915_READ(DP_TP_CTL(PORT_E)) &
213 ~DP_TP_CTL_ENABLE);
214 I915_WRITE(FDI_RX_CTL(pipe),
215 I915_READ(FDI_RX_CTL(pipe)) &
216 ~FDI_RX_PLL_ENABLE);
217 continue;
218 }
219 }
220
221 DRM_DEBUG_KMS("FDI train done.\n");
222}
0e72a5b5
ED
223
224/* For DDI connections, it is possible to support different outputs over the
225 * same DDI port, such as HDMI or DP or even VGA via FDI. So we don't know by
226 * the time the output is detected what exactly is on the other end of it. This
227 * function aims at providing support for this detection and proper output
228 * configuration.
229 */
230void intel_ddi_init(struct drm_device *dev, enum port port)
231{
232 /* For now, we don't do any proper output detection and assume that we
233 * handle HDMI only */
234
235 switch(port){
236 case PORT_A:
237 /* We don't handle eDP and DP yet */
238 DRM_DEBUG_DRIVER("Found digital output on DDI port A\n");
239 break;
240 /* Assume that the ports B, C and D are working in HDMI mode for now */
241 case PORT_B:
242 case PORT_C:
243 case PORT_D:
08d644ad 244 intel_hdmi_init(dev, DDI_BUF_CTL(port), port);
0e72a5b5
ED
245 break;
246 default:
247 DRM_DEBUG_DRIVER("No handlers defined for port %d, skipping DDI initialization\n",
248 port);
249 break;
250 }
251}
12a13a33
ED
252
253/* WRPLL clock dividers */
254struct wrpll_tmds_clock {
255 u32 clock;
256 u16 p; /* Post divider */
257 u16 n2; /* Feedback divider */
258 u16 r2; /* Reference divider */
259};
260
126e9be8
PZ
261/* Table of matching values for WRPLL clocks programming for each frequency.
262 * The code assumes this table is sorted. */
12a13a33
ED
263static const struct wrpll_tmds_clock wrpll_tmds_clock_table[] = {
264 {19750, 38, 25, 18},
265 {20000, 48, 32, 18},
266 {21000, 36, 21, 15},
267 {21912, 42, 29, 17},
268 {22000, 36, 22, 15},
269 {23000, 36, 23, 15},
270 {23500, 40, 40, 23},
271 {23750, 26, 16, 14},
12a13a33
ED
272 {24000, 36, 24, 15},
273 {25000, 36, 25, 15},
274 {25175, 26, 40, 33},
275 {25200, 30, 21, 15},
276 {26000, 36, 26, 15},
277 {27000, 30, 21, 14},
278 {27027, 18, 100, 111},
279 {27500, 30, 29, 19},
280 {28000, 34, 30, 17},
281 {28320, 26, 30, 22},
282 {28322, 32, 42, 25},
283 {28750, 24, 23, 18},
284 {29000, 30, 29, 18},
285 {29750, 32, 30, 17},
286 {30000, 30, 25, 15},
287 {30750, 30, 41, 24},
288 {31000, 30, 31, 18},
289 {31500, 30, 28, 16},
290 {32000, 30, 32, 18},
291 {32500, 28, 32, 19},
292 {33000, 24, 22, 15},
293 {34000, 28, 30, 17},
294 {35000, 26, 32, 19},
295 {35500, 24, 30, 19},
296 {36000, 26, 26, 15},
297 {36750, 26, 46, 26},
298 {37000, 24, 23, 14},
299 {37762, 22, 40, 26},
300 {37800, 20, 21, 15},
301 {38000, 24, 27, 16},
302 {38250, 24, 34, 20},
303 {39000, 24, 26, 15},
304 {40000, 24, 32, 18},
305 {40500, 20, 21, 14},
306 {40541, 22, 147, 89},
307 {40750, 18, 19, 14},
308 {41000, 16, 17, 14},
309 {41500, 22, 44, 26},
310 {41540, 22, 44, 26},
311 {42000, 18, 21, 15},
312 {42500, 22, 45, 26},
313 {43000, 20, 43, 27},
314 {43163, 20, 24, 15},
315 {44000, 18, 22, 15},
316 {44900, 20, 108, 65},
317 {45000, 20, 25, 15},
318 {45250, 20, 52, 31},
319 {46000, 18, 23, 15},
320 {46750, 20, 45, 26},
321 {47000, 20, 40, 23},
322 {48000, 18, 24, 15},
323 {49000, 18, 49, 30},
324 {49500, 16, 22, 15},
325 {50000, 18, 25, 15},
326 {50500, 18, 32, 19},
327 {51000, 18, 34, 20},
328 {52000, 18, 26, 15},
329 {52406, 14, 34, 25},
330 {53000, 16, 22, 14},
331 {54000, 16, 24, 15},
332 {54054, 16, 173, 108},
333 {54500, 14, 24, 17},
334 {55000, 12, 22, 18},
335 {56000, 14, 45, 31},
336 {56250, 16, 25, 15},
337 {56750, 14, 25, 17},
338 {57000, 16, 27, 16},
339 {58000, 16, 43, 25},
340 {58250, 16, 38, 22},
341 {58750, 16, 40, 23},
342 {59000, 14, 26, 17},
343 {59341, 14, 40, 26},
344 {59400, 16, 44, 25},
345 {60000, 16, 32, 18},
346 {60500, 12, 39, 29},
347 {61000, 14, 49, 31},
348 {62000, 14, 37, 23},
349 {62250, 14, 42, 26},
350 {63000, 12, 21, 15},
351 {63500, 14, 28, 17},
352 {64000, 12, 27, 19},
353 {65000, 14, 32, 19},
354 {65250, 12, 29, 20},
355 {65500, 12, 32, 22},
356 {66000, 12, 22, 15},
357 {66667, 14, 38, 22},
358 {66750, 10, 21, 17},
359 {67000, 14, 33, 19},
360 {67750, 14, 58, 33},
361 {68000, 14, 30, 17},
362 {68179, 14, 46, 26},
363 {68250, 14, 46, 26},
364 {69000, 12, 23, 15},
365 {70000, 12, 28, 18},
366 {71000, 12, 30, 19},
367 {72000, 12, 24, 15},
368 {73000, 10, 23, 17},
369 {74000, 12, 23, 14},
370 {74176, 8, 100, 91},
371 {74250, 10, 22, 16},
372 {74481, 12, 43, 26},
373 {74500, 10, 29, 21},
374 {75000, 12, 25, 15},
375 {75250, 10, 39, 28},
376 {76000, 12, 27, 16},
377 {77000, 12, 53, 31},
378 {78000, 12, 26, 15},
379 {78750, 12, 28, 16},
380 {79000, 10, 38, 26},
381 {79500, 10, 28, 19},
382 {80000, 12, 32, 18},
383 {81000, 10, 21, 14},
384 {81081, 6, 100, 111},
385 {81624, 8, 29, 24},
386 {82000, 8, 17, 14},
387 {83000, 10, 40, 26},
388 {83950, 10, 28, 18},
389 {84000, 10, 28, 18},
390 {84750, 6, 16, 17},
391 {85000, 6, 17, 18},
392 {85250, 10, 30, 19},
393 {85750, 10, 27, 17},
394 {86000, 10, 43, 27},
395 {87000, 10, 29, 18},
396 {88000, 10, 44, 27},
397 {88500, 10, 41, 25},
398 {89000, 10, 28, 17},
399 {89012, 6, 90, 91},
400 {89100, 10, 33, 20},
401 {90000, 10, 25, 15},
402 {91000, 10, 32, 19},
403 {92000, 10, 46, 27},
404 {93000, 10, 31, 18},
405 {94000, 10, 40, 23},
406 {94500, 10, 28, 16},
407 {95000, 10, 44, 25},
408 {95654, 10, 39, 22},
409 {95750, 10, 39, 22},
410 {96000, 10, 32, 18},
411 {97000, 8, 23, 16},
412 {97750, 8, 42, 29},
413 {98000, 8, 45, 31},
414 {99000, 8, 22, 15},
415 {99750, 8, 34, 23},
416 {100000, 6, 20, 18},
417 {100500, 6, 19, 17},
418 {101000, 6, 37, 33},
419 {101250, 8, 21, 14},
420 {102000, 6, 17, 15},
421 {102250, 6, 25, 22},
422 {103000, 8, 29, 19},
423 {104000, 8, 37, 24},
424 {105000, 8, 28, 18},
425 {106000, 8, 22, 14},
426 {107000, 8, 46, 29},
427 {107214, 8, 27, 17},
428 {108000, 8, 24, 15},
429 {108108, 8, 173, 108},
430 {109000, 6, 23, 19},
12a13a33
ED
431 {110000, 6, 22, 18},
432 {110013, 6, 22, 18},
433 {110250, 8, 49, 30},
434 {110500, 8, 36, 22},
435 {111000, 8, 23, 14},
436 {111264, 8, 150, 91},
437 {111375, 8, 33, 20},
438 {112000, 8, 63, 38},
439 {112500, 8, 25, 15},
440 {113100, 8, 57, 34},
441 {113309, 8, 42, 25},
442 {114000, 8, 27, 16},
443 {115000, 6, 23, 18},
444 {116000, 8, 43, 25},
445 {117000, 8, 26, 15},
446 {117500, 8, 40, 23},
447 {118000, 6, 38, 29},
448 {119000, 8, 30, 17},
449 {119500, 8, 46, 26},
450 {119651, 8, 39, 22},
451 {120000, 8, 32, 18},
452 {121000, 6, 39, 29},
453 {121250, 6, 31, 23},
454 {121750, 6, 23, 17},
455 {122000, 6, 42, 31},
456 {122614, 6, 30, 22},
457 {123000, 6, 41, 30},
458 {123379, 6, 37, 27},
459 {124000, 6, 51, 37},
460 {125000, 6, 25, 18},
461 {125250, 4, 13, 14},
462 {125750, 4, 27, 29},
463 {126000, 6, 21, 15},
464 {127000, 6, 24, 17},
465 {127250, 6, 41, 29},
466 {128000, 6, 27, 19},
467 {129000, 6, 43, 30},
468 {129859, 4, 25, 26},
469 {130000, 6, 26, 18},
470 {130250, 6, 42, 29},
471 {131000, 6, 32, 22},
472 {131500, 6, 38, 26},
473 {131850, 6, 41, 28},
474 {132000, 6, 22, 15},
475 {132750, 6, 28, 19},
476 {133000, 6, 34, 23},
477 {133330, 6, 37, 25},
478 {134000, 6, 61, 41},
479 {135000, 6, 21, 14},
480 {135250, 6, 167, 111},
481 {136000, 6, 62, 41},
482 {137000, 6, 35, 23},
483 {138000, 6, 23, 15},
484 {138500, 6, 40, 26},
485 {138750, 6, 37, 24},
486 {139000, 6, 34, 22},
487 {139050, 6, 34, 22},
488 {139054, 6, 34, 22},
489 {140000, 6, 28, 18},
490 {141000, 6, 36, 23},
491 {141500, 6, 22, 14},
492 {142000, 6, 30, 19},
493 {143000, 6, 27, 17},
494 {143472, 4, 17, 16},
495 {144000, 6, 24, 15},
496 {145000, 6, 29, 18},
497 {146000, 6, 47, 29},
498 {146250, 6, 26, 16},
499 {147000, 6, 49, 30},
500 {147891, 6, 23, 14},
501 {148000, 6, 23, 14},
502 {148250, 6, 28, 17},
503 {148352, 4, 100, 91},
504 {148500, 6, 33, 20},
505 {149000, 6, 48, 29},
506 {150000, 6, 25, 15},
507 {151000, 4, 19, 17},
508 {152000, 6, 27, 16},
509 {152280, 6, 44, 26},
510 {153000, 6, 34, 20},
511 {154000, 6, 53, 31},
512 {155000, 6, 31, 18},
513 {155250, 6, 50, 29},
514 {155750, 6, 45, 26},
515 {156000, 6, 26, 15},
516 {157000, 6, 61, 35},
517 {157500, 6, 28, 16},
518 {158000, 6, 65, 37},
519 {158250, 6, 44, 25},
520 {159000, 6, 53, 30},
521 {159500, 6, 39, 22},
522 {160000, 6, 32, 18},
523 {161000, 4, 31, 26},
524 {162000, 4, 18, 15},
525 {162162, 4, 131, 109},
526 {162500, 4, 53, 44},
527 {163000, 4, 29, 24},
528 {164000, 4, 17, 14},
529 {165000, 4, 22, 18},
530 {166000, 4, 32, 26},
531 {167000, 4, 26, 21},
532 {168000, 4, 46, 37},
533 {169000, 4, 104, 83},
534 {169128, 4, 64, 51},
535 {169500, 4, 39, 31},
536 {170000, 4, 34, 27},
537 {171000, 4, 19, 15},
538 {172000, 4, 51, 40},
539 {172750, 4, 32, 25},
540 {172800, 4, 32, 25},
541 {173000, 4, 41, 32},
542 {174000, 4, 49, 38},
543 {174787, 4, 22, 17},
544 {175000, 4, 35, 27},
545 {176000, 4, 30, 23},
546 {177000, 4, 38, 29},
547 {178000, 4, 29, 22},
548 {178500, 4, 37, 28},
549 {179000, 4, 53, 40},
550 {179500, 4, 73, 55},
551 {180000, 4, 20, 15},
552 {181000, 4, 55, 41},
553 {182000, 4, 31, 23},
554 {183000, 4, 42, 31},
555 {184000, 4, 30, 22},
556 {184750, 4, 26, 19},
557 {185000, 4, 37, 27},
558 {186000, 4, 51, 37},
559 {187000, 4, 36, 26},
560 {188000, 4, 32, 23},
561 {189000, 4, 21, 15},
562 {190000, 4, 38, 27},
563 {190960, 4, 41, 29},
564 {191000, 4, 41, 29},
565 {192000, 4, 27, 19},
566 {192250, 4, 37, 26},
567 {193000, 4, 20, 14},
568 {193250, 4, 53, 37},
569 {194000, 4, 23, 16},
570 {194208, 4, 23, 16},
571 {195000, 4, 26, 18},
572 {196000, 4, 45, 31},
573 {197000, 4, 35, 24},
574 {197750, 4, 41, 28},
575 {198000, 4, 22, 15},
576 {198500, 4, 25, 17},
577 {199000, 4, 28, 19},
578 {200000, 4, 37, 25},
579 {201000, 4, 61, 41},
580 {202000, 4, 112, 75},
581 {202500, 4, 21, 14},
582 {203000, 4, 146, 97},
583 {204000, 4, 62, 41},
584 {204750, 4, 44, 29},
585 {205000, 4, 38, 25},
586 {206000, 4, 29, 19},
587 {207000, 4, 23, 15},
588 {207500, 4, 40, 26},
589 {208000, 4, 37, 24},
590 {208900, 4, 48, 31},
591 {209000, 4, 48, 31},
592 {209250, 4, 31, 20},
593 {210000, 4, 28, 18},
594 {211000, 4, 25, 16},
595 {212000, 4, 22, 14},
596 {213000, 4, 30, 19},
597 {213750, 4, 38, 24},
598 {214000, 4, 46, 29},
599 {214750, 4, 35, 22},
600 {215000, 4, 43, 27},
601 {216000, 4, 24, 15},
602 {217000, 4, 37, 23},
603 {218000, 4, 42, 26},
604 {218250, 4, 42, 26},
605 {218750, 4, 34, 21},
606 {219000, 4, 47, 29},
12a13a33
ED
607 {220000, 4, 44, 27},
608 {220640, 4, 49, 30},
609 {220750, 4, 36, 22},
610 {221000, 4, 36, 22},
611 {222000, 4, 23, 14},
612 {222525, 4, 28, 17},
613 {222750, 4, 33, 20},
614 {227000, 4, 37, 22},
615 {230250, 4, 29, 17},
616 {233500, 4, 38, 22},
617 {235000, 4, 40, 23},
618 {238000, 4, 30, 17},
619 {241500, 2, 17, 19},
620 {245250, 2, 20, 22},
621 {247750, 2, 22, 24},
622 {253250, 2, 15, 16},
623 {256250, 2, 18, 19},
624 {262500, 2, 31, 32},
625 {267250, 2, 66, 67},
626 {268500, 2, 94, 95},
627 {270000, 2, 14, 14},
628 {272500, 2, 77, 76},
629 {273750, 2, 57, 56},
630 {280750, 2, 24, 23},
631 {281250, 2, 23, 22},
632 {286000, 2, 17, 16},
633 {291750, 2, 26, 24},
634 {296703, 2, 56, 51},
635 {297000, 2, 22, 20},
636 {298000, 2, 21, 19},
637};
72662e10
ED
638
639void intel_ddi_mode_set(struct drm_encoder *encoder,
640 struct drm_display_mode *mode,
641 struct drm_display_mode *adjusted_mode)
642{
643 struct drm_device *dev = encoder->dev;
644 struct drm_i915_private *dev_priv = dev->dev_private;
645 struct drm_crtc *crtc = encoder->crtc;
646 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
647 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
648 int port = intel_hdmi->ddi_port;
649 int pipe = intel_crtc->pipe;
126e9be8 650 int p, n2, r2;
8d9ddbcb 651 u32 i;
72662e10
ED
652
653 /* On Haswell, we need to enable the clocks and prepare DDI function to
654 * work in HDMI mode for this pipe.
655 */
656 DRM_DEBUG_KMS("Preparing HDMI DDI mode for Haswell on port %c, pipe %c\n", port_name(port), pipe_name(pipe));
657
126e9be8
PZ
658 for (i = 0; i < ARRAY_SIZE(wrpll_tmds_clock_table); i++)
659 if (crtc->mode.clock <= wrpll_tmds_clock_table[i].clock)
660 break;
72662e10 661
126e9be8
PZ
662 if (i == ARRAY_SIZE(wrpll_tmds_clock_table))
663 i--;
72662e10 664
126e9be8
PZ
665 p = wrpll_tmds_clock_table[i].p;
666 n2 = wrpll_tmds_clock_table[i].n2;
667 r2 = wrpll_tmds_clock_table[i].r2;
72662e10 668
126e9be8
PZ
669 if (wrpll_tmds_clock_table[i].clock != crtc->mode.clock)
670 DRM_INFO("WR PLL: using settings for %dKHz on %dKHz mode\n",
671 wrpll_tmds_clock_table[i].clock, crtc->mode.clock);
672
673 DRM_DEBUG_KMS("WR PLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
674 crtc->mode.clock, p, n2, r2);
72662e10 675
72662e10
ED
676 /* Configure WR PLL 1, program the correct divider values for
677 * the desired frequency and wait for warmup */
678 I915_WRITE(WRPLL_CTL1,
679 WRPLL_PLL_ENABLE |
680 WRPLL_PLL_SELECT_LCPLL_2700 |
681 WRPLL_DIVIDER_REFERENCE(r2) |
682 WRPLL_DIVIDER_FEEDBACK(n2) |
683 WRPLL_DIVIDER_POST(p));
684
685 udelay(20);
686
687 /* Use WRPLL1 clock to drive the output to the port, and tell the pipe to use
688 * this port for connection.
689 */
690 I915_WRITE(PORT_CLK_SEL(port),
691 PORT_CLK_SEL_WRPLL1);
692 I915_WRITE(PIPE_CLK_SEL(pipe),
693 PIPE_CLK_SEL_PORT(port));
694
695 udelay(20);
696
697 if (intel_hdmi->has_audio) {
698 /* Proper support for digital audio needs a new logic and a new set
699 * of registers, so we leave it for future patch bombing.
700 */
4f07854d 701 DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
72662e10 702 pipe_name(intel_crtc->pipe));
4f07854d
WX
703
704 /* write eld */
705 DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
706 intel_write_eld(encoder, adjusted_mode);
72662e10
ED
707 }
708
8d9ddbcb
PZ
709 intel_hdmi->set_infoframes(encoder, adjusted_mode);
710}
711
712static struct intel_encoder *
713intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
714{
715 struct drm_device *dev = crtc->dev;
716 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
717 struct intel_encoder *intel_encoder, *ret = NULL;
718 int num_encoders = 0;
719
720 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
721 ret = intel_encoder;
722 num_encoders++;
723 }
724
725 if (num_encoders != 1)
726 WARN(1, "%d encoders on crtc for pipe %d\n", num_encoders,
727 intel_crtc->pipe);
728
729 BUG_ON(ret == NULL);
730 return ret;
731}
732
733void intel_ddi_enable_pipe_func(struct drm_crtc *crtc)
734{
735 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
736 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
737 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
738 enum pipe pipe = intel_crtc->pipe;
739 uint32_t temp;
740
72662e10 741 /* Enable PIPE_DDI_FUNC_CTL for the pipe to work in HDMI mode */
8d9ddbcb 742 temp = PIPE_DDI_FUNC_ENABLE;
dfcef252
PZ
743
744 switch (intel_crtc->bpp) {
745 case 18:
746 temp |= PIPE_DDI_BPC_6;
747 break;
748 case 24:
749 temp |= PIPE_DDI_BPC_8;
750 break;
751 case 30:
752 temp |= PIPE_DDI_BPC_10;
753 break;
754 case 36:
755 temp |= PIPE_DDI_BPC_12;
756 break;
757 default:
758 WARN(1, "%d bpp unsupported by pipe DDI function\n",
759 intel_crtc->bpp);
760 }
72662e10 761
8d9ddbcb 762 if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
f63eb7c4 763 temp |= PIPE_DDI_PVSYNC;
8d9ddbcb 764 if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
f63eb7c4
PZ
765 temp |= PIPE_DDI_PHSYNC;
766
8d9ddbcb
PZ
767 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
768 struct intel_hdmi *intel_hdmi =
769 enc_to_intel_hdmi(&intel_encoder->base);
770
771 if (intel_hdmi->has_hdmi_sink)
772 temp |= PIPE_DDI_MODE_SELECT_HDMI;
773 else
774 temp |= PIPE_DDI_MODE_SELECT_DVI;
775
776 temp |= PIPE_DDI_SELECT_PORT(intel_hdmi->ddi_port);
777 } else if (intel_encoder->type == INTEL_OUTPUT_ANALOG) {
778 temp |= PIPE_DDI_MODE_SELECT_FDI;
779 temp |= PIPE_DDI_SELECT_PORT(PORT_E);
780 } else {
781 WARN(1, "Invalid encoder type %d for pipe %d\n",
782 intel_encoder->type, pipe);
783 }
784
72662e10 785 I915_WRITE(DDI_FUNC_CTL(pipe), temp);
8d9ddbcb 786}
72662e10 787
8d9ddbcb
PZ
788void intel_ddi_disable_pipe_func(struct drm_i915_private *dev_priv,
789 enum pipe pipe)
790{
791 uint32_t reg = DDI_FUNC_CTL(pipe);
792 uint32_t val = I915_READ(reg);
793
794 val &= ~(PIPE_DDI_FUNC_ENABLE | PIPE_DDI_PORT_MASK);
795 val |= PIPE_DDI_PORT_NONE;
796 I915_WRITE(reg, val);
72662e10
ED
797}
798
85234cdc
DV
799bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
800 enum pipe *pipe)
801{
802 struct drm_device *dev = encoder->base.dev;
803 struct drm_i915_private *dev_priv = dev->dev_private;
804 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
805 u32 tmp;
806 int i;
807
808 tmp = I915_READ(DDI_BUF_CTL(intel_hdmi->ddi_port));
809
810 if (!(tmp & DDI_BUF_CTL_ENABLE))
811 return false;
812
813 for_each_pipe(i) {
814 tmp = I915_READ(DDI_FUNC_CTL(i));
815
816 if ((tmp & PIPE_DDI_PORT_MASK)
817 == PIPE_DDI_SELECT_PORT(intel_hdmi->ddi_port)) {
818 *pipe = i;
819 return true;
820 }
821 }
822
823 DRM_DEBUG_KMS("No pipe for ddi port %i found\n", intel_hdmi->ddi_port);
824
825 return true;
826}
827
5ab432ef 828void intel_enable_ddi(struct intel_encoder *encoder)
72662e10 829{
5ab432ef 830 struct drm_device *dev = encoder->base.dev;
72662e10 831 struct drm_i915_private *dev_priv = dev->dev_private;
5ab432ef 832 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
72662e10
ED
833 int port = intel_hdmi->ddi_port;
834 u32 temp;
835
836 temp = I915_READ(DDI_BUF_CTL(port));
5ab432ef 837 temp |= DDI_BUF_CTL_ENABLE;
72662e10
ED
838
839 /* Enable DDI_BUF_CTL. In HDMI/DVI mode, the port width,
840 * and swing/emphasis values are ignored so nothing special needs
841 * to be done besides enabling the port.
842 */
5ab432ef
DV
843 I915_WRITE(DDI_BUF_CTL(port), temp);
844}
845
846void intel_disable_ddi(struct intel_encoder *encoder)
847{
848 struct drm_device *dev = encoder->base.dev;
849 struct drm_i915_private *dev_priv = dev->dev_private;
850 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
851 int port = intel_hdmi->ddi_port;
852 u32 temp;
853
854 temp = I915_READ(DDI_BUF_CTL(port));
855 temp &= ~DDI_BUF_CTL_ENABLE;
856
857 I915_WRITE(DDI_BUF_CTL(port), temp);
72662e10 858}
79f689aa
PZ
859
860static int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
861{
862 if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT)
863 return 450;
864 else if ((I915_READ(LCPLL_CTL) & LCPLL_CLK_FREQ_MASK) ==
865 LCPLL_CLK_FREQ_450)
866 return 450;
867 else
868 return 540;
869}
870
871void intel_ddi_pll_init(struct drm_device *dev)
872{
873 struct drm_i915_private *dev_priv = dev->dev_private;
874 uint32_t val = I915_READ(LCPLL_CTL);
875
876 /* The LCPLL register should be turned on by the BIOS. For now let's
877 * just check its state and print errors in case something is wrong.
878 * Don't even try to turn it on.
879 */
880
881 DRM_DEBUG_KMS("CDCLK running at %dMHz\n",
882 intel_ddi_get_cdclk_freq(dev_priv));
883
884 if (val & LCPLL_CD_SOURCE_FCLK)
885 DRM_ERROR("CDCLK source is not LCPLL\n");
886
887 if (val & LCPLL_PLL_DISABLE)
888 DRM_ERROR("LCPLL is disabled\n");
889}
This page took 0.078737 seconds and 5 git commands to generate.