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->hpd_status)
274 *type = dc_connection_single;
276 *type = dc_connection_none;
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_HDCP)
762 /* In case of fallback to SST when topology discovery below fails
763 * HDCP caps will be querried again later by the upper layer (caller
764 * of this function). */
765 query_hdcp_capability(SIGNAL_TYPE_DISPLAY_PORT_MST, link);
769 if (link->type != dc_connection_mst_branch &&
770 is_dp_branch_device(link))
772 link->type = dc_connection_sst_branch;
774 /* DP passive dongles */
775 sink_caps->signal = dp_passive_dongle_detection(link->ddc,
778 link->dpcd_caps.dongle_type = sink_caps->dongle_type;
779 link->dpcd_caps.dpcd_rev.raw = 0;
785 static bool is_same_edid(struct dc_edid *old_edid, struct dc_edid *new_edid)
787 if (old_edid->length != new_edid->length)
790 if (new_edid->length == 0)
793 return (memcmp(old_edid->raw_edid,
794 new_edid->raw_edid, new_edid->length) == 0);
797 static bool wait_for_entering_dp_alt_mode(struct dc_link *link)
800 * something is terribly wrong if time out is > 200ms. (5Hz)
801 * 500 microseconds * 400 tries us 200 ms
803 unsigned int sleep_time_in_microseconds = 500;
804 unsigned int tries_allowed = 400;
806 unsigned long long enter_timestamp;
807 unsigned long long finish_timestamp;
808 unsigned long long time_taken_in_ns;
811 DC_LOGGER_INIT(link->ctx->logger);
813 if (!link->link_enc->funcs->is_in_alt_mode)
816 is_in_alt_mode = link->link_enc->funcs->is_in_alt_mode(link->link_enc);
817 DC_LOG_WARNING("DP Alt mode state on HPD: %d\n", is_in_alt_mode);
822 enter_timestamp = dm_get_timestamp(link->ctx);
824 for (tries_taken = 0; tries_taken < tries_allowed; tries_taken++) {
825 udelay(sleep_time_in_microseconds);
826 /* ask the link if alt mode is enabled, if so return ok */
827 if (link->link_enc->funcs->is_in_alt_mode(link->link_enc)) {
828 finish_timestamp = dm_get_timestamp(link->ctx);
830 dm_get_elapse_time_in_ns(link->ctx,
833 DC_LOG_WARNING("Alt mode entered finished after %llu ms\n",
834 div_u64(time_taken_in_ns, 1000000));
838 finish_timestamp = dm_get_timestamp(link->ctx);
839 time_taken_in_ns = dm_get_elapse_time_in_ns(link->ctx, finish_timestamp,
841 DC_LOG_WARNING("Alt mode has timed out after %llu ms\n",
842 div_u64(time_taken_in_ns, 1000000));
847 * dc_link_detect() - Detect if a sink is attached to a given link
849 * link->local_sink is created or destroyed as needed.
851 * This does not create remote sinks but will trigger DM
852 * to start MST detection if a branch is detected.
854 static bool dc_link_detect_helper(struct dc_link *link,
855 enum dc_detect_reason reason)
857 struct dc_sink_init_data sink_init_data = { 0 };
858 struct display_sink_capability sink_caps = { 0 };
860 bool converter_disable_audio = false;
861 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
862 bool same_edid = false;
863 enum dc_edid_status edid_status;
864 struct dc_context *dc_ctx = link->ctx;
865 struct dc_sink *sink = NULL;
866 struct dc_sink *prev_sink = NULL;
867 struct dpcd_caps prev_dpcd_caps;
868 enum dc_connection_type new_connection_type = dc_connection_none;
869 enum dc_connection_type pre_connection_type = dc_connection_none;
870 bool perform_dp_seamless_boot = false;
871 const uint32_t post_oui_delay = 30; // 30ms
873 DC_LOGGER_INIT(link->ctx->logger);
875 if (dc_is_virtual_signal(link->connector_signal))
878 if (((link->connector_signal == SIGNAL_TYPE_LVDS ||
879 link->connector_signal == SIGNAL_TYPE_EDP) &&
880 (!link->dc->config.allow_edp_hotplug_detection)) &&
882 // need to re-write OUI and brightness in resume case
883 if (link->connector_signal == SIGNAL_TYPE_EDP) {
884 dpcd_set_source_specific_data(link);
885 msleep(post_oui_delay);
886 dc_link_set_default_brightness_aux(link);
893 if (!dc_link_detect_sink(link, &new_connection_type)) {
898 prev_sink = link->local_sink;
900 dc_sink_retain(prev_sink);
901 memcpy(&prev_dpcd_caps, &link->dpcd_caps, sizeof(struct dpcd_caps));
904 link_disconnect_sink(link);
905 if (new_connection_type != dc_connection_none) {
906 pre_connection_type = link->type;
907 link->type = new_connection_type;
908 link->link_state_valid = false;
910 /* From Disconnected-to-Connected. */
911 switch (link->connector_signal) {
912 case SIGNAL_TYPE_HDMI_TYPE_A: {
913 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
914 if (aud_support->hdmi_audio_native)
915 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A;
917 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
921 case SIGNAL_TYPE_DVI_SINGLE_LINK: {
922 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
923 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
927 case SIGNAL_TYPE_DVI_DUAL_LINK: {
928 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
929 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK;
933 case SIGNAL_TYPE_LVDS: {
934 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
935 sink_caps.signal = SIGNAL_TYPE_LVDS;
939 case SIGNAL_TYPE_EDP: {
940 read_current_link_settings_on_detect(link);
942 detect_edp_sink_caps(link);
943 read_current_link_settings_on_detect(link);
944 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
945 sink_caps.signal = SIGNAL_TYPE_EDP;
949 case SIGNAL_TYPE_DISPLAY_PORT: {
950 /* wa HPD high coming too early*/
951 if (link->ep_type == DISPLAY_ENDPOINT_PHY &&
952 link->link_enc->features.flags.bits.DP_IS_USB_C == 1) {
953 /* if alt mode times out, return false */
954 if (!wait_for_entering_dp_alt_mode(link))
958 if (!detect_dp(link, &sink_caps, reason)) {
960 dc_sink_release(prev_sink);
964 #if defined(CONFIG_DRM_AMD_DC_DCN)
965 if (dp_get_link_encoding_format(&link->reported_link_cap) == DP_128b_132b_ENCODING)
966 add_dp_hpo_link_encoder_to_link(link);
969 if (link->type == dc_connection_mst_branch) {
970 LINK_INFO("link=%d, mst branch is now Connected\n",
972 /* Need to setup mst link_cap struct here
973 * otherwise dc_link_detect() will leave mst link_cap
974 * empty which leads to allocate_mst_payload() has "0"
975 * pbn_per_slot value leading to exception on dc_fixpt_div()
977 dp_verify_mst_link_cap(link);
980 * This call will initiate MST topology discovery. Which
981 * will detect MST ports and add new DRM connector DRM
982 * framework. Then read EDID via remote i2c over aux. In
983 * the end, will notify DRM detect result and save EDID
984 * into DRM framework.
986 * .detect is called by .fill_modes.
987 * .fill_modes is called by user mode ioctl
988 * DRM_IOCTL_MODE_GETCONNECTOR.
990 * .get_modes is called by .fill_modes.
992 * call .get_modes, AMDGPU DM implementation will create
993 * new dc_sink and add to dc_link. For long HPD plug
994 * in/out, MST has its own handle.
996 * Therefore, just after dc_create, link->sink is not
997 * created for MST until user mode app calls
998 * DRM_IOCTL_MODE_GETCONNECTOR.
1000 * Need check ->sink usages in case ->sink = NULL
1001 * TODO: s3 resume check
1004 dm_helpers_dp_update_branch_info(link->ctx, link);
1005 if (dm_helpers_dp_mst_start_top_mgr(link->ctx,
1006 link, reason == DETECT_REASON_BOOT)) {
1008 dc_sink_release(prev_sink);
1011 link->type = dc_connection_sst_branch;
1012 sink_caps.signal = SIGNAL_TYPE_DISPLAY_PORT;
1016 /* Active SST downstream branch device unplug*/
1017 if (link->type == dc_connection_sst_branch &&
1018 link->dpcd_caps.sink_count.bits.SINK_COUNT == 0) {
1020 /* Downstream unplug */
1021 dc_sink_release(prev_sink);
1025 /* disable audio for non DP to HDMI active sst converter */
1026 if (link->type == dc_connection_sst_branch &&
1027 is_dp_active_dongle(link) &&
1028 (link->dpcd_caps.dongle_type !=
1029 DISPLAY_DONGLE_DP_HDMI_CONVERTER))
1030 converter_disable_audio = true;
1032 // link switch from MST to non-MST stop topology manager
1033 if (pre_connection_type == dc_connection_mst_branch &&
1034 link->type != dc_connection_mst_branch)
1035 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
1038 // For seamless boot, to skip verify link cap, we read UEFI settings and set them as verified.
1039 if (reason == DETECT_REASON_BOOT &&
1040 !dc_ctx->dc->config.power_down_display_on_boot &&
1041 link->link_status.link_active)
1042 perform_dp_seamless_boot = true;
1044 if (perform_dp_seamless_boot) {
1045 read_current_link_settings_on_detect(link);
1046 link->verified_link_cap = link->reported_link_cap;
1053 DC_ERROR("Invalid connector type! signal:%d\n",
1054 link->connector_signal);
1056 dc_sink_release(prev_sink);
1060 if (link->dpcd_caps.sink_count.bits.SINK_COUNT)
1061 link->dpcd_sink_count =
1062 link->dpcd_caps.sink_count.bits.SINK_COUNT;
1064 link->dpcd_sink_count = 1;
1066 dal_ddc_service_set_transaction_type(link->ddc,
1067 sink_caps.transaction_type);
1070 dal_ddc_service_is_in_aux_transaction_mode(link->ddc);
1072 sink_init_data.link = link;
1073 sink_init_data.sink_signal = sink_caps.signal;
1075 sink = dc_sink_create(&sink_init_data);
1077 DC_ERROR("Failed to create sink!\n");
1079 dc_sink_release(prev_sink);
1083 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock;
1084 sink->converter_disable_audio = converter_disable_audio;
1086 /* dc_sink_create returns a new reference */
1087 link->local_sink = sink;
1089 edid_status = dm_helpers_read_local_edid(link->ctx,
1092 switch (edid_status) {
1093 case EDID_BAD_CHECKSUM:
1094 DC_LOG_ERROR("EDID checksum invalid.\n");
1096 case EDID_NO_RESPONSE:
1097 DC_LOG_ERROR("No EDID read.\n");
1099 * Abort detection for non-DP connectors if we have
1102 * DP needs to report as connected if HDP is high
1103 * even if we have no EDID in order to go to
1106 if (dc_is_hdmi_signal(link->connector_signal) ||
1107 dc_is_dvi_signal(link->connector_signal)) {
1109 dc_sink_release(prev_sink);
1118 // Check if edid is the same
1120 (edid_status == EDID_THE_SAME || edid_status == EDID_OK))
1121 same_edid = is_same_edid(&prev_sink->dc_edid,
1124 if (sink->edid_caps.panel_patch.skip_scdc_overwrite)
1125 link->ctx->dc->debug.hdmi20_disable = true;
1127 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
1128 sink_caps.transaction_type ==
1129 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
1131 * TODO debug why Dell 2413 doesn't like
1132 * two link trainings
1134 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1135 query_hdcp_capability(sink->sink_signal, link);
1138 // verify link cap for SST non-seamless boot
1139 if (!perform_dp_seamless_boot)
1140 dp_verify_link_cap_with_retries(link,
1141 &link->reported_link_cap,
1142 LINK_TRAINING_MAX_VERIFY_RETRY);
1144 // If edid is the same, then discard new sink and revert back to original sink
1146 link_disconnect_remap(prev_sink, link);
1150 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1151 query_hdcp_capability(sink->sink_signal, link);
1155 /* HDMI-DVI Dongle */
1156 if (sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A &&
1157 !sink->edid_caps.edid_hdmi)
1158 sink->sink_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1160 /* Connectivity log: detection */
1161 for (i = 0; i < sink->dc_edid.length / DC_EDID_BLOCK_SIZE; i++) {
1162 CONN_DATA_DETECT(link,
1163 &sink->dc_edid.raw_edid[i * DC_EDID_BLOCK_SIZE],
1165 "%s: [Block %d] ", sink->edid_caps.display_name, i);
1168 DC_LOG_DETECTION_EDID_PARSER("%s: "
1169 "manufacturer_id = %X, "
1171 "serial_number = %X, "
1172 "manufacture_week = %d, "
1173 "manufacture_year = %d, "
1174 "display_name = %s, "
1175 "speaker_flag = %d, "
1176 "audio_mode_count = %d\n",
1178 sink->edid_caps.manufacturer_id,
1179 sink->edid_caps.product_id,
1180 sink->edid_caps.serial_number,
1181 sink->edid_caps.manufacture_week,
1182 sink->edid_caps.manufacture_year,
1183 sink->edid_caps.display_name,
1184 sink->edid_caps.speaker_flags,
1185 sink->edid_caps.audio_mode_count);
1187 for (i = 0; i < sink->edid_caps.audio_mode_count; i++) {
1188 DC_LOG_DETECTION_EDID_PARSER("%s: mode number = %d, "
1189 "format_code = %d, "
1190 "channel_count = %d, "
1191 "sample_rate = %d, "
1192 "sample_size = %d\n",
1195 sink->edid_caps.audio_modes[i].format_code,
1196 sink->edid_caps.audio_modes[i].channel_count,
1197 sink->edid_caps.audio_modes[i].sample_rate,
1198 sink->edid_caps.audio_modes[i].sample_size);
1201 /* From Connected-to-Disconnected. */
1202 if (link->type == dc_connection_mst_branch) {
1203 LINK_INFO("link=%d, mst branch is now Disconnected\n",
1206 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
1208 link->mst_stream_alloc_table.stream_count = 0;
1209 memset(link->mst_stream_alloc_table.stream_allocations,
1211 sizeof(link->mst_stream_alloc_table.stream_allocations));
1214 #if defined(CONFIG_DRM_AMD_DC_DCN)
1215 if (dp_get_link_encoding_format(&link->cur_link_settings) == DP_128b_132b_ENCODING)
1216 reset_dp_hpo_stream_encoders_for_link(link);
1219 link->type = dc_connection_none;
1220 sink_caps.signal = SIGNAL_TYPE_NONE;
1221 /* When we unplug a passive DP-HDMI dongle connection, dongle_max_pix_clk
1222 * is not cleared. If we emulate a DP signal on this connection, it thinks
1223 * the dongle is still there and limits the number of modes we can emulate.
1224 * Clear dongle_max_pix_clk on disconnect to fix this
1226 link->dongle_max_pix_clk = 0;
1229 LINK_INFO("link=%d, dc_sink_in=%p is now %s prev_sink=%p edid same=%d\n",
1230 link->link_index, sink,
1231 (sink_caps.signal ==
1232 SIGNAL_TYPE_NONE ? "Disconnected" : "Connected"),
1233 prev_sink, same_edid);
1236 dc_sink_release(prev_sink);
1241 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
1243 const struct dc *dc = link->dc;
1245 bool can_apply_seamless_boot = false;
1248 for (i = 0; i < dc->current_state->stream_count; i++) {
1249 if (dc->current_state->streams[i]->apply_seamless_boot_optimization) {
1250 can_apply_seamless_boot = true;
1255 #if defined(CONFIG_DRM_AMD_DC_DCN)
1259 /* get out of low power state */
1260 if (!can_apply_seamless_boot && reason != DETECT_REASON_BOOT)
1261 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
1263 ret = dc_link_detect_helper(link, reason);
1265 /* Go back to power optimized state */
1266 if (!can_apply_seamless_boot && reason != DETECT_REASON_BOOT)
1267 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
1272 bool dc_link_get_hpd_state(struct dc_link *dc_link)
1276 dal_gpio_lock_pin(dc_link->hpd_gpio);
1277 dal_gpio_get_value(dc_link->hpd_gpio, &state);
1278 dal_gpio_unlock_pin(dc_link->hpd_gpio);
1283 static enum hpd_source_id get_hpd_line(struct dc_link *link)
1286 enum hpd_source_id hpd_id = HPD_SOURCEID_UNKNOWN;
1288 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1289 link->ctx->gpio_service);
1292 switch (dal_irq_get_source(hpd)) {
1293 case DC_IRQ_SOURCE_HPD1:
1294 hpd_id = HPD_SOURCEID1;
1296 case DC_IRQ_SOURCE_HPD2:
1297 hpd_id = HPD_SOURCEID2;
1299 case DC_IRQ_SOURCE_HPD3:
1300 hpd_id = HPD_SOURCEID3;
1302 case DC_IRQ_SOURCE_HPD4:
1303 hpd_id = HPD_SOURCEID4;
1305 case DC_IRQ_SOURCE_HPD5:
1306 hpd_id = HPD_SOURCEID5;
1308 case DC_IRQ_SOURCE_HPD6:
1309 hpd_id = HPD_SOURCEID6;
1312 BREAK_TO_DEBUGGER();
1316 dal_gpio_destroy_irq(&hpd);
1322 static enum channel_id get_ddc_line(struct dc_link *link)
1325 enum channel_id channel = CHANNEL_ID_UNKNOWN;
1327 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
1330 switch (dal_ddc_get_line(ddc)) {
1331 case GPIO_DDC_LINE_DDC1:
1332 channel = CHANNEL_ID_DDC1;
1334 case GPIO_DDC_LINE_DDC2:
1335 channel = CHANNEL_ID_DDC2;
1337 case GPIO_DDC_LINE_DDC3:
1338 channel = CHANNEL_ID_DDC3;
1340 case GPIO_DDC_LINE_DDC4:
1341 channel = CHANNEL_ID_DDC4;
1343 case GPIO_DDC_LINE_DDC5:
1344 channel = CHANNEL_ID_DDC5;
1346 case GPIO_DDC_LINE_DDC6:
1347 channel = CHANNEL_ID_DDC6;
1349 case GPIO_DDC_LINE_DDC_VGA:
1350 channel = CHANNEL_ID_DDC_VGA;
1352 case GPIO_DDC_LINE_I2C_PAD:
1353 channel = CHANNEL_ID_I2C_PAD;
1356 BREAK_TO_DEBUGGER();
1364 static enum transmitter translate_encoder_to_transmitter(struct graphics_object_id encoder)
1366 switch (encoder.id) {
1367 case ENCODER_ID_INTERNAL_UNIPHY:
1368 switch (encoder.enum_id) {
1370 return TRANSMITTER_UNIPHY_A;
1372 return TRANSMITTER_UNIPHY_B;
1374 return TRANSMITTER_UNKNOWN;
1377 case ENCODER_ID_INTERNAL_UNIPHY1:
1378 switch (encoder.enum_id) {
1380 return TRANSMITTER_UNIPHY_C;
1382 return TRANSMITTER_UNIPHY_D;
1384 return TRANSMITTER_UNKNOWN;
1387 case ENCODER_ID_INTERNAL_UNIPHY2:
1388 switch (encoder.enum_id) {
1390 return TRANSMITTER_UNIPHY_E;
1392 return TRANSMITTER_UNIPHY_F;
1394 return TRANSMITTER_UNKNOWN;
1397 case ENCODER_ID_INTERNAL_UNIPHY3:
1398 switch (encoder.enum_id) {
1400 return TRANSMITTER_UNIPHY_G;
1402 return TRANSMITTER_UNKNOWN;
1405 case ENCODER_ID_EXTERNAL_NUTMEG:
1406 switch (encoder.enum_id) {
1408 return TRANSMITTER_NUTMEG_CRT;
1410 return TRANSMITTER_UNKNOWN;
1413 case ENCODER_ID_EXTERNAL_TRAVIS:
1414 switch (encoder.enum_id) {
1416 return TRANSMITTER_TRAVIS_CRT;
1418 return TRANSMITTER_TRAVIS_LCD;
1420 return TRANSMITTER_UNKNOWN;
1424 return TRANSMITTER_UNKNOWN;
1428 static bool dc_link_construct_legacy(struct dc_link *link,
1429 const struct link_init_data *init_params)
1432 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1433 struct dc_context *dc_ctx = init_params->ctx;
1434 struct encoder_init_data enc_init_data = { 0 };
1435 struct panel_cntl_init_data panel_cntl_init_data = { 0 };
1436 struct integrated_info *info;
1437 struct dc_bios *bios = init_params->dc->ctx->dc_bios;
1438 const struct dc_vbios_funcs *bp_funcs = bios->funcs;
1439 struct bp_disp_connector_caps_info disp_connect_caps_info = { 0 };
1441 DC_LOGGER_INIT(dc_ctx->logger);
1443 info = kzalloc(sizeof(*info), GFP_KERNEL);
1447 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1448 link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
1450 link->link_status.dpcd_caps = &link->dpcd_caps;
1452 link->dc = init_params->dc;
1454 link->link_index = init_params->link_index;
1456 memset(&link->preferred_training_settings, 0,
1457 sizeof(struct dc_link_training_overrides));
1458 memset(&link->preferred_link_setting, 0,
1459 sizeof(struct dc_link_settings));
1462 bios->funcs->get_connector_id(bios, init_params->connector_index);
1464 link->ep_type = DISPLAY_ENDPOINT_PHY;
1466 DC_LOG_DC("BIOS object table - link_id: %d", link->link_id.id);
1468 if (bios->funcs->get_disp_connector_caps_info) {
1469 bios->funcs->get_disp_connector_caps_info(bios, link->link_id, &disp_connect_caps_info);
1470 link->is_internal_display = disp_connect_caps_info.INTERNAL_DISPLAY;
1471 DC_LOG_DC("BIOS object table - is_internal_display: %d", link->is_internal_display);
1474 if (link->link_id.type != OBJECT_TYPE_CONNECTOR) {
1475 dm_output_to_console("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d! type %d expected %d\n",
1476 __func__, init_params->connector_index,
1477 link->link_id.type, OBJECT_TYPE_CONNECTOR);
1481 if (link->dc->res_pool->funcs->link_init)
1482 link->dc->res_pool->funcs->link_init(link);
1484 link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1485 link->ctx->gpio_service);
1487 if (link->hpd_gpio) {
1488 dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
1489 dal_gpio_unlock_pin(link->hpd_gpio);
1490 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
1492 DC_LOG_DC("BIOS object table - hpd_gpio id: %d", link->hpd_gpio->id);
1493 DC_LOG_DC("BIOS object table - hpd_gpio en: %d", link->hpd_gpio->en);
1496 switch (link->link_id.id) {
1497 case CONNECTOR_ID_HDMI_TYPE_A:
1498 link->connector_signal = SIGNAL_TYPE_HDMI_TYPE_A;
1501 case CONNECTOR_ID_SINGLE_LINK_DVID:
1502 case CONNECTOR_ID_SINGLE_LINK_DVII:
1503 link->connector_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1505 case CONNECTOR_ID_DUAL_LINK_DVID:
1506 case CONNECTOR_ID_DUAL_LINK_DVII:
1507 link->connector_signal = SIGNAL_TYPE_DVI_DUAL_LINK;
1509 case CONNECTOR_ID_DISPLAY_PORT:
1510 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1513 link->irq_source_hpd_rx =
1514 dal_irq_get_rx_source(link->hpd_gpio);
1517 case CONNECTOR_ID_EDP:
1518 link->connector_signal = SIGNAL_TYPE_EDP;
1520 if (link->hpd_gpio) {
1521 if (!link->dc->config.allow_edp_hotplug_detection)
1522 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1523 link->irq_source_hpd_rx =
1524 dal_irq_get_rx_source(link->hpd_gpio);
1528 case CONNECTOR_ID_LVDS:
1529 link->connector_signal = SIGNAL_TYPE_LVDS;
1532 DC_LOG_WARNING("Unsupported Connector type:%d!\n",
1537 /* TODO: #DAL3 Implement id to str function.*/
1538 LINK_INFO("Connector[%d] description:"
1540 init_params->connector_index,
1541 link->connector_signal);
1543 ddc_service_init_data.ctx = link->ctx;
1544 ddc_service_init_data.id = link->link_id;
1545 ddc_service_init_data.link = link;
1546 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1549 DC_ERROR("Failed to create ddc_service!\n");
1550 goto ddc_create_fail;
1553 if (!link->ddc->ddc_pin) {
1554 DC_ERROR("Failed to get I2C info for connector!\n");
1555 goto ddc_create_fail;
1559 dal_ddc_get_line(dal_ddc_service_get_ddc_pin(link->ddc));
1562 if (link->dc->res_pool->funcs->panel_cntl_create &&
1563 (link->link_id.id == CONNECTOR_ID_EDP ||
1564 link->link_id.id == CONNECTOR_ID_LVDS)) {
1565 panel_cntl_init_data.ctx = dc_ctx;
1566 panel_cntl_init_data.inst =
1567 panel_cntl_init_data.ctx->dc_edp_id_count;
1569 link->dc->res_pool->funcs->panel_cntl_create(
1570 &panel_cntl_init_data);
1571 panel_cntl_init_data.ctx->dc_edp_id_count++;
1573 if (link->panel_cntl == NULL) {
1574 DC_ERROR("Failed to create link panel_cntl!\n");
1575 goto panel_cntl_create_fail;
1579 enc_init_data.ctx = dc_ctx;
1580 bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0,
1581 &enc_init_data.encoder);
1582 enc_init_data.connector = link->link_id;
1583 enc_init_data.channel = get_ddc_line(link);
1584 enc_init_data.hpd_source = get_hpd_line(link);
1586 link->hpd_src = enc_init_data.hpd_source;
1588 enc_init_data.transmitter =
1589 translate_encoder_to_transmitter(enc_init_data.encoder);
1591 link->dc->res_pool->funcs->link_enc_create(&enc_init_data);
1593 if (!link->link_enc) {
1594 DC_ERROR("Failed to create link encoder!\n");
1595 goto link_enc_create_fail;
1598 DC_LOG_DC("BIOS object table - DP_IS_USB_C: %d", link->link_enc->features.flags.bits.DP_IS_USB_C);
1599 #if defined(CONFIG_DRM_AMD_DC_DCN)
1600 DC_LOG_DC("BIOS object table - IS_DP2_CAPABLE: %d", link->link_enc->features.flags.bits.IS_DP2_CAPABLE);
1603 /* Update link encoder tracking variables. These are used for the dynamic
1604 * assignment of link encoders to streams.
1606 link->eng_id = link->link_enc->preferred_engine;
1607 link->dc->res_pool->link_encoders[link->eng_id - ENGINE_ID_DIGA] = link->link_enc;
1608 link->dc->res_pool->dig_link_enc_count++;
1610 link->link_enc_hw_inst = link->link_enc->transmitter;
1612 for (i = 0; i < 4; i++) {
1613 if (bp_funcs->get_device_tag(dc_ctx->dc_bios,
1615 &link->device_tag) != BP_RESULT_OK) {
1616 DC_ERROR("Failed to find device tag!\n");
1617 goto device_tag_fail;
1620 /* Look for device tag that matches connector signal,
1621 * CRT for rgb, LCD for other supported signal tyes
1623 if (!bp_funcs->is_device_id_supported(dc_ctx->dc_bios,
1624 link->device_tag.dev_id))
1626 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_CRT &&
1627 link->connector_signal != SIGNAL_TYPE_RGB)
1629 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_LCD &&
1630 link->connector_signal == SIGNAL_TYPE_RGB)
1633 DC_LOG_DC("BIOS object table - device_tag.acpi_device: %d", link->device_tag.acpi_device);
1634 DC_LOG_DC("BIOS object table - device_tag.dev_id.device_type: %d", link->device_tag.dev_id.device_type);
1635 DC_LOG_DC("BIOS object table - device_tag.dev_id.enum_id: %d", link->device_tag.dev_id.enum_id);
1639 if (bios->integrated_info)
1640 memcpy(info, bios->integrated_info, sizeof(*info));
1642 /* Look for channel mapping corresponding to connector and device tag */
1643 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
1644 struct external_display_path *path =
1645 &info->ext_disp_conn_info.path[i];
1647 if (path->device_connector_id.enum_id == link->link_id.enum_id &&
1648 path->device_connector_id.id == link->link_id.id &&
1649 path->device_connector_id.type == link->link_id.type) {
1650 if (link->device_tag.acpi_device != 0 &&
1651 path->device_acpi_enum == link->device_tag.acpi_device) {
1652 link->ddi_channel_mapping = path->channel_mapping;
1653 link->chip_caps = path->caps;
1654 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1655 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1656 } else if (path->device_tag ==
1657 link->device_tag.dev_id.raw_device_tag) {
1658 link->ddi_channel_mapping = path->channel_mapping;
1659 link->chip_caps = path->caps;
1660 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1661 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1667 if (bios->funcs->get_atom_dc_golden_table)
1668 bios->funcs->get_atom_dc_golden_table(bios);
1671 * TODO check if GPIO programmed correctly
1673 * If GPIO isn't programmed correctly HPD might not rise or drain
1674 * fast enough, leading to bounces.
1676 program_hpd_filter(link);
1678 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
1680 DC_LOG_DC("BIOS object table - %s finished successfully.\n", __func__);
1684 link->link_enc->funcs->destroy(&link->link_enc);
1685 link_enc_create_fail:
1686 if (link->panel_cntl != NULL)
1687 link->panel_cntl->funcs->destroy(&link->panel_cntl);
1688 panel_cntl_create_fail:
1689 dal_ddc_service_destroy(&link->ddc);
1693 if (link->hpd_gpio) {
1694 dal_gpio_destroy_irq(&link->hpd_gpio);
1695 link->hpd_gpio = NULL;
1698 DC_LOG_DC("BIOS object table - %s failed.\n", __func__);
1704 static bool dc_link_construct_dpia(struct dc_link *link,
1705 const struct link_init_data *init_params)
1707 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1708 struct dc_context *dc_ctx = init_params->ctx;
1710 DC_LOGGER_INIT(dc_ctx->logger);
1712 /* Initialized dummy hpd and hpd rx */
1713 link->irq_source_hpd = DC_IRQ_SOURCE_USB4_DMUB_HPD;
1714 link->irq_source_hpd_rx = DC_IRQ_SOURCE_USB4_DMUB_HPDRX;
1715 link->link_status.dpcd_caps = &link->dpcd_caps;
1717 link->dc = init_params->dc;
1719 link->link_index = init_params->link_index;
1721 memset(&link->preferred_training_settings, 0,
1722 sizeof(struct dc_link_training_overrides));
1723 memset(&link->preferred_link_setting, 0,
1724 sizeof(struct dc_link_settings));
1726 /* Dummy Init for linkid */
1727 link->link_id.type = OBJECT_TYPE_CONNECTOR;
1728 link->link_id.id = CONNECTOR_ID_DISPLAY_PORT;
1729 link->is_internal_display = false;
1730 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1731 LINK_INFO("Connector[%d] description:signal %d\n",
1732 init_params->connector_index,
1733 link->connector_signal);
1735 link->ep_type = DISPLAY_ENDPOINT_USB4_DPIA;
1737 /* TODO: Initialize link : funcs->link_init */
1739 ddc_service_init_data.ctx = link->ctx;
1740 ddc_service_init_data.id = link->link_id;
1741 ddc_service_init_data.link = link;
1742 /* Set indicator for dpia link so that ddc won't be created */
1743 ddc_service_init_data.is_dpia_link = true;
1745 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1747 DC_ERROR("Failed to create ddc_service!\n");
1748 goto ddc_create_fail;
1751 /* Set dpia port index : 0 to number of dpia ports */
1752 link->ddc_hw_inst = init_params->connector_index;
1754 /* TODO: Create link encoder */
1756 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
1764 static bool dc_link_construct(struct dc_link *link,
1765 const struct link_init_data *init_params)
1767 /* Handle dpia case */
1768 if (init_params->is_dpia_link)
1769 return dc_link_construct_dpia(link, init_params);
1771 return dc_link_construct_legacy(link, init_params);
1773 /*******************************************************************************
1775 ******************************************************************************/
1776 struct dc_link *link_create(const struct link_init_data *init_params)
1778 struct dc_link *link =
1779 kzalloc(sizeof(*link), GFP_KERNEL);
1784 if (false == dc_link_construct(link, init_params))
1785 goto construct_fail;
1788 * Must use preferred_link_setting, not reported_link_cap or verified_link_cap,
1789 * since struct preferred_link_setting won't be reset after S3.
1791 link->preferred_link_setting.dpcd_source_device_specific_field_support = true;
1802 void link_destroy(struct dc_link **link)
1804 dc_link_destruct(*link);
1809 static void enable_stream_features(struct pipe_ctx *pipe_ctx)
1811 struct dc_stream_state *stream = pipe_ctx->stream;
1813 if (pipe_ctx->stream->signal != SIGNAL_TYPE_DISPLAY_PORT_MST) {
1814 struct dc_link *link = stream->link;
1815 union down_spread_ctrl old_downspread;
1816 union down_spread_ctrl new_downspread;
1818 core_link_read_dpcd(link, DP_DOWNSPREAD_CTRL,
1819 &old_downspread.raw, sizeof(old_downspread));
1821 new_downspread.raw = old_downspread.raw;
1823 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1824 (stream->ignore_msa_timing_param) ? 1 : 0;
1826 if (new_downspread.raw != old_downspread.raw) {
1827 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
1828 &new_downspread.raw, sizeof(new_downspread));
1832 dm_helpers_mst_enable_stream_features(stream);
1836 static enum dc_status enable_link_dp(struct dc_state *state,
1837 struct pipe_ctx *pipe_ctx)
1839 struct dc_stream_state *stream = pipe_ctx->stream;
1840 enum dc_status status;
1841 bool skip_video_pattern;
1842 struct dc_link *link = stream->link;
1843 struct dc_link_settings link_settings = {0};
1846 bool apply_seamless_boot_optimization = false;
1847 uint32_t bl_oled_enable_delay = 50; // in ms
1848 const uint32_t post_oui_delay = 30; // 30ms
1849 /* Reduce link bandwidth between failed link training attempts. */
1850 bool do_fallback = false;
1852 // check for seamless boot
1853 for (i = 0; i < state->stream_count; i++) {
1854 if (state->streams[i]->apply_seamless_boot_optimization) {
1855 apply_seamless_boot_optimization = true;
1860 /* get link settings for video mode timing */
1861 decide_link_settings(stream, &link_settings);
1863 #if defined(CONFIG_DRM_AMD_DC_DCN)
1864 if (dp_get_link_encoding_format(&link_settings) == DP_128b_132b_ENCODING &&
1865 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT) {
1866 dp_enable_mst_on_sink(link, true);
1870 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
1871 /*in case it is not on*/
1872 link->dc->hwss.edp_power_control(link, true);
1873 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
1876 #if defined(CONFIG_DRM_AMD_DC_DCN)
1877 if (dp_get_link_encoding_format(&link_settings) == DP_128b_132b_ENCODING) {
1878 /* TODO - DP2.0 HW: calculate 32 symbol clock for HPO encoder */
1880 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
1881 link_settings.link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
1882 if (state->clk_mgr && !apply_seamless_boot_optimization)
1883 state->clk_mgr->funcs->update_clocks(state->clk_mgr,
1887 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
1888 link_settings.link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
1889 if (state->clk_mgr && !apply_seamless_boot_optimization)
1890 state->clk_mgr->funcs->update_clocks(state->clk_mgr,
1894 // during mode switch we do DP_SET_POWER off then on, and OUI is lost
1895 dpcd_set_source_specific_data(link);
1896 if (link->dpcd_sink_ext_caps.raw != 0)
1897 msleep(post_oui_delay);
1899 skip_video_pattern = true;
1901 if (link_settings.link_rate == LINK_RATE_LOW)
1902 skip_video_pattern = false;
1904 if (perform_link_training_with_retries(&link_settings,
1906 LINK_TRAINING_ATTEMPTS,
1908 pipe_ctx->stream->signal,
1910 link->cur_link_settings = link_settings;
1913 status = DC_FAIL_DP_LINK_TRAINING;
1916 if (link->preferred_training_settings.fec_enable)
1917 fec_enable = *link->preferred_training_settings.fec_enable;
1921 #if defined(CONFIG_DRM_AMD_DC_DCN)
1922 if (dp_get_link_encoding_format(&link_settings) == DP_8b_10b_ENCODING)
1923 dp_set_fec_enable(link, fec_enable);
1925 dp_set_fec_enable(link, fec_enable);
1928 // during mode set we do DP_SET_POWER off then on, aux writes are lost
1929 if (link->dpcd_sink_ext_caps.bits.oled == 1 ||
1930 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1 ||
1931 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1) {
1932 dc_link_set_default_brightness_aux(link); // TODO: use cached if known
1933 if (link->dpcd_sink_ext_caps.bits.oled == 1)
1934 msleep(bl_oled_enable_delay);
1935 dc_link_backlight_enable_aux(link, true);
1941 static enum dc_status enable_link_edp(
1942 struct dc_state *state,
1943 struct pipe_ctx *pipe_ctx)
1945 enum dc_status status;
1947 status = enable_link_dp(state, pipe_ctx);
1952 static enum dc_status enable_link_dp_mst(
1953 struct dc_state *state,
1954 struct pipe_ctx *pipe_ctx)
1956 struct dc_link *link = pipe_ctx->stream->link;
1958 /* sink signal type after MST branch is MST. Multiple MST sinks
1959 * share one link. Link DP PHY is enable or training only once.
1961 if (link->link_status.link_active)
1964 /* clear payload table */
1965 dm_helpers_dp_mst_clear_payload_allocation_table(link->ctx, link);
1967 /* to make sure the pending down rep can be processed
1968 * before enabling the link
1970 dm_helpers_dp_mst_poll_pending_down_reply(link->ctx, link);
1972 /* set the sink to MST mode before enabling the link */
1973 dp_enable_mst_on_sink(link, true);
1975 return enable_link_dp(state, pipe_ctx);
1978 void blank_all_dp_displays(struct dc *dc, bool hw_init)
1980 unsigned int i, j, fe;
1981 uint8_t dpcd_power_state = '\0';
1982 enum dc_status status = DC_ERROR_UNEXPECTED;
1984 for (i = 0; i < dc->link_count; i++) {
1985 enum signal_type signal = dc->links[i]->connector_signal;
1987 if ((signal == SIGNAL_TYPE_EDP) ||
1988 (signal == SIGNAL_TYPE_DISPLAY_PORT)) {
1989 if (hw_init && signal != SIGNAL_TYPE_EDP && dc->links[i]->priv != NULL) {
1990 /* DP 2.0 spec requires that we read LTTPR caps first */
1991 dp_retrieve_lttpr_cap(dc->links[i]);
1992 /* if any of the displays are lit up turn them off */
1993 status = core_link_read_dpcd(dc->links[i], DP_SET_POWER,
1994 &dpcd_power_state, sizeof(dpcd_power_state));
1997 if ((signal != SIGNAL_TYPE_EDP && status == DC_OK && dpcd_power_state == DP_POWER_STATE_D0) ||
1998 (!hw_init && dc->links[i]->link_enc &&
1999 dc->links[i]->link_enc->funcs->is_dig_enabled(dc->links[i]->link_enc))) {
2000 if (dc->links[i]->link_enc->funcs->get_dig_frontend) {
2001 fe = dc->links[i]->link_enc->funcs->get_dig_frontend(dc->links[i]->link_enc);
2002 if (fe == ENGINE_ID_UNKNOWN)
2005 for (j = 0; j < dc->res_pool->stream_enc_count; j++) {
2006 if (fe == dc->res_pool->stream_enc[j]->id) {
2007 dc->res_pool->stream_enc[j]->funcs->dp_blank(dc->links[i],
2008 dc->res_pool->stream_enc[j]);
2014 if (!dc->links[i]->wa_flags.dp_keep_receiver_powered ||
2015 (hw_init && signal != SIGNAL_TYPE_EDP && dc->links[i]->priv != NULL))
2016 dp_receiver_power_ctrl(dc->links[i], false);
2023 static bool get_ext_hdmi_settings(struct pipe_ctx *pipe_ctx,
2024 enum engine_id eng_id,
2025 struct ext_hdmi_settings *settings)
2027 bool result = false;
2029 struct integrated_info *integrated_info =
2030 pipe_ctx->stream->ctx->dc_bios->integrated_info;
2032 if (integrated_info == NULL)
2036 * Get retimer settings from sbios for passing SI eye test for DCE11
2037 * The setting values are varied based on board revision and port id
2038 * Therefore the setting values of each ports is passed by sbios.
2041 // Check if current bios contains ext Hdmi settings
2042 if (integrated_info->gpu_cap_info & 0x20) {
2044 case ENGINE_ID_DIGA:
2045 settings->slv_addr = integrated_info->dp0_ext_hdmi_slv_addr;
2046 settings->reg_num = integrated_info->dp0_ext_hdmi_6g_reg_num;
2047 settings->reg_num_6g = integrated_info->dp0_ext_hdmi_6g_reg_num;
2048 memmove(settings->reg_settings,
2049 integrated_info->dp0_ext_hdmi_reg_settings,
2050 sizeof(integrated_info->dp0_ext_hdmi_reg_settings));
2051 memmove(settings->reg_settings_6g,
2052 integrated_info->dp0_ext_hdmi_6g_reg_settings,
2053 sizeof(integrated_info->dp0_ext_hdmi_6g_reg_settings));
2056 case ENGINE_ID_DIGB:
2057 settings->slv_addr = integrated_info->dp1_ext_hdmi_slv_addr;
2058 settings->reg_num = integrated_info->dp1_ext_hdmi_6g_reg_num;
2059 settings->reg_num_6g = integrated_info->dp1_ext_hdmi_6g_reg_num;
2060 memmove(settings->reg_settings,
2061 integrated_info->dp1_ext_hdmi_reg_settings,
2062 sizeof(integrated_info->dp1_ext_hdmi_reg_settings));
2063 memmove(settings->reg_settings_6g,
2064 integrated_info->dp1_ext_hdmi_6g_reg_settings,
2065 sizeof(integrated_info->dp1_ext_hdmi_6g_reg_settings));
2068 case ENGINE_ID_DIGC:
2069 settings->slv_addr = integrated_info->dp2_ext_hdmi_slv_addr;
2070 settings->reg_num = integrated_info->dp2_ext_hdmi_6g_reg_num;
2071 settings->reg_num_6g = integrated_info->dp2_ext_hdmi_6g_reg_num;
2072 memmove(settings->reg_settings,
2073 integrated_info->dp2_ext_hdmi_reg_settings,
2074 sizeof(integrated_info->dp2_ext_hdmi_reg_settings));
2075 memmove(settings->reg_settings_6g,
2076 integrated_info->dp2_ext_hdmi_6g_reg_settings,
2077 sizeof(integrated_info->dp2_ext_hdmi_6g_reg_settings));
2080 case ENGINE_ID_DIGD:
2081 settings->slv_addr = integrated_info->dp3_ext_hdmi_slv_addr;
2082 settings->reg_num = integrated_info->dp3_ext_hdmi_6g_reg_num;
2083 settings->reg_num_6g = integrated_info->dp3_ext_hdmi_6g_reg_num;
2084 memmove(settings->reg_settings,
2085 integrated_info->dp3_ext_hdmi_reg_settings,
2086 sizeof(integrated_info->dp3_ext_hdmi_reg_settings));
2087 memmove(settings->reg_settings_6g,
2088 integrated_info->dp3_ext_hdmi_6g_reg_settings,
2089 sizeof(integrated_info->dp3_ext_hdmi_6g_reg_settings));
2096 if (result == true) {
2097 // Validate settings from bios integrated info table
2098 if (settings->slv_addr == 0)
2100 if (settings->reg_num > 9)
2102 if (settings->reg_num_6g > 3)
2105 for (i = 0; i < settings->reg_num; i++) {
2106 if (settings->reg_settings[i].i2c_reg_index > 0x20)
2110 for (i = 0; i < settings->reg_num_6g; i++) {
2111 if (settings->reg_settings_6g[i].i2c_reg_index > 0x20)
2120 static bool i2c_write(struct pipe_ctx *pipe_ctx,
2121 uint8_t address, uint8_t *buffer, uint32_t length)
2123 struct i2c_command cmd = {0};
2124 struct i2c_payload payload = {0};
2126 memset(&payload, 0, sizeof(payload));
2127 memset(&cmd, 0, sizeof(cmd));
2129 cmd.number_of_payloads = 1;
2130 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
2131 cmd.speed = pipe_ctx->stream->ctx->dc->caps.i2c_speed_in_khz;
2133 payload.address = address;
2134 payload.data = buffer;
2135 payload.length = length;
2136 payload.write = true;
2137 cmd.payloads = &payload;
2139 if (dm_helpers_submit_i2c(pipe_ctx->stream->ctx,
2140 pipe_ctx->stream->link, &cmd))
2146 static void write_i2c_retimer_setting(
2147 struct pipe_ctx *pipe_ctx,
2149 bool is_over_340mhz,
2150 struct ext_hdmi_settings *settings)
2152 uint8_t slave_address = (settings->slv_addr >> 1);
2154 const uint8_t apply_rx_tx_change = 0x4;
2155 uint8_t offset = 0xA;
2158 bool i2c_success = false;
2159 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2161 memset(&buffer, 0, sizeof(buffer));
2163 /* Start Ext-Hdmi programming*/
2165 for (i = 0; i < settings->reg_num; i++) {
2166 /* Apply 3G settings */
2167 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
2169 buffer[0] = settings->reg_settings[i].i2c_reg_index;
2170 buffer[1] = settings->reg_settings[i].i2c_reg_val;
2171 i2c_success = i2c_write(pipe_ctx, slave_address,
2172 buffer, sizeof(buffer));
2173 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2174 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2175 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2178 goto i2c_write_fail;
2180 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
2181 * needs to be set to 1 on every 0xA-0xC write.
2183 if (settings->reg_settings[i].i2c_reg_index == 0xA ||
2184 settings->reg_settings[i].i2c_reg_index == 0xB ||
2185 settings->reg_settings[i].i2c_reg_index == 0xC) {
2187 /* Query current value from offset 0xA */
2188 if (settings->reg_settings[i].i2c_reg_index == 0xA)
2189 value = settings->reg_settings[i].i2c_reg_val;
2192 dal_ddc_service_query_ddc_data(
2193 pipe_ctx->stream->link->ddc,
2194 slave_address, &offset, 1, &value, 1);
2196 goto i2c_write_fail;
2200 /* Set APPLY_RX_TX_CHANGE bit to 1 */
2201 buffer[1] = value | apply_rx_tx_change;
2202 i2c_success = i2c_write(pipe_ctx, slave_address,
2203 buffer, sizeof(buffer));
2204 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2205 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2206 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2208 goto i2c_write_fail;
2213 /* Apply 3G settings */
2214 if (is_over_340mhz) {
2215 for (i = 0; i < settings->reg_num_6g; i++) {
2216 /* Apply 3G settings */
2217 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
2219 buffer[0] = settings->reg_settings_6g[i].i2c_reg_index;
2220 buffer[1] = settings->reg_settings_6g[i].i2c_reg_val;
2221 i2c_success = i2c_write(pipe_ctx, slave_address,
2222 buffer, sizeof(buffer));
2223 RETIMER_REDRIVER_INFO("above 340Mhz: retimer write to slave_address = 0x%x,\
2224 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2225 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2228 goto i2c_write_fail;
2230 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
2231 * needs to be set to 1 on every 0xA-0xC write.
2233 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA ||
2234 settings->reg_settings_6g[i].i2c_reg_index == 0xB ||
2235 settings->reg_settings_6g[i].i2c_reg_index == 0xC) {
2237 /* Query current value from offset 0xA */
2238 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA)
2239 value = settings->reg_settings_6g[i].i2c_reg_val;
2242 dal_ddc_service_query_ddc_data(
2243 pipe_ctx->stream->link->ddc,
2244 slave_address, &offset, 1, &value, 1);
2246 goto i2c_write_fail;
2250 /* Set APPLY_RX_TX_CHANGE bit to 1 */
2251 buffer[1] = value | apply_rx_tx_change;
2252 i2c_success = i2c_write(pipe_ctx, slave_address,
2253 buffer, sizeof(buffer));
2254 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2255 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2256 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2258 goto i2c_write_fail;
2265 /* Program additional settings if using 640x480 resolution */
2267 /* Write offset 0xFF to 0x01 */
2270 i2c_success = i2c_write(pipe_ctx, slave_address,
2271 buffer, sizeof(buffer));
2272 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2273 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2274 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2276 goto i2c_write_fail;
2278 /* Write offset 0x00 to 0x23 */
2281 i2c_success = i2c_write(pipe_ctx, slave_address,
2282 buffer, sizeof(buffer));
2283 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2284 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2285 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2287 goto i2c_write_fail;
2289 /* Write offset 0xff to 0x00 */
2292 i2c_success = i2c_write(pipe_ctx, slave_address,
2293 buffer, sizeof(buffer));
2294 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2295 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2296 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2298 goto i2c_write_fail;
2305 DC_LOG_DEBUG("Set retimer failed");
2308 static void write_i2c_default_retimer_setting(
2309 struct pipe_ctx *pipe_ctx,
2311 bool is_over_340mhz)
2313 uint8_t slave_address = (0xBA >> 1);
2315 bool i2c_success = false;
2316 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2318 memset(&buffer, 0, sizeof(buffer));
2320 /* Program Slave Address for tuning single integrity */
2321 /* Write offset 0x0A to 0x13 */
2324 i2c_success = i2c_write(pipe_ctx, slave_address,
2325 buffer, sizeof(buffer));
2326 RETIMER_REDRIVER_INFO("retimer writes default setting to slave_address = 0x%x,\
2327 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2328 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2330 goto i2c_write_fail;
2332 /* Write offset 0x0A to 0x17 */
2335 i2c_success = i2c_write(pipe_ctx, slave_address,
2336 buffer, sizeof(buffer));
2337 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2338 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2339 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2341 goto i2c_write_fail;
2343 /* Write offset 0x0B to 0xDA or 0xD8 */
2345 buffer[1] = is_over_340mhz ? 0xDA : 0xD8;
2346 i2c_success = i2c_write(pipe_ctx, slave_address,
2347 buffer, sizeof(buffer));
2348 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2349 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2350 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2352 goto i2c_write_fail;
2354 /* Write offset 0x0A to 0x17 */
2357 i2c_success = i2c_write(pipe_ctx, slave_address,
2358 buffer, sizeof(buffer));
2359 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2360 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2361 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2363 goto i2c_write_fail;
2365 /* Write offset 0x0C to 0x1D or 0x91 */
2367 buffer[1] = is_over_340mhz ? 0x1D : 0x91;
2368 i2c_success = i2c_write(pipe_ctx, slave_address,
2369 buffer, sizeof(buffer));
2370 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2371 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2372 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2374 goto i2c_write_fail;
2376 /* Write offset 0x0A to 0x17 */
2379 i2c_success = i2c_write(pipe_ctx, slave_address,
2380 buffer, sizeof(buffer));
2381 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2382 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2383 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2385 goto i2c_write_fail;
2389 /* Program additional settings if using 640x480 resolution */
2391 /* Write offset 0xFF to 0x01 */
2394 i2c_success = i2c_write(pipe_ctx, slave_address,
2395 buffer, sizeof(buffer));
2396 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2397 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2398 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2400 goto i2c_write_fail;
2402 /* Write offset 0x00 to 0x23 */
2405 i2c_success = i2c_write(pipe_ctx, slave_address,
2406 buffer, sizeof(buffer));
2407 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2408 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2409 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2411 goto i2c_write_fail;
2413 /* Write offset 0xff to 0x00 */
2416 i2c_success = i2c_write(pipe_ctx, slave_address,
2417 buffer, sizeof(buffer));
2418 RETIMER_REDRIVER_INFO("retimer write default setting to slave_addr = 0x%x,\
2419 offset = 0x%x, reg_val= 0x%x, i2c_success = %d end here\n",
2420 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2422 goto i2c_write_fail;
2428 DC_LOG_DEBUG("Set default retimer failed");
2431 static void write_i2c_redriver_setting(
2432 struct pipe_ctx *pipe_ctx,
2433 bool is_over_340mhz)
2435 uint8_t slave_address = (0xF0 >> 1);
2437 bool i2c_success = false;
2438 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2440 memset(&buffer, 0, sizeof(buffer));
2442 // Program Slave Address for tuning single integrity
2446 buffer[6] = is_over_340mhz ? 0x4E : 0x4A;
2448 i2c_success = i2c_write(pipe_ctx, slave_address,
2449 buffer, sizeof(buffer));
2450 RETIMER_REDRIVER_INFO("redriver write 0 to all 16 reg offset expect following:\n\
2451 \t slave_addr = 0x%x, offset[3] = 0x%x, offset[4] = 0x%x,\
2452 offset[5] = 0x%x,offset[6] is_over_340mhz = 0x%x,\
2453 i2c_success = %d\n",
2454 slave_address, buffer[3], buffer[4], buffer[5], buffer[6], i2c_success?1:0);
2457 DC_LOG_DEBUG("Set redriver failed");
2460 static void disable_link(struct dc_link *link, enum signal_type signal)
2463 * TODO: implement call for dp_set_hw_test_pattern
2464 * it is needed for compliance testing
2467 /* Here we need to specify that encoder output settings
2468 * need to be calculated as for the set mode,
2469 * it will lead to querying dynamic link capabilities
2470 * which should be done before enable output
2473 if (dc_is_dp_signal(signal)) {
2475 #if defined(CONFIG_DRM_AMD_DC_DCN)
2476 struct dc_link_settings link_settings = link->cur_link_settings;
2478 if (dc_is_dp_sst_signal(signal))
2479 dp_disable_link_phy(link, signal);
2481 dp_disable_link_phy_mst(link, signal);
2483 if (dc_is_dp_sst_signal(signal) ||
2484 link->mst_stream_alloc_table.stream_count == 0) {
2485 #if defined(CONFIG_DRM_AMD_DC_DCN)
2486 if (dp_get_link_encoding_format(&link_settings) == DP_8b_10b_ENCODING) {
2487 dp_set_fec_enable(link, false);
2488 dp_set_fec_ready(link, false);
2491 dp_set_fec_enable(link, false);
2492 dp_set_fec_ready(link, false);
2496 if (signal != SIGNAL_TYPE_VIRTUAL)
2497 link->link_enc->funcs->disable_output(link->link_enc, signal);
2500 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2501 /* MST disable link only when no stream use the link */
2502 if (link->mst_stream_alloc_table.stream_count <= 0)
2503 link->link_status.link_active = false;
2505 link->link_status.link_active = false;
2509 static void enable_link_hdmi(struct pipe_ctx *pipe_ctx)
2511 struct dc_stream_state *stream = pipe_ctx->stream;
2512 struct dc_link *link = stream->link;
2513 enum dc_color_depth display_color_depth;
2514 enum engine_id eng_id;
2515 struct ext_hdmi_settings settings = {0};
2516 bool is_over_340mhz = false;
2517 bool is_vga_mode = (stream->timing.h_addressable == 640)
2518 && (stream->timing.v_addressable == 480);
2520 if (stream->phy_pix_clk == 0)
2521 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2522 if (stream->phy_pix_clk > 340000)
2523 is_over_340mhz = true;
2525 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2526 unsigned short masked_chip_caps = pipe_ctx->stream->link->chip_caps &
2527 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
2528 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
2529 /* DP159, Retimer settings */
2530 eng_id = pipe_ctx->stream_res.stream_enc->id;
2532 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings)) {
2533 write_i2c_retimer_setting(pipe_ctx,
2534 is_vga_mode, is_over_340mhz, &settings);
2536 write_i2c_default_retimer_setting(pipe_ctx,
2537 is_vga_mode, is_over_340mhz);
2539 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
2540 /* PI3EQX1204, Redriver settings */
2541 write_i2c_redriver_setting(pipe_ctx, is_over_340mhz);
2545 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2546 dal_ddc_service_write_scdc_data(
2548 stream->phy_pix_clk,
2549 stream->timing.flags.LTE_340MCSC_SCRAMBLE);
2551 memset(&stream->link->cur_link_settings, 0,
2552 sizeof(struct dc_link_settings));
2554 display_color_depth = stream->timing.display_color_depth;
2555 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
2556 display_color_depth = COLOR_DEPTH_888;
2558 link->link_enc->funcs->enable_tmds_output(
2560 pipe_ctx->clock_source->id,
2561 display_color_depth,
2562 pipe_ctx->stream->signal,
2563 stream->phy_pix_clk);
2565 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2566 dal_ddc_service_read_scdc_data(link->ddc);
2569 static void enable_link_lvds(struct pipe_ctx *pipe_ctx)
2571 struct dc_stream_state *stream = pipe_ctx->stream;
2572 struct dc_link *link = stream->link;
2574 if (stream->phy_pix_clk == 0)
2575 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2577 memset(&stream->link->cur_link_settings, 0,
2578 sizeof(struct dc_link_settings));
2580 link->link_enc->funcs->enable_lvds_output(
2582 pipe_ctx->clock_source->id,
2583 stream->phy_pix_clk);
2587 /****************************enable_link***********************************/
2588 static enum dc_status enable_link(
2589 struct dc_state *state,
2590 struct pipe_ctx *pipe_ctx)
2592 enum dc_status status = DC_ERROR_UNEXPECTED;
2593 struct dc_stream_state *stream = pipe_ctx->stream;
2594 struct dc_link *link = stream->link;
2596 /* There's some scenarios where driver is unloaded with display
2597 * still enabled. When driver is reloaded, it may cause a display
2598 * to not light up if there is a mismatch between old and new
2599 * link settings. Need to call disable first before enabling at
2600 * new link settings.
2602 if (link->link_status.link_active) {
2603 disable_link(link, pipe_ctx->stream->signal);
2606 switch (pipe_ctx->stream->signal) {
2607 case SIGNAL_TYPE_DISPLAY_PORT:
2608 status = enable_link_dp(state, pipe_ctx);
2610 case SIGNAL_TYPE_EDP:
2611 status = enable_link_edp(state, pipe_ctx);
2613 case SIGNAL_TYPE_DISPLAY_PORT_MST:
2614 status = enable_link_dp_mst(state, pipe_ctx);
2617 case SIGNAL_TYPE_DVI_SINGLE_LINK:
2618 case SIGNAL_TYPE_DVI_DUAL_LINK:
2619 case SIGNAL_TYPE_HDMI_TYPE_A:
2620 enable_link_hdmi(pipe_ctx);
2623 case SIGNAL_TYPE_LVDS:
2624 enable_link_lvds(pipe_ctx);
2627 case SIGNAL_TYPE_VIRTUAL:
2634 if (status == DC_OK)
2635 pipe_ctx->stream->link->link_status.link_active = true;
2640 static uint32_t get_timing_pixel_clock_100hz(const struct dc_crtc_timing *timing)
2643 uint32_t pxl_clk = timing->pix_clk_100hz;
2645 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
2647 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
2648 pxl_clk = pxl_clk * 2 / 3;
2650 if (timing->display_color_depth == COLOR_DEPTH_101010)
2651 pxl_clk = pxl_clk * 10 / 8;
2652 else if (timing->display_color_depth == COLOR_DEPTH_121212)
2653 pxl_clk = pxl_clk * 12 / 8;
2658 static bool dp_active_dongle_validate_timing(
2659 const struct dc_crtc_timing *timing,
2660 const struct dpcd_caps *dpcd_caps)
2662 const struct dc_dongle_caps *dongle_caps = &dpcd_caps->dongle_caps;
2664 switch (dpcd_caps->dongle_type) {
2665 case DISPLAY_DONGLE_DP_VGA_CONVERTER:
2666 case DISPLAY_DONGLE_DP_DVI_CONVERTER:
2667 case DISPLAY_DONGLE_DP_DVI_DONGLE:
2668 if (timing->pixel_encoding == PIXEL_ENCODING_RGB)
2676 #if defined(CONFIG_DRM_AMD_DC_DCN)
2677 if (dpcd_caps->dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER &&
2678 dongle_caps->extendedCapValid == true) {
2680 if (dpcd_caps->dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER ||
2681 dongle_caps->extendedCapValid == false)
2685 /* Check Pixel Encoding */
2686 switch (timing->pixel_encoding) {
2687 case PIXEL_ENCODING_RGB:
2688 case PIXEL_ENCODING_YCBCR444:
2690 case PIXEL_ENCODING_YCBCR422:
2691 if (!dongle_caps->is_dp_hdmi_ycbcr422_pass_through)
2694 case PIXEL_ENCODING_YCBCR420:
2695 if (!dongle_caps->is_dp_hdmi_ycbcr420_pass_through)
2699 /* Invalid Pixel Encoding*/
2703 switch (timing->display_color_depth) {
2704 case COLOR_DEPTH_666:
2705 case COLOR_DEPTH_888:
2706 /*888 and 666 should always be supported*/
2708 case COLOR_DEPTH_101010:
2709 if (dongle_caps->dp_hdmi_max_bpc < 10)
2712 case COLOR_DEPTH_121212:
2713 if (dongle_caps->dp_hdmi_max_bpc < 12)
2716 case COLOR_DEPTH_141414:
2717 case COLOR_DEPTH_161616:
2719 /* These color depths are currently not supported */
2723 if (get_timing_pixel_clock_100hz(timing) > (dongle_caps->dp_hdmi_max_pixel_clk_in_khz * 10))
2726 #if defined(CONFIG_DRM_AMD_DC_DCN)
2729 if (dpcd_caps->channel_coding_cap.bits.DP_128b_132b_SUPPORTED == 0 &&
2730 dpcd_caps->dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_PASSTHROUGH_SUPPORT == 0 &&
2731 dongle_caps->dfp_cap_ext.supported) {
2733 if (dongle_caps->dfp_cap_ext.max_pixel_rate_in_mps < (timing->pix_clk_100hz / 10000))
2736 if (dongle_caps->dfp_cap_ext.max_video_h_active_width < timing->h_addressable)
2739 if (dongle_caps->dfp_cap_ext.max_video_v_active_height < timing->v_addressable)
2742 if (timing->pixel_encoding == PIXEL_ENCODING_RGB) {
2743 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2745 if (timing->display_color_depth == COLOR_DEPTH_666 &&
2746 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_6bpc)
2748 else if (timing->display_color_depth == COLOR_DEPTH_888 &&
2749 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_8bpc)
2751 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2752 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_10bpc)
2754 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2755 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_12bpc)
2757 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2758 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_16bpc)
2760 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR444) {
2761 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2763 if (timing->display_color_depth == COLOR_DEPTH_888 &&
2764 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_8bpc)
2766 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2767 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_10bpc)
2769 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2770 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_12bpc)
2772 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2773 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_16bpc)
2775 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422) {
2776 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2778 if (timing->display_color_depth == COLOR_DEPTH_888 &&
2779 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_8bpc)
2781 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2782 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_10bpc)
2784 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2785 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_12bpc)
2787 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2788 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_16bpc)
2790 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) {
2791 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb)
2793 if (timing->display_color_depth == COLOR_DEPTH_888 &&
2794 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_8bpc)
2796 else if (timing->display_color_depth == COLOR_DEPTH_101010 &&
2797 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_10bpc)
2799 else if (timing->display_color_depth == COLOR_DEPTH_121212 &&
2800 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_12bpc)
2802 else if (timing->display_color_depth == COLOR_DEPTH_161616 &&
2803 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_16bpc)
2812 enum dc_status dc_link_validate_mode_timing(
2813 const struct dc_stream_state *stream,
2814 struct dc_link *link,
2815 const struct dc_crtc_timing *timing)
2817 uint32_t max_pix_clk = stream->link->dongle_max_pix_clk * 10;
2818 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
2820 /* A hack to avoid failing any modes for EDID override feature on
2821 * topology change such as lower quality cable for DP or different dongle
2823 if (link->remote_sinks[0] && link->remote_sinks[0]->sink_signal == SIGNAL_TYPE_VIRTUAL)
2826 /* Passive Dongle */
2827 if (max_pix_clk != 0 && get_timing_pixel_clock_100hz(timing) > max_pix_clk)
2828 return DC_EXCEED_DONGLE_CAP;
2831 if (!dp_active_dongle_validate_timing(timing, dpcd_caps))
2832 return DC_EXCEED_DONGLE_CAP;
2834 switch (stream->signal) {
2835 case SIGNAL_TYPE_EDP:
2836 case SIGNAL_TYPE_DISPLAY_PORT:
2837 if (!dp_validate_mode_timing(
2840 return DC_NO_DP_LINK_BANDWIDTH;
2850 static struct abm *get_abm_from_stream_res(const struct dc_link *link)
2853 struct dc *dc = NULL;
2854 struct abm *abm = NULL;
2856 if (!link || !link->ctx)
2861 for (i = 0; i < MAX_PIPES; i++) {
2862 struct pipe_ctx pipe_ctx = dc->current_state->res_ctx.pipe_ctx[i];
2863 struct dc_stream_state *stream = pipe_ctx.stream;
2865 if (stream && stream->link == link) {
2866 abm = pipe_ctx.stream_res.abm;
2873 int dc_link_get_backlight_level(const struct dc_link *link)
2875 struct abm *abm = get_abm_from_stream_res(link);
2876 struct panel_cntl *panel_cntl = link->panel_cntl;
2877 struct dc *dc = link->ctx->dc;
2878 struct dmcu *dmcu = dc->res_pool->dmcu;
2879 bool fw_set_brightness = true;
2882 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
2884 if (!fw_set_brightness && panel_cntl->funcs->get_current_backlight)
2885 return panel_cntl->funcs->get_current_backlight(panel_cntl);
2886 else if (abm != NULL && abm->funcs->get_current_backlight != NULL)
2887 return (int) abm->funcs->get_current_backlight(abm);
2889 return DC_ERROR_UNEXPECTED;
2892 int dc_link_get_target_backlight_pwm(const struct dc_link *link)
2894 struct abm *abm = get_abm_from_stream_res(link);
2896 if (abm == NULL || abm->funcs->get_target_backlight == NULL)
2897 return DC_ERROR_UNEXPECTED;
2899 return (int) abm->funcs->get_target_backlight(abm);
2902 static struct pipe_ctx *get_pipe_from_link(const struct dc_link *link)
2905 struct dc *dc = link->ctx->dc;
2906 struct pipe_ctx *pipe_ctx = NULL;
2908 for (i = 0; i < MAX_PIPES; i++) {
2909 if (dc->current_state->res_ctx.pipe_ctx[i].stream) {
2910 if (dc->current_state->res_ctx.pipe_ctx[i].stream->link == link) {
2911 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2920 bool dc_link_set_backlight_level(const struct dc_link *link,
2921 uint32_t backlight_pwm_u16_16,
2922 uint32_t frame_ramp)
2924 struct dc *dc = link->ctx->dc;
2926 DC_LOGGER_INIT(link->ctx->logger);
2927 DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n",
2928 backlight_pwm_u16_16, backlight_pwm_u16_16);
2930 if (dc_is_embedded_signal(link->connector_signal)) {
2931 struct pipe_ctx *pipe_ctx = get_pipe_from_link(link);
2934 /* Disable brightness ramping when the display is blanked
2935 * as it can hang the DMCU
2937 if (pipe_ctx->plane_state == NULL)
2943 dc->hwss.set_backlight_level(
2945 backlight_pwm_u16_16,
2951 bool dc_link_set_psr_allow_active(struct dc_link *link, bool allow_active,
2952 bool wait, bool force_static)
2954 struct dc *dc = link->ctx->dc;
2955 struct dmcu *dmcu = dc->res_pool->dmcu;
2956 struct dmub_psr *psr = dc->res_pool->psr;
2957 unsigned int panel_inst;
2959 if (psr == NULL && force_static)
2962 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
2965 link->psr_settings.psr_allow_active = allow_active;
2966 #if defined(CONFIG_DRM_AMD_DC_DCN)
2971 if (psr != NULL && link->psr_settings.psr_feature_enabled) {
2972 if (force_static && psr->funcs->psr_force_static)
2973 psr->funcs->psr_force_static(psr, panel_inst);
2974 psr->funcs->psr_enable(psr, allow_active, wait, panel_inst);
2975 } else if ((dmcu != NULL && dmcu->funcs->is_dmcu_initialized(dmcu)) && link->psr_settings.psr_feature_enabled)
2976 dmcu->funcs->set_psr_enable(dmcu, allow_active, wait);
2983 bool dc_link_get_psr_state(const struct dc_link *link, enum dc_psr_state *state)
2985 struct dc *dc = link->ctx->dc;
2986 struct dmcu *dmcu = dc->res_pool->dmcu;
2987 struct dmub_psr *psr = dc->res_pool->psr;
2988 unsigned int panel_inst;
2990 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
2993 if (psr != NULL && link->psr_settings.psr_feature_enabled)
2994 psr->funcs->psr_get_state(psr, state, panel_inst);
2995 else if (dmcu != NULL && link->psr_settings.psr_feature_enabled)
2996 dmcu->funcs->get_psr_state(dmcu, state);
3001 static inline enum physical_phy_id
3002 transmitter_to_phy_id(enum transmitter transmitter_value)
3004 switch (transmitter_value) {
3005 case TRANSMITTER_UNIPHY_A:
3007 case TRANSMITTER_UNIPHY_B:
3009 case TRANSMITTER_UNIPHY_C:
3011 case TRANSMITTER_UNIPHY_D:
3013 case TRANSMITTER_UNIPHY_E:
3015 case TRANSMITTER_UNIPHY_F:
3017 case TRANSMITTER_NUTMEG_CRT:
3019 case TRANSMITTER_TRAVIS_CRT:
3021 case TRANSMITTER_TRAVIS_LCD:
3023 case TRANSMITTER_UNIPHY_G:
3025 case TRANSMITTER_COUNT:
3027 case TRANSMITTER_UNKNOWN:
3028 return PHYLD_UNKNOWN;
3030 WARN_ONCE(1, "Unknown transmitter value %d\n",
3032 return PHYLD_UNKNOWN;
3036 bool dc_link_setup_psr(struct dc_link *link,
3037 const struct dc_stream_state *stream, struct psr_config *psr_config,
3038 struct psr_context *psr_context)
3042 struct dmub_psr *psr;
3044 unsigned int panel_inst;
3045 /* updateSinkPsrDpcdConfig*/
3046 union dpcd_psr_configuration psr_configuration;
3048 psr_context->controllerId = CONTROLLER_ID_UNDEFINED;
3054 dmcu = dc->res_pool->dmcu;
3055 psr = dc->res_pool->psr;
3060 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
3064 memset(&psr_configuration, 0, sizeof(psr_configuration));
3066 psr_configuration.bits.ENABLE = 1;
3067 psr_configuration.bits.CRC_VERIFICATION = 1;
3068 psr_configuration.bits.FRAME_CAPTURE_INDICATION =
3069 psr_config->psr_frame_capture_indication_req;
3071 /* Check for PSR v2*/
3072 if (psr_config->psr_version == 0x2) {
3073 /* For PSR v2 selective update.
3074 * Indicates whether sink should start capturing
3075 * immediately following active scan line,
3076 * or starting with the 2nd active scan line.
3078 psr_configuration.bits.LINE_CAPTURE_INDICATION = 0;
3079 /*For PSR v2, determines whether Sink should generate
3080 * IRQ_HPD when CRC mismatch is detected.
3082 psr_configuration.bits.IRQ_HPD_WITH_CRC_ERROR = 1;
3085 dm_helpers_dp_write_dpcd(
3089 &psr_configuration.raw,
3090 sizeof(psr_configuration.raw));
3092 psr_context->channel = link->ddc->ddc_pin->hw_info.ddc_channel;
3093 psr_context->transmitterId = link->link_enc->transmitter;
3094 psr_context->engineId = link->link_enc->preferred_engine;
3096 for (i = 0; i < MAX_PIPES; i++) {
3097 if (dc->current_state->res_ctx.pipe_ctx[i].stream
3099 /* dmcu -1 for all controller id values,
3102 psr_context->controllerId =
3103 dc->current_state->res_ctx.
3104 pipe_ctx[i].stream_res.tg->inst + 1;
3109 /* Hardcoded for now. Can be Pcie or Uniphy (or Unknown)*/
3110 psr_context->phyType = PHY_TYPE_UNIPHY;
3111 /*PhyId is associated with the transmitter id*/
3112 psr_context->smuPhyId =
3113 transmitter_to_phy_id(link->link_enc->transmitter);
3115 psr_context->crtcTimingVerticalTotal = stream->timing.v_total;
3116 psr_context->vsync_rate_hz = div64_u64(div64_u64((stream->
3117 timing.pix_clk_100hz * 100),
3118 stream->timing.v_total),
3119 stream->timing.h_total);
3121 psr_context->psrSupportedDisplayConfig = true;
3122 psr_context->psrExitLinkTrainingRequired =
3123 psr_config->psr_exit_link_training_required;
3124 psr_context->sdpTransmitLineNumDeadline =
3125 psr_config->psr_sdp_transmit_line_num_deadline;
3126 psr_context->psrFrameCaptureIndicationReq =
3127 psr_config->psr_frame_capture_indication_req;
3129 psr_context->skipPsrWaitForPllLock = 0; /* only = 1 in KV */
3131 psr_context->numberOfControllers =
3132 link->dc->res_pool->timing_generator_count;
3134 psr_context->rfb_update_auto_en = true;
3136 /* 2 frames before enter PSR. */
3137 psr_context->timehyst_frames = 2;
3139 * (units in 100 lines, i.e. a value of 1 represents 100 lines)
3141 psr_context->hyst_lines = stream->timing.v_total / 2 / 100;
3142 psr_context->aux_repeats = 10;
3144 psr_context->psr_level.u32all = 0;
3146 /*skip power down the single pipe since it blocks the cstate*/
3147 #if defined(CONFIG_DRM_AMD_DC_DCN)
3148 if (link->ctx->asic_id.chip_family >= FAMILY_RV) {
3149 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
3150 if (link->ctx->asic_id.chip_family == FAMILY_YELLOW_CARP && !dc->debug.disable_z10)
3151 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = false;
3154 if (link->ctx->asic_id.chip_family >= FAMILY_RV)
3155 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
3158 /* SMU will perform additional powerdown sequence.
3159 * For unsupported ASICs, set psr_level flag to skip PSR
3160 * static screen notification to SMU.
3161 * (Always set for DAL2, did not check ASIC)
3163 psr_context->allow_smu_optimizations = psr_config->allow_smu_optimizations;
3164 psr_context->allow_multi_disp_optimizations = psr_config->allow_multi_disp_optimizations;
3166 /* Complete PSR entry before aborting to prevent intermittent
3167 * freezes on certain eDPs
3169 psr_context->psr_level.bits.DISABLE_PSR_ENTRY_ABORT = 1;
3171 /* Controls additional delay after remote frame capture before
3172 * continuing power down, default = 0
3174 psr_context->frame_delay = 0;
3177 link->psr_settings.psr_feature_enabled = psr->funcs->psr_copy_settings(psr,
3178 link, psr_context, panel_inst);
3180 link->psr_settings.psr_feature_enabled = dmcu->funcs->setup_psr(dmcu, link, psr_context);
3182 /* psr_enabled == 0 indicates setup_psr did not succeed, but this
3183 * should not happen since firmware should be running at this point
3185 if (link->psr_settings.psr_feature_enabled == 0)
3192 void dc_link_get_psr_residency(const struct dc_link *link, uint32_t *residency)
3194 struct dc *dc = link->ctx->dc;
3195 struct dmub_psr *psr = dc->res_pool->psr;
3196 unsigned int panel_inst;
3198 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
3201 /* PSR residency measurements only supported on DMCUB */
3202 if (psr != NULL && link->psr_settings.psr_feature_enabled)
3203 psr->funcs->psr_get_residency(psr, residency, panel_inst);
3208 const struct dc_link_status *dc_link_get_status(const struct dc_link *link)
3210 return &link->link_status;
3213 void core_link_resume(struct dc_link *link)
3215 if (link->connector_signal != SIGNAL_TYPE_VIRTUAL)
3216 program_hpd_filter(link);
3219 static struct fixed31_32 get_pbn_per_slot(struct dc_stream_state *stream)
3221 struct fixed31_32 mbytes_per_sec;
3222 uint32_t link_rate_in_mbytes_per_sec = dc_link_bandwidth_kbps(stream->link,
3223 &stream->link->cur_link_settings);
3224 link_rate_in_mbytes_per_sec /= 8000; /* Kbits to MBytes */
3226 mbytes_per_sec = dc_fixpt_from_int(link_rate_in_mbytes_per_sec);
3228 return dc_fixpt_div_int(mbytes_per_sec, 54);
3231 static struct fixed31_32 get_pbn_from_bw_in_kbps(uint64_t kbps)
3233 struct fixed31_32 peak_kbps;
3234 uint32_t numerator = 0;
3235 uint32_t denominator = 1;
3238 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
3239 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
3240 * common multiplier to render an integer PBN for all link rate/lane
3241 * counts combinations
3243 * peak_kbps *= (1006/1000)
3244 * peak_kbps *= (64/54)
3245 * peak_kbps *= 8 convert to bytes
3248 numerator = 64 * PEAK_FACTOR_X1000;
3249 denominator = 54 * 8 * 1000 * 1000;
3251 peak_kbps = dc_fixpt_from_fraction(kbps, denominator);
3256 static struct fixed31_32 get_pbn_from_timing(struct pipe_ctx *pipe_ctx)
3260 kbps = dc_bandwidth_in_kbps_from_timing(&pipe_ctx->stream->timing);
3261 return get_pbn_from_bw_in_kbps(kbps);
3264 static void update_mst_stream_alloc_table(
3265 struct dc_link *link,
3266 struct stream_encoder *stream_enc,
3267 const struct dp_mst_stream_allocation_table *proposed_table)
3269 struct link_mst_stream_allocation work_table[MAX_CONTROLLER_NUM] = {
3271 struct link_mst_stream_allocation *dc_alloc;
3276 /* if DRM proposed_table has more than one new payload */
3277 ASSERT(proposed_table->stream_count -
3278 link->mst_stream_alloc_table.stream_count < 2);
3280 /* copy proposed_table to link, add stream encoder */
3281 for (i = 0; i < proposed_table->stream_count; i++) {
3283 for (j = 0; j < link->mst_stream_alloc_table.stream_count; j++) {
3285 &link->mst_stream_alloc_table.stream_allocations[j];
3287 if (dc_alloc->vcp_id ==
3288 proposed_table->stream_allocations[i].vcp_id) {
3290 work_table[i] = *dc_alloc;
3291 work_table[i].slot_count = proposed_table->stream_allocations[i].slot_count;
3292 break; /* exit j loop */
3297 if (j == link->mst_stream_alloc_table.stream_count) {
3298 work_table[i].vcp_id =
3299 proposed_table->stream_allocations[i].vcp_id;
3300 work_table[i].slot_count =
3301 proposed_table->stream_allocations[i].slot_count;
3302 work_table[i].stream_enc = stream_enc;
3306 /* update link->mst_stream_alloc_table with work_table */
3307 link->mst_stream_alloc_table.stream_count =
3308 proposed_table->stream_count;
3309 for (i = 0; i < MAX_CONTROLLER_NUM; i++)
3310 link->mst_stream_alloc_table.stream_allocations[i] =
3313 #if defined(CONFIG_DRM_AMD_DC_DCN)
3314 static void dc_log_vcp_x_y(const struct dc_link *link, struct fixed31_32 avg_time_slots_per_mtp)
3316 const uint32_t VCP_Y_PRECISION = 1000;
3317 uint64_t vcp_x, vcp_y;
3319 // Add 0.5*(1/VCP_Y_PRECISION) to round up to decimal precision
3320 avg_time_slots_per_mtp = dc_fixpt_add(
3321 avg_time_slots_per_mtp, dc_fixpt_from_fraction(1, 2 * VCP_Y_PRECISION));
3323 vcp_x = dc_fixpt_floor(avg_time_slots_per_mtp);
3324 vcp_y = dc_fixpt_floor(
3326 dc_fixpt_sub_int(avg_time_slots_per_mtp, dc_fixpt_floor(avg_time_slots_per_mtp)),
3329 if (link->type == dc_connection_mst_branch)
3330 DC_LOG_DP2("MST Update Payload: set_throttled_vcp_size slot X.Y for MST stream "
3331 "X: %lld Y: %lld/%d", vcp_x, vcp_y, VCP_Y_PRECISION);
3333 DC_LOG_DP2("SST Update Payload: set_throttled_vcp_size slot X.Y for SST stream "
3334 "X: %lld Y: %lld/%d", vcp_x, vcp_y, VCP_Y_PRECISION);
3338 * Payload allocation/deallocation for SST introduced in DP2.0
3340 enum dc_status dc_link_update_sst_payload(struct pipe_ctx *pipe_ctx, bool allocate)
3342 struct dc_stream_state *stream = pipe_ctx->stream;
3343 struct dc_link *link = stream->link;
3344 struct hpo_dp_link_encoder *hpo_dp_link_encoder = link->hpo_dp_link_enc;
3345 struct hpo_dp_stream_encoder *hpo_dp_stream_encoder = pipe_ctx->stream_res.hpo_dp_stream_enc;
3346 struct link_mst_stream_allocation_table proposed_table = {0};
3347 struct fixed31_32 avg_time_slots_per_mtp;
3348 DC_LOGGER_INIT(link->ctx->logger);
3350 /* slot X.Y for SST payload deallocate */
3352 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
3354 dc_log_vcp_x_y(link, avg_time_slots_per_mtp);
3356 hpo_dp_link_encoder->funcs->set_throttled_vcp_size(
3357 hpo_dp_link_encoder,
3358 hpo_dp_stream_encoder->inst,
3359 avg_time_slots_per_mtp);
3362 /* calculate VC payload and update branch with new payload allocation table*/
3363 if (!dpcd_write_128b_132b_sst_payload_allocation_table(
3368 DC_LOG_ERROR("SST Update Payload: Failed to update "
3369 "allocation table for "
3371 pipe_ctx->pipe_idx);
3374 proposed_table.stream_allocations[0].hpo_dp_stream_enc = hpo_dp_stream_encoder;
3376 ASSERT(proposed_table.stream_count == 1);
3378 //TODO - DP2.0 Logging: Instead of hpo_dp_stream_enc pointer, log instance id
3379 DC_LOG_DP2("SST Update Payload: hpo_dp_stream_enc: %p "
3382 (void *) proposed_table.stream_allocations[0].hpo_dp_stream_enc,
3383 proposed_table.stream_allocations[0].vcp_id,
3384 proposed_table.stream_allocations[0].slot_count);
3386 /* program DP source TX for payload */
3387 hpo_dp_link_encoder->funcs->update_stream_allocation_table(
3388 hpo_dp_link_encoder,
3391 /* poll for ACT handled */
3392 if (!dpcd_poll_for_allocation_change_trigger(link)) {
3393 // Failures will result in blackscreen and errors logged
3394 BREAK_TO_DEBUGGER();
3397 /* slot X.Y for SST payload allocate */
3399 avg_time_slots_per_mtp = calculate_sst_avg_time_slots_per_mtp(stream, link);
3401 dc_log_vcp_x_y(link, avg_time_slots_per_mtp);
3403 hpo_dp_link_encoder->funcs->set_throttled_vcp_size(
3404 hpo_dp_link_encoder,
3405 hpo_dp_stream_encoder->inst,
3406 avg_time_slots_per_mtp);
3409 /* Always return DC_OK.
3410 * If part of sequence fails, log failure(s) and show blackscreen
3416 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
3417 * because stream_encoder is not exposed to dm
3419 enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx)
3421 struct dc_stream_state *stream = pipe_ctx->stream;
3422 struct dc_link *link = stream->link;
3423 struct link_encoder *link_encoder = NULL;
3424 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3425 struct dp_mst_stream_allocation_table proposed_table = {0};
3426 struct fixed31_32 avg_time_slots_per_mtp;
3427 struct fixed31_32 pbn;
3428 struct fixed31_32 pbn_per_slot;
3430 enum act_return_status ret;
3431 DC_LOGGER_INIT(link->ctx->logger);
3433 /* Link encoder may have been dynamically assigned to non-physical display endpoint. */
3434 if (link->ep_type == DISPLAY_ENDPOINT_PHY)
3435 link_encoder = link->link_enc;
3436 else if (link->dc->res_pool->funcs->link_encs_assign)
3437 link_encoder = link_enc_cfg_get_link_enc_used_by_stream(pipe_ctx->stream->ctx->dc, stream);
3438 ASSERT(link_encoder);
3440 /* enable_link_dp_mst already check link->enabled_stream_count
3441 * and stream is in link->stream[]. This is called during set mode,
3442 * stream_enc is available.
3445 /* get calculate VC payload for stream: stream_alloc */
3446 if (dm_helpers_dp_mst_write_payload_allocation_table(
3451 update_mst_stream_alloc_table(
3452 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
3455 DC_LOG_WARNING("Failed to update"
3456 "MST allocation table for"
3458 pipe_ctx->pipe_idx);
3461 "stream_count: %d: \n ",
3463 link->mst_stream_alloc_table.stream_count);
3465 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3466 DC_LOG_MST("stream_enc[%d]: %p "
3467 "stream[%d].vcp_id: %d "
3468 "stream[%d].slot_count: %d\n",
3470 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3472 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3474 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3477 ASSERT(proposed_table.stream_count > 0);
3479 /* program DP source TX for payload */
3480 link_encoder->funcs->update_mst_stream_allocation_table(
3482 &link->mst_stream_alloc_table);
3484 /* send down message */
3485 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3489 if (ret != ACT_LINK_LOST) {
3490 dm_helpers_dp_mst_send_payload_allocation(
3496 /* slot X.Y for only current stream */
3497 pbn_per_slot = get_pbn_per_slot(stream);
3498 if (pbn_per_slot.value == 0) {
3499 DC_LOG_ERROR("Failure: pbn_per_slot==0 not allowed. Cannot continue, returning DC_UNSUPPORTED_VALUE.\n");
3500 return DC_UNSUPPORTED_VALUE;
3502 pbn = get_pbn_from_timing(pipe_ctx);
3503 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
3505 stream_encoder->funcs->set_throttled_vcp_size(
3507 avg_time_slots_per_mtp);
3513 static enum dc_status deallocate_mst_payload(struct pipe_ctx *pipe_ctx)
3515 struct dc_stream_state *stream = pipe_ctx->stream;
3516 struct dc_link *link = stream->link;
3517 struct link_encoder *link_encoder = NULL;
3518 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3519 struct dp_mst_stream_allocation_table proposed_table = {0};
3520 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
3522 bool mst_mode = (link->type == dc_connection_mst_branch);
3523 DC_LOGGER_INIT(link->ctx->logger);
3525 /* Link encoder may have been dynamically assigned to non-physical display endpoint. */
3526 if (link->ep_type == DISPLAY_ENDPOINT_PHY)
3527 link_encoder = link->link_enc;
3528 else if (link->dc->res_pool->funcs->link_encs_assign)
3529 link_encoder = link_enc_cfg_get_link_enc_used_by_stream(pipe_ctx->stream->ctx->dc, stream);
3530 ASSERT(link_encoder);
3532 /* deallocate_mst_payload is called before disable link. When mode or
3533 * disable/enable monitor, new stream is created which is not in link
3534 * stream[] yet. For this, payload is not allocated yet, so de-alloc
3535 * should not done. For new mode set, map_resources will get engine
3536 * for new stream, so stream_enc->id should be validated until here.
3540 stream_encoder->funcs->set_throttled_vcp_size(
3542 avg_time_slots_per_mtp);
3544 /* TODO: which component is responsible for remove payload table? */
3546 if (dm_helpers_dp_mst_write_payload_allocation_table(
3552 update_mst_stream_alloc_table(
3553 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
3556 DC_LOG_WARNING("Failed to update"
3557 "MST allocation table for"
3559 pipe_ctx->pipe_idx);
3564 "stream_count: %d: ",
3566 link->mst_stream_alloc_table.stream_count);
3568 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3569 DC_LOG_MST("stream_enc[%d]: %p "
3570 "stream[%d].vcp_id: %d "
3571 "stream[%d].slot_count: %d\n",
3573 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3575 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3577 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3580 link_encoder->funcs->update_mst_stream_allocation_table(
3582 &link->mst_stream_alloc_table);
3585 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3589 dm_helpers_dp_mst_send_payload_allocation(
3599 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3600 static void update_psp_stream_config(struct pipe_ctx *pipe_ctx, bool dpms_off)
3602 struct cp_psp *cp_psp = &pipe_ctx->stream->ctx->cp_psp;
3603 #if defined(CONFIG_DRM_AMD_DC_DCN)
3604 struct link_encoder *link_enc = NULL;
3607 if (cp_psp && cp_psp->funcs.update_stream_config) {
3608 struct cp_psp_stream_config config = {0};
3609 enum dp_panel_mode panel_mode =
3610 dp_get_panel_mode(pipe_ctx->stream->link);
3612 config.otg_inst = (uint8_t) pipe_ctx->stream_res.tg->inst;
3614 config.dig_fe = (uint8_t) pipe_ctx->stream_res.stream_enc->stream_enc_inst;
3615 config.dig_be = pipe_ctx->stream->link->link_enc_hw_inst;
3616 #if defined(CONFIG_DRM_AMD_DC_DCN)
3617 config.stream_enc_idx = pipe_ctx->stream_res.stream_enc->id - ENGINE_ID_DIGA;
3618 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_PHY) {
3619 link_enc = pipe_ctx->stream->link->link_enc;
3620 config.phy_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
3621 } else if (pipe_ctx->stream->link->dc->res_pool->funcs->link_encs_assign) {
3622 link_enc = link_enc_cfg_get_link_enc_used_by_stream(
3623 pipe_ctx->stream->ctx->dc,
3625 config.phy_idx = 0; /* Clear phy_idx for non-physical display endpoints. */
3629 config.link_enc_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
3630 if (is_dp_128b_132b_signal(pipe_ctx)) {
3631 config.stream_enc_idx = pipe_ctx->stream_res.hpo_dp_stream_enc->id - ENGINE_ID_HPO_DP_0;
3632 config.link_enc_idx = pipe_ctx->stream->link->hpo_dp_link_enc->inst;
3633 config.dp2_enabled = 1;
3636 config.dpms_off = dpms_off;
3637 config.dm_stream_ctx = pipe_ctx->stream->dm_stream_context;
3638 config.assr_enabled = (panel_mode == DP_PANEL_MODE_EDP);
3639 config.mst_enabled = (pipe_ctx->stream->signal ==
3640 SIGNAL_TYPE_DISPLAY_PORT_MST);
3641 cp_psp->funcs.update_stream_config(cp_psp->handle, &config);
3646 #if defined(CONFIG_DRM_AMD_DC_DCN)
3647 static void fpga_dp_hpo_enable_link_and_stream(struct dc_state *state, struct pipe_ctx *pipe_ctx)
3649 struct dc *dc = pipe_ctx->stream->ctx->dc;
3650 struct dc_stream_state *stream = pipe_ctx->stream;
3651 struct link_mst_stream_allocation_table proposed_table = {0};
3652 struct fixed31_32 avg_time_slots_per_mtp;
3653 uint8_t req_slot_count = 0;
3654 uint8_t vc_id = 1; /// VC ID always 1 for SST
3656 struct dc_link_settings link_settings = {0};
3657 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
3659 decide_link_settings(stream, &link_settings);
3660 stream->link->cur_link_settings = link_settings;
3662 /* Enable clock, Configure lane count, and Enable Link Encoder*/
3663 enable_dp_hpo_output(stream->link, &stream->link->cur_link_settings);
3666 /* Workaround for FPGA HPO capture DP link data:
3667 * HPO capture will set link to active mode
3668 * This workaround is required to get a capture from start of frame
3670 if (!dc->debug.fpga_hpo_capture_en) {
3671 struct encoder_set_dp_phy_pattern_param params = {0};
3672 params.dp_phy_pattern = DP_TEST_PATTERN_VIDEO_MODE;
3674 /* Set link active */
3675 stream->link->hpo_dp_link_enc->funcs->set_link_test_pattern(
3676 stream->link->hpo_dp_link_enc,
3681 /* Enable DP_STREAM_ENC */
3682 dc->hwss.enable_stream(pipe_ctx);
3684 /* Set DPS PPS SDP (AKA "info frames") */
3685 if (pipe_ctx->stream->timing.flags.DSC) {
3686 dp_set_dsc_pps_sdp(pipe_ctx, true, true);
3689 /* Allocate Payload */
3690 if ((stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) && (state->stream_count > 1)) {
3694 proposed_table.stream_count = state->stream_count;
3695 for (i = 0; i < state->stream_count; i++) {
3696 avg_time_slots_per_mtp = calculate_sst_avg_time_slots_per_mtp(state->streams[i], state->streams[i]->link);
3697 req_slot_count = dc_fixpt_ceil(avg_time_slots_per_mtp);
3698 proposed_table.stream_allocations[i].slot_count = req_slot_count;
3699 proposed_table.stream_allocations[i].vcp_id = i+1;
3700 /* NOTE: This makes assumption that pipe_ctx index is same as stream index */
3701 proposed_table.stream_allocations[i].hpo_dp_stream_enc = state->res_ctx.pipe_ctx[i].stream_res.hpo_dp_stream_enc;
3705 avg_time_slots_per_mtp = calculate_sst_avg_time_slots_per_mtp(stream, stream->link);
3706 req_slot_count = dc_fixpt_ceil(avg_time_slots_per_mtp);
3707 proposed_table.stream_count = 1; /// Always 1 stream for SST
3708 proposed_table.stream_allocations[0].slot_count = req_slot_count;
3709 proposed_table.stream_allocations[0].vcp_id = vc_id;
3710 proposed_table.stream_allocations[0].hpo_dp_stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
3713 stream->link->hpo_dp_link_enc->funcs->update_stream_allocation_table(
3714 stream->link->hpo_dp_link_enc,
3717 stream->link->hpo_dp_link_enc->funcs->set_throttled_vcp_size(
3718 stream->link->hpo_dp_link_enc,
3719 pipe_ctx->stream_res.hpo_dp_stream_enc->inst,
3720 avg_time_slots_per_mtp);
3724 dc->hwss.unblank_stream(pipe_ctx, &stream->link->cur_link_settings);
3728 void core_link_enable_stream(
3729 struct dc_state *state,
3730 struct pipe_ctx *pipe_ctx)
3732 struct dc *dc = pipe_ctx->stream->ctx->dc;
3733 struct dc_stream_state *stream = pipe_ctx->stream;
3734 struct dc_link *link = stream->sink->link;
3735 enum dc_status status;
3736 struct link_encoder *link_enc;
3737 #if defined(CONFIG_DRM_AMD_DC_DCN)
3738 enum otg_out_mux_dest otg_out_dest = OUT_MUX_DIO;
3739 struct vpg *vpg = pipe_ctx->stream_res.stream_enc->vpg;
3741 if (is_dp_128b_132b_signal(pipe_ctx))
3742 vpg = pipe_ctx->stream_res.hpo_dp_stream_enc->vpg;
3744 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
3746 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
3747 dc_is_virtual_signal(pipe_ctx->stream->signal))
3750 if (dc->res_pool->funcs->link_encs_assign && stream->link->ep_type != DISPLAY_ENDPOINT_PHY)
3751 link_enc = link_enc_cfg_get_link_enc_used_by_stream(dc, stream);
3753 link_enc = stream->link->link_enc;
3756 #if defined(CONFIG_DRM_AMD_DC_DCN)
3757 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)
3758 && !is_dp_128b_132b_signal(pipe_ctx)) {
3760 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)) {
3763 link_enc->funcs->setup(
3765 pipe_ctx->stream->signal);
3766 pipe_ctx->stream_res.stream_enc->funcs->setup_stereo_sync(
3767 pipe_ctx->stream_res.stream_enc,
3768 pipe_ctx->stream_res.tg->inst,
3769 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
3772 #if defined(CONFIG_DRM_AMD_DC_DCN)
3773 if (is_dp_128b_132b_signal(pipe_ctx)) {
3774 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->set_stream_attribute(
3775 pipe_ctx->stream_res.hpo_dp_stream_enc,
3777 stream->output_color_space,
3778 stream->use_vsc_sdp_for_colorimetry,
3779 stream->timing.flags.DSC,
3781 otg_out_dest = OUT_MUX_HPO_DP;
3782 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
3783 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
3784 pipe_ctx->stream_res.stream_enc,
3786 stream->output_color_space,
3787 stream->use_vsc_sdp_for_colorimetry,
3788 stream->link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
3791 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
3792 pipe_ctx->stream_res.stream_enc,
3794 stream->output_color_space,
3795 stream->use_vsc_sdp_for_colorimetry,
3796 stream->link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
3799 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3800 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
3802 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
3803 pipe_ctx->stream_res.stream_enc->funcs->hdmi_set_stream_attribute(
3804 pipe_ctx->stream_res.stream_enc,
3806 stream->phy_pix_clk,
3807 pipe_ctx->stream_res.audio != NULL);
3809 pipe_ctx->stream->link->link_state_valid = true;
3811 #if defined(CONFIG_DRM_AMD_DC_DCN)
3812 if (pipe_ctx->stream_res.tg->funcs->set_out_mux)
3813 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, otg_out_dest);
3816 if (dc_is_dvi_signal(pipe_ctx->stream->signal))
3817 pipe_ctx->stream_res.stream_enc->funcs->dvi_set_stream_attribute(
3818 pipe_ctx->stream_res.stream_enc,
3820 (pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
3823 if (dc_is_lvds_signal(pipe_ctx->stream->signal))
3824 pipe_ctx->stream_res.stream_enc->funcs->lvds_set_stream_attribute(
3825 pipe_ctx->stream_res.stream_enc,
3828 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
3829 bool apply_edp_fast_boot_optimization =
3830 pipe_ctx->stream->apply_edp_fast_boot_optimization;
3832 pipe_ctx->stream->apply_edp_fast_boot_optimization = false;
3834 #if defined(CONFIG_DRM_AMD_DC_DCN)
3835 // Enable VPG before building infoframe
3836 if (vpg && vpg->funcs->vpg_poweron)
3837 vpg->funcs->vpg_poweron(vpg);
3840 resource_build_info_frame(pipe_ctx);
3841 dc->hwss.update_info_frame(pipe_ctx);
3843 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3844 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
3846 /* Do not touch link on seamless boot optimization. */
3847 if (pipe_ctx->stream->apply_seamless_boot_optimization) {
3848 pipe_ctx->stream->dpms_off = false;
3850 /* Still enable stream features & audio on seamless boot for DP external displays */
3851 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT) {
3852 enable_stream_features(pipe_ctx);
3853 if (pipe_ctx->stream_res.audio != NULL) {
3854 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
3855 dc->hwss.enable_audio_stream(pipe_ctx);
3859 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3860 update_psp_stream_config(pipe_ctx, false);
3865 /* eDP lit up by bios already, no need to enable again. */
3866 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
3867 apply_edp_fast_boot_optimization &&
3868 !pipe_ctx->stream->timing.flags.DSC) {
3869 pipe_ctx->stream->dpms_off = false;
3870 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3871 update_psp_stream_config(pipe_ctx, false);
3876 if (pipe_ctx->stream->dpms_off)
3879 /* Have to setup DSC before DIG FE and BE are connected (which happens before the
3880 * link training). This is to make sure the bandwidth sent to DIG BE won't be
3881 * bigger than what the link and/or DIG BE can handle. VBID[6]/CompressedStream_flag
3882 * will be automatically set at a later time when the video is enabled
3883 * (DP_VID_STREAM_EN = 1).
3885 if (pipe_ctx->stream->timing.flags.DSC) {
3886 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3887 dc_is_virtual_signal(pipe_ctx->stream->signal))
3888 dp_set_dsc_enable(pipe_ctx, true);
3891 status = enable_link(state, pipe_ctx);
3893 if (status != DC_OK) {
3894 DC_LOG_WARNING("enabling link %u failed: %d\n",
3895 pipe_ctx->stream->link->link_index,
3898 /* Abort stream enable *unless* the failure was due to
3899 * DP link training - some DP monitors will recover and
3900 * show the stream anyway. But MST displays can't proceed
3901 * without link training.
3903 if (status != DC_FAIL_DP_LINK_TRAINING ||
3904 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3905 BREAK_TO_DEBUGGER();
3910 /* turn off otg test pattern if enable */
3911 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
3912 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
3913 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
3914 COLOR_DEPTH_UNDEFINED);
3916 /* This second call is needed to reconfigure the DIG
3917 * as a workaround for the incorrect value being applied
3918 * from transmitter control.
3920 #if defined(CONFIG_DRM_AMD_DC_DCN)
3921 if (!(dc_is_virtual_signal(pipe_ctx->stream->signal) ||
3922 is_dp_128b_132b_signal(pipe_ctx)))
3924 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
3927 link_enc->funcs->setup(
3929 pipe_ctx->stream->signal);
3931 dc->hwss.enable_stream(pipe_ctx);
3933 /* Set DPS PPS SDP (AKA "info frames") */
3934 if (pipe_ctx->stream->timing.flags.DSC) {
3935 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3936 dc_is_virtual_signal(pipe_ctx->stream->signal)) {
3937 dp_set_dsc_on_rx(pipe_ctx, true);
3938 dp_set_dsc_pps_sdp(pipe_ctx, true, true);
3942 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
3943 dc_link_allocate_mst_payload(pipe_ctx);
3944 #if defined(CONFIG_DRM_AMD_DC_DCN)
3945 else if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
3946 is_dp_128b_132b_signal(pipe_ctx))
3947 dc_link_update_sst_payload(pipe_ctx, true);
3950 dc->hwss.unblank_stream(pipe_ctx,
3951 &pipe_ctx->stream->link->cur_link_settings);
3953 if (stream->sink_patches.delay_ignore_msa > 0)
3954 msleep(stream->sink_patches.delay_ignore_msa);
3956 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3957 enable_stream_features(pipe_ctx);
3958 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3959 update_psp_stream_config(pipe_ctx, false);
3962 dc->hwss.enable_audio_stream(pipe_ctx);
3964 } else { // if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
3965 #if defined(CONFIG_DRM_AMD_DC_DCN)
3966 if (is_dp_128b_132b_signal(pipe_ctx)) {
3967 fpga_dp_hpo_enable_link_and_stream(state, pipe_ctx);
3970 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3971 dc_is_virtual_signal(pipe_ctx->stream->signal))
3972 dp_set_dsc_enable(pipe_ctx, true);
3976 if (pipe_ctx->stream->signal == SIGNAL_TYPE_HDMI_TYPE_A) {
3977 core_link_set_avmute(pipe_ctx, false);
3981 void core_link_disable_stream(struct pipe_ctx *pipe_ctx)
3983 struct dc *dc = pipe_ctx->stream->ctx->dc;
3984 struct dc_stream_state *stream = pipe_ctx->stream;
3985 struct dc_link *link = stream->sink->link;
3986 #if defined(CONFIG_DRM_AMD_DC_DCN)
3987 struct vpg *vpg = pipe_ctx->stream_res.stream_enc->vpg;
3989 if (is_dp_128b_132b_signal(pipe_ctx))
3990 vpg = pipe_ctx->stream_res.hpo_dp_stream_enc->vpg;
3993 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
3994 dc_is_virtual_signal(pipe_ctx->stream->signal))
3997 if (!pipe_ctx->stream->sink->edid_caps.panel_patch.skip_avmute) {
3998 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
3999 core_link_set_avmute(pipe_ctx, true);
4002 dc->hwss.disable_audio_stream(pipe_ctx);
4004 #if defined(CONFIG_DRM_AMD_DC_HDCP)
4005 update_psp_stream_config(pipe_ctx, true);
4007 dc->hwss.blank_stream(pipe_ctx);
4009 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
4010 deallocate_mst_payload(pipe_ctx);
4011 #if defined(CONFIG_DRM_AMD_DC_DCN)
4012 else if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
4013 is_dp_128b_132b_signal(pipe_ctx))
4014 dc_link_update_sst_payload(pipe_ctx, false);
4017 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
4018 struct ext_hdmi_settings settings = {0};
4019 enum engine_id eng_id = pipe_ctx->stream_res.stream_enc->id;
4021 unsigned short masked_chip_caps = link->chip_caps &
4022 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
4023 //Need to inform that sink is going to use legacy HDMI mode.
4024 dal_ddc_service_write_scdc_data(
4026 165000,//vbios only handles 165Mhz.
4028 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
4029 /* DP159, Retimer settings */
4030 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings))
4031 write_i2c_retimer_setting(pipe_ctx,
4032 false, false, &settings);
4034 write_i2c_default_retimer_setting(pipe_ctx,
4036 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
4037 /* PI3EQX1204, Redriver settings */
4038 write_i2c_redriver_setting(pipe_ctx, false);
4042 #if defined(CONFIG_DRM_AMD_DC_DCN)
4043 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
4044 !is_dp_128b_132b_signal(pipe_ctx)) {
4046 /* In DP1.x SST mode, our encoder will go to TPS1
4047 * when link is on but stream is off.
4048 * Disabling link before stream will avoid exposing TPS1 pattern
4049 * during the disable sequence as it will confuse some receivers
4051 * In DP2 or MST mode, our encoder will stay video active
4053 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
4054 dc->hwss.disable_stream(pipe_ctx);
4056 dc->hwss.disable_stream(pipe_ctx);
4057 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
4060 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
4062 dc->hwss.disable_stream(pipe_ctx);
4065 if (pipe_ctx->stream->timing.flags.DSC) {
4066 if (dc_is_dp_signal(pipe_ctx->stream->signal))
4067 dp_set_dsc_enable(pipe_ctx, false);
4069 #if defined(CONFIG_DRM_AMD_DC_DCN)
4070 if (is_dp_128b_132b_signal(pipe_ctx)) {
4071 if (pipe_ctx->stream_res.tg->funcs->set_out_mux)
4072 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, OUT_MUX_DIO);
4076 #if defined(CONFIG_DRM_AMD_DC_DCN)
4077 if (vpg && vpg->funcs->vpg_powerdown)
4078 vpg->funcs->vpg_powerdown(vpg);
4082 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
4084 struct dc *dc = pipe_ctx->stream->ctx->dc;
4086 if (!dc_is_hdmi_signal(pipe_ctx->stream->signal))
4089 dc->hwss.set_avmute(pipe_ctx, enable);
4093 * dc_link_enable_hpd_filter:
4094 * If enable is true, programs HPD filter on associated HPD line using
4095 * delay_on_disconnect/delay_on_connect values dependent on
4096 * link->connector_signal
4098 * If enable is false, programs HPD filter on associated HPD line with no
4099 * delays on connect or disconnect
4101 * @link: pointer to the dc link
4102 * @enable: boolean specifying whether to enable hbd
4104 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
4109 link->is_hpd_filter_disabled = false;
4110 program_hpd_filter(link);
4112 link->is_hpd_filter_disabled = true;
4113 /* Obtain HPD handle */
4114 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
4119 /* Setup HPD filtering */
4120 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
4121 struct gpio_hpd_config config;
4123 config.delay_on_connect = 0;
4124 config.delay_on_disconnect = 0;
4126 dal_irq_setup_hpd_filter(hpd, &config);
4128 dal_gpio_close(hpd);
4130 ASSERT_CRITICAL(false);
4132 /* Release HPD handle */
4133 dal_gpio_destroy_irq(&hpd);
4137 void dc_link_set_drive_settings(struct dc *dc,
4138 struct link_training_settings *lt_settings,
4139 const struct dc_link *link)
4144 for (i = 0; i < dc->link_count; i++) {
4145 if (dc->links[i] == link)
4149 if (i >= dc->link_count)
4150 ASSERT_CRITICAL(false);
4152 dc_link_dp_set_drive_settings(dc->links[i], lt_settings);
4155 void dc_link_set_preferred_link_settings(struct dc *dc,
4156 struct dc_link_settings *link_setting,
4157 struct dc_link *link)
4160 struct pipe_ctx *pipe;
4161 struct dc_stream_state *link_stream;
4162 struct dc_link_settings store_settings = *link_setting;
4164 link->preferred_link_setting = store_settings;
4166 /* Retrain with preferred link settings only relevant for
4168 * Check for non-DP signal or if passive dongle present
4170 if (!dc_is_dp_signal(link->connector_signal) ||
4171 link->dongle_max_pix_clk > 0)
4174 for (i = 0; i < MAX_PIPES; i++) {
4175 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
4176 if (pipe->stream && pipe->stream->link) {
4177 if (pipe->stream->link == link) {
4178 link_stream = pipe->stream;
4184 /* Stream not found */
4188 /* Cannot retrain link if backend is off */
4189 if (link_stream->dpms_off)
4192 decide_link_settings(link_stream, &store_settings);
4194 if ((store_settings.lane_count != LANE_COUNT_UNKNOWN) &&
4195 (store_settings.link_rate != LINK_RATE_UNKNOWN))
4196 dp_retrain_link_dp_test(link, &store_settings, false);
4199 void dc_link_set_preferred_training_settings(struct dc *dc,
4200 struct dc_link_settings *link_setting,
4201 struct dc_link_training_overrides *lt_overrides,
4202 struct dc_link *link,
4203 bool skip_immediate_retrain)
4205 if (lt_overrides != NULL)
4206 link->preferred_training_settings = *lt_overrides;
4208 memset(&link->preferred_training_settings, 0, sizeof(link->preferred_training_settings));
4210 if (link_setting != NULL) {
4211 link->preferred_link_setting = *link_setting;
4212 #if defined(CONFIG_DRM_AMD_DC_DCN)
4213 if (dp_get_link_encoding_format(link_setting) ==
4214 DP_128b_132b_ENCODING && !link->hpo_dp_link_enc) {
4215 if (!add_dp_hpo_link_encoder_to_link(link))
4216 memset(&link->preferred_link_setting, 0, sizeof(link->preferred_link_setting));
4220 link->preferred_link_setting.lane_count = LANE_COUNT_UNKNOWN;
4221 link->preferred_link_setting.link_rate = LINK_RATE_UNKNOWN;
4224 /* Retrain now, or wait until next stream update to apply */
4225 if (skip_immediate_retrain == false)
4226 dc_link_set_preferred_link_settings(dc, &link->preferred_link_setting, link);
4229 void dc_link_enable_hpd(const struct dc_link *link)
4231 dc_link_dp_enable_hpd(link);
4234 void dc_link_disable_hpd(const struct dc_link *link)
4236 dc_link_dp_disable_hpd(link);
4239 void dc_link_set_test_pattern(struct dc_link *link,
4240 enum dp_test_pattern test_pattern,
4241 enum dp_test_pattern_color_space test_pattern_color_space,
4242 const struct link_training_settings *p_link_settings,
4243 const unsigned char *p_custom_pattern,
4244 unsigned int cust_pattern_size)
4247 dc_link_dp_set_test_pattern(
4250 test_pattern_color_space,
4256 uint32_t dc_link_bandwidth_kbps(
4257 const struct dc_link *link,
4258 const struct dc_link_settings *link_setting)
4260 #if defined(CONFIG_DRM_AMD_DC_DCN)
4261 uint32_t total_data_bw_efficiency_x10000 = 0;
4262 uint32_t link_rate_per_lane_kbps = 0;
4264 switch (dp_get_link_encoding_format(link_setting)) {
4265 case DP_8b_10b_ENCODING:
4266 /* For 8b/10b encoding:
4267 * link rate is defined in the unit of LINK_RATE_REF_FREQ_IN_KHZ per DP byte per lane.
4268 * data bandwidth efficiency is 80% with additional 3% overhead if FEC is supported.
4270 link_rate_per_lane_kbps = link_setting->link_rate * LINK_RATE_REF_FREQ_IN_KHZ * BITS_PER_DP_BYTE;
4271 total_data_bw_efficiency_x10000 = DATA_EFFICIENCY_8b_10b_x10000;
4272 if (dc_link_should_enable_fec(link)) {
4273 total_data_bw_efficiency_x10000 /= 100;
4274 total_data_bw_efficiency_x10000 *= DATA_EFFICIENCY_8b_10b_FEC_EFFICIENCY_x100;
4277 case DP_128b_132b_ENCODING:
4278 /* For 128b/132b encoding:
4279 * link rate is defined in the unit of 10mbps per lane.
4280 * total data bandwidth efficiency is always 96.71%.
4282 link_rate_per_lane_kbps = link_setting->link_rate * 10000;
4283 total_data_bw_efficiency_x10000 = DATA_EFFICIENCY_128b_132b_x10000;
4289 /* overall effective link bandwidth = link rate per lane * lane count * total data bandwidth efficiency */
4290 return link_rate_per_lane_kbps * link_setting->lane_count / 10000 * total_data_bw_efficiency_x10000;
4292 uint32_t link_bw_kbps =
4293 link_setting->link_rate * LINK_RATE_REF_FREQ_IN_KHZ; /* bytes per sec */
4295 link_bw_kbps *= 8; /* 8 bits per byte*/
4296 link_bw_kbps *= link_setting->lane_count;
4298 if (dc_link_should_enable_fec(link)) {
4299 /* Account for FEC overhead.
4300 * We have to do it based on caps,
4301 * and not based on FEC being set ready,
4302 * because FEC is set ready too late in
4303 * the process to correctly be picked up
4304 * by mode enumeration.
4306 * There's enough zeros at the end of 'kbps'
4307 * that make the below operation 100% precise
4309 * 'long long' makes it work even for HDMI 2.1
4310 * max bandwidth (and much, much bigger bandwidths
4311 * than that, actually).
4313 * NOTE: Reducing link BW by 3% may not be precise
4314 * because it may be a stream BT that increases by 3%, and so
4315 * 1/1.03 = 0.970873 factor should have been used instead,
4316 * but the difference is minimal and is in a safe direction,
4317 * which all works well around potential ambiguity of DP 1.4a spec.
4319 long long fec_link_bw_kbps = link_bw_kbps * 970LL;
4320 link_bw_kbps = (uint32_t)(div64_s64(fec_link_bw_kbps, 1000LL));
4322 return link_bw_kbps;
4327 const struct dc_link_settings *dc_link_get_link_cap(
4328 const struct dc_link *link)
4330 if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
4331 link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
4332 return &link->preferred_link_setting;
4333 return &link->verified_link_cap;
4336 void dc_link_overwrite_extended_receiver_cap(
4337 struct dc_link *link)
4339 dp_overwrite_extended_receiver_cap(link);
4342 bool dc_link_is_fec_supported(const struct dc_link *link)
4344 struct link_encoder *link_enc = NULL;
4346 /* Links supporting dynamically assigned link encoder will be assigned next
4347 * available encoder if one not already assigned.
4349 if (link->is_dig_mapping_flexible &&
4350 link->dc->res_pool->funcs->link_encs_assign) {
4351 link_enc = link_enc_cfg_get_link_enc_used_by_link(link->ctx->dc, link);
4352 if (link_enc == NULL)
4353 link_enc = link_enc_cfg_get_next_avail_link_enc(link->ctx->dc);
4355 link_enc = link->link_enc;
4358 return (dc_is_dp_signal(link->connector_signal) && link_enc &&
4359 link_enc->features.fec_supported &&
4360 link->dpcd_caps.fec_cap.bits.FEC_CAPABLE &&
4361 !IS_FPGA_MAXIMUS_DC(link->ctx->dce_environment));
4364 bool dc_link_should_enable_fec(const struct dc_link *link)
4366 bool is_fec_disable = false;
4369 if ((link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT_MST &&
4371 link->local_sink->edid_caps.panel_patch.disable_fec) ||
4372 (link->connector_signal == SIGNAL_TYPE_EDP
4374 is_fec_disable = true;
4376 if (dc_link_is_fec_supported(link) && !link->dc->debug.disable_fec && !is_fec_disable)
4382 uint32_t dc_bandwidth_in_kbps_from_timing(
4383 const struct dc_crtc_timing *timing)
4385 uint32_t bits_per_channel = 0;
4388 #if defined(CONFIG_DRM_AMD_DC_DCN)
4389 if (timing->flags.DSC)
4390 return dc_dsc_stream_bandwidth_in_kbps(timing,
4391 timing->dsc_cfg.bits_per_pixel,
4392 timing->dsc_cfg.num_slices_h,
4393 timing->dsc_cfg.is_dp);
4396 switch (timing->display_color_depth) {
4397 case COLOR_DEPTH_666:
4398 bits_per_channel = 6;
4400 case COLOR_DEPTH_888:
4401 bits_per_channel = 8;
4403 case COLOR_DEPTH_101010:
4404 bits_per_channel = 10;
4406 case COLOR_DEPTH_121212:
4407 bits_per_channel = 12;
4409 case COLOR_DEPTH_141414:
4410 bits_per_channel = 14;
4412 case COLOR_DEPTH_161616:
4413 bits_per_channel = 16;
4416 ASSERT(bits_per_channel != 0);
4417 bits_per_channel = 8;
4421 kbps = timing->pix_clk_100hz / 10;
4422 kbps *= bits_per_channel;
4424 if (timing->flags.Y_ONLY != 1) {
4425 /*Only YOnly make reduce bandwidth by 1/3 compares to RGB*/
4427 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
4429 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
4430 kbps = kbps * 2 / 3;