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"
51 #include "inc/link_enc_cfg.h"
52 #include "inc/link_dpcd.h"
54 #include "dc/dcn30/dcn30_vpg.h"
56 #define DC_LOGGER_INIT(logger)
58 #define LINK_INFO(...) \
62 #define RETIMER_REDRIVER_INFO(...) \
63 DC_LOG_RETIMER_REDRIVER( \
66 /*******************************************************************************
68 ******************************************************************************/
69 #if defined(CONFIG_DRM_AMD_DC_DCN)
70 static bool add_dp_hpo_link_encoder_to_link(struct dc_link *link)
72 struct hpo_dp_link_encoder *enc = resource_get_unused_hpo_dp_link_encoder(
75 if (!link->hpo_dp_link_enc && enc) {
76 link->hpo_dp_link_enc = enc;
77 link->hpo_dp_link_enc->transmitter = link->link_enc->transmitter;
78 link->hpo_dp_link_enc->hpd_source = link->link_enc->hpd_source;
81 return (link->hpo_dp_link_enc != NULL);
84 static void remove_dp_hpo_link_encoder_from_link(struct dc_link *link)
86 if (link->hpo_dp_link_enc) {
87 link->hpo_dp_link_enc->hpd_source = HPD_SOURCEID_UNKNOWN;
88 link->hpo_dp_link_enc->transmitter = TRANSMITTER_UNKNOWN;
89 link->hpo_dp_link_enc = NULL;
94 static void dc_link_destruct(struct dc_link *link)
99 dal_gpio_destroy_irq(&link->hpd_gpio);
100 link->hpd_gpio = NULL;
104 dal_ddc_service_destroy(&link->ddc);
106 if (link->panel_cntl)
107 link->panel_cntl->funcs->destroy(&link->panel_cntl);
109 if (link->link_enc) {
110 /* Update link encoder resource tracking variables. These are used for
111 * the dynamic assignment of link encoders to streams. Virtual links
112 * are not assigned encoder resources on creation.
114 if (link->link_id.id != CONNECTOR_ID_VIRTUAL) {
115 link->dc->res_pool->link_encoders[link->eng_id - ENGINE_ID_DIGA] = NULL;
116 link->dc->res_pool->dig_link_enc_count--;
118 link->link_enc->funcs->destroy(&link->link_enc);
121 #if defined(CONFIG_DRM_AMD_DC_DCN)
122 if (link->hpo_dp_link_enc) {
123 remove_dp_hpo_link_encoder_from_link(link);
127 if (link->local_sink)
128 dc_sink_release(link->local_sink);
130 for (i = 0; i < link->sink_count; ++i)
131 dc_sink_release(link->remote_sinks[i]);
134 struct gpio *get_hpd_gpio(struct dc_bios *dcb,
135 struct graphics_object_id link_id,
136 struct gpio_service *gpio_service)
138 enum bp_result bp_result;
139 struct graphics_object_hpd_info hpd_info;
140 struct gpio_pin_info pin_info;
142 if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
145 bp_result = dcb->funcs->get_gpio_pin_info(dcb,
146 hpd_info.hpd_int_gpio_uid, &pin_info);
148 if (bp_result != BP_RESULT_OK) {
149 ASSERT(bp_result == BP_RESULT_NORECORD);
153 return dal_gpio_service_create_irq(gpio_service,
159 * Function: program_hpd_filter
162 * Programs HPD filter on associated HPD line
164 * @param [in] delay_on_connect_in_ms: Connect filter timeout
165 * @param [in] delay_on_disconnect_in_ms: Disconnect filter timeout
168 * true on success, false otherwise
170 static bool program_hpd_filter(const struct dc_link *link)
174 int delay_on_connect_in_ms = 0;
175 int delay_on_disconnect_in_ms = 0;
177 if (link->is_hpd_filter_disabled)
179 /* Verify feature is supported */
180 switch (link->connector_signal) {
181 case SIGNAL_TYPE_DVI_SINGLE_LINK:
182 case SIGNAL_TYPE_DVI_DUAL_LINK:
183 case SIGNAL_TYPE_HDMI_TYPE_A:
184 /* Program hpd filter */
185 delay_on_connect_in_ms = 500;
186 delay_on_disconnect_in_ms = 100;
188 case SIGNAL_TYPE_DISPLAY_PORT:
189 case SIGNAL_TYPE_DISPLAY_PORT_MST:
190 /* Program hpd filter to allow DP signal to settle */
191 /* 500: not able to detect MST <-> SST switch as HPD is low for
192 * only 100ms on DELL U2413
193 * 0: some passive dongle still show aux mode instead of i2c
194 * 20-50: not enough to hide bouncing HPD with passive dongle.
195 * also see intermittent i2c read issues.
197 delay_on_connect_in_ms = 80;
198 delay_on_disconnect_in_ms = 0;
200 case SIGNAL_TYPE_LVDS:
201 case SIGNAL_TYPE_EDP:
203 /* Don't program hpd filter */
207 /* Obtain HPD handle */
208 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
209 link->ctx->gpio_service);
214 /* Setup HPD filtering */
215 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
216 struct gpio_hpd_config config;
218 config.delay_on_connect = delay_on_connect_in_ms;
219 config.delay_on_disconnect = delay_on_disconnect_in_ms;
221 dal_irq_setup_hpd_filter(hpd, &config);
227 ASSERT_CRITICAL(false);
230 /* Release HPD handle */
231 dal_gpio_destroy_irq(&hpd);
236 bool dc_link_wait_for_t12(struct dc_link *link)
238 if (link->connector_signal == SIGNAL_TYPE_EDP && link->dc->hwss.edp_wait_for_T12) {
239 link->dc->hwss.edp_wait_for_T12(link);
248 * dc_link_detect_sink() - Determine if there is a sink connected
250 * @link: pointer to the dc link
251 * @type: Returned connection type
252 * Does not detect downstream devices, such as MST sinks
253 * or display connected through active dongles
255 bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type)
257 uint32_t is_hpd_high = 0;
258 struct gpio *hpd_pin;
260 if (link->connector_signal == SIGNAL_TYPE_LVDS) {
261 *type = dc_connection_single;
265 if (link->connector_signal == SIGNAL_TYPE_EDP) {
266 /*in case it is not on*/
267 link->dc->hwss.edp_power_control(link, true);
268 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
271 /* Link may not have physical HPD pin. */
272 if (link->ep_type != DISPLAY_ENDPOINT_PHY) {
273 if (link->is_hpd_pending || !link->hpd_status)
274 *type = dc_connection_none;
276 *type = dc_connection_single;
281 /* todo: may need to lock gpio access */
282 hpd_pin = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
283 link->ctx->gpio_service);
285 goto hpd_gpio_failure;
287 dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
288 dal_gpio_get_value(hpd_pin, &is_hpd_high);
289 dal_gpio_close(hpd_pin);
290 dal_gpio_destroy_irq(&hpd_pin);
293 *type = dc_connection_single;
294 /* TODO: need to do the actual detection */
296 *type = dc_connection_none;
305 static enum ddc_transaction_type get_ddc_transaction_type(enum signal_type sink_signal)
307 enum ddc_transaction_type transaction_type = DDC_TRANSACTION_TYPE_NONE;
309 switch (sink_signal) {
310 case SIGNAL_TYPE_DVI_SINGLE_LINK:
311 case SIGNAL_TYPE_DVI_DUAL_LINK:
312 case SIGNAL_TYPE_HDMI_TYPE_A:
313 case SIGNAL_TYPE_LVDS:
314 case SIGNAL_TYPE_RGB:
315 transaction_type = DDC_TRANSACTION_TYPE_I2C;
318 case SIGNAL_TYPE_DISPLAY_PORT:
319 case SIGNAL_TYPE_EDP:
320 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
323 case SIGNAL_TYPE_DISPLAY_PORT_MST:
324 /* MST does not use I2COverAux, but there is the
325 * SPECIAL use case for "immediate dwnstrm device
326 * access" (EPR#370830).
328 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
335 return transaction_type;
338 static enum signal_type get_basic_signal_type(struct graphics_object_id encoder,
339 struct graphics_object_id downstream)
341 if (downstream.type == OBJECT_TYPE_CONNECTOR) {
342 switch (downstream.id) {
343 case CONNECTOR_ID_SINGLE_LINK_DVII:
344 switch (encoder.id) {
345 case ENCODER_ID_INTERNAL_DAC1:
346 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
347 case ENCODER_ID_INTERNAL_DAC2:
348 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
349 return SIGNAL_TYPE_RGB;
351 return SIGNAL_TYPE_DVI_SINGLE_LINK;
354 case CONNECTOR_ID_DUAL_LINK_DVII:
356 switch (encoder.id) {
357 case ENCODER_ID_INTERNAL_DAC1:
358 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
359 case ENCODER_ID_INTERNAL_DAC2:
360 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
361 return SIGNAL_TYPE_RGB;
363 return SIGNAL_TYPE_DVI_DUAL_LINK;
367 case CONNECTOR_ID_SINGLE_LINK_DVID:
368 return SIGNAL_TYPE_DVI_SINGLE_LINK;
369 case CONNECTOR_ID_DUAL_LINK_DVID:
370 return SIGNAL_TYPE_DVI_DUAL_LINK;
371 case CONNECTOR_ID_VGA:
372 return SIGNAL_TYPE_RGB;
373 case CONNECTOR_ID_HDMI_TYPE_A:
374 return SIGNAL_TYPE_HDMI_TYPE_A;
375 case CONNECTOR_ID_LVDS:
376 return SIGNAL_TYPE_LVDS;
377 case CONNECTOR_ID_DISPLAY_PORT:
378 return SIGNAL_TYPE_DISPLAY_PORT;
379 case CONNECTOR_ID_EDP:
380 return SIGNAL_TYPE_EDP;
382 return SIGNAL_TYPE_NONE;
384 } else if (downstream.type == OBJECT_TYPE_ENCODER) {
385 switch (downstream.id) {
386 case ENCODER_ID_EXTERNAL_NUTMEG:
387 case ENCODER_ID_EXTERNAL_TRAVIS:
388 return SIGNAL_TYPE_DISPLAY_PORT;
390 return SIGNAL_TYPE_NONE;
394 return SIGNAL_TYPE_NONE;
398 * dc_link_is_dp_sink_present() - Check if there is a native DP
399 * or passive DP-HDMI dongle connected
401 bool dc_link_is_dp_sink_present(struct dc_link *link)
403 enum gpio_result gpio_result;
404 uint32_t clock_pin = 0;
408 enum connector_id connector_id =
409 dal_graphics_object_id_get_connector_id(link->link_id);
412 ((connector_id == CONNECTOR_ID_DISPLAY_PORT) ||
413 (connector_id == CONNECTOR_ID_EDP));
415 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
422 /* Open GPIO and set it to I2C mode */
423 /* Note: this GpioMode_Input will be converted
424 * to GpioConfigType_I2cAuxDualMode in GPIO component,
425 * which indicates we need additional delay
428 if (dal_ddc_open(ddc, GPIO_MODE_INPUT,
429 GPIO_DDC_CONFIG_TYPE_MODE_I2C) != GPIO_RESULT_OK) {
436 * Read GPIO: DP sink is present if both clock and data pins are zero
438 * [W/A] plug-unplug DP cable, sometimes customer board has
439 * one short pulse on clk_pin(1V, < 1ms). DP will be config to HDMI/DVI
440 * then monitor can't br light up. Add retry 3 times
441 * But in real passive dongle, it need additional 3ms to detect
444 gpio_result = dal_gpio_get_value(ddc->pin_clock, &clock_pin);
445 ASSERT(gpio_result == GPIO_RESULT_OK);
450 } while (retry++ < 3);
452 present = (gpio_result == GPIO_RESULT_OK) && !clock_pin;
461 * Detect output sink type
463 static enum signal_type link_detect_sink(struct dc_link *link,
464 enum dc_detect_reason reason)
466 enum signal_type result;
467 struct graphics_object_id enc_id;
469 if (link->is_dig_mapping_flexible)
470 enc_id = (struct graphics_object_id){.id = ENCODER_ID_UNKNOWN};
472 enc_id = link->link_enc->id;
473 result = get_basic_signal_type(enc_id, link->link_id);
475 /* Use basic signal type for link without physical connector. */
476 if (link->ep_type != DISPLAY_ENDPOINT_PHY)
479 /* Internal digital encoder will detect only dongles
480 * that require digital signal
483 /* Detection mechanism is different
484 * for different native connectors.
485 * LVDS connector supports only LVDS signal;
486 * PCIE is a bus slot, the actual connector needs to be detected first;
487 * eDP connector supports only eDP signal;
488 * HDMI should check straps for audio
491 /* PCIE detects the actual connector on add-on board */
492 if (link->link_id.id == CONNECTOR_ID_PCIE) {
493 /* ZAZTODO implement PCIE add-on card detection */
496 switch (link->link_id.id) {
497 case CONNECTOR_ID_HDMI_TYPE_A: {
498 /* check audio support:
499 * if native HDMI is not supported, switch to DVI
501 struct audio_support *aud_support =
502 &link->dc->res_pool->audio_support;
504 if (!aud_support->hdmi_audio_native)
505 if (link->link_id.id == CONNECTOR_ID_HDMI_TYPE_A)
506 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
509 case CONNECTOR_ID_DISPLAY_PORT: {
510 /* DP HPD short pulse. Passive DP dongle will not
513 if (reason != DETECT_REASON_HPDRX) {
514 /* Check whether DP signal detected: if not -
515 * we assume signal is DVI; it could be corrected
516 * to HDMI after dongle detection
518 if (!dm_helpers_is_dp_sink_present(link))
519 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
530 static enum signal_type decide_signal_from_strap_and_dongle_type(enum display_dongle_type dongle_type,
531 struct audio_support *audio_support)
533 enum signal_type signal = SIGNAL_TYPE_NONE;
535 switch (dongle_type) {
536 case DISPLAY_DONGLE_DP_HDMI_DONGLE:
537 if (audio_support->hdmi_audio_on_dongle)
538 signal = SIGNAL_TYPE_HDMI_TYPE_A;
540 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
542 case DISPLAY_DONGLE_DP_DVI_DONGLE:
543 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
545 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE:
546 if (audio_support->hdmi_audio_native)
547 signal = SIGNAL_TYPE_HDMI_TYPE_A;
549 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
552 signal = SIGNAL_TYPE_NONE;
559 static enum signal_type dp_passive_dongle_detection(struct ddc_service *ddc,
560 struct display_sink_capability *sink_cap,
561 struct audio_support *audio_support)
563 dal_ddc_service_i2c_query_dp_dual_mode_adaptor(ddc, sink_cap);
565 return decide_signal_from_strap_and_dongle_type(sink_cap->dongle_type,
569 static void link_disconnect_sink(struct dc_link *link)
571 if (link->local_sink) {
572 dc_sink_release(link->local_sink);
573 link->local_sink = NULL;
576 link->dpcd_sink_count = 0;
577 //link->dpcd_caps.dpcd_rev.raw = 0;
580 static void link_disconnect_remap(struct dc_sink *prev_sink, struct dc_link *link)
582 dc_sink_release(link->local_sink);
583 link->local_sink = prev_sink;
586 #if defined(CONFIG_DRM_AMD_DC_HDCP)
587 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal)
592 case SIGNAL_TYPE_DISPLAY_PORT:
593 case SIGNAL_TYPE_DISPLAY_PORT_MST:
594 ret = link->hdcp_caps.bcaps.bits.HDCP_CAPABLE;
596 case SIGNAL_TYPE_DVI_SINGLE_LINK:
597 case SIGNAL_TYPE_DVI_DUAL_LINK:
598 case SIGNAL_TYPE_HDMI_TYPE_A:
599 /* HDMI doesn't tell us its HDCP(1.4) capability, so assume to always be capable,
600 * we can poll for bksv but some displays have an issue with this. Since its so rare
601 * for a display to not be 1.4 capable, this assumtion is ok
611 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal)
616 case SIGNAL_TYPE_DISPLAY_PORT:
617 case SIGNAL_TYPE_DISPLAY_PORT_MST:
618 ret = (link->hdcp_caps.bcaps.bits.HDCP_CAPABLE &&
619 link->hdcp_caps.rx_caps.fields.byte0.hdcp_capable &&
620 (link->hdcp_caps.rx_caps.fields.version == 0x2)) ? 1 : 0;
622 case SIGNAL_TYPE_DVI_SINGLE_LINK:
623 case SIGNAL_TYPE_DVI_DUAL_LINK:
624 case SIGNAL_TYPE_HDMI_TYPE_A:
625 ret = (link->hdcp_caps.rx_caps.fields.version == 0x4) ? 1:0;
634 static void query_hdcp_capability(enum signal_type signal, struct dc_link *link)
636 struct hdcp_protection_message msg22;
637 struct hdcp_protection_message msg14;
639 memset(&msg22, 0, sizeof(struct hdcp_protection_message));
640 memset(&msg14, 0, sizeof(struct hdcp_protection_message));
641 memset(link->hdcp_caps.rx_caps.raw, 0,
642 sizeof(link->hdcp_caps.rx_caps.raw));
644 if ((link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
645 link->ddc->transaction_type ==
646 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) ||
647 link->connector_signal == SIGNAL_TYPE_EDP) {
648 msg22.data = link->hdcp_caps.rx_caps.raw;
649 msg22.length = sizeof(link->hdcp_caps.rx_caps.raw);
650 msg22.msg_id = HDCP_MESSAGE_ID_RX_CAPS;
652 msg22.data = &link->hdcp_caps.rx_caps.fields.version;
653 msg22.length = sizeof(link->hdcp_caps.rx_caps.fields.version);
654 msg22.msg_id = HDCP_MESSAGE_ID_HDCP2VERSION;
656 msg22.version = HDCP_VERSION_22;
657 msg22.link = HDCP_LINK_PRIMARY;
658 msg22.max_retries = 5;
659 dc_process_hdcp_msg(signal, link, &msg22);
661 if (signal == SIGNAL_TYPE_DISPLAY_PORT || signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
662 msg14.data = &link->hdcp_caps.bcaps.raw;
663 msg14.length = sizeof(link->hdcp_caps.bcaps.raw);
664 msg14.msg_id = HDCP_MESSAGE_ID_READ_BCAPS;
665 msg14.version = HDCP_VERSION_14;
666 msg14.link = HDCP_LINK_PRIMARY;
667 msg14.max_retries = 5;
669 dc_process_hdcp_msg(signal, link, &msg14);
675 static void read_current_link_settings_on_detect(struct dc_link *link)
677 union lane_count_set lane_count_set = {0};
679 uint8_t link_rate_set;
680 uint32_t read_dpcd_retry_cnt = 10;
681 enum dc_status status = DC_ERROR_UNEXPECTED;
683 union max_down_spread max_down_spread = {0};
685 // Read DPCD 00101h to find out the number of lanes currently set
686 for (i = 0; i < read_dpcd_retry_cnt; i++) {
687 status = core_link_read_dpcd(link,
690 sizeof(lane_count_set));
691 /* First DPCD read after VDD ON can fail if the particular board
692 * does not have HPD pin wired correctly. So if DPCD read fails,
693 * which it should never happen, retry a few times. Target worst
694 * case scenario of 80 ms.
696 if (status == DC_OK) {
697 link->cur_link_settings.lane_count =
698 lane_count_set.bits.LANE_COUNT_SET;
705 // Read DPCD 00100h to find if standard link rates are set
706 core_link_read_dpcd(link, DP_LINK_BW_SET,
707 &link_bw_set, sizeof(link_bw_set));
709 if (link_bw_set == 0) {
710 if (link->connector_signal == SIGNAL_TYPE_EDP) {
711 /* If standard link rates are not being used,
712 * Read DPCD 00115h to find the edp link rate set used
714 core_link_read_dpcd(link, DP_LINK_RATE_SET,
715 &link_rate_set, sizeof(link_rate_set));
717 // edp_supported_link_rates_count = 0 for DP
718 if (link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
719 link->cur_link_settings.link_rate =
720 link->dpcd_caps.edp_supported_link_rates[link_rate_set];
721 link->cur_link_settings.link_rate_set = link_rate_set;
722 link->cur_link_settings.use_link_rate_set = true;
725 // Link Rate not found. Seamless boot may not work.
729 link->cur_link_settings.link_rate = link_bw_set;
730 link->cur_link_settings.use_link_rate_set = false;
732 // Read DPCD 00003h to find the max down spread.
733 core_link_read_dpcd(link, DP_MAX_DOWNSPREAD,
734 &max_down_spread.raw, sizeof(max_down_spread));
735 link->cur_link_settings.link_spread =
736 max_down_spread.bits.MAX_DOWN_SPREAD ?
737 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
740 static bool detect_dp(struct dc_link *link,
741 struct display_sink_capability *sink_caps,
742 enum dc_detect_reason reason)
744 struct audio_support *audio_support = &link->dc->res_pool->audio_support;
746 sink_caps->signal = link_detect_sink(link, reason);
747 sink_caps->transaction_type =
748 get_ddc_transaction_type(sink_caps->signal);
750 if (sink_caps->transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
751 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
752 if (!detect_dp_sink_caps(link))
754 if (is_mst_supported(link)) {
755 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
756 link->type = dc_connection_mst_branch;
758 dal_ddc_service_set_transaction_type(link->ddc,
759 sink_caps->transaction_type);
761 #if defined(CONFIG_DRM_AMD_DC_DCN)
762 /* Apply work around for tunneled MST on certain USB4 docks. Always use DSC if dock
763 * reports DSC support.
765 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA &&
766 link->type == dc_connection_mst_branch &&
767 link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_90CC24 &&
768 link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT &&
769 !link->dc->debug.dpia_debug.bits.disable_mst_dsc_work_around)
770 link->wa_flags.dpia_mst_dsc_always_on = true;
773 #if defined(CONFIG_DRM_AMD_DC_HDCP)
774 /* In case of fallback to SST when topology discovery below fails
775 * HDCP caps will be querried again later by the upper layer (caller
776 * of this function). */
777 query_hdcp_capability(SIGNAL_TYPE_DISPLAY_PORT_MST, link);
781 if (link->type != dc_connection_mst_branch &&
782 is_dp_branch_device(link))
784 link->type = dc_connection_sst_branch;
786 /* DP passive dongles */
787 sink_caps->signal = dp_passive_dongle_detection(link->ddc,
790 link->dpcd_caps.dongle_type = sink_caps->dongle_type;
791 link->dpcd_caps.dpcd_rev.raw = 0;
797 static bool is_same_edid(struct dc_edid *old_edid, struct dc_edid *new_edid)
799 if (old_edid->length != new_edid->length)
802 if (new_edid->length == 0)
805 return (memcmp(old_edid->raw_edid,
806 new_edid->raw_edid, new_edid->length) == 0);
809 static bool wait_for_entering_dp_alt_mode(struct dc_link *link)
812 * something is terribly wrong if time out is > 200ms. (5Hz)
813 * 500 microseconds * 400 tries us 200 ms
815 unsigned int sleep_time_in_microseconds = 500;
816 unsigned int tries_allowed = 400;
818 unsigned long long enter_timestamp;
819 unsigned long long finish_timestamp;
820 unsigned long long time_taken_in_ns;
823 DC_LOGGER_INIT(link->ctx->logger);
825 if (!link->link_enc->funcs->is_in_alt_mode)
828 is_in_alt_mode = link->link_enc->funcs->is_in_alt_mode(link->link_enc);
829 DC_LOG_WARNING("DP Alt mode state on HPD: %d\n", is_in_alt_mode);
834 enter_timestamp = dm_get_timestamp(link->ctx);
836 for (tries_taken = 0; tries_taken < tries_allowed; tries_taken++) {
837 udelay(sleep_time_in_microseconds);
838 /* ask the link if alt mode is enabled, if so return ok */
839 if (link->link_enc->funcs->is_in_alt_mode(link->link_enc)) {
840 finish_timestamp = dm_get_timestamp(link->ctx);
842 dm_get_elapse_time_in_ns(link->ctx,
845 DC_LOG_WARNING("Alt mode entered finished after %llu ms\n",
846 div_u64(time_taken_in_ns, 1000000));
850 finish_timestamp = dm_get_timestamp(link->ctx);
851 time_taken_in_ns = dm_get_elapse_time_in_ns(link->ctx, finish_timestamp,
853 DC_LOG_WARNING("Alt mode has timed out after %llu ms\n",
854 div_u64(time_taken_in_ns, 1000000));
859 * dc_link_detect() - Detect if a sink is attached to a given link
861 * link->local_sink is created or destroyed as needed.
863 * This does not create remote sinks but will trigger DM
864 * to start MST detection if a branch is detected.
866 static bool dc_link_detect_helper(struct dc_link *link,
867 enum dc_detect_reason reason)
869 struct dc_sink_init_data sink_init_data = { 0 };
870 struct display_sink_capability sink_caps = { 0 };
872 bool converter_disable_audio = false;
873 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
874 bool same_edid = false;
875 enum dc_edid_status edid_status;
876 struct dc_context *dc_ctx = link->ctx;
877 struct dc_sink *sink = NULL;
878 struct dc_sink *prev_sink = NULL;
879 struct dpcd_caps prev_dpcd_caps;
880 enum dc_connection_type new_connection_type = dc_connection_none;
881 enum dc_connection_type pre_connection_type = dc_connection_none;
882 bool perform_dp_seamless_boot = false;
883 const uint32_t post_oui_delay = 30; // 30ms
885 DC_LOGGER_INIT(link->ctx->logger);
887 if (dc_is_virtual_signal(link->connector_signal))
890 if (((link->connector_signal == SIGNAL_TYPE_LVDS ||
891 link->connector_signal == SIGNAL_TYPE_EDP) &&
892 (!link->dc->config.allow_edp_hotplug_detection)) &&
894 // need to re-write OUI and brightness in resume case
895 if (link->connector_signal == SIGNAL_TYPE_EDP) {
896 dpcd_set_source_specific_data(link);
897 msleep(post_oui_delay);
898 dc_link_set_default_brightness_aux(link);
905 if (!dc_link_detect_sink(link, &new_connection_type)) {
910 prev_sink = link->local_sink;
912 dc_sink_retain(prev_sink);
913 memcpy(&prev_dpcd_caps, &link->dpcd_caps, sizeof(struct dpcd_caps));
916 link_disconnect_sink(link);
917 if (new_connection_type != dc_connection_none) {
918 pre_connection_type = link->type;
919 link->type = new_connection_type;
920 link->link_state_valid = false;
922 /* From Disconnected-to-Connected. */
923 switch (link->connector_signal) {
924 case SIGNAL_TYPE_HDMI_TYPE_A: {
925 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
926 if (aud_support->hdmi_audio_native)
927 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A;
929 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
933 case SIGNAL_TYPE_DVI_SINGLE_LINK: {
934 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
935 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
939 case SIGNAL_TYPE_DVI_DUAL_LINK: {
940 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
941 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK;
945 case SIGNAL_TYPE_LVDS: {
946 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
947 sink_caps.signal = SIGNAL_TYPE_LVDS;
951 case SIGNAL_TYPE_EDP: {
952 read_current_link_settings_on_detect(link);
954 detect_edp_sink_caps(link);
955 read_current_link_settings_on_detect(link);
956 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
957 sink_caps.signal = SIGNAL_TYPE_EDP;
961 case SIGNAL_TYPE_DISPLAY_PORT: {
962 /* wa HPD high coming too early*/
963 if (link->ep_type == DISPLAY_ENDPOINT_PHY &&
964 link->link_enc->features.flags.bits.DP_IS_USB_C == 1) {
965 /* if alt mode times out, return false */
966 if (!wait_for_entering_dp_alt_mode(link))
970 if (!detect_dp(link, &sink_caps, reason)) {
972 dc_sink_release(prev_sink);
976 #if defined(CONFIG_DRM_AMD_DC_DCN)
977 if (dp_get_link_encoding_format(&link->reported_link_cap) == DP_128b_132b_ENCODING)
978 add_dp_hpo_link_encoder_to_link(link);
981 if (link->type == dc_connection_mst_branch) {
982 LINK_INFO("link=%d, mst branch is now Connected\n",
984 /* Need to setup mst link_cap struct here
985 * otherwise dc_link_detect() will leave mst link_cap
986 * empty which leads to allocate_mst_payload() has "0"
987 * pbn_per_slot value leading to exception on dc_fixpt_div()
989 dp_verify_mst_link_cap(link);
992 * This call will initiate MST topology discovery. Which
993 * will detect MST ports and add new DRM connector DRM
994 * framework. Then read EDID via remote i2c over aux. In
995 * the end, will notify DRM detect result and save EDID
996 * into DRM framework.
998 * .detect is called by .fill_modes.
999 * .fill_modes is called by user mode ioctl
1000 * DRM_IOCTL_MODE_GETCONNECTOR.
1002 * .get_modes is called by .fill_modes.
1004 * call .get_modes, AMDGPU DM implementation will create
1005 * new dc_sink and add to dc_link. For long HPD plug
1006 * in/out, MST has its own handle.
1008 * Therefore, just after dc_create, link->sink is not
1009 * created for MST until user mode app calls
1010 * DRM_IOCTL_MODE_GETCONNECTOR.
1012 * Need check ->sink usages in case ->sink = NULL
1013 * TODO: s3 resume check
1016 dm_helpers_dp_update_branch_info(link->ctx, link);
1017 if (dm_helpers_dp_mst_start_top_mgr(link->ctx,
1018 link, reason == DETECT_REASON_BOOT)) {
1020 dc_sink_release(prev_sink);
1023 link->type = dc_connection_sst_branch;
1024 sink_caps.signal = SIGNAL_TYPE_DISPLAY_PORT;
1028 /* Active SST downstream branch device unplug*/
1029 if (link->type == dc_connection_sst_branch &&
1030 link->dpcd_caps.sink_count.bits.SINK_COUNT == 0) {
1032 /* Downstream unplug */
1033 dc_sink_release(prev_sink);
1037 /* disable audio for non DP to HDMI active sst converter */
1038 if (link->type == dc_connection_sst_branch &&
1039 is_dp_active_dongle(link) &&
1040 (link->dpcd_caps.dongle_type !=
1041 DISPLAY_DONGLE_DP_HDMI_CONVERTER))
1042 converter_disable_audio = true;
1044 // link switch from MST to non-MST stop topology manager
1045 if (pre_connection_type == dc_connection_mst_branch &&
1046 link->type != dc_connection_mst_branch)
1047 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
1050 // For seamless boot, to skip verify link cap, we read UEFI settings and set them as verified.
1051 if (reason == DETECT_REASON_BOOT &&
1052 !dc_ctx->dc->config.power_down_display_on_boot &&
1053 link->link_status.link_active)
1054 perform_dp_seamless_boot = true;
1056 if (perform_dp_seamless_boot) {
1057 read_current_link_settings_on_detect(link);
1058 link->verified_link_cap = link->reported_link_cap;
1065 DC_ERROR("Invalid connector type! signal:%d\n",
1066 link->connector_signal);
1068 dc_sink_release(prev_sink);
1072 if (link->dpcd_caps.sink_count.bits.SINK_COUNT)
1073 link->dpcd_sink_count =
1074 link->dpcd_caps.sink_count.bits.SINK_COUNT;
1076 link->dpcd_sink_count = 1;
1078 dal_ddc_service_set_transaction_type(link->ddc,
1079 sink_caps.transaction_type);
1082 dal_ddc_service_is_in_aux_transaction_mode(link->ddc);
1084 sink_init_data.link = link;
1085 sink_init_data.sink_signal = sink_caps.signal;
1087 sink = dc_sink_create(&sink_init_data);
1089 DC_ERROR("Failed to create sink!\n");
1091 dc_sink_release(prev_sink);
1095 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock;
1096 sink->converter_disable_audio = converter_disable_audio;
1098 /* dc_sink_create returns a new reference */
1099 link->local_sink = sink;
1101 edid_status = dm_helpers_read_local_edid(link->ctx,
1104 switch (edid_status) {
1105 case EDID_BAD_CHECKSUM:
1106 DC_LOG_ERROR("EDID checksum invalid.\n");
1108 case EDID_NO_RESPONSE:
1109 DC_LOG_ERROR("No EDID read.\n");
1111 * Abort detection for non-DP connectors if we have
1114 * DP needs to report as connected if HDP is high
1115 * even if we have no EDID in order to go to
1118 if (dc_is_hdmi_signal(link->connector_signal) ||
1119 dc_is_dvi_signal(link->connector_signal)) {
1121 dc_sink_release(prev_sink);
1130 // Check if edid is the same
1132 (edid_status == EDID_THE_SAME || edid_status == EDID_OK))
1133 same_edid = is_same_edid(&prev_sink->dc_edid,
1136 if (sink->edid_caps.panel_patch.skip_scdc_overwrite)
1137 link->ctx->dc->debug.hdmi20_disable = true;
1139 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
1140 sink_caps.transaction_type ==
1141 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
1143 * TODO debug why Dell 2413 doesn't like
1144 * two link trainings
1146 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1147 query_hdcp_capability(sink->sink_signal, link);
1150 // verify link cap for SST non-seamless boot
1151 if (!perform_dp_seamless_boot)
1152 dp_verify_link_cap_with_retries(link,
1153 &link->reported_link_cap,
1154 LINK_TRAINING_MAX_VERIFY_RETRY);
1156 // If edid is the same, then discard new sink and revert back to original sink
1158 link_disconnect_remap(prev_sink, link);
1162 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1163 query_hdcp_capability(sink->sink_signal, link);
1167 /* HDMI-DVI Dongle */
1168 if (sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A &&
1169 !sink->edid_caps.edid_hdmi)
1170 sink->sink_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1172 /* Connectivity log: detection */
1173 for (i = 0; i < sink->dc_edid.length / DC_EDID_BLOCK_SIZE; i++) {
1174 CONN_DATA_DETECT(link,
1175 &sink->dc_edid.raw_edid[i * DC_EDID_BLOCK_SIZE],
1177 "%s: [Block %d] ", sink->edid_caps.display_name, i);
1180 DC_LOG_DETECTION_EDID_PARSER("%s: "
1181 "manufacturer_id = %X, "
1183 "serial_number = %X, "
1184 "manufacture_week = %d, "
1185 "manufacture_year = %d, "
1186 "display_name = %s, "
1187 "speaker_flag = %d, "
1188 "audio_mode_count = %d\n",
1190 sink->edid_caps.manufacturer_id,
1191 sink->edid_caps.product_id,
1192 sink->edid_caps.serial_number,
1193 sink->edid_caps.manufacture_week,
1194 sink->edid_caps.manufacture_year,
1195 sink->edid_caps.display_name,
1196 sink->edid_caps.speaker_flags,
1197 sink->edid_caps.audio_mode_count);
1199 for (i = 0; i < sink->edid_caps.audio_mode_count; i++) {
1200 DC_LOG_DETECTION_EDID_PARSER("%s: mode number = %d, "
1201 "format_code = %d, "
1202 "channel_count = %d, "
1203 "sample_rate = %d, "
1204 "sample_size = %d\n",
1207 sink->edid_caps.audio_modes[i].format_code,
1208 sink->edid_caps.audio_modes[i].channel_count,
1209 sink->edid_caps.audio_modes[i].sample_rate,
1210 sink->edid_caps.audio_modes[i].sample_size);
1213 /* From Connected-to-Disconnected. */
1214 if (link->type == dc_connection_mst_branch) {
1215 LINK_INFO("link=%d, mst branch is now Disconnected\n",
1218 /* Disable work around which keeps DSC on for tunneled MST on certain USB4 docks. */
1219 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
1220 link->wa_flags.dpia_mst_dsc_always_on = false;
1222 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
1224 link->mst_stream_alloc_table.stream_count = 0;
1225 memset(link->mst_stream_alloc_table.stream_allocations,
1227 sizeof(link->mst_stream_alloc_table.stream_allocations));
1230 #if defined(CONFIG_DRM_AMD_DC_DCN)
1231 if (dp_get_link_encoding_format(&link->cur_link_settings) == DP_128b_132b_ENCODING)
1232 reset_dp_hpo_stream_encoders_for_link(link);
1235 link->type = dc_connection_none;
1236 sink_caps.signal = SIGNAL_TYPE_NONE;
1237 /* When we unplug a passive DP-HDMI dongle connection, dongle_max_pix_clk
1238 * is not cleared. If we emulate a DP signal on this connection, it thinks
1239 * the dongle is still there and limits the number of modes we can emulate.
1240 * Clear dongle_max_pix_clk on disconnect to fix this
1242 link->dongle_max_pix_clk = 0;
1245 LINK_INFO("link=%d, dc_sink_in=%p is now %s prev_sink=%p edid same=%d\n",
1246 link->link_index, sink,
1247 (sink_caps.signal ==
1248 SIGNAL_TYPE_NONE ? "Disconnected" : "Connected"),
1249 prev_sink, same_edid);
1252 dc_sink_release(prev_sink);
1257 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
1259 const struct dc *dc = link->dc;
1261 bool can_apply_seamless_boot = false;
1264 for (i = 0; i < dc->current_state->stream_count; i++) {
1265 if (dc->current_state->streams[i]->apply_seamless_boot_optimization) {
1266 can_apply_seamless_boot = true;
1271 #if defined(CONFIG_DRM_AMD_DC_DCN)
1275 /* get out of low power state */
1276 if (!can_apply_seamless_boot && reason != DETECT_REASON_BOOT)
1277 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
1279 ret = dc_link_detect_helper(link, reason);
1281 /* Go back to power optimized state */
1282 if (!can_apply_seamless_boot && reason != DETECT_REASON_BOOT)
1283 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
1288 bool dc_link_get_hpd_state(struct dc_link *dc_link)
1292 dal_gpio_lock_pin(dc_link->hpd_gpio);
1293 dal_gpio_get_value(dc_link->hpd_gpio, &state);
1294 dal_gpio_unlock_pin(dc_link->hpd_gpio);
1299 static enum hpd_source_id get_hpd_line(struct dc_link *link)
1302 enum hpd_source_id hpd_id = HPD_SOURCEID_UNKNOWN;
1304 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1305 link->ctx->gpio_service);
1308 switch (dal_irq_get_source(hpd)) {
1309 case DC_IRQ_SOURCE_HPD1:
1310 hpd_id = HPD_SOURCEID1;
1312 case DC_IRQ_SOURCE_HPD2:
1313 hpd_id = HPD_SOURCEID2;
1315 case DC_IRQ_SOURCE_HPD3:
1316 hpd_id = HPD_SOURCEID3;
1318 case DC_IRQ_SOURCE_HPD4:
1319 hpd_id = HPD_SOURCEID4;
1321 case DC_IRQ_SOURCE_HPD5:
1322 hpd_id = HPD_SOURCEID5;
1324 case DC_IRQ_SOURCE_HPD6:
1325 hpd_id = HPD_SOURCEID6;
1328 BREAK_TO_DEBUGGER();
1332 dal_gpio_destroy_irq(&hpd);
1338 static enum channel_id get_ddc_line(struct dc_link *link)
1341 enum channel_id channel = CHANNEL_ID_UNKNOWN;
1343 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
1346 switch (dal_ddc_get_line(ddc)) {
1347 case GPIO_DDC_LINE_DDC1:
1348 channel = CHANNEL_ID_DDC1;
1350 case GPIO_DDC_LINE_DDC2:
1351 channel = CHANNEL_ID_DDC2;
1353 case GPIO_DDC_LINE_DDC3:
1354 channel = CHANNEL_ID_DDC3;
1356 case GPIO_DDC_LINE_DDC4:
1357 channel = CHANNEL_ID_DDC4;
1359 case GPIO_DDC_LINE_DDC5:
1360 channel = CHANNEL_ID_DDC5;
1362 case GPIO_DDC_LINE_DDC6:
1363 channel = CHANNEL_ID_DDC6;
1365 case GPIO_DDC_LINE_DDC_VGA:
1366 channel = CHANNEL_ID_DDC_VGA;
1368 case GPIO_DDC_LINE_I2C_PAD:
1369 channel = CHANNEL_ID_I2C_PAD;
1372 BREAK_TO_DEBUGGER();
1380 static enum transmitter translate_encoder_to_transmitter(struct graphics_object_id encoder)
1382 switch (encoder.id) {
1383 case ENCODER_ID_INTERNAL_UNIPHY:
1384 switch (encoder.enum_id) {
1386 return TRANSMITTER_UNIPHY_A;
1388 return TRANSMITTER_UNIPHY_B;
1390 return TRANSMITTER_UNKNOWN;
1393 case ENCODER_ID_INTERNAL_UNIPHY1:
1394 switch (encoder.enum_id) {
1396 return TRANSMITTER_UNIPHY_C;
1398 return TRANSMITTER_UNIPHY_D;
1400 return TRANSMITTER_UNKNOWN;
1403 case ENCODER_ID_INTERNAL_UNIPHY2:
1404 switch (encoder.enum_id) {
1406 return TRANSMITTER_UNIPHY_E;
1408 return TRANSMITTER_UNIPHY_F;
1410 return TRANSMITTER_UNKNOWN;
1413 case ENCODER_ID_INTERNAL_UNIPHY3:
1414 switch (encoder.enum_id) {
1416 return TRANSMITTER_UNIPHY_G;
1418 return TRANSMITTER_UNKNOWN;
1421 case ENCODER_ID_EXTERNAL_NUTMEG:
1422 switch (encoder.enum_id) {
1424 return TRANSMITTER_NUTMEG_CRT;
1426 return TRANSMITTER_UNKNOWN;
1429 case ENCODER_ID_EXTERNAL_TRAVIS:
1430 switch (encoder.enum_id) {
1432 return TRANSMITTER_TRAVIS_CRT;
1434 return TRANSMITTER_TRAVIS_LCD;
1436 return TRANSMITTER_UNKNOWN;
1440 return TRANSMITTER_UNKNOWN;
1444 static bool dc_link_construct_legacy(struct dc_link *link,
1445 const struct link_init_data *init_params)
1448 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1449 struct dc_context *dc_ctx = init_params->ctx;
1450 struct encoder_init_data enc_init_data = { 0 };
1451 struct panel_cntl_init_data panel_cntl_init_data = { 0 };
1452 struct integrated_info *info;
1453 struct dc_bios *bios = init_params->dc->ctx->dc_bios;
1454 const struct dc_vbios_funcs *bp_funcs = bios->funcs;
1455 struct bp_disp_connector_caps_info disp_connect_caps_info = { 0 };
1457 DC_LOGGER_INIT(dc_ctx->logger);
1459 info = kzalloc(sizeof(*info), GFP_KERNEL);
1463 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1464 link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
1466 link->link_status.dpcd_caps = &link->dpcd_caps;
1468 link->dc = init_params->dc;
1470 link->link_index = init_params->link_index;
1472 memset(&link->preferred_training_settings, 0,
1473 sizeof(struct dc_link_training_overrides));
1474 memset(&link->preferred_link_setting, 0,
1475 sizeof(struct dc_link_settings));
1478 bios->funcs->get_connector_id(bios, init_params->connector_index);
1480 link->ep_type = DISPLAY_ENDPOINT_PHY;
1482 DC_LOG_DC("BIOS object table - link_id: %d", link->link_id.id);
1484 if (bios->funcs->get_disp_connector_caps_info) {
1485 bios->funcs->get_disp_connector_caps_info(bios, link->link_id, &disp_connect_caps_info);
1486 link->is_internal_display = disp_connect_caps_info.INTERNAL_DISPLAY;
1487 DC_LOG_DC("BIOS object table - is_internal_display: %d", link->is_internal_display);
1490 if (link->link_id.type != OBJECT_TYPE_CONNECTOR) {
1491 dm_output_to_console("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d! type %d expected %d\n",
1492 __func__, init_params->connector_index,
1493 link->link_id.type, OBJECT_TYPE_CONNECTOR);
1497 if (link->dc->res_pool->funcs->link_init)
1498 link->dc->res_pool->funcs->link_init(link);
1500 link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1501 link->ctx->gpio_service);
1503 if (link->hpd_gpio) {
1504 dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
1505 dal_gpio_unlock_pin(link->hpd_gpio);
1506 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
1508 DC_LOG_DC("BIOS object table - hpd_gpio id: %d", link->hpd_gpio->id);
1509 DC_LOG_DC("BIOS object table - hpd_gpio en: %d", link->hpd_gpio->en);
1512 switch (link->link_id.id) {
1513 case CONNECTOR_ID_HDMI_TYPE_A:
1514 link->connector_signal = SIGNAL_TYPE_HDMI_TYPE_A;
1517 case CONNECTOR_ID_SINGLE_LINK_DVID:
1518 case CONNECTOR_ID_SINGLE_LINK_DVII:
1519 link->connector_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1521 case CONNECTOR_ID_DUAL_LINK_DVID:
1522 case CONNECTOR_ID_DUAL_LINK_DVII:
1523 link->connector_signal = SIGNAL_TYPE_DVI_DUAL_LINK;
1525 case CONNECTOR_ID_DISPLAY_PORT:
1526 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1529 link->irq_source_hpd_rx =
1530 dal_irq_get_rx_source(link->hpd_gpio);
1533 case CONNECTOR_ID_EDP:
1534 link->connector_signal = SIGNAL_TYPE_EDP;
1536 if (link->hpd_gpio) {
1537 if (!link->dc->config.allow_edp_hotplug_detection)
1538 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1539 link->irq_source_hpd_rx =
1540 dal_irq_get_rx_source(link->hpd_gpio);
1544 case CONNECTOR_ID_LVDS:
1545 link->connector_signal = SIGNAL_TYPE_LVDS;
1548 DC_LOG_WARNING("Unsupported Connector type:%d!\n",
1553 /* TODO: #DAL3 Implement id to str function.*/
1554 LINK_INFO("Connector[%d] description:"
1556 init_params->connector_index,
1557 link->connector_signal);
1559 ddc_service_init_data.ctx = link->ctx;
1560 ddc_service_init_data.id = link->link_id;
1561 ddc_service_init_data.link = link;
1562 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1565 DC_ERROR("Failed to create ddc_service!\n");
1566 goto ddc_create_fail;
1569 if (!link->ddc->ddc_pin) {
1570 DC_ERROR("Failed to get I2C info for connector!\n");
1571 goto ddc_create_fail;
1575 dal_ddc_get_line(dal_ddc_service_get_ddc_pin(link->ddc));
1578 if (link->dc->res_pool->funcs->panel_cntl_create &&
1579 (link->link_id.id == CONNECTOR_ID_EDP ||
1580 link->link_id.id == CONNECTOR_ID_LVDS)) {
1581 panel_cntl_init_data.ctx = dc_ctx;
1582 panel_cntl_init_data.inst =
1583 panel_cntl_init_data.ctx->dc_edp_id_count;
1585 link->dc->res_pool->funcs->panel_cntl_create(
1586 &panel_cntl_init_data);
1587 panel_cntl_init_data.ctx->dc_edp_id_count++;
1589 if (link->panel_cntl == NULL) {
1590 DC_ERROR("Failed to create link panel_cntl!\n");
1591 goto panel_cntl_create_fail;
1595 enc_init_data.ctx = dc_ctx;
1596 bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0,
1597 &enc_init_data.encoder);
1598 enc_init_data.connector = link->link_id;
1599 enc_init_data.channel = get_ddc_line(link);
1600 enc_init_data.hpd_source = get_hpd_line(link);
1602 link->hpd_src = enc_init_data.hpd_source;
1604 enc_init_data.transmitter =
1605 translate_encoder_to_transmitter(enc_init_data.encoder);
1607 link->dc->res_pool->funcs->link_enc_create(&enc_init_data);
1609 if (!link->link_enc) {
1610 DC_ERROR("Failed to create link encoder!\n");
1611 goto link_enc_create_fail;
1614 DC_LOG_DC("BIOS object table - DP_IS_USB_C: %d", link->link_enc->features.flags.bits.DP_IS_USB_C);
1615 #if defined(CONFIG_DRM_AMD_DC_DCN)
1616 DC_LOG_DC("BIOS object table - IS_DP2_CAPABLE: %d", link->link_enc->features.flags.bits.IS_DP2_CAPABLE);
1619 /* Update link encoder tracking variables. These are used for the dynamic
1620 * assignment of link encoders to streams.
1622 link->eng_id = link->link_enc->preferred_engine;
1623 link->dc->res_pool->link_encoders[link->eng_id - ENGINE_ID_DIGA] = link->link_enc;
1624 link->dc->res_pool->dig_link_enc_count++;
1626 link->link_enc_hw_inst = link->link_enc->transmitter;
1628 for (i = 0; i < 4; i++) {
1629 if (bp_funcs->get_device_tag(dc_ctx->dc_bios,
1631 &link->device_tag) != BP_RESULT_OK) {
1632 DC_ERROR("Failed to find device tag!\n");
1633 goto device_tag_fail;
1636 /* Look for device tag that matches connector signal,
1637 * CRT for rgb, LCD for other supported signal tyes
1639 if (!bp_funcs->is_device_id_supported(dc_ctx->dc_bios,
1640 link->device_tag.dev_id))
1642 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_CRT &&
1643 link->connector_signal != SIGNAL_TYPE_RGB)
1645 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_LCD &&
1646 link->connector_signal == SIGNAL_TYPE_RGB)
1649 DC_LOG_DC("BIOS object table - device_tag.acpi_device: %d", link->device_tag.acpi_device);
1650 DC_LOG_DC("BIOS object table - device_tag.dev_id.device_type: %d", link->device_tag.dev_id.device_type);
1651 DC_LOG_DC("BIOS object table - device_tag.dev_id.enum_id: %d", link->device_tag.dev_id.enum_id);
1655 if (bios->integrated_info)
1656 memcpy(info, bios->integrated_info, sizeof(*info));
1658 /* Look for channel mapping corresponding to connector and device tag */
1659 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
1660 struct external_display_path *path =
1661 &info->ext_disp_conn_info.path[i];
1663 if (path->device_connector_id.enum_id == link->link_id.enum_id &&
1664 path->device_connector_id.id == link->link_id.id &&
1665 path->device_connector_id.type == link->link_id.type) {
1666 if (link->device_tag.acpi_device != 0 &&
1667 path->device_acpi_enum == link->device_tag.acpi_device) {
1668 link->ddi_channel_mapping = path->channel_mapping;
1669 link->chip_caps = path->caps;
1670 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1671 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1672 } else if (path->device_tag ==
1673 link->device_tag.dev_id.raw_device_tag) {
1674 link->ddi_channel_mapping = path->channel_mapping;
1675 link->chip_caps = path->caps;
1676 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1677 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1680 if (link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) {
1681 link->bios_forced_drive_settings.VOLTAGE_SWING =
1682 (info->ext_disp_conn_info.fixdpvoltageswing & 0x3);
1683 link->bios_forced_drive_settings.PRE_EMPHASIS =
1684 ((info->ext_disp_conn_info.fixdpvoltageswing >> 2) & 0x3);
1691 if (bios->funcs->get_atom_dc_golden_table)
1692 bios->funcs->get_atom_dc_golden_table(bios);
1695 * TODO check if GPIO programmed correctly
1697 * If GPIO isn't programmed correctly HPD might not rise or drain
1698 * fast enough, leading to bounces.
1700 program_hpd_filter(link);
1702 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
1704 DC_LOG_DC("BIOS object table - %s finished successfully.\n", __func__);
1708 link->link_enc->funcs->destroy(&link->link_enc);
1709 link_enc_create_fail:
1710 if (link->panel_cntl != NULL)
1711 link->panel_cntl->funcs->destroy(&link->panel_cntl);
1712 panel_cntl_create_fail:
1713 dal_ddc_service_destroy(&link->ddc);
1717 if (link->hpd_gpio) {
1718 dal_gpio_destroy_irq(&link->hpd_gpio);
1719 link->hpd_gpio = NULL;
1722 DC_LOG_DC("BIOS object table - %s failed.\n", __func__);
1728 static bool dc_link_construct_dpia(struct dc_link *link,
1729 const struct link_init_data *init_params)
1731 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1732 struct dc_context *dc_ctx = init_params->ctx;
1734 DC_LOGGER_INIT(dc_ctx->logger);
1736 /* Initialized irq source for hpd and hpd rx */
1737 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1738 link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
1739 link->link_status.dpcd_caps = &link->dpcd_caps;
1741 link->dc = init_params->dc;
1743 link->link_index = init_params->link_index;
1745 memset(&link->preferred_training_settings, 0,
1746 sizeof(struct dc_link_training_overrides));
1747 memset(&link->preferred_link_setting, 0,
1748 sizeof(struct dc_link_settings));
1750 /* Dummy Init for linkid */
1751 link->link_id.type = OBJECT_TYPE_CONNECTOR;
1752 link->link_id.id = CONNECTOR_ID_DISPLAY_PORT;
1753 link->link_id.enum_id = ENUM_ID_1 + init_params->connector_index;
1754 link->is_internal_display = false;
1755 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1756 LINK_INFO("Connector[%d] description:signal %d\n",
1757 init_params->connector_index,
1758 link->connector_signal);
1760 link->ep_type = DISPLAY_ENDPOINT_USB4_DPIA;
1761 link->is_dig_mapping_flexible = true;
1763 /* TODO: Initialize link : funcs->link_init */
1765 ddc_service_init_data.ctx = link->ctx;
1766 ddc_service_init_data.id = link->link_id;
1767 ddc_service_init_data.link = link;
1768 /* Set indicator for dpia link so that ddc won't be created */
1769 ddc_service_init_data.is_dpia_link = true;
1771 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1773 DC_ERROR("Failed to create ddc_service!\n");
1774 goto ddc_create_fail;
1777 /* Set dpia port index : 0 to number of dpia ports */
1778 link->ddc_hw_inst = init_params->connector_index;
1780 /* TODO: Create link encoder */
1782 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
1784 /* Some docks seem to NAK I2C writes to segment pointer with mot=0. */
1785 link->wa_flags.dp_mot_reset_segment = true;
1793 static bool dc_link_construct(struct dc_link *link,
1794 const struct link_init_data *init_params)
1796 /* Handle dpia case */
1797 if (init_params->is_dpia_link)
1798 return dc_link_construct_dpia(link, init_params);
1800 return dc_link_construct_legacy(link, init_params);
1802 /*******************************************************************************
1804 ******************************************************************************/
1805 struct dc_link *link_create(const struct link_init_data *init_params)
1807 struct dc_link *link =
1808 kzalloc(sizeof(*link), GFP_KERNEL);
1813 if (false == dc_link_construct(link, init_params))
1814 goto construct_fail;
1817 * Must use preferred_link_setting, not reported_link_cap or verified_link_cap,
1818 * since struct preferred_link_setting won't be reset after S3.
1820 link->preferred_link_setting.dpcd_source_device_specific_field_support = true;
1831 void link_destroy(struct dc_link **link)
1833 dc_link_destruct(*link);
1838 static void enable_stream_features(struct pipe_ctx *pipe_ctx)
1840 struct dc_stream_state *stream = pipe_ctx->stream;
1842 if (pipe_ctx->stream->signal != SIGNAL_TYPE_DISPLAY_PORT_MST) {
1843 struct dc_link *link = stream->link;
1844 union down_spread_ctrl old_downspread;
1845 union down_spread_ctrl new_downspread;
1847 core_link_read_dpcd(link, DP_DOWNSPREAD_CTRL,
1848 &old_downspread.raw, sizeof(old_downspread));
1850 new_downspread.raw = old_downspread.raw;
1852 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1853 (stream->ignore_msa_timing_param) ? 1 : 0;
1855 if (new_downspread.raw != old_downspread.raw) {
1856 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
1857 &new_downspread.raw, sizeof(new_downspread));
1861 dm_helpers_mst_enable_stream_features(stream);
1865 static enum dc_status enable_link_dp(struct dc_state *state,
1866 struct pipe_ctx *pipe_ctx)
1868 struct dc_stream_state *stream = pipe_ctx->stream;
1869 enum dc_status status;
1870 bool skip_video_pattern;
1871 struct dc_link *link = stream->link;
1872 struct dc_link_settings link_settings = {0};
1875 bool apply_seamless_boot_optimization = false;
1876 uint32_t bl_oled_enable_delay = 50; // in ms
1877 const uint32_t post_oui_delay = 30; // 30ms
1878 /* Reduce link bandwidth between failed link training attempts. */
1879 bool do_fallback = false;
1881 // check for seamless boot
1882 for (i = 0; i < state->stream_count; i++) {
1883 if (state->streams[i]->apply_seamless_boot_optimization) {
1884 apply_seamless_boot_optimization = true;
1889 /* get link settings for video mode timing */
1890 decide_link_settings(stream, &link_settings);
1892 /* Train with fallback when enabling DPIA link. Conventional links are
1893 * trained with fallback during sink detection.
1895 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
1898 #if defined(CONFIG_DRM_AMD_DC_DCN)
1900 * Temporary w/a to get DP2.0 link rates to work with SST.
1901 * TODO DP2.0 - Workaround: Remove w/a if and when the issue is resolved.
1903 if (dp_get_link_encoding_format(&link_settings) == DP_128b_132b_ENCODING &&
1904 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
1905 link->dc->debug.set_mst_en_for_sst) {
1906 dp_enable_mst_on_sink(link, true);
1910 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
1911 /*in case it is not on*/
1912 link->dc->hwss.edp_power_control(link, true);
1913 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
1916 #if defined(CONFIG_DRM_AMD_DC_DCN)
1917 if (dp_get_link_encoding_format(&link_settings) == DP_128b_132b_ENCODING) {
1918 /* TODO - DP2.0 HW: calculate 32 symbol clock for HPO encoder */
1920 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
1921 link_settings.link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
1922 if (state->clk_mgr && !apply_seamless_boot_optimization)
1923 state->clk_mgr->funcs->update_clocks(state->clk_mgr,
1927 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
1928 link_settings.link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
1929 if (state->clk_mgr && !apply_seamless_boot_optimization)
1930 state->clk_mgr->funcs->update_clocks(state->clk_mgr,
1934 // during mode switch we do DP_SET_POWER off then on, and OUI is lost
1935 dpcd_set_source_specific_data(link);
1936 if (link->dpcd_sink_ext_caps.raw != 0)
1937 msleep(post_oui_delay);
1939 skip_video_pattern = true;
1941 if (link_settings.link_rate == LINK_RATE_LOW)
1942 skip_video_pattern = false;
1944 if (perform_link_training_with_retries(&link_settings,
1946 LINK_TRAINING_ATTEMPTS,
1948 pipe_ctx->stream->signal,
1950 link->cur_link_settings = link_settings;
1953 status = DC_FAIL_DP_LINK_TRAINING;
1956 if (link->preferred_training_settings.fec_enable)
1957 fec_enable = *link->preferred_training_settings.fec_enable;
1961 #if defined(CONFIG_DRM_AMD_DC_DCN)
1962 if (dp_get_link_encoding_format(&link_settings) == DP_8b_10b_ENCODING)
1963 dp_set_fec_enable(link, fec_enable);
1965 dp_set_fec_enable(link, fec_enable);
1968 // during mode set we do DP_SET_POWER off then on, aux writes are lost
1969 if (link->dpcd_sink_ext_caps.bits.oled == 1 ||
1970 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1 ||
1971 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1) {
1972 dc_link_set_default_brightness_aux(link); // TODO: use cached if known
1973 if (link->dpcd_sink_ext_caps.bits.oled == 1)
1974 msleep(bl_oled_enable_delay);
1975 dc_link_backlight_enable_aux(link, true);
1981 static enum dc_status enable_link_edp(
1982 struct dc_state *state,
1983 struct pipe_ctx *pipe_ctx)
1985 enum dc_status status;
1987 status = enable_link_dp(state, pipe_ctx);
1992 static enum dc_status enable_link_dp_mst(
1993 struct dc_state *state,
1994 struct pipe_ctx *pipe_ctx)
1996 struct dc_link *link = pipe_ctx->stream->link;
1998 /* sink signal type after MST branch is MST. Multiple MST sinks
1999 * share one link. Link DP PHY is enable or training only once.
2001 if (link->link_status.link_active)
2004 /* clear payload table */
2005 dm_helpers_dp_mst_clear_payload_allocation_table(link->ctx, link);
2007 /* to make sure the pending down rep can be processed
2008 * before enabling the link
2010 dm_helpers_dp_mst_poll_pending_down_reply(link->ctx, link);
2012 /* set the sink to MST mode before enabling the link */
2013 dp_enable_mst_on_sink(link, true);
2015 return enable_link_dp(state, pipe_ctx);
2018 void dc_link_blank_all_dp_displays(struct dc *dc)
2021 uint8_t dpcd_power_state = '\0';
2022 enum dc_status status = DC_ERROR_UNEXPECTED;
2024 for (i = 0; i < dc->link_count; i++) {
2025 if ((dc->links[i]->connector_signal != SIGNAL_TYPE_DISPLAY_PORT) ||
2026 (dc->links[i]->priv == NULL) || (dc->links[i]->local_sink == NULL))
2029 /* DP 2.0 spec requires that we read LTTPR caps first */
2030 dp_retrieve_lttpr_cap(dc->links[i]);
2031 /* if any of the displays are lit up turn them off */
2032 status = core_link_read_dpcd(dc->links[i], DP_SET_POWER,
2033 &dpcd_power_state, sizeof(dpcd_power_state));
2035 if (status == DC_OK && dpcd_power_state == DP_POWER_STATE_D0)
2036 dc_link_blank_dp_stream(dc->links[i], true);
2041 void dc_link_blank_dp_stream(struct dc_link *link, bool hw_init)
2044 struct dc *dc = link->ctx->dc;
2045 enum signal_type signal = link->connector_signal;
2047 if ((signal == SIGNAL_TYPE_EDP) ||
2048 (signal == SIGNAL_TYPE_DISPLAY_PORT)) {
2049 if (link->ep_type == DISPLAY_ENDPOINT_PHY &&
2050 link->link_enc->funcs->get_dig_frontend &&
2051 link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
2052 unsigned int fe = link->link_enc->funcs->get_dig_frontend(link->link_enc);
2054 if (fe != ENGINE_ID_UNKNOWN)
2055 for (j = 0; j < dc->res_pool->stream_enc_count; j++) {
2056 if (fe == dc->res_pool->stream_enc[j]->id) {
2057 dc->res_pool->stream_enc[j]->funcs->dp_blank(link,
2058 dc->res_pool->stream_enc[j]);
2064 if ((!link->wa_flags.dp_keep_receiver_powered) || hw_init)
2065 dp_receiver_power_ctrl(link, false);
2069 static bool get_ext_hdmi_settings(struct pipe_ctx *pipe_ctx,
2070 enum engine_id eng_id,
2071 struct ext_hdmi_settings *settings)
2073 bool result = false;
2075 struct integrated_info *integrated_info =
2076 pipe_ctx->stream->ctx->dc_bios->integrated_info;
2078 if (integrated_info == NULL)
2082 * Get retimer settings from sbios for passing SI eye test for DCE11
2083 * The setting values are varied based on board revision and port id
2084 * Therefore the setting values of each ports is passed by sbios.
2087 // Check if current bios contains ext Hdmi settings
2088 if (integrated_info->gpu_cap_info & 0x20) {
2090 case ENGINE_ID_DIGA:
2091 settings->slv_addr = integrated_info->dp0_ext_hdmi_slv_addr;
2092 settings->reg_num = integrated_info->dp0_ext_hdmi_6g_reg_num;
2093 settings->reg_num_6g = integrated_info->dp0_ext_hdmi_6g_reg_num;
2094 memmove(settings->reg_settings,
2095 integrated_info->dp0_ext_hdmi_reg_settings,
2096 sizeof(integrated_info->dp0_ext_hdmi_reg_settings));
2097 memmove(settings->reg_settings_6g,
2098 integrated_info->dp0_ext_hdmi_6g_reg_settings,
2099 sizeof(integrated_info->dp0_ext_hdmi_6g_reg_settings));
2102 case ENGINE_ID_DIGB:
2103 settings->slv_addr = integrated_info->dp1_ext_hdmi_slv_addr;
2104 settings->reg_num = integrated_info->dp1_ext_hdmi_6g_reg_num;
2105 settings->reg_num_6g = integrated_info->dp1_ext_hdmi_6g_reg_num;
2106 memmove(settings->reg_settings,
2107 integrated_info->dp1_ext_hdmi_reg_settings,
2108 sizeof(integrated_info->dp1_ext_hdmi_reg_settings));
2109 memmove(settings->reg_settings_6g,
2110 integrated_info->dp1_ext_hdmi_6g_reg_settings,
2111 sizeof(integrated_info->dp1_ext_hdmi_6g_reg_settings));
2114 case ENGINE_ID_DIGC:
2115 settings->slv_addr = integrated_info->dp2_ext_hdmi_slv_addr;
2116 settings->reg_num = integrated_info->dp2_ext_hdmi_6g_reg_num;
2117 settings->reg_num_6g = integrated_info->dp2_ext_hdmi_6g_reg_num;
2118 memmove(settings->reg_settings,
2119 integrated_info->dp2_ext_hdmi_reg_settings,
2120 sizeof(integrated_info->dp2_ext_hdmi_reg_settings));
2121 memmove(settings->reg_settings_6g,
2122 integrated_info->dp2_ext_hdmi_6g_reg_settings,
2123 sizeof(integrated_info->dp2_ext_hdmi_6g_reg_settings));
2126 case ENGINE_ID_DIGD:
2127 settings->slv_addr = integrated_info->dp3_ext_hdmi_slv_addr;
2128 settings->reg_num = integrated_info->dp3_ext_hdmi_6g_reg_num;
2129 settings->reg_num_6g = integrated_info->dp3_ext_hdmi_6g_reg_num;
2130 memmove(settings->reg_settings,
2131 integrated_info->dp3_ext_hdmi_reg_settings,
2132 sizeof(integrated_info->dp3_ext_hdmi_reg_settings));
2133 memmove(settings->reg_settings_6g,
2134 integrated_info->dp3_ext_hdmi_6g_reg_settings,
2135 sizeof(integrated_info->dp3_ext_hdmi_6g_reg_settings));
2142 if (result == true) {
2143 // Validate settings from bios integrated info table
2144 if (settings->slv_addr == 0)
2146 if (settings->reg_num > 9)
2148 if (settings->reg_num_6g > 3)
2151 for (i = 0; i < settings->reg_num; i++) {
2152 if (settings->reg_settings[i].i2c_reg_index > 0x20)
2156 for (i = 0; i < settings->reg_num_6g; i++) {
2157 if (settings->reg_settings_6g[i].i2c_reg_index > 0x20)
2166 static bool i2c_write(struct pipe_ctx *pipe_ctx,
2167 uint8_t address, uint8_t *buffer, uint32_t length)
2169 struct i2c_command cmd = {0};
2170 struct i2c_payload payload = {0};
2172 memset(&payload, 0, sizeof(payload));
2173 memset(&cmd, 0, sizeof(cmd));
2175 cmd.number_of_payloads = 1;
2176 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
2177 cmd.speed = pipe_ctx->stream->ctx->dc->caps.i2c_speed_in_khz;
2179 payload.address = address;
2180 payload.data = buffer;
2181 payload.length = length;
2182 payload.write = true;
2183 cmd.payloads = &payload;
2185 if (dm_helpers_submit_i2c(pipe_ctx->stream->ctx,
2186 pipe_ctx->stream->link, &cmd))
2192 static void write_i2c_retimer_setting(
2193 struct pipe_ctx *pipe_ctx,
2195 bool is_over_340mhz,
2196 struct ext_hdmi_settings *settings)
2198 uint8_t slave_address = (settings->slv_addr >> 1);
2200 const uint8_t apply_rx_tx_change = 0x4;
2201 uint8_t offset = 0xA;
2204 bool i2c_success = false;
2205 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2207 memset(&buffer, 0, sizeof(buffer));
2209 /* Start Ext-Hdmi programming*/
2211 for (i = 0; i < settings->reg_num; i++) {
2212 /* Apply 3G settings */
2213 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
2215 buffer[0] = settings->reg_settings[i].i2c_reg_index;
2216 buffer[1] = settings->reg_settings[i].i2c_reg_val;
2217 i2c_success = i2c_write(pipe_ctx, slave_address,
2218 buffer, sizeof(buffer));
2219 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2220 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2221 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2224 goto i2c_write_fail;
2226 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
2227 * needs to be set to 1 on every 0xA-0xC write.
2229 if (settings->reg_settings[i].i2c_reg_index == 0xA ||
2230 settings->reg_settings[i].i2c_reg_index == 0xB ||
2231 settings->reg_settings[i].i2c_reg_index == 0xC) {
2233 /* Query current value from offset 0xA */
2234 if (settings->reg_settings[i].i2c_reg_index == 0xA)
2235 value = settings->reg_settings[i].i2c_reg_val;
2238 dal_ddc_service_query_ddc_data(
2239 pipe_ctx->stream->link->ddc,
2240 slave_address, &offset, 1, &value, 1);
2242 goto i2c_write_fail;
2246 /* Set APPLY_RX_TX_CHANGE bit to 1 */
2247 buffer[1] = value | apply_rx_tx_change;
2248 i2c_success = i2c_write(pipe_ctx, slave_address,
2249 buffer, sizeof(buffer));
2250 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2251 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2252 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2254 goto i2c_write_fail;
2259 /* Apply 3G settings */
2260 if (is_over_340mhz) {
2261 for (i = 0; i < settings->reg_num_6g; i++) {
2262 /* Apply 3G settings */
2263 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
2265 buffer[0] = settings->reg_settings_6g[i].i2c_reg_index;
2266 buffer[1] = settings->reg_settings_6g[i].i2c_reg_val;
2267 i2c_success = i2c_write(pipe_ctx, slave_address,
2268 buffer, sizeof(buffer));
2269 RETIMER_REDRIVER_INFO("above 340Mhz: retimer write to slave_address = 0x%x,\
2270 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2271 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2274 goto i2c_write_fail;
2276 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
2277 * needs to be set to 1 on every 0xA-0xC write.
2279 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA ||
2280 settings->reg_settings_6g[i].i2c_reg_index == 0xB ||
2281 settings->reg_settings_6g[i].i2c_reg_index == 0xC) {
2283 /* Query current value from offset 0xA */
2284 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA)
2285 value = settings->reg_settings_6g[i].i2c_reg_val;
2288 dal_ddc_service_query_ddc_data(
2289 pipe_ctx->stream->link->ddc,
2290 slave_address, &offset, 1, &value, 1);
2292 goto i2c_write_fail;
2296 /* Set APPLY_RX_TX_CHANGE bit to 1 */
2297 buffer[1] = value | apply_rx_tx_change;
2298 i2c_success = i2c_write(pipe_ctx, slave_address,
2299 buffer, sizeof(buffer));
2300 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2301 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2302 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2304 goto i2c_write_fail;
2311 /* Program additional settings if using 640x480 resolution */
2313 /* Write offset 0xFF to 0x01 */
2316 i2c_success = i2c_write(pipe_ctx, slave_address,
2317 buffer, sizeof(buffer));
2318 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2319 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2320 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2322 goto i2c_write_fail;
2324 /* Write offset 0x00 to 0x23 */
2327 i2c_success = i2c_write(pipe_ctx, slave_address,
2328 buffer, sizeof(buffer));
2329 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2330 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2331 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2333 goto i2c_write_fail;
2335 /* Write offset 0xff to 0x00 */
2338 i2c_success = i2c_write(pipe_ctx, slave_address,
2339 buffer, sizeof(buffer));
2340 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2341 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2342 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2344 goto i2c_write_fail;
2351 DC_LOG_DEBUG("Set retimer failed");
2354 static void write_i2c_default_retimer_setting(
2355 struct pipe_ctx *pipe_ctx,
2357 bool is_over_340mhz)
2359 uint8_t slave_address = (0xBA >> 1);
2361 bool i2c_success = false;
2362 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2364 memset(&buffer, 0, sizeof(buffer));
2366 /* Program Slave Address for tuning single integrity */
2367 /* Write offset 0x0A to 0x13 */
2370 i2c_success = i2c_write(pipe_ctx, slave_address,
2371 buffer, sizeof(buffer));
2372 RETIMER_REDRIVER_INFO("retimer writes default setting to slave_address = 0x%x,\
2373 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2374 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2376 goto i2c_write_fail;
2378 /* Write offset 0x0A to 0x17 */
2381 i2c_success = i2c_write(pipe_ctx, slave_address,
2382 buffer, sizeof(buffer));
2383 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2384 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2385 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2387 goto i2c_write_fail;
2389 /* Write offset 0x0B to 0xDA or 0xD8 */
2391 buffer[1] = is_over_340mhz ? 0xDA : 0xD8;
2392 i2c_success = i2c_write(pipe_ctx, slave_address,
2393 buffer, sizeof(buffer));
2394 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2395 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2396 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2398 goto i2c_write_fail;
2400 /* Write offset 0x0A to 0x17 */
2403 i2c_success = i2c_write(pipe_ctx, slave_address,
2404 buffer, sizeof(buffer));
2405 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2406 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2407 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2409 goto i2c_write_fail;
2411 /* Write offset 0x0C to 0x1D or 0x91 */
2413 buffer[1] = is_over_340mhz ? 0x1D : 0x91;
2414 i2c_success = i2c_write(pipe_ctx, slave_address,
2415 buffer, sizeof(buffer));
2416 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2417 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2418 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2420 goto i2c_write_fail;
2422 /* Write offset 0x0A to 0x17 */
2425 i2c_success = i2c_write(pipe_ctx, slave_address,
2426 buffer, sizeof(buffer));
2427 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2428 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2429 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2431 goto i2c_write_fail;
2435 /* Program additional settings if using 640x480 resolution */
2437 /* Write offset 0xFF to 0x01 */
2440 i2c_success = i2c_write(pipe_ctx, slave_address,
2441 buffer, sizeof(buffer));
2442 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2443 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2444 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2446 goto i2c_write_fail;
2448 /* Write offset 0x00 to 0x23 */
2451 i2c_success = i2c_write(pipe_ctx, slave_address,
2452 buffer, sizeof(buffer));
2453 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2454 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2455 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2457 goto i2c_write_fail;
2459 /* Write offset 0xff to 0x00 */
2462 i2c_success = i2c_write(pipe_ctx, slave_address,
2463 buffer, sizeof(buffer));
2464 RETIMER_REDRIVER_INFO("retimer write default setting to slave_addr = 0x%x,\
2465 offset = 0x%x, reg_val= 0x%x, i2c_success = %d end here\n",
2466 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2468 goto i2c_write_fail;
2474 DC_LOG_DEBUG("Set default retimer failed");
2477 static void write_i2c_redriver_setting(
2478 struct pipe_ctx *pipe_ctx,
2479 bool is_over_340mhz)
2481 uint8_t slave_address = (0xF0 >> 1);
2483 bool i2c_success = false;
2484 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2486 memset(&buffer, 0, sizeof(buffer));
2488 // Program Slave Address for tuning single integrity
2492 buffer[6] = is_over_340mhz ? 0x4E : 0x4A;
2494 i2c_success = i2c_write(pipe_ctx, slave_address,
2495 buffer, sizeof(buffer));
2496 RETIMER_REDRIVER_INFO("redriver write 0 to all 16 reg offset expect following:\n\
2497 \t slave_addr = 0x%x, offset[3] = 0x%x, offset[4] = 0x%x,\
2498 offset[5] = 0x%x,offset[6] is_over_340mhz = 0x%x,\
2499 i2c_success = %d\n",
2500 slave_address, buffer[3], buffer[4], buffer[5], buffer[6], i2c_success?1:0);
2503 DC_LOG_DEBUG("Set redriver failed");
2506 static void disable_link(struct dc_link *link, enum signal_type signal)
2509 * TODO: implement call for dp_set_hw_test_pattern
2510 * it is needed for compliance testing
2513 /* Here we need to specify that encoder output settings
2514 * need to be calculated as for the set mode,
2515 * it will lead to querying dynamic link capabilities
2516 * which should be done before enable output
2519 if (dc_is_dp_signal(signal)) {
2521 #if defined(CONFIG_DRM_AMD_DC_DCN)
2522 struct dc_link_settings link_settings = link->cur_link_settings;
2524 if (dc_is_dp_sst_signal(signal))
2525 dp_disable_link_phy(link, signal);
2527 dp_disable_link_phy_mst(link, signal);
2529 if (dc_is_dp_sst_signal(signal) ||
2530 link->mst_stream_alloc_table.stream_count == 0) {
2531 #if defined(CONFIG_DRM_AMD_DC_DCN)
2532 if (dp_get_link_encoding_format(&link_settings) == DP_8b_10b_ENCODING) {
2533 dp_set_fec_enable(link, false);
2534 dp_set_fec_ready(link, false);
2537 dp_set_fec_enable(link, false);
2538 dp_set_fec_ready(link, false);
2542 if (signal != SIGNAL_TYPE_VIRTUAL)
2543 link->link_enc->funcs->disable_output(link->link_enc, signal);
2546 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2547 /* MST disable link only when no stream use the link */
2548 if (link->mst_stream_alloc_table.stream_count <= 0)
2549 link->link_status.link_active = false;
2551 link->link_status.link_active = false;
2555 static void enable_link_hdmi(struct pipe_ctx *pipe_ctx)
2557 struct dc_stream_state *stream = pipe_ctx->stream;
2558 struct dc_link *link = stream->link;
2559 enum dc_color_depth display_color_depth;
2560 enum engine_id eng_id;
2561 struct ext_hdmi_settings settings = {0};
2562 bool is_over_340mhz = false;
2563 bool is_vga_mode = (stream->timing.h_addressable == 640)
2564 && (stream->timing.v_addressable == 480);
2566 if (stream->phy_pix_clk == 0)
2567 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2568 if (stream->phy_pix_clk > 340000)
2569 is_over_340mhz = true;
2571 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2572 unsigned short masked_chip_caps = pipe_ctx->stream->link->chip_caps &
2573 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
2574 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
2575 /* DP159, Retimer settings */
2576 eng_id = pipe_ctx->stream_res.stream_enc->id;
2578 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings)) {
2579 write_i2c_retimer_setting(pipe_ctx,
2580 is_vga_mode, is_over_340mhz, &settings);
2582 write_i2c_default_retimer_setting(pipe_ctx,
2583 is_vga_mode, is_over_340mhz);
2585 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
2586 /* PI3EQX1204, Redriver settings */
2587 write_i2c_redriver_setting(pipe_ctx, is_over_340mhz);
2591 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2592 dal_ddc_service_write_scdc_data(
2594 stream->phy_pix_clk,
2595 stream->timing.flags.LTE_340MCSC_SCRAMBLE);
2597 memset(&stream->link->cur_link_settings, 0,
2598 sizeof(struct dc_link_settings));
2600 display_color_depth = stream->timing.display_color_depth;
2601 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
2602 display_color_depth = COLOR_DEPTH_888;
2604 link->link_enc->funcs->enable_tmds_output(
2606 pipe_ctx->clock_source->id,
2607 display_color_depth,
2608 pipe_ctx->stream->signal,
2609 stream->phy_pix_clk);
2611 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2612 dal_ddc_service_read_scdc_data(link->ddc);
2615 static void enable_link_lvds(struct pipe_ctx *pipe_ctx)
2617 struct dc_stream_state *stream = pipe_ctx->stream;
2618 struct dc_link *link = stream->link;
2620 if (stream->phy_pix_clk == 0)
2621 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2623 memset(&stream->link->cur_link_settings, 0,
2624 sizeof(struct dc_link_settings));
2626 link->link_enc->funcs->enable_lvds_output(
2628 pipe_ctx->clock_source->id,
2629 stream->phy_pix_clk);
2633 /****************************enable_link***********************************/
2634 static enum dc_status enable_link(
2635 struct dc_state *state,
2636 struct pipe_ctx *pipe_ctx)
2638 enum dc_status status = DC_ERROR_UNEXPECTED;
2639 struct dc_stream_state *stream = pipe_ctx->stream;
2640 struct dc_link *link = stream->link;
2642 /* There's some scenarios where driver is unloaded with display
2643 * still enabled. When driver is reloaded, it may cause a display
2644 * to not light up if there is a mismatch between old and new
2645 * link settings. Need to call disable first before enabling at
2646 * new link settings.
2648 if (link->link_status.link_active) {
2649 disable_link(link, pipe_ctx->stream->signal);
2652 switch (pipe_ctx->stream->signal) {
2653 case SIGNAL_TYPE_DISPLAY_PORT:
2654 status = enable_link_dp(state, pipe_ctx);
2656 case SIGNAL_TYPE_EDP:
2657 status = enable_link_edp(state, pipe_ctx);
2659 case SIGNAL_TYPE_DISPLAY_PORT_MST:
2660 status = enable_link_dp_mst(state, pipe_ctx);
2663 case SIGNAL_TYPE_DVI_SINGLE_LINK:
2664 case SIGNAL_TYPE_DVI_DUAL_LINK:
2665 case SIGNAL_TYPE_HDMI_TYPE_A:
2666 enable_link_hdmi(pipe_ctx);
2669 case SIGNAL_TYPE_LVDS:
2670 enable_link_lvds(pipe_ctx);
2673 case SIGNAL_TYPE_VIRTUAL:
2680 if (status == DC_OK)
2681 pipe_ctx->stream->link->link_status.link_active = true;
2686 static uint32_t get_timing_pixel_clock_100hz(const struct dc_crtc_timing *timing)
2689 uint32_t pxl_clk = timing->pix_clk_100hz;
2691 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
2693 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
2694 pxl_clk = pxl_clk * 2 / 3;
2696 if (timing->display_color_depth == COLOR_DEPTH_101010)
2697 pxl_clk = pxl_clk * 10 / 8;
2698 else if (timing->display_color_depth == COLOR_DEPTH_121212)
2699 pxl_clk = pxl_clk * 12 / 8;
2704 static bool dp_active_dongle_validate_timing(
2705 const struct dc_crtc_timing *timing,
2706 const struct dpcd_caps *dpcd_caps)
2708 const struct dc_dongle_caps *dongle_caps = &dpcd_caps->dongle_caps;
2710 switch (dpcd_caps->dongle_type) {
2711 case DISPLAY_DONGLE_DP_VGA_CONVERTER:
2712 case DISPLAY_DONGLE_DP_DVI_CONVERTER:
2713 case DISPLAY_DONGLE_DP_DVI_DONGLE:
2714 if (timing->pixel_encoding == PIXEL_ENCODING_RGB)
2722 #if defined(CONFIG_DRM_AMD_DC_DCN)
2723 if (dpcd_caps->dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER &&
2724 dongle_caps->extendedCapValid == true) {
2726 if (dpcd_caps->dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER ||
2727 dongle_caps->extendedCapValid == false)
2731 /* Check Pixel Encoding */
2732 switch (timing->pixel_encoding) {
2733 case PIXEL_ENCODING_RGB:
2734 case PIXEL_ENCODING_YCBCR444:
2736 case PIXEL_ENCODING_YCBCR422:
2737 if (!dongle_caps->is_dp_hdmi_ycbcr422_pass_through)
2740 case PIXEL_ENCODING_YCBCR420:
2741 if (!dongle_caps->is_dp_hdmi_ycbcr420_pass_through)
2745 /* Invalid Pixel Encoding*/
2749 switch (timing->display_color_depth) {
2750 case COLOR_DEPTH_666:
2751 case COLOR_DEPTH_888:
2752 /*888 and 666 should always be supported*/
2754 case COLOR_DEPTH_101010:
2755 if (dongle_caps->dp_hdmi_max_bpc < 10)
2758 case COLOR_DEPTH_121212:
2759 if (dongle_caps->dp_hdmi_max_bpc < 12)
2762 case COLOR_DEPTH_141414:
2763 case COLOR_DEPTH_161616:
2765 /* These color depths are currently not supported */
2769 if (get_timing_pixel_clock_100hz(timing) > (dongle_caps->dp_hdmi_max_pixel_clk_in_khz * 10))
2772 #if defined(CONFIG_DRM_AMD_DC_DCN)
2775 if (dpcd_caps->channel_coding_cap.bits.DP_128b_132b_SUPPORTED == 0 &&
2776 dpcd_caps->dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_PASSTHROUGH_SUPPORT == 0 &&
2777 dongle_caps->dfp_cap_ext.supported) {
2779 if (dongle_caps->dfp_cap_ext.max_pixel_rate_in_mps < (timing->pix_clk_100hz / 10000))
2782 if (dongle_caps->dfp_cap_ext.max_video_h_active_width < timing->h_addressable)
2785 if (dongle_caps->dfp_cap_ext.max_video_v_active_height < timing->v_addressable)
2788 if (timing->pixel_encoding == PIXEL_ENCODING_RGB) {
2789 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2791 if (timing->display_color_depth == COLOR_DEPTH_666 &&
2792 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_6bpc)
2794 else if (timing->display_color_depth == COLOR_DEPTH_888 &&
2795 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_8bpc)
2797 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2798 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_10bpc)
2800 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2801 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_12bpc)
2803 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2804 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_16bpc)
2806 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR444) {
2807 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2809 if (timing->display_color_depth == COLOR_DEPTH_888 &&
2810 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_8bpc)
2812 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2813 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_10bpc)
2815 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2816 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_12bpc)
2818 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2819 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_16bpc)
2821 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422) {
2822 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2824 if (timing->display_color_depth == COLOR_DEPTH_888 &&
2825 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_8bpc)
2827 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2828 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_10bpc)
2830 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2831 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_12bpc)
2833 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2834 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_16bpc)
2836 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) {
2837 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2839 if (timing->display_color_depth == COLOR_DEPTH_888 &&
2840 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_8bpc)
2842 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2843 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_10bpc)
2845 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2846 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_12bpc)
2848 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2849 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_16bpc)
2858 enum dc_status dc_link_validate_mode_timing(
2859 const struct dc_stream_state *stream,
2860 struct dc_link *link,
2861 const struct dc_crtc_timing *timing)
2863 uint32_t max_pix_clk = stream->link->dongle_max_pix_clk * 10;
2864 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
2866 /* A hack to avoid failing any modes for EDID override feature on
2867 * topology change such as lower quality cable for DP or different dongle
2869 if (link->remote_sinks[0] && link->remote_sinks[0]->sink_signal == SIGNAL_TYPE_VIRTUAL)
2872 /* Passive Dongle */
2873 if (max_pix_clk != 0 && get_timing_pixel_clock_100hz(timing) > max_pix_clk)
2874 return DC_EXCEED_DONGLE_CAP;
2877 if (!dp_active_dongle_validate_timing(timing, dpcd_caps))
2878 return DC_EXCEED_DONGLE_CAP;
2880 switch (stream->signal) {
2881 case SIGNAL_TYPE_EDP:
2882 case SIGNAL_TYPE_DISPLAY_PORT:
2883 if (!dp_validate_mode_timing(
2886 return DC_NO_DP_LINK_BANDWIDTH;
2896 static struct abm *get_abm_from_stream_res(const struct dc_link *link)
2899 struct dc *dc = NULL;
2900 struct abm *abm = NULL;
2902 if (!link || !link->ctx)
2907 for (i = 0; i < MAX_PIPES; i++) {
2908 struct pipe_ctx pipe_ctx = dc->current_state->res_ctx.pipe_ctx[i];
2909 struct dc_stream_state *stream = pipe_ctx.stream;
2911 if (stream && stream->link == link) {
2912 abm = pipe_ctx.stream_res.abm;
2919 int dc_link_get_backlight_level(const struct dc_link *link)
2921 struct abm *abm = get_abm_from_stream_res(link);
2922 struct panel_cntl *panel_cntl = link->panel_cntl;
2923 struct dc *dc = link->ctx->dc;
2924 struct dmcu *dmcu = dc->res_pool->dmcu;
2925 bool fw_set_brightness = true;
2928 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
2930 if (!fw_set_brightness && panel_cntl->funcs->get_current_backlight)
2931 return panel_cntl->funcs->get_current_backlight(panel_cntl);
2932 else if (abm != NULL && abm->funcs->get_current_backlight != NULL)
2933 return (int) abm->funcs->get_current_backlight(abm);
2935 return DC_ERROR_UNEXPECTED;
2938 int dc_link_get_target_backlight_pwm(const struct dc_link *link)
2940 struct abm *abm = get_abm_from_stream_res(link);
2942 if (abm == NULL || abm->funcs->get_target_backlight == NULL)
2943 return DC_ERROR_UNEXPECTED;
2945 return (int) abm->funcs->get_target_backlight(abm);
2948 static struct pipe_ctx *get_pipe_from_link(const struct dc_link *link)
2951 struct dc *dc = link->ctx->dc;
2952 struct pipe_ctx *pipe_ctx = NULL;
2954 for (i = 0; i < MAX_PIPES; i++) {
2955 if (dc->current_state->res_ctx.pipe_ctx[i].stream) {
2956 if (dc->current_state->res_ctx.pipe_ctx[i].stream->link == link) {
2957 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2966 bool dc_link_set_backlight_level(const struct dc_link *link,
2967 uint32_t backlight_pwm_u16_16,
2968 uint32_t frame_ramp)
2970 struct dc *dc = link->ctx->dc;
2972 DC_LOGGER_INIT(link->ctx->logger);
2973 DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n",
2974 backlight_pwm_u16_16, backlight_pwm_u16_16);
2976 if (dc_is_embedded_signal(link->connector_signal)) {
2977 struct pipe_ctx *pipe_ctx = get_pipe_from_link(link);
2980 /* Disable brightness ramping when the display is blanked
2981 * as it can hang the DMCU
2983 if (pipe_ctx->plane_state == NULL)
2989 dc->hwss.set_backlight_level(
2991 backlight_pwm_u16_16,
2997 bool dc_link_set_psr_allow_active(struct dc_link *link, const bool *allow_active,
2998 bool wait, bool force_static, const unsigned int *power_opts)
3000 struct dc *dc = link->ctx->dc;
3001 struct dmcu *dmcu = dc->res_pool->dmcu;
3002 struct dmub_psr *psr = dc->res_pool->psr;
3003 unsigned int panel_inst;
3005 if (psr == NULL && force_static)
3008 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
3011 /* Set power optimization flag */
3012 if (power_opts && link->psr_settings.psr_power_opt != *power_opts) {
3013 link->psr_settings.psr_power_opt = *power_opts;
3015 if (psr != NULL && link->psr_settings.psr_feature_enabled && psr->funcs->psr_set_power_opt)
3016 psr->funcs->psr_set_power_opt(psr, link->psr_settings.psr_power_opt, panel_inst);
3019 /* Enable or Disable PSR */
3020 if (allow_active && link->psr_settings.psr_allow_active != *allow_active) {
3021 link->psr_settings.psr_allow_active = *allow_active;
3023 #if defined(CONFIG_DRM_AMD_DC_DCN)
3024 if (!link->psr_settings.psr_allow_active)
3028 if (psr != NULL && link->psr_settings.psr_feature_enabled) {
3029 if (force_static && psr->funcs->psr_force_static)
3030 psr->funcs->psr_force_static(psr, panel_inst);
3031 psr->funcs->psr_enable(psr, link->psr_settings.psr_allow_active, wait, panel_inst);
3032 } else if ((dmcu != NULL && dmcu->funcs->is_dmcu_initialized(dmcu)) &&
3033 link->psr_settings.psr_feature_enabled)
3034 dmcu->funcs->set_psr_enable(dmcu, link->psr_settings.psr_allow_active, wait);
3042 bool dc_link_get_psr_state(const struct dc_link *link, enum dc_psr_state *state)
3044 struct dc *dc = link->ctx->dc;
3045 struct dmcu *dmcu = dc->res_pool->dmcu;
3046 struct dmub_psr *psr = dc->res_pool->psr;
3047 unsigned int panel_inst;
3049 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
3052 if (psr != NULL && link->psr_settings.psr_feature_enabled)
3053 psr->funcs->psr_get_state(psr, state, panel_inst);
3054 else if (dmcu != NULL && link->psr_settings.psr_feature_enabled)
3055 dmcu->funcs->get_psr_state(dmcu, state);
3060 static inline enum physical_phy_id
3061 transmitter_to_phy_id(enum transmitter transmitter_value)
3063 switch (transmitter_value) {
3064 case TRANSMITTER_UNIPHY_A:
3066 case TRANSMITTER_UNIPHY_B:
3068 case TRANSMITTER_UNIPHY_C:
3070 case TRANSMITTER_UNIPHY_D:
3072 case TRANSMITTER_UNIPHY_E:
3074 case TRANSMITTER_UNIPHY_F:
3076 case TRANSMITTER_NUTMEG_CRT:
3078 case TRANSMITTER_TRAVIS_CRT:
3080 case TRANSMITTER_TRAVIS_LCD:
3082 case TRANSMITTER_UNIPHY_G:
3084 case TRANSMITTER_COUNT:
3086 case TRANSMITTER_UNKNOWN:
3087 return PHYLD_UNKNOWN;
3089 WARN_ONCE(1, "Unknown transmitter value %d\n",
3091 return PHYLD_UNKNOWN;
3095 bool dc_link_setup_psr(struct dc_link *link,
3096 const struct dc_stream_state *stream, struct psr_config *psr_config,
3097 struct psr_context *psr_context)
3101 struct dmub_psr *psr;
3103 unsigned int panel_inst;
3104 /* updateSinkPsrDpcdConfig*/
3105 union dpcd_psr_configuration psr_configuration;
3107 psr_context->controllerId = CONTROLLER_ID_UNDEFINED;
3113 dmcu = dc->res_pool->dmcu;
3114 psr = dc->res_pool->psr;
3119 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
3123 memset(&psr_configuration, 0, sizeof(psr_configuration));
3125 psr_configuration.bits.ENABLE = 1;
3126 psr_configuration.bits.CRC_VERIFICATION = 1;
3127 psr_configuration.bits.FRAME_CAPTURE_INDICATION =
3128 psr_config->psr_frame_capture_indication_req;
3130 /* Check for PSR v2*/
3131 if (psr_config->psr_version == 0x2) {
3132 /* For PSR v2 selective update.
3133 * Indicates whether sink should start capturing
3134 * immediately following active scan line,
3135 * or starting with the 2nd active scan line.
3137 psr_configuration.bits.LINE_CAPTURE_INDICATION = 0;
3138 /*For PSR v2, determines whether Sink should generate
3139 * IRQ_HPD when CRC mismatch is detected.
3141 psr_configuration.bits.IRQ_HPD_WITH_CRC_ERROR = 1;
3144 dm_helpers_dp_write_dpcd(
3148 &psr_configuration.raw,
3149 sizeof(psr_configuration.raw));
3151 psr_context->channel = link->ddc->ddc_pin->hw_info.ddc_channel;
3152 psr_context->transmitterId = link->link_enc->transmitter;
3153 psr_context->engineId = link->link_enc->preferred_engine;
3155 for (i = 0; i < MAX_PIPES; i++) {
3156 if (dc->current_state->res_ctx.pipe_ctx[i].stream
3158 /* dmcu -1 for all controller id values,
3161 psr_context->controllerId =
3162 dc->current_state->res_ctx.
3163 pipe_ctx[i].stream_res.tg->inst + 1;
3168 /* Hardcoded for now. Can be Pcie or Uniphy (or Unknown)*/
3169 psr_context->phyType = PHY_TYPE_UNIPHY;
3170 /*PhyId is associated with the transmitter id*/
3171 psr_context->smuPhyId =
3172 transmitter_to_phy_id(link->link_enc->transmitter);
3174 psr_context->crtcTimingVerticalTotal = stream->timing.v_total;
3175 psr_context->vsync_rate_hz = div64_u64(div64_u64((stream->
3176 timing.pix_clk_100hz * 100),
3177 stream->timing.v_total),
3178 stream->timing.h_total);
3180 psr_context->psrSupportedDisplayConfig = true;
3181 psr_context->psrExitLinkTrainingRequired =
3182 psr_config->psr_exit_link_training_required;
3183 psr_context->sdpTransmitLineNumDeadline =
3184 psr_config->psr_sdp_transmit_line_num_deadline;
3185 psr_context->psrFrameCaptureIndicationReq =
3186 psr_config->psr_frame_capture_indication_req;
3188 psr_context->skipPsrWaitForPllLock = 0; /* only = 1 in KV */
3190 psr_context->numberOfControllers =
3191 link->dc->res_pool->timing_generator_count;
3193 psr_context->rfb_update_auto_en = true;
3195 /* 2 frames before enter PSR. */
3196 psr_context->timehyst_frames = 2;
3198 * (units in 100 lines, i.e. a value of 1 represents 100 lines)
3200 psr_context->hyst_lines = stream->timing.v_total / 2 / 100;
3201 psr_context->aux_repeats = 10;
3203 psr_context->psr_level.u32all = 0;
3205 /*skip power down the single pipe since it blocks the cstate*/
3206 #if defined(CONFIG_DRM_AMD_DC_DCN)
3207 if (link->ctx->asic_id.chip_family >= FAMILY_RV) {
3208 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
3209 if (link->ctx->asic_id.chip_family == FAMILY_YELLOW_CARP && !dc->debug.disable_z10)
3210 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = false;
3213 if (link->ctx->asic_id.chip_family >= FAMILY_RV)
3214 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
3217 /* SMU will perform additional powerdown sequence.
3218 * For unsupported ASICs, set psr_level flag to skip PSR
3219 * static screen notification to SMU.
3220 * (Always set for DAL2, did not check ASIC)
3222 psr_context->allow_smu_optimizations = psr_config->allow_smu_optimizations;
3223 psr_context->allow_multi_disp_optimizations = psr_config->allow_multi_disp_optimizations;
3225 /* Complete PSR entry before aborting to prevent intermittent
3226 * freezes on certain eDPs
3228 psr_context->psr_level.bits.DISABLE_PSR_ENTRY_ABORT = 1;
3230 /* Controls additional delay after remote frame capture before
3231 * continuing power down, default = 0
3233 psr_context->frame_delay = 0;
3236 link->psr_settings.psr_feature_enabled = psr->funcs->psr_copy_settings(psr,
3237 link, psr_context, panel_inst);
3239 link->psr_settings.psr_feature_enabled = dmcu->funcs->setup_psr(dmcu, link, psr_context);
3241 /* psr_enabled == 0 indicates setup_psr did not succeed, but this
3242 * should not happen since firmware should be running at this point
3244 if (link->psr_settings.psr_feature_enabled == 0)
3251 void dc_link_get_psr_residency(const struct dc_link *link, uint32_t *residency)
3253 struct dc *dc = link->ctx->dc;
3254 struct dmub_psr *psr = dc->res_pool->psr;
3255 unsigned int panel_inst;
3257 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
3260 /* PSR residency measurements only supported on DMCUB */
3261 if (psr != NULL && link->psr_settings.psr_feature_enabled)
3262 psr->funcs->psr_get_residency(psr, residency, panel_inst);
3267 const struct dc_link_status *dc_link_get_status(const struct dc_link *link)
3269 return &link->link_status;
3272 void core_link_resume(struct dc_link *link)
3274 if (link->connector_signal != SIGNAL_TYPE_VIRTUAL)
3275 program_hpd_filter(link);
3278 static struct fixed31_32 get_pbn_per_slot(struct dc_stream_state *stream)
3280 struct fixed31_32 mbytes_per_sec;
3281 uint32_t link_rate_in_mbytes_per_sec = dc_link_bandwidth_kbps(stream->link,
3282 &stream->link->cur_link_settings);
3283 link_rate_in_mbytes_per_sec /= 8000; /* Kbits to MBytes */
3285 mbytes_per_sec = dc_fixpt_from_int(link_rate_in_mbytes_per_sec);
3287 return dc_fixpt_div_int(mbytes_per_sec, 54);
3290 static struct fixed31_32 get_pbn_from_bw_in_kbps(uint64_t kbps)
3292 struct fixed31_32 peak_kbps;
3293 uint32_t numerator = 0;
3294 uint32_t denominator = 1;
3297 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
3298 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
3299 * common multiplier to render an integer PBN for all link rate/lane
3300 * counts combinations
3302 * peak_kbps *= (1006/1000)
3303 * peak_kbps *= (64/54)
3304 * peak_kbps *= 8 convert to bytes
3307 numerator = 64 * PEAK_FACTOR_X1000;
3308 denominator = 54 * 8 * 1000 * 1000;
3310 peak_kbps = dc_fixpt_from_fraction(kbps, denominator);
3315 static struct fixed31_32 get_pbn_from_timing(struct pipe_ctx *pipe_ctx)
3319 kbps = dc_bandwidth_in_kbps_from_timing(&pipe_ctx->stream->timing);
3320 return get_pbn_from_bw_in_kbps(kbps);
3323 static void update_mst_stream_alloc_table(
3324 struct dc_link *link,
3325 struct stream_encoder *stream_enc,
3326 #if defined(CONFIG_DRM_AMD_DC_DCN)
3327 struct hpo_dp_stream_encoder *hpo_dp_stream_enc, // TODO: Rename stream_enc to dio_stream_enc?
3329 const struct dp_mst_stream_allocation_table *proposed_table)
3331 struct link_mst_stream_allocation work_table[MAX_CONTROLLER_NUM] = { 0 };
3332 struct link_mst_stream_allocation *dc_alloc;
3337 /* if DRM proposed_table has more than one new payload */
3338 ASSERT(proposed_table->stream_count -
3339 link->mst_stream_alloc_table.stream_count < 2);
3341 /* copy proposed_table to link, add stream encoder */
3342 for (i = 0; i < proposed_table->stream_count; i++) {
3344 for (j = 0; j < link->mst_stream_alloc_table.stream_count; j++) {
3346 &link->mst_stream_alloc_table.stream_allocations[j];
3348 if (dc_alloc->vcp_id ==
3349 proposed_table->stream_allocations[i].vcp_id) {
3351 work_table[i] = *dc_alloc;
3352 work_table[i].slot_count = proposed_table->stream_allocations[i].slot_count;
3353 break; /* exit j loop */
3358 if (j == link->mst_stream_alloc_table.stream_count) {
3359 work_table[i].vcp_id =
3360 proposed_table->stream_allocations[i].vcp_id;
3361 work_table[i].slot_count =
3362 proposed_table->stream_allocations[i].slot_count;
3363 work_table[i].stream_enc = stream_enc;
3364 #if defined(CONFIG_DRM_AMD_DC_DCN)
3365 work_table[i].hpo_dp_stream_enc = hpo_dp_stream_enc;
3370 /* update link->mst_stream_alloc_table with work_table */
3371 link->mst_stream_alloc_table.stream_count =
3372 proposed_table->stream_count;
3373 for (i = 0; i < MAX_CONTROLLER_NUM; i++)
3374 link->mst_stream_alloc_table.stream_allocations[i] =
3377 #if defined(CONFIG_DRM_AMD_DC_DCN)
3378 static void dc_log_vcp_x_y(const struct dc_link *link, struct fixed31_32 avg_time_slots_per_mtp)
3380 const uint32_t VCP_Y_PRECISION = 1000;
3381 uint64_t vcp_x, vcp_y;
3383 // Add 0.5*(1/VCP_Y_PRECISION) to round up to decimal precision
3384 avg_time_slots_per_mtp = dc_fixpt_add(
3385 avg_time_slots_per_mtp, dc_fixpt_from_fraction(1, 2 * VCP_Y_PRECISION));
3387 vcp_x = dc_fixpt_floor(avg_time_slots_per_mtp);
3388 vcp_y = dc_fixpt_floor(
3390 dc_fixpt_sub_int(avg_time_slots_per_mtp, dc_fixpt_floor(avg_time_slots_per_mtp)),
3393 if (link->type == dc_connection_mst_branch)
3394 DC_LOG_DP2("MST Update Payload: set_throttled_vcp_size slot X.Y for MST stream "
3395 "X: %lld Y: %lld/%d", vcp_x, vcp_y, VCP_Y_PRECISION);
3397 DC_LOG_DP2("SST Update Payload: set_throttled_vcp_size slot X.Y for SST stream "
3398 "X: %lld Y: %lld/%d", vcp_x, vcp_y, VCP_Y_PRECISION);
3402 * Payload allocation/deallocation for SST introduced in DP2.0
3404 enum dc_status dc_link_update_sst_payload(struct pipe_ctx *pipe_ctx, bool allocate)
3406 struct dc_stream_state *stream = pipe_ctx->stream;
3407 struct dc_link *link = stream->link;
3408 struct hpo_dp_link_encoder *hpo_dp_link_encoder = link->hpo_dp_link_enc;
3409 struct hpo_dp_stream_encoder *hpo_dp_stream_encoder = pipe_ctx->stream_res.hpo_dp_stream_enc;
3410 struct link_mst_stream_allocation_table proposed_table = {0};
3411 struct fixed31_32 avg_time_slots_per_mtp;
3412 DC_LOGGER_INIT(link->ctx->logger);
3414 /* slot X.Y for SST payload deallocate */
3416 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
3418 dc_log_vcp_x_y(link, avg_time_slots_per_mtp);
3420 hpo_dp_link_encoder->funcs->set_throttled_vcp_size(
3421 hpo_dp_link_encoder,
3422 hpo_dp_stream_encoder->inst,
3423 avg_time_slots_per_mtp);
3426 /* calculate VC payload and update branch with new payload allocation table*/
3427 if (!dpcd_write_128b_132b_sst_payload_allocation_table(
3432 DC_LOG_ERROR("SST Update Payload: Failed to update "
3433 "allocation table for "
3435 pipe_ctx->pipe_idx);
3438 proposed_table.stream_allocations[0].hpo_dp_stream_enc = hpo_dp_stream_encoder;
3440 ASSERT(proposed_table.stream_count == 1);
3442 //TODO - DP2.0 Logging: Instead of hpo_dp_stream_enc pointer, log instance id
3443 DC_LOG_DP2("SST Update Payload: hpo_dp_stream_enc: %p "
3446 (void *) proposed_table.stream_allocations[0].hpo_dp_stream_enc,
3447 proposed_table.stream_allocations[0].vcp_id,
3448 proposed_table.stream_allocations[0].slot_count);
3450 /* program DP source TX for payload */
3451 hpo_dp_link_encoder->funcs->update_stream_allocation_table(
3452 hpo_dp_link_encoder,
3455 /* poll for ACT handled */
3456 if (!dpcd_poll_for_allocation_change_trigger(link)) {
3457 // Failures will result in blackscreen and errors logged
3458 BREAK_TO_DEBUGGER();
3461 /* slot X.Y for SST payload allocate */
3463 avg_time_slots_per_mtp = calculate_sst_avg_time_slots_per_mtp(stream, link);
3465 dc_log_vcp_x_y(link, avg_time_slots_per_mtp);
3467 hpo_dp_link_encoder->funcs->set_throttled_vcp_size(
3468 hpo_dp_link_encoder,
3469 hpo_dp_stream_encoder->inst,
3470 avg_time_slots_per_mtp);
3473 /* Always return DC_OK.
3474 * If part of sequence fails, log failure(s) and show blackscreen
3480 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
3481 * because stream_encoder is not exposed to dm
3483 enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx)
3485 struct dc_stream_state *stream = pipe_ctx->stream;
3486 struct dc_link *link = stream->link;
3487 struct link_encoder *link_encoder = NULL;
3488 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3489 #if defined(CONFIG_DRM_AMD_DC_DCN)
3490 struct hpo_dp_link_encoder *hpo_dp_link_encoder = link->hpo_dp_link_enc;
3491 struct hpo_dp_stream_encoder *hpo_dp_stream_encoder = pipe_ctx->stream_res.hpo_dp_stream_enc;
3493 struct dp_mst_stream_allocation_table proposed_table = {0};
3494 struct fixed31_32 avg_time_slots_per_mtp;
3495 struct fixed31_32 pbn;
3496 struct fixed31_32 pbn_per_slot;
3498 enum act_return_status ret;
3499 DC_LOGGER_INIT(link->ctx->logger);
3501 /* Link encoder may have been dynamically assigned to non-physical display endpoint. */
3502 if (link->ep_type == DISPLAY_ENDPOINT_PHY)
3503 link_encoder = link->link_enc;
3504 else if (link->dc->res_pool->funcs->link_encs_assign)
3505 link_encoder = link_enc_cfg_get_link_enc_used_by_stream(pipe_ctx->stream->ctx->dc, stream);
3506 ASSERT(link_encoder);
3508 /* enable_link_dp_mst already check link->enabled_stream_count
3509 * and stream is in link->stream[]. This is called during set mode,
3510 * stream_enc is available.
3513 /* get calculate VC payload for stream: stream_alloc */
3514 if (dm_helpers_dp_mst_write_payload_allocation_table(
3519 update_mst_stream_alloc_table(
3520 #if defined(CONFIG_DRM_AMD_DC_DCN)
3522 pipe_ctx->stream_res.stream_enc,
3523 pipe_ctx->stream_res.hpo_dp_stream_enc,
3526 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
3530 DC_LOG_WARNING("Failed to update"
3531 "MST allocation table for"
3533 pipe_ctx->pipe_idx);
3536 "stream_count: %d: \n ",
3538 link->mst_stream_alloc_table.stream_count);
3540 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3541 #if defined(CONFIG_DRM_AMD_DC_DCN)
3542 DC_LOG_MST("stream_enc[%d]: %p "
3543 "stream[%d].hpo_dp_stream_enc: %p "
3544 "stream[%d].vcp_id: %d "
3545 "stream[%d].slot_count: %d\n",
3547 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3549 (void *) link->mst_stream_alloc_table.stream_allocations[i].hpo_dp_stream_enc,
3551 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3553 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3555 DC_LOG_MST("stream_enc[%d]: %p "
3556 "stream[%d].vcp_id: %d "
3557 "stream[%d].slot_count: %d\n",
3559 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3561 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3563 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3567 ASSERT(proposed_table.stream_count > 0);
3569 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) {
3570 static enum dc_status status;
3571 uint8_t mst_alloc_slots = 0, prev_mst_slots_in_use = 0xFF;
3573 for (i = 0; i < link->mst_stream_alloc_table.stream_count; i++)
3574 mst_alloc_slots += link->mst_stream_alloc_table.stream_allocations[i].slot_count;
3576 status = dc_process_dmub_set_mst_slots(link->dc, link->link_index,
3577 mst_alloc_slots, &prev_mst_slots_in_use);
3578 ASSERT(status == DC_OK);
3579 DC_LOG_MST("dpia : status[%d]: alloc_slots[%d]: used_slots[%d]\n",
3580 status, mst_alloc_slots, prev_mst_slots_in_use);
3583 /* program DP source TX for payload */
3584 #if defined(CONFIG_DRM_AMD_DC_DCN)
3585 switch (dp_get_link_encoding_format(&link->cur_link_settings)) {
3586 case DP_8b_10b_ENCODING:
3587 link_encoder->funcs->update_mst_stream_allocation_table(
3589 &link->mst_stream_alloc_table);
3591 case DP_128b_132b_ENCODING:
3592 hpo_dp_link_encoder->funcs->update_stream_allocation_table(
3593 hpo_dp_link_encoder,
3594 &link->mst_stream_alloc_table);
3596 case DP_UNKNOWN_ENCODING:
3597 DC_LOG_ERROR("Failure: unknown encoding format\n");
3598 return DC_ERROR_UNEXPECTED;
3601 link_encoder->funcs->update_mst_stream_allocation_table(
3603 &link->mst_stream_alloc_table);
3606 /* send down message */
3607 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3611 if (ret != ACT_LINK_LOST) {
3612 dm_helpers_dp_mst_send_payload_allocation(
3618 /* slot X.Y for only current stream */
3619 pbn_per_slot = get_pbn_per_slot(stream);
3620 if (pbn_per_slot.value == 0) {
3621 DC_LOG_ERROR("Failure: pbn_per_slot==0 not allowed. Cannot continue, returning DC_UNSUPPORTED_VALUE.\n");
3622 return DC_UNSUPPORTED_VALUE;
3624 pbn = get_pbn_from_timing(pipe_ctx);
3625 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
3627 #if defined(CONFIG_DRM_AMD_DC_DCN)
3628 switch (dp_get_link_encoding_format(&link->cur_link_settings)) {
3629 case DP_8b_10b_ENCODING:
3630 stream_encoder->funcs->set_throttled_vcp_size(
3632 avg_time_slots_per_mtp);
3634 case DP_128b_132b_ENCODING:
3635 hpo_dp_link_encoder->funcs->set_throttled_vcp_size(
3636 hpo_dp_link_encoder,
3637 hpo_dp_stream_encoder->inst,
3638 avg_time_slots_per_mtp);
3640 case DP_UNKNOWN_ENCODING:
3641 DC_LOG_ERROR("Failure: unknown encoding format\n");
3642 return DC_ERROR_UNEXPECTED;
3645 stream_encoder->funcs->set_throttled_vcp_size(
3647 avg_time_slots_per_mtp);
3654 #if defined(CONFIG_DRM_AMD_DC_DCN)
3655 enum dc_status dc_link_reduce_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t bw_in_kbps)
3657 struct dc_stream_state *stream = pipe_ctx->stream;
3658 struct dc_link *link = stream->link;
3659 struct fixed31_32 avg_time_slots_per_mtp;
3660 struct fixed31_32 pbn;
3661 struct fixed31_32 pbn_per_slot;
3662 struct link_encoder *link_encoder = link->link_enc;
3663 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3664 struct dp_mst_stream_allocation_table proposed_table = {0};
3666 enum act_return_status ret;
3667 DC_LOGGER_INIT(link->ctx->logger);
3669 /* decrease throttled vcp size */
3670 pbn_per_slot = get_pbn_per_slot(stream);
3671 pbn = get_pbn_from_bw_in_kbps(bw_in_kbps);
3672 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
3674 stream_encoder->funcs->set_throttled_vcp_size(
3676 avg_time_slots_per_mtp);
3678 /* send ALLOCATE_PAYLOAD sideband message with updated pbn */
3679 dm_helpers_dp_mst_send_payload_allocation(
3684 /* notify immediate branch device table update */
3685 if (dm_helpers_dp_mst_write_payload_allocation_table(
3690 /* update mst stream allocation table software state */
3691 update_mst_stream_alloc_table(
3693 pipe_ctx->stream_res.stream_enc,
3694 pipe_ctx->stream_res.hpo_dp_stream_enc,
3697 DC_LOG_WARNING("Failed to update"
3698 "MST allocation table for"
3700 pipe_ctx->pipe_idx);
3704 "stream_count: %d: \n ",
3706 link->mst_stream_alloc_table.stream_count);
3708 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3709 DC_LOG_MST("stream_enc[%d]: %p "
3710 "stream[%d].vcp_id: %d "
3711 "stream[%d].slot_count: %d\n",
3713 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3715 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3717 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3720 ASSERT(proposed_table.stream_count > 0);
3722 /* update mst stream allocation table hardware state */
3723 link_encoder->funcs->update_mst_stream_allocation_table(
3725 &link->mst_stream_alloc_table);
3727 /* poll for immediate branch device ACT handled */
3728 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3735 enum dc_status dc_link_increase_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t bw_in_kbps)
3737 struct dc_stream_state *stream = pipe_ctx->stream;
3738 struct dc_link *link = stream->link;
3739 struct fixed31_32 avg_time_slots_per_mtp;
3740 struct fixed31_32 pbn;
3741 struct fixed31_32 pbn_per_slot;
3742 struct link_encoder *link_encoder = link->link_enc;
3743 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3744 struct dp_mst_stream_allocation_table proposed_table = {0};
3746 enum act_return_status ret;
3747 DC_LOGGER_INIT(link->ctx->logger);
3749 /* notify immediate branch device table update */
3750 if (dm_helpers_dp_mst_write_payload_allocation_table(
3755 /* update mst stream allocation table software state */
3756 update_mst_stream_alloc_table(
3758 pipe_ctx->stream_res.stream_enc,
3759 pipe_ctx->stream_res.hpo_dp_stream_enc,
3764 "stream_count: %d: \n ",
3766 link->mst_stream_alloc_table.stream_count);
3768 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3769 DC_LOG_MST("stream_enc[%d]: %p "
3770 "stream[%d].vcp_id: %d "
3771 "stream[%d].slot_count: %d\n",
3773 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3775 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3777 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3780 ASSERT(proposed_table.stream_count > 0);
3782 /* update mst stream allocation table hardware state */
3783 link_encoder->funcs->update_mst_stream_allocation_table(
3785 &link->mst_stream_alloc_table);
3787 /* poll for immediate branch device ACT handled */
3788 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3792 if (ret != ACT_LINK_LOST) {
3793 /* send ALLOCATE_PAYLOAD sideband message with updated pbn */
3794 dm_helpers_dp_mst_send_payload_allocation(
3800 /* increase throttled vcp size */
3801 pbn = get_pbn_from_bw_in_kbps(bw_in_kbps);
3802 pbn_per_slot = get_pbn_per_slot(stream);
3803 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
3805 stream_encoder->funcs->set_throttled_vcp_size(
3807 avg_time_slots_per_mtp);
3813 static enum dc_status deallocate_mst_payload(struct pipe_ctx *pipe_ctx)
3815 struct dc_stream_state *stream = pipe_ctx->stream;
3816 struct dc_link *link = stream->link;
3817 struct link_encoder *link_encoder = NULL;
3818 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3819 #if defined(CONFIG_DRM_AMD_DC_DCN)
3820 struct hpo_dp_link_encoder *hpo_dp_link_encoder = link->hpo_dp_link_enc;
3821 struct hpo_dp_stream_encoder *hpo_dp_stream_encoder = pipe_ctx->stream_res.hpo_dp_stream_enc;
3823 struct dp_mst_stream_allocation_table proposed_table = {0};
3824 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
3826 bool mst_mode = (link->type == dc_connection_mst_branch);
3827 DC_LOGGER_INIT(link->ctx->logger);
3829 /* Link encoder may have been dynamically assigned to non-physical display endpoint. */
3830 if (link->ep_type == DISPLAY_ENDPOINT_PHY)
3831 link_encoder = link->link_enc;
3832 else if (link->dc->res_pool->funcs->link_encs_assign)
3833 link_encoder = link_enc_cfg_get_link_enc_used_by_stream(pipe_ctx->stream->ctx->dc, stream);
3834 ASSERT(link_encoder);
3836 /* deallocate_mst_payload is called before disable link. When mode or
3837 * disable/enable monitor, new stream is created which is not in link
3838 * stream[] yet. For this, payload is not allocated yet, so de-alloc
3839 * should not done. For new mode set, map_resources will get engine
3840 * for new stream, so stream_enc->id should be validated until here.
3844 #if defined(CONFIG_DRM_AMD_DC_DCN)
3845 switch (dp_get_link_encoding_format(&link->cur_link_settings)) {
3846 case DP_8b_10b_ENCODING:
3847 stream_encoder->funcs->set_throttled_vcp_size(
3849 avg_time_slots_per_mtp);
3851 case DP_128b_132b_ENCODING:
3852 hpo_dp_link_encoder->funcs->set_throttled_vcp_size(
3853 hpo_dp_link_encoder,
3854 hpo_dp_stream_encoder->inst,
3855 avg_time_slots_per_mtp);
3857 case DP_UNKNOWN_ENCODING:
3858 DC_LOG_ERROR("Failure: unknown encoding format\n");
3859 return DC_ERROR_UNEXPECTED;
3862 stream_encoder->funcs->set_throttled_vcp_size(
3864 avg_time_slots_per_mtp);
3867 /* TODO: which component is responsible for remove payload table? */
3869 if (dm_helpers_dp_mst_write_payload_allocation_table(
3875 #if defined(CONFIG_DRM_AMD_DC_DCN)
3876 update_mst_stream_alloc_table(
3878 pipe_ctx->stream_res.stream_enc,
3879 pipe_ctx->stream_res.hpo_dp_stream_enc,
3882 update_mst_stream_alloc_table(
3883 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
3887 DC_LOG_WARNING("Failed to update"
3888 "MST allocation table for"
3890 pipe_ctx->pipe_idx);
3895 "stream_count: %d: ",
3897 link->mst_stream_alloc_table.stream_count);
3899 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3900 #if defined(CONFIG_DRM_AMD_DC_DCN)
3901 DC_LOG_MST("stream_enc[%d]: %p "
3902 "stream[%d].hpo_dp_stream_enc: %p "
3903 "stream[%d].vcp_id: %d "
3904 "stream[%d].slot_count: %d\n",
3906 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3908 (void *) link->mst_stream_alloc_table.stream_allocations[i].hpo_dp_stream_enc,
3910 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3912 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3914 DC_LOG_MST("stream_enc[%d]: %p "
3915 "stream[%d].vcp_id: %d "
3916 "stream[%d].slot_count: %d\n",
3918 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3920 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3922 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3926 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) {
3927 enum dc_status status;
3928 uint8_t mst_alloc_slots = 0, prev_mst_slots_in_use = 0xFF;
3930 for (i = 0; i < link->mst_stream_alloc_table.stream_count; i++)
3931 mst_alloc_slots += link->mst_stream_alloc_table.stream_allocations[i].slot_count;
3933 status = dc_process_dmub_set_mst_slots(link->dc, link->link_index,
3934 mst_alloc_slots, &prev_mst_slots_in_use);
3935 ASSERT(status != DC_NOT_SUPPORTED);
3936 DC_LOG_MST("dpia : status[%d]: alloc_slots[%d]: used_slots[%d]\n",
3937 status, mst_alloc_slots, prev_mst_slots_in_use);
3940 #if defined(CONFIG_DRM_AMD_DC_DCN)
3941 switch (dp_get_link_encoding_format(&link->cur_link_settings)) {
3942 case DP_8b_10b_ENCODING:
3943 link_encoder->funcs->update_mst_stream_allocation_table(
3945 &link->mst_stream_alloc_table);
3947 case DP_128b_132b_ENCODING:
3948 hpo_dp_link_encoder->funcs->update_stream_allocation_table(
3949 hpo_dp_link_encoder,
3950 &link->mst_stream_alloc_table);
3952 case DP_UNKNOWN_ENCODING:
3953 DC_LOG_ERROR("Failure: unknown encoding format\n");
3954 return DC_ERROR_UNEXPECTED;
3957 link_encoder->funcs->update_mst_stream_allocation_table(
3959 &link->mst_stream_alloc_table);
3963 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3967 dm_helpers_dp_mst_send_payload_allocation(
3977 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3978 static void update_psp_stream_config(struct pipe_ctx *pipe_ctx, bool dpms_off)
3980 struct cp_psp *cp_psp = &pipe_ctx->stream->ctx->cp_psp;
3981 #if defined(CONFIG_DRM_AMD_DC_DCN)
3982 struct link_encoder *link_enc = NULL;
3985 if (cp_psp && cp_psp->funcs.update_stream_config) {
3986 struct cp_psp_stream_config config = {0};
3987 enum dp_panel_mode panel_mode =
3988 dp_get_panel_mode(pipe_ctx->stream->link);
3990 config.otg_inst = (uint8_t) pipe_ctx->stream_res.tg->inst;
3992 config.dig_fe = (uint8_t) pipe_ctx->stream_res.stream_enc->stream_enc_inst;
3993 config.dig_be = pipe_ctx->stream->link->link_enc_hw_inst;
3994 #if defined(CONFIG_DRM_AMD_DC_DCN)
3995 config.stream_enc_idx = pipe_ctx->stream_res.stream_enc->id - ENGINE_ID_DIGA;
3997 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_PHY ||
3998 pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) {
3999 link_enc = pipe_ctx->stream->link->link_enc;
4000 config.dio_output_type = pipe_ctx->stream->link->ep_type;
4001 config.dio_output_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
4002 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_PHY)
4003 link_enc = pipe_ctx->stream->link->link_enc;
4004 else if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
4005 if (pipe_ctx->stream->link->dc->res_pool->funcs->link_encs_assign) {
4006 link_enc = link_enc_cfg_get_link_enc_used_by_stream(
4007 pipe_ctx->stream->ctx->dc,
4012 // Initialize PHY ID with ABCDE - 01234 mapping except when it is B0
4013 config.phy_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
4015 // Add flag to guard new A0 DIG mapping
4016 if (pipe_ctx->stream->ctx->dc->enable_c20_dtm_b0 == true &&
4017 pipe_ctx->stream->link->dc->ctx->dce_version == DCN_VERSION_3_1) {
4018 config.dig_be = link_enc->preferred_engine;
4019 config.dio_output_type = pipe_ctx->stream->link->ep_type;
4020 config.dio_output_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
4022 config.dio_output_type = 0;
4023 config.dio_output_idx = 0;
4026 // Add flag to guard B0 implementation
4027 if (pipe_ctx->stream->ctx->dc->enable_c20_dtm_b0 == true &&
4028 link_enc->ctx->asic_id.hw_internal_rev == YELLOW_CARP_B0) {
4029 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) {
4030 // enum ID 1-4 maps to DPIA PHY ID 0-3
4031 config.phy_idx = pipe_ctx->stream->link->link_id.enum_id - ENUM_ID_1;
4032 } else { // for non DPIA mode over B0, ABCDE maps to 01564
4034 switch (link_enc->transmitter) {
4035 case TRANSMITTER_UNIPHY_A:
4038 case TRANSMITTER_UNIPHY_B:
4041 case TRANSMITTER_UNIPHY_C:
4044 case TRANSMITTER_UNIPHY_D:
4047 case TRANSMITTER_UNIPHY_E:
4057 } else if (pipe_ctx->stream->link->dc->res_pool->funcs->link_encs_assign) {
4058 link_enc = link_enc_cfg_get_link_enc_used_by_stream(
4059 pipe_ctx->stream->ctx->dc,
4061 config.phy_idx = 0; /* Clear phy_idx for non-physical display endpoints. */
4065 config.link_enc_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
4066 if (is_dp_128b_132b_signal(pipe_ctx)) {
4067 config.stream_enc_idx = pipe_ctx->stream_res.hpo_dp_stream_enc->id - ENGINE_ID_HPO_DP_0;
4068 config.link_enc_idx = pipe_ctx->stream->link->hpo_dp_link_enc->inst;
4069 config.dp2_enabled = 1;
4072 config.dpms_off = dpms_off;
4073 config.dm_stream_ctx = pipe_ctx->stream->dm_stream_context;
4074 config.assr_enabled = (panel_mode == DP_PANEL_MODE_EDP);
4075 config.mst_enabled = (pipe_ctx->stream->signal ==
4076 SIGNAL_TYPE_DISPLAY_PORT_MST);
4077 cp_psp->funcs.update_stream_config(cp_psp->handle, &config);
4082 #if defined(CONFIG_DRM_AMD_DC_DCN)
4083 static void fpga_dp_hpo_enable_link_and_stream(struct dc_state *state, struct pipe_ctx *pipe_ctx)
4085 struct dc *dc = pipe_ctx->stream->ctx->dc;
4086 struct dc_stream_state *stream = pipe_ctx->stream;
4087 struct link_mst_stream_allocation_table proposed_table = {0};
4088 struct fixed31_32 avg_time_slots_per_mtp;
4089 uint8_t req_slot_count = 0;
4090 uint8_t vc_id = 1; /// VC ID always 1 for SST
4092 struct dc_link_settings link_settings = {0};
4093 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
4095 decide_link_settings(stream, &link_settings);
4096 stream->link->cur_link_settings = link_settings;
4098 /* Enable clock, Configure lane count, and Enable Link Encoder*/
4099 enable_dp_hpo_output(stream->link, &stream->link->cur_link_settings);
4102 /* Workaround for FPGA HPO capture DP link data:
4103 * HPO capture will set link to active mode
4104 * This workaround is required to get a capture from start of frame
4106 if (!dc->debug.fpga_hpo_capture_en) {
4107 struct encoder_set_dp_phy_pattern_param params = {0};
4108 params.dp_phy_pattern = DP_TEST_PATTERN_VIDEO_MODE;
4110 /* Set link active */
4111 stream->link->hpo_dp_link_enc->funcs->set_link_test_pattern(
4112 stream->link->hpo_dp_link_enc,
4117 /* Enable DP_STREAM_ENC */
4118 dc->hwss.enable_stream(pipe_ctx);
4120 /* Set DPS PPS SDP (AKA "info frames") */
4121 if (pipe_ctx->stream->timing.flags.DSC) {
4122 dp_set_dsc_pps_sdp(pipe_ctx, true, true);
4125 /* Allocate Payload */
4126 if ((stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) && (state->stream_count > 1)) {
4130 proposed_table.stream_count = state->stream_count;
4131 for (i = 0; i < state->stream_count; i++) {
4132 avg_time_slots_per_mtp = calculate_sst_avg_time_slots_per_mtp(state->streams[i], state->streams[i]->link);
4133 req_slot_count = dc_fixpt_ceil(avg_time_slots_per_mtp);
4134 proposed_table.stream_allocations[i].slot_count = req_slot_count;
4135 proposed_table.stream_allocations[i].vcp_id = i+1;
4136 /* NOTE: This makes assumption that pipe_ctx index is same as stream index */
4137 proposed_table.stream_allocations[i].hpo_dp_stream_enc = state->res_ctx.pipe_ctx[i].stream_res.hpo_dp_stream_enc;
4141 avg_time_slots_per_mtp = calculate_sst_avg_time_slots_per_mtp(stream, stream->link);
4142 req_slot_count = dc_fixpt_ceil(avg_time_slots_per_mtp);
4143 proposed_table.stream_count = 1; /// Always 1 stream for SST
4144 proposed_table.stream_allocations[0].slot_count = req_slot_count;
4145 proposed_table.stream_allocations[0].vcp_id = vc_id;
4146 proposed_table.stream_allocations[0].hpo_dp_stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
4149 stream->link->hpo_dp_link_enc->funcs->update_stream_allocation_table(
4150 stream->link->hpo_dp_link_enc,
4153 stream->link->hpo_dp_link_enc->funcs->set_throttled_vcp_size(
4154 stream->link->hpo_dp_link_enc,
4155 pipe_ctx->stream_res.hpo_dp_stream_enc->inst,
4156 avg_time_slots_per_mtp);
4160 dc->hwss.unblank_stream(pipe_ctx, &stream->link->cur_link_settings);
4164 void core_link_enable_stream(
4165 struct dc_state *state,
4166 struct pipe_ctx *pipe_ctx)
4168 struct dc *dc = pipe_ctx->stream->ctx->dc;
4169 struct dc_stream_state *stream = pipe_ctx->stream;
4170 struct dc_link *link = stream->sink->link;
4171 enum dc_status status;
4172 struct link_encoder *link_enc;
4173 #if defined(CONFIG_DRM_AMD_DC_DCN)
4174 enum otg_out_mux_dest otg_out_dest = OUT_MUX_DIO;
4175 struct vpg *vpg = pipe_ctx->stream_res.stream_enc->vpg;
4177 if (is_dp_128b_132b_signal(pipe_ctx))
4178 vpg = pipe_ctx->stream_res.hpo_dp_stream_enc->vpg;
4180 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
4182 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
4183 dc_is_virtual_signal(pipe_ctx->stream->signal))
4186 if (dc->res_pool->funcs->link_encs_assign && stream->link->ep_type != DISPLAY_ENDPOINT_PHY)
4187 link_enc = link_enc_cfg_get_link_enc_used_by_stream(dc, stream);
4189 link_enc = stream->link->link_enc;
4192 #if defined(CONFIG_DRM_AMD_DC_DCN)
4193 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)
4194 && !is_dp_128b_132b_signal(pipe_ctx)) {
4196 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)) {
4199 link_enc->funcs->setup(
4201 pipe_ctx->stream->signal);
4202 pipe_ctx->stream_res.stream_enc->funcs->setup_stereo_sync(
4203 pipe_ctx->stream_res.stream_enc,
4204 pipe_ctx->stream_res.tg->inst,
4205 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
4208 #if defined(CONFIG_DRM_AMD_DC_DCN)
4209 if (is_dp_128b_132b_signal(pipe_ctx)) {
4210 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->set_stream_attribute(
4211 pipe_ctx->stream_res.hpo_dp_stream_enc,
4213 stream->output_color_space,
4214 stream->use_vsc_sdp_for_colorimetry,
4215 stream->timing.flags.DSC,
4217 otg_out_dest = OUT_MUX_HPO_DP;
4218 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
4219 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
4220 pipe_ctx->stream_res.stream_enc,
4222 stream->output_color_space,
4223 stream->use_vsc_sdp_for_colorimetry,
4224 stream->link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
4227 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
4228 pipe_ctx->stream_res.stream_enc,
4230 stream->output_color_space,
4231 stream->use_vsc_sdp_for_colorimetry,
4232 stream->link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
4235 if (dc_is_dp_signal(pipe_ctx->stream->signal))
4236 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
4238 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
4239 pipe_ctx->stream_res.stream_enc->funcs->hdmi_set_stream_attribute(
4240 pipe_ctx->stream_res.stream_enc,
4242 stream->phy_pix_clk,
4243 pipe_ctx->stream_res.audio != NULL);
4245 pipe_ctx->stream->link->link_state_valid = true;
4247 #if defined(CONFIG_DRM_AMD_DC_DCN)
4248 if (pipe_ctx->stream_res.tg->funcs->set_out_mux)
4249 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, otg_out_dest);
4252 if (dc_is_dvi_signal(pipe_ctx->stream->signal))
4253 pipe_ctx->stream_res.stream_enc->funcs->dvi_set_stream_attribute(
4254 pipe_ctx->stream_res.stream_enc,
4256 (pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
4259 if (dc_is_lvds_signal(pipe_ctx->stream->signal))
4260 pipe_ctx->stream_res.stream_enc->funcs->lvds_set_stream_attribute(
4261 pipe_ctx->stream_res.stream_enc,
4264 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
4265 bool apply_edp_fast_boot_optimization =
4266 pipe_ctx->stream->apply_edp_fast_boot_optimization;
4268 pipe_ctx->stream->apply_edp_fast_boot_optimization = false;
4270 #if defined(CONFIG_DRM_AMD_DC_DCN)
4271 // Enable VPG before building infoframe
4272 if (vpg && vpg->funcs->vpg_poweron)
4273 vpg->funcs->vpg_poweron(vpg);
4276 resource_build_info_frame(pipe_ctx);
4277 dc->hwss.update_info_frame(pipe_ctx);
4279 if (dc_is_dp_signal(pipe_ctx->stream->signal))
4280 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
4282 /* Do not touch link on seamless boot optimization. */
4283 if (pipe_ctx->stream->apply_seamless_boot_optimization) {
4284 pipe_ctx->stream->dpms_off = false;
4286 /* Still enable stream features & audio on seamless boot for DP external displays */
4287 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT) {
4288 enable_stream_features(pipe_ctx);
4289 if (pipe_ctx->stream_res.audio != NULL) {
4290 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
4291 dc->hwss.enable_audio_stream(pipe_ctx);
4295 #if defined(CONFIG_DRM_AMD_DC_HDCP)
4296 update_psp_stream_config(pipe_ctx, false);
4301 /* eDP lit up by bios already, no need to enable again. */
4302 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
4303 apply_edp_fast_boot_optimization &&
4304 !pipe_ctx->stream->timing.flags.DSC &&
4305 !pipe_ctx->next_odm_pipe) {
4306 pipe_ctx->stream->dpms_off = false;
4307 #if defined(CONFIG_DRM_AMD_DC_HDCP)
4308 update_psp_stream_config(pipe_ctx, false);
4313 if (pipe_ctx->stream->dpms_off)
4316 /* Have to setup DSC before DIG FE and BE are connected (which happens before the
4317 * link training). This is to make sure the bandwidth sent to DIG BE won't be
4318 * bigger than what the link and/or DIG BE can handle. VBID[6]/CompressedStream_flag
4319 * will be automatically set at a later time when the video is enabled
4320 * (DP_VID_STREAM_EN = 1).
4322 if (pipe_ctx->stream->timing.flags.DSC) {
4323 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
4324 dc_is_virtual_signal(pipe_ctx->stream->signal))
4325 dp_set_dsc_enable(pipe_ctx, true);
4328 status = enable_link(state, pipe_ctx);
4330 if (status != DC_OK) {
4331 DC_LOG_WARNING("enabling link %u failed: %d\n",
4332 pipe_ctx->stream->link->link_index,
4335 /* Abort stream enable *unless* the failure was due to
4336 * DP link training - some DP monitors will recover and
4337 * show the stream anyway. But MST displays can't proceed
4338 * without link training.
4340 if (status != DC_FAIL_DP_LINK_TRAINING ||
4341 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
4342 if (false == stream->link->link_status.link_active)
4343 disable_link(stream->link, pipe_ctx->stream->signal);
4344 BREAK_TO_DEBUGGER();
4349 /* turn off otg test pattern if enable */
4350 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
4351 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
4352 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
4353 COLOR_DEPTH_UNDEFINED);
4355 /* This second call is needed to reconfigure the DIG
4356 * as a workaround for the incorrect value being applied
4357 * from transmitter control.
4359 #if defined(CONFIG_DRM_AMD_DC_DCN)
4360 if (!(dc_is_virtual_signal(pipe_ctx->stream->signal) ||
4361 is_dp_128b_132b_signal(pipe_ctx)))
4363 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
4366 link_enc->funcs->setup(
4368 pipe_ctx->stream->signal);
4370 dc->hwss.enable_stream(pipe_ctx);
4372 /* Set DPS PPS SDP (AKA "info frames") */
4373 if (pipe_ctx->stream->timing.flags.DSC) {
4374 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
4375 dc_is_virtual_signal(pipe_ctx->stream->signal)) {
4376 dp_set_dsc_on_rx(pipe_ctx, true);
4377 dp_set_dsc_pps_sdp(pipe_ctx, true, true);
4381 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
4382 dc_link_allocate_mst_payload(pipe_ctx);
4383 #if defined(CONFIG_DRM_AMD_DC_DCN)
4384 else if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
4385 is_dp_128b_132b_signal(pipe_ctx))
4386 dc_link_update_sst_payload(pipe_ctx, true);
4389 dc->hwss.unblank_stream(pipe_ctx,
4390 &pipe_ctx->stream->link->cur_link_settings);
4392 if (stream->sink_patches.delay_ignore_msa > 0)
4393 msleep(stream->sink_patches.delay_ignore_msa);
4395 if (dc_is_dp_signal(pipe_ctx->stream->signal))
4396 enable_stream_features(pipe_ctx);
4397 #if defined(CONFIG_DRM_AMD_DC_HDCP)
4398 update_psp_stream_config(pipe_ctx, false);
4401 dc->hwss.enable_audio_stream(pipe_ctx);
4403 } else { // if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
4404 #if defined(CONFIG_DRM_AMD_DC_DCN)
4405 if (is_dp_128b_132b_signal(pipe_ctx)) {
4406 fpga_dp_hpo_enable_link_and_stream(state, pipe_ctx);
4409 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
4410 dc_is_virtual_signal(pipe_ctx->stream->signal))
4411 dp_set_dsc_enable(pipe_ctx, true);
4415 if (pipe_ctx->stream->signal == SIGNAL_TYPE_HDMI_TYPE_A) {
4416 core_link_set_avmute(pipe_ctx, false);
4420 void core_link_disable_stream(struct pipe_ctx *pipe_ctx)
4422 struct dc *dc = pipe_ctx->stream->ctx->dc;
4423 struct dc_stream_state *stream = pipe_ctx->stream;
4424 struct dc_link *link = stream->sink->link;
4425 #if defined(CONFIG_DRM_AMD_DC_DCN)
4426 struct vpg *vpg = pipe_ctx->stream_res.stream_enc->vpg;
4428 if (is_dp_128b_132b_signal(pipe_ctx))
4429 vpg = pipe_ctx->stream_res.hpo_dp_stream_enc->vpg;
4432 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
4433 dc_is_virtual_signal(pipe_ctx->stream->signal))
4436 if (!pipe_ctx->stream->sink->edid_caps.panel_patch.skip_avmute) {
4437 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
4438 core_link_set_avmute(pipe_ctx, true);
4441 dc->hwss.disable_audio_stream(pipe_ctx);
4443 #if defined(CONFIG_DRM_AMD_DC_HDCP)
4444 update_psp_stream_config(pipe_ctx, true);
4446 dc->hwss.blank_stream(pipe_ctx);
4448 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
4449 deallocate_mst_payload(pipe_ctx);
4450 #if defined(CONFIG_DRM_AMD_DC_DCN)
4451 else if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
4452 is_dp_128b_132b_signal(pipe_ctx))
4453 dc_link_update_sst_payload(pipe_ctx, false);
4456 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
4457 struct ext_hdmi_settings settings = {0};
4458 enum engine_id eng_id = pipe_ctx->stream_res.stream_enc->id;
4460 unsigned short masked_chip_caps = link->chip_caps &
4461 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
4462 //Need to inform that sink is going to use legacy HDMI mode.
4463 dal_ddc_service_write_scdc_data(
4465 165000,//vbios only handles 165Mhz.
4467 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
4468 /* DP159, Retimer settings */
4469 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings))
4470 write_i2c_retimer_setting(pipe_ctx,
4471 false, false, &settings);
4473 write_i2c_default_retimer_setting(pipe_ctx,
4475 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
4476 /* PI3EQX1204, Redriver settings */
4477 write_i2c_redriver_setting(pipe_ctx, false);
4481 #if defined(CONFIG_DRM_AMD_DC_DCN)
4482 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
4483 !is_dp_128b_132b_signal(pipe_ctx)) {
4485 /* In DP1.x SST mode, our encoder will go to TPS1
4486 * when link is on but stream is off.
4487 * Disabling link before stream will avoid exposing TPS1 pattern
4488 * during the disable sequence as it will confuse some receivers
4490 * In DP2 or MST mode, our encoder will stay video active
4492 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
4493 dc->hwss.disable_stream(pipe_ctx);
4495 dc->hwss.disable_stream(pipe_ctx);
4496 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
4499 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
4501 dc->hwss.disable_stream(pipe_ctx);
4504 if (pipe_ctx->stream->timing.flags.DSC) {
4505 if (dc_is_dp_signal(pipe_ctx->stream->signal))
4506 dp_set_dsc_enable(pipe_ctx, false);
4508 #if defined(CONFIG_DRM_AMD_DC_DCN)
4509 if (is_dp_128b_132b_signal(pipe_ctx)) {
4510 if (pipe_ctx->stream_res.tg->funcs->set_out_mux)
4511 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, OUT_MUX_DIO);
4515 #if defined(CONFIG_DRM_AMD_DC_DCN)
4516 if (vpg && vpg->funcs->vpg_powerdown)
4517 vpg->funcs->vpg_powerdown(vpg);
4521 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
4523 struct dc *dc = pipe_ctx->stream->ctx->dc;
4525 if (!dc_is_hdmi_signal(pipe_ctx->stream->signal))
4528 dc->hwss.set_avmute(pipe_ctx, enable);
4532 * dc_link_enable_hpd_filter:
4533 * If enable is true, programs HPD filter on associated HPD line using
4534 * delay_on_disconnect/delay_on_connect values dependent on
4535 * link->connector_signal
4537 * If enable is false, programs HPD filter on associated HPD line with no
4538 * delays on connect or disconnect
4540 * @link: pointer to the dc link
4541 * @enable: boolean specifying whether to enable hbd
4543 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
4548 link->is_hpd_filter_disabled = false;
4549 program_hpd_filter(link);
4551 link->is_hpd_filter_disabled = true;
4552 /* Obtain HPD handle */
4553 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
4558 /* Setup HPD filtering */
4559 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
4560 struct gpio_hpd_config config;
4562 config.delay_on_connect = 0;
4563 config.delay_on_disconnect = 0;
4565 dal_irq_setup_hpd_filter(hpd, &config);
4567 dal_gpio_close(hpd);
4569 ASSERT_CRITICAL(false);
4571 /* Release HPD handle */
4572 dal_gpio_destroy_irq(&hpd);
4576 void dc_link_set_drive_settings(struct dc *dc,
4577 struct link_training_settings *lt_settings,
4578 const struct dc_link *link)
4583 for (i = 0; i < dc->link_count; i++) {
4584 if (dc->links[i] == link)
4588 if (i >= dc->link_count)
4589 ASSERT_CRITICAL(false);
4591 dc_link_dp_set_drive_settings(dc->links[i], lt_settings);
4594 void dc_link_set_preferred_link_settings(struct dc *dc,
4595 struct dc_link_settings *link_setting,
4596 struct dc_link *link)
4599 struct pipe_ctx *pipe;
4600 struct dc_stream_state *link_stream;
4601 struct dc_link_settings store_settings = *link_setting;
4603 link->preferred_link_setting = store_settings;
4605 /* Retrain with preferred link settings only relevant for
4607 * Check for non-DP signal or if passive dongle present
4609 if (!dc_is_dp_signal(link->connector_signal) ||
4610 link->dongle_max_pix_clk > 0)
4613 for (i = 0; i < MAX_PIPES; i++) {
4614 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
4615 if (pipe->stream && pipe->stream->link) {
4616 if (pipe->stream->link == link) {
4617 link_stream = pipe->stream;
4623 /* Stream not found */
4627 /* Cannot retrain link if backend is off */
4628 if (link_stream->dpms_off)
4631 decide_link_settings(link_stream, &store_settings);
4633 if ((store_settings.lane_count != LANE_COUNT_UNKNOWN) &&
4634 (store_settings.link_rate != LINK_RATE_UNKNOWN))
4635 dp_retrain_link_dp_test(link, &store_settings, false);
4638 void dc_link_set_preferred_training_settings(struct dc *dc,
4639 struct dc_link_settings *link_setting,
4640 struct dc_link_training_overrides *lt_overrides,
4641 struct dc_link *link,
4642 bool skip_immediate_retrain)
4644 if (lt_overrides != NULL)
4645 link->preferred_training_settings = *lt_overrides;
4647 memset(&link->preferred_training_settings, 0, sizeof(link->preferred_training_settings));
4649 if (link_setting != NULL) {
4650 link->preferred_link_setting = *link_setting;
4651 #if defined(CONFIG_DRM_AMD_DC_DCN)
4652 if (dp_get_link_encoding_format(link_setting) ==
4653 DP_128b_132b_ENCODING && !link->hpo_dp_link_enc) {
4654 if (!add_dp_hpo_link_encoder_to_link(link))
4655 memset(&link->preferred_link_setting, 0, sizeof(link->preferred_link_setting));
4659 link->preferred_link_setting.lane_count = LANE_COUNT_UNKNOWN;
4660 link->preferred_link_setting.link_rate = LINK_RATE_UNKNOWN;
4663 /* Retrain now, or wait until next stream update to apply */
4664 if (skip_immediate_retrain == false)
4665 dc_link_set_preferred_link_settings(dc, &link->preferred_link_setting, link);
4668 void dc_link_enable_hpd(const struct dc_link *link)
4670 dc_link_dp_enable_hpd(link);
4673 void dc_link_disable_hpd(const struct dc_link *link)
4675 dc_link_dp_disable_hpd(link);
4678 void dc_link_set_test_pattern(struct dc_link *link,
4679 enum dp_test_pattern test_pattern,
4680 enum dp_test_pattern_color_space test_pattern_color_space,
4681 const struct link_training_settings *p_link_settings,
4682 const unsigned char *p_custom_pattern,
4683 unsigned int cust_pattern_size)
4686 dc_link_dp_set_test_pattern(
4689 test_pattern_color_space,
4695 uint32_t dc_link_bandwidth_kbps(
4696 const struct dc_link *link,
4697 const struct dc_link_settings *link_setting)
4699 #if defined(CONFIG_DRM_AMD_DC_DCN)
4700 uint32_t total_data_bw_efficiency_x10000 = 0;
4701 uint32_t link_rate_per_lane_kbps = 0;
4703 switch (dp_get_link_encoding_format(link_setting)) {
4704 case DP_8b_10b_ENCODING:
4705 /* For 8b/10b encoding:
4706 * link rate is defined in the unit of LINK_RATE_REF_FREQ_IN_KHZ per DP byte per lane.
4707 * data bandwidth efficiency is 80% with additional 3% overhead if FEC is supported.
4709 link_rate_per_lane_kbps = link_setting->link_rate * LINK_RATE_REF_FREQ_IN_KHZ * BITS_PER_DP_BYTE;
4710 total_data_bw_efficiency_x10000 = DATA_EFFICIENCY_8b_10b_x10000;
4711 if (dc_link_should_enable_fec(link)) {
4712 total_data_bw_efficiency_x10000 /= 100;
4713 total_data_bw_efficiency_x10000 *= DATA_EFFICIENCY_8b_10b_FEC_EFFICIENCY_x100;
4716 case DP_128b_132b_ENCODING:
4717 /* For 128b/132b encoding:
4718 * link rate is defined in the unit of 10mbps per lane.
4719 * total data bandwidth efficiency is always 96.71%.
4721 link_rate_per_lane_kbps = link_setting->link_rate * 10000;
4722 total_data_bw_efficiency_x10000 = DATA_EFFICIENCY_128b_132b_x10000;
4728 /* overall effective link bandwidth = link rate per lane * lane count * total data bandwidth efficiency */
4729 return link_rate_per_lane_kbps * link_setting->lane_count / 10000 * total_data_bw_efficiency_x10000;
4731 uint32_t link_bw_kbps =
4732 link_setting->link_rate * LINK_RATE_REF_FREQ_IN_KHZ; /* bytes per sec */
4734 link_bw_kbps *= 8; /* 8 bits per byte*/
4735 link_bw_kbps *= link_setting->lane_count;
4737 if (dc_link_should_enable_fec(link)) {
4738 /* Account for FEC overhead.
4739 * We have to do it based on caps,
4740 * and not based on FEC being set ready,
4741 * because FEC is set ready too late in
4742 * the process to correctly be picked up
4743 * by mode enumeration.
4745 * There's enough zeros at the end of 'kbps'
4746 * that make the below operation 100% precise
4748 * 'long long' makes it work even for HDMI 2.1
4749 * max bandwidth (and much, much bigger bandwidths
4750 * than that, actually).
4752 * NOTE: Reducing link BW by 3% may not be precise
4753 * because it may be a stream BT that increases by 3%, and so
4754 * 1/1.03 = 0.970873 factor should have been used instead,
4755 * but the difference is minimal and is in a safe direction,
4756 * which all works well around potential ambiguity of DP 1.4a spec.
4758 long long fec_link_bw_kbps = link_bw_kbps * 970LL;
4759 link_bw_kbps = (uint32_t)(div64_s64(fec_link_bw_kbps, 1000LL));
4761 return link_bw_kbps;
4766 const struct dc_link_settings *dc_link_get_link_cap(
4767 const struct dc_link *link)
4769 if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
4770 link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
4771 return &link->preferred_link_setting;
4772 return &link->verified_link_cap;
4775 void dc_link_overwrite_extended_receiver_cap(
4776 struct dc_link *link)
4778 dp_overwrite_extended_receiver_cap(link);
4781 bool dc_link_is_fec_supported(const struct dc_link *link)
4783 struct link_encoder *link_enc = NULL;
4785 /* Links supporting dynamically assigned link encoder will be assigned next
4786 * available encoder if one not already assigned.
4788 if (link->is_dig_mapping_flexible &&
4789 link->dc->res_pool->funcs->link_encs_assign) {
4790 link_enc = link_enc_cfg_get_link_enc_used_by_link(link->ctx->dc, link);
4791 if (link_enc == NULL)
4792 link_enc = link_enc_cfg_get_next_avail_link_enc(link->ctx->dc);
4794 link_enc = link->link_enc;
4797 return (dc_is_dp_signal(link->connector_signal) && link_enc &&
4798 link_enc->features.fec_supported &&
4799 link->dpcd_caps.fec_cap.bits.FEC_CAPABLE &&
4800 !IS_FPGA_MAXIMUS_DC(link->ctx->dce_environment));
4803 bool dc_link_should_enable_fec(const struct dc_link *link)
4805 bool is_fec_disable = false;
4808 if ((link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT_MST &&
4810 link->local_sink->edid_caps.panel_patch.disable_fec) ||
4811 (link->connector_signal == SIGNAL_TYPE_EDP
4812 // enable FEC for EDP if DSC is supported
4813 && link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT == false
4815 is_fec_disable = true;
4817 if (dc_link_is_fec_supported(link) && !link->dc->debug.disable_fec && !is_fec_disable)
4823 uint32_t dc_bandwidth_in_kbps_from_timing(
4824 const struct dc_crtc_timing *timing)
4826 uint32_t bits_per_channel = 0;
4829 #if defined(CONFIG_DRM_AMD_DC_DCN)
4830 if (timing->flags.DSC)
4831 return dc_dsc_stream_bandwidth_in_kbps(timing,
4832 timing->dsc_cfg.bits_per_pixel,
4833 timing->dsc_cfg.num_slices_h,
4834 timing->dsc_cfg.is_dp);
4835 #endif /* CONFIG_DRM_AMD_DC_DCN */
4837 switch (timing->display_color_depth) {
4838 case COLOR_DEPTH_666:
4839 bits_per_channel = 6;
4841 case COLOR_DEPTH_888:
4842 bits_per_channel = 8;
4844 case COLOR_DEPTH_101010:
4845 bits_per_channel = 10;
4847 case COLOR_DEPTH_121212:
4848 bits_per_channel = 12;
4850 case COLOR_DEPTH_141414:
4851 bits_per_channel = 14;
4853 case COLOR_DEPTH_161616:
4854 bits_per_channel = 16;
4857 ASSERT(bits_per_channel != 0);
4858 bits_per_channel = 8;
4862 kbps = timing->pix_clk_100hz / 10;
4863 kbps *= bits_per_channel;
4865 if (timing->flags.Y_ONLY != 1) {
4866 /*Only YOnly make reduce bandwidth by 1/3 compares to RGB*/
4868 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
4870 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
4871 kbps = kbps * 2 / 3;