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