1 /* Copyright 2015 Advanced Micro Devices, Inc. */
2 #include "dm_services.h"
4 #include "dc_link_dp.h"
5 #include "dm_helpers.h"
10 #include "inc/core_types.h"
11 #include "link_hwss.h"
12 #include "dc_link_ddc.h"
13 #include "core_status.h"
14 #include "dpcd_defs.h"
15 #include "dc_dmub_srv.h"
16 #include "dce/dmub_hw_lock_mgr.h"
19 static const uint8_t DP_VGA_LVDS_CONVERTER_ID_2
[] = "sivarT";
21 static const uint8_t DP_VGA_LVDS_CONVERTER_ID_3
[] = "dnomlA";
25 #define DC_TRACE_LEVEL_MESSAGE(...) /* do nothing */
27 #define DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE 0x50
29 /* maximum pre emphasis level allowed for each voltage swing level*/
30 static const enum dc_pre_emphasis
31 voltage_swing_to_pre_emphasis
[] = { PRE_EMPHASIS_LEVEL3
,
34 PRE_EMPHASIS_DISABLED
};
37 POST_LT_ADJ_REQ_LIMIT
= 6,
38 POST_LT_ADJ_REQ_TIMEOUT
= 200
42 LINK_TRAINING_MAX_RETRY_COUNT
= 5,
43 /* to avoid infinite loop where-in the receiver
44 * switches between different VS
46 LINK_TRAINING_MAX_CR_RETRY
= 100
49 static bool decide_fallback_link_setting(
50 struct dc_link_settings initial_link_settings
,
51 struct dc_link_settings
*current_link_setting
,
52 enum link_training_result training_result
);
53 static struct dc_link_settings
get_common_supported_link_settings(
54 struct dc_link_settings link_setting_a
,
55 struct dc_link_settings link_setting_b
);
57 static uint32_t get_cr_training_aux_rd_interval(struct dc_link
*link
,
58 const struct dc_link_settings
*link_settings
)
60 union training_aux_rd_interval training_rd_interval
;
61 uint32_t wait_in_micro_secs
= 100;
63 memset(&training_rd_interval
, 0, sizeof(training_rd_interval
));
66 DP_TRAINING_AUX_RD_INTERVAL
,
67 (uint8_t *)&training_rd_interval
,
68 sizeof(training_rd_interval
));
69 if (training_rd_interval
.bits
.TRAINIG_AUX_RD_INTERVAL
)
70 wait_in_micro_secs
= training_rd_interval
.bits
.TRAINIG_AUX_RD_INTERVAL
* 4000;
71 return wait_in_micro_secs
;
74 static uint32_t get_eq_training_aux_rd_interval(
76 const struct dc_link_settings
*link_settings
)
78 union training_aux_rd_interval training_rd_interval
;
79 uint32_t wait_in_micro_secs
= 400;
81 memset(&training_rd_interval
, 0, sizeof(training_rd_interval
));
82 /* overwrite the delay if rev > 1.1*/
83 if (link
->dpcd_caps
.dpcd_rev
.raw
>= DPCD_REV_12
) {
84 /* DP 1.2 or later - retrieve delay through
85 * "DPCD_ADDR_TRAINING_AUX_RD_INTERVAL" register */
88 DP_TRAINING_AUX_RD_INTERVAL
,
89 (uint8_t *)&training_rd_interval
,
90 sizeof(training_rd_interval
));
92 if (training_rd_interval
.bits
.TRAINIG_AUX_RD_INTERVAL
)
93 wait_in_micro_secs
= training_rd_interval
.bits
.TRAINIG_AUX_RD_INTERVAL
* 4000;
96 return wait_in_micro_secs
;
99 static void wait_for_training_aux_rd_interval(
100 struct dc_link
*link
,
101 uint32_t wait_in_micro_secs
)
103 udelay(wait_in_micro_secs
);
105 DC_LOG_HW_LINK_TRAINING("%s:\n wait = %d\n",
110 static void dpcd_set_training_pattern(
111 struct dc_link
*link
,
112 union dpcd_training_pattern dpcd_pattern
)
114 core_link_write_dpcd(
116 DP_TRAINING_PATTERN_SET
,
120 DC_LOG_HW_LINK_TRAINING("%s\n %x pattern = %x\n",
122 DP_TRAINING_PATTERN_SET
,
123 dpcd_pattern
.v1_4
.TRAINING_PATTERN_SET
);
126 static enum dc_dp_training_pattern
decide_cr_training_pattern(
127 const struct dc_link_settings
*link_settings
)
129 return DP_TRAINING_PATTERN_SEQUENCE_1
;
132 static enum dc_dp_training_pattern
decide_eq_training_pattern(struct dc_link
*link
,
133 const struct dc_link_settings
*link_settings
)
135 enum dc_dp_training_pattern highest_tp
= DP_TRAINING_PATTERN_SEQUENCE_2
;
136 struct encoder_feature_support
*features
= &link
->link_enc
->features
;
137 struct dpcd_caps
*dpcd_caps
= &link
->dpcd_caps
;
139 if (features
->flags
.bits
.IS_TPS3_CAPABLE
)
140 highest_tp
= DP_TRAINING_PATTERN_SEQUENCE_3
;
142 if (features
->flags
.bits
.IS_TPS4_CAPABLE
)
143 highest_tp
= DP_TRAINING_PATTERN_SEQUENCE_4
;
145 if (dpcd_caps
->max_down_spread
.bits
.TPS4_SUPPORTED
&&
146 highest_tp
>= DP_TRAINING_PATTERN_SEQUENCE_4
)
147 return DP_TRAINING_PATTERN_SEQUENCE_4
;
149 if (dpcd_caps
->max_ln_count
.bits
.TPS3_SUPPORTED
&&
150 highest_tp
>= DP_TRAINING_PATTERN_SEQUENCE_3
)
151 return DP_TRAINING_PATTERN_SEQUENCE_3
;
153 return DP_TRAINING_PATTERN_SEQUENCE_2
;
156 static void dpcd_set_link_settings(
157 struct dc_link
*link
,
158 const struct link_training_settings
*lt_settings
)
162 union down_spread_ctrl downspread
= { {0} };
163 union lane_count_set lane_count_set
= { {0} };
165 downspread
.raw
= (uint8_t)
166 (lt_settings
->link_settings
.link_spread
);
168 lane_count_set
.bits
.LANE_COUNT_SET
=
169 lt_settings
->link_settings
.lane_count
;
171 lane_count_set
.bits
.ENHANCED_FRAMING
= lt_settings
->enhanced_framing
;
172 lane_count_set
.bits
.POST_LT_ADJ_REQ_GRANTED
= 0;
175 if (lt_settings
->pattern_for_eq
< DP_TRAINING_PATTERN_SEQUENCE_4
) {
176 lane_count_set
.bits
.POST_LT_ADJ_REQ_GRANTED
=
177 link
->dpcd_caps
.max_ln_count
.bits
.POST_LT_ADJ_REQ_SUPPORTED
;
180 core_link_write_dpcd(link
, DP_DOWNSPREAD_CTRL
,
181 &downspread
.raw
, sizeof(downspread
));
183 core_link_write_dpcd(link
, DP_LANE_COUNT_SET
,
184 &lane_count_set
.raw
, 1);
186 if (link
->dpcd_caps
.dpcd_rev
.raw
>= DPCD_REV_14
&&
187 lt_settings
->link_settings
.use_link_rate_set
== true) {
189 /* WA for some MUX chips that will power down with eDP and lose supported
190 * link rate set for eDP 1.4. Source reads DPCD 0x010 again to ensure
191 * MUX chip gets link rate set back before link training.
193 if (link
->connector_signal
== SIGNAL_TYPE_EDP
) {
194 uint8_t supported_link_rates
[16];
196 core_link_read_dpcd(link
, DP_SUPPORTED_LINK_RATES
,
197 supported_link_rates
, sizeof(supported_link_rates
));
199 core_link_write_dpcd(link
, DP_LINK_BW_SET
, &rate
, 1);
200 core_link_write_dpcd(link
, DP_LINK_RATE_SET
,
201 <_settings
->link_settings
.link_rate_set
, 1);
203 rate
= (uint8_t) (lt_settings
->link_settings
.link_rate
);
204 core_link_write_dpcd(link
, DP_LINK_BW_SET
, &rate
, 1);
208 DC_LOG_HW_LINK_TRAINING("%s\n %x rate = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
211 lt_settings
->link_settings
.link_rate
,
213 lt_settings
->link_settings
.lane_count
,
214 lt_settings
->enhanced_framing
,
216 lt_settings
->link_settings
.link_spread
);
218 DC_LOG_HW_LINK_TRAINING("%s\n %x rate set = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
221 lt_settings
->link_settings
.link_rate_set
,
223 lt_settings
->link_settings
.lane_count
,
224 lt_settings
->enhanced_framing
,
226 lt_settings
->link_settings
.link_spread
);
230 static enum dpcd_training_patterns
231 dc_dp_training_pattern_to_dpcd_training_pattern(
232 struct dc_link
*link
,
233 enum dc_dp_training_pattern pattern
)
235 enum dpcd_training_patterns dpcd_tr_pattern
=
236 DPCD_TRAINING_PATTERN_VIDEOIDLE
;
239 case DP_TRAINING_PATTERN_SEQUENCE_1
:
240 dpcd_tr_pattern
= DPCD_TRAINING_PATTERN_1
;
242 case DP_TRAINING_PATTERN_SEQUENCE_2
:
243 dpcd_tr_pattern
= DPCD_TRAINING_PATTERN_2
;
245 case DP_TRAINING_PATTERN_SEQUENCE_3
:
246 dpcd_tr_pattern
= DPCD_TRAINING_PATTERN_3
;
248 case DP_TRAINING_PATTERN_SEQUENCE_4
:
249 dpcd_tr_pattern
= DPCD_TRAINING_PATTERN_4
;
253 DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
258 return dpcd_tr_pattern
;
261 static uint8_t dc_dp_initialize_scrambling_data_symbols(
262 struct dc_link
*link
,
263 enum dc_dp_training_pattern pattern
)
265 uint8_t disable_scrabled_data_symbols
= 0;
268 case DP_TRAINING_PATTERN_SEQUENCE_1
:
269 case DP_TRAINING_PATTERN_SEQUENCE_2
:
270 case DP_TRAINING_PATTERN_SEQUENCE_3
:
271 disable_scrabled_data_symbols
= 1;
273 case DP_TRAINING_PATTERN_SEQUENCE_4
:
274 disable_scrabled_data_symbols
= 0;
278 DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
282 return disable_scrabled_data_symbols
;
285 static inline bool is_repeater(struct dc_link
*link
, uint32_t offset
)
287 return (link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
) && (offset
!= 0);
290 static void dpcd_set_lt_pattern_and_lane_settings(
291 struct dc_link
*link
,
292 const struct link_training_settings
*lt_settings
,
293 enum dc_dp_training_pattern pattern
,
296 union dpcd_training_lane dpcd_lane
[LANE_COUNT_DP_MAX
] = { { {0} } };
298 uint32_t dpcd_base_lt_offset
;
300 uint8_t dpcd_lt_buffer
[5] = {0};
301 union dpcd_training_pattern dpcd_pattern
= { {0} };
303 uint32_t size_in_bytes
;
304 bool edp_workaround
= false; /* TODO link_prop.INTERNAL */
305 dpcd_base_lt_offset
= DP_TRAINING_PATTERN_SET
;
307 if (is_repeater(link
, offset
))
308 dpcd_base_lt_offset
= DP_TRAINING_PATTERN_SET_PHY_REPEATER1
+
309 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE
) * (offset
- 1));
311 /*****************************************************************
312 * DpcdAddress_TrainingPatternSet
313 *****************************************************************/
314 dpcd_pattern
.v1_4
.TRAINING_PATTERN_SET
=
315 dc_dp_training_pattern_to_dpcd_training_pattern(link
, pattern
);
317 dpcd_pattern
.v1_4
.SCRAMBLING_DISABLE
=
318 dc_dp_initialize_scrambling_data_symbols(link
, pattern
);
320 dpcd_lt_buffer
[DP_TRAINING_PATTERN_SET
- DP_TRAINING_PATTERN_SET
]
323 if (is_repeater(link
, offset
)) {
324 DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n 0x%X pattern = %x\n",
328 dpcd_pattern
.v1_4
.TRAINING_PATTERN_SET
);
330 DC_LOG_HW_LINK_TRAINING("%s\n 0x%X pattern = %x\n",
333 dpcd_pattern
.v1_4
.TRAINING_PATTERN_SET
);
335 /*****************************************************************
336 * DpcdAddress_Lane0Set -> DpcdAddress_Lane3Set
337 *****************************************************************/
338 for (lane
= 0; lane
<
339 (uint32_t)(lt_settings
->link_settings
.lane_count
); lane
++) {
341 dpcd_lane
[lane
].bits
.VOLTAGE_SWING_SET
=
342 (uint8_t)(lt_settings
->lane_settings
[lane
].VOLTAGE_SWING
);
343 dpcd_lane
[lane
].bits
.PRE_EMPHASIS_SET
=
344 (uint8_t)(lt_settings
->lane_settings
[lane
].PRE_EMPHASIS
);
346 dpcd_lane
[lane
].bits
.MAX_SWING_REACHED
=
347 (lt_settings
->lane_settings
[lane
].VOLTAGE_SWING
==
348 VOLTAGE_SWING_MAX_LEVEL
? 1 : 0);
349 dpcd_lane
[lane
].bits
.MAX_PRE_EMPHASIS_REACHED
=
350 (lt_settings
->lane_settings
[lane
].PRE_EMPHASIS
==
351 PRE_EMPHASIS_MAX_LEVEL
? 1 : 0);
354 /* concatenate everything into one buffer*/
356 size_in_bytes
= lt_settings
->link_settings
.lane_count
* sizeof(dpcd_lane
[0]);
360 &dpcd_lt_buffer
[DP_TRAINING_LANE0_SET
- DP_TRAINING_PATTERN_SET
],
364 if (is_repeater(link
, offset
)) {
365 DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
366 " 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
370 dpcd_lane
[0].bits
.VOLTAGE_SWING_SET
,
371 dpcd_lane
[0].bits
.PRE_EMPHASIS_SET
,
372 dpcd_lane
[0].bits
.MAX_SWING_REACHED
,
373 dpcd_lane
[0].bits
.MAX_PRE_EMPHASIS_REACHED
);
375 DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
378 dpcd_lane
[0].bits
.VOLTAGE_SWING_SET
,
379 dpcd_lane
[0].bits
.PRE_EMPHASIS_SET
,
380 dpcd_lane
[0].bits
.MAX_SWING_REACHED
,
381 dpcd_lane
[0].bits
.MAX_PRE_EMPHASIS_REACHED
);
383 if (edp_workaround
) {
384 /* for eDP write in 2 parts because the 5-byte burst is
385 * causing issues on some eDP panels (EPR#366724)
387 core_link_write_dpcd(
389 DP_TRAINING_PATTERN_SET
,
391 sizeof(dpcd_pattern
.raw
));
393 core_link_write_dpcd(
395 DP_TRAINING_LANE0_SET
,
396 (uint8_t *)(dpcd_lane
),
400 /* write it all in (1 + number-of-lanes)-byte burst*/
401 core_link_write_dpcd(
405 size_in_bytes
+ sizeof(dpcd_pattern
.raw
));
407 link
->cur_lane_setting
= lt_settings
->lane_settings
[0];
410 static bool is_cr_done(enum dc_lane_count ln_count
,
411 union lane_status
*dpcd_lane_status
)
414 /*LANEx_CR_DONE bits All 1's?*/
415 for (lane
= 0; lane
< (uint32_t)(ln_count
); lane
++) {
416 if (!dpcd_lane_status
[lane
].bits
.CR_DONE_0
)
422 static bool is_ch_eq_done(enum dc_lane_count ln_count
,
423 union lane_status
*dpcd_lane_status
,
424 union lane_align_status_updated
*lane_status_updated
)
427 if (!lane_status_updated
->bits
.INTERLANE_ALIGN_DONE
)
430 for (lane
= 0; lane
< (uint32_t)(ln_count
); lane
++) {
431 if (!dpcd_lane_status
[lane
].bits
.SYMBOL_LOCKED_0
||
432 !dpcd_lane_status
[lane
].bits
.CHANNEL_EQ_DONE_0
)
439 static void update_drive_settings(
440 struct link_training_settings
*dest
,
441 struct link_training_settings src
)
444 for (lane
= 0; lane
< src
.link_settings
.lane_count
; lane
++) {
445 if (dest
->voltage_swing
== NULL
)
446 dest
->lane_settings
[lane
].VOLTAGE_SWING
= src
.lane_settings
[lane
].VOLTAGE_SWING
;
448 dest
->lane_settings
[lane
].VOLTAGE_SWING
= *dest
->voltage_swing
;
450 if (dest
->pre_emphasis
== NULL
)
451 dest
->lane_settings
[lane
].PRE_EMPHASIS
= src
.lane_settings
[lane
].PRE_EMPHASIS
;
453 dest
->lane_settings
[lane
].PRE_EMPHASIS
= *dest
->pre_emphasis
;
455 if (dest
->post_cursor2
== NULL
)
456 dest
->lane_settings
[lane
].POST_CURSOR2
= src
.lane_settings
[lane
].POST_CURSOR2
;
458 dest
->lane_settings
[lane
].POST_CURSOR2
= *dest
->post_cursor2
;
462 static uint8_t get_nibble_at_index(const uint8_t *buf
,
466 nibble
= buf
[index
/ 2];
476 static enum dc_pre_emphasis
get_max_pre_emphasis_for_voltage_swing(
477 enum dc_voltage_swing voltage
)
479 enum dc_pre_emphasis pre_emphasis
;
480 pre_emphasis
= PRE_EMPHASIS_MAX_LEVEL
;
482 if (voltage
<= VOLTAGE_SWING_MAX_LEVEL
)
483 pre_emphasis
= voltage_swing_to_pre_emphasis
[voltage
];
489 static void find_max_drive_settings(
490 const struct link_training_settings
*link_training_setting
,
491 struct link_training_settings
*max_lt_setting
)
494 struct dc_lane_settings max_requested
;
496 max_requested
.VOLTAGE_SWING
=
497 link_training_setting
->
498 lane_settings
[0].VOLTAGE_SWING
;
499 max_requested
.PRE_EMPHASIS
=
500 link_training_setting
->
501 lane_settings
[0].PRE_EMPHASIS
;
502 /*max_requested.postCursor2 =
503 * link_training_setting->laneSettings[0].postCursor2;*/
505 /* Determine what the maximum of the requested settings are*/
506 for (lane
= 1; lane
< link_training_setting
->link_settings
.lane_count
;
508 if (link_training_setting
->lane_settings
[lane
].VOLTAGE_SWING
>
509 max_requested
.VOLTAGE_SWING
)
511 max_requested
.VOLTAGE_SWING
=
512 link_training_setting
->
513 lane_settings
[lane
].VOLTAGE_SWING
;
515 if (link_training_setting
->lane_settings
[lane
].PRE_EMPHASIS
>
516 max_requested
.PRE_EMPHASIS
)
517 max_requested
.PRE_EMPHASIS
=
518 link_training_setting
->
519 lane_settings
[lane
].PRE_EMPHASIS
;
522 if (link_training_setting->laneSettings[lane].postCursor2 >
523 max_requested.postCursor2)
525 max_requested.postCursor2 =
526 link_training_setting->laneSettings[lane].postCursor2;
531 /* make sure the requested settings are
532 * not higher than maximum settings*/
533 if (max_requested
.VOLTAGE_SWING
> VOLTAGE_SWING_MAX_LEVEL
)
534 max_requested
.VOLTAGE_SWING
= VOLTAGE_SWING_MAX_LEVEL
;
536 if (max_requested
.PRE_EMPHASIS
> PRE_EMPHASIS_MAX_LEVEL
)
537 max_requested
.PRE_EMPHASIS
= PRE_EMPHASIS_MAX_LEVEL
;
539 if (max_requested.postCursor2 > PostCursor2_MaxLevel)
540 max_requested.postCursor2 = PostCursor2_MaxLevel;
543 /* make sure the pre-emphasis matches the voltage swing*/
544 if (max_requested
.PRE_EMPHASIS
>
545 get_max_pre_emphasis_for_voltage_swing(
546 max_requested
.VOLTAGE_SWING
))
547 max_requested
.PRE_EMPHASIS
=
548 get_max_pre_emphasis_for_voltage_swing(
549 max_requested
.VOLTAGE_SWING
);
552 * Post Cursor2 levels are completely independent from
553 * pre-emphasis (Post Cursor1) levels. But Post Cursor2 levels
554 * can only be applied to each allowable combination of voltage
555 * swing and pre-emphasis levels */
556 /* if ( max_requested.postCursor2 >
557 * getMaxPostCursor2ForVoltageSwing(max_requested.voltageSwing))
558 * max_requested.postCursor2 =
559 * getMaxPostCursor2ForVoltageSwing(max_requested.voltageSwing);
562 max_lt_setting
->link_settings
.link_rate
=
563 link_training_setting
->link_settings
.link_rate
;
564 max_lt_setting
->link_settings
.lane_count
=
565 link_training_setting
->link_settings
.lane_count
;
566 max_lt_setting
->link_settings
.link_spread
=
567 link_training_setting
->link_settings
.link_spread
;
569 for (lane
= 0; lane
<
570 link_training_setting
->link_settings
.lane_count
;
572 max_lt_setting
->lane_settings
[lane
].VOLTAGE_SWING
=
573 max_requested
.VOLTAGE_SWING
;
574 max_lt_setting
->lane_settings
[lane
].PRE_EMPHASIS
=
575 max_requested
.PRE_EMPHASIS
;
576 /*max_lt_setting->laneSettings[lane].postCursor2 =
577 * max_requested.postCursor2;
583 static void get_lane_status_and_drive_settings(
584 struct dc_link
*link
,
585 const struct link_training_settings
*link_training_setting
,
586 union lane_status
*ln_status
,
587 union lane_align_status_updated
*ln_status_updated
,
588 struct link_training_settings
*req_settings
,
591 unsigned int lane01_status_address
= DP_LANE0_1_STATUS
;
592 uint8_t lane_adjust_offset
= 4;
593 unsigned int lane01_adjust_address
;
594 uint8_t dpcd_buf
[6] = {0};
595 union lane_adjust dpcd_lane_adjust
[LANE_COUNT_DP_MAX
] = { { {0} } };
596 struct link_training_settings request_settings
= { {0} };
599 memset(req_settings
, '\0', sizeof(struct link_training_settings
));
601 if (is_repeater(link
, offset
)) {
602 lane01_status_address
=
603 DP_LANE0_1_STATUS_PHY_REPEATER1
+
604 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE
) * (offset
- 1));
605 lane_adjust_offset
= 3;
610 lane01_status_address
,
611 (uint8_t *)(dpcd_buf
),
614 for (lane
= 0; lane
<
615 (uint32_t)(link_training_setting
->link_settings
.lane_count
);
618 ln_status
[lane
].raw
=
619 get_nibble_at_index(&dpcd_buf
[0], lane
);
620 dpcd_lane_adjust
[lane
].raw
=
621 get_nibble_at_index(&dpcd_buf
[lane_adjust_offset
], lane
);
624 ln_status_updated
->raw
= dpcd_buf
[2];
626 if (is_repeater(link
, offset
)) {
627 DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
628 " 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
631 lane01_status_address
, dpcd_buf
[0],
632 lane01_status_address
+ 1, dpcd_buf
[1]);
634 DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
636 lane01_status_address
, dpcd_buf
[0],
637 lane01_status_address
+ 1, dpcd_buf
[1]);
639 lane01_adjust_address
= DP_ADJUST_REQUEST_LANE0_1
;
641 if (is_repeater(link
, offset
))
642 lane01_adjust_address
= DP_ADJUST_REQUEST_LANE0_1_PHY_REPEATER1
+
643 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE
) * (offset
- 1));
645 if (is_repeater(link
, offset
)) {
646 DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
647 " 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
650 lane01_adjust_address
,
651 dpcd_buf
[lane_adjust_offset
],
652 lane01_adjust_address
+ 1,
653 dpcd_buf
[lane_adjust_offset
+ 1]);
655 DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
657 lane01_adjust_address
,
658 dpcd_buf
[lane_adjust_offset
],
659 lane01_adjust_address
+ 1,
660 dpcd_buf
[lane_adjust_offset
+ 1]);
663 /*copy to req_settings*/
664 request_settings
.link_settings
.lane_count
=
665 link_training_setting
->link_settings
.lane_count
;
666 request_settings
.link_settings
.link_rate
=
667 link_training_setting
->link_settings
.link_rate
;
668 request_settings
.link_settings
.link_spread
=
669 link_training_setting
->link_settings
.link_spread
;
671 for (lane
= 0; lane
<
672 (uint32_t)(link_training_setting
->link_settings
.lane_count
);
675 request_settings
.lane_settings
[lane
].VOLTAGE_SWING
=
676 (enum dc_voltage_swing
)(dpcd_lane_adjust
[lane
].bits
.
678 request_settings
.lane_settings
[lane
].PRE_EMPHASIS
=
679 (enum dc_pre_emphasis
)(dpcd_lane_adjust
[lane
].bits
.
683 /*Note: for postcursor2, read adjusted
684 * postcursor2 settings from*/
685 /*DpcdAddress_AdjustRequestPostCursor2 =
686 *0x020C (not implemented yet)*/
688 /* we find the maximum of the requested settings across all lanes*/
689 /* and set this maximum for all lanes*/
690 find_max_drive_settings(&request_settings
, req_settings
);
692 /* if post cursor 2 is needed in the future,
693 * read DpcdAddress_AdjustRequestPostCursor2 = 0x020C
698 static void dpcd_set_lane_settings(
699 struct dc_link
*link
,
700 const struct link_training_settings
*link_training_setting
,
703 union dpcd_training_lane dpcd_lane
[LANE_COUNT_DP_MAX
] = {{{0}}};
705 unsigned int lane0_set_address
;
707 lane0_set_address
= DP_TRAINING_LANE0_SET
;
709 if (is_repeater(link
, offset
))
710 lane0_set_address
= DP_TRAINING_LANE0_SET_PHY_REPEATER1
+
711 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE
) * (offset
- 1));
713 for (lane
= 0; lane
<
714 (uint32_t)(link_training_setting
->
715 link_settings
.lane_count
);
717 dpcd_lane
[lane
].bits
.VOLTAGE_SWING_SET
=
718 (uint8_t)(link_training_setting
->
719 lane_settings
[lane
].VOLTAGE_SWING
);
720 dpcd_lane
[lane
].bits
.PRE_EMPHASIS_SET
=
721 (uint8_t)(link_training_setting
->
722 lane_settings
[lane
].PRE_EMPHASIS
);
723 dpcd_lane
[lane
].bits
.MAX_SWING_REACHED
=
724 (link_training_setting
->
725 lane_settings
[lane
].VOLTAGE_SWING
==
726 VOLTAGE_SWING_MAX_LEVEL
? 1 : 0);
727 dpcd_lane
[lane
].bits
.MAX_PRE_EMPHASIS_REACHED
=
728 (link_training_setting
->
729 lane_settings
[lane
].PRE_EMPHASIS
==
730 PRE_EMPHASIS_MAX_LEVEL
? 1 : 0);
733 core_link_write_dpcd(link
,
735 (uint8_t *)(dpcd_lane
),
736 link_training_setting
->link_settings
.lane_count
);
739 if (LTSettings.link.rate == LinkRate_High2)
741 DpcdTrainingLaneSet2 dpcd_lane2[lane_count_DPMax] = {0};
742 for ( uint32_t lane = 0;
743 lane < lane_count_DPMax; lane++)
745 dpcd_lane2[lane].bits.post_cursor2_set =
746 static_cast<unsigned char>(
747 LTSettings.laneSettings[lane].postCursor2);
748 dpcd_lane2[lane].bits.max_post_cursor2_reached = 0;
750 m_pDpcdAccessSrv->WriteDpcdData(
751 DpcdAddress_Lane0Set2,
752 reinterpret_cast<unsigned char*>(dpcd_lane2),
753 LTSettings.link.lanes);
757 if (is_repeater(link
, offset
)) {
758 DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n"
759 " 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
763 dpcd_lane
[0].bits
.VOLTAGE_SWING_SET
,
764 dpcd_lane
[0].bits
.PRE_EMPHASIS_SET
,
765 dpcd_lane
[0].bits
.MAX_SWING_REACHED
,
766 dpcd_lane
[0].bits
.MAX_PRE_EMPHASIS_REACHED
);
769 DC_LOG_HW_LINK_TRAINING("%s\n 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
772 dpcd_lane
[0].bits
.VOLTAGE_SWING_SET
,
773 dpcd_lane
[0].bits
.PRE_EMPHASIS_SET
,
774 dpcd_lane
[0].bits
.MAX_SWING_REACHED
,
775 dpcd_lane
[0].bits
.MAX_PRE_EMPHASIS_REACHED
);
777 link
->cur_lane_setting
= link_training_setting
->lane_settings
[0];
781 static bool is_max_vs_reached(
782 const struct link_training_settings
*lt_settings
)
785 for (lane
= 0; lane
<
786 (uint32_t)(lt_settings
->link_settings
.lane_count
);
788 if (lt_settings
->lane_settings
[lane
].VOLTAGE_SWING
789 == VOLTAGE_SWING_MAX_LEVEL
)
796 static bool perform_post_lt_adj_req_sequence(
797 struct dc_link
*link
,
798 struct link_training_settings
*lt_settings
)
800 enum dc_lane_count lane_count
=
801 lt_settings
->link_settings
.lane_count
;
803 uint32_t adj_req_count
;
804 uint32_t adj_req_timer
;
805 bool req_drv_setting_changed
;
808 req_drv_setting_changed
= false;
809 for (adj_req_count
= 0; adj_req_count
< POST_LT_ADJ_REQ_LIMIT
;
812 req_drv_setting_changed
= false;
814 for (adj_req_timer
= 0;
815 adj_req_timer
< POST_LT_ADJ_REQ_TIMEOUT
;
818 struct link_training_settings req_settings
;
819 union lane_status dpcd_lane_status
[LANE_COUNT_DP_MAX
];
820 union lane_align_status_updated
821 dpcd_lane_status_updated
;
823 get_lane_status_and_drive_settings(
827 &dpcd_lane_status_updated
,
831 if (dpcd_lane_status_updated
.bits
.
832 POST_LT_ADJ_REQ_IN_PROGRESS
== 0)
835 if (!is_cr_done(lane_count
, dpcd_lane_status
))
841 &dpcd_lane_status_updated
))
844 for (lane
= 0; lane
< (uint32_t)(lane_count
); lane
++) {
847 lane_settings
[lane
].VOLTAGE_SWING
!=
848 req_settings
.lane_settings
[lane
].
850 lt_settings
->lane_settings
[lane
].PRE_EMPHASIS
!=
851 req_settings
.lane_settings
[lane
].PRE_EMPHASIS
) {
853 req_drv_setting_changed
= true;
858 if (req_drv_setting_changed
) {
859 update_drive_settings(
860 lt_settings
, req_settings
);
862 dc_link_dp_set_drive_settings(link
,
870 if (!req_drv_setting_changed
) {
871 DC_LOG_WARNING("%s: Post Link Training Adjust Request Timed out\n",
878 DC_LOG_WARNING("%s: Post Link Training Adjust Request limit reached\n",
886 /* Only used for channel equalization */
887 static uint32_t translate_training_aux_read_interval(uint32_t dpcd_aux_read_interval
)
889 unsigned int aux_rd_interval_us
= 400;
891 switch (dpcd_aux_read_interval
) {
893 aux_rd_interval_us
= 4000;
896 aux_rd_interval_us
= 8000;
899 aux_rd_interval_us
= 12000;
902 aux_rd_interval_us
= 16000;
908 return aux_rd_interval_us
;
911 static enum link_training_result
get_cr_failure(enum dc_lane_count ln_count
,
912 union lane_status
*dpcd_lane_status
)
914 enum link_training_result result
= LINK_TRAINING_SUCCESS
;
916 if (ln_count
>= LANE_COUNT_ONE
&& !dpcd_lane_status
[0].bits
.CR_DONE_0
)
917 result
= LINK_TRAINING_CR_FAIL_LANE0
;
918 else if (ln_count
>= LANE_COUNT_TWO
&& !dpcd_lane_status
[1].bits
.CR_DONE_0
)
919 result
= LINK_TRAINING_CR_FAIL_LANE1
;
920 else if (ln_count
>= LANE_COUNT_FOUR
&& !dpcd_lane_status
[2].bits
.CR_DONE_0
)
921 result
= LINK_TRAINING_CR_FAIL_LANE23
;
922 else if (ln_count
>= LANE_COUNT_FOUR
&& !dpcd_lane_status
[3].bits
.CR_DONE_0
)
923 result
= LINK_TRAINING_CR_FAIL_LANE23
;
927 static enum link_training_result
perform_channel_equalization_sequence(
928 struct dc_link
*link
,
929 struct link_training_settings
*lt_settings
,
932 struct link_training_settings req_settings
;
933 enum dc_dp_training_pattern tr_pattern
;
934 uint32_t retries_ch_eq
;
935 uint32_t wait_time_microsec
;
936 enum dc_lane_count lane_count
= lt_settings
->link_settings
.lane_count
;
937 union lane_align_status_updated dpcd_lane_status_updated
= { {0} };
938 union lane_status dpcd_lane_status
[LANE_COUNT_DP_MAX
] = { { {0} } };
940 /* Note: also check that TPS4 is a supported feature*/
942 tr_pattern
= lt_settings
->pattern_for_eq
;
944 if (is_repeater(link
, offset
))
945 tr_pattern
= DP_TRAINING_PATTERN_SEQUENCE_4
;
947 dp_set_hw_training_pattern(link
, tr_pattern
, offset
);
949 for (retries_ch_eq
= 0; retries_ch_eq
<= LINK_TRAINING_MAX_RETRY_COUNT
;
952 dp_set_hw_lane_settings(link
, lt_settings
, offset
);
956 /* EPR #361076 - write as a 5-byte burst,
957 * but only for the 1-st iteration
960 dpcd_set_lt_pattern_and_lane_settings(
965 dpcd_set_lane_settings(link
, lt_settings
, offset
);
967 /* 3. wait for receiver to lock-on*/
968 wait_time_microsec
= lt_settings
->eq_pattern_time
;
970 if (is_repeater(link
, offset
))
972 translate_training_aux_read_interval(
973 link
->dpcd_caps
.lttpr_caps
.aux_rd_interval
[offset
- 1]);
975 wait_for_training_aux_rd_interval(
979 /* 4. Read lane status and requested
980 * drive settings as set by the sink*/
982 get_lane_status_and_drive_settings(
986 &dpcd_lane_status_updated
,
990 /* 5. check CR done*/
991 if (!is_cr_done(lane_count
, dpcd_lane_status
))
992 return LINK_TRAINING_EQ_FAIL_CR
;
994 /* 6. check CHEQ done*/
995 if (is_ch_eq_done(lane_count
,
997 &dpcd_lane_status_updated
))
998 return LINK_TRAINING_SUCCESS
;
1000 /* 7. update VS/PE/PC2 in lt_settings*/
1001 update_drive_settings(lt_settings
, req_settings
);
1004 return LINK_TRAINING_EQ_FAIL_EQ
;
1007 #define TRAINING_AUX_RD_INTERVAL 100 //us
1009 static void start_clock_recovery_pattern_early(struct dc_link
*link
,
1010 struct link_training_settings
*lt_settings
,
1013 DC_LOG_HW_LINK_TRAINING("%s\n GPU sends TPS1. Wait 400us.\n",
1015 dp_set_hw_training_pattern(link
, lt_settings
->pattern_for_cr
, offset
);
1016 dp_set_hw_lane_settings(link
, lt_settings
, offset
);
1020 static enum link_training_result
perform_clock_recovery_sequence(
1021 struct dc_link
*link
,
1022 struct link_training_settings
*lt_settings
,
1025 uint32_t retries_cr
;
1026 uint32_t retry_count
;
1027 uint32_t wait_time_microsec
;
1028 struct link_training_settings req_settings
;
1029 enum dc_lane_count lane_count
= lt_settings
->link_settings
.lane_count
;
1030 union lane_status dpcd_lane_status
[LANE_COUNT_DP_MAX
];
1031 union lane_align_status_updated dpcd_lane_status_updated
;
1036 if (!link
->ctx
->dc
->work_arounds
.lt_early_cr_pattern
)
1037 dp_set_hw_training_pattern(link
, lt_settings
->pattern_for_cr
, offset
);
1039 /* najeeb - The synaptics MST hub can put the LT in
1040 * infinite loop by switching the VS
1042 /* between level 0 and level 1 continuously, here
1043 * we try for CR lock for LinkTrainingMaxCRRetry count*/
1044 while ((retries_cr
< LINK_TRAINING_MAX_RETRY_COUNT
) &&
1045 (retry_count
< LINK_TRAINING_MAX_CR_RETRY
)) {
1047 memset(&dpcd_lane_status
, '\0', sizeof(dpcd_lane_status
));
1048 memset(&dpcd_lane_status_updated
, '\0',
1049 sizeof(dpcd_lane_status_updated
));
1051 /* 1. call HWSS to set lane settings*/
1052 dp_set_hw_lane_settings(
1057 /* 2. update DPCD of the receiver*/
1059 /* EPR #361076 - write as a 5-byte burst,
1060 * but only for the 1-st iteration.*/
1061 dpcd_set_lt_pattern_and_lane_settings(
1064 lt_settings
->pattern_for_cr
,
1067 dpcd_set_lane_settings(
1072 /* 3. wait receiver to lock-on*/
1073 wait_time_microsec
= lt_settings
->cr_pattern_time
;
1075 if (link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
)
1076 wait_time_microsec
= TRAINING_AUX_RD_INTERVAL
;
1078 wait_for_training_aux_rd_interval(
1080 wait_time_microsec
);
1082 /* 4. Read lane status and requested drive
1083 * settings as set by the sink
1085 get_lane_status_and_drive_settings(
1089 &dpcd_lane_status_updated
,
1093 /* 5. check CR done*/
1094 if (is_cr_done(lane_count
, dpcd_lane_status
))
1095 return LINK_TRAINING_SUCCESS
;
1097 /* 6. max VS reached*/
1098 if (is_max_vs_reached(lt_settings
))
1101 /* 7. same lane settings*/
1102 /* Note: settings are the same for all lanes,
1103 * so comparing first lane is sufficient*/
1104 if ((lt_settings
->lane_settings
[0].VOLTAGE_SWING
==
1105 req_settings
.lane_settings
[0].VOLTAGE_SWING
)
1106 && (lt_settings
->lane_settings
[0].PRE_EMPHASIS
==
1107 req_settings
.lane_settings
[0].PRE_EMPHASIS
))
1112 /* 8. update VS/PE/PC2 in lt_settings*/
1113 update_drive_settings(lt_settings
, req_settings
);
1118 if (retry_count
>= LINK_TRAINING_MAX_CR_RETRY
) {
1120 DC_LOG_ERROR("%s: Link Training Error, could not get CR after %d tries. Possibly voltage swing issue",
1122 LINK_TRAINING_MAX_CR_RETRY
);
1126 return get_cr_failure(lane_count
, dpcd_lane_status
);
1129 static inline enum link_training_result
perform_link_training_int(
1130 struct dc_link
*link
,
1131 struct link_training_settings
*lt_settings
,
1132 enum link_training_result status
)
1134 union lane_count_set lane_count_set
= { {0} };
1136 /* 4. mainlink output idle pattern*/
1137 dp_set_hw_test_pattern(link
, DP_TEST_PATTERN_VIDEO_MODE
, NULL
, 0);
1140 * 5. post training adjust if required
1141 * If the upstream DPTX and downstream DPRX both support TPS4,
1142 * TPS4 must be used instead of POST_LT_ADJ_REQ.
1144 if (link
->dpcd_caps
.max_ln_count
.bits
.POST_LT_ADJ_REQ_SUPPORTED
!= 1 ||
1145 lt_settings
->pattern_for_eq
== DP_TRAINING_PATTERN_SEQUENCE_4
)
1148 if (status
== LINK_TRAINING_SUCCESS
&&
1149 perform_post_lt_adj_req_sequence(link
, lt_settings
) == false)
1150 status
= LINK_TRAINING_LQA_FAIL
;
1152 lane_count_set
.bits
.LANE_COUNT_SET
= lt_settings
->link_settings
.lane_count
;
1153 lane_count_set
.bits
.ENHANCED_FRAMING
= lt_settings
->enhanced_framing
;
1154 lane_count_set
.bits
.POST_LT_ADJ_REQ_GRANTED
= 0;
1156 core_link_write_dpcd(
1159 &lane_count_set
.raw
,
1160 sizeof(lane_count_set
));
1165 static enum link_training_result
check_link_loss_status(
1166 struct dc_link
*link
,
1167 const struct link_training_settings
*link_training_setting
)
1169 enum link_training_result status
= LINK_TRAINING_SUCCESS
;
1170 union lane_status lane_status
;
1171 uint8_t dpcd_buf
[6] = {0};
1174 core_link_read_dpcd(
1177 (uint8_t *)(dpcd_buf
),
1180 /*parse lane status*/
1181 for (lane
= 0; lane
< link
->cur_link_settings
.lane_count
; lane
++) {
1183 * check lanes status
1185 lane_status
.raw
= get_nibble_at_index(&dpcd_buf
[2], lane
);
1187 if (!lane_status
.bits
.CHANNEL_EQ_DONE_0
||
1188 !lane_status
.bits
.CR_DONE_0
||
1189 !lane_status
.bits
.SYMBOL_LOCKED_0
) {
1190 /* if one of the channel equalization, clock
1191 * recovery or symbol lock is dropped
1192 * consider it as (link has been
1193 * dropped) dp sink status has changed
1195 status
= LINK_TRAINING_LINK_LOSS
;
1203 static void initialize_training_settings(
1204 struct dc_link
*link
,
1205 const struct dc_link_settings
*link_setting
,
1206 const struct dc_link_training_overrides
*overrides
,
1207 struct link_training_settings
*lt_settings
)
1211 memset(lt_settings
, '\0', sizeof(struct link_training_settings
));
1213 /* Initialize link settings */
1214 lt_settings
->link_settings
.use_link_rate_set
= link_setting
->use_link_rate_set
;
1215 lt_settings
->link_settings
.link_rate_set
= link_setting
->link_rate_set
;
1217 if (link
->preferred_link_setting
.link_rate
!= LINK_RATE_UNKNOWN
)
1218 lt_settings
->link_settings
.link_rate
= link
->preferred_link_setting
.link_rate
;
1220 lt_settings
->link_settings
.link_rate
= link_setting
->link_rate
;
1222 if (link
->preferred_link_setting
.lane_count
!= LANE_COUNT_UNKNOWN
)
1223 lt_settings
->link_settings
.lane_count
= link
->preferred_link_setting
.lane_count
;
1225 lt_settings
->link_settings
.lane_count
= link_setting
->lane_count
;
1227 /*@todo[vdevulap] move SS to LS, should not be handled by displaypath*/
1229 /* TODO hard coded to SS for now
1230 * lt_settings.link_settings.link_spread =
1231 * dal_display_path_is_ss_supported(
1232 * path_mode->display_path) ?
1233 * LINK_SPREAD_05_DOWNSPREAD_30KHZ :
1234 * LINK_SPREAD_DISABLED;
1236 /* Initialize link spread */
1237 if (link
->dp_ss_off
)
1238 lt_settings
->link_settings
.link_spread
= LINK_SPREAD_DISABLED
;
1239 else if (overrides
->downspread
!= NULL
)
1240 lt_settings
->link_settings
.link_spread
1241 = *overrides
->downspread
1242 ? LINK_SPREAD_05_DOWNSPREAD_30KHZ
1243 : LINK_SPREAD_DISABLED
;
1245 lt_settings
->link_settings
.link_spread
= LINK_SPREAD_05_DOWNSPREAD_30KHZ
;
1247 /* Initialize lane settings overrides */
1248 if (overrides
->voltage_swing
!= NULL
)
1249 lt_settings
->voltage_swing
= overrides
->voltage_swing
;
1251 if (overrides
->pre_emphasis
!= NULL
)
1252 lt_settings
->pre_emphasis
= overrides
->pre_emphasis
;
1254 if (overrides
->post_cursor2
!= NULL
)
1255 lt_settings
->post_cursor2
= overrides
->post_cursor2
;
1257 /* Initialize lane settings (VS/PE/PC2) */
1258 for (lane
= 0; lane
< LANE_COUNT_DP_MAX
; lane
++) {
1259 lt_settings
->lane_settings
[lane
].VOLTAGE_SWING
=
1260 lt_settings
->voltage_swing
!= NULL
?
1261 *lt_settings
->voltage_swing
:
1262 VOLTAGE_SWING_LEVEL0
;
1263 lt_settings
->lane_settings
[lane
].PRE_EMPHASIS
=
1264 lt_settings
->pre_emphasis
!= NULL
?
1265 *lt_settings
->pre_emphasis
1266 : PRE_EMPHASIS_DISABLED
;
1267 lt_settings
->lane_settings
[lane
].POST_CURSOR2
=
1268 lt_settings
->post_cursor2
!= NULL
?
1269 *lt_settings
->post_cursor2
1270 : POST_CURSOR2_DISABLED
;
1273 /* Initialize training timings */
1274 if (overrides
->cr_pattern_time
!= NULL
)
1275 lt_settings
->cr_pattern_time
= *overrides
->cr_pattern_time
;
1277 lt_settings
->cr_pattern_time
= get_cr_training_aux_rd_interval(link
, link_setting
);
1279 if (overrides
->eq_pattern_time
!= NULL
)
1280 lt_settings
->eq_pattern_time
= *overrides
->eq_pattern_time
;
1282 lt_settings
->eq_pattern_time
= get_eq_training_aux_rd_interval(link
, link_setting
);
1284 if (overrides
->pattern_for_cr
!= NULL
)
1285 lt_settings
->pattern_for_cr
= *overrides
->pattern_for_cr
;
1287 lt_settings
->pattern_for_cr
= decide_cr_training_pattern(link_setting
);
1288 if (overrides
->pattern_for_eq
!= NULL
)
1289 lt_settings
->pattern_for_eq
= *overrides
->pattern_for_eq
;
1291 lt_settings
->pattern_for_eq
= decide_eq_training_pattern(link
, link_setting
);
1293 if (overrides
->enhanced_framing
!= NULL
)
1294 lt_settings
->enhanced_framing
= *overrides
->enhanced_framing
;
1296 lt_settings
->enhanced_framing
= 1;
1299 static uint8_t convert_to_count(uint8_t lttpr_repeater_count
)
1301 switch (lttpr_repeater_count
) {
1302 case 0x80: // 1 lttpr repeater
1304 case 0x40: // 2 lttpr repeaters
1306 case 0x20: // 3 lttpr repeaters
1308 case 0x10: // 4 lttpr repeaters
1310 case 0x08: // 5 lttpr repeaters
1312 case 0x04: // 6 lttpr repeaters
1314 case 0x02: // 7 lttpr repeaters
1316 case 0x01: // 8 lttpr repeaters
1321 return 0; // invalid value
1324 static void configure_lttpr_mode_transparent(struct dc_link
*link
)
1326 uint8_t repeater_mode
= DP_PHY_REPEATER_MODE_TRANSPARENT
;
1328 core_link_write_dpcd(link
,
1329 DP_PHY_REPEATER_MODE
,
1330 (uint8_t *)&repeater_mode
,
1331 sizeof(repeater_mode
));
1334 static void configure_lttpr_mode_non_transparent(struct dc_link
*link
)
1336 /* aux timeout is already set to extended */
1337 /* RESET/SET lttpr mode to enable non transparent mode */
1338 uint8_t repeater_cnt
;
1339 uint32_t aux_interval_address
;
1340 uint8_t repeater_id
;
1341 enum dc_status result
= DC_ERROR_UNEXPECTED
;
1342 uint8_t repeater_mode
= DP_PHY_REPEATER_MODE_TRANSPARENT
;
1344 DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Transparent Mode\n", __func__
);
1345 result
= core_link_write_dpcd(link
,
1346 DP_PHY_REPEATER_MODE
,
1347 (uint8_t *)&repeater_mode
,
1348 sizeof(repeater_mode
));
1350 if (result
== DC_OK
) {
1351 link
->dpcd_caps
.lttpr_caps
.mode
= repeater_mode
;
1354 if (link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
) {
1356 DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Non Transparent Mode\n", __func__
);
1358 repeater_mode
= DP_PHY_REPEATER_MODE_NON_TRANSPARENT
;
1359 result
= core_link_write_dpcd(link
,
1360 DP_PHY_REPEATER_MODE
,
1361 (uint8_t *)&repeater_mode
,
1362 sizeof(repeater_mode
));
1364 if (result
== DC_OK
) {
1365 link
->dpcd_caps
.lttpr_caps
.mode
= repeater_mode
;
1368 repeater_cnt
= convert_to_count(link
->dpcd_caps
.lttpr_caps
.phy_repeater_cnt
);
1369 for (repeater_id
= repeater_cnt
; repeater_id
> 0; repeater_id
--) {
1370 aux_interval_address
= DP_TRAINING_AUX_RD_INTERVAL_PHY_REPEATER1
+
1371 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE
) * (repeater_id
- 1));
1372 core_link_read_dpcd(
1374 aux_interval_address
,
1375 (uint8_t *)&link
->dpcd_caps
.lttpr_caps
.aux_rd_interval
[repeater_id
- 1],
1376 sizeof(link
->dpcd_caps
.lttpr_caps
.aux_rd_interval
[repeater_id
- 1]));
1377 link
->dpcd_caps
.lttpr_caps
.aux_rd_interval
[repeater_id
- 1] &= 0x7F;
1382 static void repeater_training_done(struct dc_link
*link
, uint32_t offset
)
1384 union dpcd_training_pattern dpcd_pattern
= { {0} };
1386 const uint32_t dpcd_base_lt_offset
=
1387 DP_TRAINING_PATTERN_SET_PHY_REPEATER1
+
1388 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE
) * (offset
- 1));
1389 /* Set training not in progress*/
1390 dpcd_pattern
.v1_4
.TRAINING_PATTERN_SET
= DPCD_TRAINING_PATTERN_VIDEOIDLE
;
1392 core_link_write_dpcd(
1394 dpcd_base_lt_offset
,
1398 DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Id: %d 0x%X pattern = %x\n",
1401 dpcd_base_lt_offset
,
1402 dpcd_pattern
.v1_4
.TRAINING_PATTERN_SET
);
1405 static void print_status_message(
1406 struct dc_link
*link
,
1407 const struct link_training_settings
*lt_settings
,
1408 enum link_training_result status
)
1410 char *link_rate
= "Unknown";
1411 char *lt_result
= "Unknown";
1412 char *lt_spread
= "Disabled";
1414 switch (lt_settings
->link_settings
.link_rate
) {
1418 case LINK_RATE_RATE_2
:
1421 case LINK_RATE_RATE_3
:
1424 case LINK_RATE_HIGH
:
1427 case LINK_RATE_RBR2
:
1430 case LINK_RATE_RATE_6
:
1433 case LINK_RATE_HIGH2
:
1436 case LINK_RATE_HIGH3
:
1444 case LINK_TRAINING_SUCCESS
:
1447 case LINK_TRAINING_CR_FAIL_LANE0
:
1448 lt_result
= "CR failed lane0";
1450 case LINK_TRAINING_CR_FAIL_LANE1
:
1451 lt_result
= "CR failed lane1";
1453 case LINK_TRAINING_CR_FAIL_LANE23
:
1454 lt_result
= "CR failed lane23";
1456 case LINK_TRAINING_EQ_FAIL_CR
:
1457 lt_result
= "CR failed in EQ";
1459 case LINK_TRAINING_EQ_FAIL_EQ
:
1460 lt_result
= "EQ failed";
1462 case LINK_TRAINING_LQA_FAIL
:
1463 lt_result
= "LQA failed";
1465 case LINK_TRAINING_LINK_LOSS
:
1466 lt_result
= "Link loss";
1472 switch (lt_settings
->link_settings
.link_spread
) {
1473 case LINK_SPREAD_DISABLED
:
1474 lt_spread
= "Disabled";
1476 case LINK_SPREAD_05_DOWNSPREAD_30KHZ
:
1477 lt_spread
= "0.5% 30KHz";
1479 case LINK_SPREAD_05_DOWNSPREAD_33KHZ
:
1480 lt_spread
= "0.5% 33KHz";
1486 /* Connectivity log: link training */
1487 CONN_MSG_LT(link
, "%sx%d %s VS=%d, PE=%d, DS=%s",
1489 lt_settings
->link_settings
.lane_count
,
1491 lt_settings
->lane_settings
[0].VOLTAGE_SWING
,
1492 lt_settings
->lane_settings
[0].PRE_EMPHASIS
,
1496 void dc_link_dp_set_drive_settings(
1497 struct dc_link
*link
,
1498 struct link_training_settings
*lt_settings
)
1500 /* program ASIC PHY settings*/
1501 dp_set_hw_lane_settings(link
, lt_settings
, DPRX
);
1503 /* Notify DP sink the PHY settings from source */
1504 dpcd_set_lane_settings(link
, lt_settings
, DPRX
);
1507 bool dc_link_dp_perform_link_training_skip_aux(
1508 struct dc_link
*link
,
1509 const struct dc_link_settings
*link_setting
)
1511 struct link_training_settings lt_settings
;
1513 initialize_training_settings(
1516 &link
->preferred_training_settings
,
1519 /* 1. Perform_clock_recovery_sequence. */
1521 /* transmit training pattern for clock recovery */
1522 dp_set_hw_training_pattern(link
, lt_settings
.pattern_for_cr
, DPRX
);
1524 /* call HWSS to set lane settings*/
1525 dp_set_hw_lane_settings(link
, <_settings
, DPRX
);
1527 /* wait receiver to lock-on*/
1528 wait_for_training_aux_rd_interval(link
, lt_settings
.cr_pattern_time
);
1530 /* 2. Perform_channel_equalization_sequence. */
1532 /* transmit training pattern for channel equalization. */
1533 dp_set_hw_training_pattern(link
, lt_settings
.pattern_for_eq
, DPRX
);
1535 /* call HWSS to set lane settings*/
1536 dp_set_hw_lane_settings(link
, <_settings
, DPRX
);
1538 /* wait receiver to lock-on. */
1539 wait_for_training_aux_rd_interval(link
, lt_settings
.eq_pattern_time
);
1541 /* 3. Perform_link_training_int. */
1543 /* Mainlink output idle pattern. */
1544 dp_set_hw_test_pattern(link
, DP_TEST_PATTERN_VIDEO_MODE
, NULL
, 0);
1546 print_status_message(link
, <_settings
, LINK_TRAINING_SUCCESS
);
1551 enum link_training_result
dc_link_dp_perform_link_training(
1552 struct dc_link
*link
,
1553 const struct dc_link_settings
*link_setting
,
1554 bool skip_video_pattern
)
1556 enum link_training_result status
= LINK_TRAINING_SUCCESS
;
1557 struct link_training_settings lt_settings
;
1558 union dpcd_training_pattern dpcd_pattern
= { { 0 } };
1561 uint8_t repeater_cnt
;
1562 uint8_t repeater_id
;
1564 initialize_training_settings(
1567 &link
->preferred_training_settings
,
1570 /* Configure lttpr mode */
1571 if (link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
)
1572 configure_lttpr_mode_non_transparent(link
);
1573 else if (link
->lttpr_mode
== LTTPR_MODE_TRANSPARENT
)
1574 configure_lttpr_mode_transparent(link
);
1576 if (link
->ctx
->dc
->work_arounds
.lt_early_cr_pattern
)
1577 start_clock_recovery_pattern_early(link
, <_settings
, DPRX
);
1579 /* 1. set link rate, lane count and spread. */
1580 dpcd_set_link_settings(link
, <_settings
);
1582 if (link
->preferred_training_settings
.fec_enable
!= NULL
)
1583 fec_enable
= *link
->preferred_training_settings
.fec_enable
;
1587 dp_set_fec_ready(link
, fec_enable
);
1589 if (link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
) {
1591 /* 2. perform link training (set link training done
1592 * to false is done as well)
1594 repeater_cnt
= convert_to_count(link
->dpcd_caps
.lttpr_caps
.phy_repeater_cnt
);
1596 for (repeater_id
= repeater_cnt
; (repeater_id
> 0 && status
== LINK_TRAINING_SUCCESS
);
1598 status
= perform_clock_recovery_sequence(link
, <_settings
, repeater_id
);
1600 if (status
!= LINK_TRAINING_SUCCESS
)
1603 status
= perform_channel_equalization_sequence(link
,
1607 if (status
!= LINK_TRAINING_SUCCESS
)
1610 repeater_training_done(link
, repeater_id
);
1614 if (status
== LINK_TRAINING_SUCCESS
) {
1615 status
= perform_clock_recovery_sequence(link
, <_settings
, DPRX
);
1616 if (status
== LINK_TRAINING_SUCCESS
) {
1617 status
= perform_channel_equalization_sequence(link
,
1623 /* 3. set training not in progress*/
1624 dpcd_pattern
.v1_4
.TRAINING_PATTERN_SET
= DPCD_TRAINING_PATTERN_VIDEOIDLE
;
1625 dpcd_set_training_pattern(link
, dpcd_pattern
);
1626 if ((status
== LINK_TRAINING_SUCCESS
) || !skip_video_pattern
) {
1627 status
= perform_link_training_int(link
,
1632 /* delay 5ms after Main Link output idle pattern and then check
1635 if (link
->connector_signal
!= SIGNAL_TYPE_EDP
&& status
== LINK_TRAINING_SUCCESS
) {
1637 status
= check_link_loss_status(link
, <_settings
);
1640 /* 6. print status message*/
1641 print_status_message(link
, <_settings
, status
);
1643 if (status
!= LINK_TRAINING_SUCCESS
)
1644 link
->ctx
->dc
->debug_data
.ltFailCount
++;
1649 static enum dp_panel_mode
try_enable_assr(struct dc_stream_state
*stream
)
1651 struct dc_link
*link
= stream
->link
;
1652 enum dp_panel_mode panel_mode
= dp_get_panel_mode(link
);
1653 #ifdef CONFIG_DRM_AMD_DC_HDCP
1654 struct cp_psp
*cp_psp
= &stream
->ctx
->cp_psp
;
1657 /* ASSR must be supported on the panel */
1658 if (panel_mode
== DP_PANEL_MODE_DEFAULT
)
1661 /* eDP or internal DP only */
1662 if (link
->connector_signal
!= SIGNAL_TYPE_EDP
&&
1663 !(link
->connector_signal
== SIGNAL_TYPE_DISPLAY_PORT
&&
1664 link
->is_internal_display
))
1665 return DP_PANEL_MODE_DEFAULT
;
1667 #ifdef CONFIG_DRM_AMD_DC_HDCP
1668 if (cp_psp
&& cp_psp
->funcs
.enable_assr
) {
1669 if (!cp_psp
->funcs
.enable_assr(cp_psp
->handle
, link
)) {
1670 /* since eDP implies ASSR on, change panel
1671 * mode to disable ASSR
1673 panel_mode
= DP_PANEL_MODE_DEFAULT
;
1676 panel_mode
= DP_PANEL_MODE_DEFAULT
;
1679 /* turn off ASSR if the implementation is not compiled in */
1680 panel_mode
= DP_PANEL_MODE_DEFAULT
;
1685 bool perform_link_training_with_retries(
1686 const struct dc_link_settings
*link_setting
,
1687 bool skip_video_pattern
,
1689 struct pipe_ctx
*pipe_ctx
,
1690 enum signal_type signal
)
1693 uint8_t delay_between_attempts
= LINK_TRAINING_RETRY_DELAY
;
1694 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1695 struct dc_link
*link
= stream
->link
;
1696 enum dp_panel_mode panel_mode
;
1698 /* We need to do this before the link training to ensure the idle pattern in SST
1699 * mode will be sent right after the link training
1701 link
->link_enc
->funcs
->connect_dig_be_to_fe(link
->link_enc
,
1702 pipe_ctx
->stream_res
.stream_enc
->id
, true);
1704 for (j
= 0; j
< attempts
; ++j
) {
1706 DC_LOG_HW_LINK_TRAINING("%s: Beginning link training attempt %u of %d\n",
1707 __func__
, (unsigned int)j
+ 1, attempts
);
1712 pipe_ctx
->clock_source
->id
,
1715 if (stream
->sink_patches
.dppowerup_delay
> 0) {
1716 int delay_dp_power_up_in_ms
= stream
->sink_patches
.dppowerup_delay
;
1718 msleep(delay_dp_power_up_in_ms
);
1721 panel_mode
= try_enable_assr(stream
);
1722 dp_set_panel_mode(link
, panel_mode
);
1723 DC_LOG_DETECTION_DP_CAPS("Link: %d ASSR enabled: %d\n",
1725 panel_mode
!= DP_PANEL_MODE_DEFAULT
);
1727 if (link
->aux_access_disabled
) {
1728 dc_link_dp_perform_link_training_skip_aux(link
, link_setting
);
1731 enum link_training_result status
= LINK_TRAINING_CR_FAIL_LANE0
;
1733 status
= dc_link_dp_perform_link_training(
1736 skip_video_pattern
);
1737 if (status
== LINK_TRAINING_SUCCESS
)
1741 /* latest link training still fail, skip delay and keep PHY on
1743 if (j
== (attempts
- 1))
1746 DC_LOG_WARNING("%s: Link training attempt %u of %d failed\n",
1747 __func__
, (unsigned int)j
+ 1, attempts
);
1749 dp_disable_link_phy(link
, signal
);
1751 msleep(delay_between_attempts
);
1753 delay_between_attempts
+= LINK_TRAINING_RETRY_DELAY
;
1759 static enum clock_source_id
get_clock_source_id(struct dc_link
*link
)
1761 enum clock_source_id dp_cs_id
= CLOCK_SOURCE_ID_UNDEFINED
;
1762 struct clock_source
*dp_cs
= link
->dc
->res_pool
->dp_clock_source
;
1764 if (dp_cs
!= NULL
) {
1765 dp_cs_id
= dp_cs
->id
;
1768 * dp clock source is not initialized for some reason.
1769 * Should not happen, CLOCK_SOURCE_ID_EXTERNAL will be used
1777 static void set_dp_mst_mode(struct dc_link
*link
, bool mst_enable
)
1779 if (mst_enable
== false &&
1780 link
->type
== dc_connection_mst_branch
) {
1781 /* Disable MST on link. Use only local sink. */
1782 dp_disable_link_phy_mst(link
, link
->connector_signal
);
1784 link
->type
= dc_connection_single
;
1785 link
->local_sink
= link
->remote_sinks
[0];
1786 link
->local_sink
->sink_signal
= SIGNAL_TYPE_DISPLAY_PORT
;
1787 } else if (mst_enable
== true &&
1788 link
->type
== dc_connection_single
&&
1789 link
->remote_sinks
[0] != NULL
) {
1790 /* Re-enable MST on link. */
1791 dp_disable_link_phy(link
, link
->connector_signal
);
1792 dp_enable_mst_on_sink(link
, true);
1794 link
->type
= dc_connection_mst_branch
;
1795 link
->local_sink
->sink_signal
= SIGNAL_TYPE_DISPLAY_PORT_MST
;
1799 bool dc_link_dp_sync_lt_begin(struct dc_link
*link
)
1801 /* Begin Sync LT. During this time,
1802 * DPCD:600h must not be powered down.
1804 link
->sync_lt_in_progress
= true;
1806 /*Clear any existing preferred settings.*/
1807 memset(&link
->preferred_training_settings
, 0,
1808 sizeof(struct dc_link_training_overrides
));
1809 memset(&link
->preferred_link_setting
, 0,
1810 sizeof(struct dc_link_settings
));
1815 enum link_training_result
dc_link_dp_sync_lt_attempt(
1816 struct dc_link
*link
,
1817 struct dc_link_settings
*link_settings
,
1818 struct dc_link_training_overrides
*lt_overrides
)
1820 struct link_training_settings lt_settings
;
1821 enum link_training_result lt_status
= LINK_TRAINING_SUCCESS
;
1822 enum dp_panel_mode panel_mode
= DP_PANEL_MODE_DEFAULT
;
1823 enum clock_source_id dp_cs_id
= CLOCK_SOURCE_ID_EXTERNAL
;
1824 bool fec_enable
= false;
1826 initialize_training_settings(
1832 /* Setup MST Mode */
1833 if (lt_overrides
->mst_enable
)
1834 set_dp_mst_mode(link
, *lt_overrides
->mst_enable
);
1837 dp_disable_link_phy(link
, link
->connector_signal
);
1840 dp_cs_id
= get_clock_source_id(link
);
1841 dp_enable_link_phy(link
, link
->connector_signal
,
1842 dp_cs_id
, link_settings
);
1844 /* Set FEC enable */
1845 fec_enable
= lt_overrides
->fec_enable
&& *lt_overrides
->fec_enable
;
1846 dp_set_fec_ready(link
, fec_enable
);
1848 if (lt_overrides
->alternate_scrambler_reset
) {
1849 if (*lt_overrides
->alternate_scrambler_reset
)
1850 panel_mode
= DP_PANEL_MODE_EDP
;
1852 panel_mode
= DP_PANEL_MODE_DEFAULT
;
1854 panel_mode
= dp_get_panel_mode(link
);
1856 dp_set_panel_mode(link
, panel_mode
);
1858 /* Attempt to train with given link training settings */
1859 if (link
->ctx
->dc
->work_arounds
.lt_early_cr_pattern
)
1860 start_clock_recovery_pattern_early(link
, <_settings
, DPRX
);
1862 /* Set link rate, lane count and spread. */
1863 dpcd_set_link_settings(link
, <_settings
);
1865 /* 2. perform link training (set link training done
1866 * to false is done as well)
1868 lt_status
= perform_clock_recovery_sequence(link
, <_settings
, DPRX
);
1869 if (lt_status
== LINK_TRAINING_SUCCESS
) {
1870 lt_status
= perform_channel_equalization_sequence(link
,
1875 /* 3. Sync LT must skip TRAINING_PATTERN_SET:0 (video pattern)*/
1876 /* 4. print status message*/
1877 print_status_message(link
, <_settings
, lt_status
);
1882 bool dc_link_dp_sync_lt_end(struct dc_link
*link
, bool link_down
)
1884 /* If input parameter is set, shut down phy.
1885 * Still shouldn't turn off dp_receiver (DPCD:600h)
1887 if (link_down
== true) {
1888 dp_disable_link_phy(link
, link
->connector_signal
);
1889 dp_set_fec_ready(link
, false);
1892 link
->sync_lt_in_progress
= false;
1896 bool dc_link_dp_get_max_link_enc_cap(const struct dc_link
*link
, struct dc_link_settings
*max_link_enc_cap
)
1898 if (!max_link_enc_cap
) {
1899 DC_LOG_ERROR("%s: Could not return max link encoder caps", __func__
);
1903 if (link
->link_enc
->funcs
->get_max_link_cap
) {
1904 link
->link_enc
->funcs
->get_max_link_cap(link
->link_enc
, max_link_enc_cap
);
1908 DC_LOG_ERROR("%s: Max link encoder caps unknown", __func__
);
1909 max_link_enc_cap
->lane_count
= 1;
1910 max_link_enc_cap
->link_rate
= 6;
1914 static struct dc_link_settings
get_max_link_cap(struct dc_link
*link
)
1916 struct dc_link_settings max_link_cap
= {0};
1918 /* get max link encoder capability */
1919 link
->link_enc
->funcs
->get_max_link_cap(link
->link_enc
, &max_link_cap
);
1921 /* Lower link settings based on sink's link cap */
1922 if (link
->reported_link_cap
.lane_count
< max_link_cap
.lane_count
)
1923 max_link_cap
.lane_count
=
1924 link
->reported_link_cap
.lane_count
;
1925 if (link
->reported_link_cap
.link_rate
< max_link_cap
.link_rate
)
1926 max_link_cap
.link_rate
=
1927 link
->reported_link_cap
.link_rate
;
1928 if (link
->reported_link_cap
.link_spread
<
1929 max_link_cap
.link_spread
)
1930 max_link_cap
.link_spread
=
1931 link
->reported_link_cap
.link_spread
;
1933 * account for lttpr repeaters cap
1934 * notes: repeaters do not snoop in the DPRX Capabilities addresses (3.6.3).
1936 if (link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
) {
1937 if (link
->dpcd_caps
.lttpr_caps
.max_lane_count
< max_link_cap
.lane_count
)
1938 max_link_cap
.lane_count
= link
->dpcd_caps
.lttpr_caps
.max_lane_count
;
1940 if (link
->dpcd_caps
.lttpr_caps
.max_link_rate
< max_link_cap
.link_rate
)
1941 max_link_cap
.link_rate
= link
->dpcd_caps
.lttpr_caps
.max_link_rate
;
1943 DC_LOG_HW_LINK_TRAINING("%s\n Training with LTTPR, max_lane count %d max_link rate %d \n",
1945 max_link_cap
.lane_count
,
1946 max_link_cap
.link_rate
);
1948 return max_link_cap
;
1951 enum dc_status
read_hpd_rx_irq_data(
1952 struct dc_link
*link
,
1953 union hpd_irq_data
*irq_data
)
1955 static enum dc_status retval
;
1957 /* The HW reads 16 bytes from 200h on HPD,
1958 * but if we get an AUX_DEFER, the HW cannot retry
1959 * and this causes the CTS tests 4.3.2.1 - 3.2.4 to
1960 * fail, so we now explicitly read 6 bytes which is
1961 * the req from the above mentioned test cases.
1963 * For DP 1.4 we need to read those from 2002h range.
1965 if (link
->dpcd_caps
.dpcd_rev
.raw
< DPCD_REV_14
)
1966 retval
= core_link_read_dpcd(
1970 sizeof(union hpd_irq_data
));
1972 /* Read 14 bytes in a single read and then copy only the required fields.
1973 * This is more efficient than doing it in two separate AUX reads. */
1975 uint8_t tmp
[DP_SINK_STATUS_ESI
- DP_SINK_COUNT_ESI
+ 1];
1977 retval
= core_link_read_dpcd(
1983 if (retval
!= DC_OK
)
1986 irq_data
->bytes
.sink_cnt
.raw
= tmp
[DP_SINK_COUNT_ESI
- DP_SINK_COUNT_ESI
];
1987 irq_data
->bytes
.device_service_irq
.raw
= tmp
[DP_DEVICE_SERVICE_IRQ_VECTOR_ESI0
- DP_SINK_COUNT_ESI
];
1988 irq_data
->bytes
.lane01_status
.raw
= tmp
[DP_LANE0_1_STATUS_ESI
- DP_SINK_COUNT_ESI
];
1989 irq_data
->bytes
.lane23_status
.raw
= tmp
[DP_LANE2_3_STATUS_ESI
- DP_SINK_COUNT_ESI
];
1990 irq_data
->bytes
.lane_status_updated
.raw
= tmp
[DP_LANE_ALIGN_STATUS_UPDATED_ESI
- DP_SINK_COUNT_ESI
];
1991 irq_data
->bytes
.sink_status
.raw
= tmp
[DP_SINK_STATUS_ESI
- DP_SINK_COUNT_ESI
];
1997 static bool hpd_rx_irq_check_link_loss_status(
1998 struct dc_link
*link
,
1999 union hpd_irq_data
*hpd_irq_dpcd_data
)
2001 uint8_t irq_reg_rx_power_state
= 0;
2002 enum dc_status dpcd_result
= DC_ERROR_UNEXPECTED
;
2003 union lane_status lane_status
;
2005 bool sink_status_changed
;
2008 sink_status_changed
= false;
2009 return_code
= false;
2011 if (link
->cur_link_settings
.lane_count
== 0)
2014 /*1. Check that Link Status changed, before re-training.*/
2016 /*parse lane status*/
2017 for (lane
= 0; lane
< link
->cur_link_settings
.lane_count
; lane
++) {
2018 /* check status of lanes 0,1
2019 * changed DpcdAddress_Lane01Status (0x202)
2021 lane_status
.raw
= get_nibble_at_index(
2022 &hpd_irq_dpcd_data
->bytes
.lane01_status
.raw
,
2025 if (!lane_status
.bits
.CHANNEL_EQ_DONE_0
||
2026 !lane_status
.bits
.CR_DONE_0
||
2027 !lane_status
.bits
.SYMBOL_LOCKED_0
) {
2028 /* if one of the channel equalization, clock
2029 * recovery or symbol lock is dropped
2030 * consider it as (link has been
2031 * dropped) dp sink status has changed
2033 sink_status_changed
= true;
2038 /* Check interlane align.*/
2039 if (sink_status_changed
||
2040 !hpd_irq_dpcd_data
->bytes
.lane_status_updated
.bits
.INTERLANE_ALIGN_DONE
) {
2042 DC_LOG_HW_HPD_IRQ("%s: Link Status changed.\n", __func__
);
2046 /*2. Check that we can handle interrupt: Not in FS DOS,
2047 * Not in "Display Timeout" state, Link is trained.
2049 dpcd_result
= core_link_read_dpcd(link
,
2051 &irq_reg_rx_power_state
,
2052 sizeof(irq_reg_rx_power_state
));
2054 if (dpcd_result
!= DC_OK
) {
2055 DC_LOG_HW_HPD_IRQ("%s: DPCD read failed to obtain power state.\n",
2058 if (irq_reg_rx_power_state
!= DP_SET_POWER_D0
)
2059 return_code
= false;
2066 bool dp_verify_link_cap(
2067 struct dc_link
*link
,
2068 struct dc_link_settings
*known_limit_link_setting
,
2071 struct dc_link_settings max_link_cap
= {0};
2072 struct dc_link_settings cur_link_setting
= {0};
2073 struct dc_link_settings
*cur
= &cur_link_setting
;
2074 struct dc_link_settings initial_link_settings
= {0};
2076 bool skip_link_training
;
2077 bool skip_video_pattern
;
2078 enum clock_source_id dp_cs_id
= CLOCK_SOURCE_ID_EXTERNAL
;
2079 enum link_training_result status
;
2080 union hpd_irq_data irq_data
;
2082 if (link
->dc
->debug
.skip_detection_link_training
) {
2083 link
->verified_link_cap
= *known_limit_link_setting
;
2087 memset(&irq_data
, 0, sizeof(irq_data
));
2089 skip_link_training
= false;
2091 max_link_cap
= get_max_link_cap(link
);
2093 /* Grant extended timeout request */
2094 if ((link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
) && (link
->dpcd_caps
.lttpr_caps
.max_ext_timeout
> 0)) {
2095 uint8_t grant
= link
->dpcd_caps
.lttpr_caps
.max_ext_timeout
& 0x80;
2097 core_link_write_dpcd(link
, DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT
, &grant
, sizeof(grant
));
2100 /* TODO implement override and monitor patch later */
2102 /* try to train the link from high to low to
2103 * find the physical link capability
2105 /* disable PHY done possible by BIOS, will be done by driver itself */
2106 dp_disable_link_phy(link
, link
->connector_signal
);
2108 dp_cs_id
= get_clock_source_id(link
);
2110 /* link training starts with the maximum common settings
2111 * supported by both sink and ASIC.
2113 initial_link_settings
= get_common_supported_link_settings(
2114 *known_limit_link_setting
,
2116 cur_link_setting
= initial_link_settings
;
2118 /* Temporary Renoir-specific workaround for SWDEV-215184;
2119 * PHY will sometimes be in bad state on hotplugging display from certain USB-C dongle,
2120 * so add extra cycle of enabling and disabling the PHY before first link training.
2122 if (link
->link_enc
->features
.flags
.bits
.DP_IS_USB_C
&&
2123 link
->dc
->debug
.usbc_combo_phy_reset_wa
) {
2124 dp_enable_link_phy(link
, link
->connector_signal
, dp_cs_id
, cur
);
2125 dp_disable_link_phy(link
, link
->connector_signal
);
2129 skip_video_pattern
= true;
2131 if (cur
->link_rate
== LINK_RATE_LOW
)
2132 skip_video_pattern
= false;
2136 link
->connector_signal
,
2141 if (skip_link_training
)
2144 status
= dc_link_dp_perform_link_training(
2147 skip_video_pattern
);
2148 if (status
== LINK_TRAINING_SUCCESS
)
2155 link
->verified_link_cap
= *cur
;
2157 if (read_hpd_rx_irq_data(link
, &irq_data
) == DC_OK
)
2158 if (hpd_rx_irq_check_link_loss_status(
2163 /* always disable the link before trying another
2164 * setting or before returning we'll enable it later
2165 * based on the actual mode we're driving
2167 dp_disable_link_phy(link
, link
->connector_signal
);
2168 } while (!success
&& decide_fallback_link_setting(
2169 initial_link_settings
, cur
, status
));
2171 /* Link Training failed for all Link Settings
2172 * (Lane Count is still unknown)
2175 /* If all LT fails for all settings,
2176 * set verified = failed safe (1 lane low)
2178 link
->verified_link_cap
.lane_count
= LANE_COUNT_ONE
;
2179 link
->verified_link_cap
.link_rate
= LINK_RATE_LOW
;
2181 link
->verified_link_cap
.link_spread
=
2182 LINK_SPREAD_DISABLED
;
2189 bool dp_verify_link_cap_with_retries(
2190 struct dc_link
*link
,
2191 struct dc_link_settings
*known_limit_link_setting
,
2195 bool success
= false;
2197 for (i
= 0; i
< attempts
; i
++) {
2199 enum dc_connection_type type
= dc_connection_none
;
2201 memset(&link
->verified_link_cap
, 0,
2202 sizeof(struct dc_link_settings
));
2203 if (!dc_link_detect_sink(link
, &type
) || type
== dc_connection_none
) {
2204 link
->verified_link_cap
.lane_count
= LANE_COUNT_ONE
;
2205 link
->verified_link_cap
.link_rate
= LINK_RATE_LOW
;
2206 link
->verified_link_cap
.link_spread
= LINK_SPREAD_DISABLED
;
2208 } else if (dp_verify_link_cap(link
,
2209 &link
->reported_link_cap
,
2210 &fail_count
) && fail_count
== 0) {
2219 bool dp_verify_mst_link_cap(
2220 struct dc_link
*link
)
2222 struct dc_link_settings max_link_cap
= {0};
2224 max_link_cap
= get_max_link_cap(link
);
2225 link
->verified_link_cap
= get_common_supported_link_settings(
2226 link
->reported_link_cap
,
2232 static struct dc_link_settings
get_common_supported_link_settings(
2233 struct dc_link_settings link_setting_a
,
2234 struct dc_link_settings link_setting_b
)
2236 struct dc_link_settings link_settings
= {0};
2238 link_settings
.lane_count
=
2239 (link_setting_a
.lane_count
<=
2240 link_setting_b
.lane_count
) ?
2241 link_setting_a
.lane_count
:
2242 link_setting_b
.lane_count
;
2243 link_settings
.link_rate
=
2244 (link_setting_a
.link_rate
<=
2245 link_setting_b
.link_rate
) ?
2246 link_setting_a
.link_rate
:
2247 link_setting_b
.link_rate
;
2248 link_settings
.link_spread
= LINK_SPREAD_DISABLED
;
2250 /* in DP compliance test, DPR-120 may have
2251 * a random value in its MAX_LINK_BW dpcd field.
2252 * We map it to the maximum supported link rate that
2253 * is smaller than MAX_LINK_BW in this case.
2255 if (link_settings
.link_rate
> LINK_RATE_HIGH3
) {
2256 link_settings
.link_rate
= LINK_RATE_HIGH3
;
2257 } else if (link_settings
.link_rate
< LINK_RATE_HIGH3
2258 && link_settings
.link_rate
> LINK_RATE_HIGH2
) {
2259 link_settings
.link_rate
= LINK_RATE_HIGH2
;
2260 } else if (link_settings
.link_rate
< LINK_RATE_HIGH2
2261 && link_settings
.link_rate
> LINK_RATE_HIGH
) {
2262 link_settings
.link_rate
= LINK_RATE_HIGH
;
2263 } else if (link_settings
.link_rate
< LINK_RATE_HIGH
2264 && link_settings
.link_rate
> LINK_RATE_LOW
) {
2265 link_settings
.link_rate
= LINK_RATE_LOW
;
2266 } else if (link_settings
.link_rate
< LINK_RATE_LOW
) {
2267 link_settings
.link_rate
= LINK_RATE_UNKNOWN
;
2270 return link_settings
;
2273 static inline bool reached_minimum_lane_count(enum dc_lane_count lane_count
)
2275 return lane_count
<= LANE_COUNT_ONE
;
2278 static inline bool reached_minimum_link_rate(enum dc_link_rate link_rate
)
2280 return link_rate
<= LINK_RATE_LOW
;
2283 static enum dc_lane_count
reduce_lane_count(enum dc_lane_count lane_count
)
2285 switch (lane_count
) {
2286 case LANE_COUNT_FOUR
:
2287 return LANE_COUNT_TWO
;
2288 case LANE_COUNT_TWO
:
2289 return LANE_COUNT_ONE
;
2290 case LANE_COUNT_ONE
:
2291 return LANE_COUNT_UNKNOWN
;
2293 return LANE_COUNT_UNKNOWN
;
2297 static enum dc_link_rate
reduce_link_rate(enum dc_link_rate link_rate
)
2299 switch (link_rate
) {
2300 case LINK_RATE_HIGH3
:
2301 return LINK_RATE_HIGH2
;
2302 case LINK_RATE_HIGH2
:
2303 return LINK_RATE_HIGH
;
2304 case LINK_RATE_HIGH
:
2305 return LINK_RATE_LOW
;
2307 return LINK_RATE_UNKNOWN
;
2309 return LINK_RATE_UNKNOWN
;
2313 static enum dc_lane_count
increase_lane_count(enum dc_lane_count lane_count
)
2315 switch (lane_count
) {
2316 case LANE_COUNT_ONE
:
2317 return LANE_COUNT_TWO
;
2318 case LANE_COUNT_TWO
:
2319 return LANE_COUNT_FOUR
;
2321 return LANE_COUNT_UNKNOWN
;
2325 static enum dc_link_rate
increase_link_rate(enum dc_link_rate link_rate
)
2327 switch (link_rate
) {
2329 return LINK_RATE_HIGH
;
2330 case LINK_RATE_HIGH
:
2331 return LINK_RATE_HIGH2
;
2332 case LINK_RATE_HIGH2
:
2333 return LINK_RATE_HIGH3
;
2335 return LINK_RATE_UNKNOWN
;
2340 * function: set link rate and lane count fallback based
2341 * on current link setting and last link training result
2343 * true - link setting could be set
2344 * false - has reached minimum setting
2345 * and no further fallback could be done
2347 static bool decide_fallback_link_setting(
2348 struct dc_link_settings initial_link_settings
,
2349 struct dc_link_settings
*current_link_setting
,
2350 enum link_training_result training_result
)
2352 if (!current_link_setting
)
2355 switch (training_result
) {
2356 case LINK_TRAINING_CR_FAIL_LANE0
:
2357 case LINK_TRAINING_CR_FAIL_LANE1
:
2358 case LINK_TRAINING_CR_FAIL_LANE23
:
2359 case LINK_TRAINING_LQA_FAIL
:
2361 if (!reached_minimum_link_rate
2362 (current_link_setting
->link_rate
)) {
2363 current_link_setting
->link_rate
=
2365 current_link_setting
->link_rate
);
2366 } else if (!reached_minimum_lane_count
2367 (current_link_setting
->lane_count
)) {
2368 current_link_setting
->link_rate
=
2369 initial_link_settings
.link_rate
;
2370 if (training_result
== LINK_TRAINING_CR_FAIL_LANE0
)
2372 else if (training_result
== LINK_TRAINING_CR_FAIL_LANE1
)
2373 current_link_setting
->lane_count
=
2375 else if (training_result
==
2376 LINK_TRAINING_CR_FAIL_LANE23
)
2377 current_link_setting
->lane_count
=
2380 current_link_setting
->lane_count
=
2382 current_link_setting
->lane_count
);
2388 case LINK_TRAINING_EQ_FAIL_EQ
:
2390 if (!reached_minimum_lane_count
2391 (current_link_setting
->lane_count
)) {
2392 current_link_setting
->lane_count
=
2394 current_link_setting
->lane_count
);
2395 } else if (!reached_minimum_link_rate
2396 (current_link_setting
->link_rate
)) {
2397 current_link_setting
->link_rate
=
2399 current_link_setting
->link_rate
);
2405 case LINK_TRAINING_EQ_FAIL_CR
:
2407 if (!reached_minimum_link_rate
2408 (current_link_setting
->link_rate
)) {
2409 current_link_setting
->link_rate
=
2411 current_link_setting
->link_rate
);
2423 bool dp_validate_mode_timing(
2424 struct dc_link
*link
,
2425 const struct dc_crtc_timing
*timing
)
2430 const struct dc_link_settings
*link_setting
;
2432 /*always DP fail safe mode*/
2433 if ((timing
->pix_clk_100hz
/ 10) == (uint32_t) 25175 &&
2434 timing
->h_addressable
== (uint32_t) 640 &&
2435 timing
->v_addressable
== (uint32_t) 480)
2438 link_setting
= dc_link_get_link_cap(link
);
2440 /* TODO: DYNAMIC_VALIDATION needs to be implemented */
2441 /*if (flags.DYNAMIC_VALIDATION == 1 &&
2442 link->verified_link_cap.lane_count != LANE_COUNT_UNKNOWN)
2443 link_setting = &link->verified_link_cap;
2446 req_bw
= dc_bandwidth_in_kbps_from_timing(timing
);
2447 max_bw
= dc_link_bandwidth_kbps(link
, link_setting
);
2449 if (req_bw
<= max_bw
) {
2450 /* remember the biggest mode here, during
2451 * initial link training (to get
2452 * verified_link_cap), LS sends event about
2453 * cannot train at reported cap to upper
2454 * layer and upper layer will re-enumerate modes.
2455 * this is not necessary if the lower
2456 * verified_link_cap is enough to drive
2459 /* TODO: DYNAMIC_VALIDATION needs to be implemented */
2460 /* if (flags.DYNAMIC_VALIDATION == 1)
2461 dpsst->max_req_bw_for_verified_linkcap = dal_max(
2462 dpsst->max_req_bw_for_verified_linkcap, req_bw); */
2468 static bool decide_dp_link_settings(struct dc_link
*link
, struct dc_link_settings
*link_setting
, uint32_t req_bw
)
2470 struct dc_link_settings initial_link_setting
= {
2471 LANE_COUNT_ONE
, LINK_RATE_LOW
, LINK_SPREAD_DISABLED
, false, 0};
2472 struct dc_link_settings current_link_setting
=
2473 initial_link_setting
;
2476 if (req_bw
> dc_link_bandwidth_kbps(link
, &link
->verified_link_cap
))
2479 /* search for the minimum link setting that:
2480 * 1. is supported according to the link training result
2481 * 2. could support the b/w requested by the timing
2483 while (current_link_setting
.link_rate
<=
2484 link
->verified_link_cap
.link_rate
) {
2485 link_bw
= dc_link_bandwidth_kbps(
2487 ¤t_link_setting
);
2488 if (req_bw
<= link_bw
) {
2489 *link_setting
= current_link_setting
;
2493 if (current_link_setting
.lane_count
<
2494 link
->verified_link_cap
.lane_count
) {
2495 current_link_setting
.lane_count
=
2496 increase_lane_count(
2497 current_link_setting
.lane_count
);
2499 current_link_setting
.link_rate
=
2501 current_link_setting
.link_rate
);
2502 current_link_setting
.lane_count
=
2503 initial_link_setting
.lane_count
;
2510 bool decide_edp_link_settings(struct dc_link
*link
, struct dc_link_settings
*link_setting
, uint32_t req_bw
)
2512 struct dc_link_settings initial_link_setting
;
2513 struct dc_link_settings current_link_setting
;
2516 if (link
->dpcd_caps
.dpcd_rev
.raw
< DPCD_REV_14
||
2517 link
->dpcd_caps
.edp_supported_link_rates_count
== 0) {
2518 *link_setting
= link
->verified_link_cap
;
2522 memset(&initial_link_setting
, 0, sizeof(initial_link_setting
));
2523 initial_link_setting
.lane_count
= LANE_COUNT_ONE
;
2524 initial_link_setting
.link_rate
= link
->dpcd_caps
.edp_supported_link_rates
[0];
2525 initial_link_setting
.link_spread
= LINK_SPREAD_DISABLED
;
2526 initial_link_setting
.use_link_rate_set
= true;
2527 initial_link_setting
.link_rate_set
= 0;
2528 current_link_setting
= initial_link_setting
;
2530 /* search for the minimum link setting that:
2531 * 1. is supported according to the link training result
2532 * 2. could support the b/w requested by the timing
2534 while (current_link_setting
.link_rate
<=
2535 link
->verified_link_cap
.link_rate
) {
2536 link_bw
= dc_link_bandwidth_kbps(
2538 ¤t_link_setting
);
2539 if (req_bw
<= link_bw
) {
2540 *link_setting
= current_link_setting
;
2544 if (current_link_setting
.lane_count
<
2545 link
->verified_link_cap
.lane_count
) {
2546 current_link_setting
.lane_count
=
2547 increase_lane_count(
2548 current_link_setting
.lane_count
);
2550 if (current_link_setting
.link_rate_set
< link
->dpcd_caps
.edp_supported_link_rates_count
) {
2551 current_link_setting
.link_rate_set
++;
2552 current_link_setting
.link_rate
=
2553 link
->dpcd_caps
.edp_supported_link_rates
[current_link_setting
.link_rate_set
];
2554 current_link_setting
.lane_count
=
2555 initial_link_setting
.lane_count
;
2563 static bool decide_mst_link_settings(const struct dc_link
*link
, struct dc_link_settings
*link_setting
)
2565 *link_setting
= link
->verified_link_cap
;
2569 void decide_link_settings(struct dc_stream_state
*stream
,
2570 struct dc_link_settings
*link_setting
)
2572 struct dc_link
*link
;
2575 req_bw
= dc_bandwidth_in_kbps_from_timing(&stream
->timing
);
2577 link
= stream
->link
;
2579 /* if preferred is specified through AMDDP, use it, if it's enough
2582 if (link
->preferred_link_setting
.lane_count
!=
2583 LANE_COUNT_UNKNOWN
&&
2584 link
->preferred_link_setting
.link_rate
!=
2585 LINK_RATE_UNKNOWN
) {
2586 *link_setting
= link
->preferred_link_setting
;
2590 /* MST doesn't perform link training for now
2591 * TODO: add MST specific link training routine
2593 if (stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
2594 if (decide_mst_link_settings(link
, link_setting
))
2596 } else if (link
->connector_signal
== SIGNAL_TYPE_EDP
) {
2597 if (decide_edp_link_settings(link
, link_setting
, req_bw
))
2599 } else if (decide_dp_link_settings(link
, link_setting
, req_bw
))
2602 BREAK_TO_DEBUGGER();
2603 ASSERT(link
->verified_link_cap
.lane_count
!= LANE_COUNT_UNKNOWN
);
2605 *link_setting
= link
->verified_link_cap
;
2608 /*************************Short Pulse IRQ***************************/
2609 static bool allow_hpd_rx_irq(const struct dc_link
*link
)
2612 * Don't handle RX IRQ unless one of following is met:
2613 * 1) The link is established (cur_link_settings != unknown)
2614 * 2) We kicked off MST detection
2615 * 3) We know we're dealing with an active dongle
2618 if ((link
->cur_link_settings
.lane_count
!= LANE_COUNT_UNKNOWN
) ||
2619 (link
->type
== dc_connection_mst_branch
) ||
2620 is_dp_active_dongle(link
))
2626 static bool handle_hpd_irq_psr_sink(struct dc_link
*link
)
2628 union dpcd_psr_configuration psr_configuration
;
2630 if (!link
->psr_settings
.psr_feature_enabled
)
2633 dm_helpers_dp_read_dpcd(
2636 368,/*DpcdAddress_PSR_Enable_Cfg*/
2637 &psr_configuration
.raw
,
2638 sizeof(psr_configuration
.raw
));
2641 if (psr_configuration
.bits
.ENABLE
) {
2642 unsigned char dpcdbuf
[3] = {0};
2643 union psr_error_status psr_error_status
;
2644 union psr_sink_psr_status psr_sink_psr_status
;
2646 dm_helpers_dp_read_dpcd(
2649 0x2006, /*DpcdAddress_PSR_Error_Status*/
2650 (unsigned char *) dpcdbuf
,
2653 /*DPCD 2006h ERROR STATUS*/
2654 psr_error_status
.raw
= dpcdbuf
[0];
2655 /*DPCD 2008h SINK PANEL SELF REFRESH STATUS*/
2656 psr_sink_psr_status
.raw
= dpcdbuf
[2];
2658 if (psr_error_status
.bits
.LINK_CRC_ERROR
||
2659 psr_error_status
.bits
.RFB_STORAGE_ERROR
||
2660 psr_error_status
.bits
.VSC_SDP_ERROR
) {
2661 /* Acknowledge and clear error bits */
2662 dm_helpers_dp_write_dpcd(
2665 8198,/*DpcdAddress_PSR_Error_Status*/
2666 &psr_error_status
.raw
,
2667 sizeof(psr_error_status
.raw
));
2669 /* PSR error, disable and re-enable PSR */
2670 dc_link_set_psr_allow_active(link
, false, true, false);
2671 dc_link_set_psr_allow_active(link
, true, true, false);
2674 } else if (psr_sink_psr_status
.bits
.SINK_SELF_REFRESH_STATUS
==
2675 PSR_SINK_STATE_ACTIVE_DISPLAY_FROM_SINK_RFB
){
2676 /* No error is detect, PSR is active.
2677 * We should return with IRQ_HPD handled without
2678 * checking for loss of sync since PSR would have
2679 * powered down main link.
2687 static void dp_test_send_link_training(struct dc_link
*link
)
2689 struct dc_link_settings link_settings
= {0};
2691 core_link_read_dpcd(
2694 (unsigned char *)(&link_settings
.lane_count
),
2696 core_link_read_dpcd(
2699 (unsigned char *)(&link_settings
.link_rate
),
2702 /* Set preferred link settings */
2703 link
->verified_link_cap
.lane_count
= link_settings
.lane_count
;
2704 link
->verified_link_cap
.link_rate
= link_settings
.link_rate
;
2706 dp_retrain_link_dp_test(link
, &link_settings
, false);
2709 /* TODO Raven hbr2 compliance eye output is unstable
2710 * (toggling on and off) with debugger break
2711 * This caueses intermittent PHY automation failure
2712 * Need to look into the root cause */
2713 static void dp_test_send_phy_test_pattern(struct dc_link
*link
)
2715 union phy_test_pattern dpcd_test_pattern
;
2716 union lane_adjust dpcd_lane_adjustment
[2];
2717 unsigned char dpcd_post_cursor_2_adjustment
= 0;
2718 unsigned char test_80_bit_pattern
[
2719 (DP_TEST_80BIT_CUSTOM_PATTERN_79_72
-
2720 DP_TEST_80BIT_CUSTOM_PATTERN_7_0
)+1] = {0};
2721 enum dp_test_pattern test_pattern
;
2722 struct dc_link_training_settings link_settings
;
2723 union lane_adjust dpcd_lane_adjust
;
2725 struct link_training_settings link_training_settings
;
2728 dpcd_test_pattern
.raw
= 0;
2729 memset(dpcd_lane_adjustment
, 0, sizeof(dpcd_lane_adjustment
));
2730 memset(&link_settings
, 0, sizeof(link_settings
));
2732 /* get phy test pattern and pattern parameters from DP receiver */
2733 core_link_read_dpcd(
2735 DP_PHY_TEST_PATTERN
,
2736 &dpcd_test_pattern
.raw
,
2737 sizeof(dpcd_test_pattern
));
2738 core_link_read_dpcd(
2740 DP_ADJUST_REQUEST_LANE0_1
,
2741 &dpcd_lane_adjustment
[0].raw
,
2742 sizeof(dpcd_lane_adjustment
));
2744 /*get post cursor 2 parameters
2745 * For DP 1.1a or eariler, this DPCD register's value is 0
2746 * For DP 1.2 or later:
2747 * Bits 1:0 = POST_CURSOR2_LANE0; Bits 3:2 = POST_CURSOR2_LANE1
2748 * Bits 5:4 = POST_CURSOR2_LANE2; Bits 7:6 = POST_CURSOR2_LANE3
2750 core_link_read_dpcd(
2752 DP_ADJUST_REQUEST_POST_CURSOR2
,
2753 &dpcd_post_cursor_2_adjustment
,
2754 sizeof(dpcd_post_cursor_2_adjustment
));
2756 /* translate request */
2757 switch (dpcd_test_pattern
.bits
.PATTERN
) {
2758 case PHY_TEST_PATTERN_D10_2
:
2759 test_pattern
= DP_TEST_PATTERN_D102
;
2761 case PHY_TEST_PATTERN_SYMBOL_ERROR
:
2762 test_pattern
= DP_TEST_PATTERN_SYMBOL_ERROR
;
2764 case PHY_TEST_PATTERN_PRBS7
:
2765 test_pattern
= DP_TEST_PATTERN_PRBS7
;
2767 case PHY_TEST_PATTERN_80BIT_CUSTOM
:
2768 test_pattern
= DP_TEST_PATTERN_80BIT_CUSTOM
;
2770 case PHY_TEST_PATTERN_CP2520_1
:
2771 /* CP2520 pattern is unstable, temporarily use TPS4 instead */
2772 test_pattern
= (link
->dc
->caps
.force_dp_tps4_for_cp2520
== 1) ?
2773 DP_TEST_PATTERN_TRAINING_PATTERN4
:
2774 DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
;
2776 case PHY_TEST_PATTERN_CP2520_2
:
2777 /* CP2520 pattern is unstable, temporarily use TPS4 instead */
2778 test_pattern
= (link
->dc
->caps
.force_dp_tps4_for_cp2520
== 1) ?
2779 DP_TEST_PATTERN_TRAINING_PATTERN4
:
2780 DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE
;
2782 case PHY_TEST_PATTERN_CP2520_3
:
2783 test_pattern
= DP_TEST_PATTERN_TRAINING_PATTERN4
;
2786 test_pattern
= DP_TEST_PATTERN_VIDEO_MODE
;
2790 if (test_pattern
== DP_TEST_PATTERN_80BIT_CUSTOM
)
2791 core_link_read_dpcd(
2793 DP_TEST_80BIT_CUSTOM_PATTERN_7_0
,
2794 test_80_bit_pattern
,
2795 sizeof(test_80_bit_pattern
));
2797 /* prepare link training settings */
2798 link_settings
.link
= link
->cur_link_settings
;
2800 for (lane
= 0; lane
<
2801 (unsigned int)(link
->cur_link_settings
.lane_count
);
2803 dpcd_lane_adjust
.raw
=
2804 get_nibble_at_index(&dpcd_lane_adjustment
[0].raw
, lane
);
2805 link_settings
.lane_settings
[lane
].VOLTAGE_SWING
=
2806 (enum dc_voltage_swing
)
2807 (dpcd_lane_adjust
.bits
.VOLTAGE_SWING_LANE
);
2808 link_settings
.lane_settings
[lane
].PRE_EMPHASIS
=
2809 (enum dc_pre_emphasis
)
2810 (dpcd_lane_adjust
.bits
.PRE_EMPHASIS_LANE
);
2811 link_settings
.lane_settings
[lane
].POST_CURSOR2
=
2812 (enum dc_post_cursor2
)
2813 ((dpcd_post_cursor_2_adjustment
>> (lane
* 2)) & 0x03);
2816 for (i
= 0; i
< 4; i
++)
2817 link_training_settings
.lane_settings
[i
] =
2818 link_settings
.lane_settings
[i
];
2819 link_training_settings
.link_settings
= link_settings
.link
;
2820 link_training_settings
.allow_invalid_msa_timing_param
= false;
2821 /*Usage: Measure DP physical lane signal
2822 * by DP SI test equipment automatically.
2823 * PHY test pattern request is generated by equipment via HPD interrupt.
2824 * HPD needs to be active all the time. HPD should be active
2825 * all the time. Do not touch it.
2826 * forward request to DS
2828 dc_link_dp_set_test_pattern(
2831 DP_TEST_PATTERN_COLOR_SPACE_UNDEFINED
,
2832 &link_training_settings
,
2833 test_80_bit_pattern
,
2834 (DP_TEST_80BIT_CUSTOM_PATTERN_79_72
-
2835 DP_TEST_80BIT_CUSTOM_PATTERN_7_0
)+1);
2838 static void dp_test_send_link_test_pattern(struct dc_link
*link
)
2840 union link_test_pattern dpcd_test_pattern
;
2841 union test_misc dpcd_test_params
;
2842 enum dp_test_pattern test_pattern
;
2843 enum dp_test_pattern_color_space test_pattern_color_space
=
2844 DP_TEST_PATTERN_COLOR_SPACE_UNDEFINED
;
2845 enum dc_color_depth requestColorDepth
= COLOR_DEPTH_UNDEFINED
;
2846 struct pipe_ctx
*pipes
= link
->dc
->current_state
->res_ctx
.pipe_ctx
;
2847 struct pipe_ctx
*pipe_ctx
= NULL
;
2850 memset(&dpcd_test_pattern
, 0, sizeof(dpcd_test_pattern
));
2851 memset(&dpcd_test_params
, 0, sizeof(dpcd_test_params
));
2853 for (i
= 0; i
< MAX_PIPES
; i
++) {
2854 if (pipes
[i
].stream
== NULL
)
2857 if (pipes
[i
].stream
->link
== link
&& !pipes
[i
].top_pipe
&& !pipes
[i
].prev_odm_pipe
) {
2858 pipe_ctx
= &pipes
[i
];
2863 if (pipe_ctx
== NULL
)
2866 /* get link test pattern and pattern parameters */
2867 core_link_read_dpcd(
2870 &dpcd_test_pattern
.raw
,
2871 sizeof(dpcd_test_pattern
));
2872 core_link_read_dpcd(
2875 &dpcd_test_params
.raw
,
2876 sizeof(dpcd_test_params
));
2878 switch (dpcd_test_pattern
.bits
.PATTERN
) {
2879 case LINK_TEST_PATTERN_COLOR_RAMP
:
2880 test_pattern
= DP_TEST_PATTERN_COLOR_RAMP
;
2882 case LINK_TEST_PATTERN_VERTICAL_BARS
:
2883 test_pattern
= DP_TEST_PATTERN_VERTICAL_BARS
;
2884 break; /* black and white */
2885 case LINK_TEST_PATTERN_COLOR_SQUARES
:
2886 test_pattern
= (dpcd_test_params
.bits
.DYN_RANGE
==
2887 TEST_DYN_RANGE_VESA
?
2888 DP_TEST_PATTERN_COLOR_SQUARES
:
2889 DP_TEST_PATTERN_COLOR_SQUARES_CEA
);
2892 test_pattern
= DP_TEST_PATTERN_VIDEO_MODE
;
2896 if (dpcd_test_params
.bits
.CLR_FORMAT
== 0)
2897 test_pattern_color_space
= DP_TEST_PATTERN_COLOR_SPACE_RGB
;
2899 test_pattern_color_space
= dpcd_test_params
.bits
.YCBCR_COEFS
?
2900 DP_TEST_PATTERN_COLOR_SPACE_YCBCR709
:
2901 DP_TEST_PATTERN_COLOR_SPACE_YCBCR601
;
2903 switch (dpcd_test_params
.bits
.BPC
) {
2905 requestColorDepth
= COLOR_DEPTH_666
;
2908 requestColorDepth
= COLOR_DEPTH_888
;
2911 requestColorDepth
= COLOR_DEPTH_101010
;
2914 requestColorDepth
= COLOR_DEPTH_121212
;
2920 if (requestColorDepth
!= COLOR_DEPTH_UNDEFINED
2921 && pipe_ctx
->stream
->timing
.display_color_depth
!= requestColorDepth
) {
2922 DC_LOG_DEBUG("%s: original bpc %d, changing to %d\n",
2924 pipe_ctx
->stream
->timing
.display_color_depth
,
2926 pipe_ctx
->stream
->timing
.display_color_depth
= requestColorDepth
;
2927 dp_update_dsc_config(pipe_ctx
);
2930 dc_link_dp_set_test_pattern(
2933 test_pattern_color_space
,
2939 static void dp_test_get_audio_test_data(struct dc_link
*link
, bool disable_video
)
2941 union audio_test_mode dpcd_test_mode
= {0};
2942 struct audio_test_pattern_type dpcd_pattern_type
= {0};
2943 union audio_test_pattern_period dpcd_pattern_period
[AUDIO_CHANNELS_COUNT
] = {0};
2944 enum dp_test_pattern test_pattern
= DP_TEST_PATTERN_AUDIO_OPERATOR_DEFINED
;
2946 struct pipe_ctx
*pipes
= link
->dc
->current_state
->res_ctx
.pipe_ctx
;
2947 struct pipe_ctx
*pipe_ctx
= &pipes
[0];
2948 unsigned int channel_count
;
2949 unsigned int channel
= 0;
2950 unsigned int modes
= 0;
2951 unsigned int sampling_rate_in_hz
= 0;
2953 // get audio test mode and test pattern parameters
2954 core_link_read_dpcd(
2957 &dpcd_test_mode
.raw
,
2958 sizeof(dpcd_test_mode
));
2960 core_link_read_dpcd(
2962 DP_TEST_AUDIO_PATTERN_TYPE
,
2963 &dpcd_pattern_type
.value
,
2964 sizeof(dpcd_pattern_type
));
2966 channel_count
= dpcd_test_mode
.bits
.channel_count
+ 1;
2968 // read pattern periods for requested channels when sawTooth pattern is requested
2969 if (dpcd_pattern_type
.value
== AUDIO_TEST_PATTERN_SAWTOOTH
||
2970 dpcd_pattern_type
.value
== AUDIO_TEST_PATTERN_OPERATOR_DEFINED
) {
2972 test_pattern
= (dpcd_pattern_type
.value
== AUDIO_TEST_PATTERN_SAWTOOTH
) ?
2973 DP_TEST_PATTERN_AUDIO_SAWTOOTH
: DP_TEST_PATTERN_AUDIO_OPERATOR_DEFINED
;
2974 // read period for each channel
2975 for (channel
= 0; channel
< channel_count
; channel
++) {
2976 core_link_read_dpcd(
2978 DP_TEST_AUDIO_PERIOD_CH1
+ channel
,
2979 &dpcd_pattern_period
[channel
].raw
,
2980 sizeof(dpcd_pattern_period
[channel
]));
2984 // translate sampling rate
2985 switch (dpcd_test_mode
.bits
.sampling_rate
) {
2986 case AUDIO_SAMPLING_RATE_32KHZ
:
2987 sampling_rate_in_hz
= 32000;
2989 case AUDIO_SAMPLING_RATE_44_1KHZ
:
2990 sampling_rate_in_hz
= 44100;
2992 case AUDIO_SAMPLING_RATE_48KHZ
:
2993 sampling_rate_in_hz
= 48000;
2995 case AUDIO_SAMPLING_RATE_88_2KHZ
:
2996 sampling_rate_in_hz
= 88200;
2998 case AUDIO_SAMPLING_RATE_96KHZ
:
2999 sampling_rate_in_hz
= 96000;
3001 case AUDIO_SAMPLING_RATE_176_4KHZ
:
3002 sampling_rate_in_hz
= 176400;
3004 case AUDIO_SAMPLING_RATE_192KHZ
:
3005 sampling_rate_in_hz
= 192000;
3008 sampling_rate_in_hz
= 0;
3012 link
->audio_test_data
.flags
.test_requested
= 1;
3013 link
->audio_test_data
.flags
.disable_video
= disable_video
;
3014 link
->audio_test_data
.sampling_rate
= sampling_rate_in_hz
;
3015 link
->audio_test_data
.channel_count
= channel_count
;
3016 link
->audio_test_data
.pattern_type
= test_pattern
;
3018 if (test_pattern
== DP_TEST_PATTERN_AUDIO_SAWTOOTH
) {
3019 for (modes
= 0; modes
< pipe_ctx
->stream
->audio_info
.mode_count
; modes
++) {
3020 link
->audio_test_data
.pattern_period
[modes
] = dpcd_pattern_period
[modes
].bits
.pattern_period
;
3025 static void handle_automated_test(struct dc_link
*link
)
3027 union test_request test_request
;
3028 union test_response test_response
;
3030 memset(&test_request
, 0, sizeof(test_request
));
3031 memset(&test_response
, 0, sizeof(test_response
));
3033 core_link_read_dpcd(
3037 sizeof(union test_request
));
3038 if (test_request
.bits
.LINK_TRAINING
) {
3039 /* ACK first to let DP RX test box monitor LT sequence */
3040 test_response
.bits
.ACK
= 1;
3041 core_link_write_dpcd(
3045 sizeof(test_response
));
3046 dp_test_send_link_training(link
);
3047 /* no acknowledge request is needed again */
3048 test_response
.bits
.ACK
= 0;
3050 if (test_request
.bits
.LINK_TEST_PATTRN
) {
3051 dp_test_send_link_test_pattern(link
);
3052 test_response
.bits
.ACK
= 1;
3055 if (test_request
.bits
.AUDIO_TEST_PATTERN
) {
3056 dp_test_get_audio_test_data(link
, test_request
.bits
.TEST_AUDIO_DISABLED_VIDEO
);
3057 test_response
.bits
.ACK
= 1;
3060 if (test_request
.bits
.PHY_TEST_PATTERN
) {
3061 dp_test_send_phy_test_pattern(link
);
3062 test_response
.bits
.ACK
= 1;
3065 /* send request acknowledgment */
3066 if (test_response
.bits
.ACK
)
3067 core_link_write_dpcd(
3071 sizeof(test_response
));
3074 bool dc_link_handle_hpd_rx_irq(struct dc_link
*link
, union hpd_irq_data
*out_hpd_irq_dpcd_data
, bool *out_link_loss
)
3076 union hpd_irq_data hpd_irq_dpcd_data
= { { { {0} } } };
3077 union device_service_irq device_service_clear
= { { 0 } };
3078 enum dc_status result
;
3079 bool status
= false;
3080 struct pipe_ctx
*pipe_ctx
;
3084 *out_link_loss
= false;
3085 /* For use cases related to down stream connection status change,
3086 * PSR and device auto test, refer to function handle_sst_hpd_irq
3089 DC_LOG_HW_HPD_IRQ("%s: Got short pulse HPD on link %d\n",
3090 __func__
, link
->link_index
);
3093 /* All the "handle_hpd_irq_xxx()" methods
3094 * should be called only after
3095 * dal_dpsst_ls_read_hpd_irq_data
3096 * Order of calls is important too
3098 result
= read_hpd_rx_irq_data(link
, &hpd_irq_dpcd_data
);
3099 if (out_hpd_irq_dpcd_data
)
3100 *out_hpd_irq_dpcd_data
= hpd_irq_dpcd_data
;
3102 if (result
!= DC_OK
) {
3103 DC_LOG_HW_HPD_IRQ("%s: DPCD read failed to obtain irq data\n",
3108 if (hpd_irq_dpcd_data
.bytes
.device_service_irq
.bits
.AUTOMATED_TEST
) {
3109 device_service_clear
.bits
.AUTOMATED_TEST
= 1;
3110 core_link_write_dpcd(
3112 DP_DEVICE_SERVICE_IRQ_VECTOR
,
3113 &device_service_clear
.raw
,
3114 sizeof(device_service_clear
.raw
));
3115 device_service_clear
.raw
= 0;
3116 handle_automated_test(link
);
3120 if (!allow_hpd_rx_irq(link
)) {
3121 DC_LOG_HW_HPD_IRQ("%s: skipping HPD handling on %d\n",
3122 __func__
, link
->link_index
);
3126 if (handle_hpd_irq_psr_sink(link
))
3127 /* PSR-related error was detected and handled */
3130 /* If PSR-related error handled, Main link may be off,
3131 * so do not handle as a normal sink status change interrupt.
3134 if (hpd_irq_dpcd_data
.bytes
.device_service_irq
.bits
.UP_REQ_MSG_RDY
)
3137 /* check if we have MST msg and return since we poll for it */
3138 if (hpd_irq_dpcd_data
.bytes
.device_service_irq
.bits
.DOWN_REP_MSG_RDY
)
3141 /* For now we only handle 'Downstream port status' case.
3142 * If we got sink count changed it means
3143 * Downstream port status changed,
3144 * then DM should call DC to do the detection.
3145 * NOTE: Do not handle link loss on eDP since it is internal link*/
3146 if ((link
->connector_signal
!= SIGNAL_TYPE_EDP
) &&
3147 hpd_rx_irq_check_link_loss_status(
3149 &hpd_irq_dpcd_data
)) {
3150 /* Connectivity log: link loss */
3151 CONN_DATA_LINK_LOSS(link
,
3152 hpd_irq_dpcd_data
.raw
,
3153 sizeof(hpd_irq_dpcd_data
),
3156 for (i
= 0; i
< MAX_PIPES
; i
++) {
3157 pipe_ctx
= &link
->dc
->current_state
->res_ctx
.pipe_ctx
[i
];
3158 if (pipe_ctx
&& pipe_ctx
->stream
&& pipe_ctx
->stream
->link
== link
)
3162 if (pipe_ctx
== NULL
|| pipe_ctx
->stream
== NULL
)
3166 for (i
= 0; i
< MAX_PIPES
; i
++) {
3167 pipe_ctx
= &link
->dc
->current_state
->res_ctx
.pipe_ctx
[i
];
3168 if (pipe_ctx
&& pipe_ctx
->stream
&& !pipe_ctx
->stream
->dpms_off
&&
3169 pipe_ctx
->stream
->link
== link
&& !pipe_ctx
->prev_odm_pipe
)
3170 core_link_disable_stream(pipe_ctx
);
3173 for (i
= 0; i
< MAX_PIPES
; i
++) {
3174 pipe_ctx
= &link
->dc
->current_state
->res_ctx
.pipe_ctx
[i
];
3175 if (pipe_ctx
&& pipe_ctx
->stream
&& !pipe_ctx
->stream
->dpms_off
&&
3176 pipe_ctx
->stream
->link
== link
&& !pipe_ctx
->prev_odm_pipe
)
3177 core_link_enable_stream(link
->dc
->current_state
, pipe_ctx
);
3182 *out_link_loss
= true;
3185 if (link
->type
== dc_connection_active_dongle
&&
3186 hpd_irq_dpcd_data
.bytes
.sink_cnt
.bits
.SINK_COUNT
3187 != link
->dpcd_sink_count
)
3190 /* reasons for HPD RX:
3191 * 1. Link Loss - ie Re-train the Link
3192 * 2. MST sideband message
3193 * 3. Automated Test - ie. Internal Commit
3194 * 4. CP (copy protection) - (not interesting for DM???)
3196 * 6. Downstream Port status changed
3197 * -ie. Detect - this the only one
3198 * which is interesting for DM because
3199 * it must call dc_link_detect.
3204 /*query dpcd for version and mst cap addresses*/
3205 bool is_mst_supported(struct dc_link
*link
)
3208 enum dc_status st
= DC_OK
;
3212 if (link
->preferred_training_settings
.mst_enable
&&
3213 *link
->preferred_training_settings
.mst_enable
== false) {
3220 st
= core_link_read_dpcd(link
, DP_DPCD_REV
, &rev
.raw
,
3223 if (st
== DC_OK
&& rev
.raw
>= DPCD_REV_12
) {
3225 st
= core_link_read_dpcd(link
, DP_MSTM_CAP
,
3226 &cap
.raw
, sizeof(cap
));
3227 if (st
== DC_OK
&& cap
.bits
.MST_CAP
== 1)
3234 bool is_dp_active_dongle(const struct dc_link
*link
)
3236 return link
->dpcd_caps
.is_branch_dev
;
3239 static int translate_dpcd_max_bpc(enum dpcd_downstream_port_max_bpc bpc
)
3242 case DOWN_STREAM_MAX_8BPC
:
3244 case DOWN_STREAM_MAX_10BPC
:
3246 case DOWN_STREAM_MAX_12BPC
:
3248 case DOWN_STREAM_MAX_16BPC
:
3257 static void read_dp_device_vendor_id(struct dc_link
*link
)
3259 struct dp_device_vendor_id dp_id
;
3261 /* read IEEE branch device id */
3262 core_link_read_dpcd(
3268 link
->dpcd_caps
.branch_dev_id
=
3269 (dp_id
.ieee_oui
[0] << 16) +
3270 (dp_id
.ieee_oui
[1] << 8) +
3274 link
->dpcd_caps
.branch_dev_name
,
3275 dp_id
.ieee_device_id
,
3276 sizeof(dp_id
.ieee_device_id
));
3281 static void get_active_converter_info(
3282 uint8_t data
, struct dc_link
*link
)
3284 union dp_downstream_port_present ds_port
= { .byte
= data
};
3285 memset(&link
->dpcd_caps
.dongle_caps
, 0, sizeof(link
->dpcd_caps
.dongle_caps
));
3287 /* decode converter info*/
3288 if (!ds_port
.fields
.PORT_PRESENT
) {
3289 link
->dpcd_caps
.dongle_type
= DISPLAY_DONGLE_NONE
;
3290 ddc_service_set_dongle_type(link
->ddc
,
3291 link
->dpcd_caps
.dongle_type
);
3292 link
->dpcd_caps
.is_branch_dev
= false;
3296 /* DPCD 0x5 bit 0 = 1, it indicate it's branch device */
3297 link
->dpcd_caps
.is_branch_dev
= ds_port
.fields
.PORT_PRESENT
;
3299 switch (ds_port
.fields
.PORT_TYPE
) {
3300 case DOWNSTREAM_VGA
:
3301 link
->dpcd_caps
.dongle_type
= DISPLAY_DONGLE_DP_VGA_CONVERTER
;
3303 case DOWNSTREAM_DVI_HDMI_DP_PLUS_PLUS
:
3304 /* At this point we don't know is it DVI or HDMI or DP++,
3306 link
->dpcd_caps
.dongle_type
= DISPLAY_DONGLE_DP_DVI_CONVERTER
;
3309 link
->dpcd_caps
.dongle_type
= DISPLAY_DONGLE_NONE
;
3313 if (link
->dpcd_caps
.dpcd_rev
.raw
>= DPCD_REV_11
) {
3314 uint8_t det_caps
[16]; /* CTS 4.2.2.7 expects source to read Detailed Capabilities Info : 00080h-0008F.*/
3315 union dwnstream_port_caps_byte0
*port_caps
=
3316 (union dwnstream_port_caps_byte0
*)det_caps
;
3317 if (core_link_read_dpcd(link
, DP_DOWNSTREAM_PORT_0
,
3318 det_caps
, sizeof(det_caps
)) == DC_OK
) {
3320 switch (port_caps
->bits
.DWN_STRM_PORTX_TYPE
) {
3321 /*Handle DP case as DONGLE_NONE*/
3322 case DOWN_STREAM_DETAILED_DP
:
3323 link
->dpcd_caps
.dongle_type
= DISPLAY_DONGLE_NONE
;
3325 case DOWN_STREAM_DETAILED_VGA
:
3326 link
->dpcd_caps
.dongle_type
=
3327 DISPLAY_DONGLE_DP_VGA_CONVERTER
;
3329 case DOWN_STREAM_DETAILED_DVI
:
3330 link
->dpcd_caps
.dongle_type
=
3331 DISPLAY_DONGLE_DP_DVI_CONVERTER
;
3333 case DOWN_STREAM_DETAILED_HDMI
:
3334 case DOWN_STREAM_DETAILED_DP_PLUS_PLUS
:
3335 /*Handle DP++ active converter case, process DP++ case as HDMI case according DP1.4 spec*/
3336 link
->dpcd_caps
.dongle_type
=
3337 DISPLAY_DONGLE_DP_HDMI_CONVERTER
;
3339 link
->dpcd_caps
.dongle_caps
.dongle_type
= link
->dpcd_caps
.dongle_type
;
3340 if (ds_port
.fields
.DETAILED_CAPS
) {
3342 union dwnstream_port_caps_byte3_hdmi
3343 hdmi_caps
= {.raw
= det_caps
[3] };
3344 union dwnstream_port_caps_byte2
3345 hdmi_color_caps
= {.raw
= det_caps
[2] };
3346 link
->dpcd_caps
.dongle_caps
.dp_hdmi_max_pixel_clk_in_khz
=
3349 link
->dpcd_caps
.dongle_caps
.is_dp_hdmi_s3d_converter
=
3350 hdmi_caps
.bits
.FRAME_SEQ_TO_FRAME_PACK
;
3351 /*YCBCR capability only for HDMI case*/
3352 if (port_caps
->bits
.DWN_STRM_PORTX_TYPE
3353 == DOWN_STREAM_DETAILED_HDMI
) {
3354 link
->dpcd_caps
.dongle_caps
.is_dp_hdmi_ycbcr422_pass_through
=
3355 hdmi_caps
.bits
.YCrCr422_PASS_THROUGH
;
3356 link
->dpcd_caps
.dongle_caps
.is_dp_hdmi_ycbcr420_pass_through
=
3357 hdmi_caps
.bits
.YCrCr420_PASS_THROUGH
;
3358 link
->dpcd_caps
.dongle_caps
.is_dp_hdmi_ycbcr422_converter
=
3359 hdmi_caps
.bits
.YCrCr422_CONVERSION
;
3360 link
->dpcd_caps
.dongle_caps
.is_dp_hdmi_ycbcr420_converter
=
3361 hdmi_caps
.bits
.YCrCr420_CONVERSION
;
3364 link
->dpcd_caps
.dongle_caps
.dp_hdmi_max_bpc
=
3365 translate_dpcd_max_bpc(
3366 hdmi_color_caps
.bits
.MAX_BITS_PER_COLOR_COMPONENT
);
3368 if (link
->dpcd_caps
.dongle_caps
.dp_hdmi_max_pixel_clk_in_khz
!= 0)
3369 link
->dpcd_caps
.dongle_caps
.extendedCapValid
= true;
3377 ddc_service_set_dongle_type(link
->ddc
, link
->dpcd_caps
.dongle_type
);
3380 struct dp_sink_hw_fw_revision dp_hw_fw_revision
;
3382 core_link_read_dpcd(
3384 DP_BRANCH_REVISION_START
,
3385 (uint8_t *)&dp_hw_fw_revision
,
3386 sizeof(dp_hw_fw_revision
));
3388 link
->dpcd_caps
.branch_hw_revision
=
3389 dp_hw_fw_revision
.ieee_hw_rev
;
3392 link
->dpcd_caps
.branch_fw_revision
,
3393 dp_hw_fw_revision
.ieee_fw_rev
,
3394 sizeof(dp_hw_fw_revision
.ieee_fw_rev
));
3398 static void dp_wa_power_up_0010FA(struct dc_link
*link
, uint8_t *dpcd_data
,
3403 if (!link
->dpcd_caps
.dpcd_rev
.raw
) {
3405 dp_receiver_power_ctrl(link
, true);
3406 core_link_read_dpcd(link
, DP_DPCD_REV
,
3408 link
->dpcd_caps
.dpcd_rev
.raw
= dpcd_data
[
3411 } while (retry
++ < 4 && !link
->dpcd_caps
.dpcd_rev
.raw
);
3414 if (link
->dpcd_caps
.dongle_type
== DISPLAY_DONGLE_DP_VGA_CONVERTER
) {
3415 switch (link
->dpcd_caps
.branch_dev_id
) {
3416 /* 0010FA active dongles (DP-VGA, DP-DLDVI converters) power down
3417 * all internal circuits including AUX communication preventing
3418 * reading DPCD table and EDID (spec violation).
3419 * Encoder will skip DP RX power down on disable_output to
3420 * keep receiver powered all the time.*/
3421 case DP_BRANCH_DEVICE_ID_0010FA
:
3422 case DP_BRANCH_DEVICE_ID_0080E1
:
3423 case DP_BRANCH_DEVICE_ID_00E04C
:
3424 link
->wa_flags
.dp_keep_receiver_powered
= true;
3427 /* TODO: May need work around for other dongles. */
3429 link
->wa_flags
.dp_keep_receiver_powered
= false;
3433 link
->wa_flags
.dp_keep_receiver_powered
= false;
3436 /* Read additional sink caps defined in source specific DPCD area
3437 * This function currently only reads from SinkCapability address (DP_SOURCE_SINK_CAP)
3439 static bool dpcd_read_sink_ext_caps(struct dc_link
*link
)
3446 if (core_link_read_dpcd(link
, DP_SOURCE_SINK_CAP
, &dpcd_data
, 1) != DC_OK
)
3449 link
->dpcd_sink_ext_caps
.raw
= dpcd_data
;
3453 static bool retrieve_link_cap(struct dc_link
*link
)
3455 /* DP_ADAPTER_CAP - DP_DPCD_REV + 1 == 16 and also DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT + 1 == 16,
3456 * which means size 16 will be good for both of those DPCD register block reads
3458 uint8_t dpcd_data
[16];
3459 uint8_t lttpr_dpcd_data
[6];
3461 /*Only need to read 1 byte starting from DP_DPRX_FEATURE_ENUMERATION_LIST.
3463 uint8_t dpcd_dprx_data
= '\0';
3464 uint8_t dpcd_power_state
= '\0';
3466 struct dp_device_vendor_id sink_id
;
3467 union down_stream_port_count down_strm_port_count
;
3468 union edp_configuration_cap edp_config_cap
;
3469 union dp_downstream_port_present ds_port
= { 0 };
3470 enum dc_status status
= DC_ERROR_UNEXPECTED
;
3471 uint32_t read_dpcd_retry_cnt
= 3;
3473 struct dp_sink_hw_fw_revision dp_hw_fw_revision
;
3474 bool is_lttpr_present
= false;
3475 const uint32_t post_oui_delay
= 30; // 30ms
3476 bool vbios_lttpr_enable
= false;
3477 bool vbios_lttpr_interop
= false;
3478 struct dc_bios
*bios
= link
->dc
->ctx
->dc_bios
;
3480 memset(dpcd_data
, '\0', sizeof(dpcd_data
));
3481 memset(lttpr_dpcd_data
, '\0', sizeof(lttpr_dpcd_data
));
3482 memset(&down_strm_port_count
,
3483 '\0', sizeof(union down_stream_port_count
));
3484 memset(&edp_config_cap
, '\0',
3485 sizeof(union edp_configuration_cap
));
3487 /* if extended timeout is supported in hardware,
3488 * default to LTTPR timeout (3.2ms) first as a W/A for DP link layer
3489 * CTS 4.2.1.1 regression introduced by CTS specs requirement update.
3491 dc_link_aux_try_to_configure_timeout(link
->ddc
,
3492 LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD
);
3494 status
= core_link_read_dpcd(link
, DP_SET_POWER
,
3495 &dpcd_power_state
, sizeof(dpcd_power_state
));
3497 /* Delay 1 ms if AUX CH is in power down state. Based on spec
3498 * section 2.3.1.2, if AUX CH may be powered down due to
3499 * write to DPCD 600h = 2. Sink AUX CH is monitoring differential
3500 * signal and may need up to 1 ms before being able to reply.
3502 if (status
!= DC_OK
|| dpcd_power_state
== DP_SET_POWER_D3
)
3505 dpcd_set_source_specific_data(link
);
3506 /* Sink may need to configure internals based on vendor, so allow some
3507 * time before proceeding with possibly vendor specific transactions
3509 msleep(post_oui_delay
);
3511 for (i
= 0; i
< read_dpcd_retry_cnt
; i
++) {
3512 status
= core_link_read_dpcd(
3517 if (status
== DC_OK
)
3521 if (status
!= DC_OK
) {
3522 dm_error("%s: Read dpcd data failed.\n", __func__
);
3526 /* Query BIOS to determine if LTTPR functionality is forced on by system */
3527 if (bios
->funcs
->get_lttpr_caps
) {
3528 enum bp_result bp_query_result
;
3529 uint8_t is_vbios_lttpr_enable
= 0;
3531 bp_query_result
= bios
->funcs
->get_lttpr_caps(bios
, &is_vbios_lttpr_enable
);
3532 vbios_lttpr_enable
= (bp_query_result
== BP_RESULT_OK
) && !!is_vbios_lttpr_enable
;
3535 if (bios
->funcs
->get_lttpr_interop
) {
3536 enum bp_result bp_query_result
;
3537 uint8_t is_vbios_interop_enabled
= 0;
3539 bp_query_result
= bios
->funcs
->get_lttpr_interop(bios
, &is_vbios_interop_enabled
);
3540 vbios_lttpr_interop
= (bp_query_result
== BP_RESULT_OK
) && !!is_vbios_interop_enabled
;
3544 * Logic to determine LTTPR mode
3546 link
->lttpr_mode
= LTTPR_MODE_NON_LTTPR
;
3547 if (vbios_lttpr_enable
&& vbios_lttpr_interop
)
3548 link
->lttpr_mode
= LTTPR_MODE_NON_TRANSPARENT
;
3549 else if (!vbios_lttpr_enable
&& vbios_lttpr_interop
) {
3550 if (link
->dc
->config
.allow_lttpr_non_transparent_mode
)
3551 link
->lttpr_mode
= LTTPR_MODE_NON_TRANSPARENT
;
3553 link
->lttpr_mode
= LTTPR_MODE_TRANSPARENT
;
3554 } else if (!vbios_lttpr_enable
&& !vbios_lttpr_interop
) {
3555 if (!link
->dc
->config
.allow_lttpr_non_transparent_mode
3556 || !link
->dc
->caps
.extended_aux_timeout_support
)
3557 link
->lttpr_mode
= LTTPR_MODE_NON_LTTPR
;
3559 link
->lttpr_mode
= LTTPR_MODE_NON_TRANSPARENT
;
3562 if (link
->lttpr_mode
== LTTPR_MODE_NON_TRANSPARENT
|| link
->lttpr_mode
== LTTPR_MODE_TRANSPARENT
) {
3563 /* By reading LTTPR capability, RX assumes that we will enable
3564 * LTTPR extended aux timeout if LTTPR is present.
3566 status
= core_link_read_dpcd(
3568 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
,
3570 sizeof(lttpr_dpcd_data
));
3572 link
->dpcd_caps
.lttpr_caps
.revision
.raw
=
3573 lttpr_dpcd_data
[DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
-
3574 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
];
3576 link
->dpcd_caps
.lttpr_caps
.max_link_rate
=
3577 lttpr_dpcd_data
[DP_MAX_LINK_RATE_PHY_REPEATER
-
3578 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
];
3580 link
->dpcd_caps
.lttpr_caps
.phy_repeater_cnt
=
3581 lttpr_dpcd_data
[DP_PHY_REPEATER_CNT
-
3582 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
];
3584 link
->dpcd_caps
.lttpr_caps
.max_lane_count
=
3585 lttpr_dpcd_data
[DP_MAX_LANE_COUNT_PHY_REPEATER
-
3586 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
];
3588 link
->dpcd_caps
.lttpr_caps
.mode
=
3589 lttpr_dpcd_data
[DP_PHY_REPEATER_MODE
-
3590 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
];
3592 link
->dpcd_caps
.lttpr_caps
.max_ext_timeout
=
3593 lttpr_dpcd_data
[DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT
-
3594 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV
];
3596 is_lttpr_present
= (link
->dpcd_caps
.lttpr_caps
.phy_repeater_cnt
> 0 &&
3597 link
->dpcd_caps
.lttpr_caps
.max_lane_count
> 0 &&
3598 link
->dpcd_caps
.lttpr_caps
.max_lane_count
<= 4 &&
3599 link
->dpcd_caps
.lttpr_caps
.revision
.raw
>= 0x14);
3600 if (is_lttpr_present
)
3601 CONN_DATA_DETECT(link
, lttpr_dpcd_data
, sizeof(lttpr_dpcd_data
), "LTTPR Caps: ");
3603 link
->lttpr_mode
= LTTPR_MODE_NON_LTTPR
;
3606 if (!is_lttpr_present
)
3607 dc_link_aux_try_to_configure_timeout(link
->ddc
, LINK_AUX_DEFAULT_TIMEOUT_PERIOD
);
3611 union training_aux_rd_interval aux_rd_interval
;
3613 aux_rd_interval
.raw
=
3614 dpcd_data
[DP_TRAINING_AUX_RD_INTERVAL
];
3616 link
->dpcd_caps
.ext_receiver_cap_field_present
=
3617 aux_rd_interval
.bits
.EXT_RECEIVER_CAP_FIELD_PRESENT
== 1;
3619 if (aux_rd_interval
.bits
.EXT_RECEIVER_CAP_FIELD_PRESENT
== 1) {
3620 uint8_t ext_cap_data
[16];
3622 memset(ext_cap_data
, '\0', sizeof(ext_cap_data
));
3623 for (i
= 0; i
< read_dpcd_retry_cnt
; i
++) {
3624 status
= core_link_read_dpcd(
3628 sizeof(ext_cap_data
));
3629 if (status
== DC_OK
) {
3630 memcpy(dpcd_data
, ext_cap_data
, sizeof(dpcd_data
));
3634 if (status
!= DC_OK
)
3635 dm_error("%s: Read extend caps data failed, use cap from dpcd 0.\n", __func__
);
3639 link
->dpcd_caps
.dpcd_rev
.raw
=
3640 dpcd_data
[DP_DPCD_REV
- DP_DPCD_REV
];
3642 if (link
->dpcd_caps
.ext_receiver_cap_field_present
) {
3643 for (i
= 0; i
< read_dpcd_retry_cnt
; i
++) {
3644 status
= core_link_read_dpcd(
3646 DP_DPRX_FEATURE_ENUMERATION_LIST
,
3648 sizeof(dpcd_dprx_data
));
3649 if (status
== DC_OK
)
3653 link
->dpcd_caps
.dprx_feature
.raw
= dpcd_dprx_data
;
3655 if (status
!= DC_OK
)
3656 dm_error("%s: Read DPRX caps data failed.\n", __func__
);
3660 link
->dpcd_caps
.dprx_feature
.raw
= 0;
3664 /* Error condition checking...
3665 * It is impossible for Sink to report Max Lane Count = 0.
3666 * It is possible for Sink to report Max Link Rate = 0, if it is
3667 * an eDP device that is reporting specialized link rates in the
3668 * SUPPORTED_LINK_RATE table.
3670 if (dpcd_data
[DP_MAX_LANE_COUNT
- DP_DPCD_REV
] == 0)
3673 ds_port
.byte
= dpcd_data
[DP_DOWNSTREAMPORT_PRESENT
-
3676 read_dp_device_vendor_id(link
);
3678 get_active_converter_info(ds_port
.byte
, link
);
3680 dp_wa_power_up_0010FA(link
, dpcd_data
, sizeof(dpcd_data
));
3682 down_strm_port_count
.raw
= dpcd_data
[DP_DOWN_STREAM_PORT_COUNT
-
3685 link
->dpcd_caps
.allow_invalid_MSA_timing_param
=
3686 down_strm_port_count
.bits
.IGNORE_MSA_TIMING_PARAM
;
3688 link
->dpcd_caps
.max_ln_count
.raw
= dpcd_data
[
3689 DP_MAX_LANE_COUNT
- DP_DPCD_REV
];
3691 link
->dpcd_caps
.max_down_spread
.raw
= dpcd_data
[
3692 DP_MAX_DOWNSPREAD
- DP_DPCD_REV
];
3694 link
->reported_link_cap
.lane_count
=
3695 link
->dpcd_caps
.max_ln_count
.bits
.MAX_LANE_COUNT
;
3696 link
->reported_link_cap
.link_rate
= dpcd_data
[
3697 DP_MAX_LINK_RATE
- DP_DPCD_REV
];
3698 link
->reported_link_cap
.link_spread
=
3699 link
->dpcd_caps
.max_down_spread
.bits
.MAX_DOWN_SPREAD
?
3700 LINK_SPREAD_05_DOWNSPREAD_30KHZ
: LINK_SPREAD_DISABLED
;
3702 edp_config_cap
.raw
= dpcd_data
[
3703 DP_EDP_CONFIGURATION_CAP
- DP_DPCD_REV
];
3704 link
->dpcd_caps
.panel_mode_edp
=
3705 edp_config_cap
.bits
.ALT_SCRAMBLER_RESET
;
3706 link
->dpcd_caps
.dpcd_display_control_capable
=
3707 edp_config_cap
.bits
.DPCD_DISPLAY_CONTROL_CAPABLE
;
3709 link
->test_pattern_enabled
= false;
3710 link
->compliance_test_state
.raw
= 0;
3712 /* read sink count */
3713 core_link_read_dpcd(link
,
3715 &link
->dpcd_caps
.sink_count
.raw
,
3716 sizeof(link
->dpcd_caps
.sink_count
.raw
));
3718 /* read sink ieee oui */
3719 core_link_read_dpcd(link
,
3721 (uint8_t *)(&sink_id
),
3724 link
->dpcd_caps
.sink_dev_id
=
3725 (sink_id
.ieee_oui
[0] << 16) +
3726 (sink_id
.ieee_oui
[1] << 8) +
3727 (sink_id
.ieee_oui
[2]);
3730 link
->dpcd_caps
.sink_dev_id_str
,
3731 sink_id
.ieee_device_id
,
3732 sizeof(sink_id
.ieee_device_id
));
3734 /* Quirk Apple MBP 2017 15" Retina panel: Wrong DP_MAX_LINK_RATE */
3736 uint8_t str_mbp_2017
[] = { 101, 68, 21, 101, 98, 97 };
3738 if ((link
->dpcd_caps
.sink_dev_id
== 0x0010fa) &&
3739 !memcmp(link
->dpcd_caps
.sink_dev_id_str
, str_mbp_2017
,
3740 sizeof(str_mbp_2017
))) {
3741 link
->reported_link_cap
.link_rate
= 0x0c;
3745 core_link_read_dpcd(
3747 DP_SINK_HW_REVISION_START
,
3748 (uint8_t *)&dp_hw_fw_revision
,
3749 sizeof(dp_hw_fw_revision
));
3751 link
->dpcd_caps
.sink_hw_revision
=
3752 dp_hw_fw_revision
.ieee_hw_rev
;
3755 link
->dpcd_caps
.sink_fw_revision
,
3756 dp_hw_fw_revision
.ieee_fw_rev
,
3757 sizeof(dp_hw_fw_revision
.ieee_fw_rev
));
3759 memset(&link
->dpcd_caps
.dsc_caps
, '\0',
3760 sizeof(link
->dpcd_caps
.dsc_caps
));
3761 memset(&link
->dpcd_caps
.fec_cap
, '\0', sizeof(link
->dpcd_caps
.fec_cap
));
3762 /* Read DSC and FEC sink capabilities if DP revision is 1.4 and up */
3763 if (link
->dpcd_caps
.dpcd_rev
.raw
>= DPCD_REV_14
) {
3764 status
= core_link_read_dpcd(
3767 &link
->dpcd_caps
.fec_cap
.raw
,
3768 sizeof(link
->dpcd_caps
.fec_cap
.raw
));
3769 status
= core_link_read_dpcd(
3772 link
->dpcd_caps
.dsc_caps
.dsc_basic_caps
.raw
,
3773 sizeof(link
->dpcd_caps
.dsc_caps
.dsc_basic_caps
.raw
));
3774 status
= core_link_read_dpcd(
3776 DP_DSC_BRANCH_OVERALL_THROUGHPUT_0
,
3777 link
->dpcd_caps
.dsc_caps
.dsc_branch_decoder_caps
.raw
,
3778 sizeof(link
->dpcd_caps
.dsc_caps
.dsc_branch_decoder_caps
.raw
));
3781 if (!dpcd_read_sink_ext_caps(link
))
3782 link
->dpcd_sink_ext_caps
.raw
= 0;
3784 /* Connectivity log: detection */
3785 CONN_DATA_DETECT(link
, dpcd_data
, sizeof(dpcd_data
), "Rx Caps: ");
3790 bool dp_overwrite_extended_receiver_cap(struct dc_link
*link
)
3792 uint8_t dpcd_data
[16];
3793 uint32_t read_dpcd_retry_cnt
= 3;
3794 enum dc_status status
= DC_ERROR_UNEXPECTED
;
3795 union dp_downstream_port_present ds_port
= { 0 };
3796 union down_stream_port_count down_strm_port_count
;
3797 union edp_configuration_cap edp_config_cap
;
3801 for (i
= 0; i
< read_dpcd_retry_cnt
; i
++) {
3802 status
= core_link_read_dpcd(
3807 if (status
== DC_OK
)
3811 link
->dpcd_caps
.dpcd_rev
.raw
=
3812 dpcd_data
[DP_DPCD_REV
- DP_DPCD_REV
];
3814 if (dpcd_data
[DP_MAX_LANE_COUNT
- DP_DPCD_REV
] == 0)
3817 ds_port
.byte
= dpcd_data
[DP_DOWNSTREAMPORT_PRESENT
-
3820 get_active_converter_info(ds_port
.byte
, link
);
3822 down_strm_port_count
.raw
= dpcd_data
[DP_DOWN_STREAM_PORT_COUNT
-
3825 link
->dpcd_caps
.allow_invalid_MSA_timing_param
=
3826 down_strm_port_count
.bits
.IGNORE_MSA_TIMING_PARAM
;
3828 link
->dpcd_caps
.max_ln_count
.raw
= dpcd_data
[
3829 DP_MAX_LANE_COUNT
- DP_DPCD_REV
];
3831 link
->dpcd_caps
.max_down_spread
.raw
= dpcd_data
[
3832 DP_MAX_DOWNSPREAD
- DP_DPCD_REV
];
3834 link
->reported_link_cap
.lane_count
=
3835 link
->dpcd_caps
.max_ln_count
.bits
.MAX_LANE_COUNT
;
3836 link
->reported_link_cap
.link_rate
= dpcd_data
[
3837 DP_MAX_LINK_RATE
- DP_DPCD_REV
];
3838 link
->reported_link_cap
.link_spread
=
3839 link
->dpcd_caps
.max_down_spread
.bits
.MAX_DOWN_SPREAD
?
3840 LINK_SPREAD_05_DOWNSPREAD_30KHZ
: LINK_SPREAD_DISABLED
;
3842 edp_config_cap
.raw
= dpcd_data
[
3843 DP_EDP_CONFIGURATION_CAP
- DP_DPCD_REV
];
3844 link
->dpcd_caps
.panel_mode_edp
=
3845 edp_config_cap
.bits
.ALT_SCRAMBLER_RESET
;
3846 link
->dpcd_caps
.dpcd_display_control_capable
=
3847 edp_config_cap
.bits
.DPCD_DISPLAY_CONTROL_CAPABLE
;
3852 bool detect_dp_sink_caps(struct dc_link
*link
)
3854 return retrieve_link_cap(link
);
3856 /* dc init_hw has power encoder using default
3857 * signal for connector. For native DP, no
3858 * need to power up encoder again. If not native
3859 * DP, hw_init may need check signal or power up
3862 /* TODO save sink caps in link->sink */
3865 static enum dc_link_rate
linkRateInKHzToLinkRateMultiplier(uint32_t link_rate_in_khz
)
3867 enum dc_link_rate link_rate
;
3868 // LinkRate is normally stored as a multiplier of 0.27 Gbps per lane. Do the translation.
3869 switch (link_rate_in_khz
) {
3871 link_rate
= LINK_RATE_LOW
; // Rate_1 (RBR) - 1.62 Gbps/Lane
3874 link_rate
= LINK_RATE_RATE_2
; // Rate_2 - 2.16 Gbps/Lane
3877 link_rate
= LINK_RATE_RATE_3
; // Rate_3 - 2.43 Gbps/Lane
3880 link_rate
= LINK_RATE_HIGH
; // Rate_4 (HBR) - 2.70 Gbps/Lane
3883 link_rate
= LINK_RATE_RBR2
; // Rate_5 (RBR2) - 3.24 Gbps/Lane
3886 link_rate
= LINK_RATE_RATE_6
; // Rate_6 - 4.32 Gbps/Lane
3889 link_rate
= LINK_RATE_HIGH2
; // Rate_7 (HBR2) - 5.40 Gbps/Lane
3892 link_rate
= LINK_RATE_HIGH3
; // Rate_8 (HBR3) - 8.10 Gbps/Lane
3895 link_rate
= LINK_RATE_UNKNOWN
;
3901 void detect_edp_sink_caps(struct dc_link
*link
)
3903 uint8_t supported_link_rates
[16];
3905 uint32_t link_rate_in_khz
;
3906 enum dc_link_rate link_rate
= LINK_RATE_UNKNOWN
;
3907 uint8_t backlight_adj_cap
;
3909 retrieve_link_cap(link
);
3910 link
->dpcd_caps
.edp_supported_link_rates_count
= 0;
3911 memset(supported_link_rates
, 0, sizeof(supported_link_rates
));
3913 if (link
->dpcd_caps
.dpcd_rev
.raw
>= DPCD_REV_14
&&
3914 (link
->dc
->debug
.optimize_edp_link_rate
||
3915 link
->reported_link_cap
.link_rate
== LINK_RATE_UNKNOWN
)) {
3916 // Read DPCD 00010h - 0001Fh 16 bytes at one shot
3917 core_link_read_dpcd(link
, DP_SUPPORTED_LINK_RATES
,
3918 supported_link_rates
, sizeof(supported_link_rates
));
3920 for (entry
= 0; entry
< 16; entry
+= 2) {
3921 // DPCD register reports per-lane link rate = 16-bit link rate capability
3922 // value X 200 kHz. Need multiplier to find link rate in kHz.
3923 link_rate_in_khz
= (supported_link_rates
[entry
+1] * 0x100 +
3924 supported_link_rates
[entry
]) * 200;
3926 if (link_rate_in_khz
!= 0) {
3927 link_rate
= linkRateInKHzToLinkRateMultiplier(link_rate_in_khz
);
3928 link
->dpcd_caps
.edp_supported_link_rates
[link
->dpcd_caps
.edp_supported_link_rates_count
] = link_rate
;
3929 link
->dpcd_caps
.edp_supported_link_rates_count
++;
3931 if (link
->reported_link_cap
.link_rate
< link_rate
)
3932 link
->reported_link_cap
.link_rate
= link_rate
;
3936 link
->verified_link_cap
= link
->reported_link_cap
;
3938 core_link_read_dpcd(link
, DP_EDP_BACKLIGHT_ADJUSTMENT_CAP
,
3939 &backlight_adj_cap
, sizeof(backlight_adj_cap
));
3941 link
->dpcd_caps
.dynamic_backlight_capable_edp
=
3942 (backlight_adj_cap
& DP_EDP_DYNAMIC_BACKLIGHT_CAP
) ? true:false;
3944 dc_link_set_default_brightness_aux(link
);
3947 void dc_link_dp_enable_hpd(const struct dc_link
*link
)
3949 struct link_encoder
*encoder
= link
->link_enc
;
3951 if (encoder
!= NULL
&& encoder
->funcs
->enable_hpd
!= NULL
)
3952 encoder
->funcs
->enable_hpd(encoder
);
3955 void dc_link_dp_disable_hpd(const struct dc_link
*link
)
3957 struct link_encoder
*encoder
= link
->link_enc
;
3959 if (encoder
!= NULL
&& encoder
->funcs
->enable_hpd
!= NULL
)
3960 encoder
->funcs
->disable_hpd(encoder
);
3963 static bool is_dp_phy_pattern(enum dp_test_pattern test_pattern
)
3965 if ((DP_TEST_PATTERN_PHY_PATTERN_BEGIN
<= test_pattern
&&
3966 test_pattern
<= DP_TEST_PATTERN_PHY_PATTERN_END
) ||
3967 test_pattern
== DP_TEST_PATTERN_VIDEO_MODE
)
3973 static void set_crtc_test_pattern(struct dc_link
*link
,
3974 struct pipe_ctx
*pipe_ctx
,
3975 enum dp_test_pattern test_pattern
,
3976 enum dp_test_pattern_color_space test_pattern_color_space
)
3978 enum controller_dp_test_pattern controller_test_pattern
;
3979 enum dc_color_depth color_depth
= pipe_ctx
->
3980 stream
->timing
.display_color_depth
;
3981 struct bit_depth_reduction_params params
;
3982 struct output_pixel_processor
*opp
= pipe_ctx
->stream_res
.opp
;
3983 int width
= pipe_ctx
->stream
->timing
.h_addressable
+
3984 pipe_ctx
->stream
->timing
.h_border_left
+
3985 pipe_ctx
->stream
->timing
.h_border_right
;
3986 int height
= pipe_ctx
->stream
->timing
.v_addressable
+
3987 pipe_ctx
->stream
->timing
.v_border_bottom
+
3988 pipe_ctx
->stream
->timing
.v_border_top
;
3990 memset(¶ms
, 0, sizeof(params
));
3992 switch (test_pattern
) {
3993 case DP_TEST_PATTERN_COLOR_SQUARES
:
3994 controller_test_pattern
=
3995 CONTROLLER_DP_TEST_PATTERN_COLORSQUARES
;
3997 case DP_TEST_PATTERN_COLOR_SQUARES_CEA
:
3998 controller_test_pattern
=
3999 CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA
;
4001 case DP_TEST_PATTERN_VERTICAL_BARS
:
4002 controller_test_pattern
=
4003 CONTROLLER_DP_TEST_PATTERN_VERTICALBARS
;
4005 case DP_TEST_PATTERN_HORIZONTAL_BARS
:
4006 controller_test_pattern
=
4007 CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS
;
4009 case DP_TEST_PATTERN_COLOR_RAMP
:
4010 controller_test_pattern
=
4011 CONTROLLER_DP_TEST_PATTERN_COLORRAMP
;
4014 controller_test_pattern
=
4015 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE
;
4019 switch (test_pattern
) {
4020 case DP_TEST_PATTERN_COLOR_SQUARES
:
4021 case DP_TEST_PATTERN_COLOR_SQUARES_CEA
:
4022 case DP_TEST_PATTERN_VERTICAL_BARS
:
4023 case DP_TEST_PATTERN_HORIZONTAL_BARS
:
4024 case DP_TEST_PATTERN_COLOR_RAMP
:
4026 /* disable bit depth reduction */
4027 pipe_ctx
->stream
->bit_depth_params
= params
;
4028 opp
->funcs
->opp_program_bit_depth_reduction(opp
, ¶ms
);
4029 if (pipe_ctx
->stream_res
.tg
->funcs
->set_test_pattern
)
4030 pipe_ctx
->stream_res
.tg
->funcs
->set_test_pattern(pipe_ctx
->stream_res
.tg
,
4031 controller_test_pattern
, color_depth
);
4032 else if (link
->dc
->hwss
.set_disp_pattern_generator
) {
4033 struct pipe_ctx
*odm_pipe
;
4034 enum controller_dp_color_space controller_color_space
;
4037 int dpg_width
= width
;
4039 switch (test_pattern_color_space
) {
4040 case DP_TEST_PATTERN_COLOR_SPACE_RGB
:
4041 controller_color_space
= CONTROLLER_DP_COLOR_SPACE_RGB
;
4043 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR601
:
4044 controller_color_space
= CONTROLLER_DP_COLOR_SPACE_YCBCR601
;
4046 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR709
:
4047 controller_color_space
= CONTROLLER_DP_COLOR_SPACE_YCBCR709
;
4049 case DP_TEST_PATTERN_COLOR_SPACE_UNDEFINED
:
4051 controller_color_space
= CONTROLLER_DP_COLOR_SPACE_UDEFINED
;
4052 DC_LOG_ERROR("%s: Color space must be defined for test pattern", __func__
);
4057 for (odm_pipe
= pipe_ctx
->next_odm_pipe
; odm_pipe
; odm_pipe
= odm_pipe
->next_odm_pipe
)
4059 dpg_width
= width
/ opp_cnt
;
4062 link
->dc
->hwss
.set_disp_pattern_generator(link
->dc
,
4064 controller_test_pattern
,
4065 controller_color_space
,
4072 for (odm_pipe
= pipe_ctx
->next_odm_pipe
; odm_pipe
; odm_pipe
= odm_pipe
->next_odm_pipe
) {
4073 struct output_pixel_processor
*odm_opp
= odm_pipe
->stream_res
.opp
;
4075 odm_opp
->funcs
->opp_program_bit_depth_reduction(odm_opp
, ¶ms
);
4076 link
->dc
->hwss
.set_disp_pattern_generator(link
->dc
,
4078 controller_test_pattern
,
4079 controller_color_space
,
4090 case DP_TEST_PATTERN_VIDEO_MODE
:
4092 /* restore bitdepth reduction */
4093 resource_build_bit_depth_reduction_params(pipe_ctx
->stream
, ¶ms
);
4094 pipe_ctx
->stream
->bit_depth_params
= params
;
4095 opp
->funcs
->opp_program_bit_depth_reduction(opp
, ¶ms
);
4096 if (pipe_ctx
->stream_res
.tg
->funcs
->set_test_pattern
)
4097 pipe_ctx
->stream_res
.tg
->funcs
->set_test_pattern(pipe_ctx
->stream_res
.tg
,
4098 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE
,
4100 else if (link
->dc
->hwss
.set_disp_pattern_generator
) {
4101 struct pipe_ctx
*odm_pipe
;
4103 int dpg_width
= width
;
4105 for (odm_pipe
= pipe_ctx
->next_odm_pipe
; odm_pipe
; odm_pipe
= odm_pipe
->next_odm_pipe
)
4108 dpg_width
= width
/ opp_cnt
;
4109 for (odm_pipe
= pipe_ctx
->next_odm_pipe
; odm_pipe
; odm_pipe
= odm_pipe
->next_odm_pipe
) {
4110 struct output_pixel_processor
*odm_opp
= odm_pipe
->stream_res
.opp
;
4112 odm_opp
->funcs
->opp_program_bit_depth_reduction(odm_opp
, ¶ms
);
4113 link
->dc
->hwss
.set_disp_pattern_generator(link
->dc
,
4115 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE
,
4116 CONTROLLER_DP_COLOR_SPACE_UDEFINED
,
4123 link
->dc
->hwss
.set_disp_pattern_generator(link
->dc
,
4125 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE
,
4126 CONTROLLER_DP_COLOR_SPACE_UDEFINED
,
4141 bool dc_link_dp_set_test_pattern(
4142 struct dc_link
*link
,
4143 enum dp_test_pattern test_pattern
,
4144 enum dp_test_pattern_color_space test_pattern_color_space
,
4145 const struct link_training_settings
*p_link_settings
,
4146 const unsigned char *p_custom_pattern
,
4147 unsigned int cust_pattern_size
)
4149 struct pipe_ctx
*pipes
= link
->dc
->current_state
->res_ctx
.pipe_ctx
;
4150 struct pipe_ctx
*pipe_ctx
= NULL
;
4153 unsigned char link_qual_pattern
[LANE_COUNT_DP_MAX
] = {0};
4154 union dpcd_training_pattern training_pattern
;
4155 enum dpcd_phy_test_patterns pattern
;
4157 memset(&training_pattern
, 0, sizeof(training_pattern
));
4159 for (i
= 0; i
< MAX_PIPES
; i
++) {
4160 if (pipes
[i
].stream
== NULL
)
4163 if (pipes
[i
].stream
->link
== link
&& !pipes
[i
].top_pipe
&& !pipes
[i
].prev_odm_pipe
) {
4164 pipe_ctx
= &pipes
[i
];
4169 if (pipe_ctx
== NULL
)
4172 /* Reset CRTC Test Pattern if it is currently running and request is VideoMode */
4173 if (link
->test_pattern_enabled
&& test_pattern
==
4174 DP_TEST_PATTERN_VIDEO_MODE
) {
4175 /* Set CRTC Test Pattern */
4176 set_crtc_test_pattern(link
, pipe_ctx
, test_pattern
, test_pattern_color_space
);
4177 dp_set_hw_test_pattern(link
, test_pattern
,
4178 (uint8_t *)p_custom_pattern
,
4179 (uint32_t)cust_pattern_size
);
4181 /* Unblank Stream */
4182 link
->dc
->hwss
.unblank_stream(
4184 &link
->verified_link_cap
);
4185 /* TODO:m_pHwss->MuteAudioEndpoint
4186 * (pPathMode->pDisplayPath, false);
4189 /* Reset Test Pattern state */
4190 link
->test_pattern_enabled
= false;
4195 /* Check for PHY Test Patterns */
4196 if (is_dp_phy_pattern(test_pattern
)) {
4197 /* Set DPCD Lane Settings before running test pattern */
4198 if (p_link_settings
!= NULL
) {
4199 dp_set_hw_lane_settings(link
, p_link_settings
, DPRX
);
4200 dpcd_set_lane_settings(link
, p_link_settings
, DPRX
);
4203 /* Blank stream if running test pattern */
4204 if (test_pattern
!= DP_TEST_PATTERN_VIDEO_MODE
) {
4207 * MuteAudioEndpoint(pPathMode->pDisplayPath, true);
4210 pipes
->stream_res
.stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_res
.stream_enc
);
4213 dp_set_hw_test_pattern(link
, test_pattern
,
4214 (uint8_t *)p_custom_pattern
,
4215 (uint32_t)cust_pattern_size
);
4217 if (test_pattern
!= DP_TEST_PATTERN_VIDEO_MODE
) {
4218 /* Set Test Pattern state */
4219 link
->test_pattern_enabled
= true;
4220 if (p_link_settings
!= NULL
)
4221 dpcd_set_link_settings(link
,
4225 switch (test_pattern
) {
4226 case DP_TEST_PATTERN_VIDEO_MODE
:
4227 pattern
= PHY_TEST_PATTERN_NONE
;
4229 case DP_TEST_PATTERN_D102
:
4230 pattern
= PHY_TEST_PATTERN_D10_2
;
4232 case DP_TEST_PATTERN_SYMBOL_ERROR
:
4233 pattern
= PHY_TEST_PATTERN_SYMBOL_ERROR
;
4235 case DP_TEST_PATTERN_PRBS7
:
4236 pattern
= PHY_TEST_PATTERN_PRBS7
;
4238 case DP_TEST_PATTERN_80BIT_CUSTOM
:
4239 pattern
= PHY_TEST_PATTERN_80BIT_CUSTOM
;
4241 case DP_TEST_PATTERN_CP2520_1
:
4242 pattern
= PHY_TEST_PATTERN_CP2520_1
;
4244 case DP_TEST_PATTERN_CP2520_2
:
4245 pattern
= PHY_TEST_PATTERN_CP2520_2
;
4247 case DP_TEST_PATTERN_CP2520_3
:
4248 pattern
= PHY_TEST_PATTERN_CP2520_3
;
4254 if (test_pattern
== DP_TEST_PATTERN_VIDEO_MODE
4255 /*TODO:&& !pPathMode->pDisplayPath->IsTargetPoweredOn()*/)
4258 if (link
->dpcd_caps
.dpcd_rev
.raw
>= DPCD_REV_12
) {
4259 /* tell receiver that we are sending qualification
4260 * pattern DP 1.2 or later - DP receiver's link quality
4261 * pattern is set using DPCD LINK_QUAL_LANEx_SET
4262 * register (0x10B~0x10E)\
4264 for (lane
= 0; lane
< LANE_COUNT_DP_MAX
; lane
++)
4265 link_qual_pattern
[lane
] =
4266 (unsigned char)(pattern
);
4268 core_link_write_dpcd(link
,
4269 DP_LINK_QUAL_LANE0_SET
,
4271 sizeof(link_qual_pattern
));
4272 } else if (link
->dpcd_caps
.dpcd_rev
.raw
>= DPCD_REV_10
||
4273 link
->dpcd_caps
.dpcd_rev
.raw
== 0) {
4274 /* tell receiver that we are sending qualification
4275 * pattern DP 1.1a or earlier - DP receiver's link
4276 * quality pattern is set using
4277 * DPCD TRAINING_PATTERN_SET -> LINK_QUAL_PATTERN_SET
4278 * register (0x102). We will use v_1.3 when we are
4279 * setting test pattern for DP 1.1.
4281 core_link_read_dpcd(link
, DP_TRAINING_PATTERN_SET
,
4282 &training_pattern
.raw
,
4283 sizeof(training_pattern
));
4284 training_pattern
.v1_3
.LINK_QUAL_PATTERN_SET
= pattern
;
4285 core_link_write_dpcd(link
, DP_TRAINING_PATTERN_SET
,
4286 &training_pattern
.raw
,
4287 sizeof(training_pattern
));
4290 enum dc_color_space color_space
= COLOR_SPACE_UNKNOWN
;
4292 switch (test_pattern_color_space
) {
4293 case DP_TEST_PATTERN_COLOR_SPACE_RGB
:
4294 color_space
= COLOR_SPACE_SRGB
;
4295 if (test_pattern
== DP_TEST_PATTERN_COLOR_SQUARES_CEA
)
4296 color_space
= COLOR_SPACE_SRGB_LIMITED
;
4299 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR601
:
4300 color_space
= COLOR_SPACE_YCBCR601
;
4301 if (test_pattern
== DP_TEST_PATTERN_COLOR_SQUARES_CEA
)
4302 color_space
= COLOR_SPACE_YCBCR601_LIMITED
;
4304 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR709
:
4305 color_space
= COLOR_SPACE_YCBCR709
;
4306 if (test_pattern
== DP_TEST_PATTERN_COLOR_SQUARES_CEA
)
4307 color_space
= COLOR_SPACE_YCBCR709_LIMITED
;
4313 if (pipe_ctx
->stream_res
.tg
->funcs
->lock_doublebuffer_enable
) {
4314 if (pipe_ctx
->stream
&& should_use_dmub_lock(pipe_ctx
->stream
->link
)) {
4315 union dmub_hw_lock_flags hw_locks
= { 0 };
4316 struct dmub_hw_lock_inst_flags inst_flags
= { 0 };
4318 hw_locks
.bits
.lock_dig
= 1;
4319 inst_flags
.dig_inst
= pipe_ctx
->stream_res
.tg
->inst
;
4321 dmub_hw_lock_mgr_cmd(link
->ctx
->dmub_srv
,
4326 pipe_ctx
->stream_res
.tg
->funcs
->lock_doublebuffer_enable(
4327 pipe_ctx
->stream_res
.tg
);
4330 pipe_ctx
->stream_res
.tg
->funcs
->lock(pipe_ctx
->stream_res
.tg
);
4331 /* update MSA to requested color space */
4332 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_set_stream_attribute(pipe_ctx
->stream_res
.stream_enc
,
4333 &pipe_ctx
->stream
->timing
,
4335 pipe_ctx
->stream
->use_vsc_sdp_for_colorimetry
,
4336 link
->dpcd_caps
.dprx_feature
.bits
.SST_SPLIT_SDP_CAP
);
4338 if (pipe_ctx
->stream
->use_vsc_sdp_for_colorimetry
) {
4339 if (test_pattern
== DP_TEST_PATTERN_COLOR_SQUARES_CEA
)
4340 pipe_ctx
->stream
->vsc_infopacket
.sb
[17] |= (1 << 7); // sb17 bit 7 Dynamic Range: 0 = VESA range, 1 = CTA range
4342 pipe_ctx
->stream
->vsc_infopacket
.sb
[17] &= ~(1 << 7);
4343 resource_build_info_frame(pipe_ctx
);
4344 link
->dc
->hwss
.update_info_frame(pipe_ctx
);
4348 set_crtc_test_pattern(link
, pipe_ctx
, test_pattern
, test_pattern_color_space
);
4349 pipe_ctx
->stream_res
.tg
->funcs
->unlock(pipe_ctx
->stream_res
.tg
);
4350 pipe_ctx
->stream_res
.tg
->funcs
->wait_for_state(pipe_ctx
->stream_res
.tg
,
4351 CRTC_STATE_VACTIVE
);
4352 pipe_ctx
->stream_res
.tg
->funcs
->wait_for_state(pipe_ctx
->stream_res
.tg
,
4354 pipe_ctx
->stream_res
.tg
->funcs
->wait_for_state(pipe_ctx
->stream_res
.tg
,
4355 CRTC_STATE_VACTIVE
);
4357 if (pipe_ctx
->stream_res
.tg
->funcs
->lock_doublebuffer_disable
) {
4358 if (pipe_ctx
->stream
&& should_use_dmub_lock(pipe_ctx
->stream
->link
)) {
4359 union dmub_hw_lock_flags hw_locks
= { 0 };
4360 struct dmub_hw_lock_inst_flags inst_flags
= { 0 };
4362 hw_locks
.bits
.lock_dig
= 1;
4363 inst_flags
.dig_inst
= pipe_ctx
->stream_res
.tg
->inst
;
4365 dmub_hw_lock_mgr_cmd(link
->ctx
->dmub_srv
,
4370 pipe_ctx
->stream_res
.tg
->funcs
->lock_doublebuffer_disable(
4371 pipe_ctx
->stream_res
.tg
);
4374 /* Set Test Pattern state */
4375 link
->test_pattern_enabled
= true;
4381 void dp_enable_mst_on_sink(struct dc_link
*link
, bool enable
)
4383 unsigned char mstmCntl
;
4385 core_link_read_dpcd(link
, DP_MSTM_CTRL
, &mstmCntl
, 1);
4387 mstmCntl
|= DP_MST_EN
;
4389 mstmCntl
&= (~DP_MST_EN
);
4391 core_link_write_dpcd(link
, DP_MSTM_CTRL
, &mstmCntl
, 1);
4394 void dp_set_panel_mode(struct dc_link
*link
, enum dp_panel_mode panel_mode
)
4396 union dpcd_edp_config edp_config_set
;
4397 bool panel_mode_edp
= false;
4399 memset(&edp_config_set
, '\0', sizeof(union dpcd_edp_config
));
4401 if (panel_mode
!= DP_PANEL_MODE_DEFAULT
) {
4403 switch (panel_mode
) {
4404 case DP_PANEL_MODE_EDP
:
4405 case DP_PANEL_MODE_SPECIAL
:
4406 panel_mode_edp
= true;
4413 /*set edp panel mode in receiver*/
4414 core_link_read_dpcd(
4416 DP_EDP_CONFIGURATION_SET
,
4417 &edp_config_set
.raw
,
4418 sizeof(edp_config_set
.raw
));
4420 if (edp_config_set
.bits
.PANEL_MODE_EDP
4421 != panel_mode_edp
) {
4422 enum dc_status result
;
4424 edp_config_set
.bits
.PANEL_MODE_EDP
=
4426 result
= core_link_write_dpcd(
4428 DP_EDP_CONFIGURATION_SET
,
4429 &edp_config_set
.raw
,
4430 sizeof(edp_config_set
.raw
));
4432 ASSERT(result
== DC_OK
);
4435 DC_LOG_DETECTION_DP_CAPS("Link: %d eDP panel mode supported: %d "
4436 "eDP panel mode enabled: %d \n",
4438 link
->dpcd_caps
.panel_mode_edp
,
4442 enum dp_panel_mode
dp_get_panel_mode(struct dc_link
*link
)
4444 /* We need to explicitly check that connector
4445 * is not DP. Some Travis_VGA get reported
4446 * by video bios as DP.
4448 if (link
->connector_signal
!= SIGNAL_TYPE_DISPLAY_PORT
) {
4450 switch (link
->dpcd_caps
.branch_dev_id
) {
4451 case DP_BRANCH_DEVICE_ID_0022B9
:
4452 /* alternate scrambler reset is required for Travis
4453 * for the case when external chip does not
4454 * provide sink device id, alternate scrambler
4455 * scheme will be overriden later by querying
4459 link
->dpcd_caps
.branch_dev_name
,
4460 DP_VGA_LVDS_CONVERTER_ID_2
,
4463 branch_dev_name
)) == 0) {
4464 return DP_PANEL_MODE_SPECIAL
;
4467 case DP_BRANCH_DEVICE_ID_00001A
:
4468 /* alternate scrambler reset is required for Travis
4469 * for the case when external chip does not provide
4470 * sink device id, alternate scrambler scheme will
4471 * be overriden later by querying Encoder feature
4473 if (strncmp(link
->dpcd_caps
.branch_dev_name
,
4474 DP_VGA_LVDS_CONVERTER_ID_3
,
4477 branch_dev_name
)) == 0) {
4478 return DP_PANEL_MODE_SPECIAL
;
4486 if (link
->dpcd_caps
.panel_mode_edp
) {
4487 return DP_PANEL_MODE_EDP
;
4490 return DP_PANEL_MODE_DEFAULT
;
4493 void dp_set_fec_ready(struct dc_link
*link
, bool ready
)
4495 /* FEC has to be "set ready" before the link training.
4496 * The policy is to always train with FEC
4497 * if the sink supports it and leave it enabled on link.
4498 * If FEC is not supported, disable it.
4500 struct link_encoder
*link_enc
= link
->link_enc
;
4501 uint8_t fec_config
= 0;
4503 if (!dc_link_should_enable_fec(link
))
4506 if (link_enc
->funcs
->fec_set_ready
&&
4507 link
->dpcd_caps
.fec_cap
.bits
.FEC_CAPABLE
) {
4510 if (core_link_write_dpcd(link
,
4511 DP_FEC_CONFIGURATION
,
4513 sizeof(fec_config
)) == DC_OK
) {
4514 link_enc
->funcs
->fec_set_ready(link_enc
, true);
4515 link
->fec_state
= dc_link_fec_ready
;
4517 link
->link_enc
->funcs
->fec_set_ready(link
->link_enc
, false);
4518 link
->fec_state
= dc_link_fec_not_ready
;
4519 dm_error("dpcd write failed to set fec_ready");
4521 } else if (link
->fec_state
== dc_link_fec_ready
) {
4523 core_link_write_dpcd(link
,
4524 DP_FEC_CONFIGURATION
,
4526 sizeof(fec_config
));
4527 link
->link_enc
->funcs
->fec_set_ready(
4528 link
->link_enc
, false);
4529 link
->fec_state
= dc_link_fec_not_ready
;
4534 void dp_set_fec_enable(struct dc_link
*link
, bool enable
)
4536 struct link_encoder
*link_enc
= link
->link_enc
;
4538 if (!dc_link_should_enable_fec(link
))
4541 if (link_enc
->funcs
->fec_set_enable
&&
4542 link
->dpcd_caps
.fec_cap
.bits
.FEC_CAPABLE
) {
4543 if (link
->fec_state
== dc_link_fec_ready
&& enable
) {
4544 /* Accord to DP spec, FEC enable sequence can first
4545 * be transmitted anytime after 1000 LL codes have
4546 * been transmitted on the link after link training
4547 * completion. Using 1 lane RBR should have the maximum
4548 * time for transmitting 1000 LL codes which is 6.173 us.
4549 * So use 7 microseconds delay instead.
4552 link_enc
->funcs
->fec_set_enable(link_enc
, true);
4553 link
->fec_state
= dc_link_fec_enabled
;
4554 } else if (link
->fec_state
== dc_link_fec_enabled
&& !enable
) {
4555 link_enc
->funcs
->fec_set_enable(link_enc
, false);
4556 link
->fec_state
= dc_link_fec_ready
;
4561 void dpcd_set_source_specific_data(struct dc_link
*link
)
4563 if (!link
->dc
->vendor_signature
.is_valid
) {
4564 enum dc_status __maybe_unused result_write_min_hblank
= DC_NOT_SUPPORTED
;
4565 struct dpcd_amd_signature amd_signature
= {0};
4566 struct dpcd_amd_device_id amd_device_id
= {0};
4568 amd_device_id
.device_id_byte1
=
4569 (uint8_t)(link
->ctx
->asic_id
.chip_id
);
4570 amd_device_id
.device_id_byte2
=
4571 (uint8_t)(link
->ctx
->asic_id
.chip_id
>> 8);
4572 amd_device_id
.dce_version
=
4573 (uint8_t)(link
->ctx
->dce_version
);
4574 amd_device_id
.dal_version_byte1
= 0x0; // needed? where to get?
4575 amd_device_id
.dal_version_byte2
= 0x0; // needed? where to get?
4577 core_link_read_dpcd(link
, DP_SOURCE_OUI
,
4578 (uint8_t *)(&amd_signature
),
4579 sizeof(amd_signature
));
4581 if (!((amd_signature
.AMD_IEEE_TxSignature_byte1
== 0x0) &&
4582 (amd_signature
.AMD_IEEE_TxSignature_byte2
== 0x0) &&
4583 (amd_signature
.AMD_IEEE_TxSignature_byte3
== 0x1A))) {
4585 amd_signature
.AMD_IEEE_TxSignature_byte1
= 0x0;
4586 amd_signature
.AMD_IEEE_TxSignature_byte2
= 0x0;
4587 amd_signature
.AMD_IEEE_TxSignature_byte3
= 0x1A;
4589 core_link_write_dpcd(link
, DP_SOURCE_OUI
,
4590 (uint8_t *)(&amd_signature
),
4591 sizeof(amd_signature
));
4594 core_link_write_dpcd(link
, DP_SOURCE_OUI
+0x03,
4595 (uint8_t *)(&amd_device_id
),
4596 sizeof(amd_device_id
));
4598 if (link
->ctx
->dce_version
>= DCN_VERSION_2_0
&&
4599 link
->dc
->caps
.min_horizontal_blanking_period
!= 0) {
4601 uint8_t hblank_size
= (uint8_t)link
->dc
->caps
.min_horizontal_blanking_period
;
4603 result_write_min_hblank
= core_link_write_dpcd(link
,
4604 DP_SOURCE_MINIMUM_HBLANK_SUPPORTED
, (uint8_t *)(&hblank_size
),
4605 sizeof(hblank_size
));
4607 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION
,
4608 WPP_BIT_FLAG_DC_DETECTION_DP_CAPS
,
4609 "result=%u link_index=%u enum dce_version=%d DPCD=0x%04X min_hblank=%u branch_dev_id=0x%x branch_dev_name='%c%c%c%c%c%c'",
4610 result_write_min_hblank
,
4612 link
->ctx
->dce_version
,
4613 DP_SOURCE_MINIMUM_HBLANK_SUPPORTED
,
4614 link
->dc
->caps
.min_horizontal_blanking_period
,
4615 link
->dpcd_caps
.branch_dev_id
,
4616 link
->dpcd_caps
.branch_dev_name
[0],
4617 link
->dpcd_caps
.branch_dev_name
[1],
4618 link
->dpcd_caps
.branch_dev_name
[2],
4619 link
->dpcd_caps
.branch_dev_name
[3],
4620 link
->dpcd_caps
.branch_dev_name
[4],
4621 link
->dpcd_caps
.branch_dev_name
[5]);
4623 core_link_write_dpcd(link
, DP_SOURCE_OUI
,
4624 link
->dc
->vendor_signature
.data
.raw
,
4625 sizeof(link
->dc
->vendor_signature
.data
.raw
));
4629 bool dc_link_set_backlight_level_nits(struct dc_link
*link
,
4631 uint32_t backlight_millinits
,
4632 uint32_t transition_time_in_ms
)
4634 struct dpcd_source_backlight_set dpcd_backlight_set
;
4635 uint8_t backlight_control
= isHDR
? 1 : 0;
4637 if (!link
|| (link
->connector_signal
!= SIGNAL_TYPE_EDP
&&
4638 link
->connector_signal
!= SIGNAL_TYPE_DISPLAY_PORT
))
4641 // OLEDs have no PWM, they can only use AUX
4642 if (link
->dpcd_sink_ext_caps
.bits
.oled
== 1)
4643 backlight_control
= 1;
4645 *(uint32_t *)&dpcd_backlight_set
.backlight_level_millinits
= backlight_millinits
;
4646 *(uint16_t *)&dpcd_backlight_set
.backlight_transition_time_ms
= (uint16_t)transition_time_in_ms
;
4649 if (core_link_write_dpcd(link
, DP_SOURCE_BACKLIGHT_LEVEL
,
4650 (uint8_t *)(&dpcd_backlight_set
),
4651 sizeof(dpcd_backlight_set
)) != DC_OK
)
4654 if (core_link_write_dpcd(link
, DP_SOURCE_BACKLIGHT_CONTROL
,
4655 &backlight_control
, 1) != DC_OK
)
4661 bool dc_link_get_backlight_level_nits(struct dc_link
*link
,
4662 uint32_t *backlight_millinits_avg
,
4663 uint32_t *backlight_millinits_peak
)
4665 union dpcd_source_backlight_get dpcd_backlight_get
;
4667 memset(&dpcd_backlight_get
, 0, sizeof(union dpcd_source_backlight_get
));
4669 if (!link
|| (link
->connector_signal
!= SIGNAL_TYPE_EDP
&&
4670 link
->connector_signal
!= SIGNAL_TYPE_DISPLAY_PORT
))
4673 if (core_link_read_dpcd(link
, DP_SOURCE_BACKLIGHT_CURRENT_PEAK
,
4674 dpcd_backlight_get
.raw
,
4675 sizeof(union dpcd_source_backlight_get
)) != DC_OK
)
4678 *backlight_millinits_avg
=
4679 dpcd_backlight_get
.bytes
.backlight_millinits_avg
;
4680 *backlight_millinits_peak
=
4681 dpcd_backlight_get
.bytes
.backlight_millinits_peak
;
4683 /* On non-supported panels dpcd_read usually succeeds with 0 returned */
4684 if (*backlight_millinits_avg
== 0 ||
4685 *backlight_millinits_avg
> *backlight_millinits_peak
)
4691 bool dc_link_backlight_enable_aux(struct dc_link
*link
, bool enable
)
4693 uint8_t backlight_enable
= enable
? 1 : 0;
4695 if (!link
|| (link
->connector_signal
!= SIGNAL_TYPE_EDP
&&
4696 link
->connector_signal
!= SIGNAL_TYPE_DISPLAY_PORT
))
4699 if (core_link_write_dpcd(link
, DP_SOURCE_BACKLIGHT_ENABLE
,
4700 &backlight_enable
, 1) != DC_OK
)
4706 // we read default from 0x320 because we expect BIOS wrote it there
4707 // regular get_backlight_nit reads from panel set at 0x326
4708 bool dc_link_read_default_bl_aux(struct dc_link
*link
, uint32_t *backlight_millinits
)
4710 if (!link
|| (link
->connector_signal
!= SIGNAL_TYPE_EDP
&&
4711 link
->connector_signal
!= SIGNAL_TYPE_DISPLAY_PORT
))
4714 if (core_link_read_dpcd(link
, DP_SOURCE_BACKLIGHT_LEVEL
,
4715 (uint8_t *) backlight_millinits
,
4716 sizeof(uint32_t)) != DC_OK
)
4722 bool dc_link_set_default_brightness_aux(struct dc_link
*link
)
4724 uint32_t default_backlight
;
4727 (link
->dpcd_sink_ext_caps
.bits
.hdr_aux_backlight_control
== 1 ||
4728 link
->dpcd_sink_ext_caps
.bits
.sdr_aux_backlight_control
== 1)) {
4729 if (!dc_link_read_default_bl_aux(link
, &default_backlight
))
4730 default_backlight
= 150000;
4731 // if < 5 nits or > 5000, it might be wrong readback
4732 if (default_backlight
< 5000 || default_backlight
> 5000000)
4733 default_backlight
= 150000; //
4735 return dc_link_set_backlight_level_nits(link
, true,
4736 default_backlight
, 0);
4741 bool is_edp_ilr_optimization_required(struct dc_link
*link
, struct dc_crtc_timing
*crtc_timing
)
4743 struct dc_link_settings link_setting
;
4744 uint8_t link_bw_set
;
4745 uint8_t link_rate_set
;
4747 union lane_count_set lane_count_set
= { {0} };
4749 ASSERT(link
|| crtc_timing
); // invalid input
4751 if (link
->dpcd_caps
.edp_supported_link_rates_count
== 0 ||
4752 !link
->dc
->debug
.optimize_edp_link_rate
)
4756 // Read DPCD 00100h to find if standard link rates are set
4757 core_link_read_dpcd(link
, DP_LINK_BW_SET
,
4758 &link_bw_set
, sizeof(link_bw_set
));
4761 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: Optimization required, VBIOS used link_bw_set\n");
4765 // Read DPCD 00115h to find the edp link rate set used
4766 core_link_read_dpcd(link
, DP_LINK_RATE_SET
,
4767 &link_rate_set
, sizeof(link_rate_set
));
4769 // Read DPCD 00101h to find out the number of lanes currently set
4770 core_link_read_dpcd(link
, DP_LANE_COUNT_SET
,
4771 &lane_count_set
.raw
, sizeof(lane_count_set
));
4773 req_bw
= dc_bandwidth_in_kbps_from_timing(crtc_timing
);
4775 decide_edp_link_settings(link
, &link_setting
, req_bw
);
4777 if (link
->dpcd_caps
.edp_supported_link_rates
[link_rate_set
] != link_setting
.link_rate
||
4778 lane_count_set
.bits
.LANE_COUNT_SET
!= link_setting
.lane_count
) {
4779 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: Optimization required, VBIOS link_rate_set not optimal\n");
4783 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: No optimization required, VBIOS set optimal link_rate_set\n");