2 * Copyright 2012-15 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <linux/slab.h>
28 #include "dm_services.h"
29 #include "atomfirmware.h"
30 #include "dm_helpers.h"
32 #include "grph_object_id.h"
33 #include "gpio_service_interface.h"
34 #include "core_status.h"
35 #include "dc_link_dp.h"
36 #include "dc_link_ddc.h"
37 #include "link_hwss.h"
40 #include "link_encoder.h"
41 #include "hw_sequencer.h"
44 #include "fixed31_32.h"
45 #include "dpcd_defs.h"
47 #include "hw/clk_mgr.h"
48 #include "dce/dmub_psr.h"
49 #include "dmub/dmub_srv.h"
50 #include "inc/hw/panel_cntl.h"
52 #define DC_LOGGER_INIT(logger)
54 #define LINK_INFO(...) \
58 #define RETIMER_REDRIVER_INFO(...) \
59 DC_LOG_RETIMER_REDRIVER( \
61 /*******************************************************************************
63 ******************************************************************************/
66 PEAK_FACTOR_X1000 = 1006,
68 * Some receivers fail to train on first try and are good
69 * on subsequent tries. 2 retries should be plenty. If we
70 * don't have a successful training then we don't expect to
73 LINK_TRAINING_MAX_VERIFY_RETRY = 2
76 /*******************************************************************************
78 ******************************************************************************/
79 static void dc_link_destruct(struct dc_link *link)
84 dal_gpio_destroy_irq(&link->hpd_gpio);
85 link->hpd_gpio = NULL;
89 dal_ddc_service_destroy(&link->ddc);
92 link->panel_cntl->funcs->destroy(&link->panel_cntl);
95 link->link_enc->funcs->destroy(&link->link_enc);
98 dc_sink_release(link->local_sink);
100 for (i = 0; i < link->sink_count; ++i)
101 dc_sink_release(link->remote_sinks[i]);
104 struct gpio *get_hpd_gpio(struct dc_bios *dcb,
105 struct graphics_object_id link_id,
106 struct gpio_service *gpio_service)
108 enum bp_result bp_result;
109 struct graphics_object_hpd_info hpd_info;
110 struct gpio_pin_info pin_info;
112 if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
115 bp_result = dcb->funcs->get_gpio_pin_info(dcb,
116 hpd_info.hpd_int_gpio_uid, &pin_info);
118 if (bp_result != BP_RESULT_OK) {
119 ASSERT(bp_result == BP_RESULT_NORECORD);
123 return dal_gpio_service_create_irq(gpio_service,
129 * Function: program_hpd_filter
132 * Programs HPD filter on associated HPD line
134 * @param [in] delay_on_connect_in_ms: Connect filter timeout
135 * @param [in] delay_on_disconnect_in_ms: Disconnect filter timeout
138 * true on success, false otherwise
140 static bool program_hpd_filter(const struct dc_link *link)
144 int delay_on_connect_in_ms = 0;
145 int delay_on_disconnect_in_ms = 0;
147 if (link->is_hpd_filter_disabled)
149 /* Verify feature is supported */
150 switch (link->connector_signal) {
151 case SIGNAL_TYPE_DVI_SINGLE_LINK:
152 case SIGNAL_TYPE_DVI_DUAL_LINK:
153 case SIGNAL_TYPE_HDMI_TYPE_A:
154 /* Program hpd filter */
155 delay_on_connect_in_ms = 500;
156 delay_on_disconnect_in_ms = 100;
158 case SIGNAL_TYPE_DISPLAY_PORT:
159 case SIGNAL_TYPE_DISPLAY_PORT_MST:
160 /* Program hpd filter to allow DP signal to settle */
161 /* 500: not able to detect MST <-> SST switch as HPD is low for
162 * only 100ms on DELL U2413
163 * 0: some passive dongle still show aux mode instead of i2c
164 * 20-50: not enough to hide bouncing HPD with passive dongle.
165 * also see intermittent i2c read issues.
167 delay_on_connect_in_ms = 80;
168 delay_on_disconnect_in_ms = 0;
170 case SIGNAL_TYPE_LVDS:
171 case SIGNAL_TYPE_EDP:
173 /* Don't program hpd filter */
177 /* Obtain HPD handle */
178 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
179 link->ctx->gpio_service);
184 /* Setup HPD filtering */
185 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
186 struct gpio_hpd_config config;
188 config.delay_on_connect = delay_on_connect_in_ms;
189 config.delay_on_disconnect = delay_on_disconnect_in_ms;
191 dal_irq_setup_hpd_filter(hpd, &config);
197 ASSERT_CRITICAL(false);
200 /* Release HPD handle */
201 dal_gpio_destroy_irq(&hpd);
206 bool dc_link_wait_for_t12(struct dc_link *link)
208 if (link->connector_signal == SIGNAL_TYPE_EDP && link->dc->hwss.edp_wait_for_T12) {
209 link->dc->hwss.edp_wait_for_T12(link);
218 * dc_link_detect_sink() - Determine if there is a sink connected
220 * @link: pointer to the dc link
221 * @type: Returned connection type
222 * Does not detect downstream devices, such as MST sinks
223 * or display connected through active dongles
225 bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type)
227 uint32_t is_hpd_high = 0;
228 struct gpio *hpd_pin;
230 if (link->connector_signal == SIGNAL_TYPE_LVDS) {
231 *type = dc_connection_single;
235 if (link->connector_signal == SIGNAL_TYPE_EDP) {
236 /*in case it is not on*/
237 link->dc->hwss.edp_power_control(link, true);
238 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
241 /* todo: may need to lock gpio access */
242 hpd_pin = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
243 link->ctx->gpio_service);
245 goto hpd_gpio_failure;
247 dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
248 dal_gpio_get_value(hpd_pin, &is_hpd_high);
249 dal_gpio_close(hpd_pin);
250 dal_gpio_destroy_irq(&hpd_pin);
253 *type = dc_connection_single;
254 /* TODO: need to do the actual detection */
256 *type = dc_connection_none;
265 static enum ddc_transaction_type get_ddc_transaction_type(enum signal_type sink_signal)
267 enum ddc_transaction_type transaction_type = DDC_TRANSACTION_TYPE_NONE;
269 switch (sink_signal) {
270 case SIGNAL_TYPE_DVI_SINGLE_LINK:
271 case SIGNAL_TYPE_DVI_DUAL_LINK:
272 case SIGNAL_TYPE_HDMI_TYPE_A:
273 case SIGNAL_TYPE_LVDS:
274 case SIGNAL_TYPE_RGB:
275 transaction_type = DDC_TRANSACTION_TYPE_I2C;
278 case SIGNAL_TYPE_DISPLAY_PORT:
279 case SIGNAL_TYPE_EDP:
280 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
283 case SIGNAL_TYPE_DISPLAY_PORT_MST:
284 /* MST does not use I2COverAux, but there is the
285 * SPECIAL use case for "immediate dwnstrm device
286 * access" (EPR#370830).
288 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
295 return transaction_type;
298 static enum signal_type get_basic_signal_type(struct graphics_object_id encoder,
299 struct graphics_object_id downstream)
301 if (downstream.type == OBJECT_TYPE_CONNECTOR) {
302 switch (downstream.id) {
303 case CONNECTOR_ID_SINGLE_LINK_DVII:
304 switch (encoder.id) {
305 case ENCODER_ID_INTERNAL_DAC1:
306 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
307 case ENCODER_ID_INTERNAL_DAC2:
308 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
309 return SIGNAL_TYPE_RGB;
311 return SIGNAL_TYPE_DVI_SINGLE_LINK;
314 case CONNECTOR_ID_DUAL_LINK_DVII:
316 switch (encoder.id) {
317 case ENCODER_ID_INTERNAL_DAC1:
318 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
319 case ENCODER_ID_INTERNAL_DAC2:
320 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
321 return SIGNAL_TYPE_RGB;
323 return SIGNAL_TYPE_DVI_DUAL_LINK;
327 case CONNECTOR_ID_SINGLE_LINK_DVID:
328 return SIGNAL_TYPE_DVI_SINGLE_LINK;
329 case CONNECTOR_ID_DUAL_LINK_DVID:
330 return SIGNAL_TYPE_DVI_DUAL_LINK;
331 case CONNECTOR_ID_VGA:
332 return SIGNAL_TYPE_RGB;
333 case CONNECTOR_ID_HDMI_TYPE_A:
334 return SIGNAL_TYPE_HDMI_TYPE_A;
335 case CONNECTOR_ID_LVDS:
336 return SIGNAL_TYPE_LVDS;
337 case CONNECTOR_ID_DISPLAY_PORT:
338 return SIGNAL_TYPE_DISPLAY_PORT;
339 case CONNECTOR_ID_EDP:
340 return SIGNAL_TYPE_EDP;
342 return SIGNAL_TYPE_NONE;
344 } else if (downstream.type == OBJECT_TYPE_ENCODER) {
345 switch (downstream.id) {
346 case ENCODER_ID_EXTERNAL_NUTMEG:
347 case ENCODER_ID_EXTERNAL_TRAVIS:
348 return SIGNAL_TYPE_DISPLAY_PORT;
350 return SIGNAL_TYPE_NONE;
354 return SIGNAL_TYPE_NONE;
358 * dc_link_is_dp_sink_present() - Check if there is a native DP
359 * or passive DP-HDMI dongle connected
361 bool dc_link_is_dp_sink_present(struct dc_link *link)
363 enum gpio_result gpio_result;
364 uint32_t clock_pin = 0;
368 enum connector_id connector_id =
369 dal_graphics_object_id_get_connector_id(link->link_id);
372 ((connector_id == CONNECTOR_ID_DISPLAY_PORT) ||
373 (connector_id == CONNECTOR_ID_EDP));
375 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
382 /* Open GPIO and set it to I2C mode */
383 /* Note: this GpioMode_Input will be converted
384 * to GpioConfigType_I2cAuxDualMode in GPIO component,
385 * which indicates we need additional delay
388 if (dal_ddc_open(ddc, GPIO_MODE_INPUT,
389 GPIO_DDC_CONFIG_TYPE_MODE_I2C) != GPIO_RESULT_OK) {
396 * Read GPIO: DP sink is present if both clock and data pins are zero
398 * [W/A] plug-unplug DP cable, sometimes customer board has
399 * one short pulse on clk_pin(1V, < 1ms). DP will be config to HDMI/DVI
400 * then monitor can't br light up. Add retry 3 times
401 * But in real passive dongle, it need additional 3ms to detect
404 gpio_result = dal_gpio_get_value(ddc->pin_clock, &clock_pin);
405 ASSERT(gpio_result == GPIO_RESULT_OK);
410 } while (retry++ < 3);
412 present = (gpio_result == GPIO_RESULT_OK) && !clock_pin;
421 * Detect output sink type
423 static enum signal_type link_detect_sink(struct dc_link *link,
424 enum dc_detect_reason reason)
426 enum signal_type result = get_basic_signal_type(link->link_enc->id,
429 /* Internal digital encoder will detect only dongles
430 * that require digital signal
433 /* Detection mechanism is different
434 * for different native connectors.
435 * LVDS connector supports only LVDS signal;
436 * PCIE is a bus slot, the actual connector needs to be detected first;
437 * eDP connector supports only eDP signal;
438 * HDMI should check straps for audio
441 /* PCIE detects the actual connector on add-on board */
442 if (link->link_id.id == CONNECTOR_ID_PCIE) {
443 /* ZAZTODO implement PCIE add-on card detection */
446 switch (link->link_id.id) {
447 case CONNECTOR_ID_HDMI_TYPE_A: {
448 /* check audio support:
449 * if native HDMI is not supported, switch to DVI
451 struct audio_support *aud_support =
452 &link->dc->res_pool->audio_support;
454 if (!aud_support->hdmi_audio_native)
455 if (link->link_id.id == CONNECTOR_ID_HDMI_TYPE_A)
456 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
459 case CONNECTOR_ID_DISPLAY_PORT: {
460 /* DP HPD short pulse. Passive DP dongle will not
463 if (reason != DETECT_REASON_HPDRX) {
464 /* Check whether DP signal detected: if not -
465 * we assume signal is DVI; it could be corrected
466 * to HDMI after dongle detection
468 if (!dm_helpers_is_dp_sink_present(link))
469 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
480 static enum signal_type decide_signal_from_strap_and_dongle_type(enum display_dongle_type dongle_type,
481 struct audio_support *audio_support)
483 enum signal_type signal = SIGNAL_TYPE_NONE;
485 switch (dongle_type) {
486 case DISPLAY_DONGLE_DP_HDMI_DONGLE:
487 if (audio_support->hdmi_audio_on_dongle)
488 signal = SIGNAL_TYPE_HDMI_TYPE_A;
490 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
492 case DISPLAY_DONGLE_DP_DVI_DONGLE:
493 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
495 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE:
496 if (audio_support->hdmi_audio_native)
497 signal = SIGNAL_TYPE_HDMI_TYPE_A;
499 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
502 signal = SIGNAL_TYPE_NONE;
509 static enum signal_type dp_passive_dongle_detection(struct ddc_service *ddc,
510 struct display_sink_capability *sink_cap,
511 struct audio_support *audio_support)
513 dal_ddc_service_i2c_query_dp_dual_mode_adaptor(ddc, sink_cap);
515 return decide_signal_from_strap_and_dongle_type(sink_cap->dongle_type,
519 static void link_disconnect_sink(struct dc_link *link)
521 if (link->local_sink) {
522 dc_sink_release(link->local_sink);
523 link->local_sink = NULL;
526 link->dpcd_sink_count = 0;
529 static void link_disconnect_remap(struct dc_sink *prev_sink, struct dc_link *link)
531 dc_sink_release(link->local_sink);
532 link->local_sink = prev_sink;
535 #if defined(CONFIG_DRM_AMD_DC_HDCP)
536 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal)
541 case SIGNAL_TYPE_DISPLAY_PORT:
542 case SIGNAL_TYPE_DISPLAY_PORT_MST:
543 ret = link->hdcp_caps.bcaps.bits.HDCP_CAPABLE;
545 case SIGNAL_TYPE_DVI_SINGLE_LINK:
546 case SIGNAL_TYPE_DVI_DUAL_LINK:
547 case SIGNAL_TYPE_HDMI_TYPE_A:
548 /* HDMI doesn't tell us its HDCP(1.4) capability, so assume to always be capable,
549 * we can poll for bksv but some displays have an issue with this. Since its so rare
550 * for a display to not be 1.4 capable, this assumtion is ok
560 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal)
565 case SIGNAL_TYPE_DISPLAY_PORT:
566 case SIGNAL_TYPE_DISPLAY_PORT_MST:
567 ret = (link->hdcp_caps.bcaps.bits.HDCP_CAPABLE &&
568 link->hdcp_caps.rx_caps.fields.byte0.hdcp_capable &&
569 (link->hdcp_caps.rx_caps.fields.version == 0x2)) ? 1 : 0;
571 case SIGNAL_TYPE_DVI_SINGLE_LINK:
572 case SIGNAL_TYPE_DVI_DUAL_LINK:
573 case SIGNAL_TYPE_HDMI_TYPE_A:
574 ret = (link->hdcp_caps.rx_caps.fields.version == 0x4) ? 1:0;
583 static void query_hdcp_capability(enum signal_type signal, struct dc_link *link)
585 struct hdcp_protection_message msg22;
586 struct hdcp_protection_message msg14;
588 memset(&msg22, 0, sizeof(struct hdcp_protection_message));
589 memset(&msg14, 0, sizeof(struct hdcp_protection_message));
590 memset(link->hdcp_caps.rx_caps.raw, 0,
591 sizeof(link->hdcp_caps.rx_caps.raw));
593 if ((link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
594 link->ddc->transaction_type ==
595 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) ||
596 link->connector_signal == SIGNAL_TYPE_EDP) {
597 msg22.data = link->hdcp_caps.rx_caps.raw;
598 msg22.length = sizeof(link->hdcp_caps.rx_caps.raw);
599 msg22.msg_id = HDCP_MESSAGE_ID_RX_CAPS;
601 msg22.data = &link->hdcp_caps.rx_caps.fields.version;
602 msg22.length = sizeof(link->hdcp_caps.rx_caps.fields.version);
603 msg22.msg_id = HDCP_MESSAGE_ID_HDCP2VERSION;
605 msg22.version = HDCP_VERSION_22;
606 msg22.link = HDCP_LINK_PRIMARY;
607 msg22.max_retries = 5;
608 dc_process_hdcp_msg(signal, link, &msg22);
610 if (signal == SIGNAL_TYPE_DISPLAY_PORT || signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
611 msg14.data = &link->hdcp_caps.bcaps.raw;
612 msg14.length = sizeof(link->hdcp_caps.bcaps.raw);
613 msg14.msg_id = HDCP_MESSAGE_ID_READ_BCAPS;
614 msg14.version = HDCP_VERSION_14;
615 msg14.link = HDCP_LINK_PRIMARY;
616 msg14.max_retries = 5;
618 dc_process_hdcp_msg(signal, link, &msg14);
624 static void read_current_link_settings_on_detect(struct dc_link *link)
626 union lane_count_set lane_count_set = { {0} };
628 uint8_t link_rate_set;
629 uint32_t read_dpcd_retry_cnt = 10;
630 enum dc_status status = DC_ERROR_UNEXPECTED;
632 union max_down_spread max_down_spread = { {0} };
634 // Read DPCD 00101h to find out the number of lanes currently set
635 for (i = 0; i < read_dpcd_retry_cnt; i++) {
636 status = core_link_read_dpcd(link,
639 sizeof(lane_count_set));
640 /* First DPCD read after VDD ON can fail if the particular board
641 * does not have HPD pin wired correctly. So if DPCD read fails,
642 * which it should never happen, retry a few times. Target worst
643 * case scenario of 80 ms.
645 if (status == DC_OK) {
646 link->cur_link_settings.lane_count =
647 lane_count_set.bits.LANE_COUNT_SET;
654 // Read DPCD 00100h to find if standard link rates are set
655 core_link_read_dpcd(link, DP_LINK_BW_SET,
656 &link_bw_set, sizeof(link_bw_set));
658 if (link_bw_set == 0) {
659 if (link->connector_signal == SIGNAL_TYPE_EDP) {
660 /* If standard link rates are not being used,
661 * Read DPCD 00115h to find the edp link rate set used
663 core_link_read_dpcd(link, DP_LINK_RATE_SET,
664 &link_rate_set, sizeof(link_rate_set));
666 // edp_supported_link_rates_count = 0 for DP
667 if (link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
668 link->cur_link_settings.link_rate =
669 link->dpcd_caps.edp_supported_link_rates[link_rate_set];
670 link->cur_link_settings.link_rate_set = link_rate_set;
671 link->cur_link_settings.use_link_rate_set = true;
674 // Link Rate not found. Seamless boot may not work.
678 link->cur_link_settings.link_rate = link_bw_set;
679 link->cur_link_settings.use_link_rate_set = false;
681 // Read DPCD 00003h to find the max down spread.
682 core_link_read_dpcd(link, DP_MAX_DOWNSPREAD,
683 &max_down_spread.raw, sizeof(max_down_spread));
684 link->cur_link_settings.link_spread =
685 max_down_spread.bits.MAX_DOWN_SPREAD ?
686 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
689 static bool detect_dp(struct dc_link *link,
690 struct display_sink_capability *sink_caps,
691 bool *converter_disable_audio,
692 struct audio_support *audio_support,
693 enum dc_detect_reason reason)
697 sink_caps->signal = link_detect_sink(link, reason);
698 sink_caps->transaction_type =
699 get_ddc_transaction_type(sink_caps->signal);
701 if (sink_caps->transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
702 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
703 if (!detect_dp_sink_caps(link))
705 if (is_mst_supported(link)) {
706 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
707 link->type = dc_connection_mst_branch;
709 dal_ddc_service_set_transaction_type(link->ddc,
710 sink_caps->transaction_type);
712 #if defined(CONFIG_DRM_AMD_DC_HDCP)
713 /* In case of fallback to SST when topology discovery below fails
714 * HDCP caps will be querried again later by the upper layer (caller
715 * of this function). */
716 query_hdcp_capability(SIGNAL_TYPE_DISPLAY_PORT_MST, link);
719 * This call will initiate MST topology discovery. Which
720 * will detect MST ports and add new DRM connector DRM
721 * framework. Then read EDID via remote i2c over aux. In
722 * the end, will notify DRM detect result and save EDID
723 * into DRM framework.
725 * .detect is called by .fill_modes.
726 * .fill_modes is called by user mode ioctl
727 * DRM_IOCTL_MODE_GETCONNECTOR.
729 * .get_modes is called by .fill_modes.
731 * call .get_modes, AMDGPU DM implementation will create
732 * new dc_sink and add to dc_link. For long HPD plug
733 * in/out, MST has its own handle.
735 * Therefore, just after dc_create, link->sink is not
736 * created for MST until user mode app calls
737 * DRM_IOCTL_MODE_GETCONNECTOR.
739 * Need check ->sink usages in case ->sink = NULL
740 * TODO: s3 resume check
742 if (reason == DETECT_REASON_BOOT)
745 dm_helpers_dp_update_branch_info(link->ctx, link);
747 if (!dm_helpers_dp_mst_start_top_mgr(link->ctx,
749 /* MST not supported */
750 link->type = dc_connection_single;
751 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
755 if (link->type != dc_connection_mst_branch &&
756 is_dp_active_dongle(link)) {
757 /* DP active dongles */
758 link->type = dc_connection_active_dongle;
759 if (!link->dpcd_caps.sink_count.bits.SINK_COUNT) {
761 * active dongle unplug processing for short irq
763 link_disconnect_sink(link);
767 if (link->dpcd_caps.dongle_type !=
768 DISPLAY_DONGLE_DP_HDMI_CONVERTER)
769 *converter_disable_audio = true;
772 /* DP passive dongles */
773 sink_caps->signal = dp_passive_dongle_detection(link->ddc,
776 link->dpcd_caps.dongle_type = sink_caps->dongle_type;
782 static bool is_same_edid(struct dc_edid *old_edid, struct dc_edid *new_edid)
784 if (old_edid->length != new_edid->length)
787 if (new_edid->length == 0)
790 return (memcmp(old_edid->raw_edid,
791 new_edid->raw_edid, new_edid->length) == 0);
794 static bool wait_for_entering_dp_alt_mode(struct dc_link *link)
797 * something is terribly wrong if time out is > 200ms. (5Hz)
798 * 500 microseconds * 400 tries us 200 ms
800 unsigned int sleep_time_in_microseconds = 500;
801 unsigned int tries_allowed = 400;
803 unsigned long long enter_timestamp;
804 unsigned long long finish_timestamp;
805 unsigned long long time_taken_in_ns;
808 DC_LOGGER_INIT(link->ctx->logger);
810 if (!link->link_enc->funcs->is_in_alt_mode)
813 is_in_alt_mode = link->link_enc->funcs->is_in_alt_mode(link->link_enc);
814 DC_LOG_WARNING("DP Alt mode state on HPD: %d\n", is_in_alt_mode);
819 enter_timestamp = dm_get_timestamp(link->ctx);
821 for (tries_taken = 0; tries_taken < tries_allowed; tries_taken++) {
822 udelay(sleep_time_in_microseconds);
823 /* ask the link if alt mode is enabled, if so return ok */
824 if (link->link_enc->funcs->is_in_alt_mode(link->link_enc)) {
825 finish_timestamp = dm_get_timestamp(link->ctx);
827 dm_get_elapse_time_in_ns(link->ctx,
830 DC_LOG_WARNING("Alt mode entered finished after %llu ms\n",
831 div_u64(time_taken_in_ns, 1000000));
835 finish_timestamp = dm_get_timestamp(link->ctx);
836 time_taken_in_ns = dm_get_elapse_time_in_ns(link->ctx, finish_timestamp,
838 DC_LOG_WARNING("Alt mode has timed out after %llu ms\n",
839 div_u64(time_taken_in_ns, 1000000));
844 * dc_link_detect() - Detect if a sink is attached to a given link
846 * link->local_sink is created or destroyed as needed.
848 * This does not create remote sinks but will trigger DM
849 * to start MST detection if a branch is detected.
851 static bool dc_link_detect_helper(struct dc_link *link,
852 enum dc_detect_reason reason)
854 struct dc_sink_init_data sink_init_data = { 0 };
855 struct display_sink_capability sink_caps = { 0 };
857 bool converter_disable_audio = false;
858 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
859 bool same_edid = false;
860 enum dc_edid_status edid_status;
861 struct dc_context *dc_ctx = link->ctx;
862 struct dc_sink *sink = NULL;
863 struct dc_sink *prev_sink = NULL;
864 struct dpcd_caps prev_dpcd_caps;
865 bool same_dpcd = true;
866 enum dc_connection_type new_connection_type = dc_connection_none;
867 enum dc_connection_type pre_connection_type = dc_connection_none;
868 bool perform_dp_seamless_boot = false;
869 const uint32_t post_oui_delay = 30; // 30ms
871 DC_LOGGER_INIT(link->ctx->logger);
873 if (dc_is_virtual_signal(link->connector_signal))
876 if ((link->connector_signal == SIGNAL_TYPE_LVDS ||
877 link->connector_signal == SIGNAL_TYPE_EDP) &&
879 // need to re-write OUI and brightness in resume case
880 if (link->connector_signal == SIGNAL_TYPE_EDP) {
881 dpcd_set_source_specific_data(link);
882 msleep(post_oui_delay);
883 dc_link_set_default_brightness_aux(link);
890 if (!dc_link_detect_sink(link, &new_connection_type)) {
895 prev_sink = link->local_sink;
897 dc_sink_retain(prev_sink);
898 memcpy(&prev_dpcd_caps, &link->dpcd_caps, sizeof(struct dpcd_caps));
901 link_disconnect_sink(link);
902 if (new_connection_type != dc_connection_none) {
903 pre_connection_type = link->type;
904 link->type = new_connection_type;
905 link->link_state_valid = false;
907 /* From Disconnected-to-Connected. */
908 switch (link->connector_signal) {
909 case SIGNAL_TYPE_HDMI_TYPE_A: {
910 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
911 if (aud_support->hdmi_audio_native)
912 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A;
914 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
918 case SIGNAL_TYPE_DVI_SINGLE_LINK: {
919 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
920 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
924 case SIGNAL_TYPE_DVI_DUAL_LINK: {
925 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
926 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK;
930 case SIGNAL_TYPE_LVDS: {
931 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
932 sink_caps.signal = SIGNAL_TYPE_LVDS;
936 case SIGNAL_TYPE_EDP: {
937 read_current_link_settings_on_detect(link);
939 detect_edp_sink_caps(link);
940 read_current_link_settings_on_detect(link);
941 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
942 sink_caps.signal = SIGNAL_TYPE_EDP;
946 case SIGNAL_TYPE_DISPLAY_PORT: {
947 /* wa HPD high coming too early*/
948 if (link->link_enc->features.flags.bits.DP_IS_USB_C == 1) {
949 /* if alt mode times out, return false */
950 if (!wait_for_entering_dp_alt_mode(link))
954 if (!detect_dp(link, &sink_caps,
955 &converter_disable_audio,
956 aud_support, reason)) {
958 dc_sink_release(prev_sink);
962 // Check if dpcp block is the same
964 if (memcmp(&link->dpcd_caps, &prev_dpcd_caps,
965 sizeof(struct dpcd_caps)))
968 /* Active dongle downstream unplug*/
969 if (link->type == dc_connection_active_dongle &&
970 link->dpcd_caps.sink_count.bits.SINK_COUNT == 0) {
972 /* Downstream unplug */
973 dc_sink_release(prev_sink);
977 // link switch from MST to non-MST stop topology manager
978 if (pre_connection_type == dc_connection_mst_branch &&
979 link->type != dc_connection_mst_branch) {
980 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
983 if (link->type == dc_connection_mst_branch) {
984 LINK_INFO("link=%d, mst branch is now Connected\n",
986 /* Need to setup mst link_cap struct here
987 * otherwise dc_link_detect() will leave mst link_cap
988 * empty which leads to allocate_mst_payload() has "0"
989 * pbn_per_slot value leading to exception on dc_fixpt_div()
991 dp_verify_mst_link_cap(link);
994 dc_sink_release(prev_sink);
998 // For seamless boot, to skip verify link cap, we read UEFI settings and set them as verified.
999 if (reason == DETECT_REASON_BOOT &&
1000 !dc_ctx->dc->config.power_down_display_on_boot &&
1001 link->link_status.link_active)
1002 perform_dp_seamless_boot = true;
1004 if (perform_dp_seamless_boot) {
1005 read_current_link_settings_on_detect(link);
1006 link->verified_link_cap = link->reported_link_cap;
1013 DC_ERROR("Invalid connector type! signal:%d\n",
1014 link->connector_signal);
1016 dc_sink_release(prev_sink);
1020 if (link->dpcd_caps.sink_count.bits.SINK_COUNT)
1021 link->dpcd_sink_count =
1022 link->dpcd_caps.sink_count.bits.SINK_COUNT;
1024 link->dpcd_sink_count = 1;
1026 dal_ddc_service_set_transaction_type(link->ddc,
1027 sink_caps.transaction_type);
1030 dal_ddc_service_is_in_aux_transaction_mode(link->ddc);
1032 sink_init_data.link = link;
1033 sink_init_data.sink_signal = sink_caps.signal;
1035 sink = dc_sink_create(&sink_init_data);
1037 DC_ERROR("Failed to create sink!\n");
1039 dc_sink_release(prev_sink);
1043 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock;
1044 sink->converter_disable_audio = converter_disable_audio;
1046 /* dc_sink_create returns a new reference */
1047 link->local_sink = sink;
1049 edid_status = dm_helpers_read_local_edid(link->ctx,
1052 switch (edid_status) {
1053 case EDID_BAD_CHECKSUM:
1054 DC_LOG_ERROR("EDID checksum invalid.\n");
1056 case EDID_NO_RESPONSE:
1057 DC_LOG_ERROR("No EDID read.\n");
1059 * Abort detection for non-DP connectors if we have
1062 * DP needs to report as connected if HDP is high
1063 * even if we have no EDID in order to go to
1066 if (dc_is_hdmi_signal(link->connector_signal) ||
1067 dc_is_dvi_signal(link->connector_signal)) {
1069 dc_sink_release(prev_sink);
1078 // Check if edid is the same
1080 (edid_status == EDID_THE_SAME || edid_status == EDID_OK))
1081 same_edid = is_same_edid(&prev_sink->dc_edid,
1084 if (sink->edid_caps.panel_patch.skip_scdc_overwrite)
1085 link->ctx->dc->debug.hdmi20_disable = true;
1087 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
1088 sink_caps.transaction_type ==
1089 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
1091 * TODO debug why Dell 2413 doesn't like
1092 * two link trainings
1094 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1095 query_hdcp_capability(sink->sink_signal, link);
1098 // verify link cap for SST non-seamless boot
1099 if (!perform_dp_seamless_boot)
1100 dp_verify_link_cap_with_retries(link,
1101 &link->reported_link_cap,
1102 LINK_TRAINING_MAX_VERIFY_RETRY);
1104 // If edid is the same, then discard new sink and revert back to original sink
1106 link_disconnect_remap(prev_sink, link);
1110 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1111 query_hdcp_capability(sink->sink_signal, link);
1115 /* HDMI-DVI Dongle */
1116 if (sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A &&
1117 !sink->edid_caps.edid_hdmi)
1118 sink->sink_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1120 /* Connectivity log: detection */
1121 for (i = 0; i < sink->dc_edid.length / DC_EDID_BLOCK_SIZE; i++) {
1122 CONN_DATA_DETECT(link,
1123 &sink->dc_edid.raw_edid[i * DC_EDID_BLOCK_SIZE],
1125 "%s: [Block %d] ", sink->edid_caps.display_name, i);
1128 DC_LOG_DETECTION_EDID_PARSER("%s: "
1129 "manufacturer_id = %X, "
1131 "serial_number = %X, "
1132 "manufacture_week = %d, "
1133 "manufacture_year = %d, "
1134 "display_name = %s, "
1135 "speaker_flag = %d, "
1136 "audio_mode_count = %d\n",
1138 sink->edid_caps.manufacturer_id,
1139 sink->edid_caps.product_id,
1140 sink->edid_caps.serial_number,
1141 sink->edid_caps.manufacture_week,
1142 sink->edid_caps.manufacture_year,
1143 sink->edid_caps.display_name,
1144 sink->edid_caps.speaker_flags,
1145 sink->edid_caps.audio_mode_count);
1147 for (i = 0; i < sink->edid_caps.audio_mode_count; i++) {
1148 DC_LOG_DETECTION_EDID_PARSER("%s: mode number = %d, "
1149 "format_code = %d, "
1150 "channel_count = %d, "
1151 "sample_rate = %d, "
1152 "sample_size = %d\n",
1155 sink->edid_caps.audio_modes[i].format_code,
1156 sink->edid_caps.audio_modes[i].channel_count,
1157 sink->edid_caps.audio_modes[i].sample_rate,
1158 sink->edid_caps.audio_modes[i].sample_size);
1161 /* From Connected-to-Disconnected. */
1162 if (link->type == dc_connection_mst_branch) {
1163 LINK_INFO("link=%d, mst branch is now Disconnected\n",
1166 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
1168 link->mst_stream_alloc_table.stream_count = 0;
1169 memset(link->mst_stream_alloc_table.stream_allocations,
1171 sizeof(link->mst_stream_alloc_table.stream_allocations));
1174 link->type = dc_connection_none;
1175 sink_caps.signal = SIGNAL_TYPE_NONE;
1176 /* When we unplug a passive DP-HDMI dongle connection, dongle_max_pix_clk
1177 * is not cleared. If we emulate a DP signal on this connection, it thinks
1178 * the dongle is still there and limits the number of modes we can emulate.
1179 * Clear dongle_max_pix_clk on disconnect to fix this
1181 link->dongle_max_pix_clk = 0;
1184 LINK_INFO("link=%d, dc_sink_in=%p is now %s prev_sink=%p dpcd same=%d edid same=%d\n",
1185 link->link_index, sink,
1186 (sink_caps.signal ==
1187 SIGNAL_TYPE_NONE ? "Disconnected" : "Connected"),
1188 prev_sink, same_dpcd, same_edid);
1191 dc_sink_release(prev_sink);
1196 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
1198 const struct dc *dc = link->dc;
1201 /* get out of low power state */
1202 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
1204 ret = dc_link_detect_helper(link, reason);
1206 /* Go back to power optimized state */
1207 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
1212 bool dc_link_get_hpd_state(struct dc_link *dc_link)
1216 dal_gpio_lock_pin(dc_link->hpd_gpio);
1217 dal_gpio_get_value(dc_link->hpd_gpio, &state);
1218 dal_gpio_unlock_pin(dc_link->hpd_gpio);
1223 static enum hpd_source_id get_hpd_line(struct dc_link *link)
1226 enum hpd_source_id hpd_id = HPD_SOURCEID_UNKNOWN;
1228 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1229 link->ctx->gpio_service);
1232 switch (dal_irq_get_source(hpd)) {
1233 case DC_IRQ_SOURCE_HPD1:
1234 hpd_id = HPD_SOURCEID1;
1236 case DC_IRQ_SOURCE_HPD2:
1237 hpd_id = HPD_SOURCEID2;
1239 case DC_IRQ_SOURCE_HPD3:
1240 hpd_id = HPD_SOURCEID3;
1242 case DC_IRQ_SOURCE_HPD4:
1243 hpd_id = HPD_SOURCEID4;
1245 case DC_IRQ_SOURCE_HPD5:
1246 hpd_id = HPD_SOURCEID5;
1248 case DC_IRQ_SOURCE_HPD6:
1249 hpd_id = HPD_SOURCEID6;
1252 BREAK_TO_DEBUGGER();
1256 dal_gpio_destroy_irq(&hpd);
1262 static enum channel_id get_ddc_line(struct dc_link *link)
1265 enum channel_id channel = CHANNEL_ID_UNKNOWN;
1267 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
1270 switch (dal_ddc_get_line(ddc)) {
1271 case GPIO_DDC_LINE_DDC1:
1272 channel = CHANNEL_ID_DDC1;
1274 case GPIO_DDC_LINE_DDC2:
1275 channel = CHANNEL_ID_DDC2;
1277 case GPIO_DDC_LINE_DDC3:
1278 channel = CHANNEL_ID_DDC3;
1280 case GPIO_DDC_LINE_DDC4:
1281 channel = CHANNEL_ID_DDC4;
1283 case GPIO_DDC_LINE_DDC5:
1284 channel = CHANNEL_ID_DDC5;
1286 case GPIO_DDC_LINE_DDC6:
1287 channel = CHANNEL_ID_DDC6;
1289 case GPIO_DDC_LINE_DDC_VGA:
1290 channel = CHANNEL_ID_DDC_VGA;
1292 case GPIO_DDC_LINE_I2C_PAD:
1293 channel = CHANNEL_ID_I2C_PAD;
1296 BREAK_TO_DEBUGGER();
1304 static enum transmitter translate_encoder_to_transmitter(struct graphics_object_id encoder)
1306 switch (encoder.id) {
1307 case ENCODER_ID_INTERNAL_UNIPHY:
1308 switch (encoder.enum_id) {
1310 return TRANSMITTER_UNIPHY_A;
1312 return TRANSMITTER_UNIPHY_B;
1314 return TRANSMITTER_UNKNOWN;
1317 case ENCODER_ID_INTERNAL_UNIPHY1:
1318 switch (encoder.enum_id) {
1320 return TRANSMITTER_UNIPHY_C;
1322 return TRANSMITTER_UNIPHY_D;
1324 return TRANSMITTER_UNKNOWN;
1327 case ENCODER_ID_INTERNAL_UNIPHY2:
1328 switch (encoder.enum_id) {
1330 return TRANSMITTER_UNIPHY_E;
1332 return TRANSMITTER_UNIPHY_F;
1334 return TRANSMITTER_UNKNOWN;
1337 case ENCODER_ID_INTERNAL_UNIPHY3:
1338 switch (encoder.enum_id) {
1340 return TRANSMITTER_UNIPHY_G;
1342 return TRANSMITTER_UNKNOWN;
1345 case ENCODER_ID_EXTERNAL_NUTMEG:
1346 switch (encoder.enum_id) {
1348 return TRANSMITTER_NUTMEG_CRT;
1350 return TRANSMITTER_UNKNOWN;
1353 case ENCODER_ID_EXTERNAL_TRAVIS:
1354 switch (encoder.enum_id) {
1356 return TRANSMITTER_TRAVIS_CRT;
1358 return TRANSMITTER_TRAVIS_LCD;
1360 return TRANSMITTER_UNKNOWN;
1364 return TRANSMITTER_UNKNOWN;
1368 static bool dc_link_construct(struct dc_link *link,
1369 const struct link_init_data *init_params)
1372 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1373 struct dc_context *dc_ctx = init_params->ctx;
1374 struct encoder_init_data enc_init_data = { 0 };
1375 struct panel_cntl_init_data panel_cntl_init_data = { 0 };
1376 struct integrated_info *info;
1377 struct dc_bios *bios = init_params->dc->ctx->dc_bios;
1378 const struct dc_vbios_funcs *bp_funcs = bios->funcs;
1379 struct bp_disp_connector_caps_info disp_connect_caps_info = { 0 };
1381 DC_LOGGER_INIT(dc_ctx->logger);
1383 info = kzalloc(sizeof(*info), GFP_KERNEL);
1387 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1388 link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
1390 link->link_status.dpcd_caps = &link->dpcd_caps;
1392 link->dc = init_params->dc;
1394 link->link_index = init_params->link_index;
1396 memset(&link->preferred_training_settings, 0,
1397 sizeof(struct dc_link_training_overrides));
1398 memset(&link->preferred_link_setting, 0,
1399 sizeof(struct dc_link_settings));
1402 bios->funcs->get_connector_id(bios, init_params->connector_index);
1404 DC_LOG_DC("BIOS object table - link_id: %d", link->link_id.id);
1406 if (bios->funcs->get_disp_connector_caps_info) {
1407 bios->funcs->get_disp_connector_caps_info(bios, link->link_id, &disp_connect_caps_info);
1408 link->is_internal_display = disp_connect_caps_info.INTERNAL_DISPLAY;
1409 DC_LOG_DC("BIOS object table - is_internal_display: %d", link->is_internal_display);
1412 if (link->link_id.type != OBJECT_TYPE_CONNECTOR) {
1413 dm_output_to_console("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d! type %d expected %d\n",
1414 __func__, init_params->connector_index,
1415 link->link_id.type, OBJECT_TYPE_CONNECTOR);
1419 if (link->dc->res_pool->funcs->link_init)
1420 link->dc->res_pool->funcs->link_init(link);
1422 link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1423 link->ctx->gpio_service);
1425 if (link->hpd_gpio) {
1426 dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
1427 dal_gpio_unlock_pin(link->hpd_gpio);
1428 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
1430 DC_LOG_DC("BIOS object table - hpd_gpio id: %d", link->hpd_gpio->id);
1431 DC_LOG_DC("BIOS object table - hpd_gpio en: %d", link->hpd_gpio->en);
1434 switch (link->link_id.id) {
1435 case CONNECTOR_ID_HDMI_TYPE_A:
1436 link->connector_signal = SIGNAL_TYPE_HDMI_TYPE_A;
1439 case CONNECTOR_ID_SINGLE_LINK_DVID:
1440 case CONNECTOR_ID_SINGLE_LINK_DVII:
1441 link->connector_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1443 case CONNECTOR_ID_DUAL_LINK_DVID:
1444 case CONNECTOR_ID_DUAL_LINK_DVII:
1445 link->connector_signal = SIGNAL_TYPE_DVI_DUAL_LINK;
1447 case CONNECTOR_ID_DISPLAY_PORT:
1448 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1451 link->irq_source_hpd_rx =
1452 dal_irq_get_rx_source(link->hpd_gpio);
1455 case CONNECTOR_ID_EDP:
1456 link->connector_signal = SIGNAL_TYPE_EDP;
1458 if (link->hpd_gpio) {
1459 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1460 link->irq_source_hpd_rx =
1461 dal_irq_get_rx_source(link->hpd_gpio);
1465 case CONNECTOR_ID_LVDS:
1466 link->connector_signal = SIGNAL_TYPE_LVDS;
1469 DC_LOG_WARNING("Unsupported Connector type:%d!\n",
1474 /* TODO: #DAL3 Implement id to str function.*/
1475 LINK_INFO("Connector[%d] description:"
1477 init_params->connector_index,
1478 link->connector_signal);
1480 ddc_service_init_data.ctx = link->ctx;
1481 ddc_service_init_data.id = link->link_id;
1482 ddc_service_init_data.link = link;
1483 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1486 DC_ERROR("Failed to create ddc_service!\n");
1487 goto ddc_create_fail;
1490 if (!link->ddc->ddc_pin) {
1491 DC_ERROR("Failed to get I2C info for connector!\n");
1492 goto ddc_create_fail;
1496 dal_ddc_get_line(dal_ddc_service_get_ddc_pin(link->ddc));
1499 if (link->dc->res_pool->funcs->panel_cntl_create &&
1500 (link->link_id.id == CONNECTOR_ID_EDP ||
1501 link->link_id.id == CONNECTOR_ID_LVDS)) {
1502 panel_cntl_init_data.ctx = dc_ctx;
1503 panel_cntl_init_data.inst = 0;
1505 link->dc->res_pool->funcs->panel_cntl_create(
1506 &panel_cntl_init_data);
1508 if (link->panel_cntl == NULL) {
1509 DC_ERROR("Failed to create link panel_cntl!\n");
1510 goto panel_cntl_create_fail;
1514 enc_init_data.ctx = dc_ctx;
1515 bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0,
1516 &enc_init_data.encoder);
1517 enc_init_data.connector = link->link_id;
1518 enc_init_data.channel = get_ddc_line(link);
1519 enc_init_data.hpd_source = get_hpd_line(link);
1521 link->hpd_src = enc_init_data.hpd_source;
1523 enc_init_data.transmitter =
1524 translate_encoder_to_transmitter(enc_init_data.encoder);
1526 link->dc->res_pool->funcs->link_enc_create(&enc_init_data);
1528 if (!link->link_enc) {
1529 DC_ERROR("Failed to create link encoder!\n");
1530 goto link_enc_create_fail;
1533 DC_LOG_DC("BIOS object table - DP_IS_USB_C: %d", link->link_enc->features.flags.bits.DP_IS_USB_C);
1535 link->link_enc_hw_inst = link->link_enc->transmitter;
1537 for (i = 0; i < 4; i++) {
1538 if (bp_funcs->get_device_tag(dc_ctx->dc_bios,
1540 &link->device_tag) != BP_RESULT_OK) {
1541 DC_ERROR("Failed to find device tag!\n");
1542 goto device_tag_fail;
1545 /* Look for device tag that matches connector signal,
1546 * CRT for rgb, LCD for other supported signal tyes
1548 if (!bp_funcs->is_device_id_supported(dc_ctx->dc_bios,
1549 link->device_tag.dev_id))
1551 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_CRT &&
1552 link->connector_signal != SIGNAL_TYPE_RGB)
1554 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_LCD &&
1555 link->connector_signal == SIGNAL_TYPE_RGB)
1558 DC_LOG_DC("BIOS object table - device_tag.acpi_device: %d", link->device_tag.acpi_device);
1559 DC_LOG_DC("BIOS object table - device_tag.dev_id.device_type: %d", link->device_tag.dev_id.device_type);
1560 DC_LOG_DC("BIOS object table - device_tag.dev_id.enum_id: %d", link->device_tag.dev_id.enum_id);
1564 if (bios->integrated_info)
1565 memcpy(info, bios->integrated_info, sizeof(*info));
1567 /* Look for channel mapping corresponding to connector and device tag */
1568 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
1569 struct external_display_path *path =
1570 &info->ext_disp_conn_info.path[i];
1572 if (path->device_connector_id.enum_id == link->link_id.enum_id &&
1573 path->device_connector_id.id == link->link_id.id &&
1574 path->device_connector_id.type == link->link_id.type) {
1575 if (link->device_tag.acpi_device != 0 &&
1576 path->device_acpi_enum == link->device_tag.acpi_device) {
1577 link->ddi_channel_mapping = path->channel_mapping;
1578 link->chip_caps = path->caps;
1579 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1580 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1581 } else if (path->device_tag ==
1582 link->device_tag.dev_id.raw_device_tag) {
1583 link->ddi_channel_mapping = path->channel_mapping;
1584 link->chip_caps = path->caps;
1585 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1586 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1592 if (bios->funcs->get_atom_dc_golden_table)
1593 bios->funcs->get_atom_dc_golden_table(bios);
1596 * TODO check if GPIO programmed correctly
1598 * If GPIO isn't programmed correctly HPD might not rise or drain
1599 * fast enough, leading to bounces.
1601 program_hpd_filter(link);
1603 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
1605 DC_LOG_DC("BIOS object table - %s finished successfully.\n", __func__);
1608 link->link_enc->funcs->destroy(&link->link_enc);
1609 link_enc_create_fail:
1610 if (link->panel_cntl != NULL)
1611 link->panel_cntl->funcs->destroy(&link->panel_cntl);
1612 panel_cntl_create_fail:
1613 dal_ddc_service_destroy(&link->ddc);
1617 if (link->hpd_gpio) {
1618 dal_gpio_destroy_irq(&link->hpd_gpio);
1619 link->hpd_gpio = NULL;
1622 DC_LOG_DC("BIOS object table - %s failed.\n", __func__);
1628 /*******************************************************************************
1630 ******************************************************************************/
1631 struct dc_link *link_create(const struct link_init_data *init_params)
1633 struct dc_link *link =
1634 kzalloc(sizeof(*link), GFP_KERNEL);
1639 if (false == dc_link_construct(link, init_params))
1640 goto construct_fail;
1651 void link_destroy(struct dc_link **link)
1653 dc_link_destruct(*link);
1658 static void enable_stream_features(struct pipe_ctx *pipe_ctx)
1660 struct dc_stream_state *stream = pipe_ctx->stream;
1661 struct dc_link *link = stream->link;
1662 union down_spread_ctrl old_downspread;
1663 union down_spread_ctrl new_downspread;
1665 core_link_read_dpcd(link, DP_DOWNSPREAD_CTRL,
1666 &old_downspread.raw, sizeof(old_downspread));
1668 new_downspread.raw = old_downspread.raw;
1670 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1671 (stream->ignore_msa_timing_param) ? 1 : 0;
1673 if (new_downspread.raw != old_downspread.raw) {
1674 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
1675 &new_downspread.raw, sizeof(new_downspread));
1679 static enum dc_status enable_link_dp(struct dc_state *state,
1680 struct pipe_ctx *pipe_ctx)
1682 struct dc_stream_state *stream = pipe_ctx->stream;
1683 enum dc_status status;
1684 bool skip_video_pattern;
1685 struct dc_link *link = stream->link;
1686 struct dc_link_settings link_settings = {0};
1689 bool apply_seamless_boot_optimization = false;
1690 uint32_t bl_oled_enable_delay = 50; // in ms
1691 const uint32_t post_oui_delay = 30; // 30ms
1693 // check for seamless boot
1694 for (i = 0; i < state->stream_count; i++) {
1695 if (state->streams[i]->apply_seamless_boot_optimization) {
1696 apply_seamless_boot_optimization = true;
1701 /* get link settings for video mode timing */
1702 decide_link_settings(stream, &link_settings);
1704 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
1705 /*in case it is not on*/
1706 link->dc->hwss.edp_power_control(link, true);
1707 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
1710 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
1711 link_settings.link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
1712 if (state->clk_mgr && !apply_seamless_boot_optimization)
1713 state->clk_mgr->funcs->update_clocks(state->clk_mgr,
1716 // during mode switch we do DP_SET_POWER off then on, and OUI is lost
1717 dpcd_set_source_specific_data(link);
1718 if (link->dpcd_sink_ext_caps.raw != 0)
1719 msleep(post_oui_delay);
1721 skip_video_pattern = true;
1723 if (link_settings.link_rate == LINK_RATE_LOW)
1724 skip_video_pattern = false;
1726 if (perform_link_training_with_retries(&link_settings,
1728 LINK_TRAINING_ATTEMPTS,
1730 pipe_ctx->stream->signal)) {
1731 link->cur_link_settings = link_settings;
1734 status = DC_FAIL_DP_LINK_TRAINING;
1737 if (link->preferred_training_settings.fec_enable)
1738 fec_enable = *link->preferred_training_settings.fec_enable;
1742 dp_set_fec_enable(link, fec_enable);
1744 // during mode set we do DP_SET_POWER off then on, aux writes are lost
1745 if (link->dpcd_sink_ext_caps.bits.oled == 1 ||
1746 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1 ||
1747 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1) {
1748 dc_link_set_default_brightness_aux(link); // TODO: use cached if known
1749 if (link->dpcd_sink_ext_caps.bits.oled == 1)
1750 msleep(bl_oled_enable_delay);
1751 dc_link_backlight_enable_aux(link, true);
1757 static enum dc_status enable_link_edp(
1758 struct dc_state *state,
1759 struct pipe_ctx *pipe_ctx)
1761 enum dc_status status;
1763 status = enable_link_dp(state, pipe_ctx);
1768 static enum dc_status enable_link_dp_mst(
1769 struct dc_state *state,
1770 struct pipe_ctx *pipe_ctx)
1772 struct dc_link *link = pipe_ctx->stream->link;
1774 /* sink signal type after MST branch is MST. Multiple MST sinks
1775 * share one link. Link DP PHY is enable or training only once.
1777 if (link->link_status.link_active)
1780 /* clear payload table */
1781 dm_helpers_dp_mst_clear_payload_allocation_table(link->ctx, link);
1783 /* to make sure the pending down rep can be processed
1784 * before enabling the link
1786 dm_helpers_dp_mst_poll_pending_down_reply(link->ctx, link);
1788 /* set the sink to MST mode before enabling the link */
1789 dp_enable_mst_on_sink(link, true);
1791 return enable_link_dp(state, pipe_ctx);
1794 static bool get_ext_hdmi_settings(struct pipe_ctx *pipe_ctx,
1795 enum engine_id eng_id,
1796 struct ext_hdmi_settings *settings)
1798 bool result = false;
1800 struct integrated_info *integrated_info =
1801 pipe_ctx->stream->ctx->dc_bios->integrated_info;
1803 if (integrated_info == NULL)
1807 * Get retimer settings from sbios for passing SI eye test for DCE11
1808 * The setting values are varied based on board revision and port id
1809 * Therefore the setting values of each ports is passed by sbios.
1812 // Check if current bios contains ext Hdmi settings
1813 if (integrated_info->gpu_cap_info & 0x20) {
1815 case ENGINE_ID_DIGA:
1816 settings->slv_addr = integrated_info->dp0_ext_hdmi_slv_addr;
1817 settings->reg_num = integrated_info->dp0_ext_hdmi_6g_reg_num;
1818 settings->reg_num_6g = integrated_info->dp0_ext_hdmi_6g_reg_num;
1819 memmove(settings->reg_settings,
1820 integrated_info->dp0_ext_hdmi_reg_settings,
1821 sizeof(integrated_info->dp0_ext_hdmi_reg_settings));
1822 memmove(settings->reg_settings_6g,
1823 integrated_info->dp0_ext_hdmi_6g_reg_settings,
1824 sizeof(integrated_info->dp0_ext_hdmi_6g_reg_settings));
1827 case ENGINE_ID_DIGB:
1828 settings->slv_addr = integrated_info->dp1_ext_hdmi_slv_addr;
1829 settings->reg_num = integrated_info->dp1_ext_hdmi_6g_reg_num;
1830 settings->reg_num_6g = integrated_info->dp1_ext_hdmi_6g_reg_num;
1831 memmove(settings->reg_settings,
1832 integrated_info->dp1_ext_hdmi_reg_settings,
1833 sizeof(integrated_info->dp1_ext_hdmi_reg_settings));
1834 memmove(settings->reg_settings_6g,
1835 integrated_info->dp1_ext_hdmi_6g_reg_settings,
1836 sizeof(integrated_info->dp1_ext_hdmi_6g_reg_settings));
1839 case ENGINE_ID_DIGC:
1840 settings->slv_addr = integrated_info->dp2_ext_hdmi_slv_addr;
1841 settings->reg_num = integrated_info->dp2_ext_hdmi_6g_reg_num;
1842 settings->reg_num_6g = integrated_info->dp2_ext_hdmi_6g_reg_num;
1843 memmove(settings->reg_settings,
1844 integrated_info->dp2_ext_hdmi_reg_settings,
1845 sizeof(integrated_info->dp2_ext_hdmi_reg_settings));
1846 memmove(settings->reg_settings_6g,
1847 integrated_info->dp2_ext_hdmi_6g_reg_settings,
1848 sizeof(integrated_info->dp2_ext_hdmi_6g_reg_settings));
1851 case ENGINE_ID_DIGD:
1852 settings->slv_addr = integrated_info->dp3_ext_hdmi_slv_addr;
1853 settings->reg_num = integrated_info->dp3_ext_hdmi_6g_reg_num;
1854 settings->reg_num_6g = integrated_info->dp3_ext_hdmi_6g_reg_num;
1855 memmove(settings->reg_settings,
1856 integrated_info->dp3_ext_hdmi_reg_settings,
1857 sizeof(integrated_info->dp3_ext_hdmi_reg_settings));
1858 memmove(settings->reg_settings_6g,
1859 integrated_info->dp3_ext_hdmi_6g_reg_settings,
1860 sizeof(integrated_info->dp3_ext_hdmi_6g_reg_settings));
1867 if (result == true) {
1868 // Validate settings from bios integrated info table
1869 if (settings->slv_addr == 0)
1871 if (settings->reg_num > 9)
1873 if (settings->reg_num_6g > 3)
1876 for (i = 0; i < settings->reg_num; i++) {
1877 if (settings->reg_settings[i].i2c_reg_index > 0x20)
1881 for (i = 0; i < settings->reg_num_6g; i++) {
1882 if (settings->reg_settings_6g[i].i2c_reg_index > 0x20)
1891 static bool i2c_write(struct pipe_ctx *pipe_ctx,
1892 uint8_t address, uint8_t *buffer, uint32_t length)
1894 struct i2c_command cmd = {0};
1895 struct i2c_payload payload = {0};
1897 memset(&payload, 0, sizeof(payload));
1898 memset(&cmd, 0, sizeof(cmd));
1900 cmd.number_of_payloads = 1;
1901 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
1902 cmd.speed = pipe_ctx->stream->ctx->dc->caps.i2c_speed_in_khz;
1904 payload.address = address;
1905 payload.data = buffer;
1906 payload.length = length;
1907 payload.write = true;
1908 cmd.payloads = &payload;
1910 if (dm_helpers_submit_i2c(pipe_ctx->stream->ctx,
1911 pipe_ctx->stream->link, &cmd))
1917 static void write_i2c_retimer_setting(
1918 struct pipe_ctx *pipe_ctx,
1920 bool is_over_340mhz,
1921 struct ext_hdmi_settings *settings)
1923 uint8_t slave_address = (settings->slv_addr >> 1);
1925 const uint8_t apply_rx_tx_change = 0x4;
1926 uint8_t offset = 0xA;
1929 bool i2c_success = false;
1930 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1932 memset(&buffer, 0, sizeof(buffer));
1934 /* Start Ext-Hdmi programming*/
1936 for (i = 0; i < settings->reg_num; i++) {
1937 /* Apply 3G settings */
1938 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
1940 buffer[0] = settings->reg_settings[i].i2c_reg_index;
1941 buffer[1] = settings->reg_settings[i].i2c_reg_val;
1942 i2c_success = i2c_write(pipe_ctx, slave_address,
1943 buffer, sizeof(buffer));
1944 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1945 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
1946 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1949 goto i2c_write_fail;
1951 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1952 * needs to be set to 1 on every 0xA-0xC write.
1954 if (settings->reg_settings[i].i2c_reg_index == 0xA ||
1955 settings->reg_settings[i].i2c_reg_index == 0xB ||
1956 settings->reg_settings[i].i2c_reg_index == 0xC) {
1958 /* Query current value from offset 0xA */
1959 if (settings->reg_settings[i].i2c_reg_index == 0xA)
1960 value = settings->reg_settings[i].i2c_reg_val;
1963 dal_ddc_service_query_ddc_data(
1964 pipe_ctx->stream->link->ddc,
1965 slave_address, &offset, 1, &value, 1);
1967 goto i2c_write_fail;
1971 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1972 buffer[1] = value | apply_rx_tx_change;
1973 i2c_success = i2c_write(pipe_ctx, slave_address,
1974 buffer, sizeof(buffer));
1975 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1976 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1977 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1979 goto i2c_write_fail;
1984 /* Apply 3G settings */
1985 if (is_over_340mhz) {
1986 for (i = 0; i < settings->reg_num_6g; i++) {
1987 /* Apply 3G settings */
1988 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
1990 buffer[0] = settings->reg_settings_6g[i].i2c_reg_index;
1991 buffer[1] = settings->reg_settings_6g[i].i2c_reg_val;
1992 i2c_success = i2c_write(pipe_ctx, slave_address,
1993 buffer, sizeof(buffer));
1994 RETIMER_REDRIVER_INFO("above 340Mhz: retimer write to slave_address = 0x%x,\
1995 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1996 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1999 goto i2c_write_fail;
2001 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
2002 * needs to be set to 1 on every 0xA-0xC write.
2004 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA ||
2005 settings->reg_settings_6g[i].i2c_reg_index == 0xB ||
2006 settings->reg_settings_6g[i].i2c_reg_index == 0xC) {
2008 /* Query current value from offset 0xA */
2009 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA)
2010 value = settings->reg_settings_6g[i].i2c_reg_val;
2013 dal_ddc_service_query_ddc_data(
2014 pipe_ctx->stream->link->ddc,
2015 slave_address, &offset, 1, &value, 1);
2017 goto i2c_write_fail;
2021 /* Set APPLY_RX_TX_CHANGE bit to 1 */
2022 buffer[1] = value | apply_rx_tx_change;
2023 i2c_success = i2c_write(pipe_ctx, slave_address,
2024 buffer, sizeof(buffer));
2025 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2026 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2027 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2029 goto i2c_write_fail;
2036 /* Program additional settings if using 640x480 resolution */
2038 /* Write offset 0xFF to 0x01 */
2041 i2c_success = i2c_write(pipe_ctx, slave_address,
2042 buffer, sizeof(buffer));
2043 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2044 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2045 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2047 goto i2c_write_fail;
2049 /* Write offset 0x00 to 0x23 */
2052 i2c_success = i2c_write(pipe_ctx, slave_address,
2053 buffer, sizeof(buffer));
2054 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2055 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2056 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2058 goto i2c_write_fail;
2060 /* Write offset 0xff to 0x00 */
2063 i2c_success = i2c_write(pipe_ctx, slave_address,
2064 buffer, sizeof(buffer));
2065 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2066 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2067 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2069 goto i2c_write_fail;
2076 DC_LOG_DEBUG("Set retimer failed");
2079 static void write_i2c_default_retimer_setting(
2080 struct pipe_ctx *pipe_ctx,
2082 bool is_over_340mhz)
2084 uint8_t slave_address = (0xBA >> 1);
2086 bool i2c_success = false;
2087 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2089 memset(&buffer, 0, sizeof(buffer));
2091 /* Program Slave Address for tuning single integrity */
2092 /* Write offset 0x0A to 0x13 */
2095 i2c_success = i2c_write(pipe_ctx, slave_address,
2096 buffer, sizeof(buffer));
2097 RETIMER_REDRIVER_INFO("retimer writes default setting to slave_address = 0x%x,\
2098 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2099 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2101 goto i2c_write_fail;
2103 /* Write offset 0x0A to 0x17 */
2106 i2c_success = i2c_write(pipe_ctx, slave_address,
2107 buffer, sizeof(buffer));
2108 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2109 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2110 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2112 goto i2c_write_fail;
2114 /* Write offset 0x0B to 0xDA or 0xD8 */
2116 buffer[1] = is_over_340mhz ? 0xDA : 0xD8;
2117 i2c_success = i2c_write(pipe_ctx, slave_address,
2118 buffer, sizeof(buffer));
2119 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2120 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2121 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2123 goto i2c_write_fail;
2125 /* Write offset 0x0A to 0x17 */
2128 i2c_success = i2c_write(pipe_ctx, slave_address,
2129 buffer, sizeof(buffer));
2130 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2131 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2132 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2134 goto i2c_write_fail;
2136 /* Write offset 0x0C to 0x1D or 0x91 */
2138 buffer[1] = is_over_340mhz ? 0x1D : 0x91;
2139 i2c_success = i2c_write(pipe_ctx, slave_address,
2140 buffer, sizeof(buffer));
2141 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2142 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2143 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2145 goto i2c_write_fail;
2147 /* Write offset 0x0A to 0x17 */
2150 i2c_success = i2c_write(pipe_ctx, slave_address,
2151 buffer, sizeof(buffer));
2152 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2153 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2154 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2156 goto i2c_write_fail;
2160 /* Program additional settings if using 640x480 resolution */
2162 /* Write offset 0xFF to 0x01 */
2165 i2c_success = i2c_write(pipe_ctx, slave_address,
2166 buffer, sizeof(buffer));
2167 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2168 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2169 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2171 goto i2c_write_fail;
2173 /* Write offset 0x00 to 0x23 */
2176 i2c_success = i2c_write(pipe_ctx, slave_address,
2177 buffer, sizeof(buffer));
2178 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2179 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2180 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2182 goto i2c_write_fail;
2184 /* Write offset 0xff to 0x00 */
2187 i2c_success = i2c_write(pipe_ctx, slave_address,
2188 buffer, sizeof(buffer));
2189 RETIMER_REDRIVER_INFO("retimer write default setting to slave_addr = 0x%x,\
2190 offset = 0x%x, reg_val= 0x%x, i2c_success = %d end here\n",
2191 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2193 goto i2c_write_fail;
2199 DC_LOG_DEBUG("Set default retimer failed");
2202 static void write_i2c_redriver_setting(
2203 struct pipe_ctx *pipe_ctx,
2204 bool is_over_340mhz)
2206 uint8_t slave_address = (0xF0 >> 1);
2208 bool i2c_success = false;
2209 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2211 memset(&buffer, 0, sizeof(buffer));
2213 // Program Slave Address for tuning single integrity
2217 buffer[6] = is_over_340mhz ? 0x4E : 0x4A;
2219 i2c_success = i2c_write(pipe_ctx, slave_address,
2220 buffer, sizeof(buffer));
2221 RETIMER_REDRIVER_INFO("redriver write 0 to all 16 reg offset expect following:\n\
2222 \t slave_addr = 0x%x, offset[3] = 0x%x, offset[4] = 0x%x,\
2223 offset[5] = 0x%x,offset[6] is_over_340mhz = 0x%x,\
2224 i2c_success = %d\n",
2225 slave_address, buffer[3], buffer[4], buffer[5], buffer[6], i2c_success?1:0);
2228 DC_LOG_DEBUG("Set redriver failed");
2231 static void disable_link(struct dc_link *link, enum signal_type signal)
2234 * TODO: implement call for dp_set_hw_test_pattern
2235 * it is needed for compliance testing
2238 /* Here we need to specify that encoder output settings
2239 * need to be calculated as for the set mode,
2240 * it will lead to querying dynamic link capabilities
2241 * which should be done before enable output
2244 if (dc_is_dp_signal(signal)) {
2246 if (dc_is_dp_sst_signal(signal))
2247 dp_disable_link_phy(link, signal);
2249 dp_disable_link_phy_mst(link, signal);
2251 if (dc_is_dp_sst_signal(signal) ||
2252 link->mst_stream_alloc_table.stream_count == 0) {
2253 dp_set_fec_enable(link, false);
2254 dp_set_fec_ready(link, false);
2257 if (signal != SIGNAL_TYPE_VIRTUAL)
2258 link->link_enc->funcs->disable_output(link->link_enc, signal);
2261 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2262 /* MST disable link only when no stream use the link */
2263 if (link->mst_stream_alloc_table.stream_count <= 0)
2264 link->link_status.link_active = false;
2266 link->link_status.link_active = false;
2270 static void enable_link_hdmi(struct pipe_ctx *pipe_ctx)
2272 struct dc_stream_state *stream = pipe_ctx->stream;
2273 struct dc_link *link = stream->link;
2274 enum dc_color_depth display_color_depth;
2275 enum engine_id eng_id;
2276 struct ext_hdmi_settings settings = {0};
2277 bool is_over_340mhz = false;
2278 bool is_vga_mode = (stream->timing.h_addressable == 640)
2279 && (stream->timing.v_addressable == 480);
2281 if (stream->phy_pix_clk == 0)
2282 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2283 if (stream->phy_pix_clk > 340000)
2284 is_over_340mhz = true;
2286 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2287 unsigned short masked_chip_caps = pipe_ctx->stream->link->chip_caps &
2288 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
2289 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
2290 /* DP159, Retimer settings */
2291 eng_id = pipe_ctx->stream_res.stream_enc->id;
2293 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings)) {
2294 write_i2c_retimer_setting(pipe_ctx,
2295 is_vga_mode, is_over_340mhz, &settings);
2297 write_i2c_default_retimer_setting(pipe_ctx,
2298 is_vga_mode, is_over_340mhz);
2300 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
2301 /* PI3EQX1204, Redriver settings */
2302 write_i2c_redriver_setting(pipe_ctx, is_over_340mhz);
2306 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2307 dal_ddc_service_write_scdc_data(
2309 stream->phy_pix_clk,
2310 stream->timing.flags.LTE_340MCSC_SCRAMBLE);
2312 memset(&stream->link->cur_link_settings, 0,
2313 sizeof(struct dc_link_settings));
2315 display_color_depth = stream->timing.display_color_depth;
2316 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
2317 display_color_depth = COLOR_DEPTH_888;
2319 link->link_enc->funcs->enable_tmds_output(
2321 pipe_ctx->clock_source->id,
2322 display_color_depth,
2323 pipe_ctx->stream->signal,
2324 stream->phy_pix_clk);
2326 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2327 dal_ddc_service_read_scdc_data(link->ddc);
2330 static void enable_link_lvds(struct pipe_ctx *pipe_ctx)
2332 struct dc_stream_state *stream = pipe_ctx->stream;
2333 struct dc_link *link = stream->link;
2335 if (stream->phy_pix_clk == 0)
2336 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2338 memset(&stream->link->cur_link_settings, 0,
2339 sizeof(struct dc_link_settings));
2341 link->link_enc->funcs->enable_lvds_output(
2343 pipe_ctx->clock_source->id,
2344 stream->phy_pix_clk);
2348 /****************************enable_link***********************************/
2349 static enum dc_status enable_link(
2350 struct dc_state *state,
2351 struct pipe_ctx *pipe_ctx)
2353 enum dc_status status = DC_ERROR_UNEXPECTED;
2354 struct dc_stream_state *stream = pipe_ctx->stream;
2355 struct dc_link *link = stream->link;
2357 /* There's some scenarios where driver is unloaded with display
2358 * still enabled. When driver is reloaded, it may cause a display
2359 * to not light up if there is a mismatch between old and new
2360 * link settings. Need to call disable first before enabling at
2361 * new link settings.
2363 if (link->link_status.link_active) {
2364 disable_link(link, pipe_ctx->stream->signal);
2367 switch (pipe_ctx->stream->signal) {
2368 case SIGNAL_TYPE_DISPLAY_PORT:
2369 status = enable_link_dp(state, pipe_ctx);
2371 case SIGNAL_TYPE_EDP:
2372 status = enable_link_edp(state, pipe_ctx);
2374 case SIGNAL_TYPE_DISPLAY_PORT_MST:
2375 status = enable_link_dp_mst(state, pipe_ctx);
2378 case SIGNAL_TYPE_DVI_SINGLE_LINK:
2379 case SIGNAL_TYPE_DVI_DUAL_LINK:
2380 case SIGNAL_TYPE_HDMI_TYPE_A:
2381 enable_link_hdmi(pipe_ctx);
2384 case SIGNAL_TYPE_LVDS:
2385 enable_link_lvds(pipe_ctx);
2388 case SIGNAL_TYPE_VIRTUAL:
2395 if (status == DC_OK)
2396 pipe_ctx->stream->link->link_status.link_active = true;
2401 static uint32_t get_timing_pixel_clock_100hz(const struct dc_crtc_timing *timing)
2404 uint32_t pxl_clk = timing->pix_clk_100hz;
2406 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
2408 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
2409 pxl_clk = pxl_clk * 2 / 3;
2411 if (timing->display_color_depth == COLOR_DEPTH_101010)
2412 pxl_clk = pxl_clk * 10 / 8;
2413 else if (timing->display_color_depth == COLOR_DEPTH_121212)
2414 pxl_clk = pxl_clk * 12 / 8;
2419 static bool dp_active_dongle_validate_timing(
2420 const struct dc_crtc_timing *timing,
2421 const struct dpcd_caps *dpcd_caps)
2423 const struct dc_dongle_caps *dongle_caps = &dpcd_caps->dongle_caps;
2425 switch (dpcd_caps->dongle_type) {
2426 case DISPLAY_DONGLE_DP_VGA_CONVERTER:
2427 case DISPLAY_DONGLE_DP_DVI_CONVERTER:
2428 case DISPLAY_DONGLE_DP_DVI_DONGLE:
2429 if (timing->pixel_encoding == PIXEL_ENCODING_RGB)
2437 if (dpcd_caps->dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER ||
2438 dongle_caps->extendedCapValid == false)
2441 /* Check Pixel Encoding */
2442 switch (timing->pixel_encoding) {
2443 case PIXEL_ENCODING_RGB:
2444 case PIXEL_ENCODING_YCBCR444:
2446 case PIXEL_ENCODING_YCBCR422:
2447 if (!dongle_caps->is_dp_hdmi_ycbcr422_pass_through)
2450 case PIXEL_ENCODING_YCBCR420:
2451 if (!dongle_caps->is_dp_hdmi_ycbcr420_pass_through)
2455 /* Invalid Pixel Encoding*/
2459 switch (timing->display_color_depth) {
2460 case COLOR_DEPTH_666:
2461 case COLOR_DEPTH_888:
2462 /*888 and 666 should always be supported*/
2464 case COLOR_DEPTH_101010:
2465 if (dongle_caps->dp_hdmi_max_bpc < 10)
2468 case COLOR_DEPTH_121212:
2469 if (dongle_caps->dp_hdmi_max_bpc < 12)
2472 case COLOR_DEPTH_141414:
2473 case COLOR_DEPTH_161616:
2475 /* These color depths are currently not supported */
2479 if (get_timing_pixel_clock_100hz(timing) > (dongle_caps->dp_hdmi_max_pixel_clk_in_khz * 10))
2485 enum dc_status dc_link_validate_mode_timing(
2486 const struct dc_stream_state *stream,
2487 struct dc_link *link,
2488 const struct dc_crtc_timing *timing)
2490 uint32_t max_pix_clk = stream->link->dongle_max_pix_clk * 10;
2491 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
2493 /* A hack to avoid failing any modes for EDID override feature on
2494 * topology change such as lower quality cable for DP or different dongle
2496 if (link->remote_sinks[0] && link->remote_sinks[0]->sink_signal == SIGNAL_TYPE_VIRTUAL)
2499 /* Passive Dongle */
2500 if (max_pix_clk != 0 && get_timing_pixel_clock_100hz(timing) > max_pix_clk)
2501 return DC_EXCEED_DONGLE_CAP;
2504 if (!dp_active_dongle_validate_timing(timing, dpcd_caps))
2505 return DC_EXCEED_DONGLE_CAP;
2507 switch (stream->signal) {
2508 case SIGNAL_TYPE_EDP:
2509 case SIGNAL_TYPE_DISPLAY_PORT:
2510 if (!dp_validate_mode_timing(
2513 return DC_NO_DP_LINK_BANDWIDTH;
2523 static struct abm *get_abm_from_stream_res(const struct dc_link *link)
2526 struct dc *dc = NULL;
2527 struct abm *abm = NULL;
2529 if (!link || !link->ctx)
2534 for (i = 0; i < MAX_PIPES; i++) {
2535 struct pipe_ctx pipe_ctx = dc->current_state->res_ctx.pipe_ctx[i];
2536 struct dc_stream_state *stream = pipe_ctx.stream;
2538 if (stream && stream->link == link) {
2539 abm = pipe_ctx.stream_res.abm;
2546 int dc_link_get_backlight_level(const struct dc_link *link)
2549 struct abm *abm = get_abm_from_stream_res(link);
2551 if (abm == NULL || abm->funcs->get_current_backlight == NULL)
2552 return DC_ERROR_UNEXPECTED;
2554 return (int) abm->funcs->get_current_backlight(abm);
2557 int dc_link_get_target_backlight_pwm(const struct dc_link *link)
2559 struct abm *abm = get_abm_from_stream_res(link);
2561 if (abm == NULL || abm->funcs->get_target_backlight == NULL)
2562 return DC_ERROR_UNEXPECTED;
2564 return (int) abm->funcs->get_target_backlight(abm);
2567 static struct pipe_ctx *get_pipe_from_link(const struct dc_link *link)
2570 struct dc *dc = link->ctx->dc;
2571 struct pipe_ctx *pipe_ctx = NULL;
2573 for (i = 0; i < MAX_PIPES; i++) {
2574 if (dc->current_state->res_ctx.pipe_ctx[i].stream) {
2575 if (dc->current_state->res_ctx.pipe_ctx[i].stream->link == link) {
2576 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2585 bool dc_link_set_backlight_level(const struct dc_link *link,
2586 uint32_t backlight_pwm_u16_16,
2587 uint32_t frame_ramp)
2589 struct dc *dc = link->ctx->dc;
2591 DC_LOGGER_INIT(link->ctx->logger);
2592 DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n",
2593 backlight_pwm_u16_16, backlight_pwm_u16_16);
2595 if (dc_is_embedded_signal(link->connector_signal)) {
2596 struct pipe_ctx *pipe_ctx = get_pipe_from_link(link);
2599 /* Disable brightness ramping when the display is blanked
2600 * as it can hang the DMCU
2602 if (pipe_ctx->plane_state == NULL)
2608 dc->hwss.set_backlight_level(
2610 backlight_pwm_u16_16,
2616 bool dc_link_set_psr_allow_active(struct dc_link *link, bool allow_active,
2617 bool wait, bool force_static)
2619 struct dc *dc = link->ctx->dc;
2620 struct dmcu *dmcu = dc->res_pool->dmcu;
2621 struct dmub_psr *psr = dc->res_pool->psr;
2623 if (psr == NULL && force_static)
2626 link->psr_settings.psr_allow_active = allow_active;
2628 if (psr != NULL && link->psr_settings.psr_feature_enabled) {
2629 if (force_static && psr->funcs->psr_force_static)
2630 psr->funcs->psr_force_static(psr);
2631 psr->funcs->psr_enable(psr, allow_active, wait);
2632 } else if ((dmcu != NULL && dmcu->funcs->is_dmcu_initialized(dmcu)) && link->psr_settings.psr_feature_enabled)
2633 dmcu->funcs->set_psr_enable(dmcu, allow_active, wait);
2640 bool dc_link_get_psr_state(const struct dc_link *link, enum dc_psr_state *state)
2642 struct dc *dc = link->ctx->dc;
2643 struct dmcu *dmcu = dc->res_pool->dmcu;
2644 struct dmub_psr *psr = dc->res_pool->psr;
2646 if (psr != NULL && link->psr_settings.psr_feature_enabled)
2647 psr->funcs->psr_get_state(psr, state);
2648 else if (dmcu != NULL && link->psr_settings.psr_feature_enabled)
2649 dmcu->funcs->get_psr_state(dmcu, state);
2654 static inline enum physical_phy_id
2655 transmitter_to_phy_id(enum transmitter transmitter_value)
2657 switch (transmitter_value) {
2658 case TRANSMITTER_UNIPHY_A:
2660 case TRANSMITTER_UNIPHY_B:
2662 case TRANSMITTER_UNIPHY_C:
2664 case TRANSMITTER_UNIPHY_D:
2666 case TRANSMITTER_UNIPHY_E:
2668 case TRANSMITTER_UNIPHY_F:
2670 case TRANSMITTER_NUTMEG_CRT:
2672 case TRANSMITTER_TRAVIS_CRT:
2674 case TRANSMITTER_TRAVIS_LCD:
2676 case TRANSMITTER_UNIPHY_G:
2678 case TRANSMITTER_COUNT:
2680 case TRANSMITTER_UNKNOWN:
2681 return PHYLD_UNKNOWN;
2683 WARN_ONCE(1, "Unknown transmitter value %d\n",
2685 return PHYLD_UNKNOWN;
2689 bool dc_link_setup_psr(struct dc_link *link,
2690 const struct dc_stream_state *stream, struct psr_config *psr_config,
2691 struct psr_context *psr_context)
2695 struct dmub_psr *psr;
2697 /* updateSinkPsrDpcdConfig*/
2698 union dpcd_psr_configuration psr_configuration;
2700 psr_context->controllerId = CONTROLLER_ID_UNDEFINED;
2706 dmcu = dc->res_pool->dmcu;
2707 psr = dc->res_pool->psr;
2713 memset(&psr_configuration, 0, sizeof(psr_configuration));
2715 psr_configuration.bits.ENABLE = 1;
2716 psr_configuration.bits.CRC_VERIFICATION = 1;
2717 psr_configuration.bits.FRAME_CAPTURE_INDICATION =
2718 psr_config->psr_frame_capture_indication_req;
2720 /* Check for PSR v2*/
2721 if (psr_config->psr_version == 0x2) {
2722 /* For PSR v2 selective update.
2723 * Indicates whether sink should start capturing
2724 * immediately following active scan line,
2725 * or starting with the 2nd active scan line.
2727 psr_configuration.bits.LINE_CAPTURE_INDICATION = 0;
2728 /*For PSR v2, determines whether Sink should generate
2729 * IRQ_HPD when CRC mismatch is detected.
2731 psr_configuration.bits.IRQ_HPD_WITH_CRC_ERROR = 1;
2734 dm_helpers_dp_write_dpcd(
2738 &psr_configuration.raw,
2739 sizeof(psr_configuration.raw));
2741 psr_context->channel = link->ddc->ddc_pin->hw_info.ddc_channel;
2742 psr_context->transmitterId = link->link_enc->transmitter;
2743 psr_context->engineId = link->link_enc->preferred_engine;
2745 for (i = 0; i < MAX_PIPES; i++) {
2746 if (dc->current_state->res_ctx.pipe_ctx[i].stream
2748 /* dmcu -1 for all controller id values,
2751 psr_context->controllerId =
2752 dc->current_state->res_ctx.
2753 pipe_ctx[i].stream_res.tg->inst + 1;
2758 /* Hardcoded for now. Can be Pcie or Uniphy (or Unknown)*/
2759 psr_context->phyType = PHY_TYPE_UNIPHY;
2760 /*PhyId is associated with the transmitter id*/
2761 psr_context->smuPhyId =
2762 transmitter_to_phy_id(link->link_enc->transmitter);
2764 psr_context->crtcTimingVerticalTotal = stream->timing.v_total;
2765 psr_context->vsync_rate_hz = div64_u64(div64_u64((stream->
2766 timing.pix_clk_100hz * 100),
2767 stream->timing.v_total),
2768 stream->timing.h_total);
2770 psr_context->psrSupportedDisplayConfig = true;
2771 psr_context->psrExitLinkTrainingRequired =
2772 psr_config->psr_exit_link_training_required;
2773 psr_context->sdpTransmitLineNumDeadline =
2774 psr_config->psr_sdp_transmit_line_num_deadline;
2775 psr_context->psrFrameCaptureIndicationReq =
2776 psr_config->psr_frame_capture_indication_req;
2778 psr_context->skipPsrWaitForPllLock = 0; /* only = 1 in KV */
2780 psr_context->numberOfControllers =
2781 link->dc->res_pool->timing_generator_count;
2783 psr_context->rfb_update_auto_en = true;
2785 /* 2 frames before enter PSR. */
2786 psr_context->timehyst_frames = 2;
2788 * (units in 100 lines, i.e. a value of 1 represents 100 lines)
2790 psr_context->hyst_lines = stream->timing.v_total / 2 / 100;
2791 psr_context->aux_repeats = 10;
2793 psr_context->psr_level.u32all = 0;
2795 #if defined(CONFIG_DRM_AMD_DC_DCN)
2796 /*skip power down the single pipe since it blocks the cstate*/
2797 if ((link->ctx->asic_id.chip_family == FAMILY_RV) &&
2798 ASICREV_IS_RAVEN(link->ctx->asic_id.hw_internal_rev))
2799 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
2802 /* SMU will perform additional powerdown sequence.
2803 * For unsupported ASICs, set psr_level flag to skip PSR
2804 * static screen notification to SMU.
2805 * (Always set for DAL2, did not check ASIC)
2807 psr_context->allow_smu_optimizations = psr_config->allow_smu_optimizations;
2808 psr_context->allow_multi_disp_optimizations = psr_config->allow_multi_disp_optimizations;
2810 /* Complete PSR entry before aborting to prevent intermittent
2811 * freezes on certain eDPs
2813 psr_context->psr_level.bits.DISABLE_PSR_ENTRY_ABORT = 1;
2815 /* Controls additional delay after remote frame capture before
2816 * continuing power down, default = 0
2818 psr_context->frame_delay = 0;
2821 link->psr_settings.psr_feature_enabled = psr->funcs->psr_copy_settings(psr, link, psr_context);
2823 link->psr_settings.psr_feature_enabled = dmcu->funcs->setup_psr(dmcu, link, psr_context);
2825 /* psr_enabled == 0 indicates setup_psr did not succeed, but this
2826 * should not happen since firmware should be running at this point
2828 if (link->psr_settings.psr_feature_enabled == 0)
2835 void dc_link_get_psr_residency(const struct dc_link *link, uint32_t *residency)
2837 struct dc *dc = link->ctx->dc;
2838 struct dmub_psr *psr = dc->res_pool->psr;
2840 // PSR residency measurements only supported on DMCUB
2841 if (psr != NULL && link->psr_settings.psr_feature_enabled)
2842 psr->funcs->psr_get_residency(psr, residency);
2847 const struct dc_link_status *dc_link_get_status(const struct dc_link *link)
2849 return &link->link_status;
2852 void core_link_resume(struct dc_link *link)
2854 if (link->connector_signal != SIGNAL_TYPE_VIRTUAL)
2855 program_hpd_filter(link);
2858 static struct fixed31_32 get_pbn_per_slot(struct dc_stream_state *stream)
2860 struct fixed31_32 mbytes_per_sec;
2861 uint32_t link_rate_in_mbytes_per_sec = dc_link_bandwidth_kbps(stream->link,
2862 &stream->link->cur_link_settings);
2863 link_rate_in_mbytes_per_sec /= 8000; /* Kbits to MBytes */
2865 mbytes_per_sec = dc_fixpt_from_int(link_rate_in_mbytes_per_sec);
2867 return dc_fixpt_div_int(mbytes_per_sec, 54);
2870 static struct fixed31_32 get_pbn_from_bw_in_kbps(uint64_t kbps)
2872 struct fixed31_32 peak_kbps;
2874 uint32_t denominator;
2877 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
2878 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
2879 * common multiplier to render an integer PBN for all link rate/lane
2880 * counts combinations
2882 * peak_kbps *= (1006/1000)
2883 * peak_kbps *= (64/54)
2884 * peak_kbps *= 8 convert to bytes
2887 numerator = 64 * PEAK_FACTOR_X1000;
2888 denominator = 54 * 8 * 1000 * 1000;
2890 peak_kbps = dc_fixpt_from_fraction(kbps, denominator);
2895 static struct fixed31_32 get_pbn_from_timing(struct pipe_ctx *pipe_ctx)
2899 kbps = dc_bandwidth_in_kbps_from_timing(&pipe_ctx->stream->timing);
2900 return get_pbn_from_bw_in_kbps(kbps);
2903 static void update_mst_stream_alloc_table(
2904 struct dc_link *link,
2905 struct stream_encoder *stream_enc,
2906 const struct dp_mst_stream_allocation_table *proposed_table)
2908 struct link_mst_stream_allocation work_table[MAX_CONTROLLER_NUM] = {
2910 struct link_mst_stream_allocation *dc_alloc;
2915 /* if DRM proposed_table has more than one new payload */
2916 ASSERT(proposed_table->stream_count -
2917 link->mst_stream_alloc_table.stream_count < 2);
2919 /* copy proposed_table to link, add stream encoder */
2920 for (i = 0; i < proposed_table->stream_count; i++) {
2922 for (j = 0; j < link->mst_stream_alloc_table.stream_count; j++) {
2924 &link->mst_stream_alloc_table.stream_allocations[j];
2926 if (dc_alloc->vcp_id ==
2927 proposed_table->stream_allocations[i].vcp_id) {
2929 work_table[i] = *dc_alloc;
2930 work_table[i].slot_count = proposed_table->stream_allocations[i].slot_count;
2931 break; /* exit j loop */
2936 if (j == link->mst_stream_alloc_table.stream_count) {
2937 work_table[i].vcp_id =
2938 proposed_table->stream_allocations[i].vcp_id;
2939 work_table[i].slot_count =
2940 proposed_table->stream_allocations[i].slot_count;
2941 work_table[i].stream_enc = stream_enc;
2945 /* update link->mst_stream_alloc_table with work_table */
2946 link->mst_stream_alloc_table.stream_count =
2947 proposed_table->stream_count;
2948 for (i = 0; i < MAX_CONTROLLER_NUM; i++)
2949 link->mst_stream_alloc_table.stream_allocations[i] =
2953 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
2954 * because stream_encoder is not exposed to dm
2956 enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx)
2958 struct dc_stream_state *stream = pipe_ctx->stream;
2959 struct dc_link *link = stream->link;
2960 struct link_encoder *link_encoder = link->link_enc;
2961 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
2962 struct dp_mst_stream_allocation_table proposed_table = {0};
2963 struct fixed31_32 avg_time_slots_per_mtp;
2964 struct fixed31_32 pbn;
2965 struct fixed31_32 pbn_per_slot;
2967 enum act_return_status ret;
2968 DC_LOGGER_INIT(link->ctx->logger);
2970 /* enable_link_dp_mst already check link->enabled_stream_count
2971 * and stream is in link->stream[]. This is called during set mode,
2972 * stream_enc is available.
2975 /* get calculate VC payload for stream: stream_alloc */
2976 if (dm_helpers_dp_mst_write_payload_allocation_table(
2981 update_mst_stream_alloc_table(
2982 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
2985 DC_LOG_WARNING("Failed to update"
2986 "MST allocation table for"
2988 pipe_ctx->pipe_idx);
2991 "stream_count: %d: \n ",
2993 link->mst_stream_alloc_table.stream_count);
2995 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
2996 DC_LOG_MST("stream_enc[%d]: %p "
2997 "stream[%d].vcp_id: %d "
2998 "stream[%d].slot_count: %d\n",
3000 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3002 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3004 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3007 ASSERT(proposed_table.stream_count > 0);
3009 /* program DP source TX for payload */
3010 link_encoder->funcs->update_mst_stream_allocation_table(
3012 &link->mst_stream_alloc_table);
3014 /* send down message */
3015 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3019 if (ret != ACT_LINK_LOST) {
3020 dm_helpers_dp_mst_send_payload_allocation(
3026 /* slot X.Y for only current stream */
3027 pbn_per_slot = get_pbn_per_slot(stream);
3028 if (pbn_per_slot.value == 0) {
3029 DC_LOG_ERROR("Failure: pbn_per_slot==0 not allowed. Cannot continue, returning DC_UNSUPPORTED_VALUE.\n");
3030 return DC_UNSUPPORTED_VALUE;
3032 pbn = get_pbn_from_timing(pipe_ctx);
3033 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
3035 stream_encoder->funcs->set_throttled_vcp_size(
3037 avg_time_slots_per_mtp);
3043 static enum dc_status deallocate_mst_payload(struct pipe_ctx *pipe_ctx)
3045 struct dc_stream_state *stream = pipe_ctx->stream;
3046 struct dc_link *link = stream->link;
3047 struct link_encoder *link_encoder = link->link_enc;
3048 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3049 struct dp_mst_stream_allocation_table proposed_table = {0};
3050 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
3052 bool mst_mode = (link->type == dc_connection_mst_branch);
3053 DC_LOGGER_INIT(link->ctx->logger);
3055 /* deallocate_mst_payload is called before disable link. When mode or
3056 * disable/enable monitor, new stream is created which is not in link
3057 * stream[] yet. For this, payload is not allocated yet, so de-alloc
3058 * should not done. For new mode set, map_resources will get engine
3059 * for new stream, so stream_enc->id should be validated until here.
3063 stream_encoder->funcs->set_throttled_vcp_size(
3065 avg_time_slots_per_mtp);
3067 /* TODO: which component is responsible for remove payload table? */
3069 if (dm_helpers_dp_mst_write_payload_allocation_table(
3075 update_mst_stream_alloc_table(
3076 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
3079 DC_LOG_WARNING("Failed to update"
3080 "MST allocation table for"
3082 pipe_ctx->pipe_idx);
3087 "stream_count: %d: ",
3089 link->mst_stream_alloc_table.stream_count);
3091 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3092 DC_LOG_MST("stream_enc[%d]: %p "
3093 "stream[%d].vcp_id: %d "
3094 "stream[%d].slot_count: %d\n",
3096 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3098 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3100 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3103 link_encoder->funcs->update_mst_stream_allocation_table(
3105 &link->mst_stream_alloc_table);
3108 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3112 dm_helpers_dp_mst_send_payload_allocation(
3121 enum dc_status dc_link_reallocate_mst_payload(struct dc_link *link)
3124 struct pipe_ctx *pipe_ctx;
3126 // Clear all of MST payload then reallocate
3127 for (i = 0; i < MAX_PIPES; i++) {
3128 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
3130 /* driver enable split pipe for external monitors
3131 * we have to check pipe_ctx is split pipe or not
3132 * If it's split pipe, driver using top pipe to
3135 if (!pipe_ctx || pipe_ctx->top_pipe)
3138 if (pipe_ctx->stream && pipe_ctx->stream->link == link &&
3139 pipe_ctx->stream->dpms_off == false &&
3140 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3141 deallocate_mst_payload(pipe_ctx);
3145 for (i = 0; i < MAX_PIPES; i++) {
3146 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
3148 if (!pipe_ctx || pipe_ctx->top_pipe)
3151 if (pipe_ctx->stream && pipe_ctx->stream->link == link &&
3152 pipe_ctx->stream->dpms_off == false &&
3153 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3154 /* enable/disable PHY will clear connection between BE and FE
3155 * need to restore it.
3157 link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc,
3158 pipe_ctx->stream_res.stream_enc->id, true);
3159 dc_link_allocate_mst_payload(pipe_ctx);
3166 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3167 static void update_psp_stream_config(struct pipe_ctx *pipe_ctx, bool dpms_off)
3169 struct cp_psp *cp_psp = &pipe_ctx->stream->ctx->cp_psp;
3170 if (cp_psp && cp_psp->funcs.update_stream_config) {
3171 struct cp_psp_stream_config config = {0};
3172 enum dp_panel_mode panel_mode =
3173 dp_get_panel_mode(pipe_ctx->stream->link);
3175 config.otg_inst = (uint8_t) pipe_ctx->stream_res.tg->inst;
3176 config.dig_fe = (uint8_t) pipe_ctx->stream_res.stream_enc->stream_enc_inst;
3177 config.dig_be = pipe_ctx->stream->link->link_enc_hw_inst;
3178 config.dpms_off = dpms_off;
3179 config.dm_stream_ctx = pipe_ctx->stream->dm_stream_context;
3180 config.assr_enabled = (panel_mode == DP_PANEL_MODE_EDP);
3181 config.mst_enabled = (pipe_ctx->stream->signal ==
3182 SIGNAL_TYPE_DISPLAY_PORT_MST);
3183 cp_psp->funcs.update_stream_config(cp_psp->handle, &config);
3188 void core_link_enable_stream(
3189 struct dc_state *state,
3190 struct pipe_ctx *pipe_ctx)
3192 struct dc *dc = pipe_ctx->stream->ctx->dc;
3193 struct dc_stream_state *stream = pipe_ctx->stream;
3194 enum dc_status status;
3195 #if defined(CONFIG_DRM_AMD_DC_DCN)
3196 enum otg_out_mux_dest otg_out_dest = OUT_MUX_DIO;
3198 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
3200 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
3201 dc_is_virtual_signal(pipe_ctx->stream->signal))
3204 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)) {
3205 stream->link->link_enc->funcs->setup(
3206 stream->link->link_enc,
3207 pipe_ctx->stream->signal);
3208 pipe_ctx->stream_res.stream_enc->funcs->setup_stereo_sync(
3209 pipe_ctx->stream_res.stream_enc,
3210 pipe_ctx->stream_res.tg->inst,
3211 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
3214 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3215 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
3216 pipe_ctx->stream_res.stream_enc,
3218 stream->output_color_space,
3219 stream->use_vsc_sdp_for_colorimetry,
3220 stream->link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
3222 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
3223 pipe_ctx->stream_res.stream_enc->funcs->hdmi_set_stream_attribute(
3224 pipe_ctx->stream_res.stream_enc,
3226 stream->phy_pix_clk,
3227 pipe_ctx->stream_res.audio != NULL);
3229 pipe_ctx->stream->link->link_state_valid = true;
3231 #if defined(CONFIG_DRM_AMD_DC_DCN)
3232 if (pipe_ctx->stream_res.tg->funcs->set_out_mux)
3233 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, otg_out_dest);
3236 if (dc_is_dvi_signal(pipe_ctx->stream->signal))
3237 pipe_ctx->stream_res.stream_enc->funcs->dvi_set_stream_attribute(
3238 pipe_ctx->stream_res.stream_enc,
3240 (pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
3243 if (dc_is_lvds_signal(pipe_ctx->stream->signal))
3244 pipe_ctx->stream_res.stream_enc->funcs->lvds_set_stream_attribute(
3245 pipe_ctx->stream_res.stream_enc,
3248 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
3249 bool apply_edp_fast_boot_optimization =
3250 pipe_ctx->stream->apply_edp_fast_boot_optimization;
3252 pipe_ctx->stream->apply_edp_fast_boot_optimization = false;
3254 resource_build_info_frame(pipe_ctx);
3255 dc->hwss.update_info_frame(pipe_ctx);
3257 /* Do not touch link on seamless boot optimization. */
3258 if (pipe_ctx->stream->apply_seamless_boot_optimization) {
3259 pipe_ctx->stream->dpms_off = false;
3260 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3261 update_psp_stream_config(pipe_ctx, false);
3266 /* eDP lit up by bios already, no need to enable again. */
3267 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
3268 apply_edp_fast_boot_optimization) {
3269 pipe_ctx->stream->dpms_off = false;
3270 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3271 update_psp_stream_config(pipe_ctx, false);
3276 if (pipe_ctx->stream->dpms_off)
3279 /* Have to setup DSC before DIG FE and BE are connected (which happens before the
3280 * link training). This is to make sure the bandwidth sent to DIG BE won't be
3281 * bigger than what the link and/or DIG BE can handle. VBID[6]/CompressedStream_flag
3282 * will be automatically set at a later time when the video is enabled
3283 * (DP_VID_STREAM_EN = 1).
3285 if (pipe_ctx->stream->timing.flags.DSC) {
3286 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3287 dc_is_virtual_signal(pipe_ctx->stream->signal))
3288 dp_set_dsc_enable(pipe_ctx, true);
3291 status = enable_link(state, pipe_ctx);
3293 if (status != DC_OK) {
3294 DC_LOG_WARNING("enabling link %u failed: %d\n",
3295 pipe_ctx->stream->link->link_index,
3298 /* Abort stream enable *unless* the failure was due to
3299 * DP link training - some DP monitors will recover and
3300 * show the stream anyway. But MST displays can't proceed
3301 * without link training.
3303 if (status != DC_FAIL_DP_LINK_TRAINING ||
3304 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3305 BREAK_TO_DEBUGGER();
3310 /* turn off otg test pattern if enable */
3311 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
3312 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
3313 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
3314 COLOR_DEPTH_UNDEFINED);
3316 /* This second call is needed to reconfigure the DIG
3317 * as a workaround for the incorrect value being applied
3318 * from transmitter control.
3320 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
3321 stream->link->link_enc->funcs->setup(
3322 stream->link->link_enc,
3323 pipe_ctx->stream->signal);
3325 dc->hwss.enable_stream(pipe_ctx);
3327 /* Set DPS PPS SDP (AKA "info frames") */
3328 if (pipe_ctx->stream->timing.flags.DSC) {
3329 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3330 dc_is_virtual_signal(pipe_ctx->stream->signal))
3331 dp_set_dsc_pps_sdp(pipe_ctx, true);
3334 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
3335 dc_link_allocate_mst_payload(pipe_ctx);
3337 dc->hwss.unblank_stream(pipe_ctx,
3338 &pipe_ctx->stream->link->cur_link_settings);
3340 if (stream->sink_patches.delay_ignore_msa > 0)
3341 msleep(stream->sink_patches.delay_ignore_msa);
3343 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3344 enable_stream_features(pipe_ctx);
3345 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3346 update_psp_stream_config(pipe_ctx, false);
3349 dc->hwss.enable_audio_stream(pipe_ctx);
3351 } else { // if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
3352 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3353 dc_is_virtual_signal(pipe_ctx->stream->signal))
3354 dp_set_dsc_enable(pipe_ctx, true);
3358 if (pipe_ctx->stream->signal == SIGNAL_TYPE_HDMI_TYPE_A) {
3359 core_link_set_avmute(pipe_ctx, false);
3363 void core_link_disable_stream(struct pipe_ctx *pipe_ctx)
3365 struct dc *dc = pipe_ctx->stream->ctx->dc;
3366 struct dc_stream_state *stream = pipe_ctx->stream;
3367 struct dc_link *link = stream->sink->link;
3369 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
3370 dc_is_virtual_signal(pipe_ctx->stream->signal))
3373 if (!pipe_ctx->stream->sink->edid_caps.panel_patch.skip_avmute) {
3374 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
3375 core_link_set_avmute(pipe_ctx, true);
3378 dc->hwss.disable_audio_stream(pipe_ctx);
3380 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3381 update_psp_stream_config(pipe_ctx, true);
3383 dc->hwss.blank_stream(pipe_ctx);
3385 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
3386 deallocate_mst_payload(pipe_ctx);
3388 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
3389 struct ext_hdmi_settings settings = {0};
3390 enum engine_id eng_id = pipe_ctx->stream_res.stream_enc->id;
3392 unsigned short masked_chip_caps = link->chip_caps &
3393 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
3394 //Need to inform that sink is going to use legacy HDMI mode.
3395 dal_ddc_service_write_scdc_data(
3397 165000,//vbios only handles 165Mhz.
3399 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
3400 /* DP159, Retimer settings */
3401 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings))
3402 write_i2c_retimer_setting(pipe_ctx,
3403 false, false, &settings);
3405 write_i2c_default_retimer_setting(pipe_ctx,
3407 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
3408 /* PI3EQX1204, Redriver settings */
3409 write_i2c_redriver_setting(pipe_ctx, false);
3413 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
3415 dc->hwss.disable_stream(pipe_ctx);
3417 if (pipe_ctx->stream->timing.flags.DSC) {
3418 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3419 dp_set_dsc_enable(pipe_ctx, false);
3423 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
3425 struct dc *dc = pipe_ctx->stream->ctx->dc;
3427 if (!dc_is_hdmi_signal(pipe_ctx->stream->signal))
3430 dc->hwss.set_avmute(pipe_ctx, enable);
3434 * dc_link_enable_hpd_filter:
3435 * If enable is true, programs HPD filter on associated HPD line using
3436 * delay_on_disconnect/delay_on_connect values dependent on
3437 * link->connector_signal
3439 * If enable is false, programs HPD filter on associated HPD line with no
3440 * delays on connect or disconnect
3442 * @link: pointer to the dc link
3443 * @enable: boolean specifying whether to enable hbd
3445 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
3450 link->is_hpd_filter_disabled = false;
3451 program_hpd_filter(link);
3453 link->is_hpd_filter_disabled = true;
3454 /* Obtain HPD handle */
3455 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
3460 /* Setup HPD filtering */
3461 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
3462 struct gpio_hpd_config config;
3464 config.delay_on_connect = 0;
3465 config.delay_on_disconnect = 0;
3467 dal_irq_setup_hpd_filter(hpd, &config);
3469 dal_gpio_close(hpd);
3471 ASSERT_CRITICAL(false);
3473 /* Release HPD handle */
3474 dal_gpio_destroy_irq(&hpd);
3478 uint32_t dc_bandwidth_in_kbps_from_timing(
3479 const struct dc_crtc_timing *timing)
3481 uint32_t bits_per_channel = 0;
3483 struct fixed31_32 link_bw_kbps;
3485 if (timing->flags.DSC) {
3486 link_bw_kbps = dc_fixpt_from_int(timing->pix_clk_100hz);
3487 link_bw_kbps = dc_fixpt_div_int(link_bw_kbps, 160);
3488 link_bw_kbps = dc_fixpt_mul_int(link_bw_kbps, timing->dsc_cfg.bits_per_pixel);
3489 kbps = dc_fixpt_ceil(link_bw_kbps);
3493 switch (timing->display_color_depth) {
3494 case COLOR_DEPTH_666:
3495 bits_per_channel = 6;
3497 case COLOR_DEPTH_888:
3498 bits_per_channel = 8;
3500 case COLOR_DEPTH_101010:
3501 bits_per_channel = 10;
3503 case COLOR_DEPTH_121212:
3504 bits_per_channel = 12;
3506 case COLOR_DEPTH_141414:
3507 bits_per_channel = 14;
3509 case COLOR_DEPTH_161616:
3510 bits_per_channel = 16;
3513 ASSERT(bits_per_channel != 0);
3514 bits_per_channel = 8;
3518 kbps = timing->pix_clk_100hz / 10;
3519 kbps *= bits_per_channel;
3521 if (timing->flags.Y_ONLY != 1) {
3522 /*Only YOnly make reduce bandwidth by 1/3 compares to RGB*/
3524 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
3526 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
3527 kbps = kbps * 2 / 3;
3534 void dc_link_set_drive_settings(struct dc *dc,
3535 struct link_training_settings *lt_settings,
3536 const struct dc_link *link)
3541 for (i = 0; i < dc->link_count; i++) {
3542 if (dc->links[i] == link)
3546 if (i >= dc->link_count)
3547 ASSERT_CRITICAL(false);
3549 dc_link_dp_set_drive_settings(dc->links[i], lt_settings);
3552 void dc_link_perform_link_training(struct dc *dc,
3553 struct dc_link_settings *link_setting,
3554 bool skip_video_pattern)
3558 for (i = 0; i < dc->link_count; i++)
3559 dc_link_dp_perform_link_training(
3562 skip_video_pattern);
3565 void dc_link_set_preferred_link_settings(struct dc *dc,
3566 struct dc_link_settings *link_setting,
3567 struct dc_link *link)
3570 struct pipe_ctx *pipe;
3571 struct dc_stream_state *link_stream;
3572 struct dc_link_settings store_settings = *link_setting;
3574 link->preferred_link_setting = store_settings;
3576 /* Retrain with preferred link settings only relevant for
3578 * Check for non-DP signal or if passive dongle present
3580 if (!dc_is_dp_signal(link->connector_signal) ||
3581 link->dongle_max_pix_clk > 0)
3584 for (i = 0; i < MAX_PIPES; i++) {
3585 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
3586 if (pipe->stream && pipe->stream->link) {
3587 if (pipe->stream->link == link) {
3588 link_stream = pipe->stream;
3594 /* Stream not found */
3598 /* Cannot retrain link if backend is off */
3599 if (link_stream->dpms_off)
3602 decide_link_settings(link_stream, &store_settings);
3604 if ((store_settings.lane_count != LANE_COUNT_UNKNOWN) &&
3605 (store_settings.link_rate != LINK_RATE_UNKNOWN))
3606 dp_retrain_link_dp_test(link, &store_settings, false);
3609 void dc_link_set_preferred_training_settings(struct dc *dc,
3610 struct dc_link_settings *link_setting,
3611 struct dc_link_training_overrides *lt_overrides,
3612 struct dc_link *link,
3613 bool skip_immediate_retrain)
3615 if (lt_overrides != NULL)
3616 link->preferred_training_settings = *lt_overrides;
3618 memset(&link->preferred_training_settings, 0, sizeof(link->preferred_training_settings));
3620 if (link_setting != NULL) {
3621 link->preferred_link_setting = *link_setting;
3623 link->preferred_link_setting.lane_count = LANE_COUNT_UNKNOWN;
3624 link->preferred_link_setting.link_rate = LINK_RATE_UNKNOWN;
3627 /* Retrain now, or wait until next stream update to apply */
3628 if (skip_immediate_retrain == false)
3629 dc_link_set_preferred_link_settings(dc, &link->preferred_link_setting, link);
3632 void dc_link_enable_hpd(const struct dc_link *link)
3634 dc_link_dp_enable_hpd(link);
3637 void dc_link_disable_hpd(const struct dc_link *link)
3639 dc_link_dp_disable_hpd(link);
3642 void dc_link_set_test_pattern(struct dc_link *link,
3643 enum dp_test_pattern test_pattern,
3644 enum dp_test_pattern_color_space test_pattern_color_space,
3645 const struct link_training_settings *p_link_settings,
3646 const unsigned char *p_custom_pattern,
3647 unsigned int cust_pattern_size)
3650 dc_link_dp_set_test_pattern(
3653 test_pattern_color_space,
3659 uint32_t dc_link_bandwidth_kbps(
3660 const struct dc_link *link,
3661 const struct dc_link_settings *link_setting)
3663 uint32_t link_bw_kbps =
3664 link_setting->link_rate * LINK_RATE_REF_FREQ_IN_KHZ; /* bytes per sec */
3666 link_bw_kbps *= 8; /* 8 bits per byte*/
3667 link_bw_kbps *= link_setting->lane_count;
3669 if (dc_link_should_enable_fec(link)) {
3670 /* Account for FEC overhead.
3671 * We have to do it based on caps,
3672 * and not based on FEC being set ready,
3673 * because FEC is set ready too late in
3674 * the process to correctly be picked up
3675 * by mode enumeration.
3677 * There's enough zeros at the end of 'kbps'
3678 * that make the below operation 100% precise
3680 * 'long long' makes it work even for HDMI 2.1
3681 * max bandwidth (and much, much bigger bandwidths
3682 * than that, actually).
3684 * NOTE: Reducing link BW by 3% may not be precise
3685 * because it may be a stream BT that increases by 3%, and so
3686 * 1/1.03 = 0.970873 factor should have been used instead,
3687 * but the difference is minimal and is in a safe direction,
3688 * which all works well around potential ambiguity of DP 1.4a spec.
3690 long long fec_link_bw_kbps = link_bw_kbps * 970LL;
3691 link_bw_kbps = (uint32_t)(div64_s64(fec_link_bw_kbps, 1000LL));
3694 return link_bw_kbps;
3698 const struct dc_link_settings *dc_link_get_link_cap(
3699 const struct dc_link *link)
3701 if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
3702 link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
3703 return &link->preferred_link_setting;
3704 return &link->verified_link_cap;
3707 void dc_link_overwrite_extended_receiver_cap(
3708 struct dc_link *link)
3710 dp_overwrite_extended_receiver_cap(link);
3713 bool dc_link_is_fec_supported(const struct dc_link *link)
3715 return (dc_is_dp_signal(link->connector_signal) &&
3716 link->link_enc->features.fec_supported &&
3717 link->dpcd_caps.fec_cap.bits.FEC_CAPABLE &&
3718 !IS_FPGA_MAXIMUS_DC(link->ctx->dce_environment));
3721 bool dc_link_should_enable_fec(const struct dc_link *link)
3723 bool is_fec_disable = false;
3726 if ((link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT_MST &&
3728 link->local_sink->edid_caps.panel_patch.disable_fec) ||
3729 link->connector_signal == SIGNAL_TYPE_EDP) // Disable FEC for eDP
3730 is_fec_disable = true;
3732 if (dc_link_is_fec_supported(link) && !link->dc->debug.disable_fec && !is_fec_disable)