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.
25 #include "intel_ddi.h"
26 #include "intel_ddi_buf_trans.h"
28 #include "intel_display_power_well.h"
29 #include "intel_display_types.h"
31 #include "intel_dpio_phy.h"
32 #include "vlv_sideband.h"
37 * VLV, CHV and BXT have slightly peculiar display PHYs for driving DP/HDMI
38 * ports. DPIO is the name given to such a display PHY. These PHYs
39 * don't follow the standard programming model using direct MMIO
40 * registers, and instead their registers must be accessed trough IOSF
41 * sideband. VLV has one such PHY for driving ports B and C, and CHV
42 * adds another PHY for driving port D. Each PHY responds to specific
45 * Each display PHY is made up of one or two channels. Each channel
46 * houses a common lane part which contains the PLL and other common
47 * logic. CH0 common lane also contains the IOSF-SB logic for the
48 * Common Register Interface (CRI) ie. the DPIO registers. CRI clock
49 * must be running when any DPIO registers are accessed.
51 * In addition to having their own registers, the PHYs are also
52 * controlled through some dedicated signals from the display
53 * controller. These include PLL reference clock enable, PLL enable,
54 * and CRI clock selection, for example.
56 * Eeach channel also has two splines (also called data lanes), and
57 * each spline is made up of one Physical Access Coding Sub-Layer
58 * (PCS) block and two TX lanes. So each channel has two PCS blocks
59 * and four TX lanes. The TX lanes are used as DP lanes or TMDS
60 * data/clock pairs depending on the output type.
62 * Additionally the PHY also contains an AUX lane with AUX blocks
63 * for each channel. This is used for DP AUX communication, but
64 * this fact isn't really relevant for the driver since AUX is
65 * controlled from the display controller side. No DPIO registers
66 * need to be accessed during AUX communication,
68 * Generally on VLV/CHV the common lane corresponds to the pipe and
69 * the spline (PCS/TX) corresponds to the port.
71 * For dual channel PHY (VLV/CHV):
73 * pipe A == CMN/PLL/REF CH0
75 * pipe B == CMN/PLL/REF CH1
77 * port B == PCS/TX CH0
79 * port C == PCS/TX CH1
81 * This is especially important when we cross the streams
82 * ie. drive port B with pipe B, or port C with pipe A.
84 * For single channel PHY (CHV):
86 * pipe C == CMN/PLL/REF CH0
88 * port D == PCS/TX CH0
90 * On BXT the entire PHY channel corresponds to the port. That means
91 * the PLL is also now associated with the port rather than the pipe,
92 * and so the clock needs to be routed to the appropriate transcoder.
93 * Port A PLL is directly connected to transcoder EDP and port B/C
94 * PLLs can be routed to any transcoder A/B/C.
96 * Note: DDI0 is digital port B, DD1 is digital port C, and DDI2 is
97 * digital port D (CHV) or port A (BXT). ::
100 * Dual channel PHY (VLV/CHV/BXT)
101 * ---------------------------------
103 * | CMN/PLL/REF | CMN/PLL/REF |
104 * |---------------|---------------| Display PHY
105 * | PCS01 | PCS23 | PCS01 | PCS23 |
106 * |-------|-------|-------|-------|
107 * |TX0|TX1|TX2|TX3|TX0|TX1|TX2|TX3|
108 * ---------------------------------
109 * | DDI0 | DDI1 | DP/HDMI ports
110 * ---------------------------------
112 * Single channel PHY (CHV/BXT)
116 * |---------------| Display PHY
121 * | DDI2 | DP/HDMI port
126 * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
128 struct bxt_ddi_phy_info {
130 * @dual_channel: true if this phy has a second channel.
135 * @rcomp_phy: If -1, indicates this phy has its own rcomp resistor.
136 * Otherwise the GRC value will be copied from the phy indicated by
139 enum dpio_phy rcomp_phy;
142 * @reset_delay: delay in us to wait before setting the common reset
143 * bit in BXT_PHY_CTL_FAMILY, which effectively enables the phy.
148 * @pwron_mask: Mask with the appropriate bit set that would cause the
149 * punit to power this phy if written to BXT_P_CR_GT_DISP_PWRON.
154 * @channel: struct containing per channel information.
158 * @channel.port: which port maps to this channel.
164 static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = {
166 .dual_channel = true,
167 .rcomp_phy = DPIO_PHY1,
168 .pwron_mask = BIT(0),
171 [DPIO_CH0] = { .port = PORT_B },
172 [DPIO_CH1] = { .port = PORT_C },
176 .dual_channel = false,
178 .pwron_mask = BIT(1),
181 [DPIO_CH0] = { .port = PORT_A },
186 static const struct bxt_ddi_phy_info glk_ddi_phy_info[] = {
188 .dual_channel = false,
189 .rcomp_phy = DPIO_PHY1,
190 .pwron_mask = BIT(0),
194 [DPIO_CH0] = { .port = PORT_B },
198 .dual_channel = false,
200 .pwron_mask = BIT(3),
204 [DPIO_CH0] = { .port = PORT_A },
208 .dual_channel = false,
209 .rcomp_phy = DPIO_PHY1,
210 .pwron_mask = BIT(1),
214 [DPIO_CH0] = { .port = PORT_C },
219 static const struct bxt_ddi_phy_info *
220 bxt_get_phy_list(struct drm_i915_private *dev_priv, int *count)
222 if (IS_GEMINILAKE(dev_priv)) {
223 *count = ARRAY_SIZE(glk_ddi_phy_info);
224 return glk_ddi_phy_info;
226 *count = ARRAY_SIZE(bxt_ddi_phy_info);
227 return bxt_ddi_phy_info;
231 static const struct bxt_ddi_phy_info *
232 bxt_get_phy_info(struct drm_i915_private *dev_priv, enum dpio_phy phy)
235 const struct bxt_ddi_phy_info *phy_list =
236 bxt_get_phy_list(dev_priv, &count);
238 return &phy_list[phy];
241 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
242 enum dpio_phy *phy, enum dpio_channel *ch)
244 const struct bxt_ddi_phy_info *phy_info, *phys;
247 phys = bxt_get_phy_list(dev_priv, &count);
249 for (i = 0; i < count; i++) {
252 if (port == phy_info->channel[DPIO_CH0].port) {
258 if (phy_info->dual_channel &&
259 port == phy_info->channel[DPIO_CH1].port) {
266 drm_WARN(&dev_priv->drm, 1, "PHY not found for PORT %c",
272 void bxt_ddi_phy_set_signal_levels(struct intel_encoder *encoder,
273 const struct intel_crtc_state *crtc_state)
275 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
276 int level = intel_ddi_level(encoder, crtc_state, 0);
277 const struct intel_ddi_buf_trans *trans;
278 enum dpio_channel ch;
283 trans = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
284 if (drm_WARN_ON_ONCE(&dev_priv->drm, !trans))
287 bxt_port_to_phy_channel(dev_priv, encoder->port, &phy, &ch);
290 * While we write to the group register to program all lanes at once we
291 * can read only lane registers and we pick lanes 0/1 for that.
293 val = intel_de_read(dev_priv, BXT_PORT_PCS_DW10_LN01(phy, ch));
294 val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
295 intel_de_write(dev_priv, BXT_PORT_PCS_DW10_GRP(phy, ch), val);
297 val = intel_de_read(dev_priv, BXT_PORT_TX_DW2_LN0(phy, ch));
298 val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
299 val |= trans->entries[level].bxt.margin << MARGIN_000_SHIFT |
300 trans->entries[level].bxt.scale << UNIQ_TRANS_SCALE_SHIFT;
301 intel_de_write(dev_priv, BXT_PORT_TX_DW2_GRP(phy, ch), val);
303 val = intel_de_read(dev_priv, BXT_PORT_TX_DW3_LN0(phy, ch));
304 val &= ~SCALE_DCOMP_METHOD;
305 if (trans->entries[level].bxt.enable)
306 val |= SCALE_DCOMP_METHOD;
308 if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
309 drm_err(&dev_priv->drm,
310 "Disabled scaling while ouniqetrangenmethod was set");
312 intel_de_write(dev_priv, BXT_PORT_TX_DW3_GRP(phy, ch), val);
314 val = intel_de_read(dev_priv, BXT_PORT_TX_DW4_LN0(phy, ch));
316 val |= trans->entries[level].bxt.deemphasis << DEEMPH_SHIFT;
317 intel_de_write(dev_priv, BXT_PORT_TX_DW4_GRP(phy, ch), val);
319 val = intel_de_read(dev_priv, BXT_PORT_PCS_DW10_LN01(phy, ch));
320 val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
321 intel_de_write(dev_priv, BXT_PORT_PCS_DW10_GRP(phy, ch), val);
324 bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
327 const struct bxt_ddi_phy_info *phy_info;
329 phy_info = bxt_get_phy_info(dev_priv, phy);
331 if (!(intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON) & phy_info->pwron_mask))
334 if ((intel_de_read(dev_priv, BXT_PORT_CL1CM_DW0(phy)) &
335 (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
336 drm_dbg(&dev_priv->drm,
337 "DDI PHY %d powered, but power hasn't settled\n", phy);
342 if (!(intel_de_read(dev_priv, BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
343 drm_dbg(&dev_priv->drm,
344 "DDI PHY %d powered, but still in reset\n", phy);
352 static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
354 u32 val = intel_de_read(dev_priv, BXT_PORT_REF_DW6(phy));
356 return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
359 static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
362 if (intel_de_wait_for_set(dev_priv, BXT_PORT_REF_DW3(phy),
364 drm_err(&dev_priv->drm, "timeout waiting for PHY%d GRC\n",
368 static void _bxt_ddi_phy_init(struct drm_i915_private *dev_priv,
371 const struct bxt_ddi_phy_info *phy_info;
374 phy_info = bxt_get_phy_info(dev_priv, phy);
376 if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
377 /* Still read out the GRC value for state verification */
378 if (phy_info->rcomp_phy != -1)
379 dev_priv->display.state.bxt_phy_grc = bxt_get_grc(dev_priv, phy);
381 if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
382 drm_dbg(&dev_priv->drm, "DDI PHY %d already enabled, "
383 "won't reprogram it\n", phy);
387 drm_dbg(&dev_priv->drm,
388 "DDI PHY %d enabled with invalid state, "
389 "force reprogramming it\n", phy);
392 intel_de_rmw(dev_priv, BXT_P_CR_GT_DISP_PWRON, 0, phy_info->pwron_mask);
395 * The PHY registers start out inaccessible and respond to reads with
396 * all 1s. Eventually they become accessible as they power up, then
397 * the reserved bit will give the default 0. Poll on the reserved bit
398 * becoming 0 to find when the PHY is accessible.
399 * The flag should get set in 100us according to the HW team, but
400 * use 1ms due to occasional timeouts observed with that.
402 if (intel_wait_for_register_fw(&dev_priv->uncore,
403 BXT_PORT_CL1CM_DW0(phy),
404 PHY_RESERVED | PHY_POWER_GOOD,
407 drm_err(&dev_priv->drm, "timeout during PHY%d power on\n",
410 /* Program PLL Rcomp code offset */
411 intel_de_rmw(dev_priv, BXT_PORT_CL1CM_DW9(phy), IREF0RC_OFFSET_MASK,
412 0xE4 << IREF0RC_OFFSET_SHIFT);
414 intel_de_rmw(dev_priv, BXT_PORT_CL1CM_DW10(phy), IREF1RC_OFFSET_MASK,
415 0xE4 << IREF1RC_OFFSET_SHIFT);
417 /* Program power gating */
418 intel_de_rmw(dev_priv, BXT_PORT_CL1CM_DW28(phy), 0,
419 OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG);
421 if (phy_info->dual_channel)
422 intel_de_rmw(dev_priv, BXT_PORT_CL2CM_DW6(phy), 0,
423 DW6_OLDO_DYN_PWR_DOWN_EN);
425 if (phy_info->rcomp_phy != -1) {
428 bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy);
431 * PHY0 isn't connected to an RCOMP resistor so copy over
432 * the corresponding calibrated value from PHY1, and disable
433 * the automatic calibration on PHY0.
435 val = bxt_get_grc(dev_priv, phy_info->rcomp_phy);
436 dev_priv->display.state.bxt_phy_grc = val;
438 grc_code = val << GRC_CODE_FAST_SHIFT |
439 val << GRC_CODE_SLOW_SHIFT |
441 intel_de_write(dev_priv, BXT_PORT_REF_DW6(phy), grc_code);
442 intel_de_rmw(dev_priv, BXT_PORT_REF_DW8(phy),
443 0, GRC_DIS | GRC_RDY_OVRD);
446 if (phy_info->reset_delay)
447 udelay(phy_info->reset_delay);
449 intel_de_rmw(dev_priv, BXT_PHY_CTL_FAMILY(phy), 0, COMMON_RESET_DIS);
452 void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
454 const struct bxt_ddi_phy_info *phy_info;
456 phy_info = bxt_get_phy_info(dev_priv, phy);
458 intel_de_rmw(dev_priv, BXT_PHY_CTL_FAMILY(phy), COMMON_RESET_DIS, 0);
460 intel_de_rmw(dev_priv, BXT_P_CR_GT_DISP_PWRON, phy_info->pwron_mask, 0);
463 void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
465 const struct bxt_ddi_phy_info *phy_info =
466 bxt_get_phy_info(dev_priv, phy);
467 enum dpio_phy rcomp_phy = phy_info->rcomp_phy;
470 lockdep_assert_held(&dev_priv->display.power.domains.lock);
474 was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
477 * We need to copy the GRC calibration value from rcomp_phy,
478 * so make sure it's powered up.
481 _bxt_ddi_phy_init(dev_priv, rcomp_phy);
483 _bxt_ddi_phy_init(dev_priv, phy);
486 bxt_ddi_phy_uninit(dev_priv, rcomp_phy);
489 static bool __printf(6, 7)
490 __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
491 i915_reg_t reg, u32 mask, u32 expected,
492 const char *reg_fmt, ...)
494 struct va_format vaf;
498 val = intel_de_read(dev_priv, reg);
499 if ((val & mask) == expected)
502 va_start(args, reg_fmt);
506 drm_dbg(&dev_priv->drm, "DDI PHY %d reg %pV [%08x] state mismatch: "
507 "current %08x, expected %08x (mask %08x)\n",
508 phy, &vaf, reg.reg, val, (val & ~mask) | expected,
516 bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
519 const struct bxt_ddi_phy_info *phy_info;
523 phy_info = bxt_get_phy_info(dev_priv, phy);
525 #define _CHK(reg, mask, exp, fmt, ...) \
526 __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
529 if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
534 /* PLL Rcomp code offset */
535 ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
536 IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
537 "BXT_PORT_CL1CM_DW9(%d)", phy);
538 ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
539 IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
540 "BXT_PORT_CL1CM_DW10(%d)", phy);
543 mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
544 ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
545 "BXT_PORT_CL1CM_DW28(%d)", phy);
547 if (phy_info->dual_channel)
548 ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
549 DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
550 "BXT_PORT_CL2CM_DW6(%d)", phy);
552 if (phy_info->rcomp_phy != -1) {
553 u32 grc_code = dev_priv->display.state.bxt_phy_grc;
555 grc_code = grc_code << GRC_CODE_FAST_SHIFT |
556 grc_code << GRC_CODE_SLOW_SHIFT |
558 mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
560 ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code,
561 "BXT_PORT_REF_DW6(%d)", phy);
563 mask = GRC_DIS | GRC_RDY_OVRD;
564 ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask,
565 "BXT_PORT_REF_DW8(%d)", phy);
573 bxt_ddi_phy_calc_lane_lat_optim_mask(u8 lane_count)
575 switch (lane_count) {
579 return BIT(2) | BIT(0);
581 return BIT(3) | BIT(2) | BIT(0);
583 MISSING_CASE(lane_count);
589 void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
590 u8 lane_lat_optim_mask)
592 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
593 enum port port = encoder->port;
595 enum dpio_channel ch;
598 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
600 for (lane = 0; lane < 4; lane++) {
601 u32 val = intel_de_read(dev_priv,
602 BXT_PORT_TX_DW14_LN(phy, ch, lane));
605 * Note that on CHV this flag is called UPAR, but has
608 val &= ~LATENCY_OPTIM;
609 if (lane_lat_optim_mask & BIT(lane))
610 val |= LATENCY_OPTIM;
612 intel_de_write(dev_priv, BXT_PORT_TX_DW14_LN(phy, ch, lane),
618 bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
620 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
621 enum port port = encoder->port;
623 enum dpio_channel ch;
627 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
630 for (lane = 0; lane < 4; lane++) {
631 u32 val = intel_de_read(dev_priv,
632 BXT_PORT_TX_DW14_LN(phy, ch, lane));
634 if (val & LATENCY_OPTIM)
641 enum dpio_channel vlv_dig_port_to_channel(struct intel_digital_port *dig_port)
643 switch (dig_port->base.port) {
645 MISSING_CASE(dig_port->base.port);
655 enum dpio_phy vlv_dig_port_to_phy(struct intel_digital_port *dig_port)
657 switch (dig_port->base.port) {
659 MISSING_CASE(dig_port->base.port);
669 enum dpio_channel vlv_pipe_to_channel(enum pipe pipe)
683 void chv_set_phy_signal_level(struct intel_encoder *encoder,
684 const struct intel_crtc_state *crtc_state,
685 u32 deemph_reg_value, u32 margin_reg_value,
686 bool uniq_trans_scale)
688 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
689 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
690 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
691 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
692 enum pipe pipe = crtc->pipe;
696 vlv_dpio_get(dev_priv);
698 /* Clear calc init */
699 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
700 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
701 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
702 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
703 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
705 if (crtc_state->lane_count > 2) {
706 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
707 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
708 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
709 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
710 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
713 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
714 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
715 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
716 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
718 if (crtc_state->lane_count > 2) {
719 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
720 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
721 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
722 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
725 /* Program swing deemph */
726 for (i = 0; i < crtc_state->lane_count; i++) {
727 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
728 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
729 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
730 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
733 /* Program swing margin */
734 for (i = 0; i < crtc_state->lane_count; i++) {
735 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
737 val &= ~DPIO_SWING_MARGIN000_MASK;
738 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
741 * Supposedly this value shouldn't matter when unique transition
742 * scale is disabled, but in fact it does matter. Let's just
743 * always program the same value and hope it's OK.
745 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
746 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
748 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
752 * The document said it needs to set bit 27 for ch0 and bit 26
753 * for ch1. Might be a typo in the doc.
754 * For now, for this unique transition scale selection, set bit
755 * 27 for ch0 and ch1.
757 for (i = 0; i < crtc_state->lane_count; i++) {
758 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
759 if (uniq_trans_scale)
760 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
762 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
763 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
766 /* Start swing calculation */
767 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
768 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
769 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
771 if (crtc_state->lane_count > 2) {
772 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
773 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
774 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
777 vlv_dpio_put(dev_priv);
780 void chv_data_lane_soft_reset(struct intel_encoder *encoder,
781 const struct intel_crtc_state *crtc_state,
784 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
785 enum dpio_channel ch = vlv_dig_port_to_channel(enc_to_dig_port(encoder));
786 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
787 enum pipe pipe = crtc->pipe;
790 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
792 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
794 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
795 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
797 if (crtc_state->lane_count > 2) {
798 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
800 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
802 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
803 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
806 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
807 val |= CHV_PCS_REQ_SOFTRESET_EN;
809 val &= ~DPIO_PCS_CLK_SOFT_RESET;
811 val |= DPIO_PCS_CLK_SOFT_RESET;
812 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
814 if (crtc_state->lane_count > 2) {
815 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
816 val |= CHV_PCS_REQ_SOFTRESET_EN;
818 val &= ~DPIO_PCS_CLK_SOFT_RESET;
820 val |= DPIO_PCS_CLK_SOFT_RESET;
821 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
825 void chv_phy_pre_pll_enable(struct intel_encoder *encoder,
826 const struct intel_crtc_state *crtc_state)
828 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
829 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
830 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
831 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
832 enum pipe pipe = crtc->pipe;
833 unsigned int lane_mask =
834 intel_dp_unused_lane_mask(crtc_state->lane_count);
838 * Must trick the second common lane into life.
839 * Otherwise we can't even access the PLL.
841 if (ch == DPIO_CH0 && pipe == PIPE_B)
842 dig_port->release_cl2_override =
843 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
845 chv_phy_powergate_lanes(encoder, true, lane_mask);
847 vlv_dpio_get(dev_priv);
849 /* Assert data lane reset */
850 chv_data_lane_soft_reset(encoder, crtc_state, true);
852 /* program left/right clock distribution */
853 if (pipe != PIPE_B) {
854 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
855 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
857 val |= CHV_BUFLEFTENA1_FORCE;
859 val |= CHV_BUFRIGHTENA1_FORCE;
860 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
862 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
863 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
865 val |= CHV_BUFLEFTENA2_FORCE;
867 val |= CHV_BUFRIGHTENA2_FORCE;
868 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
871 /* program clock channel usage */
872 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
873 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
875 val &= ~CHV_PCS_USEDCLKCHANNEL;
877 val |= CHV_PCS_USEDCLKCHANNEL;
878 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
880 if (crtc_state->lane_count > 2) {
881 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
882 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
884 val &= ~CHV_PCS_USEDCLKCHANNEL;
886 val |= CHV_PCS_USEDCLKCHANNEL;
887 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
891 * This a a bit weird since generally CL
892 * matches the pipe, but here we need to
893 * pick the CL based on the port.
895 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
897 val &= ~CHV_CMN_USEDCLKCHANNEL;
899 val |= CHV_CMN_USEDCLKCHANNEL;
900 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
902 vlv_dpio_put(dev_priv);
905 void chv_phy_pre_encoder_enable(struct intel_encoder *encoder,
906 const struct intel_crtc_state *crtc_state)
908 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
909 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
910 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
911 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
912 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
913 enum pipe pipe = crtc->pipe;
914 int data, i, stagger;
917 vlv_dpio_get(dev_priv);
919 /* allow hardware to manage TX FIFO reset source */
920 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
921 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
922 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
924 if (crtc_state->lane_count > 2) {
925 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
926 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
927 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
930 /* Program Tx lane latency optimal setting*/
931 for (i = 0; i < crtc_state->lane_count; i++) {
932 /* Set the upar bit */
933 if (crtc_state->lane_count == 1)
936 data = (i == 1) ? 0x0 : 0x1;
937 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
938 data << DPIO_UPAR_SHIFT);
941 /* Data lane stagger programming */
942 if (crtc_state->port_clock > 270000)
944 else if (crtc_state->port_clock > 135000)
946 else if (crtc_state->port_clock > 67500)
948 else if (crtc_state->port_clock > 33750)
953 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
954 val |= DPIO_TX2_STAGGER_MASK(0x1f);
955 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
957 if (crtc_state->lane_count > 2) {
958 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
959 val |= DPIO_TX2_STAGGER_MASK(0x1f);
960 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
963 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
964 DPIO_LANESTAGGER_STRAP(stagger) |
965 DPIO_LANESTAGGER_STRAP_OVRD |
966 DPIO_TX1_STAGGER_MASK(0x1f) |
967 DPIO_TX1_STAGGER_MULT(6) |
968 DPIO_TX2_STAGGER_MULT(0));
970 if (crtc_state->lane_count > 2) {
971 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
972 DPIO_LANESTAGGER_STRAP(stagger) |
973 DPIO_LANESTAGGER_STRAP_OVRD |
974 DPIO_TX1_STAGGER_MASK(0x1f) |
975 DPIO_TX1_STAGGER_MULT(7) |
976 DPIO_TX2_STAGGER_MULT(5));
979 /* Deassert data lane reset */
980 chv_data_lane_soft_reset(encoder, crtc_state, false);
982 vlv_dpio_put(dev_priv);
985 void chv_phy_release_cl2_override(struct intel_encoder *encoder)
987 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
988 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
990 if (dig_port->release_cl2_override) {
991 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
992 dig_port->release_cl2_override = false;
996 void chv_phy_post_pll_disable(struct intel_encoder *encoder,
997 const struct intel_crtc_state *old_crtc_state)
999 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1000 enum pipe pipe = to_intel_crtc(old_crtc_state->uapi.crtc)->pipe;
1003 vlv_dpio_get(dev_priv);
1005 /* disable left/right clock distribution */
1006 if (pipe != PIPE_B) {
1007 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
1008 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
1009 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
1011 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
1012 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
1013 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
1016 vlv_dpio_put(dev_priv);
1019 * Leave the power down bit cleared for at least one
1020 * lane so that chv_powergate_phy_ch() will power
1021 * on something when the channel is otherwise unused.
1022 * When the port is off and the override is removed
1023 * the lanes power down anyway, so otherwise it doesn't
1024 * really matter what the state of power down bits is
1027 chv_phy_powergate_lanes(encoder, false, 0x0);
1030 void vlv_set_phy_signal_level(struct intel_encoder *encoder,
1031 const struct intel_crtc_state *crtc_state,
1032 u32 demph_reg_value, u32 preemph_reg_value,
1033 u32 uniqtranscale_reg_value, u32 tx3_demph)
1035 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1036 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1037 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1038 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1039 enum pipe pipe = crtc->pipe;
1041 vlv_dpio_get(dev_priv);
1043 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
1044 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
1045 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
1046 uniqtranscale_reg_value);
1047 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
1050 vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
1052 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
1053 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
1054 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
1056 vlv_dpio_put(dev_priv);
1059 void vlv_phy_pre_pll_enable(struct intel_encoder *encoder,
1060 const struct intel_crtc_state *crtc_state)
1062 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1063 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1064 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1065 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1066 enum pipe pipe = crtc->pipe;
1068 /* Program Tx lane resets to default */
1069 vlv_dpio_get(dev_priv);
1071 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
1072 DPIO_PCS_TX_LANE2_RESET |
1073 DPIO_PCS_TX_LANE1_RESET);
1074 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
1075 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1076 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1077 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1078 DPIO_PCS_CLK_SOFT_RESET);
1080 /* Fix up inter-pair skew failure */
1081 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1082 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1083 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
1085 vlv_dpio_put(dev_priv);
1088 void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder,
1089 const struct intel_crtc_state *crtc_state)
1091 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1092 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1093 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1094 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1095 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1096 enum pipe pipe = crtc->pipe;
1099 vlv_dpio_get(dev_priv);
1101 /* Enable clock channels for this port */
1102 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
1109 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1111 /* Program lane clock */
1112 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1113 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
1115 vlv_dpio_put(dev_priv);
1118 void vlv_phy_reset_lanes(struct intel_encoder *encoder,
1119 const struct intel_crtc_state *old_crtc_state)
1121 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1122 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1123 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1124 enum dpio_channel port = vlv_dig_port_to_channel(dig_port);
1125 enum pipe pipe = crtc->pipe;
1127 vlv_dpio_get(dev_priv);
1128 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
1129 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
1130 vlv_dpio_put(dev_priv);