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"
17 #include "inc/link_enc_cfg.h"
20 static const uint8_t DP_VGA_LVDS_CONVERTER_ID_2[] = "sivarT";
22 static const uint8_t DP_VGA_LVDS_CONVERTER_ID_3[] = "dnomlA";
26 #define DC_TRACE_LEVEL_MESSAGE(...) /* do nothing */
28 #define DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE 0x50
30 /* maximum pre emphasis level allowed for each voltage swing level*/
31 static const enum dc_pre_emphasis
32 voltage_swing_to_pre_emphasis[] = { PRE_EMPHASIS_LEVEL3,
35 PRE_EMPHASIS_DISABLED };
38 POST_LT_ADJ_REQ_LIMIT = 6,
39 POST_LT_ADJ_REQ_TIMEOUT = 200
43 LINK_TRAINING_MAX_RETRY_COUNT = 5,
44 /* to avoid infinite loop where-in the receiver
45 * switches between different VS
47 LINK_TRAINING_MAX_CR_RETRY = 100
50 static bool decide_fallback_link_setting(
51 struct dc_link_settings initial_link_settings,
52 struct dc_link_settings *current_link_setting,
53 enum link_training_result training_result);
54 static struct dc_link_settings get_common_supported_link_settings(
55 struct dc_link_settings link_setting_a,
56 struct dc_link_settings link_setting_b);
58 static uint32_t get_cr_training_aux_rd_interval(struct dc_link *link,
59 const struct dc_link_settings *link_settings)
61 union training_aux_rd_interval training_rd_interval;
62 uint32_t wait_in_micro_secs = 100;
64 memset(&training_rd_interval, 0, sizeof(training_rd_interval));
67 DP_TRAINING_AUX_RD_INTERVAL,
68 (uint8_t *)&training_rd_interval,
69 sizeof(training_rd_interval));
70 if (training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL)
71 wait_in_micro_secs = training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL * 4000;
72 return wait_in_micro_secs;
75 static uint32_t get_eq_training_aux_rd_interval(
77 const struct dc_link_settings *link_settings)
79 union training_aux_rd_interval training_rd_interval;
80 uint32_t wait_in_micro_secs = 400;
82 memset(&training_rd_interval, 0, sizeof(training_rd_interval));
83 /* overwrite the delay if rev > 1.1*/
84 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_12) {
85 /* DP 1.2 or later - retrieve delay through
86 * "DPCD_ADDR_TRAINING_AUX_RD_INTERVAL" register */
89 DP_TRAINING_AUX_RD_INTERVAL,
90 (uint8_t *)&training_rd_interval,
91 sizeof(training_rd_interval));
93 if (training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL)
94 wait_in_micro_secs = training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL * 4000;
97 return wait_in_micro_secs;
100 static void wait_for_training_aux_rd_interval(
101 struct dc_link *link,
102 uint32_t wait_in_micro_secs)
104 udelay(wait_in_micro_secs);
106 DC_LOG_HW_LINK_TRAINING("%s:\n wait = %d\n",
111 static enum dpcd_training_patterns
112 dc_dp_training_pattern_to_dpcd_training_pattern(
113 struct dc_link *link,
114 enum dc_dp_training_pattern pattern)
116 enum dpcd_training_patterns dpcd_tr_pattern =
117 DPCD_TRAINING_PATTERN_VIDEOIDLE;
120 case DP_TRAINING_PATTERN_SEQUENCE_1:
121 dpcd_tr_pattern = DPCD_TRAINING_PATTERN_1;
123 case DP_TRAINING_PATTERN_SEQUENCE_2:
124 dpcd_tr_pattern = DPCD_TRAINING_PATTERN_2;
126 case DP_TRAINING_PATTERN_SEQUENCE_3:
127 dpcd_tr_pattern = DPCD_TRAINING_PATTERN_3;
129 case DP_TRAINING_PATTERN_SEQUENCE_4:
130 dpcd_tr_pattern = DPCD_TRAINING_PATTERN_4;
132 case DP_TRAINING_PATTERN_VIDEOIDLE:
133 dpcd_tr_pattern = DPCD_TRAINING_PATTERN_VIDEOIDLE;
137 DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
142 return dpcd_tr_pattern;
145 static void dpcd_set_training_pattern(
146 struct dc_link *link,
147 enum dc_dp_training_pattern training_pattern)
149 union dpcd_training_pattern dpcd_pattern = { {0} };
151 dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
152 dc_dp_training_pattern_to_dpcd_training_pattern(
153 link, training_pattern);
155 core_link_write_dpcd(
157 DP_TRAINING_PATTERN_SET,
161 DC_LOG_HW_LINK_TRAINING("%s\n %x pattern = %x\n",
163 DP_TRAINING_PATTERN_SET,
164 dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
167 static enum dc_dp_training_pattern decide_cr_training_pattern(
168 const struct dc_link_settings *link_settings)
170 return DP_TRAINING_PATTERN_SEQUENCE_1;
173 static enum dc_dp_training_pattern decide_eq_training_pattern(struct dc_link *link,
174 const struct dc_link_settings *link_settings)
176 struct link_encoder *link_enc;
177 enum dc_dp_training_pattern highest_tp = DP_TRAINING_PATTERN_SEQUENCE_2;
178 struct encoder_feature_support *features;
179 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
181 /* Access link encoder capability based on whether it is statically
182 * or dynamically assigned to a link.
184 if (link->is_dig_mapping_flexible &&
185 link->dc->res_pool->funcs->link_encs_assign)
186 link_enc = link_enc_cfg_get_link_enc_used_by_link(link->dc->current_state, link);
188 link_enc = link->link_enc;
190 features = &link_enc->features;
192 if (features->flags.bits.IS_TPS3_CAPABLE)
193 highest_tp = DP_TRAINING_PATTERN_SEQUENCE_3;
195 if (features->flags.bits.IS_TPS4_CAPABLE)
196 highest_tp = DP_TRAINING_PATTERN_SEQUENCE_4;
198 if (dpcd_caps->max_down_spread.bits.TPS4_SUPPORTED &&
199 highest_tp >= DP_TRAINING_PATTERN_SEQUENCE_4)
200 return DP_TRAINING_PATTERN_SEQUENCE_4;
202 if (dpcd_caps->max_ln_count.bits.TPS3_SUPPORTED &&
203 highest_tp >= DP_TRAINING_PATTERN_SEQUENCE_3)
204 return DP_TRAINING_PATTERN_SEQUENCE_3;
206 return DP_TRAINING_PATTERN_SEQUENCE_2;
209 static void dpcd_set_link_settings(
210 struct dc_link *link,
211 const struct link_training_settings *lt_settings)
215 union down_spread_ctrl downspread = { {0} };
216 union lane_count_set lane_count_set = { {0} };
218 downspread.raw = (uint8_t)
219 (lt_settings->link_settings.link_spread);
221 lane_count_set.bits.LANE_COUNT_SET =
222 lt_settings->link_settings.lane_count;
224 lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
225 lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
228 if (lt_settings->pattern_for_eq < DP_TRAINING_PATTERN_SEQUENCE_4) {
229 lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED =
230 link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED;
233 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
234 &downspread.raw, sizeof(downspread));
236 core_link_write_dpcd(link, DP_LANE_COUNT_SET,
237 &lane_count_set.raw, 1);
239 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14 &&
240 lt_settings->link_settings.use_link_rate_set == true) {
242 /* WA for some MUX chips that will power down with eDP and lose supported
243 * link rate set for eDP 1.4. Source reads DPCD 0x010 again to ensure
244 * MUX chip gets link rate set back before link training.
246 if (link->connector_signal == SIGNAL_TYPE_EDP) {
247 uint8_t supported_link_rates[16];
249 core_link_read_dpcd(link, DP_SUPPORTED_LINK_RATES,
250 supported_link_rates, sizeof(supported_link_rates));
252 core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
253 core_link_write_dpcd(link, DP_LINK_RATE_SET,
254 <_settings->link_settings.link_rate_set, 1);
256 rate = (uint8_t) (lt_settings->link_settings.link_rate);
257 core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
261 DC_LOG_HW_LINK_TRAINING("%s\n %x rate = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
264 lt_settings->link_settings.link_rate,
266 lt_settings->link_settings.lane_count,
267 lt_settings->enhanced_framing,
269 lt_settings->link_settings.link_spread);
271 DC_LOG_HW_LINK_TRAINING("%s\n %x rate set = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
274 lt_settings->link_settings.link_rate_set,
276 lt_settings->link_settings.lane_count,
277 lt_settings->enhanced_framing,
279 lt_settings->link_settings.link_spread);
283 static uint8_t dc_dp_initialize_scrambling_data_symbols(
284 struct dc_link *link,
285 enum dc_dp_training_pattern pattern)
287 uint8_t disable_scrabled_data_symbols = 0;
290 case DP_TRAINING_PATTERN_SEQUENCE_1:
291 case DP_TRAINING_PATTERN_SEQUENCE_2:
292 case DP_TRAINING_PATTERN_SEQUENCE_3:
293 disable_scrabled_data_symbols = 1;
295 case DP_TRAINING_PATTERN_SEQUENCE_4:
296 disable_scrabled_data_symbols = 0;
300 DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
304 return disable_scrabled_data_symbols;
307 static inline bool is_repeater(struct dc_link *link, uint32_t offset)
309 return (link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) && (offset != 0);
312 static void dpcd_set_lt_pattern_and_lane_settings(
313 struct dc_link *link,
314 const struct link_training_settings *lt_settings,
315 enum dc_dp_training_pattern pattern,
318 union dpcd_training_lane dpcd_lane[LANE_COUNT_DP_MAX] = { { {0} } };
320 uint32_t dpcd_base_lt_offset;
322 uint8_t dpcd_lt_buffer[5] = {0};
323 union dpcd_training_pattern dpcd_pattern = { {0} };
325 uint32_t size_in_bytes;
326 bool edp_workaround = false; /* TODO link_prop.INTERNAL */
327 dpcd_base_lt_offset = DP_TRAINING_PATTERN_SET;
329 if (is_repeater(link, offset))
330 dpcd_base_lt_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
331 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
333 /*****************************************************************
334 * DpcdAddress_TrainingPatternSet
335 *****************************************************************/
336 dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
337 dc_dp_training_pattern_to_dpcd_training_pattern(link, pattern);
339 dpcd_pattern.v1_4.SCRAMBLING_DISABLE =
340 dc_dp_initialize_scrambling_data_symbols(link, pattern);
342 dpcd_lt_buffer[DP_TRAINING_PATTERN_SET - DP_TRAINING_PATTERN_SET]
345 if (is_repeater(link, offset)) {
346 DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n 0x%X pattern = %x\n",
350 dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
352 DC_LOG_HW_LINK_TRAINING("%s\n 0x%X pattern = %x\n",
355 dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
357 /*****************************************************************
358 * DpcdAddress_Lane0Set -> DpcdAddress_Lane3Set
359 *****************************************************************/
360 for (lane = 0; lane <
361 (uint32_t)(lt_settings->link_settings.lane_count); lane++) {
363 dpcd_lane[lane].bits.VOLTAGE_SWING_SET =
364 (uint8_t)(lt_settings->lane_settings[lane].VOLTAGE_SWING);
365 dpcd_lane[lane].bits.PRE_EMPHASIS_SET =
366 (uint8_t)(lt_settings->lane_settings[lane].PRE_EMPHASIS);
368 dpcd_lane[lane].bits.MAX_SWING_REACHED =
369 (lt_settings->lane_settings[lane].VOLTAGE_SWING ==
370 VOLTAGE_SWING_MAX_LEVEL ? 1 : 0);
371 dpcd_lane[lane].bits.MAX_PRE_EMPHASIS_REACHED =
372 (lt_settings->lane_settings[lane].PRE_EMPHASIS ==
373 PRE_EMPHASIS_MAX_LEVEL ? 1 : 0);
376 /* concatenate everything into one buffer*/
378 size_in_bytes = lt_settings->link_settings.lane_count * sizeof(dpcd_lane[0]);
382 &dpcd_lt_buffer[DP_TRAINING_LANE0_SET - DP_TRAINING_PATTERN_SET],
386 if (is_repeater(link, offset)) {
387 DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
388 " 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
392 dpcd_lane[0].bits.VOLTAGE_SWING_SET,
393 dpcd_lane[0].bits.PRE_EMPHASIS_SET,
394 dpcd_lane[0].bits.MAX_SWING_REACHED,
395 dpcd_lane[0].bits.MAX_PRE_EMPHASIS_REACHED);
397 DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
400 dpcd_lane[0].bits.VOLTAGE_SWING_SET,
401 dpcd_lane[0].bits.PRE_EMPHASIS_SET,
402 dpcd_lane[0].bits.MAX_SWING_REACHED,
403 dpcd_lane[0].bits.MAX_PRE_EMPHASIS_REACHED);
405 if (edp_workaround) {
406 /* for eDP write in 2 parts because the 5-byte burst is
407 * causing issues on some eDP panels (EPR#366724)
409 core_link_write_dpcd(
411 DP_TRAINING_PATTERN_SET,
413 sizeof(dpcd_pattern.raw));
415 core_link_write_dpcd(
417 DP_TRAINING_LANE0_SET,
418 (uint8_t *)(dpcd_lane),
422 /* write it all in (1 + number-of-lanes)-byte burst*/
423 core_link_write_dpcd(
427 size_in_bytes + sizeof(dpcd_pattern.raw));
429 link->cur_lane_setting = lt_settings->lane_settings[0];
432 static bool is_cr_done(enum dc_lane_count ln_count,
433 union lane_status *dpcd_lane_status)
436 /*LANEx_CR_DONE bits All 1's?*/
437 for (lane = 0; lane < (uint32_t)(ln_count); lane++) {
438 if (!dpcd_lane_status[lane].bits.CR_DONE_0)
444 static bool is_ch_eq_done(enum dc_lane_count ln_count,
445 union lane_status *dpcd_lane_status)
449 for (lane = 0; lane < (uint32_t)(ln_count); lane++)
450 if (!dpcd_lane_status[lane].bits.CHANNEL_EQ_DONE_0)
455 static bool is_symbol_locked(enum dc_lane_count ln_count,
456 union lane_status *dpcd_lane_status)
460 for (lane = 0; lane < (uint32_t)(ln_count); lane++)
461 if (!dpcd_lane_status[lane].bits.SYMBOL_LOCKED_0)
466 static inline bool is_interlane_aligned(union lane_align_status_updated align_status)
468 return align_status.bits.INTERLANE_ALIGN_DONE == 1;
471 static void update_drive_settings(
472 struct link_training_settings *dest,
473 struct link_training_settings src)
476 for (lane = 0; lane < src.link_settings.lane_count; lane++) {
477 if (dest->voltage_swing == NULL)
478 dest->lane_settings[lane].VOLTAGE_SWING = src.lane_settings[lane].VOLTAGE_SWING;
480 dest->lane_settings[lane].VOLTAGE_SWING = *dest->voltage_swing;
482 if (dest->pre_emphasis == NULL)
483 dest->lane_settings[lane].PRE_EMPHASIS = src.lane_settings[lane].PRE_EMPHASIS;
485 dest->lane_settings[lane].PRE_EMPHASIS = *dest->pre_emphasis;
487 if (dest->post_cursor2 == NULL)
488 dest->lane_settings[lane].POST_CURSOR2 = src.lane_settings[lane].POST_CURSOR2;
490 dest->lane_settings[lane].POST_CURSOR2 = *dest->post_cursor2;
494 static uint8_t get_nibble_at_index(const uint8_t *buf,
498 nibble = buf[index / 2];
508 static enum dc_pre_emphasis get_max_pre_emphasis_for_voltage_swing(
509 enum dc_voltage_swing voltage)
511 enum dc_pre_emphasis pre_emphasis;
512 pre_emphasis = PRE_EMPHASIS_MAX_LEVEL;
514 if (voltage <= VOLTAGE_SWING_MAX_LEVEL)
515 pre_emphasis = voltage_swing_to_pre_emphasis[voltage];
521 static void find_max_drive_settings(
522 const struct link_training_settings *link_training_setting,
523 struct link_training_settings *max_lt_setting)
526 struct dc_lane_settings max_requested;
528 max_requested.VOLTAGE_SWING =
529 link_training_setting->
530 lane_settings[0].VOLTAGE_SWING;
531 max_requested.PRE_EMPHASIS =
532 link_training_setting->
533 lane_settings[0].PRE_EMPHASIS;
534 /*max_requested.postCursor2 =
535 * link_training_setting->laneSettings[0].postCursor2;*/
537 /* Determine what the maximum of the requested settings are*/
538 for (lane = 1; lane < link_training_setting->link_settings.lane_count;
540 if (link_training_setting->lane_settings[lane].VOLTAGE_SWING >
541 max_requested.VOLTAGE_SWING)
543 max_requested.VOLTAGE_SWING =
544 link_training_setting->
545 lane_settings[lane].VOLTAGE_SWING;
547 if (link_training_setting->lane_settings[lane].PRE_EMPHASIS >
548 max_requested.PRE_EMPHASIS)
549 max_requested.PRE_EMPHASIS =
550 link_training_setting->
551 lane_settings[lane].PRE_EMPHASIS;
554 if (link_training_setting->laneSettings[lane].postCursor2 >
555 max_requested.postCursor2)
557 max_requested.postCursor2 =
558 link_training_setting->laneSettings[lane].postCursor2;
563 /* make sure the requested settings are
564 * not higher than maximum settings*/
565 if (max_requested.VOLTAGE_SWING > VOLTAGE_SWING_MAX_LEVEL)
566 max_requested.VOLTAGE_SWING = VOLTAGE_SWING_MAX_LEVEL;
568 if (max_requested.PRE_EMPHASIS > PRE_EMPHASIS_MAX_LEVEL)
569 max_requested.PRE_EMPHASIS = PRE_EMPHASIS_MAX_LEVEL;
571 if (max_requested.postCursor2 > PostCursor2_MaxLevel)
572 max_requested.postCursor2 = PostCursor2_MaxLevel;
575 /* make sure the pre-emphasis matches the voltage swing*/
576 if (max_requested.PRE_EMPHASIS >
577 get_max_pre_emphasis_for_voltage_swing(
578 max_requested.VOLTAGE_SWING))
579 max_requested.PRE_EMPHASIS =
580 get_max_pre_emphasis_for_voltage_swing(
581 max_requested.VOLTAGE_SWING);
584 * Post Cursor2 levels are completely independent from
585 * pre-emphasis (Post Cursor1) levels. But Post Cursor2 levels
586 * can only be applied to each allowable combination of voltage
587 * swing and pre-emphasis levels */
588 /* if ( max_requested.postCursor2 >
589 * getMaxPostCursor2ForVoltageSwing(max_requested.voltageSwing))
590 * max_requested.postCursor2 =
591 * getMaxPostCursor2ForVoltageSwing(max_requested.voltageSwing);
594 max_lt_setting->link_settings.link_rate =
595 link_training_setting->link_settings.link_rate;
596 max_lt_setting->link_settings.lane_count =
597 link_training_setting->link_settings.lane_count;
598 max_lt_setting->link_settings.link_spread =
599 link_training_setting->link_settings.link_spread;
601 for (lane = 0; lane <
602 link_training_setting->link_settings.lane_count;
604 max_lt_setting->lane_settings[lane].VOLTAGE_SWING =
605 max_requested.VOLTAGE_SWING;
606 max_lt_setting->lane_settings[lane].PRE_EMPHASIS =
607 max_requested.PRE_EMPHASIS;
608 /*max_lt_setting->laneSettings[lane].postCursor2 =
609 * max_requested.postCursor2;
615 static void get_lane_status_and_drive_settings(
616 struct dc_link *link,
617 const struct link_training_settings *link_training_setting,
618 union lane_status *ln_status,
619 union lane_align_status_updated *ln_status_updated,
620 struct link_training_settings *req_settings,
623 unsigned int lane01_status_address = DP_LANE0_1_STATUS;
624 uint8_t lane_adjust_offset = 4;
625 unsigned int lane01_adjust_address;
626 uint8_t dpcd_buf[6] = {0};
627 union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = { { {0} } };
628 struct link_training_settings request_settings = { {0} };
631 memset(req_settings, '\0', sizeof(struct link_training_settings));
633 if (is_repeater(link, offset)) {
634 lane01_status_address =
635 DP_LANE0_1_STATUS_PHY_REPEATER1 +
636 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
637 lane_adjust_offset = 3;
642 lane01_status_address,
643 (uint8_t *)(dpcd_buf),
646 for (lane = 0; lane <
647 (uint32_t)(link_training_setting->link_settings.lane_count);
650 ln_status[lane].raw =
651 get_nibble_at_index(&dpcd_buf[0], lane);
652 dpcd_lane_adjust[lane].raw =
653 get_nibble_at_index(&dpcd_buf[lane_adjust_offset], lane);
656 ln_status_updated->raw = dpcd_buf[2];
658 if (is_repeater(link, offset)) {
659 DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
660 " 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
663 lane01_status_address, dpcd_buf[0],
664 lane01_status_address + 1, dpcd_buf[1]);
666 DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
668 lane01_status_address, dpcd_buf[0],
669 lane01_status_address + 1, dpcd_buf[1]);
671 lane01_adjust_address = DP_ADJUST_REQUEST_LANE0_1;
673 if (is_repeater(link, offset))
674 lane01_adjust_address = DP_ADJUST_REQUEST_LANE0_1_PHY_REPEATER1 +
675 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
677 if (is_repeater(link, offset)) {
678 DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
679 " 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
682 lane01_adjust_address,
683 dpcd_buf[lane_adjust_offset],
684 lane01_adjust_address + 1,
685 dpcd_buf[lane_adjust_offset + 1]);
687 DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
689 lane01_adjust_address,
690 dpcd_buf[lane_adjust_offset],
691 lane01_adjust_address + 1,
692 dpcd_buf[lane_adjust_offset + 1]);
695 /*copy to req_settings*/
696 request_settings.link_settings.lane_count =
697 link_training_setting->link_settings.lane_count;
698 request_settings.link_settings.link_rate =
699 link_training_setting->link_settings.link_rate;
700 request_settings.link_settings.link_spread =
701 link_training_setting->link_settings.link_spread;
703 for (lane = 0; lane <
704 (uint32_t)(link_training_setting->link_settings.lane_count);
707 request_settings.lane_settings[lane].VOLTAGE_SWING =
708 (enum dc_voltage_swing)(dpcd_lane_adjust[lane].bits.
710 request_settings.lane_settings[lane].PRE_EMPHASIS =
711 (enum dc_pre_emphasis)(dpcd_lane_adjust[lane].bits.
715 /*Note: for postcursor2, read adjusted
716 * postcursor2 settings from*/
717 /*DpcdAddress_AdjustRequestPostCursor2 =
718 *0x020C (not implemented yet)*/
720 /* we find the maximum of the requested settings across all lanes*/
721 /* and set this maximum for all lanes*/
722 find_max_drive_settings(&request_settings, req_settings);
724 /* if post cursor 2 is needed in the future,
725 * read DpcdAddress_AdjustRequestPostCursor2 = 0x020C
730 static void dpcd_set_lane_settings(
731 struct dc_link *link,
732 const struct link_training_settings *link_training_setting,
735 union dpcd_training_lane dpcd_lane[LANE_COUNT_DP_MAX] = {{{0}}};
737 unsigned int lane0_set_address;
739 lane0_set_address = DP_TRAINING_LANE0_SET;
741 if (is_repeater(link, offset))
742 lane0_set_address = DP_TRAINING_LANE0_SET_PHY_REPEATER1 +
743 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
745 for (lane = 0; lane <
746 (uint32_t)(link_training_setting->
747 link_settings.lane_count);
749 dpcd_lane[lane].bits.VOLTAGE_SWING_SET =
750 (uint8_t)(link_training_setting->
751 lane_settings[lane].VOLTAGE_SWING);
752 dpcd_lane[lane].bits.PRE_EMPHASIS_SET =
753 (uint8_t)(link_training_setting->
754 lane_settings[lane].PRE_EMPHASIS);
755 dpcd_lane[lane].bits.MAX_SWING_REACHED =
756 (link_training_setting->
757 lane_settings[lane].VOLTAGE_SWING ==
758 VOLTAGE_SWING_MAX_LEVEL ? 1 : 0);
759 dpcd_lane[lane].bits.MAX_PRE_EMPHASIS_REACHED =
760 (link_training_setting->
761 lane_settings[lane].PRE_EMPHASIS ==
762 PRE_EMPHASIS_MAX_LEVEL ? 1 : 0);
765 core_link_write_dpcd(link,
767 (uint8_t *)(dpcd_lane),
768 link_training_setting->link_settings.lane_count);
771 if (LTSettings.link.rate == LinkRate_High2)
773 DpcdTrainingLaneSet2 dpcd_lane2[lane_count_DPMax] = {0};
774 for ( uint32_t lane = 0;
775 lane < lane_count_DPMax; lane++)
777 dpcd_lane2[lane].bits.post_cursor2_set =
778 static_cast<unsigned char>(
779 LTSettings.laneSettings[lane].postCursor2);
780 dpcd_lane2[lane].bits.max_post_cursor2_reached = 0;
782 m_pDpcdAccessSrv->WriteDpcdData(
783 DpcdAddress_Lane0Set2,
784 reinterpret_cast<unsigned char*>(dpcd_lane2),
785 LTSettings.link.lanes);
789 if (is_repeater(link, offset)) {
790 DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n"
791 " 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
795 dpcd_lane[0].bits.VOLTAGE_SWING_SET,
796 dpcd_lane[0].bits.PRE_EMPHASIS_SET,
797 dpcd_lane[0].bits.MAX_SWING_REACHED,
798 dpcd_lane[0].bits.MAX_PRE_EMPHASIS_REACHED);
801 DC_LOG_HW_LINK_TRAINING("%s\n 0x%X VS set = %x PE set = %x max VS Reached = %x max PE Reached = %x\n",
804 dpcd_lane[0].bits.VOLTAGE_SWING_SET,
805 dpcd_lane[0].bits.PRE_EMPHASIS_SET,
806 dpcd_lane[0].bits.MAX_SWING_REACHED,
807 dpcd_lane[0].bits.MAX_PRE_EMPHASIS_REACHED);
809 link->cur_lane_setting = link_training_setting->lane_settings[0];
813 static bool is_max_vs_reached(
814 const struct link_training_settings *lt_settings)
817 for (lane = 0; lane <
818 (uint32_t)(lt_settings->link_settings.lane_count);
820 if (lt_settings->lane_settings[lane].VOLTAGE_SWING
821 == VOLTAGE_SWING_MAX_LEVEL)
828 static bool perform_post_lt_adj_req_sequence(
829 struct dc_link *link,
830 struct link_training_settings *lt_settings)
832 enum dc_lane_count lane_count =
833 lt_settings->link_settings.lane_count;
835 uint32_t adj_req_count;
836 uint32_t adj_req_timer;
837 bool req_drv_setting_changed;
840 req_drv_setting_changed = false;
841 for (adj_req_count = 0; adj_req_count < POST_LT_ADJ_REQ_LIMIT;
844 req_drv_setting_changed = false;
846 for (adj_req_timer = 0;
847 adj_req_timer < POST_LT_ADJ_REQ_TIMEOUT;
850 struct link_training_settings req_settings;
851 union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX];
852 union lane_align_status_updated
853 dpcd_lane_status_updated;
855 get_lane_status_and_drive_settings(
859 &dpcd_lane_status_updated,
863 if (dpcd_lane_status_updated.bits.
864 POST_LT_ADJ_REQ_IN_PROGRESS == 0)
867 if (!is_cr_done(lane_count, dpcd_lane_status))
870 if (!is_ch_eq_done(lane_count, dpcd_lane_status) ||
871 !is_symbol_locked(lane_count, dpcd_lane_status) ||
872 !is_interlane_aligned(dpcd_lane_status_updated))
875 for (lane = 0; lane < (uint32_t)(lane_count); lane++) {
878 lane_settings[lane].VOLTAGE_SWING !=
879 req_settings.lane_settings[lane].
881 lt_settings->lane_settings[lane].PRE_EMPHASIS !=
882 req_settings.lane_settings[lane].PRE_EMPHASIS) {
884 req_drv_setting_changed = true;
889 if (req_drv_setting_changed) {
890 update_drive_settings(
891 lt_settings, req_settings);
893 dc_link_dp_set_drive_settings(link,
901 if (!req_drv_setting_changed) {
902 DC_LOG_WARNING("%s: Post Link Training Adjust Request Timed out\n",
909 DC_LOG_WARNING("%s: Post Link Training Adjust Request limit reached\n",
917 /* Only used for channel equalization */
918 static uint32_t translate_training_aux_read_interval(uint32_t dpcd_aux_read_interval)
920 unsigned int aux_rd_interval_us = 400;
922 switch (dpcd_aux_read_interval) {
924 aux_rd_interval_us = 4000;
927 aux_rd_interval_us = 8000;
930 aux_rd_interval_us = 12000;
933 aux_rd_interval_us = 16000;
939 return aux_rd_interval_us;
942 static enum link_training_result get_cr_failure(enum dc_lane_count ln_count,
943 union lane_status *dpcd_lane_status)
945 enum link_training_result result = LINK_TRAINING_SUCCESS;
947 if (ln_count >= LANE_COUNT_ONE && !dpcd_lane_status[0].bits.CR_DONE_0)
948 result = LINK_TRAINING_CR_FAIL_LANE0;
949 else if (ln_count >= LANE_COUNT_TWO && !dpcd_lane_status[1].bits.CR_DONE_0)
950 result = LINK_TRAINING_CR_FAIL_LANE1;
951 else if (ln_count >= LANE_COUNT_FOUR && !dpcd_lane_status[2].bits.CR_DONE_0)
952 result = LINK_TRAINING_CR_FAIL_LANE23;
953 else if (ln_count >= LANE_COUNT_FOUR && !dpcd_lane_status[3].bits.CR_DONE_0)
954 result = LINK_TRAINING_CR_FAIL_LANE23;
958 static enum link_training_result perform_channel_equalization_sequence(
959 struct dc_link *link,
960 struct link_training_settings *lt_settings,
963 struct link_training_settings req_settings;
964 enum dc_dp_training_pattern tr_pattern;
965 uint32_t retries_ch_eq;
966 uint32_t wait_time_microsec;
967 enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
968 union lane_align_status_updated dpcd_lane_status_updated = { {0} };
969 union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = { { {0} } };
971 /* Note: also check that TPS4 is a supported feature*/
973 tr_pattern = lt_settings->pattern_for_eq;
975 if (is_repeater(link, offset))
976 tr_pattern = DP_TRAINING_PATTERN_SEQUENCE_4;
978 dp_set_hw_training_pattern(link, tr_pattern, offset);
980 for (retries_ch_eq = 0; retries_ch_eq <= LINK_TRAINING_MAX_RETRY_COUNT;
983 dp_set_hw_lane_settings(link, lt_settings, offset);
987 /* EPR #361076 - write as a 5-byte burst,
988 * but only for the 1-st iteration
991 dpcd_set_lt_pattern_and_lane_settings(
996 dpcd_set_lane_settings(link, lt_settings, offset);
998 /* 3. wait for receiver to lock-on*/
999 wait_time_microsec = lt_settings->eq_pattern_time;
1001 if (is_repeater(link, offset))
1002 wait_time_microsec =
1003 translate_training_aux_read_interval(
1004 link->dpcd_caps.lttpr_caps.aux_rd_interval[offset - 1]);
1006 wait_for_training_aux_rd_interval(
1008 wait_time_microsec);
1010 /* 4. Read lane status and requested
1011 * drive settings as set by the sink*/
1013 get_lane_status_and_drive_settings(
1017 &dpcd_lane_status_updated,
1021 /* 5. check CR done*/
1022 if (!is_cr_done(lane_count, dpcd_lane_status))
1023 return LINK_TRAINING_EQ_FAIL_CR;
1025 /* 6. check CHEQ done*/
1026 if (is_ch_eq_done(lane_count, dpcd_lane_status) &&
1027 is_symbol_locked(lane_count, dpcd_lane_status) &&
1028 is_interlane_aligned(dpcd_lane_status_updated))
1029 return LINK_TRAINING_SUCCESS;
1031 /* 7. update VS/PE/PC2 in lt_settings*/
1032 update_drive_settings(lt_settings, req_settings);
1035 return LINK_TRAINING_EQ_FAIL_EQ;
1038 #define TRAINING_AUX_RD_INTERVAL 100 //us
1040 static void start_clock_recovery_pattern_early(struct dc_link *link,
1041 struct link_training_settings *lt_settings,
1044 DC_LOG_HW_LINK_TRAINING("%s\n GPU sends TPS1. Wait 400us.\n",
1046 dp_set_hw_training_pattern(link, lt_settings->pattern_for_cr, offset);
1047 dp_set_hw_lane_settings(link, lt_settings, offset);
1051 static enum link_training_result perform_clock_recovery_sequence(
1052 struct dc_link *link,
1053 struct link_training_settings *lt_settings,
1056 uint32_t retries_cr;
1057 uint32_t retry_count;
1058 uint32_t wait_time_microsec;
1059 struct link_training_settings req_settings;
1060 enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
1061 union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX];
1062 union lane_align_status_updated dpcd_lane_status_updated;
1067 if (!link->ctx->dc->work_arounds.lt_early_cr_pattern)
1068 dp_set_hw_training_pattern(link, lt_settings->pattern_for_cr, offset);
1070 /* najeeb - The synaptics MST hub can put the LT in
1071 * infinite loop by switching the VS
1073 /* between level 0 and level 1 continuously, here
1074 * we try for CR lock for LinkTrainingMaxCRRetry count*/
1075 while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
1076 (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
1078 memset(&dpcd_lane_status, '\0', sizeof(dpcd_lane_status));
1079 memset(&dpcd_lane_status_updated, '\0',
1080 sizeof(dpcd_lane_status_updated));
1082 /* 1. call HWSS to set lane settings*/
1083 dp_set_hw_lane_settings(
1088 /* 2. update DPCD of the receiver*/
1090 /* EPR #361076 - write as a 5-byte burst,
1091 * but only for the 1-st iteration.*/
1092 dpcd_set_lt_pattern_and_lane_settings(
1095 lt_settings->pattern_for_cr,
1098 dpcd_set_lane_settings(
1103 /* 3. wait receiver to lock-on*/
1104 wait_time_microsec = lt_settings->cr_pattern_time;
1106 if (link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
1107 wait_time_microsec = TRAINING_AUX_RD_INTERVAL;
1109 wait_for_training_aux_rd_interval(
1111 wait_time_microsec);
1113 /* 4. Read lane status and requested drive
1114 * settings as set by the sink
1116 get_lane_status_and_drive_settings(
1120 &dpcd_lane_status_updated,
1124 /* 5. check CR done*/
1125 if (is_cr_done(lane_count, dpcd_lane_status))
1126 return LINK_TRAINING_SUCCESS;
1128 /* 6. max VS reached*/
1129 if (is_max_vs_reached(lt_settings))
1132 /* 7. same lane settings*/
1133 /* Note: settings are the same for all lanes,
1134 * so comparing first lane is sufficient*/
1135 if ((lt_settings->lane_settings[0].VOLTAGE_SWING ==
1136 req_settings.lane_settings[0].VOLTAGE_SWING)
1137 && (lt_settings->lane_settings[0].PRE_EMPHASIS ==
1138 req_settings.lane_settings[0].PRE_EMPHASIS))
1143 /* 8. update VS/PE/PC2 in lt_settings*/
1144 update_drive_settings(lt_settings, req_settings);
1149 if (retry_count >= LINK_TRAINING_MAX_CR_RETRY) {
1151 DC_LOG_ERROR("%s: Link Training Error, could not get CR after %d tries. Possibly voltage swing issue",
1153 LINK_TRAINING_MAX_CR_RETRY);
1157 return get_cr_failure(lane_count, dpcd_lane_status);
1160 static inline enum link_training_result dp_transition_to_video_idle(
1161 struct dc_link *link,
1162 struct link_training_settings *lt_settings,
1163 enum link_training_result status)
1165 union lane_count_set lane_count_set = { {0} };
1167 /* 4. mainlink output idle pattern*/
1168 dp_set_hw_test_pattern(link, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
1171 * 5. post training adjust if required
1172 * If the upstream DPTX and downstream DPRX both support TPS4,
1173 * TPS4 must be used instead of POST_LT_ADJ_REQ.
1175 if (link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED != 1 ||
1176 lt_settings->pattern_for_eq == DP_TRAINING_PATTERN_SEQUENCE_4)
1179 if (status == LINK_TRAINING_SUCCESS &&
1180 perform_post_lt_adj_req_sequence(link, lt_settings) == false)
1181 status = LINK_TRAINING_LQA_FAIL;
1183 lane_count_set.bits.LANE_COUNT_SET = lt_settings->link_settings.lane_count;
1184 lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
1185 lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
1187 core_link_write_dpcd(
1190 &lane_count_set.raw,
1191 sizeof(lane_count_set));
1196 enum link_training_result dp_check_link_loss_status(
1197 struct dc_link *link,
1198 const struct link_training_settings *link_training_setting)
1200 enum link_training_result status = LINK_TRAINING_SUCCESS;
1201 union lane_status lane_status;
1202 uint8_t dpcd_buf[6] = {0};
1205 core_link_read_dpcd(
1208 (uint8_t *)(dpcd_buf),
1211 /*parse lane status*/
1212 for (lane = 0; lane < link->cur_link_settings.lane_count; lane++) {
1214 * check lanes status
1216 lane_status.raw = get_nibble_at_index(&dpcd_buf[2], lane);
1218 if (!lane_status.bits.CHANNEL_EQ_DONE_0 ||
1219 !lane_status.bits.CR_DONE_0 ||
1220 !lane_status.bits.SYMBOL_LOCKED_0) {
1221 /* if one of the channel equalization, clock
1222 * recovery or symbol lock is dropped
1223 * consider it as (link has been
1224 * dropped) dp sink status has changed
1226 status = LINK_TRAINING_LINK_LOSS;
1234 static inline void decide_8b_10b_training_settings(
1235 struct dc_link *link,
1236 const struct dc_link_settings *link_setting,
1237 const struct dc_link_training_overrides *overrides,
1238 struct link_training_settings *lt_settings)
1242 memset(lt_settings, '\0', sizeof(struct link_training_settings));
1244 /* Initialize link settings */
1245 lt_settings->link_settings.use_link_rate_set = link_setting->use_link_rate_set;
1246 lt_settings->link_settings.link_rate_set = link_setting->link_rate_set;
1248 if (link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
1249 lt_settings->link_settings.link_rate = link->preferred_link_setting.link_rate;
1251 lt_settings->link_settings.link_rate = link_setting->link_rate;
1253 if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN)
1254 lt_settings->link_settings.lane_count = link->preferred_link_setting.lane_count;
1256 lt_settings->link_settings.lane_count = link_setting->lane_count;
1258 /*@todo[vdevulap] move SS to LS, should not be handled by displaypath*/
1260 /* TODO hard coded to SS for now
1261 * lt_settings.link_settings.link_spread =
1262 * dal_display_path_is_ss_supported(
1263 * path_mode->display_path) ?
1264 * LINK_SPREAD_05_DOWNSPREAD_30KHZ :
1265 * LINK_SPREAD_DISABLED;
1267 /* Initialize link spread */
1268 if (link->dp_ss_off)
1269 lt_settings->link_settings.link_spread = LINK_SPREAD_DISABLED;
1270 else if (overrides->downspread != NULL)
1271 lt_settings->link_settings.link_spread
1272 = *overrides->downspread
1273 ? LINK_SPREAD_05_DOWNSPREAD_30KHZ
1274 : LINK_SPREAD_DISABLED;
1276 lt_settings->link_settings.link_spread = LINK_SPREAD_05_DOWNSPREAD_30KHZ;
1278 /* Initialize lane settings overrides */
1279 if (overrides->voltage_swing != NULL)
1280 lt_settings->voltage_swing = overrides->voltage_swing;
1282 if (overrides->pre_emphasis != NULL)
1283 lt_settings->pre_emphasis = overrides->pre_emphasis;
1285 if (overrides->post_cursor2 != NULL)
1286 lt_settings->post_cursor2 = overrides->post_cursor2;
1288 /* Initialize lane settings (VS/PE/PC2) */
1289 for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
1290 lt_settings->lane_settings[lane].VOLTAGE_SWING =
1291 lt_settings->voltage_swing != NULL ?
1292 *lt_settings->voltage_swing :
1293 VOLTAGE_SWING_LEVEL0;
1294 lt_settings->lane_settings[lane].PRE_EMPHASIS =
1295 lt_settings->pre_emphasis != NULL ?
1296 *lt_settings->pre_emphasis
1297 : PRE_EMPHASIS_DISABLED;
1298 lt_settings->lane_settings[lane].POST_CURSOR2 =
1299 lt_settings->post_cursor2 != NULL ?
1300 *lt_settings->post_cursor2
1301 : POST_CURSOR2_DISABLED;
1304 /* Initialize training timings */
1305 if (overrides->cr_pattern_time != NULL)
1306 lt_settings->cr_pattern_time = *overrides->cr_pattern_time;
1308 lt_settings->cr_pattern_time = get_cr_training_aux_rd_interval(link, link_setting);
1310 if (overrides->eq_pattern_time != NULL)
1311 lt_settings->eq_pattern_time = *overrides->eq_pattern_time;
1313 lt_settings->eq_pattern_time = get_eq_training_aux_rd_interval(link, link_setting);
1315 if (overrides->pattern_for_cr != NULL)
1316 lt_settings->pattern_for_cr = *overrides->pattern_for_cr;
1318 lt_settings->pattern_for_cr = decide_cr_training_pattern(link_setting);
1319 if (overrides->pattern_for_eq != NULL)
1320 lt_settings->pattern_for_eq = *overrides->pattern_for_eq;
1322 lt_settings->pattern_for_eq = decide_eq_training_pattern(link, link_setting);
1324 if (overrides->enhanced_framing != NULL)
1325 lt_settings->enhanced_framing = *overrides->enhanced_framing;
1327 lt_settings->enhanced_framing = 1;
1330 static void decide_training_settings(
1331 struct dc_link *link,
1332 const struct dc_link_settings *link_settings,
1333 const struct dc_link_training_overrides *overrides,
1334 struct link_training_settings *lt_settings)
1336 if (dp_get_link_encoding_format(link_settings) == DP_8b_10b_ENCODING)
1337 decide_8b_10b_training_settings(link, link_settings, overrides, lt_settings);
1341 uint8_t dp_convert_to_count(uint8_t lttpr_repeater_count)
1343 switch (lttpr_repeater_count) {
1344 case 0x80: // 1 lttpr repeater
1346 case 0x40: // 2 lttpr repeaters
1348 case 0x20: // 3 lttpr repeaters
1350 case 0x10: // 4 lttpr repeaters
1352 case 0x08: // 5 lttpr repeaters
1354 case 0x04: // 6 lttpr repeaters
1356 case 0x02: // 7 lttpr repeaters
1358 case 0x01: // 8 lttpr repeaters
1363 return 0; // invalid value
1366 static void configure_lttpr_mode_transparent(struct dc_link *link)
1368 uint8_t repeater_mode = DP_PHY_REPEATER_MODE_TRANSPARENT;
1370 core_link_write_dpcd(link,
1371 DP_PHY_REPEATER_MODE,
1372 (uint8_t *)&repeater_mode,
1373 sizeof(repeater_mode));
1376 static void configure_lttpr_mode_non_transparent(struct dc_link *link)
1378 /* aux timeout is already set to extended */
1379 /* RESET/SET lttpr mode to enable non transparent mode */
1380 uint8_t repeater_cnt;
1381 uint32_t aux_interval_address;
1382 uint8_t repeater_id;
1383 enum dc_status result = DC_ERROR_UNEXPECTED;
1384 uint8_t repeater_mode = DP_PHY_REPEATER_MODE_TRANSPARENT;
1386 DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Transparent Mode\n", __func__);
1387 result = core_link_write_dpcd(link,
1388 DP_PHY_REPEATER_MODE,
1389 (uint8_t *)&repeater_mode,
1390 sizeof(repeater_mode));
1392 if (result == DC_OK) {
1393 link->dpcd_caps.lttpr_caps.mode = repeater_mode;
1396 if (link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
1398 DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Non Transparent Mode\n", __func__);
1400 repeater_mode = DP_PHY_REPEATER_MODE_NON_TRANSPARENT;
1401 result = core_link_write_dpcd(link,
1402 DP_PHY_REPEATER_MODE,
1403 (uint8_t *)&repeater_mode,
1404 sizeof(repeater_mode));
1406 if (result == DC_OK) {
1407 link->dpcd_caps.lttpr_caps.mode = repeater_mode;
1410 repeater_cnt = dp_convert_to_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
1412 for (repeater_id = repeater_cnt; repeater_id > 0; repeater_id--) {
1413 aux_interval_address = DP_TRAINING_AUX_RD_INTERVAL_PHY_REPEATER1 +
1414 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (repeater_id - 1));
1415 core_link_read_dpcd(
1417 aux_interval_address,
1418 (uint8_t *)&link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1],
1419 sizeof(link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1]));
1420 link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1] &= 0x7F;
1425 static void repeater_training_done(struct dc_link *link, uint32_t offset)
1427 union dpcd_training_pattern dpcd_pattern = { {0} };
1429 const uint32_t dpcd_base_lt_offset =
1430 DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
1431 ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
1432 /* Set training not in progress*/
1433 dpcd_pattern.v1_4.TRAINING_PATTERN_SET = DPCD_TRAINING_PATTERN_VIDEOIDLE;
1435 core_link_write_dpcd(
1437 dpcd_base_lt_offset,
1441 DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Id: %d 0x%X pattern = %x\n",
1444 dpcd_base_lt_offset,
1445 dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
1448 static void print_status_message(
1449 struct dc_link *link,
1450 const struct link_training_settings *lt_settings,
1451 enum link_training_result status)
1453 char *link_rate = "Unknown";
1454 char *lt_result = "Unknown";
1455 char *lt_spread = "Disabled";
1457 switch (lt_settings->link_settings.link_rate) {
1461 case LINK_RATE_RATE_2:
1464 case LINK_RATE_RATE_3:
1467 case LINK_RATE_HIGH:
1470 case LINK_RATE_RBR2:
1473 case LINK_RATE_RATE_6:
1476 case LINK_RATE_HIGH2:
1479 case LINK_RATE_HIGH3:
1487 case LINK_TRAINING_SUCCESS:
1490 case LINK_TRAINING_CR_FAIL_LANE0:
1491 lt_result = "CR failed lane0";
1493 case LINK_TRAINING_CR_FAIL_LANE1:
1494 lt_result = "CR failed lane1";
1496 case LINK_TRAINING_CR_FAIL_LANE23:
1497 lt_result = "CR failed lane23";
1499 case LINK_TRAINING_EQ_FAIL_CR:
1500 lt_result = "CR failed in EQ";
1502 case LINK_TRAINING_EQ_FAIL_EQ:
1503 lt_result = "EQ failed";
1505 case LINK_TRAINING_LQA_FAIL:
1506 lt_result = "LQA failed";
1508 case LINK_TRAINING_LINK_LOSS:
1509 lt_result = "Link loss";
1515 switch (lt_settings->link_settings.link_spread) {
1516 case LINK_SPREAD_DISABLED:
1517 lt_spread = "Disabled";
1519 case LINK_SPREAD_05_DOWNSPREAD_30KHZ:
1520 lt_spread = "0.5% 30KHz";
1522 case LINK_SPREAD_05_DOWNSPREAD_33KHZ:
1523 lt_spread = "0.5% 33KHz";
1529 /* Connectivity log: link training */
1530 CONN_MSG_LT(link, "%sx%d %s VS=%d, PE=%d, DS=%s",
1532 lt_settings->link_settings.lane_count,
1534 lt_settings->lane_settings[0].VOLTAGE_SWING,
1535 lt_settings->lane_settings[0].PRE_EMPHASIS,
1539 void dc_link_dp_set_drive_settings(
1540 struct dc_link *link,
1541 struct link_training_settings *lt_settings)
1543 /* program ASIC PHY settings*/
1544 dp_set_hw_lane_settings(link, lt_settings, DPRX);
1546 /* Notify DP sink the PHY settings from source */
1547 dpcd_set_lane_settings(link, lt_settings, DPRX);
1550 bool dc_link_dp_perform_link_training_skip_aux(
1551 struct dc_link *link,
1552 const struct dc_link_settings *link_setting)
1554 struct link_training_settings lt_settings;
1556 decide_training_settings(
1559 &link->preferred_training_settings,
1562 /* 1. Perform_clock_recovery_sequence. */
1564 /* transmit training pattern for clock recovery */
1565 dp_set_hw_training_pattern(link, lt_settings.pattern_for_cr, DPRX);
1567 /* call HWSS to set lane settings*/
1568 dp_set_hw_lane_settings(link, <_settings, DPRX);
1570 /* wait receiver to lock-on*/
1571 wait_for_training_aux_rd_interval(link, lt_settings.cr_pattern_time);
1573 /* 2. Perform_channel_equalization_sequence. */
1575 /* transmit training pattern for channel equalization. */
1576 dp_set_hw_training_pattern(link, lt_settings.pattern_for_eq, DPRX);
1578 /* call HWSS to set lane settings*/
1579 dp_set_hw_lane_settings(link, <_settings, DPRX);
1581 /* wait receiver to lock-on. */
1582 wait_for_training_aux_rd_interval(link, lt_settings.eq_pattern_time);
1584 /* 3. Perform_link_training_int. */
1586 /* Mainlink output idle pattern. */
1587 dp_set_hw_test_pattern(link, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
1589 print_status_message(link, <_settings, LINK_TRAINING_SUCCESS);
1594 enum link_training_result dc_link_dp_perform_link_training(
1595 struct dc_link *link,
1596 const struct dc_link_settings *link_setting,
1597 bool skip_video_pattern)
1599 enum link_training_result status = LINK_TRAINING_SUCCESS;
1600 struct link_training_settings lt_settings;
1603 uint8_t repeater_cnt;
1604 uint8_t repeater_id;
1606 decide_training_settings(
1609 &link->preferred_training_settings,
1612 /* Configure lttpr mode */
1613 if (link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
1614 configure_lttpr_mode_non_transparent(link);
1615 else if (link->lttpr_mode == LTTPR_MODE_TRANSPARENT)
1616 configure_lttpr_mode_transparent(link);
1618 if (link->ctx->dc->work_arounds.lt_early_cr_pattern)
1619 start_clock_recovery_pattern_early(link, <_settings, DPRX);
1621 /* 1. set link rate, lane count and spread. */
1622 dpcd_set_link_settings(link, <_settings);
1624 if (link->preferred_training_settings.fec_enable != NULL)
1625 fec_enable = *link->preferred_training_settings.fec_enable;
1629 dp_set_fec_ready(link, fec_enable);
1631 if (link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
1633 /* 2. perform link training (set link training done
1634 * to false is done as well)
1636 repeater_cnt = dp_convert_to_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
1638 for (repeater_id = repeater_cnt; (repeater_id > 0 && status == LINK_TRAINING_SUCCESS);
1640 status = perform_clock_recovery_sequence(link, <_settings, repeater_id);
1642 if (status != LINK_TRAINING_SUCCESS)
1645 status = perform_channel_equalization_sequence(link,
1649 if (status != LINK_TRAINING_SUCCESS)
1652 repeater_training_done(link, repeater_id);
1656 if (status == LINK_TRAINING_SUCCESS) {
1657 status = perform_clock_recovery_sequence(link, <_settings, DPRX);
1658 if (status == LINK_TRAINING_SUCCESS) {
1659 status = perform_channel_equalization_sequence(link,
1665 /* 3. set training not in progress*/
1666 dpcd_set_training_pattern(link, DP_TRAINING_PATTERN_VIDEOIDLE);
1667 if ((status == LINK_TRAINING_SUCCESS) || !skip_video_pattern) {
1668 status = dp_transition_to_video_idle(link,
1673 /* delay 5ms after Main Link output idle pattern and then check
1676 if (link->connector_signal != SIGNAL_TYPE_EDP && status == LINK_TRAINING_SUCCESS) {
1678 status = dp_check_link_loss_status(link, <_settings);
1681 /* 6. print status message*/
1682 print_status_message(link, <_settings, status);
1684 if (status != LINK_TRAINING_SUCCESS)
1685 link->ctx->dc->debug_data.ltFailCount++;
1690 static enum dp_panel_mode try_enable_assr(struct dc_stream_state *stream)
1692 struct dc_link *link = stream->link;
1693 enum dp_panel_mode panel_mode = dp_get_panel_mode(link);
1694 #ifdef CONFIG_DRM_AMD_DC_HDCP
1695 struct cp_psp *cp_psp = &stream->ctx->cp_psp;
1698 /* ASSR must be supported on the panel */
1699 if (panel_mode == DP_PANEL_MODE_DEFAULT)
1702 /* eDP or internal DP only */
1703 if (link->connector_signal != SIGNAL_TYPE_EDP &&
1704 !(link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
1705 link->is_internal_display))
1706 return DP_PANEL_MODE_DEFAULT;
1708 #ifdef CONFIG_DRM_AMD_DC_HDCP
1709 if (cp_psp && cp_psp->funcs.enable_assr) {
1710 if (!cp_psp->funcs.enable_assr(cp_psp->handle, link)) {
1711 /* since eDP implies ASSR on, change panel
1712 * mode to disable ASSR
1714 panel_mode = DP_PANEL_MODE_DEFAULT;
1717 panel_mode = DP_PANEL_MODE_DEFAULT;
1720 /* turn off ASSR if the implementation is not compiled in */
1721 panel_mode = DP_PANEL_MODE_DEFAULT;
1726 bool perform_link_training_with_retries(
1727 const struct dc_link_settings *link_setting,
1728 bool skip_video_pattern,
1730 struct pipe_ctx *pipe_ctx,
1731 enum signal_type signal,
1735 uint8_t delay_between_attempts = LINK_TRAINING_RETRY_DELAY;
1736 struct dc_stream_state *stream = pipe_ctx->stream;
1737 struct dc_link *link = stream->link;
1738 enum dp_panel_mode panel_mode;
1739 struct link_encoder *link_enc;
1740 enum link_training_result status = LINK_TRAINING_CR_FAIL_LANE0;
1741 struct dc_link_settings currnet_setting = *link_setting;
1743 /* Dynamically assigned link encoders associated with stream rather than
1746 if (link->dc->res_pool->funcs->link_encs_assign)
1747 link_enc = stream->link_enc;
1749 link_enc = link->link_enc;
1752 /* We need to do this before the link training to ensure the idle pattern in SST
1753 * mode will be sent right after the link training
1755 link_enc->funcs->connect_dig_be_to_fe(link_enc,
1756 pipe_ctx->stream_res.stream_enc->id, true);
1758 for (j = 0; j < attempts; ++j) {
1760 DC_LOG_HW_LINK_TRAINING("%s: Beginning link training attempt %u of %d\n",
1761 __func__, (unsigned int)j + 1, attempts);
1766 pipe_ctx->clock_source->id,
1769 if (stream->sink_patches.dppowerup_delay > 0) {
1770 int delay_dp_power_up_in_ms = stream->sink_patches.dppowerup_delay;
1772 msleep(delay_dp_power_up_in_ms);
1775 panel_mode = try_enable_assr(stream);
1776 dp_set_panel_mode(link, panel_mode);
1777 DC_LOG_DETECTION_DP_CAPS("Link: %d ASSR enabled: %d\n",
1779 panel_mode != DP_PANEL_MODE_DEFAULT);
1781 if (link->aux_access_disabled) {
1782 dc_link_dp_perform_link_training_skip_aux(link, &currnet_setting);
1785 status = dc_link_dp_perform_link_training(
1788 skip_video_pattern);
1789 if (status == LINK_TRAINING_SUCCESS)
1793 /* latest link training still fail, skip delay and keep PHY on
1795 if (j == (attempts - 1) && link->ep_type == DISPLAY_ENDPOINT_PHY)
1798 DC_LOG_WARNING("%s: Link training attempt %u of %d failed\n",
1799 __func__, (unsigned int)j + 1, attempts);
1801 dp_disable_link_phy(link, signal);
1803 /* Abort link training if failure due to sink being unplugged. */
1804 if (status == LINK_TRAINING_ABORT)
1806 else if (do_fallback) {
1807 decide_fallback_link_setting(*link_setting, &currnet_setting, status);
1808 /* Fail link training if reduced link bandwidth no longer meets
1809 * stream requirements.
1811 if (dc_bandwidth_in_kbps_from_timing(&stream->timing) <
1812 dc_link_bandwidth_kbps(link, &currnet_setting))
1816 msleep(delay_between_attempts);
1818 delay_between_attempts += LINK_TRAINING_RETRY_DELAY;
1824 static enum clock_source_id get_clock_source_id(struct dc_link *link)
1826 enum clock_source_id dp_cs_id = CLOCK_SOURCE_ID_UNDEFINED;
1827 struct clock_source *dp_cs = link->dc->res_pool->dp_clock_source;
1829 if (dp_cs != NULL) {
1830 dp_cs_id = dp_cs->id;
1833 * dp clock source is not initialized for some reason.
1834 * Should not happen, CLOCK_SOURCE_ID_EXTERNAL will be used
1842 static void set_dp_mst_mode(struct dc_link *link, bool mst_enable)
1844 if (mst_enable == false &&
1845 link->type == dc_connection_mst_branch) {
1846 /* Disable MST on link. Use only local sink. */
1847 dp_disable_link_phy_mst(link, link->connector_signal);
1849 link->type = dc_connection_single;
1850 link->local_sink = link->remote_sinks[0];
1851 link->local_sink->sink_signal = SIGNAL_TYPE_DISPLAY_PORT;
1852 } else if (mst_enable == true &&
1853 link->type == dc_connection_single &&
1854 link->remote_sinks[0] != NULL) {
1855 /* Re-enable MST on link. */
1856 dp_disable_link_phy(link, link->connector_signal);
1857 dp_enable_mst_on_sink(link, true);
1859 link->type = dc_connection_mst_branch;
1860 link->local_sink->sink_signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
1864 bool dc_link_dp_sync_lt_begin(struct dc_link *link)
1866 /* Begin Sync LT. During this time,
1867 * DPCD:600h must not be powered down.
1869 link->sync_lt_in_progress = true;
1871 /*Clear any existing preferred settings.*/
1872 memset(&link->preferred_training_settings, 0,
1873 sizeof(struct dc_link_training_overrides));
1874 memset(&link->preferred_link_setting, 0,
1875 sizeof(struct dc_link_settings));
1880 enum link_training_result dc_link_dp_sync_lt_attempt(
1881 struct dc_link *link,
1882 struct dc_link_settings *link_settings,
1883 struct dc_link_training_overrides *lt_overrides)
1885 struct link_training_settings lt_settings;
1886 enum link_training_result lt_status = LINK_TRAINING_SUCCESS;
1887 enum dp_panel_mode panel_mode = DP_PANEL_MODE_DEFAULT;
1888 enum clock_source_id dp_cs_id = CLOCK_SOURCE_ID_EXTERNAL;
1889 bool fec_enable = false;
1891 decide_training_settings(
1897 /* Setup MST Mode */
1898 if (lt_overrides->mst_enable)
1899 set_dp_mst_mode(link, *lt_overrides->mst_enable);
1902 dp_disable_link_phy(link, link->connector_signal);
1905 dp_cs_id = get_clock_source_id(link);
1906 dp_enable_link_phy(link, link->connector_signal,
1907 dp_cs_id, link_settings);
1909 /* Set FEC enable */
1910 fec_enable = lt_overrides->fec_enable && *lt_overrides->fec_enable;
1911 dp_set_fec_ready(link, fec_enable);
1913 if (lt_overrides->alternate_scrambler_reset) {
1914 if (*lt_overrides->alternate_scrambler_reset)
1915 panel_mode = DP_PANEL_MODE_EDP;
1917 panel_mode = DP_PANEL_MODE_DEFAULT;
1919 panel_mode = dp_get_panel_mode(link);
1921 dp_set_panel_mode(link, panel_mode);
1923 /* Attempt to train with given link training settings */
1924 if (link->ctx->dc->work_arounds.lt_early_cr_pattern)
1925 start_clock_recovery_pattern_early(link, <_settings, DPRX);
1927 /* Set link rate, lane count and spread. */
1928 dpcd_set_link_settings(link, <_settings);
1930 /* 2. perform link training (set link training done
1931 * to false is done as well)
1933 lt_status = perform_clock_recovery_sequence(link, <_settings, DPRX);
1934 if (lt_status == LINK_TRAINING_SUCCESS) {
1935 lt_status = perform_channel_equalization_sequence(link,
1940 /* 3. Sync LT must skip TRAINING_PATTERN_SET:0 (video pattern)*/
1941 /* 4. print status message*/
1942 print_status_message(link, <_settings, lt_status);
1947 bool dc_link_dp_sync_lt_end(struct dc_link *link, bool link_down)
1949 /* If input parameter is set, shut down phy.
1950 * Still shouldn't turn off dp_receiver (DPCD:600h)
1952 if (link_down == true) {
1953 dp_disable_link_phy(link, link->connector_signal);
1954 dp_set_fec_ready(link, false);
1957 link->sync_lt_in_progress = false;
1961 static struct dc_link_settings get_max_link_cap(struct dc_link *link)
1963 struct dc_link_settings max_link_cap = {0};
1965 /* get max link encoder capability */
1966 link->link_enc->funcs->get_max_link_cap(link->link_enc, &max_link_cap);
1968 /* Lower link settings based on sink's link cap */
1969 if (link->reported_link_cap.lane_count < max_link_cap.lane_count)
1970 max_link_cap.lane_count =
1971 link->reported_link_cap.lane_count;
1972 if (link->reported_link_cap.link_rate < max_link_cap.link_rate)
1973 max_link_cap.link_rate =
1974 link->reported_link_cap.link_rate;
1975 if (link->reported_link_cap.link_spread <
1976 max_link_cap.link_spread)
1977 max_link_cap.link_spread =
1978 link->reported_link_cap.link_spread;
1980 * account for lttpr repeaters cap
1981 * notes: repeaters do not snoop in the DPRX Capabilities addresses (3.6.3).
1983 if (link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
1984 if (link->dpcd_caps.lttpr_caps.max_lane_count < max_link_cap.lane_count)
1985 max_link_cap.lane_count = link->dpcd_caps.lttpr_caps.max_lane_count;
1987 if (link->dpcd_caps.lttpr_caps.max_link_rate < max_link_cap.link_rate)
1988 max_link_cap.link_rate = link->dpcd_caps.lttpr_caps.max_link_rate;
1990 DC_LOG_HW_LINK_TRAINING("%s\n Training with LTTPR, max_lane count %d max_link rate %d \n",
1992 max_link_cap.lane_count,
1993 max_link_cap.link_rate);
1995 return max_link_cap;
1998 enum dc_status read_hpd_rx_irq_data(
1999 struct dc_link *link,
2000 union hpd_irq_data *irq_data)
2002 static enum dc_status retval;
2004 /* The HW reads 16 bytes from 200h on HPD,
2005 * but if we get an AUX_DEFER, the HW cannot retry
2006 * and this causes the CTS tests 4.3.2.1 - 3.2.4 to
2007 * fail, so we now explicitly read 6 bytes which is
2008 * the req from the above mentioned test cases.
2010 * For DP 1.4 we need to read those from 2002h range.
2012 if (link->dpcd_caps.dpcd_rev.raw < DPCD_REV_14)
2013 retval = core_link_read_dpcd(
2017 sizeof(union hpd_irq_data));
2019 /* Read 14 bytes in a single read and then copy only the required fields.
2020 * This is more efficient than doing it in two separate AUX reads. */
2022 uint8_t tmp[DP_SINK_STATUS_ESI - DP_SINK_COUNT_ESI + 1];
2024 retval = core_link_read_dpcd(
2030 if (retval != DC_OK)
2033 irq_data->bytes.sink_cnt.raw = tmp[DP_SINK_COUNT_ESI - DP_SINK_COUNT_ESI];
2034 irq_data->bytes.device_service_irq.raw = tmp[DP_DEVICE_SERVICE_IRQ_VECTOR_ESI0 - DP_SINK_COUNT_ESI];
2035 irq_data->bytes.lane01_status.raw = tmp[DP_LANE0_1_STATUS_ESI - DP_SINK_COUNT_ESI];
2036 irq_data->bytes.lane23_status.raw = tmp[DP_LANE2_3_STATUS_ESI - DP_SINK_COUNT_ESI];
2037 irq_data->bytes.lane_status_updated.raw = tmp[DP_LANE_ALIGN_STATUS_UPDATED_ESI - DP_SINK_COUNT_ESI];
2038 irq_data->bytes.sink_status.raw = tmp[DP_SINK_STATUS_ESI - DP_SINK_COUNT_ESI];
2044 static bool hpd_rx_irq_check_link_loss_status(
2045 struct dc_link *link,
2046 union hpd_irq_data *hpd_irq_dpcd_data)
2048 uint8_t irq_reg_rx_power_state = 0;
2049 enum dc_status dpcd_result = DC_ERROR_UNEXPECTED;
2050 union lane_status lane_status;
2052 bool sink_status_changed;
2055 sink_status_changed = false;
2056 return_code = false;
2058 if (link->cur_link_settings.lane_count == 0)
2061 /*1. Check that Link Status changed, before re-training.*/
2063 /*parse lane status*/
2064 for (lane = 0; lane < link->cur_link_settings.lane_count; lane++) {
2065 /* check status of lanes 0,1
2066 * changed DpcdAddress_Lane01Status (0x202)
2068 lane_status.raw = get_nibble_at_index(
2069 &hpd_irq_dpcd_data->bytes.lane01_status.raw,
2072 if (!lane_status.bits.CHANNEL_EQ_DONE_0 ||
2073 !lane_status.bits.CR_DONE_0 ||
2074 !lane_status.bits.SYMBOL_LOCKED_0) {
2075 /* if one of the channel equalization, clock
2076 * recovery or symbol lock is dropped
2077 * consider it as (link has been
2078 * dropped) dp sink status has changed
2080 sink_status_changed = true;
2085 /* Check interlane align.*/
2086 if (sink_status_changed ||
2087 !hpd_irq_dpcd_data->bytes.lane_status_updated.bits.INTERLANE_ALIGN_DONE) {
2089 DC_LOG_HW_HPD_IRQ("%s: Link Status changed.\n", __func__);
2093 /*2. Check that we can handle interrupt: Not in FS DOS,
2094 * Not in "Display Timeout" state, Link is trained.
2096 dpcd_result = core_link_read_dpcd(link,
2098 &irq_reg_rx_power_state,
2099 sizeof(irq_reg_rx_power_state));
2101 if (dpcd_result != DC_OK) {
2102 DC_LOG_HW_HPD_IRQ("%s: DPCD read failed to obtain power state.\n",
2105 if (irq_reg_rx_power_state != DP_SET_POWER_D0)
2106 return_code = false;
2113 bool dp_verify_link_cap(
2114 struct dc_link *link,
2115 struct dc_link_settings *known_limit_link_setting,
2118 struct dc_link_settings max_link_cap = {0};
2119 struct dc_link_settings cur_link_setting = {0};
2120 struct dc_link_settings *cur = &cur_link_setting;
2121 struct dc_link_settings initial_link_settings = {0};
2123 bool skip_link_training;
2124 bool skip_video_pattern;
2125 enum clock_source_id dp_cs_id = CLOCK_SOURCE_ID_EXTERNAL;
2126 enum link_training_result status;
2127 union hpd_irq_data irq_data;
2129 if (link->dc->debug.skip_detection_link_training) {
2130 link->verified_link_cap = *known_limit_link_setting;
2134 memset(&irq_data, 0, sizeof(irq_data));
2136 skip_link_training = false;
2138 max_link_cap = get_max_link_cap(link);
2140 /* Grant extended timeout request */
2141 if ((link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) && (link->dpcd_caps.lttpr_caps.max_ext_timeout > 0)) {
2142 uint8_t grant = link->dpcd_caps.lttpr_caps.max_ext_timeout & 0x80;
2144 core_link_write_dpcd(link, DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT, &grant, sizeof(grant));
2147 /* TODO implement override and monitor patch later */
2149 /* try to train the link from high to low to
2150 * find the physical link capability
2152 /* disable PHY done possible by BIOS, will be done by driver itself */
2153 dp_disable_link_phy(link, link->connector_signal);
2155 dp_cs_id = get_clock_source_id(link);
2157 /* link training starts with the maximum common settings
2158 * supported by both sink and ASIC.
2160 initial_link_settings = get_common_supported_link_settings(
2161 *known_limit_link_setting,
2163 cur_link_setting = initial_link_settings;
2165 /* Temporary Renoir-specific workaround for SWDEV-215184;
2166 * PHY will sometimes be in bad state on hotplugging display from certain USB-C dongle,
2167 * so add extra cycle of enabling and disabling the PHY before first link training.
2169 if (link->link_enc->features.flags.bits.DP_IS_USB_C &&
2170 link->dc->debug.usbc_combo_phy_reset_wa) {
2171 dp_enable_link_phy(link, link->connector_signal, dp_cs_id, cur);
2172 dp_disable_link_phy(link, link->connector_signal);
2176 skip_video_pattern = true;
2178 if (cur->link_rate == LINK_RATE_LOW)
2179 skip_video_pattern = false;
2183 link->connector_signal,
2188 if (skip_link_training)
2191 status = dc_link_dp_perform_link_training(
2194 skip_video_pattern);
2195 if (status == LINK_TRAINING_SUCCESS)
2202 link->verified_link_cap = *cur;
2204 if (read_hpd_rx_irq_data(link, &irq_data) == DC_OK)
2205 if (hpd_rx_irq_check_link_loss_status(
2210 /* always disable the link before trying another
2211 * setting or before returning we'll enable it later
2212 * based on the actual mode we're driving
2214 dp_disable_link_phy(link, link->connector_signal);
2215 } while (!success && decide_fallback_link_setting(
2216 initial_link_settings, cur, status));
2218 /* Link Training failed for all Link Settings
2219 * (Lane Count is still unknown)
2222 /* If all LT fails for all settings,
2223 * set verified = failed safe (1 lane low)
2225 link->verified_link_cap.lane_count = LANE_COUNT_ONE;
2226 link->verified_link_cap.link_rate = LINK_RATE_LOW;
2228 link->verified_link_cap.link_spread =
2229 LINK_SPREAD_DISABLED;
2236 bool dp_verify_link_cap_with_retries(
2237 struct dc_link *link,
2238 struct dc_link_settings *known_limit_link_setting,
2242 bool success = false;
2244 for (i = 0; i < attempts; i++) {
2246 enum dc_connection_type type = dc_connection_none;
2248 memset(&link->verified_link_cap, 0,
2249 sizeof(struct dc_link_settings));
2250 if (!dc_link_detect_sink(link, &type) || type == dc_connection_none) {
2251 link->verified_link_cap.lane_count = LANE_COUNT_ONE;
2252 link->verified_link_cap.link_rate = LINK_RATE_LOW;
2253 link->verified_link_cap.link_spread = LINK_SPREAD_DISABLED;
2255 } else if (dp_verify_link_cap(link,
2256 &link->reported_link_cap,
2257 &fail_count) && fail_count == 0) {
2266 bool dp_verify_mst_link_cap(
2267 struct dc_link *link)
2269 struct dc_link_settings max_link_cap = {0};
2271 max_link_cap = get_max_link_cap(link);
2272 link->verified_link_cap = get_common_supported_link_settings(
2273 link->reported_link_cap,
2279 static struct dc_link_settings get_common_supported_link_settings(
2280 struct dc_link_settings link_setting_a,
2281 struct dc_link_settings link_setting_b)
2283 struct dc_link_settings link_settings = {0};
2285 link_settings.lane_count =
2286 (link_setting_a.lane_count <=
2287 link_setting_b.lane_count) ?
2288 link_setting_a.lane_count :
2289 link_setting_b.lane_count;
2290 link_settings.link_rate =
2291 (link_setting_a.link_rate <=
2292 link_setting_b.link_rate) ?
2293 link_setting_a.link_rate :
2294 link_setting_b.link_rate;
2295 link_settings.link_spread = LINK_SPREAD_DISABLED;
2297 /* in DP compliance test, DPR-120 may have
2298 * a random value in its MAX_LINK_BW dpcd field.
2299 * We map it to the maximum supported link rate that
2300 * is smaller than MAX_LINK_BW in this case.
2302 if (link_settings.link_rate > LINK_RATE_HIGH3) {
2303 link_settings.link_rate = LINK_RATE_HIGH3;
2304 } else if (link_settings.link_rate < LINK_RATE_HIGH3
2305 && link_settings.link_rate > LINK_RATE_HIGH2) {
2306 link_settings.link_rate = LINK_RATE_HIGH2;
2307 } else if (link_settings.link_rate < LINK_RATE_HIGH2
2308 && link_settings.link_rate > LINK_RATE_HIGH) {
2309 link_settings.link_rate = LINK_RATE_HIGH;
2310 } else if (link_settings.link_rate < LINK_RATE_HIGH
2311 && link_settings.link_rate > LINK_RATE_LOW) {
2312 link_settings.link_rate = LINK_RATE_LOW;
2313 } else if (link_settings.link_rate < LINK_RATE_LOW) {
2314 link_settings.link_rate = LINK_RATE_UNKNOWN;
2317 return link_settings;
2320 static inline bool reached_minimum_lane_count(enum dc_lane_count lane_count)
2322 return lane_count <= LANE_COUNT_ONE;
2325 static inline bool reached_minimum_link_rate(enum dc_link_rate link_rate)
2327 return link_rate <= LINK_RATE_LOW;
2330 static enum dc_lane_count reduce_lane_count(enum dc_lane_count lane_count)
2332 switch (lane_count) {
2333 case LANE_COUNT_FOUR:
2334 return LANE_COUNT_TWO;
2335 case LANE_COUNT_TWO:
2336 return LANE_COUNT_ONE;
2337 case LANE_COUNT_ONE:
2338 return LANE_COUNT_UNKNOWN;
2340 return LANE_COUNT_UNKNOWN;
2344 static enum dc_link_rate reduce_link_rate(enum dc_link_rate link_rate)
2346 switch (link_rate) {
2347 case LINK_RATE_HIGH3:
2348 return LINK_RATE_HIGH2;
2349 case LINK_RATE_HIGH2:
2350 return LINK_RATE_HIGH;
2351 case LINK_RATE_HIGH:
2352 return LINK_RATE_LOW;
2354 return LINK_RATE_UNKNOWN;
2356 return LINK_RATE_UNKNOWN;
2360 static enum dc_lane_count increase_lane_count(enum dc_lane_count lane_count)
2362 switch (lane_count) {
2363 case LANE_COUNT_ONE:
2364 return LANE_COUNT_TWO;
2365 case LANE_COUNT_TWO:
2366 return LANE_COUNT_FOUR;
2368 return LANE_COUNT_UNKNOWN;
2372 static enum dc_link_rate increase_link_rate(enum dc_link_rate link_rate)
2374 switch (link_rate) {
2376 return LINK_RATE_HIGH;
2377 case LINK_RATE_HIGH:
2378 return LINK_RATE_HIGH2;
2379 case LINK_RATE_HIGH2:
2380 return LINK_RATE_HIGH3;
2382 return LINK_RATE_UNKNOWN;
2387 * function: set link rate and lane count fallback based
2388 * on current link setting and last link training result
2390 * true - link setting could be set
2391 * false - has reached minimum setting
2392 * and no further fallback could be done
2394 static bool decide_fallback_link_setting(
2395 struct dc_link_settings initial_link_settings,
2396 struct dc_link_settings *current_link_setting,
2397 enum link_training_result training_result)
2399 if (!current_link_setting)
2402 switch (training_result) {
2403 case LINK_TRAINING_CR_FAIL_LANE0:
2404 case LINK_TRAINING_CR_FAIL_LANE1:
2405 case LINK_TRAINING_CR_FAIL_LANE23:
2406 case LINK_TRAINING_LQA_FAIL:
2408 if (!reached_minimum_link_rate
2409 (current_link_setting->link_rate)) {
2410 current_link_setting->link_rate =
2412 current_link_setting->link_rate);
2413 } else if (!reached_minimum_lane_count
2414 (current_link_setting->lane_count)) {
2415 current_link_setting->link_rate =
2416 initial_link_settings.link_rate;
2417 if (training_result == LINK_TRAINING_CR_FAIL_LANE0)
2419 else if (training_result == LINK_TRAINING_CR_FAIL_LANE1)
2420 current_link_setting->lane_count =
2422 else if (training_result ==
2423 LINK_TRAINING_CR_FAIL_LANE23)
2424 current_link_setting->lane_count =
2427 current_link_setting->lane_count =
2429 current_link_setting->lane_count);
2435 case LINK_TRAINING_EQ_FAIL_EQ:
2437 if (!reached_minimum_lane_count
2438 (current_link_setting->lane_count)) {
2439 current_link_setting->lane_count =
2441 current_link_setting->lane_count);
2442 } else if (!reached_minimum_link_rate
2443 (current_link_setting->link_rate)) {
2444 current_link_setting->link_rate =
2446 current_link_setting->link_rate);
2452 case LINK_TRAINING_EQ_FAIL_CR:
2454 if (!reached_minimum_link_rate
2455 (current_link_setting->link_rate)) {
2456 current_link_setting->link_rate =
2458 current_link_setting->link_rate);
2470 bool dp_validate_mode_timing(
2471 struct dc_link *link,
2472 const struct dc_crtc_timing *timing)
2477 const struct dc_link_settings *link_setting;
2479 /* According to spec, VSC SDP should be used if pixel format is YCbCr420 */
2480 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420 &&
2481 !link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED &&
2482 dal_graphics_object_id_get_connector_id(link->link_id) != CONNECTOR_ID_VIRTUAL)
2485 /*always DP fail safe mode*/
2486 if ((timing->pix_clk_100hz / 10) == (uint32_t) 25175 &&
2487 timing->h_addressable == (uint32_t) 640 &&
2488 timing->v_addressable == (uint32_t) 480)
2491 link_setting = dc_link_get_link_cap(link);
2493 /* TODO: DYNAMIC_VALIDATION needs to be implemented */
2494 /*if (flags.DYNAMIC_VALIDATION == 1 &&
2495 link->verified_link_cap.lane_count != LANE_COUNT_UNKNOWN)
2496 link_setting = &link->verified_link_cap;
2499 req_bw = dc_bandwidth_in_kbps_from_timing(timing);
2500 max_bw = dc_link_bandwidth_kbps(link, link_setting);
2502 if (req_bw <= max_bw) {
2503 /* remember the biggest mode here, during
2504 * initial link training (to get
2505 * verified_link_cap), LS sends event about
2506 * cannot train at reported cap to upper
2507 * layer and upper layer will re-enumerate modes.
2508 * this is not necessary if the lower
2509 * verified_link_cap is enough to drive
2512 /* TODO: DYNAMIC_VALIDATION needs to be implemented */
2513 /* if (flags.DYNAMIC_VALIDATION == 1)
2514 dpsst->max_req_bw_for_verified_linkcap = dal_max(
2515 dpsst->max_req_bw_for_verified_linkcap, req_bw); */
2521 static bool decide_dp_link_settings(struct dc_link *link, struct dc_link_settings *link_setting, uint32_t req_bw)
2523 struct dc_link_settings initial_link_setting = {
2524 LANE_COUNT_ONE, LINK_RATE_LOW, LINK_SPREAD_DISABLED, false, 0};
2525 struct dc_link_settings current_link_setting =
2526 initial_link_setting;
2529 if (req_bw > dc_link_bandwidth_kbps(link, &link->verified_link_cap))
2532 /* search for the minimum link setting that:
2533 * 1. is supported according to the link training result
2534 * 2. could support the b/w requested by the timing
2536 while (current_link_setting.link_rate <=
2537 link->verified_link_cap.link_rate) {
2538 link_bw = dc_link_bandwidth_kbps(
2540 ¤t_link_setting);
2541 if (req_bw <= link_bw) {
2542 *link_setting = current_link_setting;
2546 if (current_link_setting.lane_count <
2547 link->verified_link_cap.lane_count) {
2548 current_link_setting.lane_count =
2549 increase_lane_count(
2550 current_link_setting.lane_count);
2552 current_link_setting.link_rate =
2554 current_link_setting.link_rate);
2555 current_link_setting.lane_count =
2556 initial_link_setting.lane_count;
2563 bool decide_edp_link_settings(struct dc_link *link, struct dc_link_settings *link_setting, uint32_t req_bw)
2565 struct dc_link_settings initial_link_setting;
2566 struct dc_link_settings current_link_setting;
2569 if (link->dpcd_caps.dpcd_rev.raw < DPCD_REV_14 ||
2570 link->dpcd_caps.edp_supported_link_rates_count == 0) {
2571 *link_setting = link->verified_link_cap;
2575 memset(&initial_link_setting, 0, sizeof(initial_link_setting));
2576 initial_link_setting.lane_count = LANE_COUNT_ONE;
2577 initial_link_setting.link_rate = link->dpcd_caps.edp_supported_link_rates[0];
2578 initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
2579 initial_link_setting.use_link_rate_set = true;
2580 initial_link_setting.link_rate_set = 0;
2581 current_link_setting = initial_link_setting;
2583 /* search for the minimum link setting that:
2584 * 1. is supported according to the link training result
2585 * 2. could support the b/w requested by the timing
2587 while (current_link_setting.link_rate <=
2588 link->verified_link_cap.link_rate) {
2589 link_bw = dc_link_bandwidth_kbps(
2591 ¤t_link_setting);
2592 if (req_bw <= link_bw) {
2593 *link_setting = current_link_setting;
2597 if (current_link_setting.lane_count <
2598 link->verified_link_cap.lane_count) {
2599 current_link_setting.lane_count =
2600 increase_lane_count(
2601 current_link_setting.lane_count);
2603 if (current_link_setting.link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
2604 current_link_setting.link_rate_set++;
2605 current_link_setting.link_rate =
2606 link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
2607 current_link_setting.lane_count =
2608 initial_link_setting.lane_count;
2616 static bool decide_mst_link_settings(const struct dc_link *link, struct dc_link_settings *link_setting)
2618 *link_setting = link->verified_link_cap;
2622 void decide_link_settings(struct dc_stream_state *stream,
2623 struct dc_link_settings *link_setting)
2625 struct dc_link *link;
2628 req_bw = dc_bandwidth_in_kbps_from_timing(&stream->timing);
2630 link = stream->link;
2632 /* if preferred is specified through AMDDP, use it, if it's enough
2635 if (link->preferred_link_setting.lane_count !=
2636 LANE_COUNT_UNKNOWN &&
2637 link->preferred_link_setting.link_rate !=
2638 LINK_RATE_UNKNOWN) {
2639 *link_setting = link->preferred_link_setting;
2643 /* MST doesn't perform link training for now
2644 * TODO: add MST specific link training routine
2646 if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2647 if (decide_mst_link_settings(link, link_setting))
2649 } else if (link->connector_signal == SIGNAL_TYPE_EDP) {
2650 if (decide_edp_link_settings(link, link_setting, req_bw))
2652 } else if (decide_dp_link_settings(link, link_setting, req_bw))
2655 BREAK_TO_DEBUGGER();
2656 ASSERT(link->verified_link_cap.lane_count != LANE_COUNT_UNKNOWN);
2658 *link_setting = link->verified_link_cap;
2661 /*************************Short Pulse IRQ***************************/
2662 static bool allow_hpd_rx_irq(const struct dc_link *link)
2665 * Don't handle RX IRQ unless one of following is met:
2666 * 1) The link is established (cur_link_settings != unknown)
2667 * 2) We know we're dealing with a branch device, SST or MST
2670 if ((link->cur_link_settings.lane_count != LANE_COUNT_UNKNOWN) ||
2671 is_dp_branch_device(link))
2677 static bool handle_hpd_irq_psr_sink(struct dc_link *link)
2679 union dpcd_psr_configuration psr_configuration;
2681 if (!link->psr_settings.psr_feature_enabled)
2684 dm_helpers_dp_read_dpcd(
2687 368,/*DpcdAddress_PSR_Enable_Cfg*/
2688 &psr_configuration.raw,
2689 sizeof(psr_configuration.raw));
2692 if (psr_configuration.bits.ENABLE) {
2693 unsigned char dpcdbuf[3] = {0};
2694 union psr_error_status psr_error_status;
2695 union psr_sink_psr_status psr_sink_psr_status;
2697 dm_helpers_dp_read_dpcd(
2700 0x2006, /*DpcdAddress_PSR_Error_Status*/
2701 (unsigned char *) dpcdbuf,
2704 /*DPCD 2006h ERROR STATUS*/
2705 psr_error_status.raw = dpcdbuf[0];
2706 /*DPCD 2008h SINK PANEL SELF REFRESH STATUS*/
2707 psr_sink_psr_status.raw = dpcdbuf[2];
2709 if (psr_error_status.bits.LINK_CRC_ERROR ||
2710 psr_error_status.bits.RFB_STORAGE_ERROR ||
2711 psr_error_status.bits.VSC_SDP_ERROR) {
2712 /* Acknowledge and clear error bits */
2713 dm_helpers_dp_write_dpcd(
2716 8198,/*DpcdAddress_PSR_Error_Status*/
2717 &psr_error_status.raw,
2718 sizeof(psr_error_status.raw));
2720 /* PSR error, disable and re-enable PSR */
2721 dc_link_set_psr_allow_active(link, false, true, false);
2722 dc_link_set_psr_allow_active(link, true, true, false);
2725 } else if (psr_sink_psr_status.bits.SINK_SELF_REFRESH_STATUS ==
2726 PSR_SINK_STATE_ACTIVE_DISPLAY_FROM_SINK_RFB){
2727 /* No error is detect, PSR is active.
2728 * We should return with IRQ_HPD handled without
2729 * checking for loss of sync since PSR would have
2730 * powered down main link.
2738 static void dp_test_send_link_training(struct dc_link *link)
2740 struct dc_link_settings link_settings = {0};
2742 core_link_read_dpcd(
2745 (unsigned char *)(&link_settings.lane_count),
2747 core_link_read_dpcd(
2750 (unsigned char *)(&link_settings.link_rate),
2753 /* Set preferred link settings */
2754 link->verified_link_cap.lane_count = link_settings.lane_count;
2755 link->verified_link_cap.link_rate = link_settings.link_rate;
2757 dp_retrain_link_dp_test(link, &link_settings, false);
2760 /* TODO Raven hbr2 compliance eye output is unstable
2761 * (toggling on and off) with debugger break
2762 * This caueses intermittent PHY automation failure
2763 * Need to look into the root cause */
2764 static void dp_test_send_phy_test_pattern(struct dc_link *link)
2766 union phy_test_pattern dpcd_test_pattern;
2767 union lane_adjust dpcd_lane_adjustment[2];
2768 unsigned char dpcd_post_cursor_2_adjustment = 0;
2769 unsigned char test_pattern_buffer[
2770 (DP_TEST_80BIT_CUSTOM_PATTERN_79_72 -
2771 DP_TEST_80BIT_CUSTOM_PATTERN_7_0)+1] = {0};
2772 unsigned int test_pattern_size = 0;
2773 enum dp_test_pattern test_pattern;
2774 struct dc_link_training_settings link_settings;
2775 union lane_adjust dpcd_lane_adjust;
2777 struct link_training_settings link_training_settings;
2780 dpcd_test_pattern.raw = 0;
2781 memset(dpcd_lane_adjustment, 0, sizeof(dpcd_lane_adjustment));
2782 memset(&link_settings, 0, sizeof(link_settings));
2784 /* get phy test pattern and pattern parameters from DP receiver */
2785 core_link_read_dpcd(
2787 DP_PHY_TEST_PATTERN,
2788 &dpcd_test_pattern.raw,
2789 sizeof(dpcd_test_pattern));
2790 core_link_read_dpcd(
2792 DP_ADJUST_REQUEST_LANE0_1,
2793 &dpcd_lane_adjustment[0].raw,
2794 sizeof(dpcd_lane_adjustment));
2796 /*get post cursor 2 parameters
2797 * For DP 1.1a or eariler, this DPCD register's value is 0
2798 * For DP 1.2 or later:
2799 * Bits 1:0 = POST_CURSOR2_LANE0; Bits 3:2 = POST_CURSOR2_LANE1
2800 * Bits 5:4 = POST_CURSOR2_LANE2; Bits 7:6 = POST_CURSOR2_LANE3
2802 core_link_read_dpcd(
2804 DP_ADJUST_REQUEST_POST_CURSOR2,
2805 &dpcd_post_cursor_2_adjustment,
2806 sizeof(dpcd_post_cursor_2_adjustment));
2808 /* translate request */
2809 switch (dpcd_test_pattern.bits.PATTERN) {
2810 case PHY_TEST_PATTERN_D10_2:
2811 test_pattern = DP_TEST_PATTERN_D102;
2813 case PHY_TEST_PATTERN_SYMBOL_ERROR:
2814 test_pattern = DP_TEST_PATTERN_SYMBOL_ERROR;
2816 case PHY_TEST_PATTERN_PRBS7:
2817 test_pattern = DP_TEST_PATTERN_PRBS7;
2819 case PHY_TEST_PATTERN_80BIT_CUSTOM:
2820 test_pattern = DP_TEST_PATTERN_80BIT_CUSTOM;
2822 case PHY_TEST_PATTERN_CP2520_1:
2823 /* CP2520 pattern is unstable, temporarily use TPS4 instead */
2824 test_pattern = (link->dc->caps.force_dp_tps4_for_cp2520 == 1) ?
2825 DP_TEST_PATTERN_TRAINING_PATTERN4 :
2826 DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE;
2828 case PHY_TEST_PATTERN_CP2520_2:
2829 /* CP2520 pattern is unstable, temporarily use TPS4 instead */
2830 test_pattern = (link->dc->caps.force_dp_tps4_for_cp2520 == 1) ?
2831 DP_TEST_PATTERN_TRAINING_PATTERN4 :
2832 DP_TEST_PATTERN_HBR2_COMPLIANCE_EYE;
2834 case PHY_TEST_PATTERN_CP2520_3:
2835 test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN4;
2838 test_pattern = DP_TEST_PATTERN_VIDEO_MODE;
2842 if (test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM) {
2843 test_pattern_size = (DP_TEST_80BIT_CUSTOM_PATTERN_79_72 -
2844 DP_TEST_80BIT_CUSTOM_PATTERN_7_0) + 1;
2845 core_link_read_dpcd(
2847 DP_TEST_80BIT_CUSTOM_PATTERN_7_0,
2848 test_pattern_buffer,
2852 /* prepare link training settings */
2853 link_settings.link = link->cur_link_settings;
2855 for (lane = 0; lane <
2856 (unsigned int)(link->cur_link_settings.lane_count);
2858 dpcd_lane_adjust.raw =
2859 get_nibble_at_index(&dpcd_lane_adjustment[0].raw, lane);
2860 link_settings.lane_settings[lane].VOLTAGE_SWING =
2861 (enum dc_voltage_swing)
2862 (dpcd_lane_adjust.bits.VOLTAGE_SWING_LANE);
2863 link_settings.lane_settings[lane].PRE_EMPHASIS =
2864 (enum dc_pre_emphasis)
2865 (dpcd_lane_adjust.bits.PRE_EMPHASIS_LANE);
2866 link_settings.lane_settings[lane].POST_CURSOR2 =
2867 (enum dc_post_cursor2)
2868 ((dpcd_post_cursor_2_adjustment >> (lane * 2)) & 0x03);
2871 for (i = 0; i < 4; i++)
2872 link_training_settings.lane_settings[i] =
2873 link_settings.lane_settings[i];
2874 link_training_settings.link_settings = link_settings.link;
2875 link_training_settings.allow_invalid_msa_timing_param = false;
2876 /*Usage: Measure DP physical lane signal
2877 * by DP SI test equipment automatically.
2878 * PHY test pattern request is generated by equipment via HPD interrupt.
2879 * HPD needs to be active all the time. HPD should be active
2880 * all the time. Do not touch it.
2881 * forward request to DS
2883 dc_link_dp_set_test_pattern(
2886 DP_TEST_PATTERN_COLOR_SPACE_UNDEFINED,
2887 &link_training_settings,
2888 test_pattern_buffer,
2892 static void dp_test_send_link_test_pattern(struct dc_link *link)
2894 union link_test_pattern dpcd_test_pattern;
2895 union test_misc dpcd_test_params;
2896 enum dp_test_pattern test_pattern;
2897 enum dp_test_pattern_color_space test_pattern_color_space =
2898 DP_TEST_PATTERN_COLOR_SPACE_UNDEFINED;
2899 enum dc_color_depth requestColorDepth = COLOR_DEPTH_UNDEFINED;
2900 struct pipe_ctx *pipes = link->dc->current_state->res_ctx.pipe_ctx;
2901 struct pipe_ctx *pipe_ctx = NULL;
2904 memset(&dpcd_test_pattern, 0, sizeof(dpcd_test_pattern));
2905 memset(&dpcd_test_params, 0, sizeof(dpcd_test_params));
2907 for (i = 0; i < MAX_PIPES; i++) {
2908 if (pipes[i].stream == NULL)
2911 if (pipes[i].stream->link == link && !pipes[i].top_pipe && !pipes[i].prev_odm_pipe) {
2912 pipe_ctx = &pipes[i];
2917 if (pipe_ctx == NULL)
2920 /* get link test pattern and pattern parameters */
2921 core_link_read_dpcd(
2924 &dpcd_test_pattern.raw,
2925 sizeof(dpcd_test_pattern));
2926 core_link_read_dpcd(
2929 &dpcd_test_params.raw,
2930 sizeof(dpcd_test_params));
2932 switch (dpcd_test_pattern.bits.PATTERN) {
2933 case LINK_TEST_PATTERN_COLOR_RAMP:
2934 test_pattern = DP_TEST_PATTERN_COLOR_RAMP;
2936 case LINK_TEST_PATTERN_VERTICAL_BARS:
2937 test_pattern = DP_TEST_PATTERN_VERTICAL_BARS;
2938 break; /* black and white */
2939 case LINK_TEST_PATTERN_COLOR_SQUARES:
2940 test_pattern = (dpcd_test_params.bits.DYN_RANGE ==
2941 TEST_DYN_RANGE_VESA ?
2942 DP_TEST_PATTERN_COLOR_SQUARES :
2943 DP_TEST_PATTERN_COLOR_SQUARES_CEA);
2946 test_pattern = DP_TEST_PATTERN_VIDEO_MODE;
2950 if (dpcd_test_params.bits.CLR_FORMAT == 0)
2951 test_pattern_color_space = DP_TEST_PATTERN_COLOR_SPACE_RGB;
2953 test_pattern_color_space = dpcd_test_params.bits.YCBCR_COEFS ?
2954 DP_TEST_PATTERN_COLOR_SPACE_YCBCR709 :
2955 DP_TEST_PATTERN_COLOR_SPACE_YCBCR601;
2957 switch (dpcd_test_params.bits.BPC) {
2959 requestColorDepth = COLOR_DEPTH_666;
2962 requestColorDepth = COLOR_DEPTH_888;
2965 requestColorDepth = COLOR_DEPTH_101010;
2968 requestColorDepth = COLOR_DEPTH_121212;
2974 switch (dpcd_test_params.bits.CLR_FORMAT) {
2976 pipe_ctx->stream->timing.pixel_encoding = PIXEL_ENCODING_RGB;
2979 pipe_ctx->stream->timing.pixel_encoding = PIXEL_ENCODING_YCBCR422;
2982 pipe_ctx->stream->timing.pixel_encoding = PIXEL_ENCODING_YCBCR444;
2985 pipe_ctx->stream->timing.pixel_encoding = PIXEL_ENCODING_RGB;
2990 if (requestColorDepth != COLOR_DEPTH_UNDEFINED
2991 && pipe_ctx->stream->timing.display_color_depth != requestColorDepth) {
2992 DC_LOG_DEBUG("%s: original bpc %d, changing to %d\n",
2994 pipe_ctx->stream->timing.display_color_depth,
2996 pipe_ctx->stream->timing.display_color_depth = requestColorDepth;
2999 dp_update_dsc_config(pipe_ctx);
3001 dc_link_dp_set_test_pattern(
3004 test_pattern_color_space,
3010 static void dp_test_get_audio_test_data(struct dc_link *link, bool disable_video)
3012 union audio_test_mode dpcd_test_mode = {0};
3013 struct audio_test_pattern_type dpcd_pattern_type = {0};
3014 union audio_test_pattern_period dpcd_pattern_period[AUDIO_CHANNELS_COUNT] = {0};
3015 enum dp_test_pattern test_pattern = DP_TEST_PATTERN_AUDIO_OPERATOR_DEFINED;
3017 struct pipe_ctx *pipes = link->dc->current_state->res_ctx.pipe_ctx;
3018 struct pipe_ctx *pipe_ctx = &pipes[0];
3019 unsigned int channel_count;
3020 unsigned int channel = 0;
3021 unsigned int modes = 0;
3022 unsigned int sampling_rate_in_hz = 0;
3024 // get audio test mode and test pattern parameters
3025 core_link_read_dpcd(
3028 &dpcd_test_mode.raw,
3029 sizeof(dpcd_test_mode));
3031 core_link_read_dpcd(
3033 DP_TEST_AUDIO_PATTERN_TYPE,
3034 &dpcd_pattern_type.value,
3035 sizeof(dpcd_pattern_type));
3037 channel_count = dpcd_test_mode.bits.channel_count + 1;
3039 // read pattern periods for requested channels when sawTooth pattern is requested
3040 if (dpcd_pattern_type.value == AUDIO_TEST_PATTERN_SAWTOOTH ||
3041 dpcd_pattern_type.value == AUDIO_TEST_PATTERN_OPERATOR_DEFINED) {
3043 test_pattern = (dpcd_pattern_type.value == AUDIO_TEST_PATTERN_SAWTOOTH) ?
3044 DP_TEST_PATTERN_AUDIO_SAWTOOTH : DP_TEST_PATTERN_AUDIO_OPERATOR_DEFINED;
3045 // read period for each channel
3046 for (channel = 0; channel < channel_count; channel++) {
3047 core_link_read_dpcd(
3049 DP_TEST_AUDIO_PERIOD_CH1 + channel,
3050 &dpcd_pattern_period[channel].raw,
3051 sizeof(dpcd_pattern_period[channel]));
3055 // translate sampling rate
3056 switch (dpcd_test_mode.bits.sampling_rate) {
3057 case AUDIO_SAMPLING_RATE_32KHZ:
3058 sampling_rate_in_hz = 32000;
3060 case AUDIO_SAMPLING_RATE_44_1KHZ:
3061 sampling_rate_in_hz = 44100;
3063 case AUDIO_SAMPLING_RATE_48KHZ:
3064 sampling_rate_in_hz = 48000;
3066 case AUDIO_SAMPLING_RATE_88_2KHZ:
3067 sampling_rate_in_hz = 88200;
3069 case AUDIO_SAMPLING_RATE_96KHZ:
3070 sampling_rate_in_hz = 96000;
3072 case AUDIO_SAMPLING_RATE_176_4KHZ:
3073 sampling_rate_in_hz = 176400;
3075 case AUDIO_SAMPLING_RATE_192KHZ:
3076 sampling_rate_in_hz = 192000;
3079 sampling_rate_in_hz = 0;
3083 link->audio_test_data.flags.test_requested = 1;
3084 link->audio_test_data.flags.disable_video = disable_video;
3085 link->audio_test_data.sampling_rate = sampling_rate_in_hz;
3086 link->audio_test_data.channel_count = channel_count;
3087 link->audio_test_data.pattern_type = test_pattern;
3089 if (test_pattern == DP_TEST_PATTERN_AUDIO_SAWTOOTH) {
3090 for (modes = 0; modes < pipe_ctx->stream->audio_info.mode_count; modes++) {
3091 link->audio_test_data.pattern_period[modes] = dpcd_pattern_period[modes].bits.pattern_period;
3096 static void handle_automated_test(struct dc_link *link)
3098 union test_request test_request;
3099 union test_response test_response;
3101 memset(&test_request, 0, sizeof(test_request));
3102 memset(&test_response, 0, sizeof(test_response));
3104 core_link_read_dpcd(
3108 sizeof(union test_request));
3109 if (test_request.bits.LINK_TRAINING) {
3110 /* ACK first to let DP RX test box monitor LT sequence */
3111 test_response.bits.ACK = 1;
3112 core_link_write_dpcd(
3116 sizeof(test_response));
3117 dp_test_send_link_training(link);
3118 /* no acknowledge request is needed again */
3119 test_response.bits.ACK = 0;
3121 if (test_request.bits.LINK_TEST_PATTRN) {
3122 dp_test_send_link_test_pattern(link);
3123 test_response.bits.ACK = 1;
3126 if (test_request.bits.AUDIO_TEST_PATTERN) {
3127 dp_test_get_audio_test_data(link, test_request.bits.TEST_AUDIO_DISABLED_VIDEO);
3128 test_response.bits.ACK = 1;
3131 if (test_request.bits.PHY_TEST_PATTERN) {
3132 dp_test_send_phy_test_pattern(link);
3133 test_response.bits.ACK = 1;
3136 /* send request acknowledgment */
3137 if (test_response.bits.ACK)
3138 core_link_write_dpcd(
3142 sizeof(test_response));
3145 bool dc_link_handle_hpd_rx_irq(struct dc_link *link, union hpd_irq_data *out_hpd_irq_dpcd_data, bool *out_link_loss)
3147 union hpd_irq_data hpd_irq_dpcd_data = { { { {0} } } };
3148 union device_service_irq device_service_clear = { { 0 } };
3149 enum dc_status result;
3150 bool status = false;
3151 struct pipe_ctx *pipe_ctx;
3155 *out_link_loss = false;
3156 /* For use cases related to down stream connection status change,
3157 * PSR and device auto test, refer to function handle_sst_hpd_irq
3160 DC_LOG_HW_HPD_IRQ("%s: Got short pulse HPD on link %d\n",
3161 __func__, link->link_index);
3164 /* All the "handle_hpd_irq_xxx()" methods
3165 * should be called only after
3166 * dal_dpsst_ls_read_hpd_irq_data
3167 * Order of calls is important too
3169 result = read_hpd_rx_irq_data(link, &hpd_irq_dpcd_data);
3170 if (out_hpd_irq_dpcd_data)
3171 *out_hpd_irq_dpcd_data = hpd_irq_dpcd_data;
3173 if (result != DC_OK) {
3174 DC_LOG_HW_HPD_IRQ("%s: DPCD read failed to obtain irq data\n",
3179 if (hpd_irq_dpcd_data.bytes.device_service_irq.bits.AUTOMATED_TEST) {
3180 device_service_clear.bits.AUTOMATED_TEST = 1;
3181 core_link_write_dpcd(
3183 DP_DEVICE_SERVICE_IRQ_VECTOR,
3184 &device_service_clear.raw,
3185 sizeof(device_service_clear.raw));
3186 device_service_clear.raw = 0;
3187 handle_automated_test(link);
3191 if (!allow_hpd_rx_irq(link)) {
3192 DC_LOG_HW_HPD_IRQ("%s: skipping HPD handling on %d\n",
3193 __func__, link->link_index);
3197 if (handle_hpd_irq_psr_sink(link))
3198 /* PSR-related error was detected and handled */
3201 /* If PSR-related error handled, Main link may be off,
3202 * so do not handle as a normal sink status change interrupt.
3205 if (hpd_irq_dpcd_data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY)
3208 /* check if we have MST msg and return since we poll for it */
3209 if (hpd_irq_dpcd_data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY)
3212 /* For now we only handle 'Downstream port status' case.
3213 * If we got sink count changed it means
3214 * Downstream port status changed,
3215 * then DM should call DC to do the detection.
3216 * NOTE: Do not handle link loss on eDP since it is internal link*/
3217 if ((link->connector_signal != SIGNAL_TYPE_EDP) &&
3218 hpd_rx_irq_check_link_loss_status(
3220 &hpd_irq_dpcd_data)) {
3221 /* Connectivity log: link loss */
3222 CONN_DATA_LINK_LOSS(link,
3223 hpd_irq_dpcd_data.raw,
3224 sizeof(hpd_irq_dpcd_data),
3227 for (i = 0; i < MAX_PIPES; i++) {
3228 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
3229 if (pipe_ctx && pipe_ctx->stream && pipe_ctx->stream->link == link)
3233 if (pipe_ctx == NULL || pipe_ctx->stream == NULL)
3237 for (i = 0; i < MAX_PIPES; i++) {
3238 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
3239 if (pipe_ctx && pipe_ctx->stream && !pipe_ctx->stream->dpms_off &&
3240 pipe_ctx->stream->link == link && !pipe_ctx->prev_odm_pipe)
3241 core_link_disable_stream(pipe_ctx);
3244 for (i = 0; i < MAX_PIPES; i++) {
3245 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
3246 if (pipe_ctx && pipe_ctx->stream && !pipe_ctx->stream->dpms_off &&
3247 pipe_ctx->stream->link == link && !pipe_ctx->prev_odm_pipe)
3248 core_link_enable_stream(link->dc->current_state, pipe_ctx);
3253 *out_link_loss = true;
3256 if (link->type == dc_connection_sst_branch &&
3257 hpd_irq_dpcd_data.bytes.sink_cnt.bits.SINK_COUNT
3258 != link->dpcd_sink_count)
3261 /* reasons for HPD RX:
3262 * 1. Link Loss - ie Re-train the Link
3263 * 2. MST sideband message
3264 * 3. Automated Test - ie. Internal Commit
3265 * 4. CP (copy protection) - (not interesting for DM???)
3267 * 6. Downstream Port status changed
3268 * -ie. Detect - this the only one
3269 * which is interesting for DM because
3270 * it must call dc_link_detect.
3275 /*query dpcd for version and mst cap addresses*/
3276 bool is_mst_supported(struct dc_link *link)
3279 enum dc_status st = DC_OK;
3283 if (link->preferred_training_settings.mst_enable &&
3284 *link->preferred_training_settings.mst_enable == false) {
3291 st = core_link_read_dpcd(link, DP_DPCD_REV, &rev.raw,
3294 if (st == DC_OK && rev.raw >= DPCD_REV_12) {
3296 st = core_link_read_dpcd(link, DP_MSTM_CAP,
3297 &cap.raw, sizeof(cap));
3298 if (st == DC_OK && cap.bits.MST_CAP == 1)
3305 bool is_dp_active_dongle(const struct dc_link *link)
3307 return (link->dpcd_caps.dongle_type >= DISPLAY_DONGLE_DP_VGA_CONVERTER) &&
3308 (link->dpcd_caps.dongle_type <= DISPLAY_DONGLE_DP_HDMI_CONVERTER);
3311 bool is_dp_branch_device(const struct dc_link *link)
3313 return link->dpcd_caps.is_branch_dev;
3316 static int translate_dpcd_max_bpc(enum dpcd_downstream_port_max_bpc bpc)
3319 case DOWN_STREAM_MAX_8BPC:
3321 case DOWN_STREAM_MAX_10BPC:
3323 case DOWN_STREAM_MAX_12BPC:
3325 case DOWN_STREAM_MAX_16BPC:
3334 static void read_dp_device_vendor_id(struct dc_link *link)
3336 struct dp_device_vendor_id dp_id;
3338 /* read IEEE branch device id */
3339 core_link_read_dpcd(
3345 link->dpcd_caps.branch_dev_id =
3346 (dp_id.ieee_oui[0] << 16) +
3347 (dp_id.ieee_oui[1] << 8) +
3351 link->dpcd_caps.branch_dev_name,
3352 dp_id.ieee_device_id,
3353 sizeof(dp_id.ieee_device_id));
3358 static void get_active_converter_info(
3359 uint8_t data, struct dc_link *link)
3361 union dp_downstream_port_present ds_port = { .byte = data };
3362 memset(&link->dpcd_caps.dongle_caps, 0, sizeof(link->dpcd_caps.dongle_caps));
3364 /* decode converter info*/
3365 if (!ds_port.fields.PORT_PRESENT) {
3366 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
3367 ddc_service_set_dongle_type(link->ddc,
3368 link->dpcd_caps.dongle_type);
3369 link->dpcd_caps.is_branch_dev = false;
3373 /* DPCD 0x5 bit 0 = 1, it indicate it's branch device */
3374 link->dpcd_caps.is_branch_dev = ds_port.fields.PORT_PRESENT;
3376 switch (ds_port.fields.PORT_TYPE) {
3377 case DOWNSTREAM_VGA:
3378 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_VGA_CONVERTER;
3380 case DOWNSTREAM_DVI_HDMI_DP_PLUS_PLUS:
3381 /* At this point we don't know is it DVI or HDMI or DP++,
3383 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_DVI_CONVERTER;
3386 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
3390 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_11) {
3391 uint8_t det_caps[16]; /* CTS 4.2.2.7 expects source to read Detailed Capabilities Info : 00080h-0008F.*/
3392 union dwnstream_port_caps_byte0 *port_caps =
3393 (union dwnstream_port_caps_byte0 *)det_caps;
3394 if (core_link_read_dpcd(link, DP_DOWNSTREAM_PORT_0,
3395 det_caps, sizeof(det_caps)) == DC_OK) {
3397 switch (port_caps->bits.DWN_STRM_PORTX_TYPE) {
3398 /*Handle DP case as DONGLE_NONE*/
3399 case DOWN_STREAM_DETAILED_DP:
3400 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
3402 case DOWN_STREAM_DETAILED_VGA:
3403 link->dpcd_caps.dongle_type =
3404 DISPLAY_DONGLE_DP_VGA_CONVERTER;
3406 case DOWN_STREAM_DETAILED_DVI:
3407 link->dpcd_caps.dongle_type =
3408 DISPLAY_DONGLE_DP_DVI_CONVERTER;
3410 case DOWN_STREAM_DETAILED_HDMI:
3411 case DOWN_STREAM_DETAILED_DP_PLUS_PLUS:
3412 /*Handle DP++ active converter case, process DP++ case as HDMI case according DP1.4 spec*/
3413 link->dpcd_caps.dongle_type =
3414 DISPLAY_DONGLE_DP_HDMI_CONVERTER;
3416 link->dpcd_caps.dongle_caps.dongle_type = link->dpcd_caps.dongle_type;
3417 if (ds_port.fields.DETAILED_CAPS) {
3419 union dwnstream_port_caps_byte3_hdmi
3420 hdmi_caps = {.raw = det_caps[3] };
3421 union dwnstream_port_caps_byte2
3422 hdmi_color_caps = {.raw = det_caps[2] };
3423 link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz =
3426 link->dpcd_caps.dongle_caps.is_dp_hdmi_s3d_converter =
3427 hdmi_caps.bits.FRAME_SEQ_TO_FRAME_PACK;
3428 /*YCBCR capability only for HDMI case*/
3429 if (port_caps->bits.DWN_STRM_PORTX_TYPE
3430 == DOWN_STREAM_DETAILED_HDMI) {
3431 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_pass_through =
3432 hdmi_caps.bits.YCrCr422_PASS_THROUGH;
3433 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_pass_through =
3434 hdmi_caps.bits.YCrCr420_PASS_THROUGH;
3435 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_converter =
3436 hdmi_caps.bits.YCrCr422_CONVERSION;
3437 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_converter =
3438 hdmi_caps.bits.YCrCr420_CONVERSION;
3441 link->dpcd_caps.dongle_caps.dp_hdmi_max_bpc =
3442 translate_dpcd_max_bpc(
3443 hdmi_color_caps.bits.MAX_BITS_PER_COLOR_COMPONENT);
3445 if (link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz != 0)
3446 link->dpcd_caps.dongle_caps.extendedCapValid = true;
3454 ddc_service_set_dongle_type(link->ddc, link->dpcd_caps.dongle_type);
3457 struct dp_sink_hw_fw_revision dp_hw_fw_revision;
3459 core_link_read_dpcd(
3461 DP_BRANCH_REVISION_START,
3462 (uint8_t *)&dp_hw_fw_revision,
3463 sizeof(dp_hw_fw_revision));
3465 link->dpcd_caps.branch_hw_revision =
3466 dp_hw_fw_revision.ieee_hw_rev;
3469 link->dpcd_caps.branch_fw_revision,
3470 dp_hw_fw_revision.ieee_fw_rev,
3471 sizeof(dp_hw_fw_revision.ieee_fw_rev));
3475 static void dp_wa_power_up_0010FA(struct dc_link *link, uint8_t *dpcd_data,
3480 if (!link->dpcd_caps.dpcd_rev.raw) {
3482 dp_receiver_power_ctrl(link, true);
3483 core_link_read_dpcd(link, DP_DPCD_REV,
3485 link->dpcd_caps.dpcd_rev.raw = dpcd_data[
3488 } while (retry++ < 4 && !link->dpcd_caps.dpcd_rev.raw);
3491 if (link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_VGA_CONVERTER) {
3492 switch (link->dpcd_caps.branch_dev_id) {
3493 /* 0010FA active dongles (DP-VGA, DP-DLDVI converters) power down
3494 * all internal circuits including AUX communication preventing
3495 * reading DPCD table and EDID (spec violation).
3496 * Encoder will skip DP RX power down on disable_output to
3497 * keep receiver powered all the time.*/
3498 case DP_BRANCH_DEVICE_ID_0010FA:
3499 case DP_BRANCH_DEVICE_ID_0080E1:
3500 case DP_BRANCH_DEVICE_ID_00E04C:
3501 link->wa_flags.dp_keep_receiver_powered = true;
3504 /* TODO: May need work around for other dongles. */
3506 link->wa_flags.dp_keep_receiver_powered = false;
3510 link->wa_flags.dp_keep_receiver_powered = false;
3513 /* Read additional sink caps defined in source specific DPCD area
3514 * This function currently only reads from SinkCapability address (DP_SOURCE_SINK_CAP)
3516 static bool dpcd_read_sink_ext_caps(struct dc_link *link)
3523 if (core_link_read_dpcd(link, DP_SOURCE_SINK_CAP, &dpcd_data, 1) != DC_OK)
3526 link->dpcd_sink_ext_caps.raw = dpcd_data;
3530 static bool retrieve_link_cap(struct dc_link *link)
3532 /* DP_ADAPTER_CAP - DP_DPCD_REV + 1 == 16 and also DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT + 1 == 16,
3533 * which means size 16 will be good for both of those DPCD register block reads
3535 uint8_t dpcd_data[16];
3536 uint8_t lttpr_dpcd_data[6];
3538 /*Only need to read 1 byte starting from DP_DPRX_FEATURE_ENUMERATION_LIST.
3540 uint8_t dpcd_dprx_data = '\0';
3541 uint8_t dpcd_power_state = '\0';
3543 struct dp_device_vendor_id sink_id;
3544 union down_stream_port_count down_strm_port_count;
3545 union edp_configuration_cap edp_config_cap;
3546 union dp_downstream_port_present ds_port = { 0 };
3547 enum dc_status status = DC_ERROR_UNEXPECTED;
3548 uint32_t read_dpcd_retry_cnt = 3;
3550 struct dp_sink_hw_fw_revision dp_hw_fw_revision;
3551 bool is_lttpr_present = false;
3552 const uint32_t post_oui_delay = 30; // 30ms
3553 bool vbios_lttpr_enable = false;
3554 bool vbios_lttpr_interop = false;
3555 struct dc_bios *bios = link->dc->ctx->dc_bios;
3557 memset(dpcd_data, '\0', sizeof(dpcd_data));
3558 memset(lttpr_dpcd_data, '\0', sizeof(lttpr_dpcd_data));
3559 memset(&down_strm_port_count,
3560 '\0', sizeof(union down_stream_port_count));
3561 memset(&edp_config_cap, '\0',
3562 sizeof(union edp_configuration_cap));
3564 /* if extended timeout is supported in hardware,
3565 * default to LTTPR timeout (3.2ms) first as a W/A for DP link layer
3566 * CTS 4.2.1.1 regression introduced by CTS specs requirement update.
3568 dc_link_aux_try_to_configure_timeout(link->ddc,
3569 LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD);
3571 status = core_link_read_dpcd(link, DP_SET_POWER,
3572 &dpcd_power_state, sizeof(dpcd_power_state));
3574 /* Delay 1 ms if AUX CH is in power down state. Based on spec
3575 * section 2.3.1.2, if AUX CH may be powered down due to
3576 * write to DPCD 600h = 2. Sink AUX CH is monitoring differential
3577 * signal and may need up to 1 ms before being able to reply.
3579 if (status != DC_OK || dpcd_power_state == DP_SET_POWER_D3)
3582 dpcd_set_source_specific_data(link);
3583 /* Sink may need to configure internals based on vendor, so allow some
3584 * time before proceeding with possibly vendor specific transactions
3586 msleep(post_oui_delay);
3588 for (i = 0; i < read_dpcd_retry_cnt; i++) {
3589 status = core_link_read_dpcd(
3594 if (status == DC_OK)
3598 if (status != DC_OK) {
3599 dm_error("%s: Read dpcd data failed.\n", __func__);
3603 /* Query BIOS to determine if LTTPR functionality is forced on by system */
3604 if (bios->funcs->get_lttpr_caps) {
3605 enum bp_result bp_query_result;
3606 uint8_t is_vbios_lttpr_enable = 0;
3608 bp_query_result = bios->funcs->get_lttpr_caps(bios, &is_vbios_lttpr_enable);
3609 vbios_lttpr_enable = (bp_query_result == BP_RESULT_OK) && !!is_vbios_lttpr_enable;
3612 if (bios->funcs->get_lttpr_interop) {
3613 enum bp_result bp_query_result;
3614 uint8_t is_vbios_interop_enabled = 0;
3616 bp_query_result = bios->funcs->get_lttpr_interop(bios, &is_vbios_interop_enabled);
3617 vbios_lttpr_interop = (bp_query_result == BP_RESULT_OK) && !!is_vbios_interop_enabled;
3621 * Logic to determine LTTPR mode
3623 link->lttpr_mode = LTTPR_MODE_NON_LTTPR;
3624 if (vbios_lttpr_enable && vbios_lttpr_interop)
3625 link->lttpr_mode = LTTPR_MODE_NON_TRANSPARENT;
3626 else if (!vbios_lttpr_enable && vbios_lttpr_interop) {
3627 if (link->dc->config.allow_lttpr_non_transparent_mode)
3628 link->lttpr_mode = LTTPR_MODE_NON_TRANSPARENT;
3630 link->lttpr_mode = LTTPR_MODE_TRANSPARENT;
3631 } else if (!vbios_lttpr_enable && !vbios_lttpr_interop) {
3632 if (!link->dc->config.allow_lttpr_non_transparent_mode
3633 || !link->dc->caps.extended_aux_timeout_support)
3634 link->lttpr_mode = LTTPR_MODE_NON_LTTPR;
3636 link->lttpr_mode = LTTPR_MODE_NON_TRANSPARENT;
3639 if (link->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT || link->lttpr_mode == LTTPR_MODE_TRANSPARENT) {
3640 /* By reading LTTPR capability, RX assumes that we will enable
3641 * LTTPR extended aux timeout if LTTPR is present.
3643 status = core_link_read_dpcd(
3645 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV,
3647 sizeof(lttpr_dpcd_data));
3649 link->dpcd_caps.lttpr_caps.revision.raw =
3650 lttpr_dpcd_data[DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV -
3651 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
3653 link->dpcd_caps.lttpr_caps.max_link_rate =
3654 lttpr_dpcd_data[DP_MAX_LINK_RATE_PHY_REPEATER -
3655 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
3657 link->dpcd_caps.lttpr_caps.phy_repeater_cnt =
3658 lttpr_dpcd_data[DP_PHY_REPEATER_CNT -
3659 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
3661 link->dpcd_caps.lttpr_caps.max_lane_count =
3662 lttpr_dpcd_data[DP_MAX_LANE_COUNT_PHY_REPEATER -
3663 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
3665 link->dpcd_caps.lttpr_caps.mode =
3666 lttpr_dpcd_data[DP_PHY_REPEATER_MODE -
3667 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
3669 link->dpcd_caps.lttpr_caps.max_ext_timeout =
3670 lttpr_dpcd_data[DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT -
3671 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
3673 /* Attempt to train in LTTPR transparent mode if repeater count exceeds 8. */
3674 is_lttpr_present = (link->dpcd_caps.lttpr_caps.phy_repeater_cnt > 0 &&
3675 link->dpcd_caps.lttpr_caps.phy_repeater_cnt < 0xff &&
3676 link->dpcd_caps.lttpr_caps.max_lane_count > 0 &&
3677 link->dpcd_caps.lttpr_caps.max_lane_count <= 4 &&
3678 link->dpcd_caps.lttpr_caps.revision.raw >= 0x14);
3679 if (is_lttpr_present)
3680 CONN_DATA_DETECT(link, lttpr_dpcd_data, sizeof(lttpr_dpcd_data), "LTTPR Caps: ");
3682 link->lttpr_mode = LTTPR_MODE_NON_LTTPR;
3685 if (!is_lttpr_present)
3686 dc_link_aux_try_to_configure_timeout(link->ddc, LINK_AUX_DEFAULT_TIMEOUT_PERIOD);
3690 union training_aux_rd_interval aux_rd_interval;
3692 aux_rd_interval.raw =
3693 dpcd_data[DP_TRAINING_AUX_RD_INTERVAL];
3695 link->dpcd_caps.ext_receiver_cap_field_present =
3696 aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1;
3698 if (aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1) {
3699 uint8_t ext_cap_data[16];
3701 memset(ext_cap_data, '\0', sizeof(ext_cap_data));
3702 for (i = 0; i < read_dpcd_retry_cnt; i++) {
3703 status = core_link_read_dpcd(
3707 sizeof(ext_cap_data));
3708 if (status == DC_OK) {
3709 memcpy(dpcd_data, ext_cap_data, sizeof(dpcd_data));
3713 if (status != DC_OK)
3714 dm_error("%s: Read extend caps data failed, use cap from dpcd 0.\n", __func__);
3718 link->dpcd_caps.dpcd_rev.raw =
3719 dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
3721 if (link->dpcd_caps.ext_receiver_cap_field_present) {
3722 for (i = 0; i < read_dpcd_retry_cnt; i++) {
3723 status = core_link_read_dpcd(
3725 DP_DPRX_FEATURE_ENUMERATION_LIST,
3727 sizeof(dpcd_dprx_data));
3728 if (status == DC_OK)
3732 link->dpcd_caps.dprx_feature.raw = dpcd_dprx_data;
3734 if (status != DC_OK)
3735 dm_error("%s: Read DPRX caps data failed.\n", __func__);
3739 link->dpcd_caps.dprx_feature.raw = 0;
3743 /* Error condition checking...
3744 * It is impossible for Sink to report Max Lane Count = 0.
3745 * It is possible for Sink to report Max Link Rate = 0, if it is
3746 * an eDP device that is reporting specialized link rates in the
3747 * SUPPORTED_LINK_RATE table.
3749 if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
3752 ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
3755 read_dp_device_vendor_id(link);
3757 get_active_converter_info(ds_port.byte, link);
3759 dp_wa_power_up_0010FA(link, dpcd_data, sizeof(dpcd_data));
3761 down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
3764 link->dpcd_caps.allow_invalid_MSA_timing_param =
3765 down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
3767 link->dpcd_caps.max_ln_count.raw = dpcd_data[
3768 DP_MAX_LANE_COUNT - DP_DPCD_REV];
3770 link->dpcd_caps.max_down_spread.raw = dpcd_data[
3771 DP_MAX_DOWNSPREAD - DP_DPCD_REV];
3773 link->reported_link_cap.lane_count =
3774 link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
3775 link->reported_link_cap.link_rate = dpcd_data[
3776 DP_MAX_LINK_RATE - DP_DPCD_REV];
3777 link->reported_link_cap.link_spread =
3778 link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
3779 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
3781 edp_config_cap.raw = dpcd_data[
3782 DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
3783 link->dpcd_caps.panel_mode_edp =
3784 edp_config_cap.bits.ALT_SCRAMBLER_RESET;
3785 link->dpcd_caps.dpcd_display_control_capable =
3786 edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
3788 link->test_pattern_enabled = false;
3789 link->compliance_test_state.raw = 0;
3791 /* read sink count */
3792 core_link_read_dpcd(link,
3794 &link->dpcd_caps.sink_count.raw,
3795 sizeof(link->dpcd_caps.sink_count.raw));
3797 /* read sink ieee oui */
3798 core_link_read_dpcd(link,
3800 (uint8_t *)(&sink_id),
3803 link->dpcd_caps.sink_dev_id =
3804 (sink_id.ieee_oui[0] << 16) +
3805 (sink_id.ieee_oui[1] << 8) +
3806 (sink_id.ieee_oui[2]);
3809 link->dpcd_caps.sink_dev_id_str,
3810 sink_id.ieee_device_id,
3811 sizeof(sink_id.ieee_device_id));
3813 /* Quirk Apple MBP 2017 15" Retina panel: Wrong DP_MAX_LINK_RATE */
3815 uint8_t str_mbp_2017[] = { 101, 68, 21, 101, 98, 97 };
3817 if ((link->dpcd_caps.sink_dev_id == 0x0010fa) &&
3818 !memcmp(link->dpcd_caps.sink_dev_id_str, str_mbp_2017,
3819 sizeof(str_mbp_2017))) {
3820 link->reported_link_cap.link_rate = 0x0c;
3824 core_link_read_dpcd(
3826 DP_SINK_HW_REVISION_START,
3827 (uint8_t *)&dp_hw_fw_revision,
3828 sizeof(dp_hw_fw_revision));
3830 link->dpcd_caps.sink_hw_revision =
3831 dp_hw_fw_revision.ieee_hw_rev;
3834 link->dpcd_caps.sink_fw_revision,
3835 dp_hw_fw_revision.ieee_fw_rev,
3836 sizeof(dp_hw_fw_revision.ieee_fw_rev));
3838 memset(&link->dpcd_caps.dsc_caps, '\0',
3839 sizeof(link->dpcd_caps.dsc_caps));
3840 memset(&link->dpcd_caps.fec_cap, '\0', sizeof(link->dpcd_caps.fec_cap));
3841 /* Read DSC and FEC sink capabilities if DP revision is 1.4 and up */
3842 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14) {
3843 status = core_link_read_dpcd(
3846 &link->dpcd_caps.fec_cap.raw,
3847 sizeof(link->dpcd_caps.fec_cap.raw));
3848 status = core_link_read_dpcd(
3851 link->dpcd_caps.dsc_caps.dsc_basic_caps.raw,
3852 sizeof(link->dpcd_caps.dsc_caps.dsc_basic_caps.raw));
3853 status = core_link_read_dpcd(
3855 DP_DSC_BRANCH_OVERALL_THROUGHPUT_0,
3856 link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw,
3857 sizeof(link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw));
3860 if (!dpcd_read_sink_ext_caps(link))
3861 link->dpcd_sink_ext_caps.raw = 0;
3863 /* Connectivity log: detection */
3864 CONN_DATA_DETECT(link, dpcd_data, sizeof(dpcd_data), "Rx Caps: ");
3869 bool dp_overwrite_extended_receiver_cap(struct dc_link *link)
3871 uint8_t dpcd_data[16];
3872 uint32_t read_dpcd_retry_cnt = 3;
3873 enum dc_status status = DC_ERROR_UNEXPECTED;
3874 union dp_downstream_port_present ds_port = { 0 };
3875 union down_stream_port_count down_strm_port_count;
3876 union edp_configuration_cap edp_config_cap;
3880 for (i = 0; i < read_dpcd_retry_cnt; i++) {
3881 status = core_link_read_dpcd(
3886 if (status == DC_OK)
3890 link->dpcd_caps.dpcd_rev.raw =
3891 dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
3893 if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
3896 ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
3899 get_active_converter_info(ds_port.byte, link);
3901 down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
3904 link->dpcd_caps.allow_invalid_MSA_timing_param =
3905 down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
3907 link->dpcd_caps.max_ln_count.raw = dpcd_data[
3908 DP_MAX_LANE_COUNT - DP_DPCD_REV];
3910 link->dpcd_caps.max_down_spread.raw = dpcd_data[
3911 DP_MAX_DOWNSPREAD - DP_DPCD_REV];
3913 link->reported_link_cap.lane_count =
3914 link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
3915 link->reported_link_cap.link_rate = dpcd_data[
3916 DP_MAX_LINK_RATE - DP_DPCD_REV];
3917 link->reported_link_cap.link_spread =
3918 link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
3919 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
3921 edp_config_cap.raw = dpcd_data[
3922 DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
3923 link->dpcd_caps.panel_mode_edp =
3924 edp_config_cap.bits.ALT_SCRAMBLER_RESET;
3925 link->dpcd_caps.dpcd_display_control_capable =
3926 edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
3931 bool detect_dp_sink_caps(struct dc_link *link)
3933 return retrieve_link_cap(link);
3935 /* dc init_hw has power encoder using default
3936 * signal for connector. For native DP, no
3937 * need to power up encoder again. If not native
3938 * DP, hw_init may need check signal or power up
3941 /* TODO save sink caps in link->sink */
3944 static enum dc_link_rate linkRateInKHzToLinkRateMultiplier(uint32_t link_rate_in_khz)
3946 enum dc_link_rate link_rate;
3947 // LinkRate is normally stored as a multiplier of 0.27 Gbps per lane. Do the translation.
3948 switch (link_rate_in_khz) {
3950 link_rate = LINK_RATE_LOW; // Rate_1 (RBR) - 1.62 Gbps/Lane
3953 link_rate = LINK_RATE_RATE_2; // Rate_2 - 2.16 Gbps/Lane
3956 link_rate = LINK_RATE_RATE_3; // Rate_3 - 2.43 Gbps/Lane
3959 link_rate = LINK_RATE_HIGH; // Rate_4 (HBR) - 2.70 Gbps/Lane
3962 link_rate = LINK_RATE_RBR2; // Rate_5 (RBR2) - 3.24 Gbps/Lane
3965 link_rate = LINK_RATE_RATE_6; // Rate_6 - 4.32 Gbps/Lane
3968 link_rate = LINK_RATE_HIGH2; // Rate_7 (HBR2) - 5.40 Gbps/Lane
3971 link_rate = LINK_RATE_HIGH3; // Rate_8 (HBR3) - 8.10 Gbps/Lane
3974 link_rate = LINK_RATE_UNKNOWN;
3980 void detect_edp_sink_caps(struct dc_link *link)
3982 uint8_t supported_link_rates[16];
3984 uint32_t link_rate_in_khz;
3985 enum dc_link_rate link_rate = LINK_RATE_UNKNOWN;
3986 uint8_t backlight_adj_cap;
3988 retrieve_link_cap(link);
3989 link->dpcd_caps.edp_supported_link_rates_count = 0;
3990 memset(supported_link_rates, 0, sizeof(supported_link_rates));
3992 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14 &&
3993 (link->dc->debug.optimize_edp_link_rate ||
3994 link->reported_link_cap.link_rate == LINK_RATE_UNKNOWN)) {
3995 // Read DPCD 00010h - 0001Fh 16 bytes at one shot
3996 core_link_read_dpcd(link, DP_SUPPORTED_LINK_RATES,
3997 supported_link_rates, sizeof(supported_link_rates));
3999 for (entry = 0; entry < 16; entry += 2) {
4000 // DPCD register reports per-lane link rate = 16-bit link rate capability
4001 // value X 200 kHz. Need multiplier to find link rate in kHz.
4002 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
4003 supported_link_rates[entry]) * 200;
4005 if (link_rate_in_khz != 0) {
4006 link_rate = linkRateInKHzToLinkRateMultiplier(link_rate_in_khz);
4007 link->dpcd_caps.edp_supported_link_rates[link->dpcd_caps.edp_supported_link_rates_count] = link_rate;
4008 link->dpcd_caps.edp_supported_link_rates_count++;
4010 if (link->reported_link_cap.link_rate < link_rate)
4011 link->reported_link_cap.link_rate = link_rate;
4015 link->verified_link_cap = link->reported_link_cap;
4017 core_link_read_dpcd(link, DP_EDP_BACKLIGHT_ADJUSTMENT_CAP,
4018 &backlight_adj_cap, sizeof(backlight_adj_cap));
4020 link->dpcd_caps.dynamic_backlight_capable_edp =
4021 (backlight_adj_cap & DP_EDP_DYNAMIC_BACKLIGHT_CAP) ? true:false;
4023 dc_link_set_default_brightness_aux(link);
4026 void dc_link_dp_enable_hpd(const struct dc_link *link)
4028 struct link_encoder *encoder = link->link_enc;
4030 if (encoder != NULL && encoder->funcs->enable_hpd != NULL)
4031 encoder->funcs->enable_hpd(encoder);
4034 void dc_link_dp_disable_hpd(const struct dc_link *link)
4036 struct link_encoder *encoder = link->link_enc;
4038 if (encoder != NULL && encoder->funcs->enable_hpd != NULL)
4039 encoder->funcs->disable_hpd(encoder);
4042 static bool is_dp_phy_pattern(enum dp_test_pattern test_pattern)
4044 if ((DP_TEST_PATTERN_PHY_PATTERN_BEGIN <= test_pattern &&
4045 test_pattern <= DP_TEST_PATTERN_PHY_PATTERN_END) ||
4046 test_pattern == DP_TEST_PATTERN_VIDEO_MODE)
4052 static void set_crtc_test_pattern(struct dc_link *link,
4053 struct pipe_ctx *pipe_ctx,
4054 enum dp_test_pattern test_pattern,
4055 enum dp_test_pattern_color_space test_pattern_color_space)
4057 enum controller_dp_test_pattern controller_test_pattern;
4058 enum dc_color_depth color_depth = pipe_ctx->
4059 stream->timing.display_color_depth;
4060 struct bit_depth_reduction_params params;
4061 struct output_pixel_processor *opp = pipe_ctx->stream_res.opp;
4062 int width = pipe_ctx->stream->timing.h_addressable +
4063 pipe_ctx->stream->timing.h_border_left +
4064 pipe_ctx->stream->timing.h_border_right;
4065 int height = pipe_ctx->stream->timing.v_addressable +
4066 pipe_ctx->stream->timing.v_border_bottom +
4067 pipe_ctx->stream->timing.v_border_top;
4069 memset(¶ms, 0, sizeof(params));
4071 switch (test_pattern) {
4072 case DP_TEST_PATTERN_COLOR_SQUARES:
4073 controller_test_pattern =
4074 CONTROLLER_DP_TEST_PATTERN_COLORSQUARES;
4076 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
4077 controller_test_pattern =
4078 CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA;
4080 case DP_TEST_PATTERN_VERTICAL_BARS:
4081 controller_test_pattern =
4082 CONTROLLER_DP_TEST_PATTERN_VERTICALBARS;
4084 case DP_TEST_PATTERN_HORIZONTAL_BARS:
4085 controller_test_pattern =
4086 CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS;
4088 case DP_TEST_PATTERN_COLOR_RAMP:
4089 controller_test_pattern =
4090 CONTROLLER_DP_TEST_PATTERN_COLORRAMP;
4093 controller_test_pattern =
4094 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE;
4098 switch (test_pattern) {
4099 case DP_TEST_PATTERN_COLOR_SQUARES:
4100 case DP_TEST_PATTERN_COLOR_SQUARES_CEA:
4101 case DP_TEST_PATTERN_VERTICAL_BARS:
4102 case DP_TEST_PATTERN_HORIZONTAL_BARS:
4103 case DP_TEST_PATTERN_COLOR_RAMP:
4105 /* disable bit depth reduction */
4106 pipe_ctx->stream->bit_depth_params = params;
4107 opp->funcs->opp_program_bit_depth_reduction(opp, ¶ms);
4108 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
4109 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
4110 controller_test_pattern, color_depth);
4111 else if (link->dc->hwss.set_disp_pattern_generator) {
4112 struct pipe_ctx *odm_pipe;
4113 enum controller_dp_color_space controller_color_space;
4116 int dpg_width = width;
4118 switch (test_pattern_color_space) {
4119 case DP_TEST_PATTERN_COLOR_SPACE_RGB:
4120 controller_color_space = CONTROLLER_DP_COLOR_SPACE_RGB;
4122 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR601:
4123 controller_color_space = CONTROLLER_DP_COLOR_SPACE_YCBCR601;
4125 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR709:
4126 controller_color_space = CONTROLLER_DP_COLOR_SPACE_YCBCR709;
4128 case DP_TEST_PATTERN_COLOR_SPACE_UNDEFINED:
4130 controller_color_space = CONTROLLER_DP_COLOR_SPACE_UDEFINED;
4131 DC_LOG_ERROR("%s: Color space must be defined for test pattern", __func__);
4136 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
4138 dpg_width = width / opp_cnt;
4141 link->dc->hwss.set_disp_pattern_generator(link->dc,
4143 controller_test_pattern,
4144 controller_color_space,
4151 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
4152 struct output_pixel_processor *odm_opp = odm_pipe->stream_res.opp;
4154 odm_opp->funcs->opp_program_bit_depth_reduction(odm_opp, ¶ms);
4155 link->dc->hwss.set_disp_pattern_generator(link->dc,
4157 controller_test_pattern,
4158 controller_color_space,
4169 case DP_TEST_PATTERN_VIDEO_MODE:
4171 /* restore bitdepth reduction */
4172 resource_build_bit_depth_reduction_params(pipe_ctx->stream, ¶ms);
4173 pipe_ctx->stream->bit_depth_params = params;
4174 opp->funcs->opp_program_bit_depth_reduction(opp, ¶ms);
4175 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
4176 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
4177 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
4179 else if (link->dc->hwss.set_disp_pattern_generator) {
4180 struct pipe_ctx *odm_pipe;
4182 int dpg_width = width;
4184 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
4187 dpg_width = width / opp_cnt;
4188 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
4189 struct output_pixel_processor *odm_opp = odm_pipe->stream_res.opp;
4191 odm_opp->funcs->opp_program_bit_depth_reduction(odm_opp, ¶ms);
4192 link->dc->hwss.set_disp_pattern_generator(link->dc,
4194 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
4195 CONTROLLER_DP_COLOR_SPACE_UDEFINED,
4202 link->dc->hwss.set_disp_pattern_generator(link->dc,
4204 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
4205 CONTROLLER_DP_COLOR_SPACE_UDEFINED,
4220 bool dc_link_dp_set_test_pattern(
4221 struct dc_link *link,
4222 enum dp_test_pattern test_pattern,
4223 enum dp_test_pattern_color_space test_pattern_color_space,
4224 const struct link_training_settings *p_link_settings,
4225 const unsigned char *p_custom_pattern,
4226 unsigned int cust_pattern_size)
4228 struct pipe_ctx *pipes = link->dc->current_state->res_ctx.pipe_ctx;
4229 struct pipe_ctx *pipe_ctx = NULL;
4232 unsigned char link_qual_pattern[LANE_COUNT_DP_MAX] = {0};
4233 union dpcd_training_pattern training_pattern;
4234 enum dpcd_phy_test_patterns pattern;
4236 memset(&training_pattern, 0, sizeof(training_pattern));
4238 for (i = 0; i < MAX_PIPES; i++) {
4239 if (pipes[i].stream == NULL)
4242 if (pipes[i].stream->link == link && !pipes[i].top_pipe && !pipes[i].prev_odm_pipe) {
4243 pipe_ctx = &pipes[i];
4248 if (pipe_ctx == NULL)
4251 /* Reset CRTC Test Pattern if it is currently running and request is VideoMode */
4252 if (link->test_pattern_enabled && test_pattern ==
4253 DP_TEST_PATTERN_VIDEO_MODE) {
4254 /* Set CRTC Test Pattern */
4255 set_crtc_test_pattern(link, pipe_ctx, test_pattern, test_pattern_color_space);
4256 dp_set_hw_test_pattern(link, test_pattern,
4257 (uint8_t *)p_custom_pattern,
4258 (uint32_t)cust_pattern_size);
4260 /* Unblank Stream */
4261 link->dc->hwss.unblank_stream(
4263 &link->verified_link_cap);
4264 /* TODO:m_pHwss->MuteAudioEndpoint
4265 * (pPathMode->pDisplayPath, false);
4268 /* Reset Test Pattern state */
4269 link->test_pattern_enabled = false;
4274 /* Check for PHY Test Patterns */
4275 if (is_dp_phy_pattern(test_pattern)) {
4276 /* Set DPCD Lane Settings before running test pattern */
4277 if (p_link_settings != NULL) {
4278 dp_set_hw_lane_settings(link, p_link_settings, DPRX);
4279 dpcd_set_lane_settings(link, p_link_settings, DPRX);
4282 /* Blank stream if running test pattern */
4283 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
4286 * MuteAudioEndpoint(pPathMode->pDisplayPath, true);
4289 pipes->stream_res.stream_enc->funcs->dp_blank(pipe_ctx->stream_res.stream_enc);
4292 dp_set_hw_test_pattern(link, test_pattern,
4293 (uint8_t *)p_custom_pattern,
4294 (uint32_t)cust_pattern_size);
4296 if (test_pattern != DP_TEST_PATTERN_VIDEO_MODE) {
4297 /* Set Test Pattern state */
4298 link->test_pattern_enabled = true;
4299 if (p_link_settings != NULL)
4300 dpcd_set_link_settings(link,
4304 switch (test_pattern) {
4305 case DP_TEST_PATTERN_VIDEO_MODE:
4306 pattern = PHY_TEST_PATTERN_NONE;
4308 case DP_TEST_PATTERN_D102:
4309 pattern = PHY_TEST_PATTERN_D10_2;
4311 case DP_TEST_PATTERN_SYMBOL_ERROR:
4312 pattern = PHY_TEST_PATTERN_SYMBOL_ERROR;
4314 case DP_TEST_PATTERN_PRBS7:
4315 pattern = PHY_TEST_PATTERN_PRBS7;
4317 case DP_TEST_PATTERN_80BIT_CUSTOM:
4318 pattern = PHY_TEST_PATTERN_80BIT_CUSTOM;
4320 case DP_TEST_PATTERN_CP2520_1:
4321 pattern = PHY_TEST_PATTERN_CP2520_1;
4323 case DP_TEST_PATTERN_CP2520_2:
4324 pattern = PHY_TEST_PATTERN_CP2520_2;
4326 case DP_TEST_PATTERN_CP2520_3:
4327 pattern = PHY_TEST_PATTERN_CP2520_3;
4333 if (test_pattern == DP_TEST_PATTERN_VIDEO_MODE
4334 /*TODO:&& !pPathMode->pDisplayPath->IsTargetPoweredOn()*/)
4337 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_12) {
4338 /* tell receiver that we are sending qualification
4339 * pattern DP 1.2 or later - DP receiver's link quality
4340 * pattern is set using DPCD LINK_QUAL_LANEx_SET
4341 * register (0x10B~0x10E)\
4343 for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++)
4344 link_qual_pattern[lane] =
4345 (unsigned char)(pattern);
4347 core_link_write_dpcd(link,
4348 DP_LINK_QUAL_LANE0_SET,
4350 sizeof(link_qual_pattern));
4351 } else if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_10 ||
4352 link->dpcd_caps.dpcd_rev.raw == 0) {
4353 /* tell receiver that we are sending qualification
4354 * pattern DP 1.1a or earlier - DP receiver's link
4355 * quality pattern is set using
4356 * DPCD TRAINING_PATTERN_SET -> LINK_QUAL_PATTERN_SET
4357 * register (0x102). We will use v_1.3 when we are
4358 * setting test pattern for DP 1.1.
4360 core_link_read_dpcd(link, DP_TRAINING_PATTERN_SET,
4361 &training_pattern.raw,
4362 sizeof(training_pattern));
4363 training_pattern.v1_3.LINK_QUAL_PATTERN_SET = pattern;
4364 core_link_write_dpcd(link, DP_TRAINING_PATTERN_SET,
4365 &training_pattern.raw,
4366 sizeof(training_pattern));
4369 enum dc_color_space color_space = COLOR_SPACE_UNKNOWN;
4371 switch (test_pattern_color_space) {
4372 case DP_TEST_PATTERN_COLOR_SPACE_RGB:
4373 color_space = COLOR_SPACE_SRGB;
4374 if (test_pattern == DP_TEST_PATTERN_COLOR_SQUARES_CEA)
4375 color_space = COLOR_SPACE_SRGB_LIMITED;
4378 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR601:
4379 color_space = COLOR_SPACE_YCBCR601;
4380 if (test_pattern == DP_TEST_PATTERN_COLOR_SQUARES_CEA)
4381 color_space = COLOR_SPACE_YCBCR601_LIMITED;
4383 case DP_TEST_PATTERN_COLOR_SPACE_YCBCR709:
4384 color_space = COLOR_SPACE_YCBCR709;
4385 if (test_pattern == DP_TEST_PATTERN_COLOR_SQUARES_CEA)
4386 color_space = COLOR_SPACE_YCBCR709_LIMITED;
4392 if (pipe_ctx->stream_res.tg->funcs->lock_doublebuffer_enable) {
4393 if (pipe_ctx->stream && should_use_dmub_lock(pipe_ctx->stream->link)) {
4394 union dmub_hw_lock_flags hw_locks = { 0 };
4395 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
4397 hw_locks.bits.lock_dig = 1;
4398 inst_flags.dig_inst = pipe_ctx->stream_res.tg->inst;
4400 dmub_hw_lock_mgr_cmd(link->ctx->dmub_srv,
4405 pipe_ctx->stream_res.tg->funcs->lock_doublebuffer_enable(
4406 pipe_ctx->stream_res.tg);
4409 pipe_ctx->stream_res.tg->funcs->lock(pipe_ctx->stream_res.tg);
4410 /* update MSA to requested color space */
4411 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(pipe_ctx->stream_res.stream_enc,
4412 &pipe_ctx->stream->timing,
4414 pipe_ctx->stream->use_vsc_sdp_for_colorimetry,
4415 link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
4417 if (pipe_ctx->stream->use_vsc_sdp_for_colorimetry) {
4418 if (test_pattern == DP_TEST_PATTERN_COLOR_SQUARES_CEA)
4419 pipe_ctx->stream->vsc_infopacket.sb[17] |= (1 << 7); // sb17 bit 7 Dynamic Range: 0 = VESA range, 1 = CTA range
4421 pipe_ctx->stream->vsc_infopacket.sb[17] &= ~(1 << 7);
4422 resource_build_info_frame(pipe_ctx);
4423 link->dc->hwss.update_info_frame(pipe_ctx);
4427 set_crtc_test_pattern(link, pipe_ctx, test_pattern, test_pattern_color_space);
4428 pipe_ctx->stream_res.tg->funcs->unlock(pipe_ctx->stream_res.tg);
4429 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg,
4430 CRTC_STATE_VACTIVE);
4431 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg,
4433 pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg,
4434 CRTC_STATE_VACTIVE);
4436 if (pipe_ctx->stream_res.tg->funcs->lock_doublebuffer_disable) {
4437 if (pipe_ctx->stream && should_use_dmub_lock(pipe_ctx->stream->link)) {
4438 union dmub_hw_lock_flags hw_locks = { 0 };
4439 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
4441 hw_locks.bits.lock_dig = 1;
4442 inst_flags.dig_inst = pipe_ctx->stream_res.tg->inst;
4444 dmub_hw_lock_mgr_cmd(link->ctx->dmub_srv,
4449 pipe_ctx->stream_res.tg->funcs->lock_doublebuffer_disable(
4450 pipe_ctx->stream_res.tg);
4453 /* Set Test Pattern state */
4454 link->test_pattern_enabled = true;
4460 void dp_enable_mst_on_sink(struct dc_link *link, bool enable)
4462 unsigned char mstmCntl;
4464 core_link_read_dpcd(link, DP_MSTM_CTRL, &mstmCntl, 1);
4466 mstmCntl |= DP_MST_EN;
4468 mstmCntl &= (~DP_MST_EN);
4470 core_link_write_dpcd(link, DP_MSTM_CTRL, &mstmCntl, 1);
4473 void dp_set_panel_mode(struct dc_link *link, enum dp_panel_mode panel_mode)
4475 union dpcd_edp_config edp_config_set;
4476 bool panel_mode_edp = false;
4478 memset(&edp_config_set, '\0', sizeof(union dpcd_edp_config));
4480 if (panel_mode != DP_PANEL_MODE_DEFAULT) {
4482 switch (panel_mode) {
4483 case DP_PANEL_MODE_EDP:
4484 case DP_PANEL_MODE_SPECIAL:
4485 panel_mode_edp = true;
4492 /*set edp panel mode in receiver*/
4493 core_link_read_dpcd(
4495 DP_EDP_CONFIGURATION_SET,
4496 &edp_config_set.raw,
4497 sizeof(edp_config_set.raw));
4499 if (edp_config_set.bits.PANEL_MODE_EDP
4500 != panel_mode_edp) {
4501 enum dc_status result;
4503 edp_config_set.bits.PANEL_MODE_EDP =
4505 result = core_link_write_dpcd(
4507 DP_EDP_CONFIGURATION_SET,
4508 &edp_config_set.raw,
4509 sizeof(edp_config_set.raw));
4511 ASSERT(result == DC_OK);
4514 DC_LOG_DETECTION_DP_CAPS("Link: %d eDP panel mode supported: %d "
4515 "eDP panel mode enabled: %d \n",
4517 link->dpcd_caps.panel_mode_edp,
4521 enum dp_panel_mode dp_get_panel_mode(struct dc_link *link)
4523 /* We need to explicitly check that connector
4524 * is not DP. Some Travis_VGA get reported
4525 * by video bios as DP.
4527 if (link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT) {
4529 switch (link->dpcd_caps.branch_dev_id) {
4530 case DP_BRANCH_DEVICE_ID_0022B9:
4531 /* alternate scrambler reset is required for Travis
4532 * for the case when external chip does not
4533 * provide sink device id, alternate scrambler
4534 * scheme will be overriden later by querying
4538 link->dpcd_caps.branch_dev_name,
4539 DP_VGA_LVDS_CONVERTER_ID_2,
4542 branch_dev_name)) == 0) {
4543 return DP_PANEL_MODE_SPECIAL;
4546 case DP_BRANCH_DEVICE_ID_00001A:
4547 /* alternate scrambler reset is required for Travis
4548 * for the case when external chip does not provide
4549 * sink device id, alternate scrambler scheme will
4550 * be overriden later by querying Encoder feature
4552 if (strncmp(link->dpcd_caps.branch_dev_name,
4553 DP_VGA_LVDS_CONVERTER_ID_3,
4556 branch_dev_name)) == 0) {
4557 return DP_PANEL_MODE_SPECIAL;
4565 if (link->dpcd_caps.panel_mode_edp) {
4566 return DP_PANEL_MODE_EDP;
4569 return DP_PANEL_MODE_DEFAULT;
4572 void dp_set_fec_ready(struct dc_link *link, bool ready)
4574 /* FEC has to be "set ready" before the link training.
4575 * The policy is to always train with FEC
4576 * if the sink supports it and leave it enabled on link.
4577 * If FEC is not supported, disable it.
4579 struct link_encoder *link_enc = link->link_enc;
4580 uint8_t fec_config = 0;
4582 if (!dc_link_should_enable_fec(link))
4585 if (link_enc->funcs->fec_set_ready &&
4586 link->dpcd_caps.fec_cap.bits.FEC_CAPABLE) {
4589 if (core_link_write_dpcd(link,
4590 DP_FEC_CONFIGURATION,
4592 sizeof(fec_config)) == DC_OK) {
4593 link_enc->funcs->fec_set_ready(link_enc, true);
4594 link->fec_state = dc_link_fec_ready;
4596 link->link_enc->funcs->fec_set_ready(link->link_enc, false);
4597 link->fec_state = dc_link_fec_not_ready;
4598 dm_error("dpcd write failed to set fec_ready");
4600 } else if (link->fec_state == dc_link_fec_ready) {
4602 core_link_write_dpcd(link,
4603 DP_FEC_CONFIGURATION,
4605 sizeof(fec_config));
4606 link->link_enc->funcs->fec_set_ready(
4607 link->link_enc, false);
4608 link->fec_state = dc_link_fec_not_ready;
4613 void dp_set_fec_enable(struct dc_link *link, bool enable)
4615 struct link_encoder *link_enc = link->link_enc;
4617 if (!dc_link_should_enable_fec(link))
4620 if (link_enc->funcs->fec_set_enable &&
4621 link->dpcd_caps.fec_cap.bits.FEC_CAPABLE) {
4622 if (link->fec_state == dc_link_fec_ready && enable) {
4623 /* Accord to DP spec, FEC enable sequence can first
4624 * be transmitted anytime after 1000 LL codes have
4625 * been transmitted on the link after link training
4626 * completion. Using 1 lane RBR should have the maximum
4627 * time for transmitting 1000 LL codes which is 6.173 us.
4628 * So use 7 microseconds delay instead.
4631 link_enc->funcs->fec_set_enable(link_enc, true);
4632 link->fec_state = dc_link_fec_enabled;
4633 } else if (link->fec_state == dc_link_fec_enabled && !enable) {
4634 link_enc->funcs->fec_set_enable(link_enc, false);
4635 link->fec_state = dc_link_fec_ready;
4640 void dpcd_set_source_specific_data(struct dc_link *link)
4642 if (!link->dc->vendor_signature.is_valid) {
4643 enum dc_status __maybe_unused result_write_min_hblank = DC_NOT_SUPPORTED;
4644 struct dpcd_amd_signature amd_signature = {0};
4645 struct dpcd_amd_device_id amd_device_id = {0};
4647 amd_device_id.device_id_byte1 =
4648 (uint8_t)(link->ctx->asic_id.chip_id);
4649 amd_device_id.device_id_byte2 =
4650 (uint8_t)(link->ctx->asic_id.chip_id >> 8);
4651 amd_device_id.dce_version =
4652 (uint8_t)(link->ctx->dce_version);
4653 amd_device_id.dal_version_byte1 = 0x0; // needed? where to get?
4654 amd_device_id.dal_version_byte2 = 0x0; // needed? where to get?
4656 core_link_read_dpcd(link, DP_SOURCE_OUI,
4657 (uint8_t *)(&amd_signature),
4658 sizeof(amd_signature));
4660 if (!((amd_signature.AMD_IEEE_TxSignature_byte1 == 0x0) &&
4661 (amd_signature.AMD_IEEE_TxSignature_byte2 == 0x0) &&
4662 (amd_signature.AMD_IEEE_TxSignature_byte3 == 0x1A))) {
4664 amd_signature.AMD_IEEE_TxSignature_byte1 = 0x0;
4665 amd_signature.AMD_IEEE_TxSignature_byte2 = 0x0;
4666 amd_signature.AMD_IEEE_TxSignature_byte3 = 0x1A;
4668 core_link_write_dpcd(link, DP_SOURCE_OUI,
4669 (uint8_t *)(&amd_signature),
4670 sizeof(amd_signature));
4673 core_link_write_dpcd(link, DP_SOURCE_OUI+0x03,
4674 (uint8_t *)(&amd_device_id),
4675 sizeof(amd_device_id));
4677 if (link->ctx->dce_version >= DCN_VERSION_2_0 &&
4678 link->dc->caps.min_horizontal_blanking_period != 0) {
4680 uint8_t hblank_size = (uint8_t)link->dc->caps.min_horizontal_blanking_period;
4682 result_write_min_hblank = core_link_write_dpcd(link,
4683 DP_SOURCE_MINIMUM_HBLANK_SUPPORTED, (uint8_t *)(&hblank_size),
4684 sizeof(hblank_size));
4686 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION,
4687 WPP_BIT_FLAG_DC_DETECTION_DP_CAPS,
4688 "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'",
4689 result_write_min_hblank,
4691 link->ctx->dce_version,
4692 DP_SOURCE_MINIMUM_HBLANK_SUPPORTED,
4693 link->dc->caps.min_horizontal_blanking_period,
4694 link->dpcd_caps.branch_dev_id,
4695 link->dpcd_caps.branch_dev_name[0],
4696 link->dpcd_caps.branch_dev_name[1],
4697 link->dpcd_caps.branch_dev_name[2],
4698 link->dpcd_caps.branch_dev_name[3],
4699 link->dpcd_caps.branch_dev_name[4],
4700 link->dpcd_caps.branch_dev_name[5]);
4702 core_link_write_dpcd(link, DP_SOURCE_OUI,
4703 link->dc->vendor_signature.data.raw,
4704 sizeof(link->dc->vendor_signature.data.raw));
4708 bool dc_link_set_backlight_level_nits(struct dc_link *link,
4710 uint32_t backlight_millinits,
4711 uint32_t transition_time_in_ms)
4713 struct dpcd_source_backlight_set dpcd_backlight_set;
4714 uint8_t backlight_control = isHDR ? 1 : 0;
4716 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
4717 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
4720 // OLEDs have no PWM, they can only use AUX
4721 if (link->dpcd_sink_ext_caps.bits.oled == 1)
4722 backlight_control = 1;
4724 *(uint32_t *)&dpcd_backlight_set.backlight_level_millinits = backlight_millinits;
4725 *(uint16_t *)&dpcd_backlight_set.backlight_transition_time_ms = (uint16_t)transition_time_in_ms;
4728 if (core_link_write_dpcd(link, DP_SOURCE_BACKLIGHT_LEVEL,
4729 (uint8_t *)(&dpcd_backlight_set),
4730 sizeof(dpcd_backlight_set)) != DC_OK)
4733 if (core_link_write_dpcd(link, DP_SOURCE_BACKLIGHT_CONTROL,
4734 &backlight_control, 1) != DC_OK)
4740 bool dc_link_get_backlight_level_nits(struct dc_link *link,
4741 uint32_t *backlight_millinits_avg,
4742 uint32_t *backlight_millinits_peak)
4744 union dpcd_source_backlight_get dpcd_backlight_get;
4746 memset(&dpcd_backlight_get, 0, sizeof(union dpcd_source_backlight_get));
4748 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
4749 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
4752 if (core_link_read_dpcd(link, DP_SOURCE_BACKLIGHT_CURRENT_PEAK,
4753 dpcd_backlight_get.raw,
4754 sizeof(union dpcd_source_backlight_get)) != DC_OK)
4757 *backlight_millinits_avg =
4758 dpcd_backlight_get.bytes.backlight_millinits_avg;
4759 *backlight_millinits_peak =
4760 dpcd_backlight_get.bytes.backlight_millinits_peak;
4762 /* On non-supported panels dpcd_read usually succeeds with 0 returned */
4763 if (*backlight_millinits_avg == 0 ||
4764 *backlight_millinits_avg > *backlight_millinits_peak)
4770 bool dc_link_backlight_enable_aux(struct dc_link *link, bool enable)
4772 uint8_t backlight_enable = enable ? 1 : 0;
4774 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
4775 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
4778 if (core_link_write_dpcd(link, DP_SOURCE_BACKLIGHT_ENABLE,
4779 &backlight_enable, 1) != DC_OK)
4785 // we read default from 0x320 because we expect BIOS wrote it there
4786 // regular get_backlight_nit reads from panel set at 0x326
4787 bool dc_link_read_default_bl_aux(struct dc_link *link, uint32_t *backlight_millinits)
4789 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
4790 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
4793 if (core_link_read_dpcd(link, DP_SOURCE_BACKLIGHT_LEVEL,
4794 (uint8_t *) backlight_millinits,
4795 sizeof(uint32_t)) != DC_OK)
4801 bool dc_link_set_default_brightness_aux(struct dc_link *link)
4803 uint32_t default_backlight;
4806 (link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
4807 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)) {
4808 if (!dc_link_read_default_bl_aux(link, &default_backlight))
4809 default_backlight = 150000;
4810 // if < 5 nits or > 5000, it might be wrong readback
4811 if (default_backlight < 5000 || default_backlight > 5000000)
4812 default_backlight = 150000; //
4814 return dc_link_set_backlight_level_nits(link, true,
4815 default_backlight, 0);
4820 bool is_edp_ilr_optimization_required(struct dc_link *link, struct dc_crtc_timing *crtc_timing)
4822 struct dc_link_settings link_setting;
4823 uint8_t link_bw_set;
4824 uint8_t link_rate_set;
4826 union lane_count_set lane_count_set = { {0} };
4828 ASSERT(link || crtc_timing); // invalid input
4830 if (link->dpcd_caps.edp_supported_link_rates_count == 0 ||
4831 !link->dc->debug.optimize_edp_link_rate)
4835 // Read DPCD 00100h to find if standard link rates are set
4836 core_link_read_dpcd(link, DP_LINK_BW_SET,
4837 &link_bw_set, sizeof(link_bw_set));
4840 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: Optimization required, VBIOS used link_bw_set\n");
4844 // Read DPCD 00115h to find the edp link rate set used
4845 core_link_read_dpcd(link, DP_LINK_RATE_SET,
4846 &link_rate_set, sizeof(link_rate_set));
4848 // Read DPCD 00101h to find out the number of lanes currently set
4849 core_link_read_dpcd(link, DP_LANE_COUNT_SET,
4850 &lane_count_set.raw, sizeof(lane_count_set));
4852 req_bw = dc_bandwidth_in_kbps_from_timing(crtc_timing);
4854 decide_edp_link_settings(link, &link_setting, req_bw);
4856 if (link->dpcd_caps.edp_supported_link_rates[link_rate_set] != link_setting.link_rate ||
4857 lane_count_set.bits.LANE_COUNT_SET != link_setting.lane_count) {
4858 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: Optimization required, VBIOS link_rate_set not optimal\n");
4862 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: No optimization required, VBIOS set optimal link_rate_set\n");
4866 enum dp_link_encoding dp_get_link_encoding_format(const struct dc_link_settings *link_settings)
4868 if ((link_settings->link_rate >= LINK_RATE_LOW) &&
4869 (link_settings->link_rate <= LINK_RATE_HIGH3))
4870 return DP_8b_10b_ENCODING;
4871 return DP_UNKNOWN_ENCODING;