1 /* 2 * Copyright © 2014-2016 Intel Corporation 3 * 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: 10 * 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 13 * Software. 14 * 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. 22 */ 23 24 #include "i915_reg.h" 25 #include "intel_ddi.h" 26 #include "intel_ddi_buf_trans.h" 27 #include "intel_de.h" 28 #include "intel_display_power_well.h" 29 #include "intel_display_types.h" 30 #include "intel_dp.h" 31 #include "intel_dpio_phy.h" 32 #include "vlv_sideband.h" 33 34 /** 35 * DOC: DPIO 36 * 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 43 * IOSF-SB port. 44 * 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. 50 * 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. 55 * 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. 61 * 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, 67 * 68 * Generally on VLV/CHV the common lane corresponds to the pipe and 69 * the spline (PCS/TX) corresponds to the port. 70 * 71 * For dual channel PHY (VLV/CHV): 72 * 73 * pipe A == CMN/PLL/REF CH0 74 * 75 * pipe B == CMN/PLL/REF CH1 76 * 77 * port B == PCS/TX CH0 78 * 79 * port C == PCS/TX CH1 80 * 81 * This is especially important when we cross the streams 82 * ie. drive port B with pipe B, or port C with pipe A. 83 * 84 * For single channel PHY (CHV): 85 * 86 * pipe C == CMN/PLL/REF CH0 87 * 88 * port D == PCS/TX CH0 89 * 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. 95 * 96 * Note: DDI0 is digital port B, DD1 is digital port C, and DDI2 is 97 * digital port D (CHV) or port A (BXT). :: 98 * 99 * 100 * Dual channel PHY (VLV/CHV/BXT) 101 * --------------------------------- 102 * | CH0 | CH1 | 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 * --------------------------------- 111 * 112 * Single channel PHY (CHV/BXT) 113 * ----------------- 114 * | CH0 | 115 * | CMN/PLL/REF | 116 * |---------------| Display PHY 117 * | PCS01 | PCS23 | 118 * |-------|-------| 119 * |TX0|TX1|TX2|TX3| 120 * ----------------- 121 * | DDI2 | DP/HDMI port 122 * ----------------- 123 */ 124 125 /** 126 * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy 127 */ 128 struct bxt_ddi_phy_info { 129 /** 130 * @dual_channel: true if this phy has a second channel. 131 */ 132 bool dual_channel; 133 134 /** 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 137 * this field. 138 */ 139 enum dpio_phy rcomp_phy; 140 141 /** 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. 144 */ 145 int reset_delay; 146 147 /** 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. 150 */ 151 u32 pwron_mask; 152 153 /** 154 * @channel: struct containing per channel information. 155 */ 156 struct { 157 /** 158 * @channel.port: which port maps to this channel. 159 */ 160 enum port port; 161 } channel[2]; 162 }; 163 164 static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = { 165 [DPIO_PHY0] = { 166 .dual_channel = true, 167 .rcomp_phy = DPIO_PHY1, 168 .pwron_mask = BIT(0), 169 170 .channel = { 171 [DPIO_CH0] = { .port = PORT_B }, 172 [DPIO_CH1] = { .port = PORT_C }, 173 } 174 }, 175 [DPIO_PHY1] = { 176 .dual_channel = false, 177 .rcomp_phy = -1, 178 .pwron_mask = BIT(1), 179 180 .channel = { 181 [DPIO_CH0] = { .port = PORT_A }, 182 } 183 }, 184 }; 185 186 static const struct bxt_ddi_phy_info glk_ddi_phy_info[] = { 187 [DPIO_PHY0] = { 188 .dual_channel = false, 189 .rcomp_phy = DPIO_PHY1, 190 .pwron_mask = BIT(0), 191 .reset_delay = 20, 192 193 .channel = { 194 [DPIO_CH0] = { .port = PORT_B }, 195 } 196 }, 197 [DPIO_PHY1] = { 198 .dual_channel = false, 199 .rcomp_phy = -1, 200 .pwron_mask = BIT(3), 201 .reset_delay = 20, 202 203 .channel = { 204 [DPIO_CH0] = { .port = PORT_A }, 205 } 206 }, 207 [DPIO_PHY2] = { 208 .dual_channel = false, 209 .rcomp_phy = DPIO_PHY1, 210 .pwron_mask = BIT(1), 211 .reset_delay = 20, 212 213 .channel = { 214 [DPIO_CH0] = { .port = PORT_C }, 215 } 216 }, 217 }; 218 219 static const struct bxt_ddi_phy_info * 220 bxt_get_phy_list(struct drm_i915_private *dev_priv, int *count) 221 { 222 if (IS_GEMINILAKE(dev_priv)) { 223 *count = ARRAY_SIZE(glk_ddi_phy_info); 224 return glk_ddi_phy_info; 225 } else { 226 *count = ARRAY_SIZE(bxt_ddi_phy_info); 227 return bxt_ddi_phy_info; 228 } 229 } 230 231 static const struct bxt_ddi_phy_info * 232 bxt_get_phy_info(struct drm_i915_private *dev_priv, enum dpio_phy phy) 233 { 234 int count; 235 const struct bxt_ddi_phy_info *phy_list = 236 bxt_get_phy_list(dev_priv, &count); 237 238 return &phy_list[phy]; 239 } 240 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) 243 { 244 const struct bxt_ddi_phy_info *phy_info, *phys; 245 int i, count; 246 247 phys = bxt_get_phy_list(dev_priv, &count); 248 249 for (i = 0; i < count; i++) { 250 phy_info = &phys[i]; 251 252 if (port == phy_info->channel[DPIO_CH0].port) { 253 *phy = i; 254 *ch = DPIO_CH0; 255 return; 256 } 257 258 if (phy_info->dual_channel && 259 port == phy_info->channel[DPIO_CH1].port) { 260 *phy = i; 261 *ch = DPIO_CH1; 262 return; 263 } 264 } 265 266 drm_WARN(&dev_priv->drm, 1, "PHY not found for PORT %c", 267 port_name(port)); 268 *phy = DPIO_PHY0; 269 *ch = DPIO_CH0; 270 } 271 272 void bxt_ddi_phy_set_signal_levels(struct intel_encoder *encoder, 273 const struct intel_crtc_state *crtc_state) 274 { 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; 279 enum dpio_phy phy; 280 int n_entries; 281 u32 val; 282 283 trans = encoder->get_buf_trans(encoder, crtc_state, &n_entries); 284 if (drm_WARN_ON_ONCE(&dev_priv->drm, !trans)) 285 return; 286 287 bxt_port_to_phy_channel(dev_priv, encoder->port, &phy, &ch); 288 289 /* 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. 292 */ 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); 296 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); 302 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; 307 308 if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD)) 309 drm_err(&dev_priv->drm, 310 "Disabled scaling while ouniqetrangenmethod was set"); 311 312 intel_de_write(dev_priv, BXT_PORT_TX_DW3_GRP(phy, ch), val); 313 314 val = intel_de_read(dev_priv, BXT_PORT_TX_DW4_LN0(phy, ch)); 315 val &= ~DE_EMPHASIS; 316 val |= trans->entries[level].bxt.deemphasis << DEEMPH_SHIFT; 317 intel_de_write(dev_priv, BXT_PORT_TX_DW4_GRP(phy, ch), val); 318 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); 322 } 323 324 bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv, 325 enum dpio_phy phy) 326 { 327 const struct bxt_ddi_phy_info *phy_info; 328 329 phy_info = bxt_get_phy_info(dev_priv, phy); 330 331 if (!(intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON) & phy_info->pwron_mask)) 332 return false; 333 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); 338 339 return false; 340 } 341 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); 345 346 return false; 347 } 348 349 return true; 350 } 351 352 static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy) 353 { 354 u32 val = intel_de_read(dev_priv, BXT_PORT_REF_DW6(phy)); 355 356 return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT; 357 } 358 359 static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv, 360 enum dpio_phy phy) 361 { 362 if (intel_de_wait_for_set(dev_priv, BXT_PORT_REF_DW3(phy), 363 GRC_DONE, 10)) 364 drm_err(&dev_priv->drm, "timeout waiting for PHY%d GRC\n", 365 phy); 366 } 367 368 static void _bxt_ddi_phy_init(struct drm_i915_private *dev_priv, 369 enum dpio_phy phy) 370 { 371 const struct bxt_ddi_phy_info *phy_info; 372 u32 val; 373 374 phy_info = bxt_get_phy_info(dev_priv, phy); 375 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); 380 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); 384 return; 385 } 386 387 drm_dbg(&dev_priv->drm, 388 "DDI PHY %d enabled with invalid state, " 389 "force reprogramming it\n", phy); 390 } 391 392 intel_de_rmw(dev_priv, BXT_P_CR_GT_DISP_PWRON, 0, phy_info->pwron_mask); 393 394 /* 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. 401 */ 402 if (intel_de_wait_fw(dev_priv, BXT_PORT_CL1CM_DW0(phy), 403 PHY_RESERVED | PHY_POWER_GOOD, PHY_POWER_GOOD, 1)) 404 drm_err(&dev_priv->drm, "timeout during PHY%d power on\n", 405 phy); 406 407 /* Program PLL Rcomp code offset */ 408 intel_de_rmw(dev_priv, BXT_PORT_CL1CM_DW9(phy), IREF0RC_OFFSET_MASK, 409 0xE4 << IREF0RC_OFFSET_SHIFT); 410 411 intel_de_rmw(dev_priv, BXT_PORT_CL1CM_DW10(phy), IREF1RC_OFFSET_MASK, 412 0xE4 << IREF1RC_OFFSET_SHIFT); 413 414 /* Program power gating */ 415 intel_de_rmw(dev_priv, BXT_PORT_CL1CM_DW28(phy), 0, 416 OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG); 417 418 if (phy_info->dual_channel) 419 intel_de_rmw(dev_priv, BXT_PORT_CL2CM_DW6(phy), 0, 420 DW6_OLDO_DYN_PWR_DOWN_EN); 421 422 if (phy_info->rcomp_phy != -1) { 423 u32 grc_code; 424 425 bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy); 426 427 /* 428 * PHY0 isn't connected to an RCOMP resistor so copy over 429 * the corresponding calibrated value from PHY1, and disable 430 * the automatic calibration on PHY0. 431 */ 432 val = bxt_get_grc(dev_priv, phy_info->rcomp_phy); 433 dev_priv->display.state.bxt_phy_grc = val; 434 435 grc_code = val << GRC_CODE_FAST_SHIFT | 436 val << GRC_CODE_SLOW_SHIFT | 437 val; 438 intel_de_write(dev_priv, BXT_PORT_REF_DW6(phy), grc_code); 439 intel_de_rmw(dev_priv, BXT_PORT_REF_DW8(phy), 440 0, GRC_DIS | GRC_RDY_OVRD); 441 } 442 443 if (phy_info->reset_delay) 444 udelay(phy_info->reset_delay); 445 446 intel_de_rmw(dev_priv, BXT_PHY_CTL_FAMILY(phy), 0, COMMON_RESET_DIS); 447 } 448 449 void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy) 450 { 451 const struct bxt_ddi_phy_info *phy_info; 452 453 phy_info = bxt_get_phy_info(dev_priv, phy); 454 455 intel_de_rmw(dev_priv, BXT_PHY_CTL_FAMILY(phy), COMMON_RESET_DIS, 0); 456 457 intel_de_rmw(dev_priv, BXT_P_CR_GT_DISP_PWRON, phy_info->pwron_mask, 0); 458 } 459 460 void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy) 461 { 462 const struct bxt_ddi_phy_info *phy_info = 463 bxt_get_phy_info(dev_priv, phy); 464 enum dpio_phy rcomp_phy = phy_info->rcomp_phy; 465 bool was_enabled; 466 467 lockdep_assert_held(&dev_priv->display.power.domains.lock); 468 469 was_enabled = true; 470 if (rcomp_phy != -1) 471 was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy); 472 473 /* 474 * We need to copy the GRC calibration value from rcomp_phy, 475 * so make sure it's powered up. 476 */ 477 if (!was_enabled) 478 _bxt_ddi_phy_init(dev_priv, rcomp_phy); 479 480 _bxt_ddi_phy_init(dev_priv, phy); 481 482 if (!was_enabled) 483 bxt_ddi_phy_uninit(dev_priv, rcomp_phy); 484 } 485 486 static bool __printf(6, 7) 487 __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy, 488 i915_reg_t reg, u32 mask, u32 expected, 489 const char *reg_fmt, ...) 490 { 491 struct va_format vaf; 492 va_list args; 493 u32 val; 494 495 val = intel_de_read(dev_priv, reg); 496 if ((val & mask) == expected) 497 return true; 498 499 va_start(args, reg_fmt); 500 vaf.fmt = reg_fmt; 501 vaf.va = &args; 502 503 drm_dbg(&dev_priv->drm, "DDI PHY %d reg %pV [%08x] state mismatch: " 504 "current %08x, expected %08x (mask %08x)\n", 505 phy, &vaf, reg.reg, val, (val & ~mask) | expected, 506 mask); 507 508 va_end(args); 509 510 return false; 511 } 512 513 bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv, 514 enum dpio_phy phy) 515 { 516 const struct bxt_ddi_phy_info *phy_info; 517 u32 mask; 518 bool ok; 519 520 phy_info = bxt_get_phy_info(dev_priv, phy); 521 522 #define _CHK(reg, mask, exp, fmt, ...) \ 523 __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \ 524 ## __VA_ARGS__) 525 526 if (!bxt_ddi_phy_is_enabled(dev_priv, phy)) 527 return false; 528 529 ok = true; 530 531 /* PLL Rcomp code offset */ 532 ok &= _CHK(BXT_PORT_CL1CM_DW9(phy), 533 IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT, 534 "BXT_PORT_CL1CM_DW9(%d)", phy); 535 ok &= _CHK(BXT_PORT_CL1CM_DW10(phy), 536 IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT, 537 "BXT_PORT_CL1CM_DW10(%d)", phy); 538 539 /* Power gating */ 540 mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG; 541 ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask, 542 "BXT_PORT_CL1CM_DW28(%d)", phy); 543 544 if (phy_info->dual_channel) 545 ok &= _CHK(BXT_PORT_CL2CM_DW6(phy), 546 DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN, 547 "BXT_PORT_CL2CM_DW6(%d)", phy); 548 549 if (phy_info->rcomp_phy != -1) { 550 u32 grc_code = dev_priv->display.state.bxt_phy_grc; 551 552 grc_code = grc_code << GRC_CODE_FAST_SHIFT | 553 grc_code << GRC_CODE_SLOW_SHIFT | 554 grc_code; 555 mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK | 556 GRC_CODE_NOM_MASK; 557 ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code, 558 "BXT_PORT_REF_DW6(%d)", phy); 559 560 mask = GRC_DIS | GRC_RDY_OVRD; 561 ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask, 562 "BXT_PORT_REF_DW8(%d)", phy); 563 } 564 565 return ok; 566 #undef _CHK 567 } 568 569 u8 570 bxt_ddi_phy_calc_lane_lat_optim_mask(u8 lane_count) 571 { 572 switch (lane_count) { 573 case 1: 574 return 0; 575 case 2: 576 return BIT(2) | BIT(0); 577 case 4: 578 return BIT(3) | BIT(2) | BIT(0); 579 default: 580 MISSING_CASE(lane_count); 581 582 return 0; 583 } 584 } 585 586 void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder, 587 u8 lane_lat_optim_mask) 588 { 589 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 590 enum port port = encoder->port; 591 enum dpio_phy phy; 592 enum dpio_channel ch; 593 int lane; 594 595 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch); 596 597 for (lane = 0; lane < 4; lane++) { 598 u32 val = intel_de_read(dev_priv, 599 BXT_PORT_TX_DW14_LN(phy, ch, lane)); 600 601 /* 602 * Note that on CHV this flag is called UPAR, but has 603 * the same function. 604 */ 605 val &= ~LATENCY_OPTIM; 606 if (lane_lat_optim_mask & BIT(lane)) 607 val |= LATENCY_OPTIM; 608 609 intel_de_write(dev_priv, BXT_PORT_TX_DW14_LN(phy, ch, lane), 610 val); 611 } 612 } 613 614 u8 615 bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder) 616 { 617 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 618 enum port port = encoder->port; 619 enum dpio_phy phy; 620 enum dpio_channel ch; 621 int lane; 622 u8 mask; 623 624 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch); 625 626 mask = 0; 627 for (lane = 0; lane < 4; lane++) { 628 u32 val = intel_de_read(dev_priv, 629 BXT_PORT_TX_DW14_LN(phy, ch, lane)); 630 631 if (val & LATENCY_OPTIM) 632 mask |= BIT(lane); 633 } 634 635 return mask; 636 } 637 638 enum dpio_channel vlv_dig_port_to_channel(struct intel_digital_port *dig_port) 639 { 640 switch (dig_port->base.port) { 641 default: 642 MISSING_CASE(dig_port->base.port); 643 fallthrough; 644 case PORT_B: 645 case PORT_D: 646 return DPIO_CH0; 647 case PORT_C: 648 return DPIO_CH1; 649 } 650 } 651 652 enum dpio_phy vlv_dig_port_to_phy(struct intel_digital_port *dig_port) 653 { 654 switch (dig_port->base.port) { 655 default: 656 MISSING_CASE(dig_port->base.port); 657 fallthrough; 658 case PORT_B: 659 case PORT_C: 660 return DPIO_PHY0; 661 case PORT_D: 662 return DPIO_PHY1; 663 } 664 } 665 666 enum dpio_phy vlv_pipe_to_phy(enum pipe pipe) 667 { 668 switch (pipe) { 669 default: 670 MISSING_CASE(pipe); 671 fallthrough; 672 case PIPE_A: 673 case PIPE_B: 674 return DPIO_PHY0; 675 case PIPE_C: 676 return DPIO_PHY1; 677 } 678 } 679 680 enum dpio_channel vlv_pipe_to_channel(enum pipe pipe) 681 { 682 switch (pipe) { 683 default: 684 MISSING_CASE(pipe); 685 fallthrough; 686 case PIPE_A: 687 case PIPE_C: 688 return DPIO_CH0; 689 case PIPE_B: 690 return DPIO_CH1; 691 } 692 } 693 694 void chv_set_phy_signal_level(struct intel_encoder *encoder, 695 const struct intel_crtc_state *crtc_state, 696 u32 deemph_reg_value, u32 margin_reg_value, 697 bool uniq_trans_scale) 698 { 699 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 700 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 701 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 702 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port); 703 enum dpio_phy phy = vlv_pipe_to_phy(crtc->pipe); 704 u32 val; 705 int i; 706 707 vlv_dpio_get(dev_priv); 708 709 /* Clear calc init */ 710 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW10(ch)); 711 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3); 712 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK); 713 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5; 714 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW10(ch), val); 715 716 if (crtc_state->lane_count > 2) { 717 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW10(ch)); 718 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3); 719 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK); 720 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5; 721 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW10(ch), val); 722 } 723 724 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW9(ch)); 725 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK); 726 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000; 727 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW9(ch), val); 728 729 if (crtc_state->lane_count > 2) { 730 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW9(ch)); 731 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK); 732 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000; 733 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW9(ch), val); 734 } 735 736 /* Program swing deemph */ 737 for (i = 0; i < crtc_state->lane_count; i++) { 738 val = vlv_dpio_read(dev_priv, phy, CHV_TX_DW4(ch, i)); 739 val &= ~DPIO_SWING_DEEMPH9P5_MASK; 740 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT; 741 vlv_dpio_write(dev_priv, phy, CHV_TX_DW4(ch, i), val); 742 } 743 744 /* Program swing margin */ 745 for (i = 0; i < crtc_state->lane_count; i++) { 746 val = vlv_dpio_read(dev_priv, phy, CHV_TX_DW2(ch, i)); 747 748 val &= ~DPIO_SWING_MARGIN000_MASK; 749 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT; 750 751 /* 752 * Supposedly this value shouldn't matter when unique transition 753 * scale is disabled, but in fact it does matter. Let's just 754 * always program the same value and hope it's OK. 755 */ 756 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT); 757 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT; 758 759 vlv_dpio_write(dev_priv, phy, CHV_TX_DW2(ch, i), val); 760 } 761 762 /* 763 * The document said it needs to set bit 27 for ch0 and bit 26 764 * for ch1. Might be a typo in the doc. 765 * For now, for this unique transition scale selection, set bit 766 * 27 for ch0 and ch1. 767 */ 768 for (i = 0; i < crtc_state->lane_count; i++) { 769 val = vlv_dpio_read(dev_priv, phy, CHV_TX_DW3(ch, i)); 770 if (uniq_trans_scale) 771 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN; 772 else 773 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN; 774 vlv_dpio_write(dev_priv, phy, CHV_TX_DW3(ch, i), val); 775 } 776 777 /* Start swing calculation */ 778 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW10(ch)); 779 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3; 780 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW10(ch), val); 781 782 if (crtc_state->lane_count > 2) { 783 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW10(ch)); 784 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3; 785 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW10(ch), val); 786 } 787 788 vlv_dpio_put(dev_priv); 789 } 790 791 void chv_data_lane_soft_reset(struct intel_encoder *encoder, 792 const struct intel_crtc_state *crtc_state, 793 bool reset) 794 { 795 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 796 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 797 enum dpio_channel ch = vlv_dig_port_to_channel(enc_to_dig_port(encoder)); 798 enum dpio_phy phy = vlv_pipe_to_phy(crtc->pipe); 799 u32 val; 800 801 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW0(ch)); 802 if (reset) 803 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET); 804 else 805 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET; 806 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW0(ch), val); 807 808 if (crtc_state->lane_count > 2) { 809 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW0(ch)); 810 if (reset) 811 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET); 812 else 813 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET; 814 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW0(ch), val); 815 } 816 817 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW1(ch)); 818 val |= CHV_PCS_REQ_SOFTRESET_EN; 819 if (reset) 820 val &= ~DPIO_PCS_CLK_SOFT_RESET; 821 else 822 val |= DPIO_PCS_CLK_SOFT_RESET; 823 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW1(ch), val); 824 825 if (crtc_state->lane_count > 2) { 826 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW1(ch)); 827 val |= CHV_PCS_REQ_SOFTRESET_EN; 828 if (reset) 829 val &= ~DPIO_PCS_CLK_SOFT_RESET; 830 else 831 val |= DPIO_PCS_CLK_SOFT_RESET; 832 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW1(ch), val); 833 } 834 } 835 836 void chv_phy_pre_pll_enable(struct intel_encoder *encoder, 837 const struct intel_crtc_state *crtc_state) 838 { 839 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 840 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 841 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 842 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port); 843 enum dpio_phy phy = vlv_pipe_to_phy(crtc->pipe); 844 enum pipe pipe = crtc->pipe; 845 unsigned int lane_mask = 846 intel_dp_unused_lane_mask(crtc_state->lane_count); 847 u32 val; 848 849 /* 850 * Must trick the second common lane into life. 851 * Otherwise we can't even access the PLL. 852 */ 853 if (ch == DPIO_CH0 && pipe == PIPE_B) 854 dig_port->release_cl2_override = 855 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true); 856 857 chv_phy_powergate_lanes(encoder, true, lane_mask); 858 859 vlv_dpio_get(dev_priv); 860 861 /* Assert data lane reset */ 862 chv_data_lane_soft_reset(encoder, crtc_state, true); 863 864 /* program left/right clock distribution */ 865 if (pipe != PIPE_B) { 866 val = vlv_dpio_read(dev_priv, phy, _CHV_CMN_DW5_CH0); 867 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); 868 if (ch == DPIO_CH0) 869 val |= CHV_BUFLEFTENA1_FORCE; 870 if (ch == DPIO_CH1) 871 val |= CHV_BUFRIGHTENA1_FORCE; 872 vlv_dpio_write(dev_priv, phy, _CHV_CMN_DW5_CH0, val); 873 } else { 874 val = vlv_dpio_read(dev_priv, phy, _CHV_CMN_DW1_CH1); 875 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); 876 if (ch == DPIO_CH0) 877 val |= CHV_BUFLEFTENA2_FORCE; 878 if (ch == DPIO_CH1) 879 val |= CHV_BUFRIGHTENA2_FORCE; 880 vlv_dpio_write(dev_priv, phy, _CHV_CMN_DW1_CH1, val); 881 } 882 883 /* program clock channel usage */ 884 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW8(ch)); 885 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE; 886 if (pipe != PIPE_B) 887 val &= ~CHV_PCS_USEDCLKCHANNEL; 888 else 889 val |= CHV_PCS_USEDCLKCHANNEL; 890 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW8(ch), val); 891 892 if (crtc_state->lane_count > 2) { 893 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW8(ch)); 894 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE; 895 if (pipe != PIPE_B) 896 val &= ~CHV_PCS_USEDCLKCHANNEL; 897 else 898 val |= CHV_PCS_USEDCLKCHANNEL; 899 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW8(ch), val); 900 } 901 902 /* 903 * This a a bit weird since generally CL 904 * matches the pipe, but here we need to 905 * pick the CL based on the port. 906 */ 907 val = vlv_dpio_read(dev_priv, phy, CHV_CMN_DW19(ch)); 908 if (pipe != PIPE_B) 909 val &= ~CHV_CMN_USEDCLKCHANNEL; 910 else 911 val |= CHV_CMN_USEDCLKCHANNEL; 912 vlv_dpio_write(dev_priv, phy, CHV_CMN_DW19(ch), val); 913 914 vlv_dpio_put(dev_priv); 915 } 916 917 void chv_phy_pre_encoder_enable(struct intel_encoder *encoder, 918 const struct intel_crtc_state *crtc_state) 919 { 920 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 921 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 922 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 923 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 924 enum dpio_channel ch = vlv_dig_port_to_channel(dig_port); 925 enum dpio_phy phy = vlv_pipe_to_phy(crtc->pipe); 926 int data, i, stagger; 927 u32 val; 928 929 vlv_dpio_get(dev_priv); 930 931 /* allow hardware to manage TX FIFO reset source */ 932 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW11(ch)); 933 val &= ~DPIO_LANEDESKEW_STRAP_OVRD; 934 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW11(ch), val); 935 936 if (crtc_state->lane_count > 2) { 937 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW11(ch)); 938 val &= ~DPIO_LANEDESKEW_STRAP_OVRD; 939 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW11(ch), val); 940 } 941 942 /* Program Tx lane latency optimal setting*/ 943 for (i = 0; i < crtc_state->lane_count; i++) { 944 /* Set the upar bit */ 945 if (crtc_state->lane_count == 1) 946 data = 0x0; 947 else 948 data = (i == 1) ? 0x0 : 0x1; 949 vlv_dpio_write(dev_priv, phy, CHV_TX_DW14(ch, i), 950 data << DPIO_UPAR_SHIFT); 951 } 952 953 /* Data lane stagger programming */ 954 if (crtc_state->port_clock > 270000) 955 stagger = 0x18; 956 else if (crtc_state->port_clock > 135000) 957 stagger = 0xd; 958 else if (crtc_state->port_clock > 67500) 959 stagger = 0x7; 960 else if (crtc_state->port_clock > 33750) 961 stagger = 0x4; 962 else 963 stagger = 0x2; 964 965 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW11(ch)); 966 val |= DPIO_TX2_STAGGER_MASK(0x1f); 967 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW11(ch), val); 968 969 if (crtc_state->lane_count > 2) { 970 val = vlv_dpio_read(dev_priv, phy, VLV_PCS23_DW11(ch)); 971 val |= DPIO_TX2_STAGGER_MASK(0x1f); 972 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW11(ch), val); 973 } 974 975 vlv_dpio_write(dev_priv, phy, VLV_PCS01_DW12(ch), 976 DPIO_LANESTAGGER_STRAP(stagger) | 977 DPIO_LANESTAGGER_STRAP_OVRD | 978 DPIO_TX1_STAGGER_MASK(0x1f) | 979 DPIO_TX1_STAGGER_MULT(6) | 980 DPIO_TX2_STAGGER_MULT(0)); 981 982 if (crtc_state->lane_count > 2) { 983 vlv_dpio_write(dev_priv, phy, VLV_PCS23_DW12(ch), 984 DPIO_LANESTAGGER_STRAP(stagger) | 985 DPIO_LANESTAGGER_STRAP_OVRD | 986 DPIO_TX1_STAGGER_MASK(0x1f) | 987 DPIO_TX1_STAGGER_MULT(7) | 988 DPIO_TX2_STAGGER_MULT(5)); 989 } 990 991 /* Deassert data lane reset */ 992 chv_data_lane_soft_reset(encoder, crtc_state, false); 993 994 vlv_dpio_put(dev_priv); 995 } 996 997 void chv_phy_release_cl2_override(struct intel_encoder *encoder) 998 { 999 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 1000 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1001 1002 if (dig_port->release_cl2_override) { 1003 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false); 1004 dig_port->release_cl2_override = false; 1005 } 1006 } 1007 1008 void chv_phy_post_pll_disable(struct intel_encoder *encoder, 1009 const struct intel_crtc_state *old_crtc_state) 1010 { 1011 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1012 enum pipe pipe = to_intel_crtc(old_crtc_state->uapi.crtc)->pipe; 1013 enum dpio_phy phy = vlv_pipe_to_phy(pipe); 1014 u32 val; 1015 1016 vlv_dpio_get(dev_priv); 1017 1018 /* disable left/right clock distribution */ 1019 if (pipe != PIPE_B) { 1020 val = vlv_dpio_read(dev_priv, phy, _CHV_CMN_DW5_CH0); 1021 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); 1022 vlv_dpio_write(dev_priv, phy, _CHV_CMN_DW5_CH0, val); 1023 } else { 1024 val = vlv_dpio_read(dev_priv, phy, _CHV_CMN_DW1_CH1); 1025 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); 1026 vlv_dpio_write(dev_priv, phy, _CHV_CMN_DW1_CH1, val); 1027 } 1028 1029 vlv_dpio_put(dev_priv); 1030 1031 /* 1032 * Leave the power down bit cleared for at least one 1033 * lane so that chv_powergate_phy_ch() will power 1034 * on something when the channel is otherwise unused. 1035 * When the port is off and the override is removed 1036 * the lanes power down anyway, so otherwise it doesn't 1037 * really matter what the state of power down bits is 1038 * after this. 1039 */ 1040 chv_phy_powergate_lanes(encoder, false, 0x0); 1041 } 1042 1043 void vlv_set_phy_signal_level(struct intel_encoder *encoder, 1044 const struct intel_crtc_state *crtc_state, 1045 u32 demph_reg_value, u32 preemph_reg_value, 1046 u32 uniqtranscale_reg_value, u32 tx3_demph) 1047 { 1048 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1049 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 1050 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1051 enum dpio_channel port = vlv_dig_port_to_channel(dig_port); 1052 enum dpio_phy phy = vlv_pipe_to_phy(crtc->pipe); 1053 1054 vlv_dpio_get(dev_priv); 1055 1056 vlv_dpio_write(dev_priv, phy, VLV_TX_DW5(port), 0x00000000); 1057 vlv_dpio_write(dev_priv, phy, VLV_TX_DW4(port), demph_reg_value); 1058 vlv_dpio_write(dev_priv, phy, VLV_TX_DW2(port), 1059 uniqtranscale_reg_value); 1060 vlv_dpio_write(dev_priv, phy, VLV_TX_DW3(port), 0x0C782040); 1061 1062 if (tx3_demph) 1063 vlv_dpio_write(dev_priv, phy, VLV_TX3_DW4(port), tx3_demph); 1064 1065 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW11(port), 0x00030000); 1066 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW9(port), preemph_reg_value); 1067 vlv_dpio_write(dev_priv, phy, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN); 1068 1069 vlv_dpio_put(dev_priv); 1070 } 1071 1072 void vlv_phy_pre_pll_enable(struct intel_encoder *encoder, 1073 const struct intel_crtc_state *crtc_state) 1074 { 1075 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 1076 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1077 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1078 enum dpio_channel port = vlv_dig_port_to_channel(dig_port); 1079 enum dpio_phy phy = vlv_pipe_to_phy(crtc->pipe); 1080 1081 /* Program Tx lane resets to default */ 1082 vlv_dpio_get(dev_priv); 1083 1084 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW0(port), 1085 DPIO_PCS_TX_LANE2_RESET | 1086 DPIO_PCS_TX_LANE1_RESET); 1087 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW1(port), 1088 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN | 1089 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN | 1090 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) | 1091 DPIO_PCS_CLK_SOFT_RESET); 1092 1093 /* Fix up inter-pair skew failure */ 1094 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW12(port), 0x00750f00); 1095 vlv_dpio_write(dev_priv, phy, VLV_TX_DW11(port), 0x00001500); 1096 vlv_dpio_write(dev_priv, phy, VLV_TX_DW14(port), 0x40400000); 1097 1098 vlv_dpio_put(dev_priv); 1099 } 1100 1101 void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder, 1102 const struct intel_crtc_state *crtc_state) 1103 { 1104 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1105 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 1106 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1107 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1108 enum dpio_channel port = vlv_dig_port_to_channel(dig_port); 1109 enum pipe pipe = crtc->pipe; 1110 enum dpio_phy phy = vlv_pipe_to_phy(pipe); 1111 u32 val; 1112 1113 vlv_dpio_get(dev_priv); 1114 1115 /* Enable clock channels for this port */ 1116 val = vlv_dpio_read(dev_priv, phy, VLV_PCS01_DW8(port)); 1117 val = 0; 1118 if (pipe) 1119 val |= (1<<21); 1120 else 1121 val &= ~(1<<21); 1122 val |= 0x001000c4; 1123 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW8(port), val); 1124 1125 /* Program lane clock */ 1126 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW14(port), 0x00760018); 1127 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW23(port), 0x00400888); 1128 1129 vlv_dpio_put(dev_priv); 1130 } 1131 1132 void vlv_phy_reset_lanes(struct intel_encoder *encoder, 1133 const struct intel_crtc_state *old_crtc_state) 1134 { 1135 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 1136 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1137 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 1138 enum dpio_channel port = vlv_dig_port_to_channel(dig_port); 1139 enum dpio_phy phy = vlv_pipe_to_phy(crtc->pipe); 1140 1141 vlv_dpio_get(dev_priv); 1142 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW0(port), 0x00000000); 1143 vlv_dpio_write(dev_priv, phy, VLV_PCS_DW1(port), 0x00e00060); 1144 vlv_dpio_put(dev_priv); 1145 } 1146