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