1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "intel_drv.h"
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120struct bxt_ddi_phy_info {
121
122
123
124 bool dual_channel;
125
126
127
128
129
130
131 enum dpio_phy rcomp_phy;
132
133
134
135
136
137 int reset_delay;
138
139
140
141
142
143 u32 pwron_mask;
144
145
146
147
148 struct {
149
150
151
152 enum port port;
153 } channel[2];
154};
155
156static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = {
157 [DPIO_PHY0] = {
158 .dual_channel = true,
159 .rcomp_phy = DPIO_PHY1,
160 .pwron_mask = BIT(0),
161
162 .channel = {
163 [DPIO_CH0] = { .port = PORT_B },
164 [DPIO_CH1] = { .port = PORT_C },
165 }
166 },
167 [DPIO_PHY1] = {
168 .dual_channel = false,
169 .rcomp_phy = -1,
170 .pwron_mask = BIT(1),
171
172 .channel = {
173 [DPIO_CH0] = { .port = PORT_A },
174 }
175 },
176};
177
178static const struct bxt_ddi_phy_info glk_ddi_phy_info[] = {
179 [DPIO_PHY0] = {
180 .dual_channel = false,
181 .rcomp_phy = DPIO_PHY1,
182 .pwron_mask = BIT(0),
183 .reset_delay = 20,
184
185 .channel = {
186 [DPIO_CH0] = { .port = PORT_B },
187 }
188 },
189 [DPIO_PHY1] = {
190 .dual_channel = false,
191 .rcomp_phy = -1,
192 .pwron_mask = BIT(3),
193 .reset_delay = 20,
194
195 .channel = {
196 [DPIO_CH0] = { .port = PORT_A },
197 }
198 },
199 [DPIO_PHY2] = {
200 .dual_channel = false,
201 .rcomp_phy = DPIO_PHY1,
202 .pwron_mask = BIT(1),
203 .reset_delay = 20,
204
205 .channel = {
206 [DPIO_CH0] = { .port = PORT_C },
207 }
208 },
209};
210
211static const struct bxt_ddi_phy_info *
212bxt_get_phy_list(struct drm_i915_private *dev_priv, int *count)
213{
214 if (IS_GEMINILAKE(dev_priv)) {
215 *count = ARRAY_SIZE(glk_ddi_phy_info);
216 return glk_ddi_phy_info;
217 } else {
218 *count = ARRAY_SIZE(bxt_ddi_phy_info);
219 return bxt_ddi_phy_info;
220 }
221}
222
223static const struct bxt_ddi_phy_info *
224bxt_get_phy_info(struct drm_i915_private *dev_priv, enum dpio_phy phy)
225{
226 int count;
227 const struct bxt_ddi_phy_info *phy_list =
228 bxt_get_phy_list(dev_priv, &count);
229
230 return &phy_list[phy];
231}
232
233void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
234 enum dpio_phy *phy, enum dpio_channel *ch)
235{
236 const struct bxt_ddi_phy_info *phy_info, *phys;
237 int i, count;
238
239 phys = bxt_get_phy_list(dev_priv, &count);
240
241 for (i = 0; i < count; i++) {
242 phy_info = &phys[i];
243
244 if (port == phy_info->channel[DPIO_CH0].port) {
245 *phy = i;
246 *ch = DPIO_CH0;
247 return;
248 }
249
250 if (phy_info->dual_channel &&
251 port == phy_info->channel[DPIO_CH1].port) {
252 *phy = i;
253 *ch = DPIO_CH1;
254 return;
255 }
256 }
257
258 WARN(1, "PHY not found for PORT %c", port_name(port));
259 *phy = DPIO_PHY0;
260 *ch = DPIO_CH0;
261}
262
263void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
264 enum port port, u32 margin, u32 scale,
265 u32 enable, u32 deemphasis)
266{
267 u32 val;
268 enum dpio_phy phy;
269 enum dpio_channel ch;
270
271 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
272
273
274
275
276
277 val = I915_READ(BXT_PORT_PCS_DW10_LN01(phy, ch));
278 val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
279 I915_WRITE(BXT_PORT_PCS_DW10_GRP(phy, ch), val);
280
281 val = I915_READ(BXT_PORT_TX_DW2_LN0(phy, ch));
282 val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
283 val |= margin << MARGIN_000_SHIFT | scale << UNIQ_TRANS_SCALE_SHIFT;
284 I915_WRITE(BXT_PORT_TX_DW2_GRP(phy, ch), val);
285
286 val = I915_READ(BXT_PORT_TX_DW3_LN0(phy, ch));
287 val &= ~SCALE_DCOMP_METHOD;
288 if (enable)
289 val |= SCALE_DCOMP_METHOD;
290
291 if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
292 DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set");
293
294 I915_WRITE(BXT_PORT_TX_DW3_GRP(phy, ch), val);
295
296 val = I915_READ(BXT_PORT_TX_DW4_LN0(phy, ch));
297 val &= ~DE_EMPHASIS;
298 val |= deemphasis << DEEMPH_SHIFT;
299 I915_WRITE(BXT_PORT_TX_DW4_GRP(phy, ch), val);
300
301 val = I915_READ(BXT_PORT_PCS_DW10_LN01(phy, ch));
302 val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
303 I915_WRITE(BXT_PORT_PCS_DW10_GRP(phy, ch), val);
304}
305
306bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
307 enum dpio_phy phy)
308{
309 const struct bxt_ddi_phy_info *phy_info;
310
311 phy_info = bxt_get_phy_info(dev_priv, phy);
312
313 if (!(I915_READ(BXT_P_CR_GT_DISP_PWRON) & phy_info->pwron_mask))
314 return false;
315
316 if ((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
317 (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
318 DRM_DEBUG_DRIVER("DDI PHY %d powered, but power hasn't settled\n",
319 phy);
320
321 return false;
322 }
323
324 if (!(I915_READ(BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
325 DRM_DEBUG_DRIVER("DDI PHY %d powered, but still in reset\n",
326 phy);
327
328 return false;
329 }
330
331 return true;
332}
333
334static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
335{
336 u32 val = I915_READ(BXT_PORT_REF_DW6(phy));
337
338 return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
339}
340
341static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
342 enum dpio_phy phy)
343{
344 if (intel_wait_for_register(dev_priv,
345 BXT_PORT_REF_DW3(phy),
346 GRC_DONE, GRC_DONE,
347 10))
348 DRM_ERROR("timeout waiting for PHY%d GRC\n", phy);
349}
350
351static void _bxt_ddi_phy_init(struct drm_i915_private *dev_priv,
352 enum dpio_phy phy)
353{
354 const struct bxt_ddi_phy_info *phy_info;
355 u32 val;
356
357 phy_info = bxt_get_phy_info(dev_priv, phy);
358
359 if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
360
361 if (phy_info->rcomp_phy != -1)
362 dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy);
363
364 if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
365 DRM_DEBUG_DRIVER("DDI PHY %d already enabled, "
366 "won't reprogram it\n", phy);
367 return;
368 }
369
370 DRM_DEBUG_DRIVER("DDI PHY %d enabled with invalid state, "
371 "force reprogramming it\n", phy);
372 }
373
374 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
375 val |= phy_info->pwron_mask;
376 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
377
378
379
380
381
382
383
384
385
386 if (intel_wait_for_register_fw(dev_priv, BXT_PORT_CL1CM_DW0(phy),
387 PHY_RESERVED | PHY_POWER_GOOD,
388 PHY_POWER_GOOD,
389 1))
390 DRM_ERROR("timeout during PHY%d power on\n", phy);
391
392
393 val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
394 val &= ~IREF0RC_OFFSET_MASK;
395 val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
396 I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
397
398 val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
399 val &= ~IREF1RC_OFFSET_MASK;
400 val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
401 I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
402
403
404 val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
405 val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
406 SUS_CLK_CONFIG;
407 I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
408
409 if (phy_info->dual_channel) {
410 val = I915_READ(BXT_PORT_CL2CM_DW6(phy));
411 val |= DW6_OLDO_DYN_PWR_DOWN_EN;
412 I915_WRITE(BXT_PORT_CL2CM_DW6(phy), val);
413 }
414
415 if (phy_info->rcomp_phy != -1) {
416 u32 grc_code;
417
418 bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy);
419
420
421
422
423
424
425 val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv,
426 phy_info->rcomp_phy);
427 grc_code = val << GRC_CODE_FAST_SHIFT |
428 val << GRC_CODE_SLOW_SHIFT |
429 val;
430 I915_WRITE(BXT_PORT_REF_DW6(phy), grc_code);
431
432 val = I915_READ(BXT_PORT_REF_DW8(phy));
433 val |= GRC_DIS | GRC_RDY_OVRD;
434 I915_WRITE(BXT_PORT_REF_DW8(phy), val);
435 }
436
437 if (phy_info->reset_delay)
438 udelay(phy_info->reset_delay);
439
440 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
441 val |= COMMON_RESET_DIS;
442 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
443}
444
445void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
446{
447 const struct bxt_ddi_phy_info *phy_info;
448 u32 val;
449
450 phy_info = bxt_get_phy_info(dev_priv, phy);
451
452 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
453 val &= ~COMMON_RESET_DIS;
454 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
455
456 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
457 val &= ~phy_info->pwron_mask;
458 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
459}
460
461void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
462{
463 const struct bxt_ddi_phy_info *phy_info =
464 bxt_get_phy_info(dev_priv, phy);
465 enum dpio_phy rcomp_phy = phy_info->rcomp_phy;
466 bool was_enabled;
467
468 lockdep_assert_held(&dev_priv->power_domains.lock);
469
470 was_enabled = true;
471 if (rcomp_phy != -1)
472 was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
473
474
475
476
477
478 if (!was_enabled)
479 _bxt_ddi_phy_init(dev_priv, rcomp_phy);
480
481 _bxt_ddi_phy_init(dev_priv, phy);
482
483 if (!was_enabled)
484 bxt_ddi_phy_uninit(dev_priv, rcomp_phy);
485}
486
487static bool __printf(6, 7)
488__phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
489 i915_reg_t reg, u32 mask, u32 expected,
490 const char *reg_fmt, ...)
491{
492 struct va_format vaf;
493 va_list args;
494 u32 val;
495
496 val = I915_READ(reg);
497 if ((val & mask) == expected)
498 return true;
499
500 va_start(args, reg_fmt);
501 vaf.fmt = reg_fmt;
502 vaf.va = &args;
503
504 DRM_DEBUG_DRIVER("DDI PHY %d reg %pV [%08x] state mismatch: "
505 "current %08x, expected %08x (mask %08x)\n",
506 phy, &vaf, reg.reg, val, (val & ~mask) | expected,
507 mask);
508
509 va_end(args);
510
511 return false;
512}
513
514bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
515 enum dpio_phy phy)
516{
517 const struct bxt_ddi_phy_info *phy_info;
518 u32 mask;
519 bool ok;
520
521 phy_info = bxt_get_phy_info(dev_priv, phy);
522
523#define _CHK(reg, mask, exp, fmt, ...) \
524 __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
525 ## __VA_ARGS__)
526
527 if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
528 return false;
529
530 ok = true;
531
532
533 ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
534 IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
535 "BXT_PORT_CL1CM_DW9(%d)", phy);
536 ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
537 IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
538 "BXT_PORT_CL1CM_DW10(%d)", phy);
539
540
541 mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
542 ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
543 "BXT_PORT_CL1CM_DW28(%d)", phy);
544
545 if (phy_info->dual_channel)
546 ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
547 DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
548 "BXT_PORT_CL2CM_DW6(%d)", phy);
549
550 if (phy_info->rcomp_phy != -1) {
551 u32 grc_code = dev_priv->bxt_phy_grc;
552
553 grc_code = grc_code << GRC_CODE_FAST_SHIFT |
554 grc_code << GRC_CODE_SLOW_SHIFT |
555 grc_code;
556 mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
557 GRC_CODE_NOM_MASK;
558 ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code,
559 "BXT_PORT_REF_DW6(%d)", phy);
560
561 mask = GRC_DIS | GRC_RDY_OVRD;
562 ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask,
563 "BXT_PORT_REF_DW8(%d)", phy);
564 }
565
566 return ok;
567#undef _CHK
568}
569
570u8
571bxt_ddi_phy_calc_lane_lat_optim_mask(u8 lane_count)
572{
573 switch (lane_count) {
574 case 1:
575 return 0;
576 case 2:
577 return BIT(2) | BIT(0);
578 case 4:
579 return BIT(3) | BIT(2) | BIT(0);
580 default:
581 MISSING_CASE(lane_count);
582
583 return 0;
584 }
585}
586
587void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
588 u8 lane_lat_optim_mask)
589{
590 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
591 enum port port = encoder->port;
592 enum dpio_phy phy;
593 enum dpio_channel ch;
594 int lane;
595
596 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
597
598 for (lane = 0; lane < 4; lane++) {
599 u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
600
601
602
603
604
605 val &= ~LATENCY_OPTIM;
606 if (lane_lat_optim_mask & BIT(lane))
607 val |= LATENCY_OPTIM;
608
609 I915_WRITE(BXT_PORT_TX_DW14_LN(phy, ch, lane), val);
610 }
611}
612
613u8
614bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
615{
616 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
617 enum port port = encoder->port;
618 enum dpio_phy phy;
619 enum dpio_channel ch;
620 int lane;
621 u8 mask;
622
623 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
624
625 mask = 0;
626 for (lane = 0; lane < 4; lane++) {
627 u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
628
629 if (val & LATENCY_OPTIM)
630 mask |= BIT(lane);
631 }
632
633 return mask;
634}
635
636
637void chv_set_phy_signal_level(struct intel_encoder *encoder,
638 u32 deemph_reg_value, u32 margin_reg_value,
639 bool uniq_trans_scale)
640{
641 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
642 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
643 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
644 enum dpio_channel ch = vlv_dport_to_channel(dport);
645 enum pipe pipe = intel_crtc->pipe;
646 u32 val;
647 int i;
648
649 mutex_lock(&dev_priv->sb_lock);
650
651
652 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
653 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
654 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
655 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
656 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
657
658 if (intel_crtc->config->lane_count > 2) {
659 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
660 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
661 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
662 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
663 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
664 }
665
666 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
667 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
668 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
669 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
670
671 if (intel_crtc->config->lane_count > 2) {
672 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
673 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
674 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
675 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
676 }
677
678
679 for (i = 0; i < intel_crtc->config->lane_count; i++) {
680 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
681 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
682 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
683 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
684 }
685
686
687 for (i = 0; i < intel_crtc->config->lane_count; i++) {
688 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
689
690 val &= ~DPIO_SWING_MARGIN000_MASK;
691 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
692
693
694
695
696
697
698 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
699 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
700
701 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
702 }
703
704
705
706
707
708
709
710 for (i = 0; i < intel_crtc->config->lane_count; i++) {
711 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
712 if (uniq_trans_scale)
713 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
714 else
715 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
716 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
717 }
718
719
720 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
721 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
722 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
723
724 if (intel_crtc->config->lane_count > 2) {
725 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
726 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
727 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
728 }
729
730 mutex_unlock(&dev_priv->sb_lock);
731
732}
733
734void chv_data_lane_soft_reset(struct intel_encoder *encoder,
735 const struct intel_crtc_state *crtc_state,
736 bool reset)
737{
738 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
739 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
740 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
741 enum pipe pipe = crtc->pipe;
742 u32 val;
743
744 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
745 if (reset)
746 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
747 else
748 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
749 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
750
751 if (crtc_state->lane_count > 2) {
752 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
753 if (reset)
754 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
755 else
756 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
757 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
758 }
759
760 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
761 val |= CHV_PCS_REQ_SOFTRESET_EN;
762 if (reset)
763 val &= ~DPIO_PCS_CLK_SOFT_RESET;
764 else
765 val |= DPIO_PCS_CLK_SOFT_RESET;
766 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
767
768 if (crtc_state->lane_count > 2) {
769 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
770 val |= CHV_PCS_REQ_SOFTRESET_EN;
771 if (reset)
772 val &= ~DPIO_PCS_CLK_SOFT_RESET;
773 else
774 val |= DPIO_PCS_CLK_SOFT_RESET;
775 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
776 }
777}
778
779void chv_phy_pre_pll_enable(struct intel_encoder *encoder,
780 const struct intel_crtc_state *crtc_state)
781{
782 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
783 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
784 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
785 enum dpio_channel ch = vlv_dport_to_channel(dport);
786 enum pipe pipe = crtc->pipe;
787 unsigned int lane_mask =
788 intel_dp_unused_lane_mask(crtc_state->lane_count);
789 u32 val;
790
791
792
793
794
795 if (ch == DPIO_CH0 && pipe == PIPE_B)
796 dport->release_cl2_override =
797 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
798
799 chv_phy_powergate_lanes(encoder, true, lane_mask);
800
801 mutex_lock(&dev_priv->sb_lock);
802
803
804 chv_data_lane_soft_reset(encoder, crtc_state, true);
805
806
807 if (pipe != PIPE_B) {
808 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
809 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
810 if (ch == DPIO_CH0)
811 val |= CHV_BUFLEFTENA1_FORCE;
812 if (ch == DPIO_CH1)
813 val |= CHV_BUFRIGHTENA1_FORCE;
814 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
815 } else {
816 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
817 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
818 if (ch == DPIO_CH0)
819 val |= CHV_BUFLEFTENA2_FORCE;
820 if (ch == DPIO_CH1)
821 val |= CHV_BUFRIGHTENA2_FORCE;
822 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
823 }
824
825
826 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
827 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
828 if (pipe != PIPE_B)
829 val &= ~CHV_PCS_USEDCLKCHANNEL;
830 else
831 val |= CHV_PCS_USEDCLKCHANNEL;
832 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
833
834 if (crtc_state->lane_count > 2) {
835 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
836 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
837 if (pipe != PIPE_B)
838 val &= ~CHV_PCS_USEDCLKCHANNEL;
839 else
840 val |= CHV_PCS_USEDCLKCHANNEL;
841 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
842 }
843
844
845
846
847
848
849 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
850 if (pipe != PIPE_B)
851 val &= ~CHV_CMN_USEDCLKCHANNEL;
852 else
853 val |= CHV_CMN_USEDCLKCHANNEL;
854 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
855
856 mutex_unlock(&dev_priv->sb_lock);
857}
858
859void chv_phy_pre_encoder_enable(struct intel_encoder *encoder,
860 const struct intel_crtc_state *crtc_state)
861{
862 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
863 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
864 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
865 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
866 enum dpio_channel ch = vlv_dport_to_channel(dport);
867 enum pipe pipe = crtc->pipe;
868 int data, i, stagger;
869 u32 val;
870
871 mutex_lock(&dev_priv->sb_lock);
872
873
874 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
875 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
876 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
877
878 if (crtc_state->lane_count > 2) {
879 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
880 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
881 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
882 }
883
884
885 for (i = 0; i < crtc_state->lane_count; i++) {
886
887 if (crtc_state->lane_count == 1)
888 data = 0x0;
889 else
890 data = (i == 1) ? 0x0 : 0x1;
891 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
892 data << DPIO_UPAR_SHIFT);
893 }
894
895
896 if (crtc_state->port_clock > 270000)
897 stagger = 0x18;
898 else if (crtc_state->port_clock > 135000)
899 stagger = 0xd;
900 else if (crtc_state->port_clock > 67500)
901 stagger = 0x7;
902 else if (crtc_state->port_clock > 33750)
903 stagger = 0x4;
904 else
905 stagger = 0x2;
906
907 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
908 val |= DPIO_TX2_STAGGER_MASK(0x1f);
909 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
910
911 if (crtc_state->lane_count > 2) {
912 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
913 val |= DPIO_TX2_STAGGER_MASK(0x1f);
914 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
915 }
916
917 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
918 DPIO_LANESTAGGER_STRAP(stagger) |
919 DPIO_LANESTAGGER_STRAP_OVRD |
920 DPIO_TX1_STAGGER_MASK(0x1f) |
921 DPIO_TX1_STAGGER_MULT(6) |
922 DPIO_TX2_STAGGER_MULT(0));
923
924 if (crtc_state->lane_count > 2) {
925 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
926 DPIO_LANESTAGGER_STRAP(stagger) |
927 DPIO_LANESTAGGER_STRAP_OVRD |
928 DPIO_TX1_STAGGER_MASK(0x1f) |
929 DPIO_TX1_STAGGER_MULT(7) |
930 DPIO_TX2_STAGGER_MULT(5));
931 }
932
933
934 chv_data_lane_soft_reset(encoder, crtc_state, false);
935
936 mutex_unlock(&dev_priv->sb_lock);
937}
938
939void chv_phy_release_cl2_override(struct intel_encoder *encoder)
940{
941 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
942 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
943
944 if (dport->release_cl2_override) {
945 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
946 dport->release_cl2_override = false;
947 }
948}
949
950void chv_phy_post_pll_disable(struct intel_encoder *encoder,
951 const struct intel_crtc_state *old_crtc_state)
952{
953 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
954 enum pipe pipe = to_intel_crtc(old_crtc_state->base.crtc)->pipe;
955 u32 val;
956
957 mutex_lock(&dev_priv->sb_lock);
958
959
960 if (pipe != PIPE_B) {
961 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
962 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
963 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
964 } else {
965 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
966 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
967 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
968 }
969
970 mutex_unlock(&dev_priv->sb_lock);
971
972
973
974
975
976
977
978
979
980
981 chv_phy_powergate_lanes(encoder, false, 0x0);
982}
983
984void vlv_set_phy_signal_level(struct intel_encoder *encoder,
985 u32 demph_reg_value, u32 preemph_reg_value,
986 u32 uniqtranscale_reg_value, u32 tx3_demph)
987{
988 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
989 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
990 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
991 enum dpio_channel port = vlv_dport_to_channel(dport);
992 enum pipe pipe = intel_crtc->pipe;
993
994 mutex_lock(&dev_priv->sb_lock);
995 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
996 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
997 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
998 uniqtranscale_reg_value);
999 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
1000
1001 if (tx3_demph)
1002 vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
1003
1004 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
1005 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
1006 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
1007 mutex_unlock(&dev_priv->sb_lock);
1008}
1009
1010void vlv_phy_pre_pll_enable(struct intel_encoder *encoder,
1011 const struct intel_crtc_state *crtc_state)
1012{
1013 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1014 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1015 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1016 enum dpio_channel port = vlv_dport_to_channel(dport);
1017 enum pipe pipe = crtc->pipe;
1018
1019
1020 mutex_lock(&dev_priv->sb_lock);
1021 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
1022 DPIO_PCS_TX_LANE2_RESET |
1023 DPIO_PCS_TX_LANE1_RESET);
1024 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
1025 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1026 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1027 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1028 DPIO_PCS_CLK_SOFT_RESET);
1029
1030
1031 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1032 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1033 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
1034 mutex_unlock(&dev_priv->sb_lock);
1035}
1036
1037void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder,
1038 const struct intel_crtc_state *crtc_state)
1039{
1040 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1041 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1042 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1043 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1044 enum dpio_channel port = vlv_dport_to_channel(dport);
1045 enum pipe pipe = crtc->pipe;
1046 u32 val;
1047
1048 mutex_lock(&dev_priv->sb_lock);
1049
1050
1051 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
1052 val = 0;
1053 if (pipe)
1054 val |= (1<<21);
1055 else
1056 val &= ~(1<<21);
1057 val |= 0x001000c4;
1058 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1059
1060
1061 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1062 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
1063
1064 mutex_unlock(&dev_priv->sb_lock);
1065}
1066
1067void vlv_phy_reset_lanes(struct intel_encoder *encoder,
1068 const struct intel_crtc_state *old_crtc_state)
1069{
1070 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1071 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1072 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
1073 enum dpio_channel port = vlv_dport_to_channel(dport);
1074 enum pipe pipe = crtc->pipe;
1075
1076 mutex_lock(&dev_priv->sb_lock);
1077 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
1078 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
1079 mutex_unlock(&dev_priv->sb_lock);
1080}
1081