2 * Copyright 2012-15 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/slab.h>
28 #include "dm_services.h"
29 #include "atomfirmware.h"
30 #include "dm_helpers.h"
32 #include "grph_object_id.h"
33 #include "gpio_service_interface.h"
34 #include "core_status.h"
35 #include "dc_link_dp.h"
36 #include "dc_link_ddc.h"
37 #include "link_hwss.h"
40 #include "link_encoder.h"
41 #include "hw_sequencer.h"
44 #include "fixed31_32.h"
45 #include "dpcd_defs.h"
47 #include "hw/clk_mgr.h"
48 #include "dce/dmub_psr.h"
49 #include "dmub/dmub_srv.h"
50 #include "inc/hw/panel_cntl.h"
52 #define DC_LOGGER_INIT(logger)
54 #define LINK_INFO(...) \
58 #define RETIMER_REDRIVER_INFO(...) \
59 DC_LOG_RETIMER_REDRIVER( \
61 /*******************************************************************************
63 ******************************************************************************/
66 PEAK_FACTOR_X1000 = 1006,
68 * Some receivers fail to train on first try and are good
69 * on subsequent tries. 2 retries should be plenty. If we
70 * don't have a successful training then we don't expect to
73 LINK_TRAINING_MAX_VERIFY_RETRY = 2
76 /*******************************************************************************
78 ******************************************************************************/
79 static void dc_link_destruct(struct dc_link *link)
84 dal_gpio_destroy_irq(&link->hpd_gpio);
85 link->hpd_gpio = NULL;
89 dal_ddc_service_destroy(&link->ddc);
92 link->panel_cntl->funcs->destroy(&link->panel_cntl);
95 /* Update link encoder tracking variables. These are used for the dynamic
96 * assignment of link encoders to streams.
98 link->dc->res_pool->link_encoders[link->link_enc->preferred_engine] = NULL;
99 link->dc->res_pool->dig_link_enc_count--;
100 link->link_enc->funcs->destroy(&link->link_enc);
103 if (link->local_sink)
104 dc_sink_release(link->local_sink);
106 for (i = 0; i < link->sink_count; ++i)
107 dc_sink_release(link->remote_sinks[i]);
110 struct gpio *get_hpd_gpio(struct dc_bios *dcb,
111 struct graphics_object_id link_id,
112 struct gpio_service *gpio_service)
114 enum bp_result bp_result;
115 struct graphics_object_hpd_info hpd_info;
116 struct gpio_pin_info pin_info;
118 if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
121 bp_result = dcb->funcs->get_gpio_pin_info(dcb,
122 hpd_info.hpd_int_gpio_uid, &pin_info);
124 if (bp_result != BP_RESULT_OK) {
125 ASSERT(bp_result == BP_RESULT_NORECORD);
129 return dal_gpio_service_create_irq(gpio_service,
135 * Function: program_hpd_filter
138 * Programs HPD filter on associated HPD line
140 * @param [in] delay_on_connect_in_ms: Connect filter timeout
141 * @param [in] delay_on_disconnect_in_ms: Disconnect filter timeout
144 * true on success, false otherwise
146 static bool program_hpd_filter(const struct dc_link *link)
150 int delay_on_connect_in_ms = 0;
151 int delay_on_disconnect_in_ms = 0;
153 if (link->is_hpd_filter_disabled)
155 /* Verify feature is supported */
156 switch (link->connector_signal) {
157 case SIGNAL_TYPE_DVI_SINGLE_LINK:
158 case SIGNAL_TYPE_DVI_DUAL_LINK:
159 case SIGNAL_TYPE_HDMI_TYPE_A:
160 /* Program hpd filter */
161 delay_on_connect_in_ms = 500;
162 delay_on_disconnect_in_ms = 100;
164 case SIGNAL_TYPE_DISPLAY_PORT:
165 case SIGNAL_TYPE_DISPLAY_PORT_MST:
166 /* Program hpd filter to allow DP signal to settle */
167 /* 500: not able to detect MST <-> SST switch as HPD is low for
168 * only 100ms on DELL U2413
169 * 0: some passive dongle still show aux mode instead of i2c
170 * 20-50: not enough to hide bouncing HPD with passive dongle.
171 * also see intermittent i2c read issues.
173 delay_on_connect_in_ms = 80;
174 delay_on_disconnect_in_ms = 0;
176 case SIGNAL_TYPE_LVDS:
177 case SIGNAL_TYPE_EDP:
179 /* Don't program hpd filter */
183 /* Obtain HPD handle */
184 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
185 link->ctx->gpio_service);
190 /* Setup HPD filtering */
191 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
192 struct gpio_hpd_config config;
194 config.delay_on_connect = delay_on_connect_in_ms;
195 config.delay_on_disconnect = delay_on_disconnect_in_ms;
197 dal_irq_setup_hpd_filter(hpd, &config);
203 ASSERT_CRITICAL(false);
206 /* Release HPD handle */
207 dal_gpio_destroy_irq(&hpd);
212 bool dc_link_wait_for_t12(struct dc_link *link)
214 if (link->connector_signal == SIGNAL_TYPE_EDP && link->dc->hwss.edp_wait_for_T12) {
215 link->dc->hwss.edp_wait_for_T12(link);
224 * dc_link_detect_sink() - Determine if there is a sink connected
226 * @link: pointer to the dc link
227 * @type: Returned connection type
228 * Does not detect downstream devices, such as MST sinks
229 * or display connected through active dongles
231 bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type)
233 uint32_t is_hpd_high = 0;
234 struct gpio *hpd_pin;
236 if (link->connector_signal == SIGNAL_TYPE_LVDS) {
237 *type = dc_connection_single;
241 if (link->connector_signal == SIGNAL_TYPE_EDP) {
242 /*in case it is not on*/
243 link->dc->hwss.edp_power_control(link, true);
244 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
247 /* todo: may need to lock gpio access */
248 hpd_pin = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
249 link->ctx->gpio_service);
251 goto hpd_gpio_failure;
253 dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
254 dal_gpio_get_value(hpd_pin, &is_hpd_high);
255 dal_gpio_close(hpd_pin);
256 dal_gpio_destroy_irq(&hpd_pin);
259 *type = dc_connection_single;
260 /* TODO: need to do the actual detection */
262 *type = dc_connection_none;
271 static enum ddc_transaction_type get_ddc_transaction_type(enum signal_type sink_signal)
273 enum ddc_transaction_type transaction_type = DDC_TRANSACTION_TYPE_NONE;
275 switch (sink_signal) {
276 case SIGNAL_TYPE_DVI_SINGLE_LINK:
277 case SIGNAL_TYPE_DVI_DUAL_LINK:
278 case SIGNAL_TYPE_HDMI_TYPE_A:
279 case SIGNAL_TYPE_LVDS:
280 case SIGNAL_TYPE_RGB:
281 transaction_type = DDC_TRANSACTION_TYPE_I2C;
284 case SIGNAL_TYPE_DISPLAY_PORT:
285 case SIGNAL_TYPE_EDP:
286 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
289 case SIGNAL_TYPE_DISPLAY_PORT_MST:
290 /* MST does not use I2COverAux, but there is the
291 * SPECIAL use case for "immediate dwnstrm device
292 * access" (EPR#370830).
294 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
301 return transaction_type;
304 static enum signal_type get_basic_signal_type(struct graphics_object_id encoder,
305 struct graphics_object_id downstream)
307 if (downstream.type == OBJECT_TYPE_CONNECTOR) {
308 switch (downstream.id) {
309 case CONNECTOR_ID_SINGLE_LINK_DVII:
310 switch (encoder.id) {
311 case ENCODER_ID_INTERNAL_DAC1:
312 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
313 case ENCODER_ID_INTERNAL_DAC2:
314 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
315 return SIGNAL_TYPE_RGB;
317 return SIGNAL_TYPE_DVI_SINGLE_LINK;
320 case CONNECTOR_ID_DUAL_LINK_DVII:
322 switch (encoder.id) {
323 case ENCODER_ID_INTERNAL_DAC1:
324 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
325 case ENCODER_ID_INTERNAL_DAC2:
326 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
327 return SIGNAL_TYPE_RGB;
329 return SIGNAL_TYPE_DVI_DUAL_LINK;
333 case CONNECTOR_ID_SINGLE_LINK_DVID:
334 return SIGNAL_TYPE_DVI_SINGLE_LINK;
335 case CONNECTOR_ID_DUAL_LINK_DVID:
336 return SIGNAL_TYPE_DVI_DUAL_LINK;
337 case CONNECTOR_ID_VGA:
338 return SIGNAL_TYPE_RGB;
339 case CONNECTOR_ID_HDMI_TYPE_A:
340 return SIGNAL_TYPE_HDMI_TYPE_A;
341 case CONNECTOR_ID_LVDS:
342 return SIGNAL_TYPE_LVDS;
343 case CONNECTOR_ID_DISPLAY_PORT:
344 return SIGNAL_TYPE_DISPLAY_PORT;
345 case CONNECTOR_ID_EDP:
346 return SIGNAL_TYPE_EDP;
348 return SIGNAL_TYPE_NONE;
350 } else if (downstream.type == OBJECT_TYPE_ENCODER) {
351 switch (downstream.id) {
352 case ENCODER_ID_EXTERNAL_NUTMEG:
353 case ENCODER_ID_EXTERNAL_TRAVIS:
354 return SIGNAL_TYPE_DISPLAY_PORT;
356 return SIGNAL_TYPE_NONE;
360 return SIGNAL_TYPE_NONE;
364 * dc_link_is_dp_sink_present() - Check if there is a native DP
365 * or passive DP-HDMI dongle connected
367 bool dc_link_is_dp_sink_present(struct dc_link *link)
369 enum gpio_result gpio_result;
370 uint32_t clock_pin = 0;
374 enum connector_id connector_id =
375 dal_graphics_object_id_get_connector_id(link->link_id);
378 ((connector_id == CONNECTOR_ID_DISPLAY_PORT) ||
379 (connector_id == CONNECTOR_ID_EDP));
381 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
388 /* Open GPIO and set it to I2C mode */
389 /* Note: this GpioMode_Input will be converted
390 * to GpioConfigType_I2cAuxDualMode in GPIO component,
391 * which indicates we need additional delay
394 if (dal_ddc_open(ddc, GPIO_MODE_INPUT,
395 GPIO_DDC_CONFIG_TYPE_MODE_I2C) != GPIO_RESULT_OK) {
402 * Read GPIO: DP sink is present if both clock and data pins are zero
404 * [W/A] plug-unplug DP cable, sometimes customer board has
405 * one short pulse on clk_pin(1V, < 1ms). DP will be config to HDMI/DVI
406 * then monitor can't br light up. Add retry 3 times
407 * But in real passive dongle, it need additional 3ms to detect
410 gpio_result = dal_gpio_get_value(ddc->pin_clock, &clock_pin);
411 ASSERT(gpio_result == GPIO_RESULT_OK);
416 } while (retry++ < 3);
418 present = (gpio_result == GPIO_RESULT_OK) && !clock_pin;
427 * Detect output sink type
429 static enum signal_type link_detect_sink(struct dc_link *link,
430 enum dc_detect_reason reason)
432 enum signal_type result = get_basic_signal_type(link->link_enc->id,
435 /* Internal digital encoder will detect only dongles
436 * that require digital signal
439 /* Detection mechanism is different
440 * for different native connectors.
441 * LVDS connector supports only LVDS signal;
442 * PCIE is a bus slot, the actual connector needs to be detected first;
443 * eDP connector supports only eDP signal;
444 * HDMI should check straps for audio
447 /* PCIE detects the actual connector on add-on board */
448 if (link->link_id.id == CONNECTOR_ID_PCIE) {
449 /* ZAZTODO implement PCIE add-on card detection */
452 switch (link->link_id.id) {
453 case CONNECTOR_ID_HDMI_TYPE_A: {
454 /* check audio support:
455 * if native HDMI is not supported, switch to DVI
457 struct audio_support *aud_support =
458 &link->dc->res_pool->audio_support;
460 if (!aud_support->hdmi_audio_native)
461 if (link->link_id.id == CONNECTOR_ID_HDMI_TYPE_A)
462 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
465 case CONNECTOR_ID_DISPLAY_PORT: {
466 /* DP HPD short pulse. Passive DP dongle will not
469 if (reason != DETECT_REASON_HPDRX) {
470 /* Check whether DP signal detected: if not -
471 * we assume signal is DVI; it could be corrected
472 * to HDMI after dongle detection
474 if (!dm_helpers_is_dp_sink_present(link))
475 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
486 static enum signal_type decide_signal_from_strap_and_dongle_type(enum display_dongle_type dongle_type,
487 struct audio_support *audio_support)
489 enum signal_type signal = SIGNAL_TYPE_NONE;
491 switch (dongle_type) {
492 case DISPLAY_DONGLE_DP_HDMI_DONGLE:
493 if (audio_support->hdmi_audio_on_dongle)
494 signal = SIGNAL_TYPE_HDMI_TYPE_A;
496 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
498 case DISPLAY_DONGLE_DP_DVI_DONGLE:
499 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
501 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE:
502 if (audio_support->hdmi_audio_native)
503 signal = SIGNAL_TYPE_HDMI_TYPE_A;
505 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
508 signal = SIGNAL_TYPE_NONE;
515 static enum signal_type dp_passive_dongle_detection(struct ddc_service *ddc,
516 struct display_sink_capability *sink_cap,
517 struct audio_support *audio_support)
519 dal_ddc_service_i2c_query_dp_dual_mode_adaptor(ddc, sink_cap);
521 return decide_signal_from_strap_and_dongle_type(sink_cap->dongle_type,
525 static void link_disconnect_sink(struct dc_link *link)
527 if (link->local_sink) {
528 dc_sink_release(link->local_sink);
529 link->local_sink = NULL;
532 link->dpcd_sink_count = 0;
535 static void link_disconnect_remap(struct dc_sink *prev_sink, struct dc_link *link)
537 dc_sink_release(link->local_sink);
538 link->local_sink = prev_sink;
541 #if defined(CONFIG_DRM_AMD_DC_HDCP)
542 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal)
547 case SIGNAL_TYPE_DISPLAY_PORT:
548 case SIGNAL_TYPE_DISPLAY_PORT_MST:
549 ret = link->hdcp_caps.bcaps.bits.HDCP_CAPABLE;
551 case SIGNAL_TYPE_DVI_SINGLE_LINK:
552 case SIGNAL_TYPE_DVI_DUAL_LINK:
553 case SIGNAL_TYPE_HDMI_TYPE_A:
554 /* HDMI doesn't tell us its HDCP(1.4) capability, so assume to always be capable,
555 * we can poll for bksv but some displays have an issue with this. Since its so rare
556 * for a display to not be 1.4 capable, this assumtion is ok
566 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal)
571 case SIGNAL_TYPE_DISPLAY_PORT:
572 case SIGNAL_TYPE_DISPLAY_PORT_MST:
573 ret = (link->hdcp_caps.bcaps.bits.HDCP_CAPABLE &&
574 link->hdcp_caps.rx_caps.fields.byte0.hdcp_capable &&
575 (link->hdcp_caps.rx_caps.fields.version == 0x2)) ? 1 : 0;
577 case SIGNAL_TYPE_DVI_SINGLE_LINK:
578 case SIGNAL_TYPE_DVI_DUAL_LINK:
579 case SIGNAL_TYPE_HDMI_TYPE_A:
580 ret = (link->hdcp_caps.rx_caps.fields.version == 0x4) ? 1:0;
589 static void query_hdcp_capability(enum signal_type signal, struct dc_link *link)
591 struct hdcp_protection_message msg22;
592 struct hdcp_protection_message msg14;
594 memset(&msg22, 0, sizeof(struct hdcp_protection_message));
595 memset(&msg14, 0, sizeof(struct hdcp_protection_message));
596 memset(link->hdcp_caps.rx_caps.raw, 0,
597 sizeof(link->hdcp_caps.rx_caps.raw));
599 if ((link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
600 link->ddc->transaction_type ==
601 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) ||
602 link->connector_signal == SIGNAL_TYPE_EDP) {
603 msg22.data = link->hdcp_caps.rx_caps.raw;
604 msg22.length = sizeof(link->hdcp_caps.rx_caps.raw);
605 msg22.msg_id = HDCP_MESSAGE_ID_RX_CAPS;
607 msg22.data = &link->hdcp_caps.rx_caps.fields.version;
608 msg22.length = sizeof(link->hdcp_caps.rx_caps.fields.version);
609 msg22.msg_id = HDCP_MESSAGE_ID_HDCP2VERSION;
611 msg22.version = HDCP_VERSION_22;
612 msg22.link = HDCP_LINK_PRIMARY;
613 msg22.max_retries = 5;
614 dc_process_hdcp_msg(signal, link, &msg22);
616 if (signal == SIGNAL_TYPE_DISPLAY_PORT || signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
617 msg14.data = &link->hdcp_caps.bcaps.raw;
618 msg14.length = sizeof(link->hdcp_caps.bcaps.raw);
619 msg14.msg_id = HDCP_MESSAGE_ID_READ_BCAPS;
620 msg14.version = HDCP_VERSION_14;
621 msg14.link = HDCP_LINK_PRIMARY;
622 msg14.max_retries = 5;
624 dc_process_hdcp_msg(signal, link, &msg14);
630 static void read_current_link_settings_on_detect(struct dc_link *link)
632 union lane_count_set lane_count_set = { {0} };
634 uint8_t link_rate_set;
635 uint32_t read_dpcd_retry_cnt = 10;
636 enum dc_status status = DC_ERROR_UNEXPECTED;
638 union max_down_spread max_down_spread = { {0} };
640 // Read DPCD 00101h to find out the number of lanes currently set
641 for (i = 0; i < read_dpcd_retry_cnt; i++) {
642 status = core_link_read_dpcd(link,
645 sizeof(lane_count_set));
646 /* First DPCD read after VDD ON can fail if the particular board
647 * does not have HPD pin wired correctly. So if DPCD read fails,
648 * which it should never happen, retry a few times. Target worst
649 * case scenario of 80 ms.
651 if (status == DC_OK) {
652 link->cur_link_settings.lane_count =
653 lane_count_set.bits.LANE_COUNT_SET;
660 // Read DPCD 00100h to find if standard link rates are set
661 core_link_read_dpcd(link, DP_LINK_BW_SET,
662 &link_bw_set, sizeof(link_bw_set));
664 if (link_bw_set == 0) {
665 if (link->connector_signal == SIGNAL_TYPE_EDP) {
666 /* If standard link rates are not being used,
667 * Read DPCD 00115h to find the edp link rate set used
669 core_link_read_dpcd(link, DP_LINK_RATE_SET,
670 &link_rate_set, sizeof(link_rate_set));
672 // edp_supported_link_rates_count = 0 for DP
673 if (link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
674 link->cur_link_settings.link_rate =
675 link->dpcd_caps.edp_supported_link_rates[link_rate_set];
676 link->cur_link_settings.link_rate_set = link_rate_set;
677 link->cur_link_settings.use_link_rate_set = true;
680 // Link Rate not found. Seamless boot may not work.
684 link->cur_link_settings.link_rate = link_bw_set;
685 link->cur_link_settings.use_link_rate_set = false;
687 // Read DPCD 00003h to find the max down spread.
688 core_link_read_dpcd(link, DP_MAX_DOWNSPREAD,
689 &max_down_spread.raw, sizeof(max_down_spread));
690 link->cur_link_settings.link_spread =
691 max_down_spread.bits.MAX_DOWN_SPREAD ?
692 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
695 static bool detect_dp(struct dc_link *link,
696 struct display_sink_capability *sink_caps,
697 bool *converter_disable_audio,
698 struct audio_support *audio_support,
699 enum dc_detect_reason reason)
703 sink_caps->signal = link_detect_sink(link, reason);
704 sink_caps->transaction_type =
705 get_ddc_transaction_type(sink_caps->signal);
707 if (sink_caps->transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
708 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
709 if (!detect_dp_sink_caps(link))
711 if (is_mst_supported(link)) {
712 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
713 link->type = dc_connection_mst_branch;
715 dal_ddc_service_set_transaction_type(link->ddc,
716 sink_caps->transaction_type);
718 #if defined(CONFIG_DRM_AMD_DC_HDCP)
719 /* In case of fallback to SST when topology discovery below fails
720 * HDCP caps will be querried again later by the upper layer (caller
721 * of this function). */
722 query_hdcp_capability(SIGNAL_TYPE_DISPLAY_PORT_MST, link);
725 * This call will initiate MST topology discovery. Which
726 * will detect MST ports and add new DRM connector DRM
727 * framework. Then read EDID via remote i2c over aux. In
728 * the end, will notify DRM detect result and save EDID
729 * into DRM framework.
731 * .detect is called by .fill_modes.
732 * .fill_modes is called by user mode ioctl
733 * DRM_IOCTL_MODE_GETCONNECTOR.
735 * .get_modes is called by .fill_modes.
737 * call .get_modes, AMDGPU DM implementation will create
738 * new dc_sink and add to dc_link. For long HPD plug
739 * in/out, MST has its own handle.
741 * Therefore, just after dc_create, link->sink is not
742 * created for MST until user mode app calls
743 * DRM_IOCTL_MODE_GETCONNECTOR.
745 * Need check ->sink usages in case ->sink = NULL
746 * TODO: s3 resume check
748 if (reason == DETECT_REASON_BOOT)
751 dm_helpers_dp_update_branch_info(link->ctx, link);
753 if (!dm_helpers_dp_mst_start_top_mgr(link->ctx,
755 /* MST not supported */
756 link->type = dc_connection_single;
757 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
761 if (link->type != dc_connection_mst_branch &&
762 is_dp_active_dongle(link)) {
763 /* DP active dongles */
764 link->type = dc_connection_active_dongle;
765 if (!link->dpcd_caps.sink_count.bits.SINK_COUNT) {
767 * active dongle unplug processing for short irq
769 link_disconnect_sink(link);
773 if (link->dpcd_caps.dongle_type !=
774 DISPLAY_DONGLE_DP_HDMI_CONVERTER)
775 *converter_disable_audio = true;
778 /* DP passive dongles */
779 sink_caps->signal = dp_passive_dongle_detection(link->ddc,
782 link->dpcd_caps.dongle_type = sink_caps->dongle_type;
788 static bool is_same_edid(struct dc_edid *old_edid, struct dc_edid *new_edid)
790 if (old_edid->length != new_edid->length)
793 if (new_edid->length == 0)
796 return (memcmp(old_edid->raw_edid,
797 new_edid->raw_edid, new_edid->length) == 0);
800 static bool wait_for_entering_dp_alt_mode(struct dc_link *link)
803 * something is terribly wrong if time out is > 200ms. (5Hz)
804 * 500 microseconds * 400 tries us 200 ms
806 unsigned int sleep_time_in_microseconds = 500;
807 unsigned int tries_allowed = 400;
809 unsigned long long enter_timestamp;
810 unsigned long long finish_timestamp;
811 unsigned long long time_taken_in_ns;
814 DC_LOGGER_INIT(link->ctx->logger);
816 if (!link->link_enc->funcs->is_in_alt_mode)
819 is_in_alt_mode = link->link_enc->funcs->is_in_alt_mode(link->link_enc);
820 DC_LOG_WARNING("DP Alt mode state on HPD: %d\n", is_in_alt_mode);
825 enter_timestamp = dm_get_timestamp(link->ctx);
827 for (tries_taken = 0; tries_taken < tries_allowed; tries_taken++) {
828 udelay(sleep_time_in_microseconds);
829 /* ask the link if alt mode is enabled, if so return ok */
830 if (link->link_enc->funcs->is_in_alt_mode(link->link_enc)) {
831 finish_timestamp = dm_get_timestamp(link->ctx);
833 dm_get_elapse_time_in_ns(link->ctx,
836 DC_LOG_WARNING("Alt mode entered finished after %llu ms\n",
837 div_u64(time_taken_in_ns, 1000000));
841 finish_timestamp = dm_get_timestamp(link->ctx);
842 time_taken_in_ns = dm_get_elapse_time_in_ns(link->ctx, finish_timestamp,
844 DC_LOG_WARNING("Alt mode has timed out after %llu ms\n",
845 div_u64(time_taken_in_ns, 1000000));
850 * dc_link_detect() - Detect if a sink is attached to a given link
852 * link->local_sink is created or destroyed as needed.
854 * This does not create remote sinks but will trigger DM
855 * to start MST detection if a branch is detected.
857 static bool dc_link_detect_helper(struct dc_link *link,
858 enum dc_detect_reason reason)
860 struct dc_sink_init_data sink_init_data = { 0 };
861 struct display_sink_capability sink_caps = { 0 };
863 bool converter_disable_audio = false;
864 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
865 bool same_edid = false;
866 enum dc_edid_status edid_status;
867 struct dc_context *dc_ctx = link->ctx;
868 struct dc_sink *sink = NULL;
869 struct dc_sink *prev_sink = NULL;
870 struct dpcd_caps prev_dpcd_caps;
871 bool same_dpcd = true;
872 enum dc_connection_type new_connection_type = dc_connection_none;
873 enum dc_connection_type pre_connection_type = dc_connection_none;
874 bool perform_dp_seamless_boot = false;
875 const uint32_t post_oui_delay = 30; // 30ms
877 DC_LOGGER_INIT(link->ctx->logger);
879 if (dc_is_virtual_signal(link->connector_signal))
882 if ((link->connector_signal == SIGNAL_TYPE_LVDS ||
883 link->connector_signal == SIGNAL_TYPE_EDP) &&
885 // need to re-write OUI and brightness in resume case
886 if (link->connector_signal == SIGNAL_TYPE_EDP) {
887 dpcd_set_source_specific_data(link);
888 msleep(post_oui_delay);
889 dc_link_set_default_brightness_aux(link);
896 if (!dc_link_detect_sink(link, &new_connection_type)) {
901 prev_sink = link->local_sink;
903 dc_sink_retain(prev_sink);
904 memcpy(&prev_dpcd_caps, &link->dpcd_caps, sizeof(struct dpcd_caps));
907 link_disconnect_sink(link);
908 if (new_connection_type != dc_connection_none) {
909 pre_connection_type = link->type;
910 link->type = new_connection_type;
911 link->link_state_valid = false;
913 /* From Disconnected-to-Connected. */
914 switch (link->connector_signal) {
915 case SIGNAL_TYPE_HDMI_TYPE_A: {
916 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
917 if (aud_support->hdmi_audio_native)
918 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A;
920 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
924 case SIGNAL_TYPE_DVI_SINGLE_LINK: {
925 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
926 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
930 case SIGNAL_TYPE_DVI_DUAL_LINK: {
931 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
932 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK;
936 case SIGNAL_TYPE_LVDS: {
937 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
938 sink_caps.signal = SIGNAL_TYPE_LVDS;
942 case SIGNAL_TYPE_EDP: {
943 read_current_link_settings_on_detect(link);
945 detect_edp_sink_caps(link);
946 read_current_link_settings_on_detect(link);
947 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
948 sink_caps.signal = SIGNAL_TYPE_EDP;
952 case SIGNAL_TYPE_DISPLAY_PORT: {
953 /* wa HPD high coming too early*/
954 if (link->link_enc->features.flags.bits.DP_IS_USB_C == 1) {
955 /* if alt mode times out, return false */
956 if (!wait_for_entering_dp_alt_mode(link))
960 if (!detect_dp(link, &sink_caps,
961 &converter_disable_audio,
962 aud_support, reason)) {
964 dc_sink_release(prev_sink);
968 // Check if dpcp block is the same
970 if (memcmp(&link->dpcd_caps, &prev_dpcd_caps,
971 sizeof(struct dpcd_caps)))
974 /* Active dongle downstream unplug*/
975 if (link->type == dc_connection_active_dongle &&
976 link->dpcd_caps.sink_count.bits.SINK_COUNT == 0) {
978 /* Downstream unplug */
979 dc_sink_release(prev_sink);
983 // link switch from MST to non-MST stop topology manager
984 if (pre_connection_type == dc_connection_mst_branch &&
985 link->type != dc_connection_mst_branch) {
986 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
989 if (link->type == dc_connection_mst_branch) {
990 LINK_INFO("link=%d, mst branch is now Connected\n",
992 /* Need to setup mst link_cap struct here
993 * otherwise dc_link_detect() will leave mst link_cap
994 * empty which leads to allocate_mst_payload() has "0"
995 * pbn_per_slot value leading to exception on dc_fixpt_div()
997 dp_verify_mst_link_cap(link);
1000 dc_sink_release(prev_sink);
1004 // For seamless boot, to skip verify link cap, we read UEFI settings and set them as verified.
1005 if (reason == DETECT_REASON_BOOT &&
1006 !dc_ctx->dc->config.power_down_display_on_boot &&
1007 link->link_status.link_active)
1008 perform_dp_seamless_boot = true;
1010 if (perform_dp_seamless_boot) {
1011 read_current_link_settings_on_detect(link);
1012 link->verified_link_cap = link->reported_link_cap;
1019 DC_ERROR("Invalid connector type! signal:%d\n",
1020 link->connector_signal);
1022 dc_sink_release(prev_sink);
1026 if (link->dpcd_caps.sink_count.bits.SINK_COUNT)
1027 link->dpcd_sink_count =
1028 link->dpcd_caps.sink_count.bits.SINK_COUNT;
1030 link->dpcd_sink_count = 1;
1032 dal_ddc_service_set_transaction_type(link->ddc,
1033 sink_caps.transaction_type);
1036 dal_ddc_service_is_in_aux_transaction_mode(link->ddc);
1038 sink_init_data.link = link;
1039 sink_init_data.sink_signal = sink_caps.signal;
1041 sink = dc_sink_create(&sink_init_data);
1043 DC_ERROR("Failed to create sink!\n");
1045 dc_sink_release(prev_sink);
1049 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock;
1050 sink->converter_disable_audio = converter_disable_audio;
1052 /* dc_sink_create returns a new reference */
1053 link->local_sink = sink;
1055 edid_status = dm_helpers_read_local_edid(link->ctx,
1058 switch (edid_status) {
1059 case EDID_BAD_CHECKSUM:
1060 DC_LOG_ERROR("EDID checksum invalid.\n");
1062 case EDID_NO_RESPONSE:
1063 DC_LOG_ERROR("No EDID read.\n");
1065 * Abort detection for non-DP connectors if we have
1068 * DP needs to report as connected if HDP is high
1069 * even if we have no EDID in order to go to
1072 if (dc_is_hdmi_signal(link->connector_signal) ||
1073 dc_is_dvi_signal(link->connector_signal)) {
1075 dc_sink_release(prev_sink);
1084 // Check if edid is the same
1086 (edid_status == EDID_THE_SAME || edid_status == EDID_OK))
1087 same_edid = is_same_edid(&prev_sink->dc_edid,
1090 if (sink->edid_caps.panel_patch.skip_scdc_overwrite)
1091 link->ctx->dc->debug.hdmi20_disable = true;
1093 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
1094 sink_caps.transaction_type ==
1095 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
1097 * TODO debug why Dell 2413 doesn't like
1098 * two link trainings
1100 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1101 query_hdcp_capability(sink->sink_signal, link);
1104 // verify link cap for SST non-seamless boot
1105 if (!perform_dp_seamless_boot)
1106 dp_verify_link_cap_with_retries(link,
1107 &link->reported_link_cap,
1108 LINK_TRAINING_MAX_VERIFY_RETRY);
1110 // If edid is the same, then discard new sink and revert back to original sink
1112 link_disconnect_remap(prev_sink, link);
1116 #if defined(CONFIG_DRM_AMD_DC_HDCP)
1117 query_hdcp_capability(sink->sink_signal, link);
1121 /* HDMI-DVI Dongle */
1122 if (sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A &&
1123 !sink->edid_caps.edid_hdmi)
1124 sink->sink_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1126 /* Connectivity log: detection */
1127 for (i = 0; i < sink->dc_edid.length / DC_EDID_BLOCK_SIZE; i++) {
1128 CONN_DATA_DETECT(link,
1129 &sink->dc_edid.raw_edid[i * DC_EDID_BLOCK_SIZE],
1131 "%s: [Block %d] ", sink->edid_caps.display_name, i);
1134 DC_LOG_DETECTION_EDID_PARSER("%s: "
1135 "manufacturer_id = %X, "
1137 "serial_number = %X, "
1138 "manufacture_week = %d, "
1139 "manufacture_year = %d, "
1140 "display_name = %s, "
1141 "speaker_flag = %d, "
1142 "audio_mode_count = %d\n",
1144 sink->edid_caps.manufacturer_id,
1145 sink->edid_caps.product_id,
1146 sink->edid_caps.serial_number,
1147 sink->edid_caps.manufacture_week,
1148 sink->edid_caps.manufacture_year,
1149 sink->edid_caps.display_name,
1150 sink->edid_caps.speaker_flags,
1151 sink->edid_caps.audio_mode_count);
1153 for (i = 0; i < sink->edid_caps.audio_mode_count; i++) {
1154 DC_LOG_DETECTION_EDID_PARSER("%s: mode number = %d, "
1155 "format_code = %d, "
1156 "channel_count = %d, "
1157 "sample_rate = %d, "
1158 "sample_size = %d\n",
1161 sink->edid_caps.audio_modes[i].format_code,
1162 sink->edid_caps.audio_modes[i].channel_count,
1163 sink->edid_caps.audio_modes[i].sample_rate,
1164 sink->edid_caps.audio_modes[i].sample_size);
1167 /* From Connected-to-Disconnected. */
1168 if (link->type == dc_connection_mst_branch) {
1169 LINK_INFO("link=%d, mst branch is now Disconnected\n",
1172 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
1174 link->mst_stream_alloc_table.stream_count = 0;
1175 memset(link->mst_stream_alloc_table.stream_allocations,
1177 sizeof(link->mst_stream_alloc_table.stream_allocations));
1180 link->type = dc_connection_none;
1181 sink_caps.signal = SIGNAL_TYPE_NONE;
1182 /* When we unplug a passive DP-HDMI dongle connection, dongle_max_pix_clk
1183 * is not cleared. If we emulate a DP signal on this connection, it thinks
1184 * the dongle is still there and limits the number of modes we can emulate.
1185 * Clear dongle_max_pix_clk on disconnect to fix this
1187 link->dongle_max_pix_clk = 0;
1190 LINK_INFO("link=%d, dc_sink_in=%p is now %s prev_sink=%p dpcd same=%d edid same=%d\n",
1191 link->link_index, sink,
1192 (sink_caps.signal ==
1193 SIGNAL_TYPE_NONE ? "Disconnected" : "Connected"),
1194 prev_sink, same_dpcd, same_edid);
1197 dc_sink_release(prev_sink);
1202 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
1204 const struct dc *dc = link->dc;
1207 /* get out of low power state */
1208 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
1210 ret = dc_link_detect_helper(link, reason);
1212 /* Go back to power optimized state */
1213 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
1218 bool dc_link_get_hpd_state(struct dc_link *dc_link)
1222 dal_gpio_lock_pin(dc_link->hpd_gpio);
1223 dal_gpio_get_value(dc_link->hpd_gpio, &state);
1224 dal_gpio_unlock_pin(dc_link->hpd_gpio);
1229 static enum hpd_source_id get_hpd_line(struct dc_link *link)
1232 enum hpd_source_id hpd_id = HPD_SOURCEID_UNKNOWN;
1234 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1235 link->ctx->gpio_service);
1238 switch (dal_irq_get_source(hpd)) {
1239 case DC_IRQ_SOURCE_HPD1:
1240 hpd_id = HPD_SOURCEID1;
1242 case DC_IRQ_SOURCE_HPD2:
1243 hpd_id = HPD_SOURCEID2;
1245 case DC_IRQ_SOURCE_HPD3:
1246 hpd_id = HPD_SOURCEID3;
1248 case DC_IRQ_SOURCE_HPD4:
1249 hpd_id = HPD_SOURCEID4;
1251 case DC_IRQ_SOURCE_HPD5:
1252 hpd_id = HPD_SOURCEID5;
1254 case DC_IRQ_SOURCE_HPD6:
1255 hpd_id = HPD_SOURCEID6;
1258 BREAK_TO_DEBUGGER();
1262 dal_gpio_destroy_irq(&hpd);
1268 static enum channel_id get_ddc_line(struct dc_link *link)
1271 enum channel_id channel = CHANNEL_ID_UNKNOWN;
1273 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
1276 switch (dal_ddc_get_line(ddc)) {
1277 case GPIO_DDC_LINE_DDC1:
1278 channel = CHANNEL_ID_DDC1;
1280 case GPIO_DDC_LINE_DDC2:
1281 channel = CHANNEL_ID_DDC2;
1283 case GPIO_DDC_LINE_DDC3:
1284 channel = CHANNEL_ID_DDC3;
1286 case GPIO_DDC_LINE_DDC4:
1287 channel = CHANNEL_ID_DDC4;
1289 case GPIO_DDC_LINE_DDC5:
1290 channel = CHANNEL_ID_DDC5;
1292 case GPIO_DDC_LINE_DDC6:
1293 channel = CHANNEL_ID_DDC6;
1295 case GPIO_DDC_LINE_DDC_VGA:
1296 channel = CHANNEL_ID_DDC_VGA;
1298 case GPIO_DDC_LINE_I2C_PAD:
1299 channel = CHANNEL_ID_I2C_PAD;
1302 BREAK_TO_DEBUGGER();
1310 static enum transmitter translate_encoder_to_transmitter(struct graphics_object_id encoder)
1312 switch (encoder.id) {
1313 case ENCODER_ID_INTERNAL_UNIPHY:
1314 switch (encoder.enum_id) {
1316 return TRANSMITTER_UNIPHY_A;
1318 return TRANSMITTER_UNIPHY_B;
1320 return TRANSMITTER_UNKNOWN;
1323 case ENCODER_ID_INTERNAL_UNIPHY1:
1324 switch (encoder.enum_id) {
1326 return TRANSMITTER_UNIPHY_C;
1328 return TRANSMITTER_UNIPHY_D;
1330 return TRANSMITTER_UNKNOWN;
1333 case ENCODER_ID_INTERNAL_UNIPHY2:
1334 switch (encoder.enum_id) {
1336 return TRANSMITTER_UNIPHY_E;
1338 return TRANSMITTER_UNIPHY_F;
1340 return TRANSMITTER_UNKNOWN;
1343 case ENCODER_ID_INTERNAL_UNIPHY3:
1344 switch (encoder.enum_id) {
1346 return TRANSMITTER_UNIPHY_G;
1348 return TRANSMITTER_UNKNOWN;
1351 case ENCODER_ID_EXTERNAL_NUTMEG:
1352 switch (encoder.enum_id) {
1354 return TRANSMITTER_NUTMEG_CRT;
1356 return TRANSMITTER_UNKNOWN;
1359 case ENCODER_ID_EXTERNAL_TRAVIS:
1360 switch (encoder.enum_id) {
1362 return TRANSMITTER_TRAVIS_CRT;
1364 return TRANSMITTER_TRAVIS_LCD;
1366 return TRANSMITTER_UNKNOWN;
1370 return TRANSMITTER_UNKNOWN;
1374 static bool dc_link_construct(struct dc_link *link,
1375 const struct link_init_data *init_params)
1378 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1379 struct dc_context *dc_ctx = init_params->ctx;
1380 struct encoder_init_data enc_init_data = { 0 };
1381 struct panel_cntl_init_data panel_cntl_init_data = { 0 };
1382 struct integrated_info *info;
1383 struct dc_bios *bios = init_params->dc->ctx->dc_bios;
1384 const struct dc_vbios_funcs *bp_funcs = bios->funcs;
1385 struct bp_disp_connector_caps_info disp_connect_caps_info = { 0 };
1387 DC_LOGGER_INIT(dc_ctx->logger);
1389 info = kzalloc(sizeof(*info), GFP_KERNEL);
1393 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1394 link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
1396 link->link_status.dpcd_caps = &link->dpcd_caps;
1398 link->dc = init_params->dc;
1400 link->link_index = init_params->link_index;
1402 memset(&link->preferred_training_settings, 0,
1403 sizeof(struct dc_link_training_overrides));
1404 memset(&link->preferred_link_setting, 0,
1405 sizeof(struct dc_link_settings));
1408 bios->funcs->get_connector_id(bios, init_params->connector_index);
1410 DC_LOG_DC("BIOS object table - link_id: %d", link->link_id.id);
1412 if (bios->funcs->get_disp_connector_caps_info) {
1413 bios->funcs->get_disp_connector_caps_info(bios, link->link_id, &disp_connect_caps_info);
1414 link->is_internal_display = disp_connect_caps_info.INTERNAL_DISPLAY;
1415 DC_LOG_DC("BIOS object table - is_internal_display: %d", link->is_internal_display);
1418 if (link->link_id.type != OBJECT_TYPE_CONNECTOR) {
1419 dm_output_to_console("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d! type %d expected %d\n",
1420 __func__, init_params->connector_index,
1421 link->link_id.type, OBJECT_TYPE_CONNECTOR);
1425 if (link->dc->res_pool->funcs->link_init)
1426 link->dc->res_pool->funcs->link_init(link);
1428 link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id,
1429 link->ctx->gpio_service);
1431 if (link->hpd_gpio) {
1432 dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
1433 dal_gpio_unlock_pin(link->hpd_gpio);
1434 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
1436 DC_LOG_DC("BIOS object table - hpd_gpio id: %d", link->hpd_gpio->id);
1437 DC_LOG_DC("BIOS object table - hpd_gpio en: %d", link->hpd_gpio->en);
1440 switch (link->link_id.id) {
1441 case CONNECTOR_ID_HDMI_TYPE_A:
1442 link->connector_signal = SIGNAL_TYPE_HDMI_TYPE_A;
1445 case CONNECTOR_ID_SINGLE_LINK_DVID:
1446 case CONNECTOR_ID_SINGLE_LINK_DVII:
1447 link->connector_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1449 case CONNECTOR_ID_DUAL_LINK_DVID:
1450 case CONNECTOR_ID_DUAL_LINK_DVII:
1451 link->connector_signal = SIGNAL_TYPE_DVI_DUAL_LINK;
1453 case CONNECTOR_ID_DISPLAY_PORT:
1454 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1457 link->irq_source_hpd_rx =
1458 dal_irq_get_rx_source(link->hpd_gpio);
1461 case CONNECTOR_ID_EDP:
1462 link->connector_signal = SIGNAL_TYPE_EDP;
1464 if (link->hpd_gpio) {
1465 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1466 link->irq_source_hpd_rx =
1467 dal_irq_get_rx_source(link->hpd_gpio);
1471 case CONNECTOR_ID_LVDS:
1472 link->connector_signal = SIGNAL_TYPE_LVDS;
1475 DC_LOG_WARNING("Unsupported Connector type:%d!\n",
1480 /* TODO: #DAL3 Implement id to str function.*/
1481 LINK_INFO("Connector[%d] description:"
1483 init_params->connector_index,
1484 link->connector_signal);
1486 ddc_service_init_data.ctx = link->ctx;
1487 ddc_service_init_data.id = link->link_id;
1488 ddc_service_init_data.link = link;
1489 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1492 DC_ERROR("Failed to create ddc_service!\n");
1493 goto ddc_create_fail;
1496 if (!link->ddc->ddc_pin) {
1497 DC_ERROR("Failed to get I2C info for connector!\n");
1498 goto ddc_create_fail;
1502 dal_ddc_get_line(dal_ddc_service_get_ddc_pin(link->ddc));
1505 if (link->dc->res_pool->funcs->panel_cntl_create &&
1506 (link->link_id.id == CONNECTOR_ID_EDP ||
1507 link->link_id.id == CONNECTOR_ID_LVDS)) {
1508 panel_cntl_init_data.ctx = dc_ctx;
1509 panel_cntl_init_data.inst = 0;
1511 link->dc->res_pool->funcs->panel_cntl_create(
1512 &panel_cntl_init_data);
1514 if (link->panel_cntl == NULL) {
1515 DC_ERROR("Failed to create link panel_cntl!\n");
1516 goto panel_cntl_create_fail;
1520 enc_init_data.ctx = dc_ctx;
1521 bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0,
1522 &enc_init_data.encoder);
1523 enc_init_data.connector = link->link_id;
1524 enc_init_data.channel = get_ddc_line(link);
1525 enc_init_data.hpd_source = get_hpd_line(link);
1527 link->hpd_src = enc_init_data.hpd_source;
1529 enc_init_data.transmitter =
1530 translate_encoder_to_transmitter(enc_init_data.encoder);
1532 link->dc->res_pool->funcs->link_enc_create(&enc_init_data);
1534 if (!link->link_enc) {
1535 DC_ERROR("Failed to create link encoder!\n");
1536 goto link_enc_create_fail;
1539 DC_LOG_DC("BIOS object table - DP_IS_USB_C: %d", link->link_enc->features.flags.bits.DP_IS_USB_C);
1541 /* Update link encoder tracking variables. These are used for the dynamic
1542 * assignment of link encoders to streams.
1544 link->dc->res_pool->link_encoders[link->link_enc->preferred_engine] = link->link_enc;
1545 link->dc->res_pool->dig_link_enc_count++;
1547 link->link_enc_hw_inst = link->link_enc->transmitter;
1549 for (i = 0; i < 4; i++) {
1550 if (bp_funcs->get_device_tag(dc_ctx->dc_bios,
1552 &link->device_tag) != BP_RESULT_OK) {
1553 DC_ERROR("Failed to find device tag!\n");
1554 goto device_tag_fail;
1557 /* Look for device tag that matches connector signal,
1558 * CRT for rgb, LCD for other supported signal tyes
1560 if (!bp_funcs->is_device_id_supported(dc_ctx->dc_bios,
1561 link->device_tag.dev_id))
1563 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_CRT &&
1564 link->connector_signal != SIGNAL_TYPE_RGB)
1566 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_LCD &&
1567 link->connector_signal == SIGNAL_TYPE_RGB)
1570 DC_LOG_DC("BIOS object table - device_tag.acpi_device: %d", link->device_tag.acpi_device);
1571 DC_LOG_DC("BIOS object table - device_tag.dev_id.device_type: %d", link->device_tag.dev_id.device_type);
1572 DC_LOG_DC("BIOS object table - device_tag.dev_id.enum_id: %d", link->device_tag.dev_id.enum_id);
1576 if (bios->integrated_info)
1577 memcpy(info, bios->integrated_info, sizeof(*info));
1579 /* Look for channel mapping corresponding to connector and device tag */
1580 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
1581 struct external_display_path *path =
1582 &info->ext_disp_conn_info.path[i];
1584 if (path->device_connector_id.enum_id == link->link_id.enum_id &&
1585 path->device_connector_id.id == link->link_id.id &&
1586 path->device_connector_id.type == link->link_id.type) {
1587 if (link->device_tag.acpi_device != 0 &&
1588 path->device_acpi_enum == link->device_tag.acpi_device) {
1589 link->ddi_channel_mapping = path->channel_mapping;
1590 link->chip_caps = path->caps;
1591 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1592 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1593 } else if (path->device_tag ==
1594 link->device_tag.dev_id.raw_device_tag) {
1595 link->ddi_channel_mapping = path->channel_mapping;
1596 link->chip_caps = path->caps;
1597 DC_LOG_DC("BIOS object table - ddi_channel_mapping: 0x%04X", link->ddi_channel_mapping.raw);
1598 DC_LOG_DC("BIOS object table - chip_caps: %d", link->chip_caps);
1604 if (bios->funcs->get_atom_dc_golden_table)
1605 bios->funcs->get_atom_dc_golden_table(bios);
1608 * TODO check if GPIO programmed correctly
1610 * If GPIO isn't programmed correctly HPD might not rise or drain
1611 * fast enough, leading to bounces.
1613 program_hpd_filter(link);
1615 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
1617 DC_LOG_DC("BIOS object table - %s finished successfully.\n", __func__);
1620 link->link_enc->funcs->destroy(&link->link_enc);
1621 link_enc_create_fail:
1622 if (link->panel_cntl != NULL)
1623 link->panel_cntl->funcs->destroy(&link->panel_cntl);
1624 panel_cntl_create_fail:
1625 dal_ddc_service_destroy(&link->ddc);
1629 if (link->hpd_gpio) {
1630 dal_gpio_destroy_irq(&link->hpd_gpio);
1631 link->hpd_gpio = NULL;
1634 DC_LOG_DC("BIOS object table - %s failed.\n", __func__);
1640 /*******************************************************************************
1642 ******************************************************************************/
1643 struct dc_link *link_create(const struct link_init_data *init_params)
1645 struct dc_link *link =
1646 kzalloc(sizeof(*link), GFP_KERNEL);
1651 if (false == dc_link_construct(link, init_params))
1652 goto construct_fail;
1663 void link_destroy(struct dc_link **link)
1665 dc_link_destruct(*link);
1670 static void enable_stream_features(struct pipe_ctx *pipe_ctx)
1672 struct dc_stream_state *stream = pipe_ctx->stream;
1673 struct dc_link *link = stream->link;
1674 union down_spread_ctrl old_downspread;
1675 union down_spread_ctrl new_downspread;
1677 core_link_read_dpcd(link, DP_DOWNSPREAD_CTRL,
1678 &old_downspread.raw, sizeof(old_downspread));
1680 new_downspread.raw = old_downspread.raw;
1682 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1683 (stream->ignore_msa_timing_param) ? 1 : 0;
1685 if (new_downspread.raw != old_downspread.raw) {
1686 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
1687 &new_downspread.raw, sizeof(new_downspread));
1691 static enum dc_status enable_link_dp(struct dc_state *state,
1692 struct pipe_ctx *pipe_ctx)
1694 struct dc_stream_state *stream = pipe_ctx->stream;
1695 enum dc_status status;
1696 bool skip_video_pattern;
1697 struct dc_link *link = stream->link;
1698 struct dc_link_settings link_settings = {0};
1701 bool apply_seamless_boot_optimization = false;
1702 uint32_t bl_oled_enable_delay = 50; // in ms
1703 const uint32_t post_oui_delay = 30; // 30ms
1705 // check for seamless boot
1706 for (i = 0; i < state->stream_count; i++) {
1707 if (state->streams[i]->apply_seamless_boot_optimization) {
1708 apply_seamless_boot_optimization = true;
1713 /* get link settings for video mode timing */
1714 decide_link_settings(stream, &link_settings);
1716 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
1717 /*in case it is not on*/
1718 link->dc->hwss.edp_power_control(link, true);
1719 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
1722 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
1723 link_settings.link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
1724 if (state->clk_mgr && !apply_seamless_boot_optimization)
1725 state->clk_mgr->funcs->update_clocks(state->clk_mgr,
1728 // during mode switch we do DP_SET_POWER off then on, and OUI is lost
1729 dpcd_set_source_specific_data(link);
1730 if (link->dpcd_sink_ext_caps.raw != 0)
1731 msleep(post_oui_delay);
1733 skip_video_pattern = true;
1735 if (link_settings.link_rate == LINK_RATE_LOW)
1736 skip_video_pattern = false;
1738 if (perform_link_training_with_retries(&link_settings,
1740 LINK_TRAINING_ATTEMPTS,
1742 pipe_ctx->stream->signal)) {
1743 link->cur_link_settings = link_settings;
1746 status = DC_FAIL_DP_LINK_TRAINING;
1749 if (link->preferred_training_settings.fec_enable)
1750 fec_enable = *link->preferred_training_settings.fec_enable;
1754 dp_set_fec_enable(link, fec_enable);
1756 // during mode set we do DP_SET_POWER off then on, aux writes are lost
1757 if (link->dpcd_sink_ext_caps.bits.oled == 1 ||
1758 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1 ||
1759 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1) {
1760 dc_link_set_default_brightness_aux(link); // TODO: use cached if known
1761 if (link->dpcd_sink_ext_caps.bits.oled == 1)
1762 msleep(bl_oled_enable_delay);
1763 dc_link_backlight_enable_aux(link, true);
1769 static enum dc_status enable_link_edp(
1770 struct dc_state *state,
1771 struct pipe_ctx *pipe_ctx)
1773 enum dc_status status;
1775 status = enable_link_dp(state, pipe_ctx);
1780 static enum dc_status enable_link_dp_mst(
1781 struct dc_state *state,
1782 struct pipe_ctx *pipe_ctx)
1784 struct dc_link *link = pipe_ctx->stream->link;
1786 /* sink signal type after MST branch is MST. Multiple MST sinks
1787 * share one link. Link DP PHY is enable or training only once.
1789 if (link->link_status.link_active)
1792 /* clear payload table */
1793 dm_helpers_dp_mst_clear_payload_allocation_table(link->ctx, link);
1795 /* to make sure the pending down rep can be processed
1796 * before enabling the link
1798 dm_helpers_dp_mst_poll_pending_down_reply(link->ctx, link);
1800 /* set the sink to MST mode before enabling the link */
1801 dp_enable_mst_on_sink(link, true);
1803 return enable_link_dp(state, pipe_ctx);
1806 static bool get_ext_hdmi_settings(struct pipe_ctx *pipe_ctx,
1807 enum engine_id eng_id,
1808 struct ext_hdmi_settings *settings)
1810 bool result = false;
1812 struct integrated_info *integrated_info =
1813 pipe_ctx->stream->ctx->dc_bios->integrated_info;
1815 if (integrated_info == NULL)
1819 * Get retimer settings from sbios for passing SI eye test for DCE11
1820 * The setting values are varied based on board revision and port id
1821 * Therefore the setting values of each ports is passed by sbios.
1824 // Check if current bios contains ext Hdmi settings
1825 if (integrated_info->gpu_cap_info & 0x20) {
1827 case ENGINE_ID_DIGA:
1828 settings->slv_addr = integrated_info->dp0_ext_hdmi_slv_addr;
1829 settings->reg_num = integrated_info->dp0_ext_hdmi_6g_reg_num;
1830 settings->reg_num_6g = integrated_info->dp0_ext_hdmi_6g_reg_num;
1831 memmove(settings->reg_settings,
1832 integrated_info->dp0_ext_hdmi_reg_settings,
1833 sizeof(integrated_info->dp0_ext_hdmi_reg_settings));
1834 memmove(settings->reg_settings_6g,
1835 integrated_info->dp0_ext_hdmi_6g_reg_settings,
1836 sizeof(integrated_info->dp0_ext_hdmi_6g_reg_settings));
1839 case ENGINE_ID_DIGB:
1840 settings->slv_addr = integrated_info->dp1_ext_hdmi_slv_addr;
1841 settings->reg_num = integrated_info->dp1_ext_hdmi_6g_reg_num;
1842 settings->reg_num_6g = integrated_info->dp1_ext_hdmi_6g_reg_num;
1843 memmove(settings->reg_settings,
1844 integrated_info->dp1_ext_hdmi_reg_settings,
1845 sizeof(integrated_info->dp1_ext_hdmi_reg_settings));
1846 memmove(settings->reg_settings_6g,
1847 integrated_info->dp1_ext_hdmi_6g_reg_settings,
1848 sizeof(integrated_info->dp1_ext_hdmi_6g_reg_settings));
1851 case ENGINE_ID_DIGC:
1852 settings->slv_addr = integrated_info->dp2_ext_hdmi_slv_addr;
1853 settings->reg_num = integrated_info->dp2_ext_hdmi_6g_reg_num;
1854 settings->reg_num_6g = integrated_info->dp2_ext_hdmi_6g_reg_num;
1855 memmove(settings->reg_settings,
1856 integrated_info->dp2_ext_hdmi_reg_settings,
1857 sizeof(integrated_info->dp2_ext_hdmi_reg_settings));
1858 memmove(settings->reg_settings_6g,
1859 integrated_info->dp2_ext_hdmi_6g_reg_settings,
1860 sizeof(integrated_info->dp2_ext_hdmi_6g_reg_settings));
1863 case ENGINE_ID_DIGD:
1864 settings->slv_addr = integrated_info->dp3_ext_hdmi_slv_addr;
1865 settings->reg_num = integrated_info->dp3_ext_hdmi_6g_reg_num;
1866 settings->reg_num_6g = integrated_info->dp3_ext_hdmi_6g_reg_num;
1867 memmove(settings->reg_settings,
1868 integrated_info->dp3_ext_hdmi_reg_settings,
1869 sizeof(integrated_info->dp3_ext_hdmi_reg_settings));
1870 memmove(settings->reg_settings_6g,
1871 integrated_info->dp3_ext_hdmi_6g_reg_settings,
1872 sizeof(integrated_info->dp3_ext_hdmi_6g_reg_settings));
1879 if (result == true) {
1880 // Validate settings from bios integrated info table
1881 if (settings->slv_addr == 0)
1883 if (settings->reg_num > 9)
1885 if (settings->reg_num_6g > 3)
1888 for (i = 0; i < settings->reg_num; i++) {
1889 if (settings->reg_settings[i].i2c_reg_index > 0x20)
1893 for (i = 0; i < settings->reg_num_6g; i++) {
1894 if (settings->reg_settings_6g[i].i2c_reg_index > 0x20)
1903 static bool i2c_write(struct pipe_ctx *pipe_ctx,
1904 uint8_t address, uint8_t *buffer, uint32_t length)
1906 struct i2c_command cmd = {0};
1907 struct i2c_payload payload = {0};
1909 memset(&payload, 0, sizeof(payload));
1910 memset(&cmd, 0, sizeof(cmd));
1912 cmd.number_of_payloads = 1;
1913 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
1914 cmd.speed = pipe_ctx->stream->ctx->dc->caps.i2c_speed_in_khz;
1916 payload.address = address;
1917 payload.data = buffer;
1918 payload.length = length;
1919 payload.write = true;
1920 cmd.payloads = &payload;
1922 if (dm_helpers_submit_i2c(pipe_ctx->stream->ctx,
1923 pipe_ctx->stream->link, &cmd))
1929 static void write_i2c_retimer_setting(
1930 struct pipe_ctx *pipe_ctx,
1932 bool is_over_340mhz,
1933 struct ext_hdmi_settings *settings)
1935 uint8_t slave_address = (settings->slv_addr >> 1);
1937 const uint8_t apply_rx_tx_change = 0x4;
1938 uint8_t offset = 0xA;
1941 bool i2c_success = false;
1942 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1944 memset(&buffer, 0, sizeof(buffer));
1946 /* Start Ext-Hdmi programming*/
1948 for (i = 0; i < settings->reg_num; i++) {
1949 /* Apply 3G settings */
1950 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
1952 buffer[0] = settings->reg_settings[i].i2c_reg_index;
1953 buffer[1] = settings->reg_settings[i].i2c_reg_val;
1954 i2c_success = i2c_write(pipe_ctx, slave_address,
1955 buffer, sizeof(buffer));
1956 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1957 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
1958 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1961 goto i2c_write_fail;
1963 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1964 * needs to be set to 1 on every 0xA-0xC write.
1966 if (settings->reg_settings[i].i2c_reg_index == 0xA ||
1967 settings->reg_settings[i].i2c_reg_index == 0xB ||
1968 settings->reg_settings[i].i2c_reg_index == 0xC) {
1970 /* Query current value from offset 0xA */
1971 if (settings->reg_settings[i].i2c_reg_index == 0xA)
1972 value = settings->reg_settings[i].i2c_reg_val;
1975 dal_ddc_service_query_ddc_data(
1976 pipe_ctx->stream->link->ddc,
1977 slave_address, &offset, 1, &value, 1);
1979 goto i2c_write_fail;
1983 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1984 buffer[1] = value | apply_rx_tx_change;
1985 i2c_success = i2c_write(pipe_ctx, slave_address,
1986 buffer, sizeof(buffer));
1987 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1988 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1989 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1991 goto i2c_write_fail;
1996 /* Apply 3G settings */
1997 if (is_over_340mhz) {
1998 for (i = 0; i < settings->reg_num_6g; i++) {
1999 /* Apply 3G settings */
2000 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
2002 buffer[0] = settings->reg_settings_6g[i].i2c_reg_index;
2003 buffer[1] = settings->reg_settings_6g[i].i2c_reg_val;
2004 i2c_success = i2c_write(pipe_ctx, slave_address,
2005 buffer, sizeof(buffer));
2006 RETIMER_REDRIVER_INFO("above 340Mhz: retimer write to slave_address = 0x%x,\
2007 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2008 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2011 goto i2c_write_fail;
2013 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
2014 * needs to be set to 1 on every 0xA-0xC write.
2016 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA ||
2017 settings->reg_settings_6g[i].i2c_reg_index == 0xB ||
2018 settings->reg_settings_6g[i].i2c_reg_index == 0xC) {
2020 /* Query current value from offset 0xA */
2021 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA)
2022 value = settings->reg_settings_6g[i].i2c_reg_val;
2025 dal_ddc_service_query_ddc_data(
2026 pipe_ctx->stream->link->ddc,
2027 slave_address, &offset, 1, &value, 1);
2029 goto i2c_write_fail;
2033 /* Set APPLY_RX_TX_CHANGE bit to 1 */
2034 buffer[1] = value | apply_rx_tx_change;
2035 i2c_success = i2c_write(pipe_ctx, slave_address,
2036 buffer, sizeof(buffer));
2037 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2038 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2039 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2041 goto i2c_write_fail;
2048 /* Program additional settings if using 640x480 resolution */
2050 /* Write offset 0xFF to 0x01 */
2053 i2c_success = i2c_write(pipe_ctx, slave_address,
2054 buffer, sizeof(buffer));
2055 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2056 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2057 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2059 goto i2c_write_fail;
2061 /* Write offset 0x00 to 0x23 */
2064 i2c_success = i2c_write(pipe_ctx, slave_address,
2065 buffer, sizeof(buffer));
2066 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2067 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2068 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2070 goto i2c_write_fail;
2072 /* Write offset 0xff to 0x00 */
2075 i2c_success = i2c_write(pipe_ctx, slave_address,
2076 buffer, sizeof(buffer));
2077 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
2078 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2079 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2081 goto i2c_write_fail;
2088 DC_LOG_DEBUG("Set retimer failed");
2091 static void write_i2c_default_retimer_setting(
2092 struct pipe_ctx *pipe_ctx,
2094 bool is_over_340mhz)
2096 uint8_t slave_address = (0xBA >> 1);
2098 bool i2c_success = false;
2099 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2101 memset(&buffer, 0, sizeof(buffer));
2103 /* Program Slave Address for tuning single integrity */
2104 /* Write offset 0x0A to 0x13 */
2107 i2c_success = i2c_write(pipe_ctx, slave_address,
2108 buffer, sizeof(buffer));
2109 RETIMER_REDRIVER_INFO("retimer writes default setting to slave_address = 0x%x,\
2110 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2111 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2113 goto i2c_write_fail;
2115 /* Write offset 0x0A to 0x17 */
2118 i2c_success = i2c_write(pipe_ctx, slave_address,
2119 buffer, sizeof(buffer));
2120 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2121 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2122 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2124 goto i2c_write_fail;
2126 /* Write offset 0x0B to 0xDA or 0xD8 */
2128 buffer[1] = is_over_340mhz ? 0xDA : 0xD8;
2129 i2c_success = i2c_write(pipe_ctx, slave_address,
2130 buffer, sizeof(buffer));
2131 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2132 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2133 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2135 goto i2c_write_fail;
2137 /* Write offset 0x0A to 0x17 */
2140 i2c_success = i2c_write(pipe_ctx, slave_address,
2141 buffer, sizeof(buffer));
2142 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2143 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2144 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2146 goto i2c_write_fail;
2148 /* Write offset 0x0C to 0x1D or 0x91 */
2150 buffer[1] = is_over_340mhz ? 0x1D : 0x91;
2151 i2c_success = i2c_write(pipe_ctx, slave_address,
2152 buffer, sizeof(buffer));
2153 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2154 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2155 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2157 goto i2c_write_fail;
2159 /* Write offset 0x0A to 0x17 */
2162 i2c_success = i2c_write(pipe_ctx, slave_address,
2163 buffer, sizeof(buffer));
2164 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2165 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2166 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2168 goto i2c_write_fail;
2172 /* Program additional settings if using 640x480 resolution */
2174 /* Write offset 0xFF to 0x01 */
2177 i2c_success = i2c_write(pipe_ctx, slave_address,
2178 buffer, sizeof(buffer));
2179 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2180 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2181 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2183 goto i2c_write_fail;
2185 /* Write offset 0x00 to 0x23 */
2188 i2c_success = i2c_write(pipe_ctx, slave_address,
2189 buffer, sizeof(buffer));
2190 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2191 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2192 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2194 goto i2c_write_fail;
2196 /* Write offset 0xff to 0x00 */
2199 i2c_success = i2c_write(pipe_ctx, slave_address,
2200 buffer, sizeof(buffer));
2201 RETIMER_REDRIVER_INFO("retimer write default setting to slave_addr = 0x%x,\
2202 offset = 0x%x, reg_val= 0x%x, i2c_success = %d end here\n",
2203 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2205 goto i2c_write_fail;
2211 DC_LOG_DEBUG("Set default retimer failed");
2214 static void write_i2c_redriver_setting(
2215 struct pipe_ctx *pipe_ctx,
2216 bool is_over_340mhz)
2218 uint8_t slave_address = (0xF0 >> 1);
2220 bool i2c_success = false;
2221 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2223 memset(&buffer, 0, sizeof(buffer));
2225 // Program Slave Address for tuning single integrity
2229 buffer[6] = is_over_340mhz ? 0x4E : 0x4A;
2231 i2c_success = i2c_write(pipe_ctx, slave_address,
2232 buffer, sizeof(buffer));
2233 RETIMER_REDRIVER_INFO("redriver write 0 to all 16 reg offset expect following:\n\
2234 \t slave_addr = 0x%x, offset[3] = 0x%x, offset[4] = 0x%x,\
2235 offset[5] = 0x%x,offset[6] is_over_340mhz = 0x%x,\
2236 i2c_success = %d\n",
2237 slave_address, buffer[3], buffer[4], buffer[5], buffer[6], i2c_success?1:0);
2240 DC_LOG_DEBUG("Set redriver failed");
2243 static void disable_link(struct dc_link *link, enum signal_type signal)
2246 * TODO: implement call for dp_set_hw_test_pattern
2247 * it is needed for compliance testing
2250 /* Here we need to specify that encoder output settings
2251 * need to be calculated as for the set mode,
2252 * it will lead to querying dynamic link capabilities
2253 * which should be done before enable output
2256 if (dc_is_dp_signal(signal)) {
2258 if (dc_is_dp_sst_signal(signal))
2259 dp_disable_link_phy(link, signal);
2261 dp_disable_link_phy_mst(link, signal);
2263 if (dc_is_dp_sst_signal(signal) ||
2264 link->mst_stream_alloc_table.stream_count == 0) {
2265 dp_set_fec_enable(link, false);
2266 dp_set_fec_ready(link, false);
2269 if (signal != SIGNAL_TYPE_VIRTUAL)
2270 link->link_enc->funcs->disable_output(link->link_enc, signal);
2273 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2274 /* MST disable link only when no stream use the link */
2275 if (link->mst_stream_alloc_table.stream_count <= 0)
2276 link->link_status.link_active = false;
2278 link->link_status.link_active = false;
2282 static void enable_link_hdmi(struct pipe_ctx *pipe_ctx)
2284 struct dc_stream_state *stream = pipe_ctx->stream;
2285 struct dc_link *link = stream->link;
2286 enum dc_color_depth display_color_depth;
2287 enum engine_id eng_id;
2288 struct ext_hdmi_settings settings = {0};
2289 bool is_over_340mhz = false;
2290 bool is_vga_mode = (stream->timing.h_addressable == 640)
2291 && (stream->timing.v_addressable == 480);
2293 if (stream->phy_pix_clk == 0)
2294 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2295 if (stream->phy_pix_clk > 340000)
2296 is_over_340mhz = true;
2298 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2299 unsigned short masked_chip_caps = pipe_ctx->stream->link->chip_caps &
2300 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
2301 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
2302 /* DP159, Retimer settings */
2303 eng_id = pipe_ctx->stream_res.stream_enc->id;
2305 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings)) {
2306 write_i2c_retimer_setting(pipe_ctx,
2307 is_vga_mode, is_over_340mhz, &settings);
2309 write_i2c_default_retimer_setting(pipe_ctx,
2310 is_vga_mode, is_over_340mhz);
2312 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
2313 /* PI3EQX1204, Redriver settings */
2314 write_i2c_redriver_setting(pipe_ctx, is_over_340mhz);
2318 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2319 dal_ddc_service_write_scdc_data(
2321 stream->phy_pix_clk,
2322 stream->timing.flags.LTE_340MCSC_SCRAMBLE);
2324 memset(&stream->link->cur_link_settings, 0,
2325 sizeof(struct dc_link_settings));
2327 display_color_depth = stream->timing.display_color_depth;
2328 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
2329 display_color_depth = COLOR_DEPTH_888;
2331 link->link_enc->funcs->enable_tmds_output(
2333 pipe_ctx->clock_source->id,
2334 display_color_depth,
2335 pipe_ctx->stream->signal,
2336 stream->phy_pix_clk);
2338 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2339 dal_ddc_service_read_scdc_data(link->ddc);
2342 static void enable_link_lvds(struct pipe_ctx *pipe_ctx)
2344 struct dc_stream_state *stream = pipe_ctx->stream;
2345 struct dc_link *link = stream->link;
2347 if (stream->phy_pix_clk == 0)
2348 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2350 memset(&stream->link->cur_link_settings, 0,
2351 sizeof(struct dc_link_settings));
2353 link->link_enc->funcs->enable_lvds_output(
2355 pipe_ctx->clock_source->id,
2356 stream->phy_pix_clk);
2360 /****************************enable_link***********************************/
2361 static enum dc_status enable_link(
2362 struct dc_state *state,
2363 struct pipe_ctx *pipe_ctx)
2365 enum dc_status status = DC_ERROR_UNEXPECTED;
2366 struct dc_stream_state *stream = pipe_ctx->stream;
2367 struct dc_link *link = stream->link;
2369 /* There's some scenarios where driver is unloaded with display
2370 * still enabled. When driver is reloaded, it may cause a display
2371 * to not light up if there is a mismatch between old and new
2372 * link settings. Need to call disable first before enabling at
2373 * new link settings.
2375 if (link->link_status.link_active) {
2376 disable_link(link, pipe_ctx->stream->signal);
2379 switch (pipe_ctx->stream->signal) {
2380 case SIGNAL_TYPE_DISPLAY_PORT:
2381 status = enable_link_dp(state, pipe_ctx);
2383 case SIGNAL_TYPE_EDP:
2384 status = enable_link_edp(state, pipe_ctx);
2386 case SIGNAL_TYPE_DISPLAY_PORT_MST:
2387 status = enable_link_dp_mst(state, pipe_ctx);
2390 case SIGNAL_TYPE_DVI_SINGLE_LINK:
2391 case SIGNAL_TYPE_DVI_DUAL_LINK:
2392 case SIGNAL_TYPE_HDMI_TYPE_A:
2393 enable_link_hdmi(pipe_ctx);
2396 case SIGNAL_TYPE_LVDS:
2397 enable_link_lvds(pipe_ctx);
2400 case SIGNAL_TYPE_VIRTUAL:
2407 if (status == DC_OK)
2408 pipe_ctx->stream->link->link_status.link_active = true;
2413 static uint32_t get_timing_pixel_clock_100hz(const struct dc_crtc_timing *timing)
2416 uint32_t pxl_clk = timing->pix_clk_100hz;
2418 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
2420 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
2421 pxl_clk = pxl_clk * 2 / 3;
2423 if (timing->display_color_depth == COLOR_DEPTH_101010)
2424 pxl_clk = pxl_clk * 10 / 8;
2425 else if (timing->display_color_depth == COLOR_DEPTH_121212)
2426 pxl_clk = pxl_clk * 12 / 8;
2431 static bool dp_active_dongle_validate_timing(
2432 const struct dc_crtc_timing *timing,
2433 const struct dpcd_caps *dpcd_caps)
2435 const struct dc_dongle_caps *dongle_caps = &dpcd_caps->dongle_caps;
2437 switch (dpcd_caps->dongle_type) {
2438 case DISPLAY_DONGLE_DP_VGA_CONVERTER:
2439 case DISPLAY_DONGLE_DP_DVI_CONVERTER:
2440 case DISPLAY_DONGLE_DP_DVI_DONGLE:
2441 if (timing->pixel_encoding == PIXEL_ENCODING_RGB)
2449 if (dpcd_caps->dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER ||
2450 dongle_caps->extendedCapValid == false)
2453 /* Check Pixel Encoding */
2454 switch (timing->pixel_encoding) {
2455 case PIXEL_ENCODING_RGB:
2456 case PIXEL_ENCODING_YCBCR444:
2458 case PIXEL_ENCODING_YCBCR422:
2459 if (!dongle_caps->is_dp_hdmi_ycbcr422_pass_through)
2462 case PIXEL_ENCODING_YCBCR420:
2463 if (!dongle_caps->is_dp_hdmi_ycbcr420_pass_through)
2467 /* Invalid Pixel Encoding*/
2471 switch (timing->display_color_depth) {
2472 case COLOR_DEPTH_666:
2473 case COLOR_DEPTH_888:
2474 /*888 and 666 should always be supported*/
2476 case COLOR_DEPTH_101010:
2477 if (dongle_caps->dp_hdmi_max_bpc < 10)
2480 case COLOR_DEPTH_121212:
2481 if (dongle_caps->dp_hdmi_max_bpc < 12)
2484 case COLOR_DEPTH_141414:
2485 case COLOR_DEPTH_161616:
2487 /* These color depths are currently not supported */
2491 if (get_timing_pixel_clock_100hz(timing) > (dongle_caps->dp_hdmi_max_pixel_clk_in_khz * 10))
2497 enum dc_status dc_link_validate_mode_timing(
2498 const struct dc_stream_state *stream,
2499 struct dc_link *link,
2500 const struct dc_crtc_timing *timing)
2502 uint32_t max_pix_clk = stream->link->dongle_max_pix_clk * 10;
2503 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
2505 /* A hack to avoid failing any modes for EDID override feature on
2506 * topology change such as lower quality cable for DP or different dongle
2508 if (link->remote_sinks[0] && link->remote_sinks[0]->sink_signal == SIGNAL_TYPE_VIRTUAL)
2511 /* Passive Dongle */
2512 if (max_pix_clk != 0 && get_timing_pixel_clock_100hz(timing) > max_pix_clk)
2513 return DC_EXCEED_DONGLE_CAP;
2516 if (!dp_active_dongle_validate_timing(timing, dpcd_caps))
2517 return DC_EXCEED_DONGLE_CAP;
2519 switch (stream->signal) {
2520 case SIGNAL_TYPE_EDP:
2521 case SIGNAL_TYPE_DISPLAY_PORT:
2522 if (!dp_validate_mode_timing(
2525 return DC_NO_DP_LINK_BANDWIDTH;
2535 static struct abm *get_abm_from_stream_res(const struct dc_link *link)
2538 struct dc *dc = NULL;
2539 struct abm *abm = NULL;
2541 if (!link || !link->ctx)
2546 for (i = 0; i < MAX_PIPES; i++) {
2547 struct pipe_ctx pipe_ctx = dc->current_state->res_ctx.pipe_ctx[i];
2548 struct dc_stream_state *stream = pipe_ctx.stream;
2550 if (stream && stream->link == link) {
2551 abm = pipe_ctx.stream_res.abm;
2558 int dc_link_get_backlight_level(const struct dc_link *link)
2561 struct abm *abm = get_abm_from_stream_res(link);
2563 if (abm == NULL || abm->funcs->get_current_backlight == NULL)
2564 return DC_ERROR_UNEXPECTED;
2566 return (int) abm->funcs->get_current_backlight(abm);
2569 int dc_link_get_target_backlight_pwm(const struct dc_link *link)
2571 struct abm *abm = get_abm_from_stream_res(link);
2573 if (abm == NULL || abm->funcs->get_target_backlight == NULL)
2574 return DC_ERROR_UNEXPECTED;
2576 return (int) abm->funcs->get_target_backlight(abm);
2579 static struct pipe_ctx *get_pipe_from_link(const struct dc_link *link)
2582 struct dc *dc = link->ctx->dc;
2583 struct pipe_ctx *pipe_ctx = NULL;
2585 for (i = 0; i < MAX_PIPES; i++) {
2586 if (dc->current_state->res_ctx.pipe_ctx[i].stream) {
2587 if (dc->current_state->res_ctx.pipe_ctx[i].stream->link == link) {
2588 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2597 bool dc_link_set_backlight_level(const struct dc_link *link,
2598 uint32_t backlight_pwm_u16_16,
2599 uint32_t frame_ramp)
2601 struct dc *dc = link->ctx->dc;
2603 DC_LOGGER_INIT(link->ctx->logger);
2604 DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n",
2605 backlight_pwm_u16_16, backlight_pwm_u16_16);
2607 if (dc_is_embedded_signal(link->connector_signal)) {
2608 struct pipe_ctx *pipe_ctx = get_pipe_from_link(link);
2611 /* Disable brightness ramping when the display is blanked
2612 * as it can hang the DMCU
2614 if (pipe_ctx->plane_state == NULL)
2621 dc->hwss.set_backlight_level(
2623 backlight_pwm_u16_16,
2629 bool dc_link_set_psr_allow_active(struct dc_link *link, bool allow_active,
2630 bool wait, bool force_static)
2632 struct dc *dc = link->ctx->dc;
2633 struct dmcu *dmcu = dc->res_pool->dmcu;
2634 struct dmub_psr *psr = dc->res_pool->psr;
2636 if (psr == NULL && force_static)
2639 link->psr_settings.psr_allow_active = allow_active;
2641 if (psr != NULL && link->psr_settings.psr_feature_enabled) {
2642 if (force_static && psr->funcs->psr_force_static)
2643 psr->funcs->psr_force_static(psr);
2644 psr->funcs->psr_enable(psr, allow_active, wait);
2645 } else if ((dmcu != NULL && dmcu->funcs->is_dmcu_initialized(dmcu)) && link->psr_settings.psr_feature_enabled)
2646 dmcu->funcs->set_psr_enable(dmcu, allow_active, wait);
2653 bool dc_link_get_psr_state(const struct dc_link *link, enum dc_psr_state *state)
2655 struct dc *dc = link->ctx->dc;
2656 struct dmcu *dmcu = dc->res_pool->dmcu;
2657 struct dmub_psr *psr = dc->res_pool->psr;
2659 if (psr != NULL && link->psr_settings.psr_feature_enabled)
2660 psr->funcs->psr_get_state(psr, state);
2661 else if (dmcu != NULL && link->psr_settings.psr_feature_enabled)
2662 dmcu->funcs->get_psr_state(dmcu, state);
2667 static inline enum physical_phy_id
2668 transmitter_to_phy_id(enum transmitter transmitter_value)
2670 switch (transmitter_value) {
2671 case TRANSMITTER_UNIPHY_A:
2673 case TRANSMITTER_UNIPHY_B:
2675 case TRANSMITTER_UNIPHY_C:
2677 case TRANSMITTER_UNIPHY_D:
2679 case TRANSMITTER_UNIPHY_E:
2681 case TRANSMITTER_UNIPHY_F:
2683 case TRANSMITTER_NUTMEG_CRT:
2685 case TRANSMITTER_TRAVIS_CRT:
2687 case TRANSMITTER_TRAVIS_LCD:
2689 case TRANSMITTER_UNIPHY_G:
2691 case TRANSMITTER_COUNT:
2693 case TRANSMITTER_UNKNOWN:
2694 return PHYLD_UNKNOWN;
2696 WARN_ONCE(1, "Unknown transmitter value %d\n",
2698 return PHYLD_UNKNOWN;
2702 bool dc_link_setup_psr(struct dc_link *link,
2703 const struct dc_stream_state *stream, struct psr_config *psr_config,
2704 struct psr_context *psr_context)
2708 struct dmub_psr *psr;
2710 /* updateSinkPsrDpcdConfig*/
2711 union dpcd_psr_configuration psr_configuration;
2713 psr_context->controllerId = CONTROLLER_ID_UNDEFINED;
2719 dmcu = dc->res_pool->dmcu;
2720 psr = dc->res_pool->psr;
2726 memset(&psr_configuration, 0, sizeof(psr_configuration));
2728 psr_configuration.bits.ENABLE = 1;
2729 psr_configuration.bits.CRC_VERIFICATION = 1;
2730 psr_configuration.bits.FRAME_CAPTURE_INDICATION =
2731 psr_config->psr_frame_capture_indication_req;
2733 /* Check for PSR v2*/
2734 if (psr_config->psr_version == 0x2) {
2735 /* For PSR v2 selective update.
2736 * Indicates whether sink should start capturing
2737 * immediately following active scan line,
2738 * or starting with the 2nd active scan line.
2740 psr_configuration.bits.LINE_CAPTURE_INDICATION = 0;
2741 /*For PSR v2, determines whether Sink should generate
2742 * IRQ_HPD when CRC mismatch is detected.
2744 psr_configuration.bits.IRQ_HPD_WITH_CRC_ERROR = 1;
2747 dm_helpers_dp_write_dpcd(
2751 &psr_configuration.raw,
2752 sizeof(psr_configuration.raw));
2754 psr_context->channel = link->ddc->ddc_pin->hw_info.ddc_channel;
2755 psr_context->transmitterId = link->link_enc->transmitter;
2756 psr_context->engineId = link->link_enc->preferred_engine;
2758 for (i = 0; i < MAX_PIPES; i++) {
2759 if (dc->current_state->res_ctx.pipe_ctx[i].stream
2761 /* dmcu -1 for all controller id values,
2764 psr_context->controllerId =
2765 dc->current_state->res_ctx.
2766 pipe_ctx[i].stream_res.tg->inst + 1;
2771 /* Hardcoded for now. Can be Pcie or Uniphy (or Unknown)*/
2772 psr_context->phyType = PHY_TYPE_UNIPHY;
2773 /*PhyId is associated with the transmitter id*/
2774 psr_context->smuPhyId =
2775 transmitter_to_phy_id(link->link_enc->transmitter);
2777 psr_context->crtcTimingVerticalTotal = stream->timing.v_total;
2778 psr_context->vsync_rate_hz = div64_u64(div64_u64((stream->
2779 timing.pix_clk_100hz * 100),
2780 stream->timing.v_total),
2781 stream->timing.h_total);
2783 psr_context->psrSupportedDisplayConfig = true;
2784 psr_context->psrExitLinkTrainingRequired =
2785 psr_config->psr_exit_link_training_required;
2786 psr_context->sdpTransmitLineNumDeadline =
2787 psr_config->psr_sdp_transmit_line_num_deadline;
2788 psr_context->psrFrameCaptureIndicationReq =
2789 psr_config->psr_frame_capture_indication_req;
2791 psr_context->skipPsrWaitForPllLock = 0; /* only = 1 in KV */
2793 psr_context->numberOfControllers =
2794 link->dc->res_pool->timing_generator_count;
2796 psr_context->rfb_update_auto_en = true;
2798 /* 2 frames before enter PSR. */
2799 psr_context->timehyst_frames = 2;
2801 * (units in 100 lines, i.e. a value of 1 represents 100 lines)
2803 psr_context->hyst_lines = stream->timing.v_total / 2 / 100;
2804 psr_context->aux_repeats = 10;
2806 psr_context->psr_level.u32all = 0;
2808 #if defined(CONFIG_DRM_AMD_DC_DCN)
2809 /*skip power down the single pipe since it blocks the cstate*/
2810 if ((link->ctx->asic_id.chip_family == FAMILY_RV) &&
2811 ASICREV_IS_RAVEN(link->ctx->asic_id.hw_internal_rev))
2812 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
2815 /* SMU will perform additional powerdown sequence.
2816 * For unsupported ASICs, set psr_level flag to skip PSR
2817 * static screen notification to SMU.
2818 * (Always set for DAL2, did not check ASIC)
2820 psr_context->allow_smu_optimizations = psr_config->allow_smu_optimizations;
2821 psr_context->allow_multi_disp_optimizations = psr_config->allow_multi_disp_optimizations;
2823 /* Complete PSR entry before aborting to prevent intermittent
2824 * freezes on certain eDPs
2826 psr_context->psr_level.bits.DISABLE_PSR_ENTRY_ABORT = 1;
2828 /* Controls additional delay after remote frame capture before
2829 * continuing power down, default = 0
2831 psr_context->frame_delay = 0;
2834 link->psr_settings.psr_feature_enabled = psr->funcs->psr_copy_settings(psr, link, psr_context);
2836 link->psr_settings.psr_feature_enabled = dmcu->funcs->setup_psr(dmcu, link, psr_context);
2838 /* psr_enabled == 0 indicates setup_psr did not succeed, but this
2839 * should not happen since firmware should be running at this point
2841 if (link->psr_settings.psr_feature_enabled == 0)
2848 void dc_link_get_psr_residency(const struct dc_link *link, uint32_t *residency)
2850 struct dc *dc = link->ctx->dc;
2851 struct dmub_psr *psr = dc->res_pool->psr;
2853 // PSR residency measurements only supported on DMCUB
2854 if (psr != NULL && link->psr_settings.psr_feature_enabled)
2855 psr->funcs->psr_get_residency(psr, residency);
2860 const struct dc_link_status *dc_link_get_status(const struct dc_link *link)
2862 return &link->link_status;
2865 void core_link_resume(struct dc_link *link)
2867 if (link->connector_signal != SIGNAL_TYPE_VIRTUAL)
2868 program_hpd_filter(link);
2871 static struct fixed31_32 get_pbn_per_slot(struct dc_stream_state *stream)
2873 struct fixed31_32 mbytes_per_sec;
2874 uint32_t link_rate_in_mbytes_per_sec = dc_link_bandwidth_kbps(stream->link,
2875 &stream->link->cur_link_settings);
2876 link_rate_in_mbytes_per_sec /= 8000; /* Kbits to MBytes */
2878 mbytes_per_sec = dc_fixpt_from_int(link_rate_in_mbytes_per_sec);
2880 return dc_fixpt_div_int(mbytes_per_sec, 54);
2883 static struct fixed31_32 get_pbn_from_bw_in_kbps(uint64_t kbps)
2885 struct fixed31_32 peak_kbps;
2887 uint32_t denominator;
2890 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
2891 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
2892 * common multiplier to render an integer PBN for all link rate/lane
2893 * counts combinations
2895 * peak_kbps *= (1006/1000)
2896 * peak_kbps *= (64/54)
2897 * peak_kbps *= 8 convert to bytes
2900 numerator = 64 * PEAK_FACTOR_X1000;
2901 denominator = 54 * 8 * 1000 * 1000;
2903 peak_kbps = dc_fixpt_from_fraction(kbps, denominator);
2908 static struct fixed31_32 get_pbn_from_timing(struct pipe_ctx *pipe_ctx)
2912 kbps = dc_bandwidth_in_kbps_from_timing(&pipe_ctx->stream->timing);
2913 return get_pbn_from_bw_in_kbps(kbps);
2916 static void update_mst_stream_alloc_table(
2917 struct dc_link *link,
2918 struct stream_encoder *stream_enc,
2919 const struct dp_mst_stream_allocation_table *proposed_table)
2921 struct link_mst_stream_allocation work_table[MAX_CONTROLLER_NUM] = {
2923 struct link_mst_stream_allocation *dc_alloc;
2928 /* if DRM proposed_table has more than one new payload */
2929 ASSERT(proposed_table->stream_count -
2930 link->mst_stream_alloc_table.stream_count < 2);
2932 /* copy proposed_table to link, add stream encoder */
2933 for (i = 0; i < proposed_table->stream_count; i++) {
2935 for (j = 0; j < link->mst_stream_alloc_table.stream_count; j++) {
2937 &link->mst_stream_alloc_table.stream_allocations[j];
2939 if (dc_alloc->vcp_id ==
2940 proposed_table->stream_allocations[i].vcp_id) {
2942 work_table[i] = *dc_alloc;
2943 work_table[i].slot_count = proposed_table->stream_allocations[i].slot_count;
2944 break; /* exit j loop */
2949 if (j == link->mst_stream_alloc_table.stream_count) {
2950 work_table[i].vcp_id =
2951 proposed_table->stream_allocations[i].vcp_id;
2952 work_table[i].slot_count =
2953 proposed_table->stream_allocations[i].slot_count;
2954 work_table[i].stream_enc = stream_enc;
2958 /* update link->mst_stream_alloc_table with work_table */
2959 link->mst_stream_alloc_table.stream_count =
2960 proposed_table->stream_count;
2961 for (i = 0; i < MAX_CONTROLLER_NUM; i++)
2962 link->mst_stream_alloc_table.stream_allocations[i] =
2966 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
2967 * because stream_encoder is not exposed to dm
2969 enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx)
2971 struct dc_stream_state *stream = pipe_ctx->stream;
2972 struct dc_link *link = stream->link;
2973 struct link_encoder *link_encoder = link->link_enc;
2974 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
2975 struct dp_mst_stream_allocation_table proposed_table = {0};
2976 struct fixed31_32 avg_time_slots_per_mtp;
2977 struct fixed31_32 pbn;
2978 struct fixed31_32 pbn_per_slot;
2980 enum act_return_status ret;
2981 DC_LOGGER_INIT(link->ctx->logger);
2983 /* enable_link_dp_mst already check link->enabled_stream_count
2984 * and stream is in link->stream[]. This is called during set mode,
2985 * stream_enc is available.
2988 /* get calculate VC payload for stream: stream_alloc */
2989 if (dm_helpers_dp_mst_write_payload_allocation_table(
2994 update_mst_stream_alloc_table(
2995 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
2998 DC_LOG_WARNING("Failed to update"
2999 "MST allocation table for"
3001 pipe_ctx->pipe_idx);
3004 "stream_count: %d: \n ",
3006 link->mst_stream_alloc_table.stream_count);
3008 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3009 DC_LOG_MST("stream_enc[%d]: %p "
3010 "stream[%d].vcp_id: %d "
3011 "stream[%d].slot_count: %d\n",
3013 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3015 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3017 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3020 ASSERT(proposed_table.stream_count > 0);
3022 /* program DP source TX for payload */
3023 link_encoder->funcs->update_mst_stream_allocation_table(
3025 &link->mst_stream_alloc_table);
3027 /* send down message */
3028 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3032 if (ret != ACT_LINK_LOST) {
3033 dm_helpers_dp_mst_send_payload_allocation(
3039 /* slot X.Y for only current stream */
3040 pbn_per_slot = get_pbn_per_slot(stream);
3041 if (pbn_per_slot.value == 0) {
3042 DC_LOG_ERROR("Failure: pbn_per_slot==0 not allowed. Cannot continue, returning DC_UNSUPPORTED_VALUE.\n");
3043 return DC_UNSUPPORTED_VALUE;
3045 pbn = get_pbn_from_timing(pipe_ctx);
3046 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
3048 stream_encoder->funcs->set_throttled_vcp_size(
3050 avg_time_slots_per_mtp);
3056 static enum dc_status deallocate_mst_payload(struct pipe_ctx *pipe_ctx)
3058 struct dc_stream_state *stream = pipe_ctx->stream;
3059 struct dc_link *link = stream->link;
3060 struct link_encoder *link_encoder = link->link_enc;
3061 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
3062 struct dp_mst_stream_allocation_table proposed_table = {0};
3063 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
3065 bool mst_mode = (link->type == dc_connection_mst_branch);
3066 DC_LOGGER_INIT(link->ctx->logger);
3068 /* deallocate_mst_payload is called before disable link. When mode or
3069 * disable/enable monitor, new stream is created which is not in link
3070 * stream[] yet. For this, payload is not allocated yet, so de-alloc
3071 * should not done. For new mode set, map_resources will get engine
3072 * for new stream, so stream_enc->id should be validated until here.
3076 stream_encoder->funcs->set_throttled_vcp_size(
3078 avg_time_slots_per_mtp);
3080 /* TODO: which component is responsible for remove payload table? */
3082 if (dm_helpers_dp_mst_write_payload_allocation_table(
3088 update_mst_stream_alloc_table(
3089 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
3092 DC_LOG_WARNING("Failed to update"
3093 "MST allocation table for"
3095 pipe_ctx->pipe_idx);
3100 "stream_count: %d: ",
3102 link->mst_stream_alloc_table.stream_count);
3104 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
3105 DC_LOG_MST("stream_enc[%d]: %p "
3106 "stream[%d].vcp_id: %d "
3107 "stream[%d].slot_count: %d\n",
3109 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
3111 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
3113 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
3116 link_encoder->funcs->update_mst_stream_allocation_table(
3118 &link->mst_stream_alloc_table);
3121 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
3125 dm_helpers_dp_mst_send_payload_allocation(
3134 enum dc_status dc_link_reallocate_mst_payload(struct dc_link *link)
3137 struct pipe_ctx *pipe_ctx;
3139 // Clear all of MST payload then reallocate
3140 for (i = 0; i < MAX_PIPES; i++) {
3141 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
3143 /* driver enable split pipe for external monitors
3144 * we have to check pipe_ctx is split pipe or not
3145 * If it's split pipe, driver using top pipe to
3148 if (!pipe_ctx || pipe_ctx->top_pipe)
3151 if (pipe_ctx->stream && pipe_ctx->stream->link == link &&
3152 pipe_ctx->stream->dpms_off == false &&
3153 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3154 deallocate_mst_payload(pipe_ctx);
3158 for (i = 0; i < MAX_PIPES; i++) {
3159 pipe_ctx = &link->dc->current_state->res_ctx.pipe_ctx[i];
3161 if (!pipe_ctx || pipe_ctx->top_pipe)
3164 if (pipe_ctx->stream && pipe_ctx->stream->link == link &&
3165 pipe_ctx->stream->dpms_off == false &&
3166 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3167 /* enable/disable PHY will clear connection between BE and FE
3168 * need to restore it.
3170 link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc,
3171 pipe_ctx->stream_res.stream_enc->id, true);
3172 dc_link_allocate_mst_payload(pipe_ctx);
3179 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3180 static void update_psp_stream_config(struct pipe_ctx *pipe_ctx, bool dpms_off)
3182 struct cp_psp *cp_psp = &pipe_ctx->stream->ctx->cp_psp;
3183 if (cp_psp && cp_psp->funcs.update_stream_config) {
3184 struct cp_psp_stream_config config = {0};
3185 enum dp_panel_mode panel_mode =
3186 dp_get_panel_mode(pipe_ctx->stream->link);
3188 config.otg_inst = (uint8_t) pipe_ctx->stream_res.tg->inst;
3189 config.dig_fe = (uint8_t) pipe_ctx->stream_res.stream_enc->stream_enc_inst;
3190 config.dig_be = pipe_ctx->stream->link->link_enc_hw_inst;
3191 config.dpms_off = dpms_off;
3192 config.dm_stream_ctx = pipe_ctx->stream->dm_stream_context;
3193 config.assr_enabled = (panel_mode == DP_PANEL_MODE_EDP);
3194 config.mst_enabled = (pipe_ctx->stream->signal ==
3195 SIGNAL_TYPE_DISPLAY_PORT_MST);
3196 cp_psp->funcs.update_stream_config(cp_psp->handle, &config);
3201 void core_link_enable_stream(
3202 struct dc_state *state,
3203 struct pipe_ctx *pipe_ctx)
3205 struct dc *dc = pipe_ctx->stream->ctx->dc;
3206 struct dc_stream_state *stream = pipe_ctx->stream;
3207 enum dc_status status;
3208 #if defined(CONFIG_DRM_AMD_DC_DCN)
3209 enum otg_out_mux_dest otg_out_dest = OUT_MUX_DIO;
3211 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
3213 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
3214 dc_is_virtual_signal(pipe_ctx->stream->signal))
3217 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)) {
3218 stream->link->link_enc->funcs->setup(
3219 stream->link->link_enc,
3220 pipe_ctx->stream->signal);
3221 pipe_ctx->stream_res.stream_enc->funcs->setup_stereo_sync(
3222 pipe_ctx->stream_res.stream_enc,
3223 pipe_ctx->stream_res.tg->inst,
3224 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
3227 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3228 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
3229 pipe_ctx->stream_res.stream_enc,
3231 stream->output_color_space,
3232 stream->use_vsc_sdp_for_colorimetry,
3233 stream->link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
3235 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
3236 pipe_ctx->stream_res.stream_enc->funcs->hdmi_set_stream_attribute(
3237 pipe_ctx->stream_res.stream_enc,
3239 stream->phy_pix_clk,
3240 pipe_ctx->stream_res.audio != NULL);
3242 pipe_ctx->stream->link->link_state_valid = true;
3244 #if defined(CONFIG_DRM_AMD_DC_DCN)
3245 if (pipe_ctx->stream_res.tg->funcs->set_out_mux)
3246 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, otg_out_dest);
3249 if (dc_is_dvi_signal(pipe_ctx->stream->signal))
3250 pipe_ctx->stream_res.stream_enc->funcs->dvi_set_stream_attribute(
3251 pipe_ctx->stream_res.stream_enc,
3253 (pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
3256 if (dc_is_lvds_signal(pipe_ctx->stream->signal))
3257 pipe_ctx->stream_res.stream_enc->funcs->lvds_set_stream_attribute(
3258 pipe_ctx->stream_res.stream_enc,
3261 if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
3262 bool apply_edp_fast_boot_optimization =
3263 pipe_ctx->stream->apply_edp_fast_boot_optimization;
3265 pipe_ctx->stream->apply_edp_fast_boot_optimization = false;
3267 resource_build_info_frame(pipe_ctx);
3268 dc->hwss.update_info_frame(pipe_ctx);
3270 /* Do not touch link on seamless boot optimization. */
3271 if (pipe_ctx->stream->apply_seamless_boot_optimization) {
3272 pipe_ctx->stream->dpms_off = false;
3274 /* Still enable stream features & audio on seamless boot for DP external displays */
3275 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT) {
3276 enable_stream_features(pipe_ctx);
3277 if (pipe_ctx->stream_res.audio != NULL) {
3278 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
3279 dc->hwss.enable_audio_stream(pipe_ctx);
3283 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3284 update_psp_stream_config(pipe_ctx, false);
3289 /* eDP lit up by bios already, no need to enable again. */
3290 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
3291 apply_edp_fast_boot_optimization) {
3292 pipe_ctx->stream->dpms_off = false;
3293 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3294 update_psp_stream_config(pipe_ctx, false);
3299 if (pipe_ctx->stream->dpms_off)
3302 /* Have to setup DSC before DIG FE and BE are connected (which happens before the
3303 * link training). This is to make sure the bandwidth sent to DIG BE won't be
3304 * bigger than what the link and/or DIG BE can handle. VBID[6]/CompressedStream_flag
3305 * will be automatically set at a later time when the video is enabled
3306 * (DP_VID_STREAM_EN = 1).
3308 if (pipe_ctx->stream->timing.flags.DSC) {
3309 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3310 dc_is_virtual_signal(pipe_ctx->stream->signal))
3311 dp_set_dsc_enable(pipe_ctx, true);
3314 status = enable_link(state, pipe_ctx);
3316 if (status != DC_OK) {
3317 DC_LOG_WARNING("enabling link %u failed: %d\n",
3318 pipe_ctx->stream->link->link_index,
3321 /* Abort stream enable *unless* the failure was due to
3322 * DP link training - some DP monitors will recover and
3323 * show the stream anyway. But MST displays can't proceed
3324 * without link training.
3326 if (status != DC_FAIL_DP_LINK_TRAINING ||
3327 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3328 BREAK_TO_DEBUGGER();
3333 /* turn off otg test pattern if enable */
3334 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
3335 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
3336 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
3337 COLOR_DEPTH_UNDEFINED);
3339 /* This second call is needed to reconfigure the DIG
3340 * as a workaround for the incorrect value being applied
3341 * from transmitter control.
3343 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
3344 stream->link->link_enc->funcs->setup(
3345 stream->link->link_enc,
3346 pipe_ctx->stream->signal);
3348 dc->hwss.enable_stream(pipe_ctx);
3350 /* Set DPS PPS SDP (AKA "info frames") */
3351 if (pipe_ctx->stream->timing.flags.DSC) {
3352 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3353 dc_is_virtual_signal(pipe_ctx->stream->signal))
3354 dp_set_dsc_pps_sdp(pipe_ctx, true);
3357 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
3358 dc_link_allocate_mst_payload(pipe_ctx);
3360 dc->hwss.unblank_stream(pipe_ctx,
3361 &pipe_ctx->stream->link->cur_link_settings);
3363 if (stream->sink_patches.delay_ignore_msa > 0)
3364 msleep(stream->sink_patches.delay_ignore_msa);
3366 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3367 enable_stream_features(pipe_ctx);
3368 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3369 update_psp_stream_config(pipe_ctx, false);
3372 dc->hwss.enable_audio_stream(pipe_ctx);
3374 } else { // if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
3375 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3376 dc_is_virtual_signal(pipe_ctx->stream->signal))
3377 dp_set_dsc_enable(pipe_ctx, true);
3381 if (pipe_ctx->stream->signal == SIGNAL_TYPE_HDMI_TYPE_A) {
3382 core_link_set_avmute(pipe_ctx, false);
3386 void core_link_disable_stream(struct pipe_ctx *pipe_ctx)
3388 struct dc *dc = pipe_ctx->stream->ctx->dc;
3389 struct dc_stream_state *stream = pipe_ctx->stream;
3390 struct dc_link *link = stream->sink->link;
3392 if (!IS_DIAG_DC(dc->ctx->dce_environment) &&
3393 dc_is_virtual_signal(pipe_ctx->stream->signal))
3396 if (!pipe_ctx->stream->sink->edid_caps.panel_patch.skip_avmute) {
3397 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
3398 core_link_set_avmute(pipe_ctx, true);
3401 dc->hwss.disable_audio_stream(pipe_ctx);
3403 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3404 update_psp_stream_config(pipe_ctx, true);
3406 dc->hwss.blank_stream(pipe_ctx);
3408 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
3409 deallocate_mst_payload(pipe_ctx);
3411 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
3412 struct ext_hdmi_settings settings = {0};
3413 enum engine_id eng_id = pipe_ctx->stream_res.stream_enc->id;
3415 unsigned short masked_chip_caps = link->chip_caps &
3416 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
3417 //Need to inform that sink is going to use legacy HDMI mode.
3418 dal_ddc_service_write_scdc_data(
3420 165000,//vbios only handles 165Mhz.
3422 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
3423 /* DP159, Retimer settings */
3424 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings))
3425 write_i2c_retimer_setting(pipe_ctx,
3426 false, false, &settings);
3428 write_i2c_default_retimer_setting(pipe_ctx,
3430 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
3431 /* PI3EQX1204, Redriver settings */
3432 write_i2c_redriver_setting(pipe_ctx, false);
3436 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
3438 dc->hwss.disable_stream(pipe_ctx);
3440 if (pipe_ctx->stream->timing.flags.DSC) {
3441 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3442 dp_set_dsc_enable(pipe_ctx, false);
3446 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
3448 struct dc *dc = pipe_ctx->stream->ctx->dc;
3450 if (!dc_is_hdmi_signal(pipe_ctx->stream->signal))
3453 dc->hwss.set_avmute(pipe_ctx, enable);
3457 * dc_link_enable_hpd_filter:
3458 * If enable is true, programs HPD filter on associated HPD line using
3459 * delay_on_disconnect/delay_on_connect values dependent on
3460 * link->connector_signal
3462 * If enable is false, programs HPD filter on associated HPD line with no
3463 * delays on connect or disconnect
3465 * @link: pointer to the dc link
3466 * @enable: boolean specifying whether to enable hbd
3468 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
3473 link->is_hpd_filter_disabled = false;
3474 program_hpd_filter(link);
3476 link->is_hpd_filter_disabled = true;
3477 /* Obtain HPD handle */
3478 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
3483 /* Setup HPD filtering */
3484 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
3485 struct gpio_hpd_config config;
3487 config.delay_on_connect = 0;
3488 config.delay_on_disconnect = 0;
3490 dal_irq_setup_hpd_filter(hpd, &config);
3492 dal_gpio_close(hpd);
3494 ASSERT_CRITICAL(false);
3496 /* Release HPD handle */
3497 dal_gpio_destroy_irq(&hpd);
3501 uint32_t dc_bandwidth_in_kbps_from_timing(
3502 const struct dc_crtc_timing *timing)
3504 uint32_t bits_per_channel = 0;
3506 struct fixed31_32 link_bw_kbps;
3508 if (timing->flags.DSC) {
3509 link_bw_kbps = dc_fixpt_from_int(timing->pix_clk_100hz);
3510 link_bw_kbps = dc_fixpt_div_int(link_bw_kbps, 160);
3511 link_bw_kbps = dc_fixpt_mul_int(link_bw_kbps, timing->dsc_cfg.bits_per_pixel);
3512 kbps = dc_fixpt_ceil(link_bw_kbps);
3516 switch (timing->display_color_depth) {
3517 case COLOR_DEPTH_666:
3518 bits_per_channel = 6;
3520 case COLOR_DEPTH_888:
3521 bits_per_channel = 8;
3523 case COLOR_DEPTH_101010:
3524 bits_per_channel = 10;
3526 case COLOR_DEPTH_121212:
3527 bits_per_channel = 12;
3529 case COLOR_DEPTH_141414:
3530 bits_per_channel = 14;
3532 case COLOR_DEPTH_161616:
3533 bits_per_channel = 16;
3536 ASSERT(bits_per_channel != 0);
3537 bits_per_channel = 8;
3541 kbps = timing->pix_clk_100hz / 10;
3542 kbps *= bits_per_channel;
3544 if (timing->flags.Y_ONLY != 1) {
3545 /*Only YOnly make reduce bandwidth by 1/3 compares to RGB*/
3547 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
3549 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
3550 kbps = kbps * 2 / 3;
3557 void dc_link_set_drive_settings(struct dc *dc,
3558 struct link_training_settings *lt_settings,
3559 const struct dc_link *link)
3564 for (i = 0; i < dc->link_count; i++) {
3565 if (dc->links[i] == link)
3569 if (i >= dc->link_count)
3570 ASSERT_CRITICAL(false);
3572 dc_link_dp_set_drive_settings(dc->links[i], lt_settings);
3575 void dc_link_perform_link_training(struct dc *dc,
3576 struct dc_link_settings *link_setting,
3577 bool skip_video_pattern)
3581 for (i = 0; i < dc->link_count; i++)
3582 dc_link_dp_perform_link_training(
3585 skip_video_pattern);
3588 void dc_link_set_preferred_link_settings(struct dc *dc,
3589 struct dc_link_settings *link_setting,
3590 struct dc_link *link)
3593 struct pipe_ctx *pipe;
3594 struct dc_stream_state *link_stream;
3595 struct dc_link_settings store_settings = *link_setting;
3597 link->preferred_link_setting = store_settings;
3599 /* Retrain with preferred link settings only relevant for
3601 * Check for non-DP signal or if passive dongle present
3603 if (!dc_is_dp_signal(link->connector_signal) ||
3604 link->dongle_max_pix_clk > 0)
3607 for (i = 0; i < MAX_PIPES; i++) {
3608 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
3609 if (pipe->stream && pipe->stream->link) {
3610 if (pipe->stream->link == link) {
3611 link_stream = pipe->stream;
3617 /* Stream not found */
3621 /* Cannot retrain link if backend is off */
3622 if (link_stream->dpms_off)
3625 decide_link_settings(link_stream, &store_settings);
3627 if ((store_settings.lane_count != LANE_COUNT_UNKNOWN) &&
3628 (store_settings.link_rate != LINK_RATE_UNKNOWN))
3629 dp_retrain_link_dp_test(link, &store_settings, false);
3632 void dc_link_set_preferred_training_settings(struct dc *dc,
3633 struct dc_link_settings *link_setting,
3634 struct dc_link_training_overrides *lt_overrides,
3635 struct dc_link *link,
3636 bool skip_immediate_retrain)
3638 if (lt_overrides != NULL)
3639 link->preferred_training_settings = *lt_overrides;
3641 memset(&link->preferred_training_settings, 0, sizeof(link->preferred_training_settings));
3643 if (link_setting != NULL) {
3644 link->preferred_link_setting = *link_setting;
3646 link->preferred_link_setting.lane_count = LANE_COUNT_UNKNOWN;
3647 link->preferred_link_setting.link_rate = LINK_RATE_UNKNOWN;
3650 /* Retrain now, or wait until next stream update to apply */
3651 if (skip_immediate_retrain == false)
3652 dc_link_set_preferred_link_settings(dc, &link->preferred_link_setting, link);
3655 void dc_link_enable_hpd(const struct dc_link *link)
3657 dc_link_dp_enable_hpd(link);
3660 void dc_link_disable_hpd(const struct dc_link *link)
3662 dc_link_dp_disable_hpd(link);
3665 void dc_link_set_test_pattern(struct dc_link *link,
3666 enum dp_test_pattern test_pattern,
3667 enum dp_test_pattern_color_space test_pattern_color_space,
3668 const struct link_training_settings *p_link_settings,
3669 const unsigned char *p_custom_pattern,
3670 unsigned int cust_pattern_size)
3673 dc_link_dp_set_test_pattern(
3676 test_pattern_color_space,
3682 uint32_t dc_link_bandwidth_kbps(
3683 const struct dc_link *link,
3684 const struct dc_link_settings *link_setting)
3686 uint32_t link_bw_kbps =
3687 link_setting->link_rate * LINK_RATE_REF_FREQ_IN_KHZ; /* bytes per sec */
3689 link_bw_kbps *= 8; /* 8 bits per byte*/
3690 link_bw_kbps *= link_setting->lane_count;
3692 if (dc_link_should_enable_fec(link)) {
3693 /* Account for FEC overhead.
3694 * We have to do it based on caps,
3695 * and not based on FEC being set ready,
3696 * because FEC is set ready too late in
3697 * the process to correctly be picked up
3698 * by mode enumeration.
3700 * There's enough zeros at the end of 'kbps'
3701 * that make the below operation 100% precise
3703 * 'long long' makes it work even for HDMI 2.1
3704 * max bandwidth (and much, much bigger bandwidths
3705 * than that, actually).
3707 * NOTE: Reducing link BW by 3% may not be precise
3708 * because it may be a stream BT that increases by 3%, and so
3709 * 1/1.03 = 0.970873 factor should have been used instead,
3710 * but the difference is minimal and is in a safe direction,
3711 * which all works well around potential ambiguity of DP 1.4a spec.
3713 long long fec_link_bw_kbps = link_bw_kbps * 970LL;
3714 link_bw_kbps = (uint32_t)(div64_s64(fec_link_bw_kbps, 1000LL));
3717 return link_bw_kbps;
3721 const struct dc_link_settings *dc_link_get_link_cap(
3722 const struct dc_link *link)
3724 if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
3725 link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
3726 return &link->preferred_link_setting;
3727 return &link->verified_link_cap;
3730 void dc_link_overwrite_extended_receiver_cap(
3731 struct dc_link *link)
3733 dp_overwrite_extended_receiver_cap(link);
3736 bool dc_link_is_fec_supported(const struct dc_link *link)
3738 return (dc_is_dp_signal(link->connector_signal) &&
3739 link->link_enc->features.fec_supported &&
3740 link->dpcd_caps.fec_cap.bits.FEC_CAPABLE &&
3741 !IS_FPGA_MAXIMUS_DC(link->ctx->dce_environment));
3744 bool dc_link_should_enable_fec(const struct dc_link *link)
3746 bool is_fec_disable = false;
3749 if ((link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT_MST &&
3751 link->local_sink->edid_caps.panel_patch.disable_fec) ||
3752 link->connector_signal == SIGNAL_TYPE_EDP) // Disable FEC for eDP
3753 is_fec_disable = true;
3755 if (dc_link_is_fec_supported(link) && !link->dc->debug.disable_fec && !is_fec_disable)