1 /*
2 * Copyright 2022 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: AMD
23 *
24 */
25
26 /* FILE POLICY AND INTENDED USAGE:
27 * This file implements dp specific link capability retrieval sequence. It is
28 * responsible for retrieving, parsing, overriding, deciding capability obtained
29 * from dp link. Link capability consists of encoders, DPRXs, cables, retimers,
30 * usb and all other possible backend capabilities. Other components should
31 * include this header file in order to access link capability. Accessing link
32 * capability by dereferencing dc_link outside dp_link_capability is not a
33 * recommended method as it makes the component dependent on the underlying data
34 * structure used to represent link capability instead of function interfaces.
35 */
36
37 #include "link_dp_capability.h"
38 #include "link_ddc.h"
39 #include "link_dpcd.h"
40 #include "link_dp_dpia.h"
41 #include "link_dp_phy.h"
42 #include "link_edp_panel_control.h"
43 #include "link_dp_irq_handler.h"
44 #include "link/accessories/link_dp_trace.h"
45 #include "link/link_detection.h"
46 #include "link/link_validation.h"
47 #include "link_dp_training.h"
48 #include "atomfirmware.h"
49 #include "resource.h"
50 #include "link_enc_cfg.h"
51 #include "dc_dmub_srv.h"
52 #include "gpio_service_interface.h"
53
54 #define DC_LOGGER \
55 link->ctx->logger
56 #define DC_TRACE_LEVEL_MESSAGE(...) /* do nothing */
57
58 #ifndef MAX
59 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
60 #endif
61 #ifndef MIN
62 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
63 #endif
64
65 struct dp_lt_fallback_entry {
66 enum dc_lane_count lane_count;
67 enum dc_link_rate link_rate;
68 };
69
70 static const struct dp_lt_fallback_entry dp_lt_fallbacks[] = {
71 /* This link training fallback array is ordered by
72 * link bandwidth from highest to lowest.
73 * DP specs makes it a normative policy to always
74 * choose the next highest link bandwidth during
75 * link training fallback.
76 */
77 {LANE_COUNT_FOUR, LINK_RATE_UHBR20},
78 {LANE_COUNT_FOUR, LINK_RATE_UHBR13_5},
79 {LANE_COUNT_TWO, LINK_RATE_UHBR20},
80 {LANE_COUNT_FOUR, LINK_RATE_UHBR10},
81 {LANE_COUNT_TWO, LINK_RATE_UHBR13_5},
82 {LANE_COUNT_FOUR, LINK_RATE_HIGH3},
83 {LANE_COUNT_ONE, LINK_RATE_UHBR20},
84 {LANE_COUNT_TWO, LINK_RATE_UHBR10},
85 {LANE_COUNT_FOUR, LINK_RATE_HIGH2},
86 {LANE_COUNT_ONE, LINK_RATE_UHBR13_5},
87 {LANE_COUNT_TWO, LINK_RATE_HIGH3},
88 {LANE_COUNT_ONE, LINK_RATE_UHBR10},
89 {LANE_COUNT_TWO, LINK_RATE_HIGH2},
90 {LANE_COUNT_FOUR, LINK_RATE_HIGH},
91 {LANE_COUNT_ONE, LINK_RATE_HIGH3},
92 {LANE_COUNT_FOUR, LINK_RATE_LOW},
93 {LANE_COUNT_ONE, LINK_RATE_HIGH2},
94 {LANE_COUNT_TWO, LINK_RATE_HIGH},
95 {LANE_COUNT_TWO, LINK_RATE_LOW},
96 {LANE_COUNT_ONE, LINK_RATE_HIGH},
97 {LANE_COUNT_ONE, LINK_RATE_LOW},
98 };
99
100 static const struct dc_link_settings fail_safe_link_settings = {
101 .lane_count = LANE_COUNT_ONE,
102 .link_rate = LINK_RATE_LOW,
103 .link_spread = LINK_SPREAD_DISABLED,
104 };
105
is_dp_active_dongle(const struct dc_link * link)106 bool is_dp_active_dongle(const struct dc_link *link)
107 {
108 return (link->dpcd_caps.dongle_type >= DISPLAY_DONGLE_DP_VGA_CONVERTER) &&
109 (link->dpcd_caps.dongle_type <= DISPLAY_DONGLE_DP_HDMI_CONVERTER);
110 }
111
is_dp_branch_device(const struct dc_link * link)112 bool is_dp_branch_device(const struct dc_link *link)
113 {
114 return link->dpcd_caps.is_branch_dev;
115 }
116
translate_dpcd_max_bpc(enum dpcd_downstream_port_max_bpc bpc)117 static int translate_dpcd_max_bpc(enum dpcd_downstream_port_max_bpc bpc)
118 {
119 switch (bpc) {
120 case DOWN_STREAM_MAX_8BPC:
121 return 8;
122 case DOWN_STREAM_MAX_10BPC:
123 return 10;
124 case DOWN_STREAM_MAX_12BPC:
125 return 12;
126 case DOWN_STREAM_MAX_16BPC:
127 return 16;
128 default:
129 break;
130 }
131
132 return -1;
133 }
134
dp_parse_lttpr_repeater_count(uint8_t lttpr_repeater_count)135 uint8_t dp_parse_lttpr_repeater_count(uint8_t lttpr_repeater_count)
136 {
137 switch (lttpr_repeater_count) {
138 case 0x80: // 1 lttpr repeater
139 return 1;
140 case 0x40: // 2 lttpr repeaters
141 return 2;
142 case 0x20: // 3 lttpr repeaters
143 return 3;
144 case 0x10: // 4 lttpr repeaters
145 return 4;
146 case 0x08: // 5 lttpr repeaters
147 return 5;
148 case 0x04: // 6 lttpr repeaters
149 return 6;
150 case 0x02: // 7 lttpr repeaters
151 return 7;
152 case 0x01: // 8 lttpr repeaters
153 return 8;
154 default:
155 break;
156 }
157 return 0; // invalid value
158 }
159
link_bw_kbps_from_raw_frl_link_rate_data(uint8_t bw)160 uint32_t link_bw_kbps_from_raw_frl_link_rate_data(uint8_t bw)
161 {
162 switch (bw) {
163 case 0b001:
164 return 9000000;
165 case 0b010:
166 return 18000000;
167 case 0b011:
168 return 24000000;
169 case 0b100:
170 return 32000000;
171 case 0b101:
172 return 40000000;
173 case 0b110:
174 return 48000000;
175 }
176
177 return 0;
178 }
179
linkRateInKHzToLinkRateMultiplier(uint32_t link_rate_in_khz)180 static enum dc_link_rate linkRateInKHzToLinkRateMultiplier(uint32_t link_rate_in_khz)
181 {
182 enum dc_link_rate link_rate;
183 // LinkRate is normally stored as a multiplier of 0.27 Gbps per lane. Do the translation.
184 switch (link_rate_in_khz) {
185 case 1620000:
186 link_rate = LINK_RATE_LOW; // Rate_1 (RBR) - 1.62 Gbps/Lane
187 break;
188 case 2160000:
189 link_rate = LINK_RATE_RATE_2; // Rate_2 - 2.16 Gbps/Lane
190 break;
191 case 2430000:
192 link_rate = LINK_RATE_RATE_3; // Rate_3 - 2.43 Gbps/Lane
193 break;
194 case 2700000:
195 link_rate = LINK_RATE_HIGH; // Rate_4 (HBR) - 2.70 Gbps/Lane
196 break;
197 case 3240000:
198 link_rate = LINK_RATE_RBR2; // Rate_5 (RBR2)- 3.24 Gbps/Lane
199 break;
200 case 4320000:
201 link_rate = LINK_RATE_RATE_6; // Rate_6 - 4.32 Gbps/Lane
202 break;
203 case 5400000:
204 link_rate = LINK_RATE_HIGH2; // Rate_7 (HBR2)- 5.40 Gbps/Lane
205 break;
206 case 6750000:
207 link_rate = LINK_RATE_RATE_8; // Rate_8 - 6.75 Gbps/Lane
208 break;
209 case 8100000:
210 link_rate = LINK_RATE_HIGH3; // Rate_9 (HBR3)- 8.10 Gbps/Lane
211 break;
212 default:
213 link_rate = LINK_RATE_UNKNOWN;
214 break;
215 }
216 return link_rate;
217 }
218
intersect_cable_id(union dp_cable_id * a,union dp_cable_id * b)219 static union dp_cable_id intersect_cable_id(
220 union dp_cable_id *a, union dp_cable_id *b)
221 {
222 union dp_cable_id out;
223
224 out.bits.UHBR10_20_CAPABILITY = MIN(a->bits.UHBR10_20_CAPABILITY,
225 b->bits.UHBR10_20_CAPABILITY);
226 out.bits.UHBR13_5_CAPABILITY = MIN(a->bits.UHBR13_5_CAPABILITY,
227 b->bits.UHBR13_5_CAPABILITY);
228 out.bits.CABLE_TYPE = MAX(a->bits.CABLE_TYPE, b->bits.CABLE_TYPE);
229
230 return out;
231 }
232
233 /*
234 * Return PCON's post FRL link training supported BW if its non-zero, otherwise return max_supported_frl_bw.
235 */
intersect_frl_link_bw_support(const uint32_t max_supported_frl_bw_in_kbps,const union hdmi_encoded_link_bw hdmi_encoded_link_bw)236 static uint32_t intersect_frl_link_bw_support(
237 const uint32_t max_supported_frl_bw_in_kbps,
238 const union hdmi_encoded_link_bw hdmi_encoded_link_bw)
239 {
240 uint32_t supported_bw_in_kbps = max_supported_frl_bw_in_kbps;
241
242 /* Skip checking FRL_MODE bit, as certain PCON will clear
243 * it despite supporting the link BW indicated in the other bits.
244 */
245 if (hdmi_encoded_link_bw.bits.BW_48Gbps)
246 supported_bw_in_kbps = 48000000;
247 else if (hdmi_encoded_link_bw.bits.BW_40Gbps)
248 supported_bw_in_kbps = 40000000;
249 else if (hdmi_encoded_link_bw.bits.BW_32Gbps)
250 supported_bw_in_kbps = 32000000;
251 else if (hdmi_encoded_link_bw.bits.BW_24Gbps)
252 supported_bw_in_kbps = 24000000;
253 else if (hdmi_encoded_link_bw.bits.BW_18Gbps)
254 supported_bw_in_kbps = 18000000;
255 else if (hdmi_encoded_link_bw.bits.BW_9Gbps)
256 supported_bw_in_kbps = 9000000;
257
258 return supported_bw_in_kbps;
259 }
260
get_clock_source_id(struct dc_link * link)261 static enum clock_source_id get_clock_source_id(struct dc_link *link)
262 {
263 enum clock_source_id dp_cs_id = CLOCK_SOURCE_ID_UNDEFINED;
264 struct clock_source *dp_cs = link->dc->res_pool->dp_clock_source;
265
266 if (dp_cs != NULL) {
267 dp_cs_id = dp_cs->id;
268 } else {
269 /*
270 * dp clock source is not initialized for some reason.
271 * Should not happen, CLOCK_SOURCE_ID_EXTERNAL will be used
272 */
273 ASSERT(dp_cs);
274 }
275
276 return dp_cs_id;
277 }
278
dp_wa_power_up_0010FA(struct dc_link * link,uint8_t * dpcd_data,int length)279 static void dp_wa_power_up_0010FA(struct dc_link *link, uint8_t *dpcd_data,
280 int length)
281 {
282 int retry = 0;
283
284 if (!link->dpcd_caps.dpcd_rev.raw) {
285 do {
286 dpcd_write_rx_power_ctrl(link, true);
287 core_link_read_dpcd(link, DP_DPCD_REV,
288 dpcd_data, length);
289 link->dpcd_caps.dpcd_rev.raw = dpcd_data[
290 DP_DPCD_REV -
291 DP_DPCD_REV];
292 } while (retry++ < 4 && !link->dpcd_caps.dpcd_rev.raw);
293 }
294
295 if (link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_VGA_CONVERTER) {
296 switch (link->dpcd_caps.branch_dev_id) {
297 /* 0010FA active dongles (DP-VGA, DP-DLDVI converters) power down
298 * all internal circuits including AUX communication preventing
299 * reading DPCD table and EDID (spec violation).
300 * Encoder will skip DP RX power down on disable_output to
301 * keep receiver powered all the time.*/
302 case DP_BRANCH_DEVICE_ID_0010FA:
303 case DP_BRANCH_DEVICE_ID_0080E1:
304 case DP_BRANCH_DEVICE_ID_00E04C:
305 link->wa_flags.dp_keep_receiver_powered = true;
306 break;
307
308 /* TODO: May need work around for other dongles. */
309 default:
310 link->wa_flags.dp_keep_receiver_powered = false;
311 break;
312 }
313 } else
314 link->wa_flags.dp_keep_receiver_powered = false;
315 }
316
dp_is_fec_supported(const struct dc_link * link)317 bool dp_is_fec_supported(const struct dc_link *link)
318 {
319 /* TODO - use asic cap instead of link_enc->features
320 * we no longer know which link enc to use for this link before commit
321 */
322 struct link_encoder *link_enc = NULL;
323
324 link_enc = link_enc_cfg_get_link_enc(link);
325 ASSERT(link_enc);
326
327 return (dc_is_dp_signal(link->connector_signal) && link_enc &&
328 link_enc->features.fec_supported &&
329 link->dpcd_caps.fec_cap.bits.FEC_CAPABLE);
330 }
331
dp_should_enable_fec(const struct dc_link * link)332 bool dp_should_enable_fec(const struct dc_link *link)
333 {
334 bool force_disable = false;
335
336 if (link->fec_state == dc_link_fec_enabled)
337 force_disable = false;
338 else if (link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT_MST &&
339 link->local_sink &&
340 link->local_sink->edid_caps.panel_patch.disable_fec)
341 force_disable = true;
342 else if (link->connector_signal == SIGNAL_TYPE_EDP
343 && (link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.
344 dsc_support.DSC_SUPPORT == false
345 || link->panel_config.dsc.disable_dsc_edp
346 || !link->dc->caps.edp_dsc_support))
347 force_disable = true;
348
349 return !force_disable && dp_is_fec_supported(link);
350 }
351
dp_is_128b_132b_signal(struct pipe_ctx * pipe_ctx)352 bool dp_is_128b_132b_signal(struct pipe_ctx *pipe_ctx)
353 {
354 /* If this assert is hit then we have a link encoder dynamic management issue */
355 ASSERT(pipe_ctx->stream_res.hpo_dp_stream_enc ? pipe_ctx->link_res.hpo_dp_link_enc != NULL : true);
356 return (pipe_ctx->stream_res.hpo_dp_stream_enc &&
357 pipe_ctx->link_res.hpo_dp_link_enc &&
358 dc_is_dp_signal(pipe_ctx->stream->signal));
359 }
360
dp_is_lttpr_present(struct dc_link * link)361 bool dp_is_lttpr_present(struct dc_link *link)
362 {
363 return (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) != 0 &&
364 link->dpcd_caps.lttpr_caps.max_lane_count > 0 &&
365 link->dpcd_caps.lttpr_caps.max_lane_count <= 4 &&
366 link->dpcd_caps.lttpr_caps.revision.raw >= 0x14);
367 }
368
369 /* in DP compliance test, DPR-120 may have
370 * a random value in its MAX_LINK_BW dpcd field.
371 * We map it to the maximum supported link rate that
372 * is smaller than MAX_LINK_BW in this case.
373 */
get_link_rate_from_max_link_bw(uint8_t max_link_bw)374 static enum dc_link_rate get_link_rate_from_max_link_bw(
375 uint8_t max_link_bw)
376 {
377 enum dc_link_rate link_rate;
378
379 if (max_link_bw >= LINK_RATE_HIGH3) {
380 link_rate = LINK_RATE_HIGH3;
381 } else if (max_link_bw < LINK_RATE_HIGH3
382 && max_link_bw >= LINK_RATE_HIGH2) {
383 link_rate = LINK_RATE_HIGH2;
384 } else if (max_link_bw < LINK_RATE_HIGH2
385 && max_link_bw >= LINK_RATE_HIGH) {
386 link_rate = LINK_RATE_HIGH;
387 } else if (max_link_bw < LINK_RATE_HIGH
388 && max_link_bw >= LINK_RATE_LOW) {
389 link_rate = LINK_RATE_LOW;
390 } else {
391 link_rate = LINK_RATE_UNKNOWN;
392 }
393
394 return link_rate;
395 }
396
get_lttpr_max_link_rate(struct dc_link * link)397 static enum dc_link_rate get_lttpr_max_link_rate(struct dc_link *link)
398 {
399 enum dc_link_rate lttpr_max_link_rate = link->dpcd_caps.lttpr_caps.max_link_rate;
400
401 if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR20)
402 lttpr_max_link_rate = LINK_RATE_UHBR20;
403 else if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR13_5)
404 lttpr_max_link_rate = LINK_RATE_UHBR13_5;
405 else if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR10)
406 lttpr_max_link_rate = LINK_RATE_UHBR10;
407
408 return lttpr_max_link_rate;
409 }
410
get_cable_max_link_rate(struct dc_link * link)411 static enum dc_link_rate get_cable_max_link_rate(struct dc_link *link)
412 {
413 enum dc_link_rate cable_max_link_rate = LINK_RATE_UNKNOWN;
414
415 if (link->dpcd_caps.cable_id.bits.UHBR10_20_CAPABILITY & DP_UHBR20)
416 cable_max_link_rate = LINK_RATE_UHBR20;
417 else if (link->dpcd_caps.cable_id.bits.UHBR13_5_CAPABILITY)
418 cable_max_link_rate = LINK_RATE_UHBR13_5;
419 else if (link->dpcd_caps.cable_id.bits.UHBR10_20_CAPABILITY & DP_UHBR10)
420 cable_max_link_rate = LINK_RATE_UHBR10;
421
422 return cable_max_link_rate;
423 }
424
reached_minimum_lane_count(enum dc_lane_count lane_count)425 static inline bool reached_minimum_lane_count(enum dc_lane_count lane_count)
426 {
427 return lane_count <= LANE_COUNT_ONE;
428 }
429
reached_minimum_link_rate(enum dc_link_rate link_rate)430 static inline bool reached_minimum_link_rate(enum dc_link_rate link_rate)
431 {
432 return link_rate <= LINK_RATE_LOW;
433 }
434
reduce_lane_count(enum dc_lane_count lane_count)435 static enum dc_lane_count reduce_lane_count(enum dc_lane_count lane_count)
436 {
437 switch (lane_count) {
438 case LANE_COUNT_FOUR:
439 return LANE_COUNT_TWO;
440 case LANE_COUNT_TWO:
441 return LANE_COUNT_ONE;
442 case LANE_COUNT_ONE:
443 return LANE_COUNT_UNKNOWN;
444 default:
445 return LANE_COUNT_UNKNOWN;
446 }
447 }
448
reduce_link_rate(const struct dc_link * link,enum dc_link_rate link_rate)449 static enum dc_link_rate reduce_link_rate(const struct dc_link *link, enum dc_link_rate link_rate)
450 {
451 // NEEDSWORK: provide some details about why this function never returns some of the
452 // obscure link rates such as 4.32 Gbps or 3.24 Gbps and if such behavior is intended.
453 //
454
455 switch (link_rate) {
456 case LINK_RATE_UHBR20:
457 return LINK_RATE_UHBR13_5;
458 case LINK_RATE_UHBR13_5:
459 return LINK_RATE_UHBR10;
460 case LINK_RATE_UHBR10:
461 return LINK_RATE_HIGH3;
462 case LINK_RATE_HIGH3:
463 if (link->connector_signal == SIGNAL_TYPE_EDP && link->dc->debug.support_eDP1_5)
464 return LINK_RATE_RATE_8;
465 return LINK_RATE_HIGH2;
466 case LINK_RATE_RATE_8:
467 return LINK_RATE_HIGH2;
468 case LINK_RATE_HIGH2:
469 return LINK_RATE_HIGH;
470 case LINK_RATE_RATE_6:
471 case LINK_RATE_RBR2:
472 return LINK_RATE_HIGH;
473 case LINK_RATE_HIGH:
474 return LINK_RATE_LOW;
475 case LINK_RATE_RATE_3:
476 case LINK_RATE_RATE_2:
477 return LINK_RATE_LOW;
478 case LINK_RATE_LOW:
479 default:
480 return LINK_RATE_UNKNOWN;
481 }
482 }
483
increase_lane_count(enum dc_lane_count lane_count)484 static enum dc_lane_count increase_lane_count(enum dc_lane_count lane_count)
485 {
486 switch (lane_count) {
487 case LANE_COUNT_ONE:
488 return LANE_COUNT_TWO;
489 case LANE_COUNT_TWO:
490 return LANE_COUNT_FOUR;
491 default:
492 return LANE_COUNT_UNKNOWN;
493 }
494 }
495
increase_link_rate(struct dc_link * link,enum dc_link_rate link_rate)496 static enum dc_link_rate increase_link_rate(struct dc_link *link,
497 enum dc_link_rate link_rate)
498 {
499 switch (link_rate) {
500 case LINK_RATE_LOW:
501 return LINK_RATE_HIGH;
502 case LINK_RATE_HIGH:
503 return LINK_RATE_HIGH2;
504 case LINK_RATE_HIGH2:
505 return LINK_RATE_HIGH3;
506 case LINK_RATE_HIGH3:
507 return LINK_RATE_UHBR10;
508 case LINK_RATE_UHBR10:
509 /* upto DP2.x specs UHBR13.5 is the only link rate that could be
510 * not supported by DPRX when higher link rate is supported.
511 * so we treat it as a special case for code simplicity. When we
512 * have new specs with more link rates like this, we should
513 * consider a more generic solution to handle discrete link
514 * rate capabilities.
515 */
516 return link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5 ?
517 LINK_RATE_UHBR13_5 : LINK_RATE_UHBR20;
518 case LINK_RATE_UHBR13_5:
519 return LINK_RATE_UHBR20;
520 default:
521 return LINK_RATE_UNKNOWN;
522 }
523 }
524
decide_fallback_link_setting_max_bw_policy(struct dc_link * link,const struct dc_link_settings * max,struct dc_link_settings * cur,enum link_training_result training_result)525 static bool decide_fallback_link_setting_max_bw_policy(
526 struct dc_link *link,
527 const struct dc_link_settings *max,
528 struct dc_link_settings *cur,
529 enum link_training_result training_result)
530 {
531 uint32_t cur_idx = 0, next_idx;
532 bool found = false;
533
534 if (training_result == LINK_TRAINING_ABORT)
535 return false;
536
537 while (cur_idx < ARRAY_SIZE(dp_lt_fallbacks))
538 /* find current index */
539 if (dp_lt_fallbacks[cur_idx].lane_count == cur->lane_count &&
540 dp_lt_fallbacks[cur_idx].link_rate == cur->link_rate)
541 break;
542 else
543 cur_idx++;
544
545 next_idx = cur_idx + 1;
546
547 while (next_idx < ARRAY_SIZE(dp_lt_fallbacks))
548 /* find next index */
549 if (dp_lt_fallbacks[next_idx].lane_count > max->lane_count ||
550 dp_lt_fallbacks[next_idx].link_rate > max->link_rate)
551 next_idx++;
552 else if (dp_lt_fallbacks[next_idx].link_rate == LINK_RATE_UHBR13_5 &&
553 link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5 == 0)
554 /* upto DP2.x specs UHBR13.5 is the only link rate that
555 * could be not supported by DPRX when higher link rate
556 * is supported. so we treat it as a special case for
557 * code simplicity. When we have new specs with more
558 * link rates like this, we should consider a more
559 * generic solution to handle discrete link rate
560 * capabilities.
561 */
562 next_idx++;
563 else
564 break;
565
566 if (next_idx < ARRAY_SIZE(dp_lt_fallbacks)) {
567 cur->lane_count = dp_lt_fallbacks[next_idx].lane_count;
568 cur->link_rate = dp_lt_fallbacks[next_idx].link_rate;
569 found = true;
570 }
571
572 return found;
573 }
574
575 /*
576 * function: set link rate and lane count fallback based
577 * on current link setting and last link training result
578 * return value:
579 * true - link setting could be set
580 * false - has reached minimum setting
581 * and no further fallback could be done
582 */
decide_fallback_link_setting(struct dc_link * link,struct dc_link_settings * max,struct dc_link_settings * cur,enum link_training_result training_result)583 bool decide_fallback_link_setting(
584 struct dc_link *link,
585 struct dc_link_settings *max,
586 struct dc_link_settings *cur,
587 enum link_training_result training_result)
588 {
589 if (link_dp_get_encoding_format(max) == DP_128b_132b_ENCODING ||
590 link->dc->debug.force_dp2_lt_fallback_method)
591 return decide_fallback_link_setting_max_bw_policy(link, max,
592 cur, training_result);
593
594 switch (training_result) {
595 case LINK_TRAINING_CR_FAIL_LANE0:
596 case LINK_TRAINING_CR_FAIL_LANE1:
597 case LINK_TRAINING_CR_FAIL_LANE23:
598 case LINK_TRAINING_LQA_FAIL:
599 {
600 if (!reached_minimum_link_rate(cur->link_rate)) {
601 cur->link_rate = reduce_link_rate(link, cur->link_rate);
602 } else if (!reached_minimum_lane_count(cur->lane_count)) {
603 cur->link_rate = max->link_rate;
604 if (training_result == LINK_TRAINING_CR_FAIL_LANE0)
605 return false;
606 else if (training_result == LINK_TRAINING_CR_FAIL_LANE1)
607 cur->lane_count = LANE_COUNT_ONE;
608 else if (training_result == LINK_TRAINING_CR_FAIL_LANE23)
609 cur->lane_count = LANE_COUNT_TWO;
610 else
611 cur->lane_count = reduce_lane_count(cur->lane_count);
612 } else {
613 return false;
614 }
615 break;
616 }
617 case LINK_TRAINING_EQ_FAIL_EQ:
618 case LINK_TRAINING_EQ_FAIL_CR_PARTIAL:
619 {
620 if (!reached_minimum_lane_count(cur->lane_count)) {
621 cur->lane_count = reduce_lane_count(cur->lane_count);
622 } else if (!reached_minimum_link_rate(cur->link_rate)) {
623 cur->link_rate = reduce_link_rate(link, cur->link_rate);
624 /* Reduce max link rate to avoid potential infinite loop.
625 * Needed so that any subsequent CR_FAIL fallback can't
626 * re-set the link rate higher than the link rate from
627 * the latest EQ_FAIL fallback.
628 */
629 max->link_rate = cur->link_rate;
630 cur->lane_count = max->lane_count;
631 } else {
632 return false;
633 }
634 break;
635 }
636 case LINK_TRAINING_EQ_FAIL_CR:
637 {
638 if (!reached_minimum_link_rate(cur->link_rate)) {
639 cur->link_rate = reduce_link_rate(link, cur->link_rate);
640 /* Reduce max link rate to avoid potential infinite loop.
641 * Needed so that any subsequent CR_FAIL fallback can't
642 * re-set the link rate higher than the link rate from
643 * the latest EQ_FAIL fallback.
644 */
645 max->link_rate = cur->link_rate;
646 cur->lane_count = max->lane_count;
647 } else {
648 return false;
649 }
650 break;
651 }
652 default:
653 return false;
654 }
655 return true;
656 }
decide_dp_link_settings(struct dc_link * link,struct dc_link_settings * link_setting,uint32_t req_bw)657 static bool decide_dp_link_settings(struct dc_link *link, struct dc_link_settings *link_setting, uint32_t req_bw)
658 {
659 struct dc_link_settings initial_link_setting = {
660 LANE_COUNT_ONE, LINK_RATE_LOW, LINK_SPREAD_DISABLED, false, 0};
661 struct dc_link_settings current_link_setting =
662 initial_link_setting;
663 uint32_t link_bw;
664
665 if (req_bw > dp_link_bandwidth_kbps(link, &link->verified_link_cap))
666 return false;
667
668 /* search for the minimum link setting that:
669 * 1. is supported according to the link training result
670 * 2. could support the b/w requested by the timing
671 */
672 while (current_link_setting.link_rate <=
673 link->verified_link_cap.link_rate) {
674 link_bw = dp_link_bandwidth_kbps(
675 link,
676 ¤t_link_setting);
677 if (req_bw <= link_bw) {
678 *link_setting = current_link_setting;
679 return true;
680 }
681
682 if (current_link_setting.lane_count <
683 link->verified_link_cap.lane_count) {
684 current_link_setting.lane_count =
685 increase_lane_count(
686 current_link_setting.lane_count);
687 } else {
688 current_link_setting.link_rate =
689 increase_link_rate(link,
690 current_link_setting.link_rate);
691 current_link_setting.lane_count =
692 initial_link_setting.lane_count;
693 }
694 }
695
696 return false;
697 }
698
edp_decide_link_settings(struct dc_link * link,struct dc_link_settings * link_setting,uint32_t req_bw)699 bool edp_decide_link_settings(struct dc_link *link,
700 struct dc_link_settings *link_setting, uint32_t req_bw)
701 {
702 struct dc_link_settings initial_link_setting;
703 struct dc_link_settings current_link_setting;
704 uint32_t link_bw;
705
706 /*
707 * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
708 * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
709 */
710 if (!edp_is_ilr_optimization_enabled(link)) {
711 *link_setting = link->verified_link_cap;
712 return true;
713 }
714
715 memset(&initial_link_setting, 0, sizeof(initial_link_setting));
716 initial_link_setting.lane_count = LANE_COUNT_ONE;
717 initial_link_setting.link_rate = link->dpcd_caps.edp_supported_link_rates[0];
718 initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
719 initial_link_setting.use_link_rate_set = true;
720 initial_link_setting.link_rate_set = 0;
721 current_link_setting = initial_link_setting;
722
723 /* search for the minimum link setting that:
724 * 1. is supported according to the link training result
725 * 2. could support the b/w requested by the timing
726 */
727 while (current_link_setting.link_rate <=
728 link->verified_link_cap.link_rate) {
729 link_bw = dp_link_bandwidth_kbps(
730 link,
731 ¤t_link_setting);
732 if (req_bw <= link_bw) {
733 *link_setting = current_link_setting;
734 return true;
735 }
736
737 if (current_link_setting.lane_count <
738 link->verified_link_cap.lane_count) {
739 current_link_setting.lane_count =
740 increase_lane_count(
741 current_link_setting.lane_count);
742 } else {
743 if (current_link_setting.link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
744 current_link_setting.link_rate_set++;
745 current_link_setting.link_rate =
746 link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
747 current_link_setting.lane_count =
748 initial_link_setting.lane_count;
749 } else
750 break;
751 }
752 }
753 return false;
754 }
755
decide_edp_link_settings_with_dsc(struct dc_link * link,struct dc_link_settings * link_setting,uint32_t req_bw,enum dc_link_rate max_link_rate)756 bool decide_edp_link_settings_with_dsc(struct dc_link *link,
757 struct dc_link_settings *link_setting,
758 uint32_t req_bw,
759 enum dc_link_rate max_link_rate)
760 {
761 struct dc_link_settings initial_link_setting;
762 struct dc_link_settings current_link_setting;
763 uint32_t link_bw;
764
765 unsigned int policy = 0;
766
767 policy = link->panel_config.dsc.force_dsc_edp_policy;
768 if (max_link_rate == LINK_RATE_UNKNOWN)
769 max_link_rate = link->verified_link_cap.link_rate;
770 /*
771 * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
772 * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
773 */
774 if (!edp_is_ilr_optimization_enabled(link)) {
775 /* for DSC enabled case, we search for minimum lane count */
776 memset(&initial_link_setting, 0, sizeof(initial_link_setting));
777 initial_link_setting.lane_count = LANE_COUNT_ONE;
778 initial_link_setting.link_rate = LINK_RATE_LOW;
779 initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
780 initial_link_setting.use_link_rate_set = false;
781 initial_link_setting.link_rate_set = 0;
782 current_link_setting = initial_link_setting;
783 if (req_bw > dp_link_bandwidth_kbps(link, &link->verified_link_cap))
784 return false;
785
786 /* search for the minimum link setting that:
787 * 1. is supported according to the link training result
788 * 2. could support the b/w requested by the timing
789 */
790 while (current_link_setting.link_rate <=
791 max_link_rate) {
792 link_bw = dp_link_bandwidth_kbps(
793 link,
794 ¤t_link_setting);
795 if (req_bw <= link_bw) {
796 *link_setting = current_link_setting;
797 return true;
798 }
799 if (policy) {
800 /* minimize lane */
801 if (current_link_setting.link_rate < max_link_rate) {
802 current_link_setting.link_rate =
803 increase_link_rate(link,
804 current_link_setting.link_rate);
805 } else {
806 if (current_link_setting.lane_count <
807 link->verified_link_cap.lane_count) {
808 current_link_setting.lane_count =
809 increase_lane_count(
810 current_link_setting.lane_count);
811 current_link_setting.link_rate = initial_link_setting.link_rate;
812 } else
813 break;
814 }
815 } else {
816 /* minimize link rate */
817 if (current_link_setting.lane_count <
818 link->verified_link_cap.lane_count) {
819 current_link_setting.lane_count =
820 increase_lane_count(
821 current_link_setting.lane_count);
822 } else {
823 current_link_setting.link_rate =
824 increase_link_rate(link,
825 current_link_setting.link_rate);
826 current_link_setting.lane_count =
827 initial_link_setting.lane_count;
828 }
829 }
830 }
831 return false;
832 }
833
834 /* if optimize edp link is supported */
835 memset(&initial_link_setting, 0, sizeof(initial_link_setting));
836 initial_link_setting.lane_count = LANE_COUNT_ONE;
837 initial_link_setting.link_rate = link->dpcd_caps.edp_supported_link_rates[0];
838 initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
839 initial_link_setting.use_link_rate_set = true;
840 initial_link_setting.link_rate_set = 0;
841 current_link_setting = initial_link_setting;
842
843 /* search for the minimum link setting that:
844 * 1. is supported according to the link training result
845 * 2. could support the b/w requested by the timing
846 */
847 while (current_link_setting.link_rate <=
848 max_link_rate) {
849 link_bw = dp_link_bandwidth_kbps(
850 link,
851 ¤t_link_setting);
852 if (req_bw <= link_bw) {
853 *link_setting = current_link_setting;
854 return true;
855 }
856 if (policy) {
857 /* minimize lane */
858 if (current_link_setting.link_rate_set <
859 link->dpcd_caps.edp_supported_link_rates_count
860 && current_link_setting.link_rate < max_link_rate) {
861 current_link_setting.link_rate_set++;
862 current_link_setting.link_rate =
863 link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
864 } else {
865 if (current_link_setting.lane_count < link->verified_link_cap.lane_count) {
866 current_link_setting.lane_count =
867 increase_lane_count(
868 current_link_setting.lane_count);
869 current_link_setting.link_rate_set = initial_link_setting.link_rate_set;
870 current_link_setting.link_rate =
871 link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
872 } else
873 break;
874 }
875 } else {
876 /* minimize link rate */
877 if (current_link_setting.lane_count <
878 link->verified_link_cap.lane_count) {
879 current_link_setting.lane_count =
880 increase_lane_count(
881 current_link_setting.lane_count);
882 } else {
883 if (current_link_setting.link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
884 current_link_setting.link_rate_set++;
885 current_link_setting.link_rate =
886 link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
887 current_link_setting.lane_count =
888 initial_link_setting.lane_count;
889 } else
890 break;
891 }
892 }
893 }
894 return false;
895 }
896
decide_mst_link_settings(const struct dc_link * link,struct dc_link_settings * link_setting)897 static bool decide_mst_link_settings(const struct dc_link *link, struct dc_link_settings *link_setting)
898 {
899 *link_setting = link->verified_link_cap;
900 return true;
901 }
902
link_decide_link_settings(struct dc_stream_state * stream,struct dc_link_settings * link_setting)903 bool link_decide_link_settings(struct dc_stream_state *stream,
904 struct dc_link_settings *link_setting)
905 {
906 struct dc_link *link = stream->link;
907 uint32_t req_bw = dc_bandwidth_in_kbps_from_timing(&stream->timing, dc_link_get_highest_encoding_format(link));
908
909 memset(link_setting, 0, sizeof(*link_setting));
910
911 if (dc_is_dp_signal(stream->signal) &&
912 link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
913 link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN) {
914 /* if preferred is specified through AMDDP, use it, if it's enough
915 * to drive the mode
916 */
917 *link_setting = link->preferred_link_setting;
918 } else if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
919 /* MST doesn't perform link training for now
920 * TODO: add MST specific link training routine
921 */
922 decide_mst_link_settings(link, link_setting);
923 } else if (stream->signal == SIGNAL_TYPE_VIRTUAL) {
924 link_setting->lane_count = LANE_COUNT_FOUR;
925 link_setting->link_rate = LINK_RATE_HIGH3;
926 } else if (link->connector_signal == SIGNAL_TYPE_EDP) {
927 /* enable edp link optimization for DSC eDP case */
928 if (stream->timing.flags.DSC) {
929 enum dc_link_rate max_link_rate = LINK_RATE_UNKNOWN;
930
931 if (link->panel_config.dsc.force_dsc_edp_policy) {
932 /* calculate link max link rate cap*/
933 struct dc_link_settings tmp_link_setting;
934 struct dc_crtc_timing tmp_timing = stream->timing;
935 uint32_t orig_req_bw;
936
937 tmp_link_setting.link_rate = LINK_RATE_UNKNOWN;
938 tmp_timing.flags.DSC = 0;
939 orig_req_bw = dc_bandwidth_in_kbps_from_timing(&tmp_timing,
940 dc_link_get_highest_encoding_format(link));
941 edp_decide_link_settings(link, &tmp_link_setting, orig_req_bw);
942 max_link_rate = tmp_link_setting.link_rate;
943 }
944 decide_edp_link_settings_with_dsc(link, link_setting, req_bw, max_link_rate);
945 } else {
946 edp_decide_link_settings(link, link_setting, req_bw);
947 }
948 } else {
949 decide_dp_link_settings(link, link_setting, req_bw);
950 }
951
952 return link_setting->lane_count != LANE_COUNT_UNKNOWN &&
953 link_setting->link_rate != LINK_RATE_UNKNOWN;
954 }
955
link_dp_get_encoding_format(const struct dc_link_settings * link_settings)956 enum dp_link_encoding link_dp_get_encoding_format(const struct dc_link_settings *link_settings)
957 {
958 if ((link_settings->link_rate >= LINK_RATE_LOW) &&
959 (link_settings->link_rate <= LINK_RATE_HIGH3))
960 return DP_8b_10b_ENCODING;
961 else if ((link_settings->link_rate >= LINK_RATE_UHBR10) &&
962 (link_settings->link_rate <= LINK_RATE_UHBR20))
963 return DP_128b_132b_ENCODING;
964 return DP_UNKNOWN_ENCODING;
965 }
966
mst_decide_link_encoding_format(const struct dc_link * link)967 enum dp_link_encoding mst_decide_link_encoding_format(const struct dc_link *link)
968 {
969 struct dc_link_settings link_settings = {0};
970
971 if (!dc_is_dp_signal(link->connector_signal))
972 return DP_UNKNOWN_ENCODING;
973
974 if (link->preferred_link_setting.lane_count !=
975 LANE_COUNT_UNKNOWN &&
976 link->preferred_link_setting.link_rate !=
977 LINK_RATE_UNKNOWN) {
978 link_settings = link->preferred_link_setting;
979 } else {
980 decide_mst_link_settings(link, &link_settings);
981 }
982
983 return link_dp_get_encoding_format(&link_settings);
984 }
985
read_dp_device_vendor_id(struct dc_link * link)986 static void read_dp_device_vendor_id(struct dc_link *link)
987 {
988 struct dp_device_vendor_id dp_id;
989
990 /* read IEEE branch device id */
991 core_link_read_dpcd(
992 link,
993 DP_BRANCH_OUI,
994 (uint8_t *)&dp_id,
995 sizeof(dp_id));
996
997 link->dpcd_caps.branch_dev_id =
998 (dp_id.ieee_oui[0] << 16) +
999 (dp_id.ieee_oui[1] << 8) +
1000 dp_id.ieee_oui[2];
1001
1002 memmove(
1003 link->dpcd_caps.branch_dev_name,
1004 dp_id.ieee_device_id,
1005 sizeof(dp_id.ieee_device_id));
1006 }
1007
wake_up_aux_channel(struct dc_link * link)1008 static enum dc_status wake_up_aux_channel(struct dc_link *link)
1009 {
1010 enum dc_status status = DC_ERROR_UNEXPECTED;
1011 uint32_t aux_channel_retry_cnt = 0;
1012 uint8_t dpcd_power_state = '\0';
1013
1014 while (status != DC_OK && aux_channel_retry_cnt < 10) {
1015 status = core_link_read_dpcd(link, DP_SET_POWER,
1016 &dpcd_power_state, sizeof(dpcd_power_state));
1017
1018 /* Delay 1 ms if AUX CH is in power down state. Based on spec
1019 * section 2.3.1.2, if AUX CH may be powered down due to
1020 * write to DPCD 600h = 2. Sink AUX CH is monitoring differential
1021 * signal and may need up to 1 ms before being able to reply.
1022 */
1023 if (status != DC_OK || dpcd_power_state == DP_SET_POWER_D3) {
1024 fsleep(1000);
1025 aux_channel_retry_cnt++;
1026 }
1027 }
1028
1029 if (status != DC_OK) {
1030 dpcd_power_state = DP_SET_POWER_D0;
1031 status = core_link_write_dpcd(
1032 link,
1033 DP_SET_POWER,
1034 &dpcd_power_state,
1035 sizeof(dpcd_power_state));
1036
1037 dpcd_power_state = DP_SET_POWER_D3;
1038 status = core_link_write_dpcd(
1039 link,
1040 DP_SET_POWER,
1041 &dpcd_power_state,
1042 sizeof(dpcd_power_state));
1043 DC_LOG_DC("%s: Failed to power up sink\n", __func__);
1044 return DC_ERROR_UNEXPECTED;
1045 }
1046
1047 return DC_OK;
1048 }
1049
get_active_converter_info(uint8_t data,struct dc_link * link)1050 static void get_active_converter_info(
1051 uint8_t data, struct dc_link *link)
1052 {
1053 union dp_downstream_port_present ds_port = { .byte = data };
1054 memset(&link->dpcd_caps.dongle_caps, 0, sizeof(link->dpcd_caps.dongle_caps));
1055
1056 /* decode converter info*/
1057 if (!ds_port.fields.PORT_PRESENT) {
1058 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
1059 set_dongle_type(link->ddc,
1060 link->dpcd_caps.dongle_type);
1061 link->dpcd_caps.is_branch_dev = false;
1062 return;
1063 }
1064
1065 /* DPCD 0x5 bit 0 = 1, it indicate it's branch device */
1066 link->dpcd_caps.is_branch_dev = ds_port.fields.PORT_PRESENT;
1067
1068 switch (ds_port.fields.PORT_TYPE) {
1069 case DOWNSTREAM_VGA:
1070 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_VGA_CONVERTER;
1071 break;
1072 case DOWNSTREAM_DVI_HDMI_DP_PLUS_PLUS:
1073 /* At this point we don't know is it DVI or HDMI or DP++,
1074 * assume DVI.*/
1075 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_DVI_CONVERTER;
1076 break;
1077 default:
1078 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
1079 break;
1080 }
1081
1082 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_11) {
1083 uint8_t det_caps[16]; /* CTS 4.2.2.7 expects source to read Detailed Capabilities Info : 00080h-0008F.*/
1084 union dwnstream_port_caps_byte0 *port_caps =
1085 (union dwnstream_port_caps_byte0 *)det_caps;
1086 if (core_link_read_dpcd(link, DP_DOWNSTREAM_PORT_0,
1087 det_caps, sizeof(det_caps)) == DC_OK) {
1088
1089 switch (port_caps->bits.DWN_STRM_PORTX_TYPE) {
1090 /*Handle DP case as DONGLE_NONE*/
1091 case DOWN_STREAM_DETAILED_DP:
1092 link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
1093 break;
1094 case DOWN_STREAM_DETAILED_VGA:
1095 link->dpcd_caps.dongle_type =
1096 DISPLAY_DONGLE_DP_VGA_CONVERTER;
1097 break;
1098 case DOWN_STREAM_DETAILED_DVI:
1099 link->dpcd_caps.dongle_type =
1100 DISPLAY_DONGLE_DP_DVI_CONVERTER;
1101 break;
1102 case DOWN_STREAM_DETAILED_HDMI:
1103 case DOWN_STREAM_DETAILED_DP_PLUS_PLUS:
1104 /*Handle DP++ active converter case, process DP++ case as HDMI case according DP1.4 spec*/
1105 link->dpcd_caps.dongle_type =
1106 DISPLAY_DONGLE_DP_HDMI_CONVERTER;
1107
1108 link->dpcd_caps.dongle_caps.dongle_type = link->dpcd_caps.dongle_type;
1109 if (ds_port.fields.DETAILED_CAPS) {
1110
1111 union dwnstream_port_caps_byte3_hdmi
1112 hdmi_caps = {.raw = det_caps[3] };
1113 union dwnstream_port_caps_byte2
1114 hdmi_color_caps = {.raw = det_caps[2] };
1115 link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz =
1116 det_caps[1] * 2500;
1117
1118 link->dpcd_caps.dongle_caps.is_dp_hdmi_s3d_converter =
1119 hdmi_caps.bits.FRAME_SEQ_TO_FRAME_PACK;
1120 /*YCBCR capability only for HDMI case*/
1121 if (port_caps->bits.DWN_STRM_PORTX_TYPE
1122 == DOWN_STREAM_DETAILED_HDMI) {
1123 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_pass_through =
1124 hdmi_caps.bits.YCrCr422_PASS_THROUGH;
1125 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_pass_through =
1126 hdmi_caps.bits.YCrCr420_PASS_THROUGH;
1127 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_converter =
1128 hdmi_caps.bits.YCrCr422_CONVERSION;
1129 link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_converter =
1130 hdmi_caps.bits.YCrCr420_CONVERSION;
1131 }
1132
1133 link->dpcd_caps.dongle_caps.dp_hdmi_max_bpc =
1134 translate_dpcd_max_bpc(
1135 hdmi_color_caps.bits.MAX_BITS_PER_COLOR_COMPONENT);
1136
1137 if (link->dc->caps.dp_hdmi21_pcon_support) {
1138 union hdmi_encoded_link_bw hdmi_encoded_link_bw;
1139
1140 link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps =
1141 link_bw_kbps_from_raw_frl_link_rate_data(
1142 hdmi_color_caps.bits.MAX_ENCODED_LINK_BW_SUPPORT);
1143
1144 // Intersect reported max link bw support with the supported link rate post FRL link training
1145 if (core_link_read_dpcd(link, DP_PCON_HDMI_POST_FRL_STATUS,
1146 &hdmi_encoded_link_bw.raw, sizeof(hdmi_encoded_link_bw)) == DC_OK) {
1147 link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps = intersect_frl_link_bw_support(
1148 link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps,
1149 hdmi_encoded_link_bw);
1150 }
1151
1152 if (link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps > 0)
1153 link->dpcd_caps.dongle_caps.extendedCapValid = true;
1154 }
1155
1156 if (link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz != 0)
1157 link->dpcd_caps.dongle_caps.extendedCapValid = true;
1158 }
1159
1160 break;
1161 }
1162 }
1163 }
1164
1165 set_dongle_type(link->ddc, link->dpcd_caps.dongle_type);
1166
1167 {
1168 struct dp_sink_hw_fw_revision dp_hw_fw_revision;
1169
1170 core_link_read_dpcd(
1171 link,
1172 DP_BRANCH_REVISION_START,
1173 (uint8_t *)&dp_hw_fw_revision,
1174 sizeof(dp_hw_fw_revision));
1175
1176 link->dpcd_caps.branch_hw_revision =
1177 dp_hw_fw_revision.ieee_hw_rev;
1178
1179 memmove(
1180 link->dpcd_caps.branch_fw_revision,
1181 dp_hw_fw_revision.ieee_fw_rev,
1182 sizeof(dp_hw_fw_revision.ieee_fw_rev));
1183 }
1184 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14 &&
1185 link->dpcd_caps.dongle_type != DISPLAY_DONGLE_NONE) {
1186 union dp_dfp_cap_ext dfp_cap_ext;
1187 memset(&dfp_cap_ext, '\0', sizeof (dfp_cap_ext));
1188 core_link_read_dpcd(
1189 link,
1190 DP_DFP_CAPABILITY_EXTENSION_SUPPORT,
1191 dfp_cap_ext.raw,
1192 sizeof(dfp_cap_ext.raw));
1193 link->dpcd_caps.dongle_caps.dfp_cap_ext.supported = dfp_cap_ext.fields.supported;
1194 link->dpcd_caps.dongle_caps.dfp_cap_ext.max_pixel_rate_in_mps =
1195 dfp_cap_ext.fields.max_pixel_rate_in_mps[0] +
1196 (dfp_cap_ext.fields.max_pixel_rate_in_mps[1] << 8);
1197 link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_h_active_width =
1198 dfp_cap_ext.fields.max_video_h_active_width[0] +
1199 (dfp_cap_ext.fields.max_video_h_active_width[1] << 8);
1200 link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_v_active_height =
1201 dfp_cap_ext.fields.max_video_v_active_height[0] +
1202 (dfp_cap_ext.fields.max_video_v_active_height[1] << 8);
1203 link->dpcd_caps.dongle_caps.dfp_cap_ext.encoding_format_caps =
1204 dfp_cap_ext.fields.encoding_format_caps;
1205 link->dpcd_caps.dongle_caps.dfp_cap_ext.rgb_color_depth_caps =
1206 dfp_cap_ext.fields.rgb_color_depth_caps;
1207 link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr444_color_depth_caps =
1208 dfp_cap_ext.fields.ycbcr444_color_depth_caps;
1209 link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr422_color_depth_caps =
1210 dfp_cap_ext.fields.ycbcr422_color_depth_caps;
1211 link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr420_color_depth_caps =
1212 dfp_cap_ext.fields.ycbcr420_color_depth_caps;
1213 DC_LOG_DP2("DFP capability extension is read at link %d", link->link_index);
1214 DC_LOG_DP2("\tdfp_cap_ext.supported = %s", link->dpcd_caps.dongle_caps.dfp_cap_ext.supported ? "true" : "false");
1215 DC_LOG_DP2("\tdfp_cap_ext.max_pixel_rate_in_mps = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_pixel_rate_in_mps);
1216 DC_LOG_DP2("\tdfp_cap_ext.max_video_h_active_width = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_h_active_width);
1217 DC_LOG_DP2("\tdfp_cap_ext.max_video_v_active_height = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_v_active_height);
1218 }
1219 }
1220
apply_usbc_combo_phy_reset_wa(struct dc_link * link,struct dc_link_settings * link_settings)1221 static void apply_usbc_combo_phy_reset_wa(struct dc_link *link,
1222 struct dc_link_settings *link_settings)
1223 {
1224 /* Temporary Renoir-specific workaround PHY will sometimes be in bad
1225 * state on hotplugging display from certain USB-C dongle, so add extra
1226 * cycle of enabling and disabling the PHY before first link training.
1227 */
1228 struct link_resource link_res = {0};
1229 enum clock_source_id dp_cs_id = get_clock_source_id(link);
1230
1231 dp_enable_link_phy(link, &link_res, link->connector_signal,
1232 dp_cs_id, link_settings);
1233 dp_disable_link_phy(link, &link_res, link->connector_signal);
1234 }
1235
dp_overwrite_extended_receiver_cap(struct dc_link * link)1236 bool dp_overwrite_extended_receiver_cap(struct dc_link *link)
1237 {
1238 uint8_t dpcd_data[16];
1239 uint32_t read_dpcd_retry_cnt = 3;
1240 enum dc_status status = DC_ERROR_UNEXPECTED;
1241 union dp_downstream_port_present ds_port = { 0 };
1242 union down_stream_port_count down_strm_port_count;
1243 union edp_configuration_cap edp_config_cap;
1244
1245 int i;
1246
1247 for (i = 0; i < read_dpcd_retry_cnt; i++) {
1248 status = core_link_read_dpcd(
1249 link,
1250 DP_DPCD_REV,
1251 dpcd_data,
1252 sizeof(dpcd_data));
1253 if (status == DC_OK)
1254 break;
1255 }
1256
1257 link->dpcd_caps.dpcd_rev.raw =
1258 dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
1259
1260 if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
1261 return false;
1262
1263 ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
1264 DP_DPCD_REV];
1265
1266 get_active_converter_info(ds_port.byte, link);
1267
1268 down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
1269 DP_DPCD_REV];
1270
1271 link->dpcd_caps.allow_invalid_MSA_timing_param =
1272 down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
1273
1274 link->dpcd_caps.max_ln_count.raw = dpcd_data[
1275 DP_MAX_LANE_COUNT - DP_DPCD_REV];
1276
1277 link->dpcd_caps.max_down_spread.raw = dpcd_data[
1278 DP_MAX_DOWNSPREAD - DP_DPCD_REV];
1279
1280 link->reported_link_cap.lane_count =
1281 link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
1282 link->reported_link_cap.link_rate = dpcd_data[
1283 DP_MAX_LINK_RATE - DP_DPCD_REV];
1284 link->reported_link_cap.link_spread =
1285 link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
1286 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
1287
1288 edp_config_cap.raw = dpcd_data[
1289 DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
1290 link->dpcd_caps.panel_mode_edp =
1291 edp_config_cap.bits.ALT_SCRAMBLER_RESET;
1292 link->dpcd_caps.dpcd_display_control_capable =
1293 edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
1294
1295 return true;
1296 }
1297
dpcd_set_source_specific_data(struct dc_link * link)1298 void dpcd_set_source_specific_data(struct dc_link *link)
1299 {
1300 if (!link->dc->vendor_signature.is_valid) {
1301 enum dc_status __maybe_unused result_write_min_hblank = DC_NOT_SUPPORTED;
1302 struct dpcd_amd_signature amd_signature = {0};
1303 struct dpcd_amd_device_id amd_device_id = {0};
1304
1305 amd_device_id.device_id_byte1 =
1306 (uint8_t)(link->ctx->asic_id.chip_id);
1307 amd_device_id.device_id_byte2 =
1308 (uint8_t)(link->ctx->asic_id.chip_id >> 8);
1309 amd_device_id.dce_version =
1310 (uint8_t)(link->ctx->dce_version);
1311 amd_device_id.dal_version_byte1 = 0x0; // needed? where to get?
1312 amd_device_id.dal_version_byte2 = 0x0; // needed? where to get?
1313
1314 core_link_read_dpcd(link, DP_SOURCE_OUI,
1315 (uint8_t *)(&amd_signature),
1316 sizeof(amd_signature));
1317
1318 if (!((amd_signature.AMD_IEEE_TxSignature_byte1 == 0x0) &&
1319 (amd_signature.AMD_IEEE_TxSignature_byte2 == 0x0) &&
1320 (amd_signature.AMD_IEEE_TxSignature_byte3 == 0x1A))) {
1321
1322 amd_signature.AMD_IEEE_TxSignature_byte1 = 0x0;
1323 amd_signature.AMD_IEEE_TxSignature_byte2 = 0x0;
1324 amd_signature.AMD_IEEE_TxSignature_byte3 = 0x1A;
1325
1326 core_link_write_dpcd(link, DP_SOURCE_OUI,
1327 (uint8_t *)(&amd_signature),
1328 sizeof(amd_signature));
1329 }
1330
1331 core_link_write_dpcd(link, DP_SOURCE_OUI+0x03,
1332 (uint8_t *)(&amd_device_id),
1333 sizeof(amd_device_id));
1334
1335 if (link->ctx->dce_version >= DCN_VERSION_2_0 &&
1336 link->dc->caps.min_horizontal_blanking_period != 0) {
1337
1338 uint8_t hblank_size = (uint8_t)link->dc->caps.min_horizontal_blanking_period;
1339
1340 result_write_min_hblank = core_link_write_dpcd(link,
1341 DP_SOURCE_MINIMUM_HBLANK_SUPPORTED, (uint8_t *)(&hblank_size),
1342 sizeof(hblank_size));
1343 }
1344 DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION,
1345 WPP_BIT_FLAG_DC_DETECTION_DP_CAPS,
1346 "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'",
1347 result_write_min_hblank,
1348 link->link_index,
1349 link->ctx->dce_version,
1350 DP_SOURCE_MINIMUM_HBLANK_SUPPORTED,
1351 link->dc->caps.min_horizontal_blanking_period,
1352 link->dpcd_caps.branch_dev_id,
1353 link->dpcd_caps.branch_dev_name[0],
1354 link->dpcd_caps.branch_dev_name[1],
1355 link->dpcd_caps.branch_dev_name[2],
1356 link->dpcd_caps.branch_dev_name[3],
1357 link->dpcd_caps.branch_dev_name[4],
1358 link->dpcd_caps.branch_dev_name[5]);
1359 } else {
1360 core_link_write_dpcd(link, DP_SOURCE_OUI,
1361 link->dc->vendor_signature.data.raw,
1362 sizeof(link->dc->vendor_signature.data.raw));
1363 }
1364 }
1365
dpcd_write_cable_id_to_dprx(struct dc_link * link)1366 void dpcd_write_cable_id_to_dprx(struct dc_link *link)
1367 {
1368 if (!link->dpcd_caps.channel_coding_cap.bits.DP_128b_132b_SUPPORTED ||
1369 link->dpcd_caps.cable_id.raw == 0 ||
1370 link->dprx_states.cable_id_written)
1371 return;
1372
1373 core_link_write_dpcd(link, DP_CABLE_ATTRIBUTES_UPDATED_BY_DPTX,
1374 &link->dpcd_caps.cable_id.raw,
1375 sizeof(link->dpcd_caps.cable_id.raw));
1376
1377 link->dprx_states.cable_id_written = 1;
1378 }
1379
get_usbc_cable_id(struct dc_link * link,union dp_cable_id * cable_id)1380 static bool get_usbc_cable_id(struct dc_link *link, union dp_cable_id *cable_id)
1381 {
1382 union dmub_rb_cmd cmd;
1383
1384 if (!link->ctx->dmub_srv ||
1385 link->ep_type != DISPLAY_ENDPOINT_PHY ||
1386 link->link_enc->features.flags.bits.DP_IS_USB_C == 0)
1387 return false;
1388
1389 memset(&cmd, 0, sizeof(cmd));
1390 cmd.cable_id.header.type = DMUB_CMD_GET_USBC_CABLE_ID;
1391 cmd.cable_id.header.payload_bytes = sizeof(cmd.cable_id.data);
1392 cmd.cable_id.data.input.phy_inst = resource_transmitter_to_phy_idx(
1393 link->dc, link->link_enc->transmitter);
1394 if (dm_execute_dmub_cmd(link->dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY) &&
1395 cmd.cable_id.header.ret_status == 1) {
1396 cable_id->raw = cmd.cable_id.data.output_raw;
1397 DC_LOG_DC("usbc_cable_id = %d.\n", cable_id->raw);
1398 }
1399 return cmd.cable_id.header.ret_status == 1;
1400 }
1401
retrieve_cable_id(struct dc_link * link)1402 static void retrieve_cable_id(struct dc_link *link)
1403 {
1404 union dp_cable_id usbc_cable_id;
1405
1406 link->dpcd_caps.cable_id.raw = 0;
1407 core_link_read_dpcd(link, DP_CABLE_ATTRIBUTES_UPDATED_BY_DPRX,
1408 &link->dpcd_caps.cable_id.raw, sizeof(uint8_t));
1409
1410 if (get_usbc_cable_id(link, &usbc_cable_id))
1411 link->dpcd_caps.cable_id = intersect_cable_id(
1412 &link->dpcd_caps.cable_id, &usbc_cable_id);
1413 }
1414
read_is_mst_supported(struct dc_link * link)1415 bool read_is_mst_supported(struct dc_link *link)
1416 {
1417 bool mst = false;
1418 enum dc_status st = DC_OK;
1419 union dpcd_rev rev;
1420 union mstm_cap cap;
1421
1422 if (link->preferred_training_settings.mst_enable &&
1423 *link->preferred_training_settings.mst_enable == false) {
1424 return false;
1425 }
1426
1427 rev.raw = 0;
1428 cap.raw = 0;
1429
1430 st = core_link_read_dpcd(link, DP_DPCD_REV, &rev.raw,
1431 sizeof(rev));
1432
1433 if (st == DC_OK && rev.raw >= DPCD_REV_12) {
1434
1435 st = core_link_read_dpcd(link, DP_MSTM_CAP,
1436 &cap.raw, sizeof(cap));
1437 if (st == DC_OK && cap.bits.MST_CAP == 1)
1438 mst = true;
1439 }
1440 return mst;
1441
1442 }
1443
1444 /* Read additional sink caps defined in source specific DPCD area
1445 * This function currently only reads from SinkCapability address (DP_SOURCE_SINK_CAP)
1446 * TODO: Add FS caps and read from DP_SOURCE_SINK_FS_CAP as well
1447 */
dpcd_read_sink_ext_caps(struct dc_link * link)1448 static bool dpcd_read_sink_ext_caps(struct dc_link *link)
1449 {
1450 uint8_t dpcd_data = 0;
1451 uint8_t edp_general_cap2 = 0;
1452
1453 if (!link)
1454 return false;
1455
1456 if (core_link_read_dpcd(link, DP_SOURCE_SINK_CAP, &dpcd_data, 1) != DC_OK)
1457 return false;
1458
1459 link->dpcd_sink_ext_caps.raw = dpcd_data;
1460
1461 if (core_link_read_dpcd(link, DP_EDP_GENERAL_CAP_2, &edp_general_cap2, 1) != DC_OK)
1462 return false;
1463
1464 link->dpcd_caps.panel_luminance_control = (edp_general_cap2 & DP_EDP_PANEL_LUMINANCE_CONTROL_CAPABLE) != 0;
1465
1466 return true;
1467 }
1468
dp_retrieve_lttpr_cap(struct dc_link * link)1469 enum dc_status dp_retrieve_lttpr_cap(struct dc_link *link)
1470 {
1471 uint8_t lttpr_dpcd_data[8];
1472 enum dc_status status;
1473 bool is_lttpr_present;
1474
1475 /* Logic to determine LTTPR support*/
1476 bool vbios_lttpr_interop = link->dc->caps.vbios_lttpr_aware;
1477
1478 if (!vbios_lttpr_interop || !link->dc->caps.extended_aux_timeout_support)
1479 return DC_NOT_SUPPORTED;
1480
1481 /* By reading LTTPR capability, RX assumes that we will enable
1482 * LTTPR extended aux timeout if LTTPR is present.
1483 */
1484 status = core_link_read_dpcd(
1485 link,
1486 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV,
1487 lttpr_dpcd_data,
1488 sizeof(lttpr_dpcd_data));
1489
1490 link->dpcd_caps.lttpr_caps.revision.raw =
1491 lttpr_dpcd_data[DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV -
1492 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1493
1494 link->dpcd_caps.lttpr_caps.max_link_rate =
1495 lttpr_dpcd_data[DP_MAX_LINK_RATE_PHY_REPEATER -
1496 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1497
1498 link->dpcd_caps.lttpr_caps.phy_repeater_cnt =
1499 lttpr_dpcd_data[DP_PHY_REPEATER_CNT -
1500 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1501
1502 link->dpcd_caps.lttpr_caps.max_lane_count =
1503 lttpr_dpcd_data[DP_MAX_LANE_COUNT_PHY_REPEATER -
1504 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1505
1506 link->dpcd_caps.lttpr_caps.mode =
1507 lttpr_dpcd_data[DP_PHY_REPEATER_MODE -
1508 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1509
1510 link->dpcd_caps.lttpr_caps.max_ext_timeout =
1511 lttpr_dpcd_data[DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT -
1512 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1513 link->dpcd_caps.lttpr_caps.main_link_channel_coding.raw =
1514 lttpr_dpcd_data[DP_MAIN_LINK_CHANNEL_CODING_PHY_REPEATER -
1515 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1516
1517 link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.raw =
1518 lttpr_dpcd_data[DP_PHY_REPEATER_128B132B_RATES -
1519 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
1520
1521 /* If this chip cap is set, at least one retimer must exist in the chain
1522 * Override count to 1 if we receive a known bad count (0 or an invalid value) */
1523 if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
1524 (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) == 0)) {
1525 ASSERT(0);
1526 link->dpcd_caps.lttpr_caps.phy_repeater_cnt = 0x80;
1527 DC_LOG_DC("lttpr_caps forced phy_repeater_cnt = %d\n", link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
1528 }
1529
1530 /* Attempt to train in LTTPR transparent mode if repeater count exceeds 8. */
1531 is_lttpr_present = dp_is_lttpr_present(link);
1532
1533 if (is_lttpr_present)
1534 CONN_DATA_DETECT(link, lttpr_dpcd_data, sizeof(lttpr_dpcd_data), "LTTPR Caps: ");
1535
1536 DC_LOG_DC("is_lttpr_present = %d\n", is_lttpr_present);
1537 return status;
1538 }
1539
retrieve_link_cap(struct dc_link * link)1540 static bool retrieve_link_cap(struct dc_link *link)
1541 {
1542 /* DP_ADAPTER_CAP - DP_DPCD_REV + 1 == 16 and also DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT + 1 == 16,
1543 * which means size 16 will be good for both of those DPCD register block reads
1544 */
1545 uint8_t dpcd_data[16];
1546 /*Only need to read 1 byte starting from DP_DPRX_FEATURE_ENUMERATION_LIST.
1547 */
1548 uint8_t dpcd_dprx_data = '\0';
1549
1550 struct dp_device_vendor_id sink_id;
1551 union down_stream_port_count down_strm_port_count;
1552 union edp_configuration_cap edp_config_cap;
1553 union dp_downstream_port_present ds_port = { 0 };
1554 enum dc_status status = DC_ERROR_UNEXPECTED;
1555 uint32_t read_dpcd_retry_cnt = 3;
1556 int i;
1557 struct dp_sink_hw_fw_revision dp_hw_fw_revision;
1558 const uint32_t post_oui_delay = 30; // 30ms
1559 bool is_fec_supported = false;
1560 bool is_dsc_basic_supported = false;
1561 bool is_dsc_passthrough_supported = false;
1562
1563 memset(dpcd_data, '\0', sizeof(dpcd_data));
1564 memset(&down_strm_port_count,
1565 '\0', sizeof(union down_stream_port_count));
1566 memset(&edp_config_cap, '\0',
1567 sizeof(union edp_configuration_cap));
1568
1569 /* if extended timeout is supported in hardware,
1570 * default to LTTPR timeout (3.2ms) first as a W/A for DP link layer
1571 * CTS 4.2.1.1 regression introduced by CTS specs requirement update.
1572 */
1573 try_to_configure_aux_timeout(link->ddc,
1574 LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD);
1575
1576 status = dp_retrieve_lttpr_cap(link);
1577
1578 if (status != DC_OK) {
1579 status = wake_up_aux_channel(link);
1580 if (status == DC_OK)
1581 dp_retrieve_lttpr_cap(link);
1582 else
1583 return false;
1584 }
1585
1586 if (dp_is_lttpr_present(link)) {
1587 configure_lttpr_mode_transparent(link);
1588
1589 // Echo TOTAL_LTTPR_CNT back downstream
1590 core_link_write_dpcd(
1591 link,
1592 DP_TOTAL_LTTPR_CNT,
1593 &link->dpcd_caps.lttpr_caps.phy_repeater_cnt,
1594 sizeof(link->dpcd_caps.lttpr_caps.phy_repeater_cnt));
1595 }
1596
1597 /* Read DP tunneling information. */
1598 status = dpcd_get_tunneling_device_data(link);
1599
1600 dpcd_set_source_specific_data(link);
1601 /* Sink may need to configure internals based on vendor, so allow some
1602 * time before proceeding with possibly vendor specific transactions
1603 */
1604 msleep(post_oui_delay);
1605
1606 for (i = 0; i < read_dpcd_retry_cnt; i++) {
1607 status = core_link_read_dpcd(
1608 link,
1609 DP_DPCD_REV,
1610 dpcd_data,
1611 sizeof(dpcd_data));
1612 if (status == DC_OK)
1613 break;
1614 }
1615
1616
1617 if (status != DC_OK) {
1618 dm_error("%s: Read receiver caps dpcd data failed.\n", __func__);
1619 return false;
1620 }
1621
1622 if (!dp_is_lttpr_present(link))
1623 try_to_configure_aux_timeout(link->ddc, LINK_AUX_DEFAULT_TIMEOUT_PERIOD);
1624
1625
1626 {
1627 union training_aux_rd_interval aux_rd_interval;
1628
1629 aux_rd_interval.raw =
1630 dpcd_data[DP_TRAINING_AUX_RD_INTERVAL];
1631
1632 link->dpcd_caps.ext_receiver_cap_field_present =
1633 aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1;
1634
1635 if (aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1) {
1636 uint8_t ext_cap_data[16];
1637
1638 memset(ext_cap_data, '\0', sizeof(ext_cap_data));
1639 for (i = 0; i < read_dpcd_retry_cnt; i++) {
1640 status = core_link_read_dpcd(
1641 link,
1642 DP_DP13_DPCD_REV,
1643 ext_cap_data,
1644 sizeof(ext_cap_data));
1645 if (status == DC_OK) {
1646 memcpy(dpcd_data, ext_cap_data, sizeof(dpcd_data));
1647 break;
1648 }
1649 }
1650 if (status != DC_OK)
1651 dm_error("%s: Read extend caps data failed, use cap from dpcd 0.\n", __func__);
1652 }
1653 }
1654
1655 link->dpcd_caps.dpcd_rev.raw =
1656 dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
1657
1658 if (link->dpcd_caps.ext_receiver_cap_field_present) {
1659 for (i = 0; i < read_dpcd_retry_cnt; i++) {
1660 status = core_link_read_dpcd(
1661 link,
1662 DP_DPRX_FEATURE_ENUMERATION_LIST,
1663 &dpcd_dprx_data,
1664 sizeof(dpcd_dprx_data));
1665 if (status == DC_OK)
1666 break;
1667 }
1668
1669 link->dpcd_caps.dprx_feature.raw = dpcd_dprx_data;
1670
1671 if (status != DC_OK)
1672 dm_error("%s: Read DPRX caps data failed.\n", __func__);
1673
1674 /* AdaptiveSyncCapability */
1675 dpcd_dprx_data = 0;
1676 for (i = 0; i < read_dpcd_retry_cnt; i++) {
1677 status = core_link_read_dpcd(
1678 link, DP_DPRX_FEATURE_ENUMERATION_LIST_CONT_1,
1679 &dpcd_dprx_data, sizeof(dpcd_dprx_data));
1680 if (status == DC_OK)
1681 break;
1682 }
1683
1684 link->dpcd_caps.adaptive_sync_caps.dp_adap_sync_caps.raw = dpcd_dprx_data;
1685
1686 if (status != DC_OK)
1687 dm_error("%s: Read DPRX caps data failed. Addr:%#x\n",
1688 __func__, DP_DPRX_FEATURE_ENUMERATION_LIST_CONT_1);
1689 }
1690
1691 else {
1692 link->dpcd_caps.dprx_feature.raw = 0;
1693 }
1694
1695
1696 /* Error condition checking...
1697 * It is impossible for Sink to report Max Lane Count = 0.
1698 * It is possible for Sink to report Max Link Rate = 0, if it is
1699 * an eDP device that is reporting specialized link rates in the
1700 * SUPPORTED_LINK_RATE table.
1701 */
1702 if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
1703 return false;
1704
1705 ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
1706 DP_DPCD_REV];
1707
1708 read_dp_device_vendor_id(link);
1709
1710 /* TODO - decouple raw mst capability from policy decision */
1711 link->dpcd_caps.is_mst_capable = read_is_mst_supported(link);
1712 DC_LOG_DC("%s: MST_Support: %s\n", __func__, str_yes_no(link->dpcd_caps.is_mst_capable));
1713
1714 get_active_converter_info(ds_port.byte, link);
1715
1716 dp_wa_power_up_0010FA(link, dpcd_data, sizeof(dpcd_data));
1717
1718 down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
1719 DP_DPCD_REV];
1720
1721 link->dpcd_caps.allow_invalid_MSA_timing_param =
1722 down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
1723
1724 link->dpcd_caps.max_ln_count.raw = dpcd_data[
1725 DP_MAX_LANE_COUNT - DP_DPCD_REV];
1726
1727 link->dpcd_caps.max_down_spread.raw = dpcd_data[
1728 DP_MAX_DOWNSPREAD - DP_DPCD_REV];
1729
1730 link->reported_link_cap.lane_count =
1731 link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
1732 link->reported_link_cap.link_rate = get_link_rate_from_max_link_bw(
1733 dpcd_data[DP_MAX_LINK_RATE - DP_DPCD_REV]);
1734 link->reported_link_cap.link_spread =
1735 link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
1736 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
1737
1738 edp_config_cap.raw = dpcd_data[
1739 DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
1740 link->dpcd_caps.panel_mode_edp =
1741 edp_config_cap.bits.ALT_SCRAMBLER_RESET;
1742 link->dpcd_caps.dpcd_display_control_capable =
1743 edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
1744 link->dpcd_caps.channel_coding_cap.raw =
1745 dpcd_data[DP_MAIN_LINK_CHANNEL_CODING - DP_DPCD_REV];
1746 link->test_pattern_enabled = false;
1747 link->compliance_test_state.raw = 0;
1748
1749 /* read sink count */
1750 core_link_read_dpcd(link,
1751 DP_SINK_COUNT,
1752 &link->dpcd_caps.sink_count.raw,
1753 sizeof(link->dpcd_caps.sink_count.raw));
1754
1755 /* read sink ieee oui */
1756 core_link_read_dpcd(link,
1757 DP_SINK_OUI,
1758 (uint8_t *)(&sink_id),
1759 sizeof(sink_id));
1760
1761 link->dpcd_caps.sink_dev_id =
1762 (sink_id.ieee_oui[0] << 16) +
1763 (sink_id.ieee_oui[1] << 8) +
1764 (sink_id.ieee_oui[2]);
1765
1766 memmove(
1767 link->dpcd_caps.sink_dev_id_str,
1768 sink_id.ieee_device_id,
1769 sizeof(sink_id.ieee_device_id));
1770
1771 core_link_read_dpcd(
1772 link,
1773 DP_SINK_HW_REVISION_START,
1774 (uint8_t *)&dp_hw_fw_revision,
1775 sizeof(dp_hw_fw_revision));
1776
1777 link->dpcd_caps.sink_hw_revision =
1778 dp_hw_fw_revision.ieee_hw_rev;
1779
1780 memmove(
1781 link->dpcd_caps.sink_fw_revision,
1782 dp_hw_fw_revision.ieee_fw_rev,
1783 sizeof(dp_hw_fw_revision.ieee_fw_rev));
1784
1785 /* Quirk for Retina panels: wrong DP_MAX_LINK_RATE */
1786 {
1787 uint8_t str_mbp_2018[] = { 101, 68, 21, 103, 98, 97 };
1788 uint8_t fwrev_mbp_2018[] = { 7, 4 };
1789 uint8_t fwrev_mbp_2018_vega[] = { 8, 4 };
1790
1791 /* We also check for the firmware revision as 16,1 models have an
1792 * identical device id and are incorrectly quirked otherwise.
1793 */
1794 if ((link->dpcd_caps.sink_dev_id == 0x0010fa) &&
1795 !memcmp(link->dpcd_caps.sink_dev_id_str, str_mbp_2018,
1796 sizeof(str_mbp_2018)) &&
1797 (!memcmp(link->dpcd_caps.sink_fw_revision, fwrev_mbp_2018,
1798 sizeof(fwrev_mbp_2018)) ||
1799 !memcmp(link->dpcd_caps.sink_fw_revision, fwrev_mbp_2018_vega,
1800 sizeof(fwrev_mbp_2018_vega)))) {
1801 link->reported_link_cap.link_rate = LINK_RATE_RBR2;
1802 }
1803 }
1804
1805 memset(&link->dpcd_caps.dsc_caps, '\0',
1806 sizeof(link->dpcd_caps.dsc_caps));
1807 memset(&link->dpcd_caps.fec_cap, '\0', sizeof(link->dpcd_caps.fec_cap));
1808 /* Read DSC and FEC sink capabilities if DP revision is 1.4 and up */
1809 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14) {
1810 status = core_link_read_dpcd(
1811 link,
1812 DP_FEC_CAPABILITY,
1813 &link->dpcd_caps.fec_cap.raw,
1814 sizeof(link->dpcd_caps.fec_cap.raw));
1815 status = core_link_read_dpcd(
1816 link,
1817 DP_DSC_SUPPORT,
1818 link->dpcd_caps.dsc_caps.dsc_basic_caps.raw,
1819 sizeof(link->dpcd_caps.dsc_caps.dsc_basic_caps.raw));
1820 if (status == DC_OK) {
1821 is_fec_supported = link->dpcd_caps.fec_cap.bits.FEC_CAPABLE;
1822 is_dsc_basic_supported = link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT;
1823 is_dsc_passthrough_supported = link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_PASSTHROUGH_SUPPORT;
1824 DC_LOG_DC("%s: FEC_Sink_Support: %s\n", __func__,
1825 str_yes_no(is_fec_supported));
1826 DC_LOG_DC("%s: DSC_Basic_Sink_Support: %s\n", __func__,
1827 str_yes_no(is_dsc_basic_supported));
1828 DC_LOG_DC("%s: DSC_Passthrough_Sink_Support: %s\n", __func__,
1829 str_yes_no(is_dsc_passthrough_supported));
1830 }
1831 if (link->dpcd_caps.dongle_type != DISPLAY_DONGLE_NONE) {
1832 status = core_link_read_dpcd(
1833 link,
1834 DP_DSC_BRANCH_OVERALL_THROUGHPUT_0,
1835 link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw,
1836 sizeof(link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw));
1837 DC_LOG_DSC("DSC branch decoder capability is read at link %d", link->link_index);
1838 DC_LOG_DSC("\tBRANCH_OVERALL_THROUGHPUT_0 = 0x%02x",
1839 link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_OVERALL_THROUGHPUT_0);
1840 DC_LOG_DSC("\tBRANCH_OVERALL_THROUGHPUT_1 = 0x%02x",
1841 link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_OVERALL_THROUGHPUT_1);
1842 DC_LOG_DSC("\tBRANCH_MAX_LINE_WIDTH 0x%02x",
1843 link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_MAX_LINE_WIDTH);
1844 }
1845
1846 /* Apply work around to disable FEC and DSC for USB4 tunneling in TBT3 compatibility mode
1847 * only if required.
1848 */
1849 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA &&
1850 link->dc->debug.dpia_debug.bits.enable_force_tbt3_work_around &&
1851 link->dpcd_caps.is_branch_dev &&
1852 link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_90CC24 &&
1853 link->dpcd_caps.branch_hw_revision == DP_BRANCH_HW_REV_10 &&
1854 (link->dpcd_caps.fec_cap.bits.FEC_CAPABLE ||
1855 link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT)) {
1856 /* A TBT3 device is expected to report no support for FEC or DSC to a USB4 DPIA.
1857 * Clear FEC and DSC capabilities as a work around if that is not the case.
1858 */
1859 link->wa_flags.dpia_forced_tbt3_mode = true;
1860 memset(&link->dpcd_caps.dsc_caps, '\0', sizeof(link->dpcd_caps.dsc_caps));
1861 memset(&link->dpcd_caps.fec_cap, '\0', sizeof(link->dpcd_caps.fec_cap));
1862 DC_LOG_DSC("Clear DSC SUPPORT for USB4 link(%d) in TBT3 compatibility mode", link->link_index);
1863 } else
1864 link->wa_flags.dpia_forced_tbt3_mode = false;
1865 }
1866
1867 if (!dpcd_read_sink_ext_caps(link))
1868 link->dpcd_sink_ext_caps.raw = 0;
1869
1870 if (link->dpcd_caps.channel_coding_cap.bits.DP_128b_132b_SUPPORTED) {
1871 DC_LOG_DP2("128b/132b encoding is supported at link %d", link->link_index);
1872
1873 core_link_read_dpcd(link,
1874 DP_128B132B_SUPPORTED_LINK_RATES,
1875 &link->dpcd_caps.dp_128b_132b_supported_link_rates.raw,
1876 sizeof(link->dpcd_caps.dp_128b_132b_supported_link_rates.raw));
1877 if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR20)
1878 link->reported_link_cap.link_rate = LINK_RATE_UHBR20;
1879 else if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5)
1880 link->reported_link_cap.link_rate = LINK_RATE_UHBR13_5;
1881 else if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR10)
1882 link->reported_link_cap.link_rate = LINK_RATE_UHBR10;
1883 else
1884 dm_error("%s: Invalid RX 128b_132b_supported_link_rates\n", __func__);
1885 DC_LOG_DP2("128b/132b supported link rates is read at link %d", link->link_index);
1886 DC_LOG_DP2("\tmax 128b/132b link rate support is %d.%d GHz",
1887 link->reported_link_cap.link_rate / 100,
1888 link->reported_link_cap.link_rate % 100);
1889
1890 core_link_read_dpcd(link,
1891 DP_SINK_VIDEO_FALLBACK_FORMATS,
1892 &link->dpcd_caps.fallback_formats.raw,
1893 sizeof(link->dpcd_caps.fallback_formats.raw));
1894 DC_LOG_DP2("sink video fallback format is read at link %d", link->link_index);
1895 if (link->dpcd_caps.fallback_formats.bits.dp_1920x1080_60Hz_24bpp_support)
1896 DC_LOG_DP2("\t1920x1080@60Hz 24bpp fallback format supported");
1897 if (link->dpcd_caps.fallback_formats.bits.dp_1280x720_60Hz_24bpp_support)
1898 DC_LOG_DP2("\t1280x720@60Hz 24bpp fallback format supported");
1899 if (link->dpcd_caps.fallback_formats.bits.dp_1024x768_60Hz_24bpp_support)
1900 DC_LOG_DP2("\t1024x768@60Hz 24bpp fallback format supported");
1901 if (link->dpcd_caps.fallback_formats.raw == 0) {
1902 DC_LOG_DP2("\tno supported fallback formats, assume 1920x1080@60Hz 24bpp is supported");
1903 link->dpcd_caps.fallback_formats.bits.dp_1920x1080_60Hz_24bpp_support = 1;
1904 }
1905
1906 core_link_read_dpcd(link,
1907 DP_FEC_CAPABILITY_1,
1908 &link->dpcd_caps.fec_cap1.raw,
1909 sizeof(link->dpcd_caps.fec_cap1.raw));
1910 DC_LOG_DP2("FEC CAPABILITY 1 is read at link %d", link->link_index);
1911 if (link->dpcd_caps.fec_cap1.bits.AGGREGATED_ERROR_COUNTERS_CAPABLE)
1912 DC_LOG_DP2("\tFEC aggregated error counters are supported");
1913 }
1914
1915 retrieve_cable_id(link);
1916 dpcd_write_cable_id_to_dprx(link);
1917
1918 /* Connectivity log: detection */
1919 CONN_DATA_DETECT(link, dpcd_data, sizeof(dpcd_data), "Rx Caps: ");
1920
1921 return true;
1922 }
1923
detect_dp_sink_caps(struct dc_link * link)1924 bool detect_dp_sink_caps(struct dc_link *link)
1925 {
1926 return retrieve_link_cap(link);
1927 }
1928
detect_edp_sink_caps(struct dc_link * link)1929 void detect_edp_sink_caps(struct dc_link *link)
1930 {
1931 uint8_t supported_link_rates[16];
1932 uint32_t entry;
1933 uint32_t link_rate_in_khz;
1934 enum dc_link_rate link_rate = LINK_RATE_UNKNOWN;
1935 uint8_t backlight_adj_cap;
1936 uint8_t general_edp_cap;
1937
1938 retrieve_link_cap(link);
1939 link->dpcd_caps.edp_supported_link_rates_count = 0;
1940 memset(supported_link_rates, 0, sizeof(supported_link_rates));
1941
1942 /*
1943 * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
1944 * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
1945 */
1946 if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_13) {
1947 // Read DPCD 00010h - 0001Fh 16 bytes at one shot
1948 core_link_read_dpcd(link, DP_SUPPORTED_LINK_RATES,
1949 supported_link_rates, sizeof(supported_link_rates));
1950
1951 for (entry = 0; entry < 16; entry += 2) {
1952 // DPCD register reports per-lane link rate = 16-bit link rate capability
1953 // value X 200 kHz. Need multiplier to find link rate in kHz.
1954 link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
1955 supported_link_rates[entry]) * 200;
1956
1957 DC_LOG_DC("%s: eDP v1.4 supported sink rates: [%d] %d kHz\n", __func__,
1958 entry / 2, link_rate_in_khz);
1959
1960 if (link_rate_in_khz != 0) {
1961 link_rate = linkRateInKHzToLinkRateMultiplier(link_rate_in_khz);
1962 link->dpcd_caps.edp_supported_link_rates[link->dpcd_caps.edp_supported_link_rates_count] = link_rate;
1963 link->dpcd_caps.edp_supported_link_rates_count++;
1964 }
1965 }
1966 }
1967
1968 core_link_read_dpcd(link, DP_EDP_BACKLIGHT_ADJUSTMENT_CAP,
1969 &backlight_adj_cap, sizeof(backlight_adj_cap));
1970
1971 link->dpcd_caps.dynamic_backlight_capable_edp =
1972 (backlight_adj_cap & DP_EDP_DYNAMIC_BACKLIGHT_CAP) ? true:false;
1973
1974 core_link_read_dpcd(link, DP_EDP_GENERAL_CAP_1,
1975 &general_edp_cap, sizeof(general_edp_cap));
1976
1977 link->dpcd_caps.set_power_state_capable_edp =
1978 (general_edp_cap & DP_EDP_SET_POWER_CAP) ? true:false;
1979
1980 set_default_brightness_aux(link);
1981
1982 core_link_read_dpcd(link, DP_EDP_DPCD_REV,
1983 &link->dpcd_caps.edp_rev,
1984 sizeof(link->dpcd_caps.edp_rev));
1985 /*
1986 * PSR is only valid for eDP v1.3 or higher.
1987 */
1988 if (link->dpcd_caps.edp_rev >= DP_EDP_13) {
1989 core_link_read_dpcd(link, DP_PSR_SUPPORT,
1990 &link->dpcd_caps.psr_info.psr_version,
1991 sizeof(link->dpcd_caps.psr_info.psr_version));
1992 if (link->dpcd_caps.sink_dev_id == DP_BRANCH_DEVICE_ID_001CF8)
1993 core_link_read_dpcd(link, DP_FORCE_PSRSU_CAPABILITY,
1994 &link->dpcd_caps.psr_info.force_psrsu_cap,
1995 sizeof(link->dpcd_caps.psr_info.force_psrsu_cap));
1996 core_link_read_dpcd(link, DP_PSR_CAPS,
1997 &link->dpcd_caps.psr_info.psr_dpcd_caps.raw,
1998 sizeof(link->dpcd_caps.psr_info.psr_dpcd_caps.raw));
1999 if (link->dpcd_caps.psr_info.psr_dpcd_caps.bits.Y_COORDINATE_REQUIRED) {
2000 core_link_read_dpcd(link, DP_PSR2_SU_Y_GRANULARITY,
2001 &link->dpcd_caps.psr_info.psr2_su_y_granularity_cap,
2002 sizeof(link->dpcd_caps.psr_info.psr2_su_y_granularity_cap));
2003 }
2004 }
2005
2006 /*
2007 * ALPM is only valid for eDP v1.4 or higher.
2008 */
2009 if (link->dpcd_caps.dpcd_rev.raw >= DP_EDP_14)
2010 core_link_read_dpcd(link, DP_RECEIVER_ALPM_CAP,
2011 &link->dpcd_caps.alpm_caps.raw,
2012 sizeof(link->dpcd_caps.alpm_caps.raw));
2013
2014 /*
2015 * Read REPLAY info
2016 */
2017 core_link_read_dpcd(link, DP_SINK_PR_PIXEL_DEVIATION_PER_LINE,
2018 &link->dpcd_caps.pr_info.pixel_deviation_per_line,
2019 sizeof(link->dpcd_caps.pr_info.pixel_deviation_per_line));
2020 core_link_read_dpcd(link, DP_SINK_PR_MAX_NUMBER_OF_DEVIATION_LINE,
2021 &link->dpcd_caps.pr_info.max_deviation_line,
2022 sizeof(link->dpcd_caps.pr_info.max_deviation_line));
2023 }
2024
dp_get_max_link_enc_cap(const struct dc_link * link,struct dc_link_settings * max_link_enc_cap)2025 bool dp_get_max_link_enc_cap(const struct dc_link *link, struct dc_link_settings *max_link_enc_cap)
2026 {
2027 struct link_encoder *link_enc = NULL;
2028
2029 if (!max_link_enc_cap) {
2030 DC_LOG_ERROR("%s: Could not return max link encoder caps", __func__);
2031 return false;
2032 }
2033
2034 link_enc = link_enc_cfg_get_link_enc(link);
2035 ASSERT(link_enc);
2036
2037 if (link_enc && link_enc->funcs->get_max_link_cap) {
2038 link_enc->funcs->get_max_link_cap(link_enc, max_link_enc_cap);
2039 return true;
2040 }
2041
2042 DC_LOG_ERROR("%s: Max link encoder caps unknown", __func__);
2043 max_link_enc_cap->lane_count = 1;
2044 max_link_enc_cap->link_rate = 6;
2045 return false;
2046 }
2047
dp_get_verified_link_cap(const struct dc_link * link)2048 const struct dc_link_settings *dp_get_verified_link_cap(
2049 const struct dc_link *link)
2050 {
2051 if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
2052 link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
2053 return &link->preferred_link_setting;
2054 return &link->verified_link_cap;
2055 }
2056
dp_get_max_link_cap(struct dc_link * link)2057 struct dc_link_settings dp_get_max_link_cap(struct dc_link *link)
2058 {
2059 struct dc_link_settings max_link_cap = {0};
2060 enum dc_link_rate lttpr_max_link_rate;
2061 enum dc_link_rate cable_max_link_rate;
2062 struct link_encoder *link_enc = NULL;
2063
2064
2065 link_enc = link_enc_cfg_get_link_enc(link);
2066 ASSERT(link_enc);
2067
2068 /* get max link encoder capability */
2069 if (link_enc)
2070 link_enc->funcs->get_max_link_cap(link_enc, &max_link_cap);
2071
2072 /* Lower link settings based on sink's link cap */
2073 if (link->reported_link_cap.lane_count < max_link_cap.lane_count)
2074 max_link_cap.lane_count =
2075 link->reported_link_cap.lane_count;
2076 if (link->reported_link_cap.link_rate < max_link_cap.link_rate)
2077 max_link_cap.link_rate =
2078 link->reported_link_cap.link_rate;
2079 if (link->reported_link_cap.link_spread <
2080 max_link_cap.link_spread)
2081 max_link_cap.link_spread =
2082 link->reported_link_cap.link_spread;
2083
2084 /* Lower link settings based on cable attributes
2085 * Cable ID is a DP2 feature to identify max certified link rate that
2086 * a cable can carry. The cable identification method requires both
2087 * cable and display hardware support. Since the specs comes late, it is
2088 * anticipated that the first round of DP2 cables and displays may not
2089 * be fully compatible to reliably return cable ID data. Therefore the
2090 * decision of our cable id policy is that if the cable can return non
2091 * zero cable id data, we will take cable's link rate capability into
2092 * account. However if we get zero data, the cable link rate capability
2093 * is considered inconclusive. In this case, we will not take cable's
2094 * capability into account to avoid of over limiting hardware capability
2095 * from users. The max overall link rate capability is still determined
2096 * after actual dp pre-training. Cable id is considered as an auxiliary
2097 * method of determining max link bandwidth capability.
2098 */
2099 cable_max_link_rate = get_cable_max_link_rate(link);
2100
2101 if (!link->dc->debug.ignore_cable_id &&
2102 cable_max_link_rate != LINK_RATE_UNKNOWN &&
2103 cable_max_link_rate < max_link_cap.link_rate)
2104 max_link_cap.link_rate = cable_max_link_rate;
2105
2106 /* account for lttpr repeaters cap
2107 * notes: repeaters do not snoop in the DPRX Capabilities addresses (3.6.3).
2108 */
2109 if (dp_is_lttpr_present(link)) {
2110 if (link->dpcd_caps.lttpr_caps.max_lane_count < max_link_cap.lane_count)
2111 max_link_cap.lane_count = link->dpcd_caps.lttpr_caps.max_lane_count;
2112 lttpr_max_link_rate = get_lttpr_max_link_rate(link);
2113
2114 if (lttpr_max_link_rate < max_link_cap.link_rate)
2115 max_link_cap.link_rate = lttpr_max_link_rate;
2116
2117 DC_LOG_HW_LINK_TRAINING("%s\n Training with LTTPR, max_lane count %d max_link rate %d \n",
2118 __func__,
2119 max_link_cap.lane_count,
2120 max_link_cap.link_rate);
2121 }
2122
2123 if (link_dp_get_encoding_format(&max_link_cap) == DP_128b_132b_ENCODING &&
2124 link->dc->debug.disable_uhbr)
2125 max_link_cap.link_rate = LINK_RATE_HIGH3;
2126
2127 return max_link_cap;
2128 }
2129
dp_verify_link_cap(struct dc_link * link,struct dc_link_settings * known_limit_link_setting,int * fail_count)2130 static bool dp_verify_link_cap(
2131 struct dc_link *link,
2132 struct dc_link_settings *known_limit_link_setting,
2133 int *fail_count)
2134 {
2135 struct dc_link_settings cur_link_settings = {0};
2136 struct dc_link_settings max_link_settings = *known_limit_link_setting;
2137 bool success = false;
2138 bool skip_video_pattern;
2139 enum clock_source_id dp_cs_id = get_clock_source_id(link);
2140 enum link_training_result status = LINK_TRAINING_SUCCESS;
2141 union hpd_irq_data irq_data;
2142 struct link_resource link_res;
2143
2144 memset(&irq_data, 0, sizeof(irq_data));
2145 cur_link_settings = max_link_settings;
2146
2147 /* Grant extended timeout request */
2148 if (dp_is_lttpr_present(link) && link->dpcd_caps.lttpr_caps.max_ext_timeout > 0) {
2149 uint8_t grant = link->dpcd_caps.lttpr_caps.max_ext_timeout & 0x80;
2150
2151 core_link_write_dpcd(link, DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT, &grant, sizeof(grant));
2152 }
2153
2154 do {
2155 if (!get_temp_dp_link_res(link, &link_res, &cur_link_settings))
2156 continue;
2157
2158 skip_video_pattern = cur_link_settings.link_rate != LINK_RATE_LOW;
2159 dp_enable_link_phy(
2160 link,
2161 &link_res,
2162 link->connector_signal,
2163 dp_cs_id,
2164 &cur_link_settings);
2165
2166 status = dp_perform_link_training(
2167 link,
2168 &link_res,
2169 &cur_link_settings,
2170 skip_video_pattern);
2171
2172 if (status == LINK_TRAINING_SUCCESS) {
2173 success = true;
2174 fsleep(1000);
2175 if (dp_read_hpd_rx_irq_data(link, &irq_data) == DC_OK &&
2176 dp_parse_link_loss_status(
2177 link,
2178 &irq_data))
2179 (*fail_count)++;
2180 } else if (status == LINK_TRAINING_LINK_LOSS) {
2181 success = true;
2182 (*fail_count)++;
2183 } else {
2184 (*fail_count)++;
2185 }
2186 dp_trace_lt_total_count_increment(link, true);
2187 dp_trace_lt_result_update(link, status, true);
2188 dp_disable_link_phy(link, &link_res, link->connector_signal);
2189 } while (!success && decide_fallback_link_setting(link,
2190 &max_link_settings, &cur_link_settings, status));
2191
2192 link->verified_link_cap = success ?
2193 cur_link_settings : fail_safe_link_settings;
2194 return success;
2195 }
2196
dp_verify_link_cap_with_retries(struct dc_link * link,struct dc_link_settings * known_limit_link_setting,int attempts)2197 bool dp_verify_link_cap_with_retries(
2198 struct dc_link *link,
2199 struct dc_link_settings *known_limit_link_setting,
2200 int attempts)
2201 {
2202 int i = 0;
2203 bool success = false;
2204 int fail_count = 0;
2205 struct dc_link_settings last_verified_link_cap = fail_safe_link_settings;
2206
2207 dp_trace_detect_lt_init(link);
2208
2209 if (link->link_enc && link->link_enc->features.flags.bits.DP_IS_USB_C &&
2210 link->dc->debug.usbc_combo_phy_reset_wa)
2211 apply_usbc_combo_phy_reset_wa(link, known_limit_link_setting);
2212
2213 dp_trace_set_lt_start_timestamp(link, false);
2214 for (i = 0; i < attempts; i++) {
2215 enum dc_connection_type type = dc_connection_none;
2216
2217 memset(&link->verified_link_cap, 0,
2218 sizeof(struct dc_link_settings));
2219 if (!link_detect_connection_type(link, &type) || type == dc_connection_none) {
2220 link->verified_link_cap = fail_safe_link_settings;
2221 break;
2222 } else if (dp_verify_link_cap(link, known_limit_link_setting, &fail_count)) {
2223 last_verified_link_cap = link->verified_link_cap;
2224 if (fail_count == 0) {
2225 success = true;
2226 break;
2227 }
2228 } else {
2229 link->verified_link_cap = last_verified_link_cap;
2230 }
2231 fsleep(10 * 1000);
2232 }
2233
2234 dp_trace_lt_fail_count_update(link, fail_count, true);
2235 dp_trace_set_lt_end_timestamp(link, true);
2236
2237 return success;
2238 }
2239
2240 /*
2241 * Check if there is a native DP or passive DP-HDMI dongle connected
2242 */
dp_is_sink_present(struct dc_link * link)2243 bool dp_is_sink_present(struct dc_link *link)
2244 {
2245 enum gpio_result gpio_result;
2246 uint32_t clock_pin = 0;
2247 uint8_t retry = 0;
2248 struct ddc *ddc;
2249
2250 enum connector_id connector_id =
2251 dal_graphics_object_id_get_connector_id(link->link_id);
2252
2253 bool present =
2254 ((connector_id == CONNECTOR_ID_DISPLAY_PORT) ||
2255 (connector_id == CONNECTOR_ID_EDP) ||
2256 (connector_id == CONNECTOR_ID_USBC));
2257
2258 ddc = get_ddc_pin(link->ddc);
2259
2260 if (!ddc) {
2261 BREAK_TO_DEBUGGER();
2262 return present;
2263 }
2264
2265 /* Open GPIO and set it to I2C mode */
2266 /* Note: this GpioMode_Input will be converted
2267 * to GpioConfigType_I2cAuxDualMode in GPIO component,
2268 * which indicates we need additional delay
2269 */
2270
2271 if (dal_ddc_open(ddc, GPIO_MODE_INPUT,
2272 GPIO_DDC_CONFIG_TYPE_MODE_I2C) != GPIO_RESULT_OK) {
2273 dal_ddc_close(ddc);
2274
2275 return present;
2276 }
2277
2278 /*
2279 * Read GPIO: DP sink is present if both clock and data pins are zero
2280 *
2281 * [W/A] plug-unplug DP cable, sometimes customer board has
2282 * one short pulse on clk_pin(1V, < 1ms). DP will be config to HDMI/DVI
2283 * then monitor can't br light up. Add retry 3 times
2284 * But in real passive dongle, it need additional 3ms to detect
2285 */
2286 do {
2287 gpio_result = dal_gpio_get_value(ddc->pin_clock, &clock_pin);
2288 ASSERT(gpio_result == GPIO_RESULT_OK);
2289 if (clock_pin)
2290 fsleep(1000);
2291 else
2292 break;
2293 } while (retry++ < 3);
2294
2295 present = (gpio_result == GPIO_RESULT_OK) && !clock_pin;
2296
2297 dal_ddc_close(ddc);
2298
2299 return present;
2300 }
2301