2 * Copyright © 2014-2016 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
21 * DEALINGS IN THE SOFTWARE.
24 #include "intel_drv.h"
29 * VLV, CHV and BXT have slightly peculiar display PHYs for driving DP/HDMI
30 * ports. DPIO is the name given to such a display PHY. These PHYs
31 * don't follow the standard programming model using direct MMIO
32 * registers, and instead their registers must be accessed trough IOSF
33 * sideband. VLV has one such PHY for driving ports B and C, and CHV
34 * adds another PHY for driving port D. Each PHY responds to specific
37 * Each display PHY is made up of one or two channels. Each channel
38 * houses a common lane part which contains the PLL and other common
39 * logic. CH0 common lane also contains the IOSF-SB logic for the
40 * Common Register Interface (CRI) ie. the DPIO registers. CRI clock
41 * must be running when any DPIO registers are accessed.
43 * In addition to having their own registers, the PHYs are also
44 * controlled through some dedicated signals from the display
45 * controller. These include PLL reference clock enable, PLL enable,
46 * and CRI clock selection, for example.
48 * Eeach channel also has two splines (also called data lanes), and
49 * each spline is made up of one Physical Access Coding Sub-Layer
50 * (PCS) block and two TX lanes. So each channel has two PCS blocks
51 * and four TX lanes. The TX lanes are used as DP lanes or TMDS
52 * data/clock pairs depending on the output type.
54 * Additionally the PHY also contains an AUX lane with AUX blocks
55 * for each channel. This is used for DP AUX communication, but
56 * this fact isn't really relevant for the driver since AUX is
57 * controlled from the display controller side. No DPIO registers
58 * need to be accessed during AUX communication,
60 * Generally on VLV/CHV the common lane corresponds to the pipe and
61 * the spline (PCS/TX) corresponds to the port.
63 * For dual channel PHY (VLV/CHV):
65 * pipe A == CMN/PLL/REF CH0
67 * pipe B == CMN/PLL/REF CH1
69 * port B == PCS/TX CH0
71 * port C == PCS/TX CH1
73 * This is especially important when we cross the streams
74 * ie. drive port B with pipe B, or port C with pipe A.
76 * For single channel PHY (CHV):
78 * pipe C == CMN/PLL/REF CH0
80 * port D == PCS/TX CH0
82 * On BXT the entire PHY channel corresponds to the port. That means
83 * the PLL is also now associated with the port rather than the pipe,
84 * and so the clock needs to be routed to the appropriate transcoder.
85 * Port A PLL is directly connected to transcoder EDP and port B/C
86 * PLLs can be routed to any transcoder A/B/C.
88 * Note: DDI0 is digital port B, DD1 is digital port C, and DDI2 is
89 * digital port D (CHV) or port A (BXT). ::
92 * Dual channel PHY (VLV/CHV/BXT)
93 * ---------------------------------
95 * | CMN/PLL/REF | CMN/PLL/REF |
96 * |---------------|---------------| Display PHY
97 * | PCS01 | PCS23 | PCS01 | PCS23 |
98 * |-------|-------|-------|-------|
99 * |TX0|TX1|TX2|TX3|TX0|TX1|TX2|TX3|
100 * ---------------------------------
101 * | DDI0 | DDI1 | DP/HDMI ports
102 * ---------------------------------
104 * Single channel PHY (CHV/BXT)
108 * |---------------| Display PHY
113 * | DDI2 | DP/HDMI port
118 * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
120 struct bxt_ddi_phy_info {
122 * @dual_channel: true if this phy has a second channel.
127 * @channel: struct containing per channel information.
131 * @port: which port maps to this channel.
137 static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = {
139 .dual_channel = true,
142 [DPIO_CH0] = { .port = PORT_B },
143 [DPIO_CH1] = { .port = PORT_C },
147 .dual_channel = false,
150 [DPIO_CH0] = { .port = PORT_A },
155 static u32 bxt_phy_port_mask(const struct bxt_ddi_phy_info *phy_info)
157 return (phy_info->dual_channel * BIT(phy_info->channel[DPIO_CH1].port)) |
158 BIT(phy_info->channel[DPIO_CH0].port);
161 void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
162 enum port port, u32 margin, u32 scale,
163 u32 enable, u32 deemphasis)
168 * While we write to the group register to program all lanes at once we
169 * can read only lane registers and we pick lanes 0/1 for that.
171 val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
172 val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
173 I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
175 val = I915_READ(BXT_PORT_TX_DW2_LN0(port));
176 val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
177 val |= margin << MARGIN_000_SHIFT | scale << UNIQ_TRANS_SCALE_SHIFT;
178 I915_WRITE(BXT_PORT_TX_DW2_GRP(port), val);
180 val = I915_READ(BXT_PORT_TX_DW3_LN0(port));
181 val &= ~SCALE_DCOMP_METHOD;
183 val |= SCALE_DCOMP_METHOD;
185 if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
186 DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set");
188 I915_WRITE(BXT_PORT_TX_DW3_GRP(port), val);
190 val = I915_READ(BXT_PORT_TX_DW4_LN0(port));
192 val |= deemphasis << DEEMPH_SHIFT;
193 I915_WRITE(BXT_PORT_TX_DW4_GRP(port), val);
195 val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
196 val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
197 I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
200 bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
203 const struct bxt_ddi_phy_info *phy_info = &bxt_ddi_phy_info[phy];
206 if (!(I915_READ(BXT_P_CR_GT_DISP_PWRON) & GT_DISPLAY_POWER_ON(phy)))
209 if ((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
210 (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
211 DRM_DEBUG_DRIVER("DDI PHY %d powered, but power hasn't settled\n",
217 if (phy == DPIO_PHY1 &&
218 !(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE)) {
219 DRM_DEBUG_DRIVER("DDI PHY 1 powered, but GRC isn't done\n");
224 if (!(I915_READ(BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
225 DRM_DEBUG_DRIVER("DDI PHY %d powered, but still in reset\n",
231 for_each_port_masked(port, bxt_phy_port_mask(phy_info)) {
232 u32 tmp = I915_READ(BXT_PHY_CTL(port));
234 if (tmp & BXT_PHY_CMNLANE_POWERDOWN_ACK) {
235 DRM_DEBUG_DRIVER("DDI PHY %d powered, but common lane "
236 "for port %c powered down "
238 phy, port_name(port), tmp);
247 static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
249 u32 val = I915_READ(BXT_PORT_REF_DW6(phy));
251 return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
254 static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
257 if (intel_wait_for_register(dev_priv,
258 BXT_PORT_REF_DW3(phy),
261 DRM_ERROR("timeout waiting for PHY%d GRC\n", phy);
264 void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
266 const struct bxt_ddi_phy_info *phy_info = &bxt_ddi_phy_info[phy];
269 if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
270 /* Still read out the GRC value for state verification */
271 if (phy == DPIO_PHY0)
272 dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy);
274 if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
275 DRM_DEBUG_DRIVER("DDI PHY %d already enabled, "
276 "won't reprogram it\n", phy);
281 DRM_DEBUG_DRIVER("DDI PHY %d enabled with invalid state, "
282 "force reprogramming it\n", phy);
285 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
286 val |= GT_DISPLAY_POWER_ON(phy);
287 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
290 * The PHY registers start out inaccessible and respond to reads with
291 * all 1s. Eventually they become accessible as they power up, then
292 * the reserved bit will give the default 0. Poll on the reserved bit
293 * becoming 0 to find when the PHY is accessible.
294 * HW team confirmed that the time to reach phypowergood status is
295 * anywhere between 50 us and 100us.
297 if (wait_for_us(((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
298 (PHY_RESERVED | PHY_POWER_GOOD)) == PHY_POWER_GOOD), 100)) {
299 DRM_ERROR("timeout during PHY%d power on\n", phy);
302 /* Program PLL Rcomp code offset */
303 val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
304 val &= ~IREF0RC_OFFSET_MASK;
305 val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
306 I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
308 val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
309 val &= ~IREF1RC_OFFSET_MASK;
310 val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
311 I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
313 /* Program power gating */
314 val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
315 val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
317 I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
319 if (phy_info->dual_channel) {
320 val = I915_READ(BXT_PORT_CL2CM_DW6(phy));
321 val |= DW6_OLDO_DYN_PWR_DOWN_EN;
322 I915_WRITE(BXT_PORT_CL2CM_DW6(phy), val);
325 val = I915_READ(BXT_PORT_CL1CM_DW30(phy));
326 val &= ~OCL2_LDOFUSE_PWR_DIS;
328 * On PHY1 disable power on the second channel, since no port is
329 * connected there. On PHY0 both channels have a port, so leave it
331 * TODO: port C is only connected on BXT-P, so on BXT0/1 we should
332 * power down the second channel on PHY0 as well.
334 * FIXME: Clarify programming of the following, the register is
335 * read-only with bit 6 fixed at 0 at least in stepping A.
337 if (!phy_info->dual_channel)
338 val |= OCL2_LDOFUSE_PWR_DIS;
339 I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val);
341 if (phy == DPIO_PHY0) {
344 * PHY0 isn't connected to an RCOMP resistor so copy over
345 * the corresponding calibrated value from PHY1, and disable
346 * the automatic calibration on PHY0.
348 val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, DPIO_PHY1);
349 grc_code = val << GRC_CODE_FAST_SHIFT |
350 val << GRC_CODE_SLOW_SHIFT |
352 I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code);
354 val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0));
355 val |= GRC_DIS | GRC_RDY_OVRD;
356 I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val);
359 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
360 val |= COMMON_RESET_DIS;
361 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
363 if (phy == DPIO_PHY1)
364 bxt_phy_wait_grc_done(dev_priv, DPIO_PHY1);
367 void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
371 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
372 val &= ~COMMON_RESET_DIS;
373 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
375 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
376 val &= ~GT_DISPLAY_POWER_ON(phy);
377 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
380 static bool __printf(6, 7)
381 __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
382 i915_reg_t reg, u32 mask, u32 expected,
383 const char *reg_fmt, ...)
385 struct va_format vaf;
389 val = I915_READ(reg);
390 if ((val & mask) == expected)
393 va_start(args, reg_fmt);
397 DRM_DEBUG_DRIVER("DDI PHY %d reg %pV [%08x] state mismatch: "
398 "current %08x, expected %08x (mask %08x)\n",
399 phy, &vaf, reg.reg, val, (val & ~mask) | expected,
407 bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
410 const struct bxt_ddi_phy_info *phy_info = &bxt_ddi_phy_info[phy];
414 #define _CHK(reg, mask, exp, fmt, ...) \
415 __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
418 if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
423 /* PLL Rcomp code offset */
424 ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
425 IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
426 "BXT_PORT_CL1CM_DW9(%d)", phy);
427 ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
428 IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
429 "BXT_PORT_CL1CM_DW10(%d)", phy);
432 mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
433 ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
434 "BXT_PORT_CL1CM_DW28(%d)", phy);
436 if (phy_info->dual_channel)
437 ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
438 DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
439 "BXT_PORT_CL2CM_DW6(%d)", phy);
442 * TODO: Verify BXT_PORT_CL1CM_DW30 bit OCL2_LDOFUSE_PWR_DIS,
443 * at least on stepping A this bit is read-only and fixed at 0.
446 if (phy == DPIO_PHY0) {
447 u32 grc_code = dev_priv->bxt_phy_grc;
449 grc_code = grc_code << GRC_CODE_FAST_SHIFT |
450 grc_code << GRC_CODE_SLOW_SHIFT |
452 mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
454 ok &= _CHK(BXT_PORT_REF_DW6(DPIO_PHY0), mask, grc_code,
455 "BXT_PORT_REF_DW6(%d)", DPIO_PHY0);
457 mask = GRC_DIS | GRC_RDY_OVRD;
458 ok &= _CHK(BXT_PORT_REF_DW8(DPIO_PHY0), mask, mask,
459 "BXT_PORT_REF_DW8(%d)", DPIO_PHY0);
467 bxt_ddi_phy_calc_lane_lat_optim_mask(struct intel_encoder *encoder,
470 switch (lane_count) {
474 return BIT(2) | BIT(0);
476 return BIT(3) | BIT(2) | BIT(0);
478 MISSING_CASE(lane_count);
484 void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
485 uint8_t lane_lat_optim_mask)
487 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
488 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
489 enum port port = dport->port;
492 for (lane = 0; lane < 4; lane++) {
493 u32 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
496 * Note that on CHV this flag is called UPAR, but has
499 val &= ~LATENCY_OPTIM;
500 if (lane_lat_optim_mask & BIT(lane))
501 val |= LATENCY_OPTIM;
503 I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val);
508 bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
510 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
511 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
512 enum port port = dport->port;
517 for (lane = 0; lane < 4; lane++) {
518 u32 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
520 if (val & LATENCY_OPTIM)
528 void chv_set_phy_signal_level(struct intel_encoder *encoder,
529 u32 deemph_reg_value, u32 margin_reg_value,
530 bool uniq_trans_scale)
532 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
533 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
534 struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
535 enum dpio_channel ch = vlv_dport_to_channel(dport);
536 enum pipe pipe = intel_crtc->pipe;
540 mutex_lock(&dev_priv->sb_lock);
542 /* Clear calc init */
543 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
544 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
545 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
546 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
547 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
549 if (intel_crtc->config->lane_count > 2) {
550 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
551 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
552 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
553 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
554 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
557 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
558 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
559 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
560 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
562 if (intel_crtc->config->lane_count > 2) {
563 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
564 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
565 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
566 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
569 /* Program swing deemph */
570 for (i = 0; i < intel_crtc->config->lane_count; i++) {
571 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
572 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
573 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
574 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
577 /* Program swing margin */
578 for (i = 0; i < intel_crtc->config->lane_count; i++) {
579 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
581 val &= ~DPIO_SWING_MARGIN000_MASK;
582 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
585 * Supposedly this value shouldn't matter when unique transition
586 * scale is disabled, but in fact it does matter. Let's just
587 * always program the same value and hope it's OK.
589 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
590 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
592 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
596 * The document said it needs to set bit 27 for ch0 and bit 26
597 * for ch1. Might be a typo in the doc.
598 * For now, for this unique transition scale selection, set bit
599 * 27 for ch0 and ch1.
601 for (i = 0; i < intel_crtc->config->lane_count; i++) {
602 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
603 if (uniq_trans_scale)
604 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
606 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
607 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
610 /* Start swing calculation */
611 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
612 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
613 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
615 if (intel_crtc->config->lane_count > 2) {
616 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
617 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
618 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
621 mutex_unlock(&dev_priv->sb_lock);
625 void chv_data_lane_soft_reset(struct intel_encoder *encoder,
628 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
629 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
630 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
631 enum pipe pipe = crtc->pipe;
634 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
636 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
638 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
639 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
641 if (crtc->config->lane_count > 2) {
642 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
644 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
646 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
647 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
650 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
651 val |= CHV_PCS_REQ_SOFTRESET_EN;
653 val &= ~DPIO_PCS_CLK_SOFT_RESET;
655 val |= DPIO_PCS_CLK_SOFT_RESET;
656 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
658 if (crtc->config->lane_count > 2) {
659 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
660 val |= CHV_PCS_REQ_SOFTRESET_EN;
662 val &= ~DPIO_PCS_CLK_SOFT_RESET;
664 val |= DPIO_PCS_CLK_SOFT_RESET;
665 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
669 void chv_phy_pre_pll_enable(struct intel_encoder *encoder)
671 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
672 struct drm_device *dev = encoder->base.dev;
673 struct drm_i915_private *dev_priv = to_i915(dev);
674 struct intel_crtc *intel_crtc =
675 to_intel_crtc(encoder->base.crtc);
676 enum dpio_channel ch = vlv_dport_to_channel(dport);
677 enum pipe pipe = intel_crtc->pipe;
678 unsigned int lane_mask =
679 intel_dp_unused_lane_mask(intel_crtc->config->lane_count);
683 * Must trick the second common lane into life.
684 * Otherwise we can't even access the PLL.
686 if (ch == DPIO_CH0 && pipe == PIPE_B)
687 dport->release_cl2_override =
688 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
690 chv_phy_powergate_lanes(encoder, true, lane_mask);
692 mutex_lock(&dev_priv->sb_lock);
694 /* Assert data lane reset */
695 chv_data_lane_soft_reset(encoder, true);
697 /* program left/right clock distribution */
698 if (pipe != PIPE_B) {
699 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
700 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
702 val |= CHV_BUFLEFTENA1_FORCE;
704 val |= CHV_BUFRIGHTENA1_FORCE;
705 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
707 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
708 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
710 val |= CHV_BUFLEFTENA2_FORCE;
712 val |= CHV_BUFRIGHTENA2_FORCE;
713 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
716 /* program clock channel usage */
717 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
718 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
720 val &= ~CHV_PCS_USEDCLKCHANNEL;
722 val |= CHV_PCS_USEDCLKCHANNEL;
723 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
725 if (intel_crtc->config->lane_count > 2) {
726 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
727 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
729 val &= ~CHV_PCS_USEDCLKCHANNEL;
731 val |= CHV_PCS_USEDCLKCHANNEL;
732 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
736 * This a a bit weird since generally CL
737 * matches the pipe, but here we need to
738 * pick the CL based on the port.
740 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
742 val &= ~CHV_CMN_USEDCLKCHANNEL;
744 val |= CHV_CMN_USEDCLKCHANNEL;
745 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
747 mutex_unlock(&dev_priv->sb_lock);
750 void chv_phy_pre_encoder_enable(struct intel_encoder *encoder)
752 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
753 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
754 struct drm_device *dev = encoder->base.dev;
755 struct drm_i915_private *dev_priv = to_i915(dev);
756 struct intel_crtc *intel_crtc =
757 to_intel_crtc(encoder->base.crtc);
758 enum dpio_channel ch = vlv_dport_to_channel(dport);
759 int pipe = intel_crtc->pipe;
760 int data, i, stagger;
763 mutex_lock(&dev_priv->sb_lock);
765 /* allow hardware to manage TX FIFO reset source */
766 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
767 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
768 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
770 if (intel_crtc->config->lane_count > 2) {
771 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
772 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
773 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
776 /* Program Tx lane latency optimal setting*/
777 for (i = 0; i < intel_crtc->config->lane_count; i++) {
778 /* Set the upar bit */
779 if (intel_crtc->config->lane_count == 1)
782 data = (i == 1) ? 0x0 : 0x1;
783 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
784 data << DPIO_UPAR_SHIFT);
787 /* Data lane stagger programming */
788 if (intel_crtc->config->port_clock > 270000)
790 else if (intel_crtc->config->port_clock > 135000)
792 else if (intel_crtc->config->port_clock > 67500)
794 else if (intel_crtc->config->port_clock > 33750)
799 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
800 val |= DPIO_TX2_STAGGER_MASK(0x1f);
801 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
803 if (intel_crtc->config->lane_count > 2) {
804 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
805 val |= DPIO_TX2_STAGGER_MASK(0x1f);
806 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
809 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
810 DPIO_LANESTAGGER_STRAP(stagger) |
811 DPIO_LANESTAGGER_STRAP_OVRD |
812 DPIO_TX1_STAGGER_MASK(0x1f) |
813 DPIO_TX1_STAGGER_MULT(6) |
814 DPIO_TX2_STAGGER_MULT(0));
816 if (intel_crtc->config->lane_count > 2) {
817 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
818 DPIO_LANESTAGGER_STRAP(stagger) |
819 DPIO_LANESTAGGER_STRAP_OVRD |
820 DPIO_TX1_STAGGER_MASK(0x1f) |
821 DPIO_TX1_STAGGER_MULT(7) |
822 DPIO_TX2_STAGGER_MULT(5));
825 /* Deassert data lane reset */
826 chv_data_lane_soft_reset(encoder, false);
828 mutex_unlock(&dev_priv->sb_lock);
831 void chv_phy_release_cl2_override(struct intel_encoder *encoder)
833 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
834 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
836 if (dport->release_cl2_override) {
837 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
838 dport->release_cl2_override = false;
842 void chv_phy_post_pll_disable(struct intel_encoder *encoder)
844 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
845 enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
848 mutex_lock(&dev_priv->sb_lock);
850 /* disable left/right clock distribution */
851 if (pipe != PIPE_B) {
852 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
853 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
854 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
856 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
857 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
858 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
861 mutex_unlock(&dev_priv->sb_lock);
864 * Leave the power down bit cleared for at least one
865 * lane so that chv_powergate_phy_ch() will power
866 * on something when the channel is otherwise unused.
867 * When the port is off and the override is removed
868 * the lanes power down anyway, so otherwise it doesn't
869 * really matter what the state of power down bits is
872 chv_phy_powergate_lanes(encoder, false, 0x0);
875 void vlv_set_phy_signal_level(struct intel_encoder *encoder,
876 u32 demph_reg_value, u32 preemph_reg_value,
877 u32 uniqtranscale_reg_value, u32 tx3_demph)
879 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
880 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
881 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
882 enum dpio_channel port = vlv_dport_to_channel(dport);
883 int pipe = intel_crtc->pipe;
885 mutex_lock(&dev_priv->sb_lock);
886 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
887 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
888 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
889 uniqtranscale_reg_value);
890 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
893 vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
895 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
896 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
897 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
898 mutex_unlock(&dev_priv->sb_lock);
901 void vlv_phy_pre_pll_enable(struct intel_encoder *encoder)
903 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
904 struct drm_device *dev = encoder->base.dev;
905 struct drm_i915_private *dev_priv = to_i915(dev);
906 struct intel_crtc *intel_crtc =
907 to_intel_crtc(encoder->base.crtc);
908 enum dpio_channel port = vlv_dport_to_channel(dport);
909 int pipe = intel_crtc->pipe;
911 /* Program Tx lane resets to default */
912 mutex_lock(&dev_priv->sb_lock);
913 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
914 DPIO_PCS_TX_LANE2_RESET |
915 DPIO_PCS_TX_LANE1_RESET);
916 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
917 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
918 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
919 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
920 DPIO_PCS_CLK_SOFT_RESET);
922 /* Fix up inter-pair skew failure */
923 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
924 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
925 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
926 mutex_unlock(&dev_priv->sb_lock);
929 void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder)
931 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
932 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
933 struct drm_device *dev = encoder->base.dev;
934 struct drm_i915_private *dev_priv = to_i915(dev);
935 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
936 enum dpio_channel port = vlv_dport_to_channel(dport);
937 int pipe = intel_crtc->pipe;
940 mutex_lock(&dev_priv->sb_lock);
942 /* Enable clock channels for this port */
943 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
950 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
952 /* Program lane clock */
953 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
954 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
956 mutex_unlock(&dev_priv->sb_lock);
959 void vlv_phy_reset_lanes(struct intel_encoder *encoder)
961 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
962 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
963 struct intel_crtc *intel_crtc =
964 to_intel_crtc(encoder->base.crtc);
965 enum dpio_channel port = vlv_dport_to_channel(dport);
966 int pipe = intel_crtc->pipe;
968 mutex_lock(&dev_priv->sb_lock);
969 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
970 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
971 mutex_unlock(&dev_priv->sb_lock);