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_ddi.h"
25 #include "intel_ddi_buf_trans.h"
27 #include "intel_display_power_well.h"
28 #include "intel_display_types.h"
30 #include "intel_dpio_phy.h"
31 #include "vlv_sideband.h"
36 * VLV, CHV and BXT have slightly peculiar display PHYs for driving DP/HDMI
37 * ports. DPIO is the name given to such a display PHY. These PHYs
38 * don't follow the standard programming model using direct MMIO
39 * registers, and instead their registers must be accessed trough IOSF
40 * sideband. VLV has one such PHY for driving ports B and C, and CHV
41 * adds another PHY for driving port D. Each PHY responds to specific
44 * Each display PHY is made up of one or two channels. Each channel
45 * houses a common lane part which contains the PLL and other common
46 * logic. CH0 common lane also contains the IOSF-SB logic for the
47 * Common Register Interface (CRI) ie. the DPIO registers. CRI clock
48 * must be running when any DPIO registers are accessed.
50 * In addition to having their own registers, the PHYs are also
51 * controlled through some dedicated signals from the display
52 * controller. These include PLL reference clock enable, PLL enable,
53 * and CRI clock selection, for example.
55 * Eeach channel also has two splines (also called data lanes), and
56 * each spline is made up of one Physical Access Coding Sub-Layer
57 * (PCS) block and two TX lanes. So each channel has two PCS blocks
58 * and four TX lanes. The TX lanes are used as DP lanes or TMDS
59 * data/clock pairs depending on the output type.
61 * Additionally the PHY also contains an AUX lane with AUX blocks
62 * for each channel. This is used for DP AUX communication, but
63 * this fact isn't really relevant for the driver since AUX is
64 * controlled from the display controller side. No DPIO registers
65 * need to be accessed during AUX communication,
67 * Generally on VLV/CHV the common lane corresponds to the pipe and
68 * the spline (PCS/TX) corresponds to the port.
70 * For dual channel PHY (VLV/CHV):
72 * pipe A == CMN/PLL/REF CH0
74 * pipe B == CMN/PLL/REF CH1
76 * port B == PCS/TX CH0
78 * port C == PCS/TX CH1
80 * This is especially important when we cross the streams
81 * ie. drive port B with pipe B, or port C with pipe A.
83 * For single channel PHY (CHV):
85 * pipe C == CMN/PLL/REF CH0
87 * port D == PCS/TX CH0
89 * On BXT the entire PHY channel corresponds to the port. That means
90 * the PLL is also now associated with the port rather than the pipe,
91 * and so the clock needs to be routed to the appropriate transcoder.
92 * Port A PLL is directly connected to transcoder EDP and port B/C
93 * PLLs can be routed to any transcoder A/B/C.
95 * Note: DDI0 is digital port B, DD1 is digital port C, and DDI2 is
96 * digital port D (CHV) or port A (BXT). ::
99 * Dual channel PHY (VLV/CHV/BXT)
100 * ---------------------------------
102 * | CMN/PLL/REF | CMN/PLL/REF |
103 * |---------------|---------------| Display PHY
104 * | PCS01 | PCS23 | PCS01 | PCS23 |
105 * |-------|-------|-------|-------|
106 * |TX0|TX1|TX2|TX3|TX0|TX1|TX2|TX3|
107 * ---------------------------------
108 * | DDI0 | DDI1 | DP/HDMI ports
109 * ---------------------------------
111 * Single channel PHY (CHV/BXT)
115 * |---------------| Display PHY
120 * | DDI2 | DP/HDMI port
125 * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
127 struct bxt_ddi_phy_info {
129 * @dual_channel: true if this phy has a second channel.
134 * @rcomp_phy: If -1, indicates this phy has its own rcomp resistor.
135 * Otherwise the GRC value will be copied from the phy indicated by
138 enum dpio_phy rcomp_phy;
141 * @reset_delay: delay in us to wait before setting the common reset
142 * bit in BXT_PHY_CTL_FAMILY, which effectively enables the phy.
147 * @pwron_mask: Mask with the appropriate bit set that would cause the
148 * punit to power this phy if written to BXT_P_CR_GT_DISP_PWRON.
153 * @channel: struct containing per channel information.
157 * @channel.port: which port maps to this channel.
163 static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = {
165 .dual_channel = true,
166 .rcomp_phy = DPIO_PHY1,
167 .pwron_mask = BIT(0),
170 [DPIO_CH0] = { .port = PORT_B },
171 [DPIO_CH1] = { .port = PORT_C },
175 .dual_channel = false,
177 .pwron_mask = BIT(1),
180 [DPIO_CH0] = { .port = PORT_A },
185 static const struct bxt_ddi_phy_info glk_ddi_phy_info[] = {
187 .dual_channel = false,
188 .rcomp_phy = DPIO_PHY1,
189 .pwron_mask = BIT(0),
193 [DPIO_CH0] = { .port = PORT_B },
197 .dual_channel = false,
199 .pwron_mask = BIT(3),
203 [DPIO_CH0] = { .port = PORT_A },
207 .dual_channel = false,
208 .rcomp_phy = DPIO_PHY1,
209 .pwron_mask = BIT(1),
213 [DPIO_CH0] = { .port = PORT_C },
218 static const struct bxt_ddi_phy_info *
219 bxt_get_phy_list(struct drm_i915_private *dev_priv, int *count)
221 if (IS_GEMINILAKE(dev_priv)) {
222 *count = ARRAY_SIZE(glk_ddi_phy_info);
223 return glk_ddi_phy_info;
225 *count = ARRAY_SIZE(bxt_ddi_phy_info);
226 return bxt_ddi_phy_info;
230 static const struct bxt_ddi_phy_info *
231 bxt_get_phy_info(struct drm_i915_private *dev_priv, enum dpio_phy phy)
234 const struct bxt_ddi_phy_info *phy_list =
235 bxt_get_phy_list(dev_priv, &count);
237 return &phy_list[phy];
240 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
241 enum dpio_phy *phy, enum dpio_channel *ch)
243 const struct bxt_ddi_phy_info *phy_info, *phys;
246 phys = bxt_get_phy_list(dev_priv, &count);
248 for (i = 0; i < count; i++) {
251 if (port == phy_info->channel[DPIO_CH0].port) {
257 if (phy_info->dual_channel &&
258 port == phy_info->channel[DPIO_CH1].port) {
265 drm_WARN(&dev_priv->drm, 1, "PHY not found for PORT %c",
271 void bxt_ddi_phy_set_signal_levels(struct intel_encoder *encoder,
272 const struct intel_crtc_state *crtc_state)
274 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
275 int level = intel_ddi_level(encoder, crtc_state, 0);
276 const struct intel_ddi_buf_trans *trans;
277 enum dpio_channel ch;
282 trans = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
283 if (drm_WARN_ON_ONCE(&dev_priv->drm, !trans))
286 bxt_port_to_phy_channel(dev_priv, encoder->port, &phy, &ch);
289 * While we write to the group register to program all lanes at once we
290 * can read only lane registers and we pick lanes 0/1 for that.
292 val = intel_de_read(dev_priv, BXT_PORT_PCS_DW10_LN01(phy, ch));
293 val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
294 intel_de_write(dev_priv, BXT_PORT_PCS_DW10_GRP(phy, ch), val);
296 val = intel_de_read(dev_priv, BXT_PORT_TX_DW2_LN0(phy, ch));
297 val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
298 val |= trans->entries[level].bxt.margin << MARGIN_000_SHIFT |
299 trans->entries[level].bxt.scale << UNIQ_TRANS_SCALE_SHIFT;
300 intel_de_write(dev_priv, BXT_PORT_TX_DW2_GRP(phy, ch), val);
302 val = intel_de_read(dev_priv, BXT_PORT_TX_DW3_LN0(phy, ch));
303 val &= ~SCALE_DCOMP_METHOD;
304 if (trans->entries[level].bxt.enable)
305 val |= SCALE_DCOMP_METHOD;
307 if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
308 drm_err(&dev_priv->drm,
309 "Disabled scaling while ouniqetrangenmethod was set");
311 intel_de_write(dev_priv, BXT_PORT_TX_DW3_GRP(phy, ch), val);
313 val = intel_de_read(dev_priv, BXT_PORT_TX_DW4_LN0(phy, ch));
315 val |= trans->entries[level].bxt.deemphasis << DEEMPH_SHIFT;
316 intel_de_write(dev_priv, BXT_PORT_TX_DW4_GRP(phy, ch), val);
318 val = intel_de_read(dev_priv, BXT_PORT_PCS_DW10_LN01(phy, ch));
319 val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
320 intel_de_write(dev_priv, BXT_PORT_PCS_DW10_GRP(phy, ch), val);
323 bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
326 const struct bxt_ddi_phy_info *phy_info;
328 phy_info = bxt_get_phy_info(dev_priv, phy);
330 if (!(intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON) & phy_info->pwron_mask))
333 if ((intel_de_read(dev_priv, BXT_PORT_CL1CM_DW0(phy)) &
334 (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
335 drm_dbg(&dev_priv->drm,
336 "DDI PHY %d powered, but power hasn't settled\n", phy);
341 if (!(intel_de_read(dev_priv, BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
342 drm_dbg(&dev_priv->drm,
343 "DDI PHY %d powered, but still in reset\n", phy);
351 static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
353 u32 val = intel_de_read(dev_priv, BXT_PORT_REF_DW6(phy));
355 return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
358 static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
361 if (intel_de_wait_for_set(dev_priv, BXT_PORT_REF_DW3(phy),
363 drm_err(&dev_priv->drm, "timeout waiting for PHY%d GRC\n",
367 static void _bxt_ddi_phy_init(struct drm_i915_private *dev_priv,
370 const struct bxt_ddi_phy_info *phy_info;
373 phy_info = bxt_get_phy_info(dev_priv, phy);
375 if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
376 /* Still read out the GRC value for state verification */
377 if (phy_info->rcomp_phy != -1)
378 dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy);
380 if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
381 drm_dbg(&dev_priv->drm, "DDI PHY %d already enabled, "
382 "won't reprogram it\n", phy);
386 drm_dbg(&dev_priv->drm,
387 "DDI PHY %d enabled with invalid state, "
388 "force reprogramming it\n", phy);
391 val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
392 val |= phy_info->pwron_mask;
393 intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON, val);
396 * The PHY registers start out inaccessible and respond to reads with
397 * all 1s. Eventually they become accessible as they power up, then
398 * the reserved bit will give the default 0. Poll on the reserved bit
399 * becoming 0 to find when the PHY is accessible.
400 * The flag should get set in 100us according to the HW team, but
401 * use 1ms due to occasional timeouts observed with that.
403 if (intel_wait_for_register_fw(&dev_priv->uncore,
404 BXT_PORT_CL1CM_DW0(phy),
405 PHY_RESERVED | PHY_POWER_GOOD,
408 drm_err(&dev_priv->drm, "timeout during PHY%d power on\n",
411 /* Program PLL Rcomp code offset */
412 val = intel_de_read(dev_priv, BXT_PORT_CL1CM_DW9(phy));
413 val &= ~IREF0RC_OFFSET_MASK;
414 val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
415 intel_de_write(dev_priv, BXT_PORT_CL1CM_DW9(phy), val);
417 val = intel_de_read(dev_priv, BXT_PORT_CL1CM_DW10(phy));
418 val &= ~IREF1RC_OFFSET_MASK;
419 val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
420 intel_de_write(dev_priv, BXT_PORT_CL1CM_DW10(phy), val);
422 /* Program power gating */
423 val = intel_de_read(dev_priv, BXT_PORT_CL1CM_DW28(phy));
424 val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
426 intel_de_write(dev_priv, BXT_PORT_CL1CM_DW28(phy), val);
428 if (phy_info->dual_channel) {
429 val = intel_de_read(dev_priv, BXT_PORT_CL2CM_DW6(phy));
430 val |= DW6_OLDO_DYN_PWR_DOWN_EN;
431 intel_de_write(dev_priv, BXT_PORT_CL2CM_DW6(phy), val);
434 if (phy_info->rcomp_phy != -1) {
437 bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy);
440 * PHY0 isn't connected to an RCOMP resistor so copy over
441 * the corresponding calibrated value from PHY1, and disable
442 * the automatic calibration on PHY0.
444 val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv,
445 phy_info->rcomp_phy);
446 grc_code = val << GRC_CODE_FAST_SHIFT |
447 val << GRC_CODE_SLOW_SHIFT |
449 intel_de_write(dev_priv, BXT_PORT_REF_DW6(phy), grc_code);
451 val = intel_de_read(dev_priv, BXT_PORT_REF_DW8(phy));
452 val |= GRC_DIS | GRC_RDY_OVRD;
453 intel_de_write(dev_priv, BXT_PORT_REF_DW8(phy), val);
456 if (phy_info->reset_delay)
457 udelay(phy_info->reset_delay);
459 val = intel_de_read(dev_priv, BXT_PHY_CTL_FAMILY(phy));
460 val |= COMMON_RESET_DIS;
461 intel_de_write(dev_priv, BXT_PHY_CTL_FAMILY(phy), val);
464 void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
466 const struct bxt_ddi_phy_info *phy_info;
469 phy_info = bxt_get_phy_info(dev_priv, phy);
471 val = intel_de_read(dev_priv, BXT_PHY_CTL_FAMILY(phy));
472 val &= ~COMMON_RESET_DIS;
473 intel_de_write(dev_priv, BXT_PHY_CTL_FAMILY(phy), val);
475 val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
476 val &= ~phy_info->pwron_mask;
477 intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON, val);
480 void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
482 const struct bxt_ddi_phy_info *phy_info =
483 bxt_get_phy_info(dev_priv, phy);
484 enum dpio_phy rcomp_phy = phy_info->rcomp_phy;
487 lockdep_assert_held(&dev_priv->power_domains.lock);
491 was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
494 * We need to copy the GRC calibration value from rcomp_phy,
495 * so make sure it's powered up.
498 _bxt_ddi_phy_init(dev_priv, rcomp_phy);
500 _bxt_ddi_phy_init(dev_priv, phy);
503 bxt_ddi_phy_uninit(dev_priv, rcomp_phy);
506 static bool __printf(6, 7)
507 __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
508 i915_reg_t reg, u32 mask, u32 expected,
509 const char *reg_fmt, ...)
511 struct va_format vaf;
515 val = intel_de_read(dev_priv, reg);
516 if ((val & mask) == expected)
519 va_start(args, reg_fmt);
523 drm_dbg(&dev_priv->drm, "DDI PHY %d reg %pV [%08x] state mismatch: "
524 "current %08x, expected %08x (mask %08x)\n",
525 phy, &vaf, reg.reg, val, (val & ~mask) | expected,
533 bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
536 const struct bxt_ddi_phy_info *phy_info;
540 phy_info = bxt_get_phy_info(dev_priv, phy);
542 #define _CHK(reg, mask, exp, fmt, ...) \
543 __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
546 if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
551 /* PLL Rcomp code offset */
552 ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
553 IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
554 "BXT_PORT_CL1CM_DW9(%d)", phy);
555 ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
556 IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
557 "BXT_PORT_CL1CM_DW10(%d)", phy);
560 mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
561 ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
562 "BXT_PORT_CL1CM_DW28(%d)", phy);
564 if (phy_info->dual_channel)
565 ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
566 DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
567 "BXT_PORT_CL2CM_DW6(%d)", phy);
569 if (phy_info->rcomp_phy != -1) {
570 u32 grc_code = dev_priv->bxt_phy_grc;
572 grc_code = grc_code << GRC_CODE_FAST_SHIFT |
573 grc_code << GRC_CODE_SLOW_SHIFT |
575 mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
577 ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code,
578 "BXT_PORT_REF_DW6(%d)", phy);
580 mask = GRC_DIS | GRC_RDY_OVRD;
581 ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask,
582 "BXT_PORT_REF_DW8(%d)", phy);
590 bxt_ddi_phy_calc_lane_lat_optim_mask(u8 lane_count)
592 switch (lane_count) {
596 return BIT(2) | BIT(0);
598 return BIT(3) | BIT(2) | BIT(0);
600 MISSING_CASE(lane_count);
606 void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
607 u8 lane_lat_optim_mask)
609 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
610 enum port port = encoder->port;
612 enum dpio_channel ch;
615 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
617 for (lane = 0; lane < 4; lane++) {
618 u32 val = intel_de_read(dev_priv,
619 BXT_PORT_TX_DW14_LN(phy, ch, lane));
622 * Note that on CHV this flag is called UPAR, but has
625 val &= ~LATENCY_OPTIM;
626 if (lane_lat_optim_mask & BIT(lane))
627 val |= LATENCY_OPTIM;
629 intel_de_write(dev_priv, BXT_PORT_TX_DW14_LN(phy, ch, lane),
635 bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
637 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
638 enum port port = encoder->port;
640 enum dpio_channel ch;
644 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
647 for (lane = 0; lane < 4; lane++) {
648 u32 val = intel_de_read(dev_priv,
649 BXT_PORT_TX_DW14_LN(phy, ch, lane));
651 if (val & LATENCY_OPTIM)
658 void chv_set_phy_signal_level(struct intel_encoder *encoder,
659 const struct intel_crtc_state *crtc_state,
660 u32 deemph_reg_value, u32 margin_reg_value,
661 bool uniq_trans_scale)
663 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
664 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
665 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
666 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
667 enum pipe pipe = crtc->pipe;
671 vlv_dpio_get(dev_priv);
673 /* Clear calc init */
674 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
675 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
676 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
677 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
678 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
680 if (crtc_state->lane_count > 2) {
681 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
682 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
683 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
684 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
685 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
688 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
689 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
690 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
691 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
693 if (crtc_state->lane_count > 2) {
694 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
695 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
696 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
697 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
700 /* Program swing deemph */
701 for (i = 0; i < crtc_state->lane_count; i++) {
702 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
703 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
704 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
705 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
708 /* Program swing margin */
709 for (i = 0; i < crtc_state->lane_count; i++) {
710 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
712 val &= ~DPIO_SWING_MARGIN000_MASK;
713 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
716 * Supposedly this value shouldn't matter when unique transition
717 * scale is disabled, but in fact it does matter. Let's just
718 * always program the same value and hope it's OK.
720 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
721 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
723 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
727 * The document said it needs to set bit 27 for ch0 and bit 26
728 * for ch1. Might be a typo in the doc.
729 * For now, for this unique transition scale selection, set bit
730 * 27 for ch0 and ch1.
732 for (i = 0; i < crtc_state->lane_count; i++) {
733 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
734 if (uniq_trans_scale)
735 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
737 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
738 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
741 /* Start swing calculation */
742 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
743 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
744 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
746 if (crtc_state->lane_count > 2) {
747 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
748 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
749 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
752 vlv_dpio_put(dev_priv);
755 void chv_data_lane_soft_reset(struct intel_encoder *encoder,
756 const struct intel_crtc_state *crtc_state,
759 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
760 enum dpio_channel ch = vlv_dig_port_to_channel(enc_to_dig_port(encoder));
761 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
762 enum pipe pipe = crtc->pipe;
765 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
767 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
769 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
770 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
772 if (crtc_state->lane_count > 2) {
773 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
775 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
777 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
778 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
781 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
782 val |= CHV_PCS_REQ_SOFTRESET_EN;
784 val &= ~DPIO_PCS_CLK_SOFT_RESET;
786 val |= DPIO_PCS_CLK_SOFT_RESET;
787 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
789 if (crtc_state->lane_count > 2) {
790 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
791 val |= CHV_PCS_REQ_SOFTRESET_EN;
793 val &= ~DPIO_PCS_CLK_SOFT_RESET;
795 val |= DPIO_PCS_CLK_SOFT_RESET;
796 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
800 void chv_phy_pre_pll_enable(struct intel_encoder *encoder,
801 const struct intel_crtc_state *crtc_state)
803 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
804 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
805 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
806 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
807 enum pipe pipe = crtc->pipe;
808 unsigned int lane_mask =
809 intel_dp_unused_lane_mask(crtc_state->lane_count);
813 * Must trick the second common lane into life.
814 * Otherwise we can't even access the PLL.
816 if (ch == DPIO_CH0 && pipe == PIPE_B)
817 dig_port->release_cl2_override =
818 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
820 chv_phy_powergate_lanes(encoder, true, lane_mask);
822 vlv_dpio_get(dev_priv);
824 /* Assert data lane reset */
825 chv_data_lane_soft_reset(encoder, crtc_state, true);
827 /* program left/right clock distribution */
828 if (pipe != PIPE_B) {
829 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
830 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
832 val |= CHV_BUFLEFTENA1_FORCE;
834 val |= CHV_BUFRIGHTENA1_FORCE;
835 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
837 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
838 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
840 val |= CHV_BUFLEFTENA2_FORCE;
842 val |= CHV_BUFRIGHTENA2_FORCE;
843 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
846 /* program clock channel usage */
847 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
848 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
850 val &= ~CHV_PCS_USEDCLKCHANNEL;
852 val |= CHV_PCS_USEDCLKCHANNEL;
853 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
855 if (crtc_state->lane_count > 2) {
856 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
857 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
859 val &= ~CHV_PCS_USEDCLKCHANNEL;
861 val |= CHV_PCS_USEDCLKCHANNEL;
862 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
866 * This a a bit weird since generally CL
867 * matches the pipe, but here we need to
868 * pick the CL based on the port.
870 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
872 val &= ~CHV_CMN_USEDCLKCHANNEL;
874 val |= CHV_CMN_USEDCLKCHANNEL;
875 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
877 vlv_dpio_put(dev_priv);
880 void chv_phy_pre_encoder_enable(struct intel_encoder *encoder,
881 const struct intel_crtc_state *crtc_state)
883 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
884 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
885 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
886 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
887 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
888 enum pipe pipe = crtc->pipe;
889 int data, i, stagger;
892 vlv_dpio_get(dev_priv);
894 /* allow hardware to manage TX FIFO reset source */
895 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
896 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
897 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
899 if (crtc_state->lane_count > 2) {
900 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
901 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
902 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
905 /* Program Tx lane latency optimal setting*/
906 for (i = 0; i < crtc_state->lane_count; i++) {
907 /* Set the upar bit */
908 if (crtc_state->lane_count == 1)
911 data = (i == 1) ? 0x0 : 0x1;
912 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
913 data << DPIO_UPAR_SHIFT);
916 /* Data lane stagger programming */
917 if (crtc_state->port_clock > 270000)
919 else if (crtc_state->port_clock > 135000)
921 else if (crtc_state->port_clock > 67500)
923 else if (crtc_state->port_clock > 33750)
928 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
929 val |= DPIO_TX2_STAGGER_MASK(0x1f);
930 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
932 if (crtc_state->lane_count > 2) {
933 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
934 val |= DPIO_TX2_STAGGER_MASK(0x1f);
935 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
938 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
939 DPIO_LANESTAGGER_STRAP(stagger) |
940 DPIO_LANESTAGGER_STRAP_OVRD |
941 DPIO_TX1_STAGGER_MASK(0x1f) |
942 DPIO_TX1_STAGGER_MULT(6) |
943 DPIO_TX2_STAGGER_MULT(0));
945 if (crtc_state->lane_count > 2) {
946 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
947 DPIO_LANESTAGGER_STRAP(stagger) |
948 DPIO_LANESTAGGER_STRAP_OVRD |
949 DPIO_TX1_STAGGER_MASK(0x1f) |
950 DPIO_TX1_STAGGER_MULT(7) |
951 DPIO_TX2_STAGGER_MULT(5));
954 /* Deassert data lane reset */
955 chv_data_lane_soft_reset(encoder, crtc_state, false);
957 vlv_dpio_put(dev_priv);
960 void chv_phy_release_cl2_override(struct intel_encoder *encoder)
962 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
963 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
965 if (dig_port->release_cl2_override) {
966 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
967 dig_port->release_cl2_override = false;
971 void chv_phy_post_pll_disable(struct intel_encoder *encoder,
972 const struct intel_crtc_state *old_crtc_state)
974 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
975 enum pipe pipe = to_intel_crtc(old_crtc_state->uapi.crtc)->pipe;
978 vlv_dpio_get(dev_priv);
980 /* disable left/right clock distribution */
981 if (pipe != PIPE_B) {
982 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
983 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
984 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
986 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
987 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
988 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
991 vlv_dpio_put(dev_priv);
994 * Leave the power down bit cleared for at least one
995 * lane so that chv_powergate_phy_ch() will power
996 * on something when the channel is otherwise unused.
997 * When the port is off and the override is removed
998 * the lanes power down anyway, so otherwise it doesn't
999 * really matter what the state of power down bits is
1002 chv_phy_powergate_lanes(encoder, false, 0x0);
1005 void vlv_set_phy_signal_level(struct intel_encoder *encoder,
1006 const struct intel_crtc_state *crtc_state,
1007 u32 demph_reg_value, u32 preemph_reg_value,
1008 u32 uniqtranscale_reg_value, u32 tx3_demph)
1010 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1011 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1012 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1013 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1014 enum pipe pipe = crtc->pipe;
1016 vlv_dpio_get(dev_priv);
1018 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
1019 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
1020 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
1021 uniqtranscale_reg_value);
1022 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
1025 vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
1027 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
1028 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
1029 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
1031 vlv_dpio_put(dev_priv);
1034 void vlv_phy_pre_pll_enable(struct intel_encoder *encoder,
1035 const struct intel_crtc_state *crtc_state)
1037 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1038 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1039 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1040 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1041 enum pipe pipe = crtc->pipe;
1043 /* Program Tx lane resets to default */
1044 vlv_dpio_get(dev_priv);
1046 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
1047 DPIO_PCS_TX_LANE2_RESET |
1048 DPIO_PCS_TX_LANE1_RESET);
1049 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
1050 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1051 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1052 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1053 DPIO_PCS_CLK_SOFT_RESET);
1055 /* Fix up inter-pair skew failure */
1056 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1057 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1058 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
1060 vlv_dpio_put(dev_priv);
1063 void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder,
1064 const struct intel_crtc_state *crtc_state)
1066 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1067 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1068 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1069 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1070 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1071 enum pipe pipe = crtc->pipe;
1074 vlv_dpio_get(dev_priv);
1076 /* Enable clock channels for this port */
1077 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
1084 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1086 /* Program lane clock */
1087 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1088 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
1090 vlv_dpio_put(dev_priv);
1093 void vlv_phy_reset_lanes(struct intel_encoder *encoder,
1094 const struct intel_crtc_state *old_crtc_state)
1096 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1097 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1098 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1099 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1100 enum pipe pipe = crtc->pipe;
1102 vlv_dpio_get(dev_priv);
1103 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
1104 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
1105 vlv_dpio_put(dev_priv);