Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright © 2014-2016 Intel Corporation
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice (including the next
0012  * paragraph) shall be included in all copies or substantial portions of the
0013  * Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0021  * DEALINGS IN THE SOFTWARE.
0022  */
0023 
0024 #include "intel_ddi.h"
0025 #include "intel_ddi_buf_trans.h"
0026 #include "intel_de.h"
0027 #include "intel_display_power_well.h"
0028 #include "intel_display_types.h"
0029 #include "intel_dp.h"
0030 #include "intel_dpio_phy.h"
0031 #include "vlv_sideband.h"
0032 
0033 /**
0034  * DOC: DPIO
0035  *
0036  * VLV, CHV and BXT have slightly peculiar display PHYs for driving DP/HDMI
0037  * ports. DPIO is the name given to such a display PHY. These PHYs
0038  * don't follow the standard programming model using direct MMIO
0039  * registers, and instead their registers must be accessed trough IOSF
0040  * sideband. VLV has one such PHY for driving ports B and C, and CHV
0041  * adds another PHY for driving port D. Each PHY responds to specific
0042  * IOSF-SB port.
0043  *
0044  * Each display PHY is made up of one or two channels. Each channel
0045  * houses a common lane part which contains the PLL and other common
0046  * logic. CH0 common lane also contains the IOSF-SB logic for the
0047  * Common Register Interface (CRI) ie. the DPIO registers. CRI clock
0048  * must be running when any DPIO registers are accessed.
0049  *
0050  * In addition to having their own registers, the PHYs are also
0051  * controlled through some dedicated signals from the display
0052  * controller. These include PLL reference clock enable, PLL enable,
0053  * and CRI clock selection, for example.
0054  *
0055  * Eeach channel also has two splines (also called data lanes), and
0056  * each spline is made up of one Physical Access Coding Sub-Layer
0057  * (PCS) block and two TX lanes. So each channel has two PCS blocks
0058  * and four TX lanes. The TX lanes are used as DP lanes or TMDS
0059  * data/clock pairs depending on the output type.
0060  *
0061  * Additionally the PHY also contains an AUX lane with AUX blocks
0062  * for each channel. This is used for DP AUX communication, but
0063  * this fact isn't really relevant for the driver since AUX is
0064  * controlled from the display controller side. No DPIO registers
0065  * need to be accessed during AUX communication,
0066  *
0067  * Generally on VLV/CHV the common lane corresponds to the pipe and
0068  * the spline (PCS/TX) corresponds to the port.
0069  *
0070  * For dual channel PHY (VLV/CHV):
0071  *
0072  *  pipe A == CMN/PLL/REF CH0
0073  *
0074  *  pipe B == CMN/PLL/REF CH1
0075  *
0076  *  port B == PCS/TX CH0
0077  *
0078  *  port C == PCS/TX CH1
0079  *
0080  * This is especially important when we cross the streams
0081  * ie. drive port B with pipe B, or port C with pipe A.
0082  *
0083  * For single channel PHY (CHV):
0084  *
0085  *  pipe C == CMN/PLL/REF CH0
0086  *
0087  *  port D == PCS/TX CH0
0088  *
0089  * On BXT the entire PHY channel corresponds to the port. That means
0090  * the PLL is also now associated with the port rather than the pipe,
0091  * and so the clock needs to be routed to the appropriate transcoder.
0092  * Port A PLL is directly connected to transcoder EDP and port B/C
0093  * PLLs can be routed to any transcoder A/B/C.
0094  *
0095  * Note: DDI0 is digital port B, DD1 is digital port C, and DDI2 is
0096  * digital port D (CHV) or port A (BXT). ::
0097  *
0098  *
0099  *     Dual channel PHY (VLV/CHV/BXT)
0100  *     ---------------------------------
0101  *     |      CH0      |      CH1      |
0102  *     |  CMN/PLL/REF  |  CMN/PLL/REF  |
0103  *     |---------------|---------------| Display PHY
0104  *     | PCS01 | PCS23 | PCS01 | PCS23 |
0105  *     |-------|-------|-------|-------|
0106  *     |TX0|TX1|TX2|TX3|TX0|TX1|TX2|TX3|
0107  *     ---------------------------------
0108  *     |     DDI0      |     DDI1      | DP/HDMI ports
0109  *     ---------------------------------
0110  *
0111  *     Single channel PHY (CHV/BXT)
0112  *     -----------------
0113  *     |      CH0      |
0114  *     |  CMN/PLL/REF  |
0115  *     |---------------| Display PHY
0116  *     | PCS01 | PCS23 |
0117  *     |-------|-------|
0118  *     |TX0|TX1|TX2|TX3|
0119  *     -----------------
0120  *     |     DDI2      | DP/HDMI port
0121  *     -----------------
0122  */
0123 
0124 /**
0125  * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
0126  */
0127 struct bxt_ddi_phy_info {
0128     /**
0129      * @dual_channel: true if this phy has a second channel.
0130      */
0131     bool dual_channel;
0132 
0133     /**
0134      * @rcomp_phy: If -1, indicates this phy has its own rcomp resistor.
0135      * Otherwise the GRC value will be copied from the phy indicated by
0136      * this field.
0137      */
0138     enum dpio_phy rcomp_phy;
0139 
0140     /**
0141      * @reset_delay: delay in us to wait before setting the common reset
0142      * bit in BXT_PHY_CTL_FAMILY, which effectively enables the phy.
0143      */
0144     int reset_delay;
0145 
0146     /**
0147      * @pwron_mask: Mask with the appropriate bit set that would cause the
0148      * punit to power this phy if written to BXT_P_CR_GT_DISP_PWRON.
0149      */
0150     u32 pwron_mask;
0151 
0152     /**
0153      * @channel: struct containing per channel information.
0154      */
0155     struct {
0156         /**
0157          * @channel.port: which port maps to this channel.
0158          */
0159         enum port port;
0160     } channel[2];
0161 };
0162 
0163 static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = {
0164     [DPIO_PHY0] = {
0165         .dual_channel = true,
0166         .rcomp_phy = DPIO_PHY1,
0167         .pwron_mask = BIT(0),
0168 
0169         .channel = {
0170             [DPIO_CH0] = { .port = PORT_B },
0171             [DPIO_CH1] = { .port = PORT_C },
0172         }
0173     },
0174     [DPIO_PHY1] = {
0175         .dual_channel = false,
0176         .rcomp_phy = -1,
0177         .pwron_mask = BIT(1),
0178 
0179         .channel = {
0180             [DPIO_CH0] = { .port = PORT_A },
0181         }
0182     },
0183 };
0184 
0185 static const struct bxt_ddi_phy_info glk_ddi_phy_info[] = {
0186     [DPIO_PHY0] = {
0187         .dual_channel = false,
0188         .rcomp_phy = DPIO_PHY1,
0189         .pwron_mask = BIT(0),
0190         .reset_delay = 20,
0191 
0192         .channel = {
0193             [DPIO_CH0] = { .port = PORT_B },
0194         }
0195     },
0196     [DPIO_PHY1] = {
0197         .dual_channel = false,
0198         .rcomp_phy = -1,
0199         .pwron_mask = BIT(3),
0200         .reset_delay = 20,
0201 
0202         .channel = {
0203             [DPIO_CH0] = { .port = PORT_A },
0204         }
0205     },
0206     [DPIO_PHY2] = {
0207         .dual_channel = false,
0208         .rcomp_phy = DPIO_PHY1,
0209         .pwron_mask = BIT(1),
0210         .reset_delay = 20,
0211 
0212         .channel = {
0213             [DPIO_CH0] = { .port = PORT_C },
0214         }
0215     },
0216 };
0217 
0218 static const struct bxt_ddi_phy_info *
0219 bxt_get_phy_list(struct drm_i915_private *dev_priv, int *count)
0220 {
0221     if (IS_GEMINILAKE(dev_priv)) {
0222         *count =  ARRAY_SIZE(glk_ddi_phy_info);
0223         return glk_ddi_phy_info;
0224     } else {
0225         *count =  ARRAY_SIZE(bxt_ddi_phy_info);
0226         return bxt_ddi_phy_info;
0227     }
0228 }
0229 
0230 static const struct bxt_ddi_phy_info *
0231 bxt_get_phy_info(struct drm_i915_private *dev_priv, enum dpio_phy phy)
0232 {
0233     int count;
0234     const struct bxt_ddi_phy_info *phy_list =
0235         bxt_get_phy_list(dev_priv, &count);
0236 
0237     return &phy_list[phy];
0238 }
0239 
0240 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
0241                  enum dpio_phy *phy, enum dpio_channel *ch)
0242 {
0243     const struct bxt_ddi_phy_info *phy_info, *phys;
0244     int i, count;
0245 
0246     phys = bxt_get_phy_list(dev_priv, &count);
0247 
0248     for (i = 0; i < count; i++) {
0249         phy_info = &phys[i];
0250 
0251         if (port == phy_info->channel[DPIO_CH0].port) {
0252             *phy = i;
0253             *ch = DPIO_CH0;
0254             return;
0255         }
0256 
0257         if (phy_info->dual_channel &&
0258             port == phy_info->channel[DPIO_CH1].port) {
0259             *phy = i;
0260             *ch = DPIO_CH1;
0261             return;
0262         }
0263     }
0264 
0265     drm_WARN(&dev_priv->drm, 1, "PHY not found for PORT %c",
0266          port_name(port));
0267     *phy = DPIO_PHY0;
0268     *ch = DPIO_CH0;
0269 }
0270 
0271 void bxt_ddi_phy_set_signal_levels(struct intel_encoder *encoder,
0272                    const struct intel_crtc_state *crtc_state)
0273 {
0274     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0275     int level = intel_ddi_level(encoder, crtc_state, 0);
0276     const struct intel_ddi_buf_trans *trans;
0277     enum dpio_channel ch;
0278     enum dpio_phy phy;
0279     int n_entries;
0280     u32 val;
0281 
0282     trans = encoder->get_buf_trans(encoder, crtc_state, &n_entries);
0283     if (drm_WARN_ON_ONCE(&dev_priv->drm, !trans))
0284         return;
0285 
0286     bxt_port_to_phy_channel(dev_priv, encoder->port, &phy, &ch);
0287 
0288     /*
0289      * While we write to the group register to program all lanes at once we
0290      * can read only lane registers and we pick lanes 0/1 for that.
0291      */
0292     val = intel_de_read(dev_priv, BXT_PORT_PCS_DW10_LN01(phy, ch));
0293     val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
0294     intel_de_write(dev_priv, BXT_PORT_PCS_DW10_GRP(phy, ch), val);
0295 
0296     val = intel_de_read(dev_priv, BXT_PORT_TX_DW2_LN0(phy, ch));
0297     val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
0298     val |= trans->entries[level].bxt.margin << MARGIN_000_SHIFT |
0299         trans->entries[level].bxt.scale << UNIQ_TRANS_SCALE_SHIFT;
0300     intel_de_write(dev_priv, BXT_PORT_TX_DW2_GRP(phy, ch), val);
0301 
0302     val = intel_de_read(dev_priv, BXT_PORT_TX_DW3_LN0(phy, ch));
0303     val &= ~SCALE_DCOMP_METHOD;
0304     if (trans->entries[level].bxt.enable)
0305         val |= SCALE_DCOMP_METHOD;
0306 
0307     if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
0308         drm_err(&dev_priv->drm,
0309             "Disabled scaling while ouniqetrangenmethod was set");
0310 
0311     intel_de_write(dev_priv, BXT_PORT_TX_DW3_GRP(phy, ch), val);
0312 
0313     val = intel_de_read(dev_priv, BXT_PORT_TX_DW4_LN0(phy, ch));
0314     val &= ~DE_EMPHASIS;
0315     val |= trans->entries[level].bxt.deemphasis << DEEMPH_SHIFT;
0316     intel_de_write(dev_priv, BXT_PORT_TX_DW4_GRP(phy, ch), val);
0317 
0318     val = intel_de_read(dev_priv, BXT_PORT_PCS_DW10_LN01(phy, ch));
0319     val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
0320     intel_de_write(dev_priv, BXT_PORT_PCS_DW10_GRP(phy, ch), val);
0321 }
0322 
0323 bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
0324                 enum dpio_phy phy)
0325 {
0326     const struct bxt_ddi_phy_info *phy_info;
0327 
0328     phy_info = bxt_get_phy_info(dev_priv, phy);
0329 
0330     if (!(intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON) & phy_info->pwron_mask))
0331         return false;
0332 
0333     if ((intel_de_read(dev_priv, BXT_PORT_CL1CM_DW0(phy)) &
0334          (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
0335         drm_dbg(&dev_priv->drm,
0336             "DDI PHY %d powered, but power hasn't settled\n", phy);
0337 
0338         return false;
0339     }
0340 
0341     if (!(intel_de_read(dev_priv, BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
0342         drm_dbg(&dev_priv->drm,
0343             "DDI PHY %d powered, but still in reset\n", phy);
0344 
0345         return false;
0346     }
0347 
0348     return true;
0349 }
0350 
0351 static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
0352 {
0353     u32 val = intel_de_read(dev_priv, BXT_PORT_REF_DW6(phy));
0354 
0355     return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
0356 }
0357 
0358 static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
0359                   enum dpio_phy phy)
0360 {
0361     if (intel_de_wait_for_set(dev_priv, BXT_PORT_REF_DW3(phy),
0362                   GRC_DONE, 10))
0363         drm_err(&dev_priv->drm, "timeout waiting for PHY%d GRC\n",
0364             phy);
0365 }
0366 
0367 static void _bxt_ddi_phy_init(struct drm_i915_private *dev_priv,
0368                   enum dpio_phy phy)
0369 {
0370     const struct bxt_ddi_phy_info *phy_info;
0371     u32 val;
0372 
0373     phy_info = bxt_get_phy_info(dev_priv, phy);
0374 
0375     if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
0376         /* Still read out the GRC value for state verification */
0377         if (phy_info->rcomp_phy != -1)
0378             dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy);
0379 
0380         if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
0381             drm_dbg(&dev_priv->drm, "DDI PHY %d already enabled, "
0382                 "won't reprogram it\n", phy);
0383             return;
0384         }
0385 
0386         drm_dbg(&dev_priv->drm,
0387             "DDI PHY %d enabled with invalid state, "
0388             "force reprogramming it\n", phy);
0389     }
0390 
0391     val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
0392     val |= phy_info->pwron_mask;
0393     intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON, val);
0394 
0395     /*
0396      * The PHY registers start out inaccessible and respond to reads with
0397      * all 1s.  Eventually they become accessible as they power up, then
0398      * the reserved bit will give the default 0.  Poll on the reserved bit
0399      * becoming 0 to find when the PHY is accessible.
0400      * The flag should get set in 100us according to the HW team, but
0401      * use 1ms due to occasional timeouts observed with that.
0402      */
0403     if (intel_wait_for_register_fw(&dev_priv->uncore,
0404                        BXT_PORT_CL1CM_DW0(phy),
0405                        PHY_RESERVED | PHY_POWER_GOOD,
0406                        PHY_POWER_GOOD,
0407                        1))
0408         drm_err(&dev_priv->drm, "timeout during PHY%d power on\n",
0409             phy);
0410 
0411     /* Program PLL Rcomp code offset */
0412     val = intel_de_read(dev_priv, BXT_PORT_CL1CM_DW9(phy));
0413     val &= ~IREF0RC_OFFSET_MASK;
0414     val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
0415     intel_de_write(dev_priv, BXT_PORT_CL1CM_DW9(phy), val);
0416 
0417     val = intel_de_read(dev_priv, BXT_PORT_CL1CM_DW10(phy));
0418     val &= ~IREF1RC_OFFSET_MASK;
0419     val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
0420     intel_de_write(dev_priv, BXT_PORT_CL1CM_DW10(phy), val);
0421 
0422     /* Program power gating */
0423     val = intel_de_read(dev_priv, BXT_PORT_CL1CM_DW28(phy));
0424     val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
0425         SUS_CLK_CONFIG;
0426     intel_de_write(dev_priv, BXT_PORT_CL1CM_DW28(phy), val);
0427 
0428     if (phy_info->dual_channel) {
0429         val = intel_de_read(dev_priv, BXT_PORT_CL2CM_DW6(phy));
0430         val |= DW6_OLDO_DYN_PWR_DOWN_EN;
0431         intel_de_write(dev_priv, BXT_PORT_CL2CM_DW6(phy), val);
0432     }
0433 
0434     if (phy_info->rcomp_phy != -1) {
0435         u32 grc_code;
0436 
0437         bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy);
0438 
0439         /*
0440          * PHY0 isn't connected to an RCOMP resistor so copy over
0441          * the corresponding calibrated value from PHY1, and disable
0442          * the automatic calibration on PHY0.
0443          */
0444         val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv,
0445                               phy_info->rcomp_phy);
0446         grc_code = val << GRC_CODE_FAST_SHIFT |
0447                val << GRC_CODE_SLOW_SHIFT |
0448                val;
0449         intel_de_write(dev_priv, BXT_PORT_REF_DW6(phy), grc_code);
0450 
0451         val = intel_de_read(dev_priv, BXT_PORT_REF_DW8(phy));
0452         val |= GRC_DIS | GRC_RDY_OVRD;
0453         intel_de_write(dev_priv, BXT_PORT_REF_DW8(phy), val);
0454     }
0455 
0456     if (phy_info->reset_delay)
0457         udelay(phy_info->reset_delay);
0458 
0459     val = intel_de_read(dev_priv, BXT_PHY_CTL_FAMILY(phy));
0460     val |= COMMON_RESET_DIS;
0461     intel_de_write(dev_priv, BXT_PHY_CTL_FAMILY(phy), val);
0462 }
0463 
0464 void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
0465 {
0466     const struct bxt_ddi_phy_info *phy_info;
0467     u32 val;
0468 
0469     phy_info = bxt_get_phy_info(dev_priv, phy);
0470 
0471     val = intel_de_read(dev_priv, BXT_PHY_CTL_FAMILY(phy));
0472     val &= ~COMMON_RESET_DIS;
0473     intel_de_write(dev_priv, BXT_PHY_CTL_FAMILY(phy), val);
0474 
0475     val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
0476     val &= ~phy_info->pwron_mask;
0477     intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON, val);
0478 }
0479 
0480 void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
0481 {
0482     const struct bxt_ddi_phy_info *phy_info =
0483         bxt_get_phy_info(dev_priv, phy);
0484     enum dpio_phy rcomp_phy = phy_info->rcomp_phy;
0485     bool was_enabled;
0486 
0487     lockdep_assert_held(&dev_priv->power_domains.lock);
0488 
0489     was_enabled = true;
0490     if (rcomp_phy != -1)
0491         was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
0492 
0493     /*
0494      * We need to copy the GRC calibration value from rcomp_phy,
0495      * so make sure it's powered up.
0496      */
0497     if (!was_enabled)
0498         _bxt_ddi_phy_init(dev_priv, rcomp_phy);
0499 
0500     _bxt_ddi_phy_init(dev_priv, phy);
0501 
0502     if (!was_enabled)
0503         bxt_ddi_phy_uninit(dev_priv, rcomp_phy);
0504 }
0505 
0506 static bool __printf(6, 7)
0507 __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
0508                i915_reg_t reg, u32 mask, u32 expected,
0509                const char *reg_fmt, ...)
0510 {
0511     struct va_format vaf;
0512     va_list args;
0513     u32 val;
0514 
0515     val = intel_de_read(dev_priv, reg);
0516     if ((val & mask) == expected)
0517         return true;
0518 
0519     va_start(args, reg_fmt);
0520     vaf.fmt = reg_fmt;
0521     vaf.va = &args;
0522 
0523     drm_dbg(&dev_priv->drm, "DDI PHY %d reg %pV [%08x] state mismatch: "
0524              "current %08x, expected %08x (mask %08x)\n",
0525              phy, &vaf, reg.reg, val, (val & ~mask) | expected,
0526              mask);
0527 
0528     va_end(args);
0529 
0530     return false;
0531 }
0532 
0533 bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
0534                   enum dpio_phy phy)
0535 {
0536     const struct bxt_ddi_phy_info *phy_info;
0537     u32 mask;
0538     bool ok;
0539 
0540     phy_info = bxt_get_phy_info(dev_priv, phy);
0541 
0542 #define _CHK(reg, mask, exp, fmt, ...)                  \
0543     __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt,  \
0544                    ## __VA_ARGS__)
0545 
0546     if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
0547         return false;
0548 
0549     ok = true;
0550 
0551     /* PLL Rcomp code offset */
0552     ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
0553             IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
0554             "BXT_PORT_CL1CM_DW9(%d)", phy);
0555     ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
0556             IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
0557             "BXT_PORT_CL1CM_DW10(%d)", phy);
0558 
0559     /* Power gating */
0560     mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
0561     ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
0562             "BXT_PORT_CL1CM_DW28(%d)", phy);
0563 
0564     if (phy_info->dual_channel)
0565         ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
0566                DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
0567                "BXT_PORT_CL2CM_DW6(%d)", phy);
0568 
0569     if (phy_info->rcomp_phy != -1) {
0570         u32 grc_code = dev_priv->bxt_phy_grc;
0571 
0572         grc_code = grc_code << GRC_CODE_FAST_SHIFT |
0573                grc_code << GRC_CODE_SLOW_SHIFT |
0574                grc_code;
0575         mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
0576                GRC_CODE_NOM_MASK;
0577         ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code,
0578                "BXT_PORT_REF_DW6(%d)", phy);
0579 
0580         mask = GRC_DIS | GRC_RDY_OVRD;
0581         ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask,
0582                 "BXT_PORT_REF_DW8(%d)", phy);
0583     }
0584 
0585     return ok;
0586 #undef _CHK
0587 }
0588 
0589 u8
0590 bxt_ddi_phy_calc_lane_lat_optim_mask(u8 lane_count)
0591 {
0592     switch (lane_count) {
0593     case 1:
0594         return 0;
0595     case 2:
0596         return BIT(2) | BIT(0);
0597     case 4:
0598         return BIT(3) | BIT(2) | BIT(0);
0599     default:
0600         MISSING_CASE(lane_count);
0601 
0602         return 0;
0603     }
0604 }
0605 
0606 void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
0607                      u8 lane_lat_optim_mask)
0608 {
0609     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0610     enum port port = encoder->port;
0611     enum dpio_phy phy;
0612     enum dpio_channel ch;
0613     int lane;
0614 
0615     bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
0616 
0617     for (lane = 0; lane < 4; lane++) {
0618         u32 val = intel_de_read(dev_priv,
0619                     BXT_PORT_TX_DW14_LN(phy, ch, lane));
0620 
0621         /*
0622          * Note that on CHV this flag is called UPAR, but has
0623          * the same function.
0624          */
0625         val &= ~LATENCY_OPTIM;
0626         if (lane_lat_optim_mask & BIT(lane))
0627             val |= LATENCY_OPTIM;
0628 
0629         intel_de_write(dev_priv, BXT_PORT_TX_DW14_LN(phy, ch, lane),
0630                    val);
0631     }
0632 }
0633 
0634 u8
0635 bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
0636 {
0637     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0638     enum port port = encoder->port;
0639     enum dpio_phy phy;
0640     enum dpio_channel ch;
0641     int lane;
0642     u8 mask;
0643 
0644     bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
0645 
0646     mask = 0;
0647     for (lane = 0; lane < 4; lane++) {
0648         u32 val = intel_de_read(dev_priv,
0649                     BXT_PORT_TX_DW14_LN(phy, ch, lane));
0650 
0651         if (val & LATENCY_OPTIM)
0652             mask |= BIT(lane);
0653     }
0654 
0655     return mask;
0656 }
0657 
0658 void chv_set_phy_signal_level(struct intel_encoder *encoder,
0659                   const struct intel_crtc_state *crtc_state,
0660                   u32 deemph_reg_value, u32 margin_reg_value,
0661                   bool uniq_trans_scale)
0662 {
0663     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0664     struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
0665     struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
0666     enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
0667     enum pipe pipe = crtc->pipe;
0668     u32 val;
0669     int i;
0670 
0671     vlv_dpio_get(dev_priv);
0672 
0673     /* Clear calc init */
0674     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
0675     val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
0676     val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
0677     val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
0678     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
0679 
0680     if (crtc_state->lane_count > 2) {
0681         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
0682         val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
0683         val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
0684         val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
0685         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
0686     }
0687 
0688     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
0689     val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
0690     val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
0691     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
0692 
0693     if (crtc_state->lane_count > 2) {
0694         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
0695         val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
0696         val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
0697         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
0698     }
0699 
0700     /* Program swing deemph */
0701     for (i = 0; i < crtc_state->lane_count; i++) {
0702         val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
0703         val &= ~DPIO_SWING_DEEMPH9P5_MASK;
0704         val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
0705         vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
0706     }
0707 
0708     /* Program swing margin */
0709     for (i = 0; i < crtc_state->lane_count; i++) {
0710         val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
0711 
0712         val &= ~DPIO_SWING_MARGIN000_MASK;
0713         val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
0714 
0715         /*
0716          * Supposedly this value shouldn't matter when unique transition
0717          * scale is disabled, but in fact it does matter. Let's just
0718          * always program the same value and hope it's OK.
0719          */
0720         val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
0721         val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
0722 
0723         vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
0724     }
0725 
0726     /*
0727      * The document said it needs to set bit 27 for ch0 and bit 26
0728      * for ch1. Might be a typo in the doc.
0729      * For now, for this unique transition scale selection, set bit
0730      * 27 for ch0 and ch1.
0731      */
0732     for (i = 0; i < crtc_state->lane_count; i++) {
0733         val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
0734         if (uniq_trans_scale)
0735             val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
0736         else
0737             val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
0738         vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
0739     }
0740 
0741     /* Start swing calculation */
0742     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
0743     val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
0744     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
0745 
0746     if (crtc_state->lane_count > 2) {
0747         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
0748         val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
0749         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
0750     }
0751 
0752     vlv_dpio_put(dev_priv);
0753 }
0754 
0755 void chv_data_lane_soft_reset(struct intel_encoder *encoder,
0756                   const struct intel_crtc_state *crtc_state,
0757                   bool reset)
0758 {
0759     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0760     enum dpio_channel ch = vlv_dig_port_to_channel(enc_to_dig_port(encoder));
0761     struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
0762     enum pipe pipe = crtc->pipe;
0763     u32 val;
0764 
0765     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
0766     if (reset)
0767         val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
0768     else
0769         val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
0770     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
0771 
0772     if (crtc_state->lane_count > 2) {
0773         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
0774         if (reset)
0775             val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
0776         else
0777             val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
0778         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
0779     }
0780 
0781     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
0782     val |= CHV_PCS_REQ_SOFTRESET_EN;
0783     if (reset)
0784         val &= ~DPIO_PCS_CLK_SOFT_RESET;
0785     else
0786         val |= DPIO_PCS_CLK_SOFT_RESET;
0787     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
0788 
0789     if (crtc_state->lane_count > 2) {
0790         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
0791         val |= CHV_PCS_REQ_SOFTRESET_EN;
0792         if (reset)
0793             val &= ~DPIO_PCS_CLK_SOFT_RESET;
0794         else
0795             val |= DPIO_PCS_CLK_SOFT_RESET;
0796         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
0797     }
0798 }
0799 
0800 void chv_phy_pre_pll_enable(struct intel_encoder *encoder,
0801                 const struct intel_crtc_state *crtc_state)
0802 {
0803     struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
0804     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0805     struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
0806     enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
0807     enum pipe pipe = crtc->pipe;
0808     unsigned int lane_mask =
0809         intel_dp_unused_lane_mask(crtc_state->lane_count);
0810     u32 val;
0811 
0812     /*
0813      * Must trick the second common lane into life.
0814      * Otherwise we can't even access the PLL.
0815      */
0816     if (ch == DPIO_CH0 && pipe == PIPE_B)
0817         dig_port->release_cl2_override =
0818             !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
0819 
0820     chv_phy_powergate_lanes(encoder, true, lane_mask);
0821 
0822     vlv_dpio_get(dev_priv);
0823 
0824     /* Assert data lane reset */
0825     chv_data_lane_soft_reset(encoder, crtc_state, true);
0826 
0827     /* program left/right clock distribution */
0828     if (pipe != PIPE_B) {
0829         val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
0830         val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
0831         if (ch == DPIO_CH0)
0832             val |= CHV_BUFLEFTENA1_FORCE;
0833         if (ch == DPIO_CH1)
0834             val |= CHV_BUFRIGHTENA1_FORCE;
0835         vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
0836     } else {
0837         val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
0838         val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
0839         if (ch == DPIO_CH0)
0840             val |= CHV_BUFLEFTENA2_FORCE;
0841         if (ch == DPIO_CH1)
0842             val |= CHV_BUFRIGHTENA2_FORCE;
0843         vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
0844     }
0845 
0846     /* program clock channel usage */
0847     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
0848     val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
0849     if (pipe != PIPE_B)
0850         val &= ~CHV_PCS_USEDCLKCHANNEL;
0851     else
0852         val |= CHV_PCS_USEDCLKCHANNEL;
0853     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
0854 
0855     if (crtc_state->lane_count > 2) {
0856         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
0857         val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
0858         if (pipe != PIPE_B)
0859             val &= ~CHV_PCS_USEDCLKCHANNEL;
0860         else
0861             val |= CHV_PCS_USEDCLKCHANNEL;
0862         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
0863     }
0864 
0865     /*
0866      * This a a bit weird since generally CL
0867      * matches the pipe, but here we need to
0868      * pick the CL based on the port.
0869      */
0870     val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
0871     if (pipe != PIPE_B)
0872         val &= ~CHV_CMN_USEDCLKCHANNEL;
0873     else
0874         val |= CHV_CMN_USEDCLKCHANNEL;
0875     vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
0876 
0877     vlv_dpio_put(dev_priv);
0878 }
0879 
0880 void chv_phy_pre_encoder_enable(struct intel_encoder *encoder,
0881                 const struct intel_crtc_state *crtc_state)
0882 {
0883     struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
0884     struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
0885     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0886     struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
0887     enum dpio_channel ch = vlv_dig_port_to_channel(dig_port);
0888     enum pipe pipe = crtc->pipe;
0889     int data, i, stagger;
0890     u32 val;
0891 
0892     vlv_dpio_get(dev_priv);
0893 
0894     /* allow hardware to manage TX FIFO reset source */
0895     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
0896     val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
0897     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
0898 
0899     if (crtc_state->lane_count > 2) {
0900         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
0901         val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
0902         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
0903     }
0904 
0905     /* Program Tx lane latency optimal setting*/
0906     for (i = 0; i < crtc_state->lane_count; i++) {
0907         /* Set the upar bit */
0908         if (crtc_state->lane_count == 1)
0909             data = 0x0;
0910         else
0911             data = (i == 1) ? 0x0 : 0x1;
0912         vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
0913                 data << DPIO_UPAR_SHIFT);
0914     }
0915 
0916     /* Data lane stagger programming */
0917     if (crtc_state->port_clock > 270000)
0918         stagger = 0x18;
0919     else if (crtc_state->port_clock > 135000)
0920         stagger = 0xd;
0921     else if (crtc_state->port_clock > 67500)
0922         stagger = 0x7;
0923     else if (crtc_state->port_clock > 33750)
0924         stagger = 0x4;
0925     else
0926         stagger = 0x2;
0927 
0928     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
0929     val |= DPIO_TX2_STAGGER_MASK(0x1f);
0930     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
0931 
0932     if (crtc_state->lane_count > 2) {
0933         val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
0934         val |= DPIO_TX2_STAGGER_MASK(0x1f);
0935         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
0936     }
0937 
0938     vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
0939                DPIO_LANESTAGGER_STRAP(stagger) |
0940                DPIO_LANESTAGGER_STRAP_OVRD |
0941                DPIO_TX1_STAGGER_MASK(0x1f) |
0942                DPIO_TX1_STAGGER_MULT(6) |
0943                DPIO_TX2_STAGGER_MULT(0));
0944 
0945     if (crtc_state->lane_count > 2) {
0946         vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
0947                    DPIO_LANESTAGGER_STRAP(stagger) |
0948                    DPIO_LANESTAGGER_STRAP_OVRD |
0949                    DPIO_TX1_STAGGER_MASK(0x1f) |
0950                    DPIO_TX1_STAGGER_MULT(7) |
0951                    DPIO_TX2_STAGGER_MULT(5));
0952     }
0953 
0954     /* Deassert data lane reset */
0955     chv_data_lane_soft_reset(encoder, crtc_state, false);
0956 
0957     vlv_dpio_put(dev_priv);
0958 }
0959 
0960 void chv_phy_release_cl2_override(struct intel_encoder *encoder)
0961 {
0962     struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
0963     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0964 
0965     if (dig_port->release_cl2_override) {
0966         chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
0967         dig_port->release_cl2_override = false;
0968     }
0969 }
0970 
0971 void chv_phy_post_pll_disable(struct intel_encoder *encoder,
0972                   const struct intel_crtc_state *old_crtc_state)
0973 {
0974     struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
0975     enum pipe pipe = to_intel_crtc(old_crtc_state->uapi.crtc)->pipe;
0976     u32 val;
0977 
0978     vlv_dpio_get(dev_priv);
0979 
0980     /* disable left/right clock distribution */
0981     if (pipe != PIPE_B) {
0982         val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
0983         val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
0984         vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
0985     } else {
0986         val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
0987         val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
0988         vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
0989     }
0990 
0991     vlv_dpio_put(dev_priv);
0992 
0993     /*
0994      * Leave the power down bit cleared for at least one
0995      * lane so that chv_powergate_phy_ch() will power
0996      * on something when the channel is otherwise unused.
0997      * When the port is off and the override is removed
0998      * the lanes power down anyway, so otherwise it doesn't
0999      * really matter what the state of power down bits is
1000      * after this.
1001      */
1002     chv_phy_powergate_lanes(encoder, false, 0x0);
1003 }
1004 
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)
1009 {
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;
1015 
1016     vlv_dpio_get(dev_priv);
1017 
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);
1023 
1024     if (tx3_demph)
1025         vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
1026 
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);
1030 
1031     vlv_dpio_put(dev_priv);
1032 }
1033 
1034 void vlv_phy_pre_pll_enable(struct intel_encoder *encoder,
1035                 const struct intel_crtc_state *crtc_state)
1036 {
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;
1042 
1043     /* Program Tx lane resets to default */
1044     vlv_dpio_get(dev_priv);
1045 
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);
1054 
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);
1059 
1060     vlv_dpio_put(dev_priv);
1061 }
1062 
1063 void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder,
1064                 const struct intel_crtc_state *crtc_state)
1065 {
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;
1072     u32 val;
1073 
1074     vlv_dpio_get(dev_priv);
1075 
1076     /* Enable clock channels for this port */
1077     val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
1078     val = 0;
1079     if (pipe)
1080         val |= (1<<21);
1081     else
1082         val &= ~(1<<21);
1083     val |= 0x001000c4;
1084     vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1085 
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);
1089 
1090     vlv_dpio_put(dev_priv);
1091 }
1092 
1093 void vlv_phy_reset_lanes(struct intel_encoder *encoder,
1094              const struct intel_crtc_state *old_crtc_state)
1095 {
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;
1101 
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);
1106 }