2 * Copyright © 2012 Intel Corporation
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:
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
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
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
29 #include "intel_drv.h"
31 struct ddi_buf_trans
{
32 u32 trans1
; /* balance leg enable, de-emph level */
33 u32 trans2
; /* vref sel, vswing */
36 /* HDMI/DVI modes ignore everything but the last 2 items. So we share
37 * them for both DP and FDI transports, allowing those ports to
38 * automatically adapt to HDMI connections as well
40 static const struct ddi_buf_trans hsw_ddi_translations_dp
[] = {
41 { 0x00FFFFFF, 0x0006000E },
42 { 0x00D75FFF, 0x0005000A },
43 { 0x00C30FFF, 0x00040006 },
44 { 0x80AAAFFF, 0x000B0000 },
45 { 0x00FFFFFF, 0x0005000A },
46 { 0x00D75FFF, 0x000C0004 },
47 { 0x80C30FFF, 0x000B0000 },
48 { 0x00FFFFFF, 0x00040006 },
49 { 0x80D75FFF, 0x000B0000 },
52 static const struct ddi_buf_trans hsw_ddi_translations_fdi
[] = {
53 { 0x00FFFFFF, 0x0007000E },
54 { 0x00D75FFF, 0x000F000A },
55 { 0x00C30FFF, 0x00060006 },
56 { 0x00AAAFFF, 0x001E0000 },
57 { 0x00FFFFFF, 0x000F000A },
58 { 0x00D75FFF, 0x00160004 },
59 { 0x00C30FFF, 0x001E0000 },
60 { 0x00FFFFFF, 0x00060006 },
61 { 0x00D75FFF, 0x001E0000 },
64 static const struct ddi_buf_trans hsw_ddi_translations_hdmi
[] = {
65 /* Idx NT mV d T mV d db */
66 { 0x00FFFFFF, 0x0006000E }, /* 0: 400 400 0 */
67 { 0x00E79FFF, 0x000E000C }, /* 1: 400 500 2 */
68 { 0x00D75FFF, 0x0005000A }, /* 2: 400 600 3.5 */
69 { 0x00FFFFFF, 0x0005000A }, /* 3: 600 600 0 */
70 { 0x00E79FFF, 0x001D0007 }, /* 4: 600 750 2 */
71 { 0x00D75FFF, 0x000C0004 }, /* 5: 600 900 3.5 */
72 { 0x00FFFFFF, 0x00040006 }, /* 6: 800 800 0 */
73 { 0x80E79FFF, 0x00030002 }, /* 7: 800 1000 2 */
74 { 0x00FFFFFF, 0x00140005 }, /* 8: 850 850 0 */
75 { 0x00FFFFFF, 0x000C0004 }, /* 9: 900 900 0 */
76 { 0x00FFFFFF, 0x001C0003 }, /* 10: 950 950 0 */
77 { 0x80FFFFFF, 0x00030002 }, /* 11: 1000 1000 0 */
80 static const struct ddi_buf_trans bdw_ddi_translations_edp
[] = {
81 { 0x00FFFFFF, 0x00000012 },
82 { 0x00EBAFFF, 0x00020011 },
83 { 0x00C71FFF, 0x0006000F },
84 { 0x00AAAFFF, 0x000E000A },
85 { 0x00FFFFFF, 0x00020011 },
86 { 0x00DB6FFF, 0x0005000F },
87 { 0x00BEEFFF, 0x000A000C },
88 { 0x00FFFFFF, 0x0005000F },
89 { 0x00DB6FFF, 0x000A000C },
92 static const struct ddi_buf_trans bdw_ddi_translations_dp
[] = {
93 { 0x00FFFFFF, 0x0007000E },
94 { 0x00D75FFF, 0x000E000A },
95 { 0x00BEFFFF, 0x00140006 },
96 { 0x80B2CFFF, 0x001B0002 },
97 { 0x00FFFFFF, 0x000E000A },
98 { 0x00DB6FFF, 0x00160005 },
99 { 0x80C71FFF, 0x001A0002 },
100 { 0x00F7DFFF, 0x00180004 },
101 { 0x80D75FFF, 0x001B0002 },
104 static const struct ddi_buf_trans bdw_ddi_translations_fdi
[] = {
105 { 0x00FFFFFF, 0x0001000E },
106 { 0x00D75FFF, 0x0004000A },
107 { 0x00C30FFF, 0x00070006 },
108 { 0x00AAAFFF, 0x000C0000 },
109 { 0x00FFFFFF, 0x0004000A },
110 { 0x00D75FFF, 0x00090004 },
111 { 0x00C30FFF, 0x000C0000 },
112 { 0x00FFFFFF, 0x00070006 },
113 { 0x00D75FFF, 0x000C0000 },
116 static const struct ddi_buf_trans bdw_ddi_translations_hdmi
[] = {
117 /* Idx NT mV d T mV df db */
118 { 0x00FFFFFF, 0x0007000E }, /* 0: 400 400 0 */
119 { 0x00D75FFF, 0x000E000A }, /* 1: 400 600 3.5 */
120 { 0x00BEFFFF, 0x00140006 }, /* 2: 400 800 6 */
121 { 0x00FFFFFF, 0x0009000D }, /* 3: 450 450 0 */
122 { 0x00FFFFFF, 0x000E000A }, /* 4: 600 600 0 */
123 { 0x00D7FFFF, 0x00140006 }, /* 5: 600 800 2.5 */
124 { 0x80CB2FFF, 0x001B0002 }, /* 6: 600 1000 4.5 */
125 { 0x00FFFFFF, 0x00140006 }, /* 7: 800 800 0 */
126 { 0x80E79FFF, 0x001B0002 }, /* 8: 800 1000 2 */
127 { 0x80FFFFFF, 0x001B0002 }, /* 9: 1000 1000 0 */
130 static const struct ddi_buf_trans skl_ddi_translations_dp
[] = {
131 { 0x00000018, 0x000000a0 },
132 { 0x00004014, 0x00000098 },
133 { 0x00006012, 0x00000088 },
134 { 0x00008010, 0x00000080 },
135 { 0x00000018, 0x00000098 },
136 { 0x00004014, 0x00000088 },
137 { 0x00006012, 0x00000080 },
138 { 0x00000018, 0x00000088 },
139 { 0x00004014, 0x00000080 },
142 static const struct ddi_buf_trans skl_ddi_translations_hdmi
[] = {
143 /* Idx NT mV T mV db */
144 { 0x00000018, 0x000000a0 }, /* 0: 400 400 0 */
145 { 0x00004014, 0x00000098 }, /* 1: 400 600 3.5 */
146 { 0x00006012, 0x00000088 }, /* 2: 400 800 6 */
147 { 0x00000018, 0x0000003c }, /* 3: 450 450 0 */
148 { 0x00000018, 0x00000098 }, /* 4: 600 600 0 */
149 { 0x00003015, 0x00000088 }, /* 5: 600 800 2.5 */
150 { 0x00005013, 0x00000080 }, /* 6: 600 1000 4.5 */
151 { 0x00000018, 0x00000088 }, /* 7: 800 800 0 */
152 { 0x00000096, 0x00000080 }, /* 8: 800 1000 2 */
153 { 0x00000018, 0x00000080 }, /* 9: 1200 1200 0 */
156 enum port
intel_ddi_get_encoder_port(struct intel_encoder
*intel_encoder
)
158 struct drm_encoder
*encoder
= &intel_encoder
->base
;
159 int type
= intel_encoder
->type
;
161 if (type
== INTEL_OUTPUT_DP_MST
) {
162 struct intel_digital_port
*intel_dig_port
= enc_to_mst(encoder
)->primary
;
163 return intel_dig_port
->port
;
164 } else if (type
== INTEL_OUTPUT_DISPLAYPORT
|| type
== INTEL_OUTPUT_EDP
||
165 type
== INTEL_OUTPUT_HDMI
|| type
== INTEL_OUTPUT_UNKNOWN
) {
166 struct intel_digital_port
*intel_dig_port
=
167 enc_to_dig_port(encoder
);
168 return intel_dig_port
->port
;
170 } else if (type
== INTEL_OUTPUT_ANALOG
) {
174 DRM_ERROR("Invalid DDI encoder type %d\n", type
);
180 * Starting with Haswell, DDI port buffers must be programmed with correct
181 * values in advance. The buffer values are different for FDI and DP modes,
182 * but the HDMI/DVI fields are shared among those. So we program the DDI
183 * in either FDI or DP modes only, as HDMI connections will work with both
186 static void intel_prepare_ddi_buffers(struct drm_device
*dev
, enum port port
)
188 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
190 int i
, n_hdmi_entries
, hdmi_800mV_0dB
;
191 int hdmi_level
= dev_priv
->vbt
.ddi_port_info
[port
].hdmi_level_shift
;
192 const struct ddi_buf_trans
*ddi_translations_fdi
;
193 const struct ddi_buf_trans
*ddi_translations_dp
;
194 const struct ddi_buf_trans
*ddi_translations_edp
;
195 const struct ddi_buf_trans
*ddi_translations_hdmi
;
196 const struct ddi_buf_trans
*ddi_translations
;
198 if (IS_SKYLAKE(dev
)) {
199 ddi_translations_fdi
= NULL
;
200 ddi_translations_dp
= skl_ddi_translations_dp
;
201 ddi_translations_edp
= skl_ddi_translations_dp
;
202 ddi_translations_hdmi
= skl_ddi_translations_hdmi
;
203 n_hdmi_entries
= ARRAY_SIZE(skl_ddi_translations_hdmi
);
205 } else if (IS_BROADWELL(dev
)) {
206 ddi_translations_fdi
= bdw_ddi_translations_fdi
;
207 ddi_translations_dp
= bdw_ddi_translations_dp
;
208 ddi_translations_edp
= bdw_ddi_translations_edp
;
209 ddi_translations_hdmi
= bdw_ddi_translations_hdmi
;
210 n_hdmi_entries
= ARRAY_SIZE(bdw_ddi_translations_hdmi
);
212 } else if (IS_HASWELL(dev
)) {
213 ddi_translations_fdi
= hsw_ddi_translations_fdi
;
214 ddi_translations_dp
= hsw_ddi_translations_dp
;
215 ddi_translations_edp
= hsw_ddi_translations_dp
;
216 ddi_translations_hdmi
= hsw_ddi_translations_hdmi
;
217 n_hdmi_entries
= ARRAY_SIZE(hsw_ddi_translations_hdmi
);
220 WARN(1, "ddi translation table missing\n");
221 ddi_translations_edp
= bdw_ddi_translations_dp
;
222 ddi_translations_fdi
= bdw_ddi_translations_fdi
;
223 ddi_translations_dp
= bdw_ddi_translations_dp
;
224 ddi_translations_hdmi
= bdw_ddi_translations_hdmi
;
225 n_hdmi_entries
= ARRAY_SIZE(bdw_ddi_translations_hdmi
);
231 ddi_translations
= ddi_translations_edp
;
235 ddi_translations
= ddi_translations_dp
;
238 if (intel_dp_is_edp(dev
, PORT_D
))
239 ddi_translations
= ddi_translations_edp
;
241 ddi_translations
= ddi_translations_dp
;
244 if (ddi_translations_fdi
)
245 ddi_translations
= ddi_translations_fdi
;
247 ddi_translations
= ddi_translations_dp
;
253 for (i
= 0, reg
= DDI_BUF_TRANS(port
);
254 i
< ARRAY_SIZE(hsw_ddi_translations_fdi
); i
++) {
255 I915_WRITE(reg
, ddi_translations
[i
].trans1
);
257 I915_WRITE(reg
, ddi_translations
[i
].trans2
);
261 /* Choose a good default if VBT is badly populated */
262 if (hdmi_level
== HDMI_LEVEL_SHIFT_UNKNOWN
||
263 hdmi_level
>= n_hdmi_entries
)
264 hdmi_level
= hdmi_800mV_0dB
;
266 /* Entry 9 is for HDMI: */
267 I915_WRITE(reg
, ddi_translations_hdmi
[hdmi_level
].trans1
);
269 I915_WRITE(reg
, ddi_translations_hdmi
[hdmi_level
].trans2
);
273 /* Program DDI buffers translations for DP. By default, program ports A-D in DP
274 * mode and port E for FDI.
276 void intel_prepare_ddi(struct drm_device
*dev
)
283 for (port
= PORT_A
; port
<= PORT_E
; port
++)
284 intel_prepare_ddi_buffers(dev
, port
);
287 static void intel_wait_ddi_buf_idle(struct drm_i915_private
*dev_priv
,
290 uint32_t reg
= DDI_BUF_CTL(port
);
293 for (i
= 0; i
< 8; i
++) {
295 if (I915_READ(reg
) & DDI_BUF_IS_IDLE
)
298 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port
));
301 /* Starting with Haswell, different DDI ports can work in FDI mode for
302 * connection to the PCH-located connectors. For this, it is necessary to train
303 * both the DDI port and PCH receiver for the desired DDI buffer settings.
305 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
306 * please note that when FDI mode is active on DDI E, it shares 2 lines with
307 * DDI A (which is used for eDP)
310 void hsw_fdi_link_train(struct drm_crtc
*crtc
)
312 struct drm_device
*dev
= crtc
->dev
;
313 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
314 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
315 u32 temp
, i
, rx_ctl_val
;
317 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
318 * mode set "sequence for CRT port" document:
319 * - TP1 to TP2 time with the default value
322 * WaFDIAutoLinkSetTimingOverrride:hsw
324 I915_WRITE(_FDI_RXA_MISC
, FDI_RX_PWRDN_LANE1_VAL(2) |
325 FDI_RX_PWRDN_LANE0_VAL(2) |
326 FDI_RX_TP1_TO_TP2_48
| FDI_RX_FDI_DELAY_90
);
328 /* Enable the PCH Receiver FDI PLL */
329 rx_ctl_val
= dev_priv
->fdi_rx_config
| FDI_RX_ENHANCE_FRAME_ENABLE
|
331 FDI_DP_PORT_WIDTH(intel_crtc
->config
.fdi_lanes
);
332 I915_WRITE(_FDI_RXA_CTL
, rx_ctl_val
);
333 POSTING_READ(_FDI_RXA_CTL
);
336 /* Switch from Rawclk to PCDclk */
337 rx_ctl_val
|= FDI_PCDCLK
;
338 I915_WRITE(_FDI_RXA_CTL
, rx_ctl_val
);
340 /* Configure Port Clock Select */
341 I915_WRITE(PORT_CLK_SEL(PORT_E
), intel_crtc
->config
.ddi_pll_sel
);
342 WARN_ON(intel_crtc
->config
.ddi_pll_sel
!= PORT_CLK_SEL_SPLL
);
344 /* Start the training iterating through available voltages and emphasis,
345 * testing each value twice. */
346 for (i
= 0; i
< ARRAY_SIZE(hsw_ddi_translations_fdi
) * 2; i
++) {
347 /* Configure DP_TP_CTL with auto-training */
348 I915_WRITE(DP_TP_CTL(PORT_E
),
349 DP_TP_CTL_FDI_AUTOTRAIN
|
350 DP_TP_CTL_ENHANCED_FRAME_ENABLE
|
351 DP_TP_CTL_LINK_TRAIN_PAT1
|
354 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
355 * DDI E does not support port reversal, the functionality is
356 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
357 * port reversal bit */
358 I915_WRITE(DDI_BUF_CTL(PORT_E
),
360 ((intel_crtc
->config
.fdi_lanes
- 1) << 1) |
361 DDI_BUF_TRANS_SELECT(i
/ 2));
362 POSTING_READ(DDI_BUF_CTL(PORT_E
));
366 /* Program PCH FDI Receiver TU */
367 I915_WRITE(_FDI_RXA_TUSIZE1
, TU_SIZE(64));
369 /* Enable PCH FDI Receiver with auto-training */
370 rx_ctl_val
|= FDI_RX_ENABLE
| FDI_LINK_TRAIN_AUTO
;
371 I915_WRITE(_FDI_RXA_CTL
, rx_ctl_val
);
372 POSTING_READ(_FDI_RXA_CTL
);
374 /* Wait for FDI receiver lane calibration */
377 /* Unset FDI_RX_MISC pwrdn lanes */
378 temp
= I915_READ(_FDI_RXA_MISC
);
379 temp
&= ~(FDI_RX_PWRDN_LANE1_MASK
| FDI_RX_PWRDN_LANE0_MASK
);
380 I915_WRITE(_FDI_RXA_MISC
, temp
);
381 POSTING_READ(_FDI_RXA_MISC
);
383 /* Wait for FDI auto training time */
386 temp
= I915_READ(DP_TP_STATUS(PORT_E
));
387 if (temp
& DP_TP_STATUS_AUTOTRAIN_DONE
) {
388 DRM_DEBUG_KMS("FDI link training done on step %d\n", i
);
390 /* Enable normal pixel sending for FDI */
391 I915_WRITE(DP_TP_CTL(PORT_E
),
392 DP_TP_CTL_FDI_AUTOTRAIN
|
393 DP_TP_CTL_LINK_TRAIN_NORMAL
|
394 DP_TP_CTL_ENHANCED_FRAME_ENABLE
|
400 temp
= I915_READ(DDI_BUF_CTL(PORT_E
));
401 temp
&= ~DDI_BUF_CTL_ENABLE
;
402 I915_WRITE(DDI_BUF_CTL(PORT_E
), temp
);
403 POSTING_READ(DDI_BUF_CTL(PORT_E
));
405 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
406 temp
= I915_READ(DP_TP_CTL(PORT_E
));
407 temp
&= ~(DP_TP_CTL_ENABLE
| DP_TP_CTL_LINK_TRAIN_MASK
);
408 temp
|= DP_TP_CTL_LINK_TRAIN_PAT1
;
409 I915_WRITE(DP_TP_CTL(PORT_E
), temp
);
410 POSTING_READ(DP_TP_CTL(PORT_E
));
412 intel_wait_ddi_buf_idle(dev_priv
, PORT_E
);
414 rx_ctl_val
&= ~FDI_RX_ENABLE
;
415 I915_WRITE(_FDI_RXA_CTL
, rx_ctl_val
);
416 POSTING_READ(_FDI_RXA_CTL
);
418 /* Reset FDI_RX_MISC pwrdn lanes */
419 temp
= I915_READ(_FDI_RXA_MISC
);
420 temp
&= ~(FDI_RX_PWRDN_LANE1_MASK
| FDI_RX_PWRDN_LANE0_MASK
);
421 temp
|= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
422 I915_WRITE(_FDI_RXA_MISC
, temp
);
423 POSTING_READ(_FDI_RXA_MISC
);
426 DRM_ERROR("FDI link training failed!\n");
429 void intel_ddi_init_dp_buf_reg(struct intel_encoder
*encoder
)
431 struct intel_dp
*intel_dp
= enc_to_intel_dp(&encoder
->base
);
432 struct intel_digital_port
*intel_dig_port
=
433 enc_to_dig_port(&encoder
->base
);
435 intel_dp
->DP
= intel_dig_port
->saved_port_bits
|
436 DDI_BUF_CTL_ENABLE
| DDI_BUF_TRANS_SELECT(0);
437 intel_dp
->DP
|= DDI_PORT_WIDTH(intel_dp
->lane_count
);
441 static struct intel_encoder
*
442 intel_ddi_get_crtc_encoder(struct drm_crtc
*crtc
)
444 struct drm_device
*dev
= crtc
->dev
;
445 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
446 struct intel_encoder
*intel_encoder
, *ret
= NULL
;
447 int num_encoders
= 0;
449 for_each_encoder_on_crtc(dev
, crtc
, intel_encoder
) {
454 if (num_encoders
!= 1)
455 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders
,
456 pipe_name(intel_crtc
->pipe
));
462 static struct intel_encoder
*
463 intel_ddi_get_crtc_new_encoder(struct intel_crtc
*crtc
)
465 struct drm_device
*dev
= crtc
->base
.dev
;
466 struct intel_encoder
*intel_encoder
, *ret
= NULL
;
467 int num_encoders
= 0;
469 for_each_intel_encoder(dev
, intel_encoder
) {
470 if (intel_encoder
->new_crtc
== crtc
) {
476 WARN(num_encoders
!= 1, "%d encoders on crtc for pipe %c\n", num_encoders
,
477 pipe_name(crtc
->pipe
));
484 #define LC_FREQ_2K U64_C(LC_FREQ * 2000)
490 /* Constraints for PLL good behavior */
496 #define abs_diff(a, b) ({ \
497 typeof(a) __a = (a); \
498 typeof(b) __b = (b); \
499 (void) (&__a == &__b); \
500 __a > __b ? (__a - __b) : (__b - __a); })
506 static unsigned wrpll_get_budget_for_freq(int clock
)
580 static void wrpll_update_rnp(uint64_t freq2k
, unsigned budget
,
581 unsigned r2
, unsigned n2
, unsigned p
,
582 struct wrpll_rnp
*best
)
584 uint64_t a
, b
, c
, d
, diff
, diff_best
;
586 /* No best (r,n,p) yet */
595 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
599 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
602 * and we would like delta <= budget.
604 * If the discrepancy is above the PPM-based budget, always prefer to
605 * improve upon the previous solution. However, if you're within the
606 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
608 a
= freq2k
* budget
* p
* r2
;
609 b
= freq2k
* budget
* best
->p
* best
->r2
;
610 diff
= abs_diff(freq2k
* p
* r2
, LC_FREQ_2K
* n2
);
611 diff_best
= abs_diff(freq2k
* best
->p
* best
->r2
,
612 LC_FREQ_2K
* best
->n2
);
614 d
= 1000000 * diff_best
;
616 if (a
< c
&& b
< d
) {
617 /* If both are above the budget, pick the closer */
618 if (best
->p
* best
->r2
* diff
< p
* r2
* diff_best
) {
623 } else if (a
>= c
&& b
< d
) {
624 /* If A is below the threshold but B is above it? Update. */
628 } else if (a
>= c
&& b
>= d
) {
629 /* Both are below the limit, so pick the higher n2/(r2*r2) */
630 if (n2
* best
->r2
* best
->r2
> best
->n2
* r2
* r2
) {
636 /* Otherwise a < c && b >= d, do nothing */
639 static int intel_ddi_calc_wrpll_link(struct drm_i915_private
*dev_priv
,
642 int refclk
= LC_FREQ
;
646 wrpll
= I915_READ(reg
);
647 switch (wrpll
& WRPLL_PLL_REF_MASK
) {
649 case WRPLL_PLL_NON_SSC
:
651 * We could calculate spread here, but our checking
652 * code only cares about 5% accuracy, and spread is a max of
657 case WRPLL_PLL_LCPLL
:
661 WARN(1, "bad wrpll refclk\n");
665 r
= wrpll
& WRPLL_DIVIDER_REF_MASK
;
666 p
= (wrpll
& WRPLL_DIVIDER_POST_MASK
) >> WRPLL_DIVIDER_POST_SHIFT
;
667 n
= (wrpll
& WRPLL_DIVIDER_FB_MASK
) >> WRPLL_DIVIDER_FB_SHIFT
;
669 /* Convert to KHz, p & r have a fixed point portion */
670 return (refclk
* n
* 100) / (p
* r
);
673 static void hsw_ddi_clock_get(struct intel_encoder
*encoder
,
674 struct intel_crtc_config
*pipe_config
)
676 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
680 val
= pipe_config
->ddi_pll_sel
;
681 switch (val
& PORT_CLK_SEL_MASK
) {
682 case PORT_CLK_SEL_LCPLL_810
:
685 case PORT_CLK_SEL_LCPLL_1350
:
688 case PORT_CLK_SEL_LCPLL_2700
:
691 case PORT_CLK_SEL_WRPLL1
:
692 link_clock
= intel_ddi_calc_wrpll_link(dev_priv
, WRPLL_CTL1
);
694 case PORT_CLK_SEL_WRPLL2
:
695 link_clock
= intel_ddi_calc_wrpll_link(dev_priv
, WRPLL_CTL2
);
697 case PORT_CLK_SEL_SPLL
:
698 pll
= I915_READ(SPLL_CTL
) & SPLL_PLL_FREQ_MASK
;
699 if (pll
== SPLL_PLL_FREQ_810MHz
)
701 else if (pll
== SPLL_PLL_FREQ_1350MHz
)
703 else if (pll
== SPLL_PLL_FREQ_2700MHz
)
706 WARN(1, "bad spll freq\n");
711 WARN(1, "bad port clock sel\n");
715 pipe_config
->port_clock
= link_clock
* 2;
717 if (pipe_config
->has_pch_encoder
)
718 pipe_config
->adjusted_mode
.crtc_clock
=
719 intel_dotclock_calculate(pipe_config
->port_clock
,
720 &pipe_config
->fdi_m_n
);
721 else if (pipe_config
->has_dp_encoder
)
722 pipe_config
->adjusted_mode
.crtc_clock
=
723 intel_dotclock_calculate(pipe_config
->port_clock
,
724 &pipe_config
->dp_m_n
);
726 pipe_config
->adjusted_mode
.crtc_clock
= pipe_config
->port_clock
;
729 void intel_ddi_clock_get(struct intel_encoder
*encoder
,
730 struct intel_crtc_config
*pipe_config
)
732 hsw_ddi_clock_get(encoder
, pipe_config
);
736 hsw_ddi_calculate_wrpll(int clock
/* in Hz */,
737 unsigned *r2_out
, unsigned *n2_out
, unsigned *p_out
)
741 struct wrpll_rnp best
= { 0, 0, 0 };
744 freq2k
= clock
/ 100;
746 budget
= wrpll_get_budget_for_freq(clock
);
748 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
749 * and directly pass the LC PLL to it. */
750 if (freq2k
== 5400000) {
758 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
761 * We want R so that REF_MIN <= Ref <= REF_MAX.
762 * Injecting R2 = 2 * R gives:
763 * REF_MAX * r2 > LC_FREQ * 2 and
764 * REF_MIN * r2 < LC_FREQ * 2
766 * Which means the desired boundaries for r2 are:
767 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
770 for (r2
= LC_FREQ
* 2 / REF_MAX
+ 1;
771 r2
<= LC_FREQ
* 2 / REF_MIN
;
775 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
777 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
778 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
779 * VCO_MAX * r2 > n2 * LC_FREQ and
780 * VCO_MIN * r2 < n2 * LC_FREQ)
782 * Which means the desired boundaries for n2 are:
783 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
785 for (n2
= VCO_MIN
* r2
/ LC_FREQ
+ 1;
786 n2
<= VCO_MAX
* r2
/ LC_FREQ
;
789 for (p
= P_MIN
; p
<= P_MAX
; p
+= P_INC
)
790 wrpll_update_rnp(freq2k
, budget
,
801 hsw_ddi_pll_select(struct intel_crtc
*intel_crtc
,
802 struct intel_encoder
*intel_encoder
,
805 if (intel_encoder
->type
== INTEL_OUTPUT_HDMI
) {
806 struct intel_shared_dpll
*pll
;
810 hsw_ddi_calculate_wrpll(clock
* 1000, &r2
, &n2
, &p
);
812 val
= WRPLL_PLL_ENABLE
| WRPLL_PLL_LCPLL
|
813 WRPLL_DIVIDER_REFERENCE(r2
) | WRPLL_DIVIDER_FEEDBACK(n2
) |
814 WRPLL_DIVIDER_POST(p
);
816 intel_crtc
->new_config
->dpll_hw_state
.wrpll
= val
;
818 pll
= intel_get_shared_dpll(intel_crtc
);
820 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
821 pipe_name(intel_crtc
->pipe
));
825 intel_crtc
->new_config
->ddi_pll_sel
= PORT_CLK_SEL_WRPLL(pll
->id
);
833 * Tries to find a *shared* PLL for the CRTC and store it in
834 * intel_crtc->ddi_pll_sel.
836 * For private DPLLs, compute_config() should do the selection for us. This
837 * function should be folded into compute_config() eventually.
839 bool intel_ddi_pll_select(struct intel_crtc
*intel_crtc
)
841 struct intel_encoder
*intel_encoder
=
842 intel_ddi_get_crtc_new_encoder(intel_crtc
);
843 int clock
= intel_crtc
->new_config
->port_clock
;
845 intel_put_shared_dpll(intel_crtc
);
847 return hsw_ddi_pll_select(intel_crtc
, intel_encoder
, clock
);
850 void intel_ddi_set_pipe_settings(struct drm_crtc
*crtc
)
852 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
853 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
854 struct intel_encoder
*intel_encoder
= intel_ddi_get_crtc_encoder(crtc
);
855 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
856 int type
= intel_encoder
->type
;
859 if (type
== INTEL_OUTPUT_DISPLAYPORT
|| type
== INTEL_OUTPUT_EDP
|| type
== INTEL_OUTPUT_DP_MST
) {
860 temp
= TRANS_MSA_SYNC_CLK
;
861 switch (intel_crtc
->config
.pipe_bpp
) {
863 temp
|= TRANS_MSA_6_BPC
;
866 temp
|= TRANS_MSA_8_BPC
;
869 temp
|= TRANS_MSA_10_BPC
;
872 temp
|= TRANS_MSA_12_BPC
;
877 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder
), temp
);
881 void intel_ddi_set_vc_payload_alloc(struct drm_crtc
*crtc
, bool state
)
883 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
884 struct drm_device
*dev
= crtc
->dev
;
885 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
886 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
888 temp
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
890 temp
|= TRANS_DDI_DP_VC_PAYLOAD_ALLOC
;
892 temp
&= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC
;
893 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder
), temp
);
896 void intel_ddi_enable_transcoder_func(struct drm_crtc
*crtc
)
898 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
899 struct intel_encoder
*intel_encoder
= intel_ddi_get_crtc_encoder(crtc
);
900 struct drm_encoder
*encoder
= &intel_encoder
->base
;
901 struct drm_device
*dev
= crtc
->dev
;
902 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
903 enum pipe pipe
= intel_crtc
->pipe
;
904 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
905 enum port port
= intel_ddi_get_encoder_port(intel_encoder
);
906 int type
= intel_encoder
->type
;
909 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
910 temp
= TRANS_DDI_FUNC_ENABLE
;
911 temp
|= TRANS_DDI_SELECT_PORT(port
);
913 switch (intel_crtc
->config
.pipe_bpp
) {
915 temp
|= TRANS_DDI_BPC_6
;
918 temp
|= TRANS_DDI_BPC_8
;
921 temp
|= TRANS_DDI_BPC_10
;
924 temp
|= TRANS_DDI_BPC_12
;
930 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_PVSYNC
)
931 temp
|= TRANS_DDI_PVSYNC
;
932 if (intel_crtc
->config
.adjusted_mode
.flags
& DRM_MODE_FLAG_PHSYNC
)
933 temp
|= TRANS_DDI_PHSYNC
;
935 if (cpu_transcoder
== TRANSCODER_EDP
) {
938 /* On Haswell, can only use the always-on power well for
939 * eDP when not using the panel fitter, and when not
940 * using motion blur mitigation (which we don't
942 if (IS_HASWELL(dev
) &&
943 (intel_crtc
->config
.pch_pfit
.enabled
||
944 intel_crtc
->config
.pch_pfit
.force_thru
))
945 temp
|= TRANS_DDI_EDP_INPUT_A_ONOFF
;
947 temp
|= TRANS_DDI_EDP_INPUT_A_ON
;
950 temp
|= TRANS_DDI_EDP_INPUT_B_ONOFF
;
953 temp
|= TRANS_DDI_EDP_INPUT_C_ONOFF
;
961 if (type
== INTEL_OUTPUT_HDMI
) {
962 if (intel_crtc
->config
.has_hdmi_sink
)
963 temp
|= TRANS_DDI_MODE_SELECT_HDMI
;
965 temp
|= TRANS_DDI_MODE_SELECT_DVI
;
967 } else if (type
== INTEL_OUTPUT_ANALOG
) {
968 temp
|= TRANS_DDI_MODE_SELECT_FDI
;
969 temp
|= (intel_crtc
->config
.fdi_lanes
- 1) << 1;
971 } else if (type
== INTEL_OUTPUT_DISPLAYPORT
||
972 type
== INTEL_OUTPUT_EDP
) {
973 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
975 if (intel_dp
->is_mst
) {
976 temp
|= TRANS_DDI_MODE_SELECT_DP_MST
;
978 temp
|= TRANS_DDI_MODE_SELECT_DP_SST
;
980 temp
|= DDI_PORT_WIDTH(intel_dp
->lane_count
);
981 } else if (type
== INTEL_OUTPUT_DP_MST
) {
982 struct intel_dp
*intel_dp
= &enc_to_mst(encoder
)->primary
->dp
;
984 if (intel_dp
->is_mst
) {
985 temp
|= TRANS_DDI_MODE_SELECT_DP_MST
;
987 temp
|= TRANS_DDI_MODE_SELECT_DP_SST
;
989 temp
|= DDI_PORT_WIDTH(intel_dp
->lane_count
);
991 WARN(1, "Invalid encoder type %d for pipe %c\n",
992 intel_encoder
->type
, pipe_name(pipe
));
995 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder
), temp
);
998 void intel_ddi_disable_transcoder_func(struct drm_i915_private
*dev_priv
,
999 enum transcoder cpu_transcoder
)
1001 uint32_t reg
= TRANS_DDI_FUNC_CTL(cpu_transcoder
);
1002 uint32_t val
= I915_READ(reg
);
1004 val
&= ~(TRANS_DDI_FUNC_ENABLE
| TRANS_DDI_PORT_MASK
| TRANS_DDI_DP_VC_PAYLOAD_ALLOC
);
1005 val
|= TRANS_DDI_PORT_NONE
;
1006 I915_WRITE(reg
, val
);
1009 bool intel_ddi_connector_get_hw_state(struct intel_connector
*intel_connector
)
1011 struct drm_device
*dev
= intel_connector
->base
.dev
;
1012 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1013 struct intel_encoder
*intel_encoder
= intel_connector
->encoder
;
1014 int type
= intel_connector
->base
.connector_type
;
1015 enum port port
= intel_ddi_get_encoder_port(intel_encoder
);
1017 enum transcoder cpu_transcoder
;
1018 enum intel_display_power_domain power_domain
;
1021 power_domain
= intel_display_port_power_domain(intel_encoder
);
1022 if (!intel_display_power_is_enabled(dev_priv
, power_domain
))
1025 if (!intel_encoder
->get_hw_state(intel_encoder
, &pipe
))
1029 cpu_transcoder
= TRANSCODER_EDP
;
1031 cpu_transcoder
= (enum transcoder
) pipe
;
1033 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1035 switch (tmp
& TRANS_DDI_MODE_SELECT_MASK
) {
1036 case TRANS_DDI_MODE_SELECT_HDMI
:
1037 case TRANS_DDI_MODE_SELECT_DVI
:
1038 return (type
== DRM_MODE_CONNECTOR_HDMIA
);
1040 case TRANS_DDI_MODE_SELECT_DP_SST
:
1041 if (type
== DRM_MODE_CONNECTOR_eDP
)
1043 return (type
== DRM_MODE_CONNECTOR_DisplayPort
);
1044 case TRANS_DDI_MODE_SELECT_DP_MST
:
1045 /* if the transcoder is in MST state then
1046 * connector isn't connected */
1049 case TRANS_DDI_MODE_SELECT_FDI
:
1050 return (type
== DRM_MODE_CONNECTOR_VGA
);
1057 bool intel_ddi_get_hw_state(struct intel_encoder
*encoder
,
1060 struct drm_device
*dev
= encoder
->base
.dev
;
1061 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1062 enum port port
= intel_ddi_get_encoder_port(encoder
);
1063 enum intel_display_power_domain power_domain
;
1067 power_domain
= intel_display_port_power_domain(encoder
);
1068 if (!intel_display_power_is_enabled(dev_priv
, power_domain
))
1071 tmp
= I915_READ(DDI_BUF_CTL(port
));
1073 if (!(tmp
& DDI_BUF_CTL_ENABLE
))
1076 if (port
== PORT_A
) {
1077 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP
));
1079 switch (tmp
& TRANS_DDI_EDP_INPUT_MASK
) {
1080 case TRANS_DDI_EDP_INPUT_A_ON
:
1081 case TRANS_DDI_EDP_INPUT_A_ONOFF
:
1084 case TRANS_DDI_EDP_INPUT_B_ONOFF
:
1087 case TRANS_DDI_EDP_INPUT_C_ONOFF
:
1094 for (i
= TRANSCODER_A
; i
<= TRANSCODER_C
; i
++) {
1095 tmp
= I915_READ(TRANS_DDI_FUNC_CTL(i
));
1097 if ((tmp
& TRANS_DDI_PORT_MASK
)
1098 == TRANS_DDI_SELECT_PORT(port
)) {
1099 if ((tmp
& TRANS_DDI_MODE_SELECT_MASK
) == TRANS_DDI_MODE_SELECT_DP_MST
)
1108 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port
));
1113 void intel_ddi_enable_pipe_clock(struct intel_crtc
*intel_crtc
)
1115 struct drm_crtc
*crtc
= &intel_crtc
->base
;
1116 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
1117 struct intel_encoder
*intel_encoder
= intel_ddi_get_crtc_encoder(crtc
);
1118 enum port port
= intel_ddi_get_encoder_port(intel_encoder
);
1119 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
1121 if (cpu_transcoder
!= TRANSCODER_EDP
)
1122 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder
),
1123 TRANS_CLK_SEL_PORT(port
));
1126 void intel_ddi_disable_pipe_clock(struct intel_crtc
*intel_crtc
)
1128 struct drm_i915_private
*dev_priv
= intel_crtc
->base
.dev
->dev_private
;
1129 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
1131 if (cpu_transcoder
!= TRANSCODER_EDP
)
1132 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder
),
1133 TRANS_CLK_SEL_DISABLED
);
1136 static void intel_ddi_pre_enable(struct intel_encoder
*intel_encoder
)
1138 struct drm_encoder
*encoder
= &intel_encoder
->base
;
1139 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
1140 struct intel_crtc
*crtc
= to_intel_crtc(encoder
->crtc
);
1141 enum port port
= intel_ddi_get_encoder_port(intel_encoder
);
1142 int type
= intel_encoder
->type
;
1144 if (type
== INTEL_OUTPUT_EDP
) {
1145 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
1146 intel_edp_panel_on(intel_dp
);
1149 WARN_ON(crtc
->config
.ddi_pll_sel
== PORT_CLK_SEL_NONE
);
1150 I915_WRITE(PORT_CLK_SEL(port
), crtc
->config
.ddi_pll_sel
);
1152 if (type
== INTEL_OUTPUT_DISPLAYPORT
|| type
== INTEL_OUTPUT_EDP
) {
1153 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
1155 intel_ddi_init_dp_buf_reg(intel_encoder
);
1157 intel_dp_sink_dpms(intel_dp
, DRM_MODE_DPMS_ON
);
1158 intel_dp_start_link_train(intel_dp
);
1159 intel_dp_complete_link_train(intel_dp
);
1161 intel_dp_stop_link_train(intel_dp
);
1162 } else if (type
== INTEL_OUTPUT_HDMI
) {
1163 struct intel_hdmi
*intel_hdmi
= enc_to_intel_hdmi(encoder
);
1165 intel_hdmi
->set_infoframes(encoder
,
1166 crtc
->config
.has_hdmi_sink
,
1167 &crtc
->config
.adjusted_mode
);
1171 static void intel_ddi_post_disable(struct intel_encoder
*intel_encoder
)
1173 struct drm_encoder
*encoder
= &intel_encoder
->base
;
1174 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
1175 enum port port
= intel_ddi_get_encoder_port(intel_encoder
);
1176 int type
= intel_encoder
->type
;
1180 val
= I915_READ(DDI_BUF_CTL(port
));
1181 if (val
& DDI_BUF_CTL_ENABLE
) {
1182 val
&= ~DDI_BUF_CTL_ENABLE
;
1183 I915_WRITE(DDI_BUF_CTL(port
), val
);
1187 val
= I915_READ(DP_TP_CTL(port
));
1188 val
&= ~(DP_TP_CTL_ENABLE
| DP_TP_CTL_LINK_TRAIN_MASK
);
1189 val
|= DP_TP_CTL_LINK_TRAIN_PAT1
;
1190 I915_WRITE(DP_TP_CTL(port
), val
);
1193 intel_wait_ddi_buf_idle(dev_priv
, port
);
1195 if (type
== INTEL_OUTPUT_DISPLAYPORT
|| type
== INTEL_OUTPUT_EDP
) {
1196 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
1197 intel_dp_sink_dpms(intel_dp
, DRM_MODE_DPMS_OFF
);
1198 intel_edp_panel_vdd_on(intel_dp
);
1199 intel_edp_panel_off(intel_dp
);
1202 I915_WRITE(PORT_CLK_SEL(port
), PORT_CLK_SEL_NONE
);
1205 static void intel_enable_ddi(struct intel_encoder
*intel_encoder
)
1207 struct drm_encoder
*encoder
= &intel_encoder
->base
;
1208 struct drm_crtc
*crtc
= encoder
->crtc
;
1209 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1210 struct drm_device
*dev
= encoder
->dev
;
1211 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1212 enum port port
= intel_ddi_get_encoder_port(intel_encoder
);
1213 int type
= intel_encoder
->type
;
1215 if (type
== INTEL_OUTPUT_HDMI
) {
1216 struct intel_digital_port
*intel_dig_port
=
1217 enc_to_dig_port(encoder
);
1219 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1220 * are ignored so nothing special needs to be done besides
1221 * enabling the port.
1223 I915_WRITE(DDI_BUF_CTL(port
),
1224 intel_dig_port
->saved_port_bits
|
1225 DDI_BUF_CTL_ENABLE
);
1226 } else if (type
== INTEL_OUTPUT_EDP
) {
1227 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
1230 intel_dp_stop_link_train(intel_dp
);
1232 intel_edp_backlight_on(intel_dp
);
1233 intel_edp_psr_enable(intel_dp
);
1236 if (intel_crtc
->config
.has_audio
) {
1237 intel_display_power_get(dev_priv
, POWER_DOMAIN_AUDIO
);
1238 intel_audio_codec_enable(intel_encoder
);
1242 static void intel_disable_ddi(struct intel_encoder
*intel_encoder
)
1244 struct drm_encoder
*encoder
= &intel_encoder
->base
;
1245 struct drm_crtc
*crtc
= encoder
->crtc
;
1246 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1247 int type
= intel_encoder
->type
;
1248 struct drm_device
*dev
= encoder
->dev
;
1249 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1251 if (intel_crtc
->config
.has_audio
) {
1252 intel_audio_codec_disable(intel_encoder
);
1253 intel_display_power_put(dev_priv
, POWER_DOMAIN_AUDIO
);
1256 if (type
== INTEL_OUTPUT_EDP
) {
1257 struct intel_dp
*intel_dp
= enc_to_intel_dp(encoder
);
1259 intel_edp_psr_disable(intel_dp
);
1260 intel_edp_backlight_off(intel_dp
);
1264 static int bdw_get_cdclk_freq(struct drm_i915_private
*dev_priv
)
1266 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
1267 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
1269 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
1271 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
1273 else if (freq
== LCPLL_CLK_FREQ_450
)
1275 else if (freq
== LCPLL_CLK_FREQ_54O_BDW
)
1277 else if (freq
== LCPLL_CLK_FREQ_337_5_BDW
)
1283 static int hsw_get_cdclk_freq(struct drm_i915_private
*dev_priv
)
1285 struct drm_device
*dev
= dev_priv
->dev
;
1286 uint32_t lcpll
= I915_READ(LCPLL_CTL
);
1287 uint32_t freq
= lcpll
& LCPLL_CLK_FREQ_MASK
;
1289 if (lcpll
& LCPLL_CD_SOURCE_FCLK
)
1291 else if (I915_READ(FUSE_STRAP
) & HSW_CDCLK_LIMIT
)
1293 else if (freq
== LCPLL_CLK_FREQ_450
)
1295 else if (IS_HSW_ULT(dev
))
1301 int intel_ddi_get_cdclk_freq(struct drm_i915_private
*dev_priv
)
1303 struct drm_device
*dev
= dev_priv
->dev
;
1305 if (IS_BROADWELL(dev
))
1306 return bdw_get_cdclk_freq(dev_priv
);
1309 return hsw_get_cdclk_freq(dev_priv
);
1312 static void hsw_ddi_pll_enable(struct drm_i915_private
*dev_priv
,
1313 struct intel_shared_dpll
*pll
)
1315 I915_WRITE(WRPLL_CTL(pll
->id
), pll
->hw_state
.wrpll
);
1316 POSTING_READ(WRPLL_CTL(pll
->id
));
1320 static void hsw_ddi_pll_disable(struct drm_i915_private
*dev_priv
,
1321 struct intel_shared_dpll
*pll
)
1325 val
= I915_READ(WRPLL_CTL(pll
->id
));
1326 I915_WRITE(WRPLL_CTL(pll
->id
), val
& ~WRPLL_PLL_ENABLE
);
1327 POSTING_READ(WRPLL_CTL(pll
->id
));
1330 static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private
*dev_priv
,
1331 struct intel_shared_dpll
*pll
,
1332 struct intel_dpll_hw_state
*hw_state
)
1336 if (!intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_PLLS
))
1339 val
= I915_READ(WRPLL_CTL(pll
->id
));
1340 hw_state
->wrpll
= val
;
1342 return val
& WRPLL_PLL_ENABLE
;
1345 static const char * const hsw_ddi_pll_names
[] = {
1350 static void hsw_shared_dplls_init(struct drm_i915_private
*dev_priv
)
1354 dev_priv
->num_shared_dpll
= 2;
1356 for (i
= 0; i
< dev_priv
->num_shared_dpll
; i
++) {
1357 dev_priv
->shared_dplls
[i
].id
= i
;
1358 dev_priv
->shared_dplls
[i
].name
= hsw_ddi_pll_names
[i
];
1359 dev_priv
->shared_dplls
[i
].disable
= hsw_ddi_pll_disable
;
1360 dev_priv
->shared_dplls
[i
].enable
= hsw_ddi_pll_enable
;
1361 dev_priv
->shared_dplls
[i
].get_hw_state
=
1362 hsw_ddi_pll_get_hw_state
;
1366 void intel_ddi_pll_init(struct drm_device
*dev
)
1368 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1369 uint32_t val
= I915_READ(LCPLL_CTL
);
1371 hsw_shared_dplls_init(dev_priv
);
1373 /* The LCPLL register should be turned on by the BIOS. For now let's
1374 * just check its state and print errors in case something is wrong.
1375 * Don't even try to turn it on.
1378 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
1379 intel_ddi_get_cdclk_freq(dev_priv
));
1381 if (val
& LCPLL_CD_SOURCE_FCLK
)
1382 DRM_ERROR("CDCLK source is not LCPLL\n");
1384 if (val
& LCPLL_PLL_DISABLE
)
1385 DRM_ERROR("LCPLL is disabled\n");
1388 void intel_ddi_prepare_link_retrain(struct drm_encoder
*encoder
)
1390 struct intel_digital_port
*intel_dig_port
= enc_to_dig_port(encoder
);
1391 struct intel_dp
*intel_dp
= &intel_dig_port
->dp
;
1392 struct drm_i915_private
*dev_priv
= encoder
->dev
->dev_private
;
1393 enum port port
= intel_dig_port
->port
;
1397 if (I915_READ(DP_TP_CTL(port
)) & DP_TP_CTL_ENABLE
) {
1398 val
= I915_READ(DDI_BUF_CTL(port
));
1399 if (val
& DDI_BUF_CTL_ENABLE
) {
1400 val
&= ~DDI_BUF_CTL_ENABLE
;
1401 I915_WRITE(DDI_BUF_CTL(port
), val
);
1405 val
= I915_READ(DP_TP_CTL(port
));
1406 val
&= ~(DP_TP_CTL_ENABLE
| DP_TP_CTL_LINK_TRAIN_MASK
);
1407 val
|= DP_TP_CTL_LINK_TRAIN_PAT1
;
1408 I915_WRITE(DP_TP_CTL(port
), val
);
1409 POSTING_READ(DP_TP_CTL(port
));
1412 intel_wait_ddi_buf_idle(dev_priv
, port
);
1415 val
= DP_TP_CTL_ENABLE
|
1416 DP_TP_CTL_LINK_TRAIN_PAT1
| DP_TP_CTL_SCRAMBLE_DISABLE
;
1417 if (intel_dp
->is_mst
)
1418 val
|= DP_TP_CTL_MODE_MST
;
1420 val
|= DP_TP_CTL_MODE_SST
;
1421 if (drm_dp_enhanced_frame_cap(intel_dp
->dpcd
))
1422 val
|= DP_TP_CTL_ENHANCED_FRAME_ENABLE
;
1424 I915_WRITE(DP_TP_CTL(port
), val
);
1425 POSTING_READ(DP_TP_CTL(port
));
1427 intel_dp
->DP
|= DDI_BUF_CTL_ENABLE
;
1428 I915_WRITE(DDI_BUF_CTL(port
), intel_dp
->DP
);
1429 POSTING_READ(DDI_BUF_CTL(port
));
1434 void intel_ddi_fdi_disable(struct drm_crtc
*crtc
)
1436 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
1437 struct intel_encoder
*intel_encoder
= intel_ddi_get_crtc_encoder(crtc
);
1440 intel_ddi_post_disable(intel_encoder
);
1442 val
= I915_READ(_FDI_RXA_CTL
);
1443 val
&= ~FDI_RX_ENABLE
;
1444 I915_WRITE(_FDI_RXA_CTL
, val
);
1446 val
= I915_READ(_FDI_RXA_MISC
);
1447 val
&= ~(FDI_RX_PWRDN_LANE1_MASK
| FDI_RX_PWRDN_LANE0_MASK
);
1448 val
|= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
1449 I915_WRITE(_FDI_RXA_MISC
, val
);
1451 val
= I915_READ(_FDI_RXA_CTL
);
1453 I915_WRITE(_FDI_RXA_CTL
, val
);
1455 val
= I915_READ(_FDI_RXA_CTL
);
1456 val
&= ~FDI_RX_PLL_ENABLE
;
1457 I915_WRITE(_FDI_RXA_CTL
, val
);
1460 static void intel_ddi_hot_plug(struct intel_encoder
*intel_encoder
)
1462 struct intel_digital_port
*intel_dig_port
= enc_to_dig_port(&intel_encoder
->base
);
1463 int type
= intel_dig_port
->base
.type
;
1465 if (type
!= INTEL_OUTPUT_DISPLAYPORT
&&
1466 type
!= INTEL_OUTPUT_EDP
&&
1467 type
!= INTEL_OUTPUT_UNKNOWN
) {
1471 intel_dp_hot_plug(intel_encoder
);
1474 void intel_ddi_get_config(struct intel_encoder
*encoder
,
1475 struct intel_crtc_config
*pipe_config
)
1477 struct drm_i915_private
*dev_priv
= encoder
->base
.dev
->dev_private
;
1478 struct intel_crtc
*intel_crtc
= to_intel_crtc(encoder
->base
.crtc
);
1479 enum transcoder cpu_transcoder
= intel_crtc
->config
.cpu_transcoder
;
1480 u32 temp
, flags
= 0;
1482 temp
= I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder
));
1483 if (temp
& TRANS_DDI_PHSYNC
)
1484 flags
|= DRM_MODE_FLAG_PHSYNC
;
1486 flags
|= DRM_MODE_FLAG_NHSYNC
;
1487 if (temp
& TRANS_DDI_PVSYNC
)
1488 flags
|= DRM_MODE_FLAG_PVSYNC
;
1490 flags
|= DRM_MODE_FLAG_NVSYNC
;
1492 pipe_config
->adjusted_mode
.flags
|= flags
;
1494 switch (temp
& TRANS_DDI_BPC_MASK
) {
1495 case TRANS_DDI_BPC_6
:
1496 pipe_config
->pipe_bpp
= 18;
1498 case TRANS_DDI_BPC_8
:
1499 pipe_config
->pipe_bpp
= 24;
1501 case TRANS_DDI_BPC_10
:
1502 pipe_config
->pipe_bpp
= 30;
1504 case TRANS_DDI_BPC_12
:
1505 pipe_config
->pipe_bpp
= 36;
1511 switch (temp
& TRANS_DDI_MODE_SELECT_MASK
) {
1512 case TRANS_DDI_MODE_SELECT_HDMI
:
1513 pipe_config
->has_hdmi_sink
= true;
1514 case TRANS_DDI_MODE_SELECT_DVI
:
1515 case TRANS_DDI_MODE_SELECT_FDI
:
1517 case TRANS_DDI_MODE_SELECT_DP_SST
:
1518 case TRANS_DDI_MODE_SELECT_DP_MST
:
1519 pipe_config
->has_dp_encoder
= true;
1520 intel_dp_get_m_n(intel_crtc
, pipe_config
);
1526 if (intel_display_power_is_enabled(dev_priv
, POWER_DOMAIN_AUDIO
)) {
1527 temp
= I915_READ(HSW_AUD_PIN_ELD_CP_VLD
);
1528 if (temp
& (AUDIO_OUTPUT_ENABLE_A
<< (intel_crtc
->pipe
* 4)))
1529 pipe_config
->has_audio
= true;
1532 if (encoder
->type
== INTEL_OUTPUT_EDP
&& dev_priv
->vbt
.edp_bpp
&&
1533 pipe_config
->pipe_bpp
> dev_priv
->vbt
.edp_bpp
) {
1535 * This is a big fat ugly hack.
1537 * Some machines in UEFI boot mode provide us a VBT that has 18
1538 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1539 * unknown we fail to light up. Yet the same BIOS boots up with
1540 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1541 * max, not what it tells us to use.
1543 * Note: This will still be broken if the eDP panel is not lit
1544 * up by the BIOS, and thus we can't get the mode at module
1547 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1548 pipe_config
->pipe_bpp
, dev_priv
->vbt
.edp_bpp
);
1549 dev_priv
->vbt
.edp_bpp
= pipe_config
->pipe_bpp
;
1552 hsw_ddi_clock_get(encoder
, pipe_config
);
1555 static void intel_ddi_destroy(struct drm_encoder
*encoder
)
1557 /* HDMI has nothing special to destroy, so we can go with this. */
1558 intel_dp_encoder_destroy(encoder
);
1561 static bool intel_ddi_compute_config(struct intel_encoder
*encoder
,
1562 struct intel_crtc_config
*pipe_config
)
1564 int type
= encoder
->type
;
1565 int port
= intel_ddi_get_encoder_port(encoder
);
1567 WARN(type
== INTEL_OUTPUT_UNKNOWN
, "compute_config() on unknown output!\n");
1570 pipe_config
->cpu_transcoder
= TRANSCODER_EDP
;
1572 if (type
== INTEL_OUTPUT_HDMI
)
1573 return intel_hdmi_compute_config(encoder
, pipe_config
);
1575 return intel_dp_compute_config(encoder
, pipe_config
);
1578 static const struct drm_encoder_funcs intel_ddi_funcs
= {
1579 .destroy
= intel_ddi_destroy
,
1582 static struct intel_connector
*
1583 intel_ddi_init_dp_connector(struct intel_digital_port
*intel_dig_port
)
1585 struct intel_connector
*connector
;
1586 enum port port
= intel_dig_port
->port
;
1588 connector
= kzalloc(sizeof(*connector
), GFP_KERNEL
);
1592 intel_dig_port
->dp
.output_reg
= DDI_BUF_CTL(port
);
1593 if (!intel_dp_init_connector(intel_dig_port
, connector
)) {
1601 static struct intel_connector
*
1602 intel_ddi_init_hdmi_connector(struct intel_digital_port
*intel_dig_port
)
1604 struct intel_connector
*connector
;
1605 enum port port
= intel_dig_port
->port
;
1607 connector
= kzalloc(sizeof(*connector
), GFP_KERNEL
);
1611 intel_dig_port
->hdmi
.hdmi_reg
= DDI_BUF_CTL(port
);
1612 intel_hdmi_init_connector(intel_dig_port
, connector
);
1617 void intel_ddi_init(struct drm_device
*dev
, enum port port
)
1619 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1620 struct intel_digital_port
*intel_dig_port
;
1621 struct intel_encoder
*intel_encoder
;
1622 struct drm_encoder
*encoder
;
1623 bool init_hdmi
, init_dp
;
1625 init_hdmi
= (dev_priv
->vbt
.ddi_port_info
[port
].supports_dvi
||
1626 dev_priv
->vbt
.ddi_port_info
[port
].supports_hdmi
);
1627 init_dp
= dev_priv
->vbt
.ddi_port_info
[port
].supports_dp
;
1628 if (!init_dp
&& !init_hdmi
) {
1629 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, assuming it is\n",
1635 intel_dig_port
= kzalloc(sizeof(*intel_dig_port
), GFP_KERNEL
);
1636 if (!intel_dig_port
)
1639 intel_encoder
= &intel_dig_port
->base
;
1640 encoder
= &intel_encoder
->base
;
1642 drm_encoder_init(dev
, encoder
, &intel_ddi_funcs
,
1643 DRM_MODE_ENCODER_TMDS
);
1645 intel_encoder
->compute_config
= intel_ddi_compute_config
;
1646 intel_encoder
->enable
= intel_enable_ddi
;
1647 intel_encoder
->pre_enable
= intel_ddi_pre_enable
;
1648 intel_encoder
->disable
= intel_disable_ddi
;
1649 intel_encoder
->post_disable
= intel_ddi_post_disable
;
1650 intel_encoder
->get_hw_state
= intel_ddi_get_hw_state
;
1651 intel_encoder
->get_config
= intel_ddi_get_config
;
1653 intel_dig_port
->port
= port
;
1654 intel_dig_port
->saved_port_bits
= I915_READ(DDI_BUF_CTL(port
)) &
1655 (DDI_BUF_PORT_REVERSAL
|
1658 intel_encoder
->type
= INTEL_OUTPUT_UNKNOWN
;
1659 intel_encoder
->crtc_mask
= (1 << 0) | (1 << 1) | (1 << 2);
1660 intel_encoder
->cloneable
= 0;
1661 intel_encoder
->hot_plug
= intel_ddi_hot_plug
;
1664 if (!intel_ddi_init_dp_connector(intel_dig_port
))
1667 intel_dig_port
->hpd_pulse
= intel_dp_hpd_pulse
;
1668 dev_priv
->hpd_irq_port
[port
] = intel_dig_port
;
1671 /* In theory we don't need the encoder->type check, but leave it just in
1672 * case we have some really bad VBTs... */
1673 if (intel_encoder
->type
!= INTEL_OUTPUT_EDP
&& init_hdmi
) {
1674 if (!intel_ddi_init_hdmi_connector(intel_dig_port
))
1681 drm_encoder_cleanup(encoder
);
1682 kfree(intel_dig_port
);