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"
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"
49 #define DC_LOGGER_INIT(logger)
52 #define LINK_INFO(...) \
56 #define RETIMER_REDRIVER_INFO(...) \
57 DC_LOG_RETIMER_REDRIVER( \
59 /*******************************************************************************
61 ******************************************************************************/
64 PEAK_FACTOR_X1000 = 1006,
66 * Some receivers fail to train on first try and are good
67 * on subsequent tries. 2 retries should be plenty. If we
68 * don't have a successful training then we don't expect to
71 LINK_TRAINING_MAX_VERIFY_RETRY = 2
74 /*******************************************************************************
76 ******************************************************************************/
77 static void destruct(struct dc_link *link)
81 if (link->hpd_gpio != NULL) {
82 dal_gpio_destroy_irq(&link->hpd_gpio);
83 link->hpd_gpio = NULL;
87 dal_ddc_service_destroy(&link->ddc);
90 link->link_enc->funcs->destroy(&link->link_enc);
93 dc_sink_release(link->local_sink);
95 for (i = 0; i < link->sink_count; ++i)
96 dc_sink_release(link->remote_sinks[i]);
99 struct gpio *get_hpd_gpio(struct dc_bios *dcb,
100 struct graphics_object_id link_id,
101 struct gpio_service *gpio_service)
103 enum bp_result bp_result;
104 struct graphics_object_hpd_info hpd_info;
105 struct gpio_pin_info pin_info;
107 if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
110 bp_result = dcb->funcs->get_gpio_pin_info(dcb,
111 hpd_info.hpd_int_gpio_uid, &pin_info);
113 if (bp_result != BP_RESULT_OK) {
114 ASSERT(bp_result == BP_RESULT_NORECORD);
118 return dal_gpio_service_create_irq(
125 * Function: program_hpd_filter
128 * Programs HPD filter on associated HPD line
130 * @param [in] delay_on_connect_in_ms: Connect filter timeout
131 * @param [in] delay_on_disconnect_in_ms: Disconnect filter timeout
134 * true on success, false otherwise
136 static bool program_hpd_filter(
137 const struct dc_link *link)
143 int delay_on_connect_in_ms = 0;
144 int delay_on_disconnect_in_ms = 0;
146 if (link->is_hpd_filter_disabled)
148 /* Verify feature is supported */
149 switch (link->connector_signal) {
150 case SIGNAL_TYPE_DVI_SINGLE_LINK:
151 case SIGNAL_TYPE_DVI_DUAL_LINK:
152 case SIGNAL_TYPE_HDMI_TYPE_A:
153 /* Program hpd filter */
154 delay_on_connect_in_ms = 500;
155 delay_on_disconnect_in_ms = 100;
157 case SIGNAL_TYPE_DISPLAY_PORT:
158 case SIGNAL_TYPE_DISPLAY_PORT_MST:
159 /* Program hpd filter to allow DP signal to settle */
160 /* 500: not able to detect MST <-> SST switch as HPD is low for
161 * only 100ms on DELL U2413
162 * 0: some passive dongle still show aux mode instead of i2c
163 * 20-50:not enough to hide bouncing HPD with passive dongle.
164 * also see intermittent i2c read issues.
166 delay_on_connect_in_ms = 80;
167 delay_on_disconnect_in_ms = 0;
169 case SIGNAL_TYPE_LVDS:
170 case SIGNAL_TYPE_EDP:
172 /* Don't program hpd filter */
176 /* Obtain HPD handle */
177 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
182 /* Setup HPD filtering */
183 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
184 struct gpio_hpd_config config;
186 config.delay_on_connect = delay_on_connect_in_ms;
187 config.delay_on_disconnect = delay_on_disconnect_in_ms;
189 dal_irq_setup_hpd_filter(hpd, &config);
195 ASSERT_CRITICAL(false);
198 /* Release HPD handle */
199 dal_gpio_destroy_irq(&hpd);
205 * dc_link_detect_sink() - Determine if there is a sink connected
207 * @type: Returned connection type
208 * Does not detect downstream devices, such as MST sinks
209 * or display connected through active dongles
211 bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type)
213 uint32_t is_hpd_high = 0;
214 struct gpio *hpd_pin;
216 if (link->connector_signal == SIGNAL_TYPE_LVDS) {
217 *type = dc_connection_single;
221 if (link->connector_signal == SIGNAL_TYPE_EDP) {
222 /*in case it is not on*/
223 link->dc->hwss.edp_power_control(link, true);
224 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
227 /* todo: may need to lock gpio access */
228 hpd_pin = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
230 goto hpd_gpio_failure;
232 dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
233 dal_gpio_get_value(hpd_pin, &is_hpd_high);
234 dal_gpio_close(hpd_pin);
235 dal_gpio_destroy_irq(&hpd_pin);
238 *type = dc_connection_single;
239 /* TODO: need to do the actual detection */
241 *type = dc_connection_none;
250 static enum ddc_transaction_type get_ddc_transaction_type(
251 enum signal_type sink_signal)
253 enum ddc_transaction_type transaction_type = DDC_TRANSACTION_TYPE_NONE;
255 switch (sink_signal) {
256 case SIGNAL_TYPE_DVI_SINGLE_LINK:
257 case SIGNAL_TYPE_DVI_DUAL_LINK:
258 case SIGNAL_TYPE_HDMI_TYPE_A:
259 case SIGNAL_TYPE_LVDS:
260 case SIGNAL_TYPE_RGB:
261 transaction_type = DDC_TRANSACTION_TYPE_I2C;
264 case SIGNAL_TYPE_DISPLAY_PORT:
265 case SIGNAL_TYPE_EDP:
266 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
269 case SIGNAL_TYPE_DISPLAY_PORT_MST:
270 /* MST does not use I2COverAux, but there is the
271 * SPECIAL use case for "immediate dwnstrm device
272 * access" (EPR#370830). */
273 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
280 return transaction_type;
283 static enum signal_type get_basic_signal_type(
284 struct graphics_object_id encoder,
285 struct graphics_object_id downstream)
287 if (downstream.type == OBJECT_TYPE_CONNECTOR) {
288 switch (downstream.id) {
289 case CONNECTOR_ID_SINGLE_LINK_DVII:
290 switch (encoder.id) {
291 case ENCODER_ID_INTERNAL_DAC1:
292 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
293 case ENCODER_ID_INTERNAL_DAC2:
294 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
295 return SIGNAL_TYPE_RGB;
297 return SIGNAL_TYPE_DVI_SINGLE_LINK;
300 case CONNECTOR_ID_DUAL_LINK_DVII:
302 switch (encoder.id) {
303 case ENCODER_ID_INTERNAL_DAC1:
304 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
305 case ENCODER_ID_INTERNAL_DAC2:
306 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
307 return SIGNAL_TYPE_RGB;
309 return SIGNAL_TYPE_DVI_DUAL_LINK;
313 case CONNECTOR_ID_SINGLE_LINK_DVID:
314 return SIGNAL_TYPE_DVI_SINGLE_LINK;
315 case CONNECTOR_ID_DUAL_LINK_DVID:
316 return SIGNAL_TYPE_DVI_DUAL_LINK;
317 case CONNECTOR_ID_VGA:
318 return SIGNAL_TYPE_RGB;
319 case CONNECTOR_ID_HDMI_TYPE_A:
320 return SIGNAL_TYPE_HDMI_TYPE_A;
321 case CONNECTOR_ID_LVDS:
322 return SIGNAL_TYPE_LVDS;
323 case CONNECTOR_ID_DISPLAY_PORT:
324 return SIGNAL_TYPE_DISPLAY_PORT;
325 case CONNECTOR_ID_EDP:
326 return SIGNAL_TYPE_EDP;
328 return SIGNAL_TYPE_NONE;
330 } else if (downstream.type == OBJECT_TYPE_ENCODER) {
331 switch (downstream.id) {
332 case ENCODER_ID_EXTERNAL_NUTMEG:
333 case ENCODER_ID_EXTERNAL_TRAVIS:
334 return SIGNAL_TYPE_DISPLAY_PORT;
336 return SIGNAL_TYPE_NONE;
340 return SIGNAL_TYPE_NONE;
344 * dc_link_is_dp_sink_present() - Check if there is a native DP
345 * or passive DP-HDMI dongle connected
347 bool dc_link_is_dp_sink_present(struct dc_link *link)
349 enum gpio_result gpio_result;
350 uint32_t clock_pin = 0;
354 enum connector_id connector_id =
355 dal_graphics_object_id_get_connector_id(link->link_id);
358 ((connector_id == CONNECTOR_ID_DISPLAY_PORT) ||
359 (connector_id == CONNECTOR_ID_EDP));
361 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
368 /* Open GPIO and set it to I2C mode */
369 /* Note: this GpioMode_Input will be converted
370 * to GpioConfigType_I2cAuxDualMode in GPIO component,
371 * which indicates we need additional delay */
373 if (GPIO_RESULT_OK != dal_ddc_open(
374 ddc, GPIO_MODE_INPUT, GPIO_DDC_CONFIG_TYPE_MODE_I2C)) {
375 dal_gpio_destroy_ddc(&ddc);
381 * Read GPIO: DP sink is present if both clock and data pins are zero
383 * [W/A] plug-unplug DP cable, sometimes customer board has
384 * one short pulse on clk_pin(1V, < 1ms). DP will be config to HDMI/DVI
385 * then monitor can't br light up. Add retry 3 times
386 * But in real passive dongle, it need additional 3ms to detect
389 gpio_result = dal_gpio_get_value(ddc->pin_clock, &clock_pin);
390 ASSERT(gpio_result == GPIO_RESULT_OK);
395 } while (retry++ < 3);
397 present = (gpio_result == GPIO_RESULT_OK) && !clock_pin;
406 * Detect output sink type
408 static enum signal_type link_detect_sink(
409 struct dc_link *link,
410 enum dc_detect_reason reason)
412 enum signal_type result = get_basic_signal_type(
413 link->link_enc->id, link->link_id);
415 /* Internal digital encoder will detect only dongles
416 * that require digital signal */
418 /* Detection mechanism is different
419 * for different native connectors.
420 * LVDS connector supports only LVDS signal;
421 * PCIE is a bus slot, the actual connector needs to be detected first;
422 * eDP connector supports only eDP signal;
423 * HDMI should check straps for audio */
425 /* PCIE detects the actual connector on add-on board */
427 if (link->link_id.id == CONNECTOR_ID_PCIE) {
428 /* ZAZTODO implement PCIE add-on card detection */
431 switch (link->link_id.id) {
432 case CONNECTOR_ID_HDMI_TYPE_A: {
433 /* check audio support:
434 * if native HDMI is not supported, switch to DVI */
435 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
437 if (!aud_support->hdmi_audio_native)
438 if (link->link_id.id == CONNECTOR_ID_HDMI_TYPE_A)
439 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
442 case CONNECTOR_ID_DISPLAY_PORT: {
443 /* DP HPD short pulse. Passive DP dongle will not
446 if (reason != DETECT_REASON_HPDRX) {
447 /* Check whether DP signal detected: if not -
448 * we assume signal is DVI; it could be corrected
449 * to HDMI after dongle detection
451 if (!dm_helpers_is_dp_sink_present(link))
452 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
463 static enum signal_type decide_signal_from_strap_and_dongle_type(
464 enum display_dongle_type dongle_type,
465 struct audio_support *audio_support)
467 enum signal_type signal = SIGNAL_TYPE_NONE;
469 switch (dongle_type) {
470 case DISPLAY_DONGLE_DP_HDMI_DONGLE:
471 if (audio_support->hdmi_audio_on_dongle)
472 signal = SIGNAL_TYPE_HDMI_TYPE_A;
474 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
476 case DISPLAY_DONGLE_DP_DVI_DONGLE:
477 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
479 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE:
480 if (audio_support->hdmi_audio_native)
481 signal = SIGNAL_TYPE_HDMI_TYPE_A;
483 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
486 signal = SIGNAL_TYPE_NONE;
493 static enum signal_type dp_passive_dongle_detection(
494 struct ddc_service *ddc,
495 struct display_sink_capability *sink_cap,
496 struct audio_support *audio_support)
498 dal_ddc_service_i2c_query_dp_dual_mode_adaptor(
500 return decide_signal_from_strap_and_dongle_type(
501 sink_cap->dongle_type,
505 static void link_disconnect_sink(struct dc_link *link)
507 if (link->local_sink) {
508 dc_sink_release(link->local_sink);
509 link->local_sink = NULL;
512 link->dpcd_sink_count = 0;
515 static void link_disconnect_remap(struct dc_sink *prev_sink, struct dc_link *link)
517 dc_sink_release(link->local_sink);
518 link->local_sink = prev_sink;
522 static void read_current_link_settings_on_detect(struct dc_link *link)
524 union lane_count_set lane_count_set = { {0} };
526 uint8_t link_rate_set;
527 uint32_t read_dpcd_retry_cnt = 10;
528 enum dc_status status = DC_ERROR_UNEXPECTED;
530 union max_down_spread max_down_spread = { {0} };
532 // Read DPCD 00101h to find out the number of lanes currently set
533 for (i = 0; i < read_dpcd_retry_cnt; i++) {
534 status = core_link_read_dpcd(
538 sizeof(lane_count_set));
539 /* First DPCD read after VDD ON can fail if the particular board
540 * does not have HPD pin wired correctly. So if DPCD read fails,
541 * which it should never happen, retry a few times. Target worst
542 * case scenario of 80 ms.
544 if (status == DC_OK) {
545 link->cur_link_settings.lane_count = lane_count_set.bits.LANE_COUNT_SET;
552 // Read DPCD 00100h to find if standard link rates are set
553 core_link_read_dpcd(link, DP_LINK_BW_SET,
554 &link_bw_set, sizeof(link_bw_set));
556 if (link_bw_set == 0) {
557 if (link->connector_signal == SIGNAL_TYPE_EDP) {
558 /* If standard link rates are not being used,
559 * Read DPCD 00115h to find the edp link rate set used
561 core_link_read_dpcd(link, DP_LINK_RATE_SET,
562 &link_rate_set, sizeof(link_rate_set));
564 // edp_supported_link_rates_count = 0 for DP
565 if (link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
566 link->cur_link_settings.link_rate =
567 link->dpcd_caps.edp_supported_link_rates[link_rate_set];
568 link->cur_link_settings.link_rate_set = link_rate_set;
569 link->cur_link_settings.use_link_rate_set = true;
572 // Link Rate not found. Seamless boot may not work.
576 link->cur_link_settings.link_rate = link_bw_set;
577 link->cur_link_settings.use_link_rate_set = false;
579 // Read DPCD 00003h to find the max down spread.
580 core_link_read_dpcd(link, DP_MAX_DOWNSPREAD,
581 &max_down_spread.raw, sizeof(max_down_spread));
582 link->cur_link_settings.link_spread =
583 max_down_spread.bits.MAX_DOWN_SPREAD ?
584 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
587 static bool detect_dp(
588 struct dc_link *link,
589 struct display_sink_capability *sink_caps,
590 bool *converter_disable_audio,
591 struct audio_support *audio_support,
592 enum dc_detect_reason reason)
595 sink_caps->signal = link_detect_sink(link, reason);
596 sink_caps->transaction_type =
597 get_ddc_transaction_type(sink_caps->signal);
599 if (sink_caps->transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
600 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
601 if (!detect_dp_sink_caps(link))
604 if (is_mst_supported(link)) {
605 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
606 link->type = dc_connection_mst_branch;
608 dal_ddc_service_set_transaction_type(
610 sink_caps->transaction_type);
613 * This call will initiate MST topology discovery. Which
614 * will detect MST ports and add new DRM connector DRM
615 * framework. Then read EDID via remote i2c over aux. In
616 * the end, will notify DRM detect result and save EDID
617 * into DRM framework.
619 * .detect is called by .fill_modes.
620 * .fill_modes is called by user mode ioctl
621 * DRM_IOCTL_MODE_GETCONNECTOR.
623 * .get_modes is called by .fill_modes.
625 * call .get_modes, AMDGPU DM implementation will create
626 * new dc_sink and add to dc_link. For long HPD plug
627 * in/out, MST has its own handle.
629 * Therefore, just after dc_create, link->sink is not
630 * created for MST until user mode app calls
631 * DRM_IOCTL_MODE_GETCONNECTOR.
633 * Need check ->sink usages in case ->sink = NULL
634 * TODO: s3 resume check
636 if (reason == DETECT_REASON_BOOT)
639 dm_helpers_dp_update_branch_info(
643 if (!dm_helpers_dp_mst_start_top_mgr(
646 /* MST not supported */
647 link->type = dc_connection_single;
648 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
652 if (link->type != dc_connection_mst_branch &&
653 is_dp_active_dongle(link)) {
654 /* DP active dongles */
655 link->type = dc_connection_active_dongle;
656 if (!link->dpcd_caps.sink_count.bits.SINK_COUNT) {
658 * active dongle unplug processing for short irq
660 link_disconnect_sink(link);
664 if (link->dpcd_caps.dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER)
665 *converter_disable_audio = true;
668 /* DP passive dongles */
669 sink_caps->signal = dp_passive_dongle_detection(link->ddc,
677 static bool is_same_edid(struct dc_edid *old_edid, struct dc_edid *new_edid)
679 if (old_edid->length != new_edid->length)
682 if (new_edid->length == 0)
685 return (memcmp(old_edid->raw_edid, new_edid->raw_edid, new_edid->length) == 0);
688 static bool wait_for_alt_mode(struct dc_link *link)
692 * something is terribly wrong if time out is > 200ms. (5Hz)
693 * 500 microseconds * 400 tries us 200 ms
695 unsigned int sleep_time_in_microseconds = 500;
696 unsigned int tries_allowed = 400;
698 unsigned long long enter_timestamp;
699 unsigned long long finish_timestamp;
700 unsigned long long time_taken_in_ns;
703 DC_LOGGER_INIT(link->ctx->logger);
705 if (link->link_enc->funcs->is_in_alt_mode == NULL)
708 is_in_alt_mode = link->link_enc->funcs->is_in_alt_mode(link->link_enc);
709 DC_LOG_WARNING("DP Alt mode state on HPD: %d\n", is_in_alt_mode);
714 enter_timestamp = dm_get_timestamp(link->ctx);
716 for (tries_taken = 0; tries_taken < tries_allowed; tries_taken++) {
717 udelay(sleep_time_in_microseconds);
718 /* ask the link if alt mode is enabled, if so return ok */
719 if (link->link_enc->funcs->is_in_alt_mode(link->link_enc)) {
721 finish_timestamp = dm_get_timestamp(link->ctx);
722 time_taken_in_ns = dm_get_elapse_time_in_ns(
723 link->ctx, finish_timestamp, enter_timestamp);
724 DC_LOG_WARNING("Alt mode entered finished after %llu ms\n",
725 div_u64(time_taken_in_ns, 1000000));
730 finish_timestamp = dm_get_timestamp(link->ctx);
731 time_taken_in_ns = dm_get_elapse_time_in_ns(link->ctx, finish_timestamp,
733 DC_LOG_WARNING("Alt mode has timed out after %llu ms\n",
734 div_u64(time_taken_in_ns, 1000000));
739 * dc_link_detect() - Detect if a sink is attached to a given link
741 * link->local_sink is created or destroyed as needed.
743 * This does not create remote sinks but will trigger DM
744 * to start MST detection if a branch is detected.
746 static bool dc_link_detect_helper(struct dc_link *link,
747 enum dc_detect_reason reason)
749 struct dc_sink_init_data sink_init_data = { 0 };
750 struct display_sink_capability sink_caps = { 0 };
752 bool converter_disable_audio = false;
753 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
754 bool same_edid = false;
755 enum dc_edid_status edid_status;
756 struct dc_context *dc_ctx = link->ctx;
757 struct dc_sink *sink = NULL;
758 struct dc_sink *prev_sink = NULL;
759 struct dpcd_caps prev_dpcd_caps;
760 bool same_dpcd = true;
761 enum dc_connection_type new_connection_type = dc_connection_none;
762 bool perform_dp_seamless_boot = false;
764 DC_LOGGER_INIT(link->ctx->logger);
766 if (dc_is_virtual_signal(link->connector_signal))
769 if ((link->connector_signal == SIGNAL_TYPE_LVDS ||
770 link->connector_signal == SIGNAL_TYPE_EDP) &&
774 if (false == dc_link_detect_sink(link, &new_connection_type)) {
779 prev_sink = link->local_sink;
780 if (prev_sink != NULL) {
781 dc_sink_retain(prev_sink);
782 memcpy(&prev_dpcd_caps, &link->dpcd_caps, sizeof(struct dpcd_caps));
784 link_disconnect_sink(link);
786 if (new_connection_type != dc_connection_none) {
787 link->type = new_connection_type;
788 link->link_state_valid = false;
790 /* From Disconnected-to-Connected. */
791 switch (link->connector_signal) {
792 case SIGNAL_TYPE_HDMI_TYPE_A: {
793 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
794 if (aud_support->hdmi_audio_native)
795 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A;
797 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
801 case SIGNAL_TYPE_DVI_SINGLE_LINK: {
802 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
803 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
807 case SIGNAL_TYPE_DVI_DUAL_LINK: {
808 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
809 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK;
813 case SIGNAL_TYPE_LVDS: {
814 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
815 sink_caps.signal = SIGNAL_TYPE_LVDS;
819 case SIGNAL_TYPE_EDP: {
820 read_current_link_settings_on_detect(link);
821 detect_edp_sink_caps(link);
822 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
823 sink_caps.signal = SIGNAL_TYPE_EDP;
827 case SIGNAL_TYPE_DISPLAY_PORT: {
829 /* wa HPD high coming too early*/
830 if (link->link_enc->features.flags.bits.DP_IS_USB_C == 1) {
832 /* if alt mode times out, return false */
833 if (wait_for_alt_mode(link) == false) {
841 &converter_disable_audio,
842 aud_support, reason)) {
843 if (prev_sink != NULL)
844 dc_sink_release(prev_sink);
848 // Check if dpcp block is the same
849 if (prev_sink != NULL) {
850 if (memcmp(&link->dpcd_caps, &prev_dpcd_caps, sizeof(struct dpcd_caps)))
853 /* Active dongle plug in without display or downstream unplug*/
854 if (link->type == dc_connection_active_dongle &&
855 link->dpcd_caps.sink_count.bits.SINK_COUNT == 0) {
856 if (prev_sink != NULL) {
857 /* Downstream unplug */
858 dc_sink_release(prev_sink);
860 /* Empty dongle plug in */
861 dp_verify_link_cap_with_retries(link,
862 &link->reported_link_cap,
863 LINK_TRAINING_MAX_VERIFY_RETRY);
868 if (link->type == dc_connection_mst_branch) {
869 LINK_INFO("link=%d, mst branch is now Connected\n",
871 /* Need to setup mst link_cap struct here
872 * otherwise dc_link_detect() will leave mst link_cap
873 * empty which leads to allocate_mst_payload() has "0"
874 * pbn_per_slot value leading to exception on dc_fixpt_div()
876 dp_verify_mst_link_cap(link);
878 if (prev_sink != NULL)
879 dc_sink_release(prev_sink);
883 // For seamless boot, to skip verify link cap, we read UEFI settings and set them as verified.
884 if (reason == DETECT_REASON_BOOT &&
885 dc_ctx->dc->config.power_down_display_on_boot == false &&
886 link->link_status.link_active == true)
887 perform_dp_seamless_boot = true;
889 if (perform_dp_seamless_boot) {
890 read_current_link_settings_on_detect(link);
891 link->verified_link_cap = link->reported_link_cap;
898 DC_ERROR("Invalid connector type! signal:%d\n",
899 link->connector_signal);
900 if (prev_sink != NULL)
901 dc_sink_release(prev_sink);
905 if (link->dpcd_caps.sink_count.bits.SINK_COUNT)
906 link->dpcd_sink_count = link->dpcd_caps.sink_count.
909 link->dpcd_sink_count = 1;
911 dal_ddc_service_set_transaction_type(
913 sink_caps.transaction_type);
915 link->aux_mode = dal_ddc_service_is_in_aux_transaction_mode(
918 sink_init_data.link = link;
919 sink_init_data.sink_signal = sink_caps.signal;
921 sink = dc_sink_create(&sink_init_data);
923 DC_ERROR("Failed to create sink!\n");
924 if (prev_sink != NULL)
925 dc_sink_release(prev_sink);
929 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock;
930 sink->converter_disable_audio = converter_disable_audio;
932 /* dc_sink_create returns a new reference */
933 link->local_sink = sink;
935 edid_status = dm_helpers_read_local_edid(
940 switch (edid_status) {
941 case EDID_BAD_CHECKSUM:
942 DC_LOG_ERROR("EDID checksum invalid.\n");
944 case EDID_NO_RESPONSE:
945 DC_LOG_ERROR("No EDID read.\n");
948 * Abort detection for non-DP connectors if we have
951 * DP needs to report as connected if HDP is high
952 * even if we have no EDID in order to go to
955 if (dc_is_hdmi_signal(link->connector_signal) ||
956 dc_is_dvi_signal(link->connector_signal)) {
957 if (prev_sink != NULL)
958 dc_sink_release(prev_sink);
966 // Check if edid is the same
967 if ((prev_sink != NULL) && ((edid_status == EDID_THE_SAME) || (edid_status == EDID_OK)))
968 same_edid = is_same_edid(&prev_sink->dc_edid, &sink->dc_edid);
970 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
971 sink_caps.transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX &&
972 reason != DETECT_REASON_HPDRX) {
974 * TODO debug why Dell 2413 doesn't like
978 // verify link cap for SST non-seamless boot
979 if (!perform_dp_seamless_boot)
980 dp_verify_link_cap_with_retries(link,
981 &link->reported_link_cap,
982 LINK_TRAINING_MAX_VERIFY_RETRY);
984 // If edid is the same, then discard new sink and revert back to original sink
986 link_disconnect_remap(prev_sink, link);
993 /* HDMI-DVI Dongle */
994 if (sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A &&
995 !sink->edid_caps.edid_hdmi)
996 sink->sink_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
998 /* Connectivity log: detection */
999 for (i = 0; i < sink->dc_edid.length / DC_EDID_BLOCK_SIZE; i++) {
1000 CONN_DATA_DETECT(link,
1001 &sink->dc_edid.raw_edid[i * DC_EDID_BLOCK_SIZE],
1003 "%s: [Block %d] ", sink->edid_caps.display_name, i);
1006 DC_LOG_DETECTION_EDID_PARSER("%s: "
1007 "manufacturer_id = %X, "
1009 "serial_number = %X, "
1010 "manufacture_week = %d, "
1011 "manufacture_year = %d, "
1012 "display_name = %s, "
1013 "speaker_flag = %d, "
1014 "audio_mode_count = %d\n",
1016 sink->edid_caps.manufacturer_id,
1017 sink->edid_caps.product_id,
1018 sink->edid_caps.serial_number,
1019 sink->edid_caps.manufacture_week,
1020 sink->edid_caps.manufacture_year,
1021 sink->edid_caps.display_name,
1022 sink->edid_caps.speaker_flags,
1023 sink->edid_caps.audio_mode_count);
1025 for (i = 0; i < sink->edid_caps.audio_mode_count; i++) {
1026 DC_LOG_DETECTION_EDID_PARSER("%s: mode number = %d, "
1027 "format_code = %d, "
1028 "channel_count = %d, "
1029 "sample_rate = %d, "
1030 "sample_size = %d\n",
1033 sink->edid_caps.audio_modes[i].format_code,
1034 sink->edid_caps.audio_modes[i].channel_count,
1035 sink->edid_caps.audio_modes[i].sample_rate,
1036 sink->edid_caps.audio_modes[i].sample_size);
1040 /* From Connected-to-Disconnected. */
1041 if (link->type == dc_connection_mst_branch) {
1042 LINK_INFO("link=%d, mst branch is now Disconnected\n",
1045 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
1047 link->mst_stream_alloc_table.stream_count = 0;
1048 memset(link->mst_stream_alloc_table.stream_allocations, 0, sizeof(link->mst_stream_alloc_table.stream_allocations));
1051 link->type = dc_connection_none;
1052 sink_caps.signal = SIGNAL_TYPE_NONE;
1053 /* When we unplug a passive DP-HDMI dongle connection, dongle_max_pix_clk
1054 * is not cleared. If we emulate a DP signal on this connection, it thinks
1055 * the dongle is still there and limits the number of modes we can emulate.
1056 * Clear dongle_max_pix_clk on disconnect to fix this
1058 link->dongle_max_pix_clk = 0;
1061 LINK_INFO("link=%d, dc_sink_in=%p is now %s prev_sink=%p dpcd same=%d edid same=%d\n",
1062 link->link_index, sink,
1063 (sink_caps.signal == SIGNAL_TYPE_NONE ?
1064 "Disconnected":"Connected"), prev_sink,
1065 same_dpcd, same_edid);
1067 if (prev_sink != NULL)
1068 dc_sink_release(prev_sink);
1074 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
1076 const struct dc *dc = link->dc;
1079 /* get out of low power state */
1080 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
1082 ret = dc_link_detect_helper(link, reason);
1084 /* Go back to power optimized state */
1085 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
1090 bool dc_link_get_hpd_state(struct dc_link *dc_link)
1094 dal_gpio_lock_pin(dc_link->hpd_gpio);
1095 dal_gpio_get_value(dc_link->hpd_gpio, &state);
1096 dal_gpio_unlock_pin(dc_link->hpd_gpio);
1101 static enum hpd_source_id get_hpd_line(
1102 struct dc_link *link)
1105 enum hpd_source_id hpd_id = HPD_SOURCEID_UNKNOWN;
1107 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
1110 switch (dal_irq_get_source(hpd)) {
1111 case DC_IRQ_SOURCE_HPD1:
1112 hpd_id = HPD_SOURCEID1;
1114 case DC_IRQ_SOURCE_HPD2:
1115 hpd_id = HPD_SOURCEID2;
1117 case DC_IRQ_SOURCE_HPD3:
1118 hpd_id = HPD_SOURCEID3;
1120 case DC_IRQ_SOURCE_HPD4:
1121 hpd_id = HPD_SOURCEID4;
1123 case DC_IRQ_SOURCE_HPD5:
1124 hpd_id = HPD_SOURCEID5;
1126 case DC_IRQ_SOURCE_HPD6:
1127 hpd_id = HPD_SOURCEID6;
1130 BREAK_TO_DEBUGGER();
1134 dal_gpio_destroy_irq(&hpd);
1140 static enum channel_id get_ddc_line(struct dc_link *link)
1143 enum channel_id channel = CHANNEL_ID_UNKNOWN;
1145 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
1148 switch (dal_ddc_get_line(ddc)) {
1149 case GPIO_DDC_LINE_DDC1:
1150 channel = CHANNEL_ID_DDC1;
1152 case GPIO_DDC_LINE_DDC2:
1153 channel = CHANNEL_ID_DDC2;
1155 case GPIO_DDC_LINE_DDC3:
1156 channel = CHANNEL_ID_DDC3;
1158 case GPIO_DDC_LINE_DDC4:
1159 channel = CHANNEL_ID_DDC4;
1161 case GPIO_DDC_LINE_DDC5:
1162 channel = CHANNEL_ID_DDC5;
1164 case GPIO_DDC_LINE_DDC6:
1165 channel = CHANNEL_ID_DDC6;
1167 case GPIO_DDC_LINE_DDC_VGA:
1168 channel = CHANNEL_ID_DDC_VGA;
1170 case GPIO_DDC_LINE_I2C_PAD:
1171 channel = CHANNEL_ID_I2C_PAD;
1174 BREAK_TO_DEBUGGER();
1182 static enum transmitter translate_encoder_to_transmitter(
1183 struct graphics_object_id encoder)
1185 switch (encoder.id) {
1186 case ENCODER_ID_INTERNAL_UNIPHY:
1187 switch (encoder.enum_id) {
1189 return TRANSMITTER_UNIPHY_A;
1191 return TRANSMITTER_UNIPHY_B;
1193 return TRANSMITTER_UNKNOWN;
1196 case ENCODER_ID_INTERNAL_UNIPHY1:
1197 switch (encoder.enum_id) {
1199 return TRANSMITTER_UNIPHY_C;
1201 return TRANSMITTER_UNIPHY_D;
1203 return TRANSMITTER_UNKNOWN;
1206 case ENCODER_ID_INTERNAL_UNIPHY2:
1207 switch (encoder.enum_id) {
1209 return TRANSMITTER_UNIPHY_E;
1211 return TRANSMITTER_UNIPHY_F;
1213 return TRANSMITTER_UNKNOWN;
1216 case ENCODER_ID_INTERNAL_UNIPHY3:
1217 switch (encoder.enum_id) {
1219 return TRANSMITTER_UNIPHY_G;
1221 return TRANSMITTER_UNKNOWN;
1224 case ENCODER_ID_EXTERNAL_NUTMEG:
1225 switch (encoder.enum_id) {
1227 return TRANSMITTER_NUTMEG_CRT;
1229 return TRANSMITTER_UNKNOWN;
1232 case ENCODER_ID_EXTERNAL_TRAVIS:
1233 switch (encoder.enum_id) {
1235 return TRANSMITTER_TRAVIS_CRT;
1237 return TRANSMITTER_TRAVIS_LCD;
1239 return TRANSMITTER_UNKNOWN;
1243 return TRANSMITTER_UNKNOWN;
1247 static bool construct(
1248 struct dc_link *link,
1249 const struct link_init_data *init_params)
1252 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1253 struct dc_context *dc_ctx = init_params->ctx;
1254 struct encoder_init_data enc_init_data = { 0 };
1255 struct integrated_info info = {{{ 0 }}};
1256 struct dc_bios *bios = init_params->dc->ctx->dc_bios;
1257 const struct dc_vbios_funcs *bp_funcs = bios->funcs;
1258 DC_LOGGER_INIT(dc_ctx->logger);
1260 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1261 link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
1263 link->link_status.dpcd_caps = &link->dpcd_caps;
1265 link->dc = init_params->dc;
1267 link->link_index = init_params->link_index;
1269 memset(&link->preferred_training_settings, 0, sizeof(struct dc_link_training_overrides));
1270 memset(&link->preferred_link_setting, 0, sizeof(struct dc_link_settings));
1272 link->link_id = bios->funcs->get_connector_id(bios, init_params->connector_index);
1274 if (link->link_id.type != OBJECT_TYPE_CONNECTOR) {
1275 dm_output_to_console("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d! type %d expected %d\n",
1276 __func__, init_params->connector_index,
1277 link->link_id.type, OBJECT_TYPE_CONNECTOR);
1281 if (link->dc->res_pool->funcs->link_init)
1282 link->dc->res_pool->funcs->link_init(link);
1284 link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
1285 if (link->hpd_gpio != NULL) {
1286 dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
1287 dal_gpio_unlock_pin(link->hpd_gpio);
1288 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
1291 switch (link->link_id.id) {
1292 case CONNECTOR_ID_HDMI_TYPE_A:
1293 link->connector_signal = SIGNAL_TYPE_HDMI_TYPE_A;
1296 case CONNECTOR_ID_SINGLE_LINK_DVID:
1297 case CONNECTOR_ID_SINGLE_LINK_DVII:
1298 link->connector_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1300 case CONNECTOR_ID_DUAL_LINK_DVID:
1301 case CONNECTOR_ID_DUAL_LINK_DVII:
1302 link->connector_signal = SIGNAL_TYPE_DVI_DUAL_LINK;
1304 case CONNECTOR_ID_DISPLAY_PORT:
1305 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1307 if (link->hpd_gpio != NULL)
1308 link->irq_source_hpd_rx =
1309 dal_irq_get_rx_source(link->hpd_gpio);
1312 case CONNECTOR_ID_EDP:
1313 link->connector_signal = SIGNAL_TYPE_EDP;
1315 if (link->hpd_gpio != NULL) {
1316 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1317 link->irq_source_hpd_rx =
1318 dal_irq_get_rx_source(link->hpd_gpio);
1321 case CONNECTOR_ID_LVDS:
1322 link->connector_signal = SIGNAL_TYPE_LVDS;
1325 DC_LOG_WARNING("Unsupported Connector type:%d!\n", link->link_id.id);
1329 /* TODO: #DAL3 Implement id to str function.*/
1330 LINK_INFO("Connector[%d] description:"
1332 init_params->connector_index,
1333 link->connector_signal);
1335 ddc_service_init_data.ctx = link->ctx;
1336 ddc_service_init_data.id = link->link_id;
1337 ddc_service_init_data.link = link;
1338 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1340 if (link->ddc == NULL) {
1341 DC_ERROR("Failed to create ddc_service!\n");
1342 goto ddc_create_fail;
1347 dal_ddc_service_get_ddc_pin(link->ddc));
1349 enc_init_data.ctx = dc_ctx;
1350 bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0, &enc_init_data.encoder);
1351 enc_init_data.connector = link->link_id;
1352 enc_init_data.channel = get_ddc_line(link);
1353 enc_init_data.hpd_source = get_hpd_line(link);
1355 link->hpd_src = enc_init_data.hpd_source;
1357 enc_init_data.transmitter =
1358 translate_encoder_to_transmitter(enc_init_data.encoder);
1359 link->link_enc = link->dc->res_pool->funcs->link_enc_create(
1362 if (link->link_enc == NULL) {
1363 DC_ERROR("Failed to create link encoder!\n");
1364 goto link_enc_create_fail;
1367 link->link_enc_hw_inst = link->link_enc->transmitter;
1369 for (i = 0; i < 4; i++) {
1371 bp_funcs->get_device_tag(dc_ctx->dc_bios, link->link_id, i, &link->device_tag)) {
1372 DC_ERROR("Failed to find device tag!\n");
1373 goto device_tag_fail;
1376 /* Look for device tag that matches connector signal,
1377 * CRT for rgb, LCD for other supported signal tyes
1379 if (!bp_funcs->is_device_id_supported(dc_ctx->dc_bios, link->device_tag.dev_id))
1381 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_CRT
1382 && link->connector_signal != SIGNAL_TYPE_RGB)
1384 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_LCD
1385 && link->connector_signal == SIGNAL_TYPE_RGB)
1390 if (bios->integrated_info)
1391 info = *bios->integrated_info;
1393 /* Look for channel mapping corresponding to connector and device tag */
1394 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
1395 struct external_display_path *path =
1396 &info.ext_disp_conn_info.path[i];
1397 if (path->device_connector_id.enum_id == link->link_id.enum_id
1398 && path->device_connector_id.id == link->link_id.id
1399 && path->device_connector_id.type == link->link_id.type) {
1401 if (link->device_tag.acpi_device != 0
1402 && path->device_acpi_enum == link->device_tag.acpi_device) {
1403 link->ddi_channel_mapping = path->channel_mapping;
1404 link->chip_caps = path->caps;
1405 } else if (path->device_tag ==
1406 link->device_tag.dev_id.raw_device_tag) {
1407 link->ddi_channel_mapping = path->channel_mapping;
1408 link->chip_caps = path->caps;
1415 * TODO check if GPIO programmed correctly
1417 * If GPIO isn't programmed correctly HPD might not rise or drain
1418 * fast enough, leading to bounces.
1420 program_hpd_filter(link);
1424 link->link_enc->funcs->destroy(&link->link_enc);
1425 link_enc_create_fail:
1426 dal_ddc_service_destroy(&link->ddc);
1430 if (link->hpd_gpio != NULL) {
1431 dal_gpio_destroy_irq(&link->hpd_gpio);
1432 link->hpd_gpio = NULL;
1438 /*******************************************************************************
1440 ******************************************************************************/
1441 struct dc_link *link_create(const struct link_init_data *init_params)
1443 struct dc_link *link =
1444 kzalloc(sizeof(*link), GFP_KERNEL);
1449 if (false == construct(link, init_params))
1450 goto construct_fail;
1461 void link_destroy(struct dc_link **link)
1468 static void enable_stream_features(struct pipe_ctx *pipe_ctx)
1470 struct dc_stream_state *stream = pipe_ctx->stream;
1471 struct dc_link *link = stream->link;
1472 union down_spread_ctrl old_downspread;
1473 union down_spread_ctrl new_downspread;
1475 core_link_read_dpcd(link, DP_DOWNSPREAD_CTRL,
1476 &old_downspread.raw, sizeof(old_downspread));
1478 new_downspread.raw = old_downspread.raw;
1480 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1481 (stream->ignore_msa_timing_param) ? 1 : 0;
1483 if (new_downspread.raw != old_downspread.raw) {
1484 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
1485 &new_downspread.raw, sizeof(new_downspread));
1489 static enum dc_status enable_link_dp(
1490 struct dc_state *state,
1491 struct pipe_ctx *pipe_ctx)
1493 struct dc_stream_state *stream = pipe_ctx->stream;
1494 enum dc_status status;
1495 bool skip_video_pattern;
1496 struct dc_link *link = stream->link;
1497 struct dc_link_settings link_settings = {0};
1498 enum dp_panel_mode panel_mode;
1499 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
1503 bool apply_seamless_boot_optimization = false;
1505 // check for seamless boot
1506 for (i = 0; i < state->stream_count; i++) {
1507 if (state->streams[i]->apply_seamless_boot_optimization) {
1508 apply_seamless_boot_optimization = true;
1513 /* get link settings for video mode timing */
1514 decide_link_settings(stream, &link_settings);
1516 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
1517 /* If link settings are different than current and link already enabled
1518 * then need to disable before programming to new rate.
1520 if (link->link_status.link_active &&
1521 (link->cur_link_settings.lane_count != link_settings.lane_count ||
1522 link->cur_link_settings.link_rate != link_settings.link_rate)) {
1523 dp_disable_link_phy(link, pipe_ctx->stream->signal);
1526 /*in case it is not on*/
1527 link->dc->hwss.edp_power_control(link, true);
1528 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
1531 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
1532 link_settings.link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
1533 if (state->clk_mgr && !apply_seamless_boot_optimization)
1534 state->clk_mgr->funcs->update_clocks(state->clk_mgr, state, false);
1538 pipe_ctx->stream->signal,
1539 pipe_ctx->clock_source->id,
1542 if (stream->sink_patches.dppowerup_delay > 0) {
1543 int delay_dp_power_up_in_ms = stream->sink_patches.dppowerup_delay;
1545 msleep(delay_dp_power_up_in_ms);
1548 panel_mode = dp_get_panel_mode(link);
1549 dp_set_panel_mode(link, panel_mode);
1551 skip_video_pattern = true;
1553 if (link_settings.link_rate == LINK_RATE_LOW)
1554 skip_video_pattern = false;
1556 if (link->aux_access_disabled) {
1557 dc_link_dp_perform_link_training_skip_aux(link, &link_settings);
1559 link->cur_link_settings = link_settings;
1561 } else if (perform_link_training_with_retries(
1565 LINK_TRAINING_ATTEMPTS)) {
1566 link->cur_link_settings = link_settings;
1570 status = DC_FAIL_DP_LINK_TRAINING;
1572 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
1573 if (link->preferred_training_settings.fec_enable != NULL)
1574 fec_enable = *link->preferred_training_settings.fec_enable;
1578 dp_set_fec_enable(link, fec_enable);
1583 static enum dc_status enable_link_edp(
1584 struct dc_state *state,
1585 struct pipe_ctx *pipe_ctx)
1587 enum dc_status status;
1589 status = enable_link_dp(state, pipe_ctx);
1594 static enum dc_status enable_link_dp_mst(
1595 struct dc_state *state,
1596 struct pipe_ctx *pipe_ctx)
1598 struct dc_link *link = pipe_ctx->stream->link;
1600 /* sink signal type after MST branch is MST. Multiple MST sinks
1601 * share one link. Link DP PHY is enable or training only once.
1603 if (link->cur_link_settings.lane_count != LANE_COUNT_UNKNOWN)
1606 /* clear payload table */
1607 dm_helpers_dp_mst_clear_payload_allocation_table(link->ctx, link);
1609 /* to make sure the pending down rep can be processed
1610 * before enabling the link
1612 dm_helpers_dp_mst_poll_pending_down_reply(link->ctx, link);
1614 /* set the sink to MST mode before enabling the link */
1615 dp_enable_mst_on_sink(link, true);
1617 return enable_link_dp(state, pipe_ctx);
1620 static bool get_ext_hdmi_settings(struct pipe_ctx *pipe_ctx,
1621 enum engine_id eng_id,
1622 struct ext_hdmi_settings *settings)
1624 bool result = false;
1626 struct integrated_info *integrated_info =
1627 pipe_ctx->stream->ctx->dc_bios->integrated_info;
1629 if (integrated_info == NULL)
1633 * Get retimer settings from sbios for passing SI eye test for DCE11
1634 * The setting values are varied based on board revision and port id
1635 * Therefore the setting values of each ports is passed by sbios.
1638 // Check if current bios contains ext Hdmi settings
1639 if (integrated_info->gpu_cap_info & 0x20) {
1641 case ENGINE_ID_DIGA:
1642 settings->slv_addr = integrated_info->dp0_ext_hdmi_slv_addr;
1643 settings->reg_num = integrated_info->dp0_ext_hdmi_6g_reg_num;
1644 settings->reg_num_6g = integrated_info->dp0_ext_hdmi_6g_reg_num;
1645 memmove(settings->reg_settings,
1646 integrated_info->dp0_ext_hdmi_reg_settings,
1647 sizeof(integrated_info->dp0_ext_hdmi_reg_settings));
1648 memmove(settings->reg_settings_6g,
1649 integrated_info->dp0_ext_hdmi_6g_reg_settings,
1650 sizeof(integrated_info->dp0_ext_hdmi_6g_reg_settings));
1653 case ENGINE_ID_DIGB:
1654 settings->slv_addr = integrated_info->dp1_ext_hdmi_slv_addr;
1655 settings->reg_num = integrated_info->dp1_ext_hdmi_6g_reg_num;
1656 settings->reg_num_6g = integrated_info->dp1_ext_hdmi_6g_reg_num;
1657 memmove(settings->reg_settings,
1658 integrated_info->dp1_ext_hdmi_reg_settings,
1659 sizeof(integrated_info->dp1_ext_hdmi_reg_settings));
1660 memmove(settings->reg_settings_6g,
1661 integrated_info->dp1_ext_hdmi_6g_reg_settings,
1662 sizeof(integrated_info->dp1_ext_hdmi_6g_reg_settings));
1665 case ENGINE_ID_DIGC:
1666 settings->slv_addr = integrated_info->dp2_ext_hdmi_slv_addr;
1667 settings->reg_num = integrated_info->dp2_ext_hdmi_6g_reg_num;
1668 settings->reg_num_6g = integrated_info->dp2_ext_hdmi_6g_reg_num;
1669 memmove(settings->reg_settings,
1670 integrated_info->dp2_ext_hdmi_reg_settings,
1671 sizeof(integrated_info->dp2_ext_hdmi_reg_settings));
1672 memmove(settings->reg_settings_6g,
1673 integrated_info->dp2_ext_hdmi_6g_reg_settings,
1674 sizeof(integrated_info->dp2_ext_hdmi_6g_reg_settings));
1677 case ENGINE_ID_DIGD:
1678 settings->slv_addr = integrated_info->dp3_ext_hdmi_slv_addr;
1679 settings->reg_num = integrated_info->dp3_ext_hdmi_6g_reg_num;
1680 settings->reg_num_6g = integrated_info->dp3_ext_hdmi_6g_reg_num;
1681 memmove(settings->reg_settings,
1682 integrated_info->dp3_ext_hdmi_reg_settings,
1683 sizeof(integrated_info->dp3_ext_hdmi_reg_settings));
1684 memmove(settings->reg_settings_6g,
1685 integrated_info->dp3_ext_hdmi_6g_reg_settings,
1686 sizeof(integrated_info->dp3_ext_hdmi_6g_reg_settings));
1693 if (result == true) {
1694 // Validate settings from bios integrated info table
1695 if (settings->slv_addr == 0)
1697 if (settings->reg_num > 9)
1699 if (settings->reg_num_6g > 3)
1702 for (i = 0; i < settings->reg_num; i++) {
1703 if (settings->reg_settings[i].i2c_reg_index > 0x20)
1707 for (i = 0; i < settings->reg_num_6g; i++) {
1708 if (settings->reg_settings_6g[i].i2c_reg_index > 0x20)
1717 static bool i2c_write(struct pipe_ctx *pipe_ctx,
1718 uint8_t address, uint8_t *buffer, uint32_t length)
1720 struct i2c_command cmd = {0};
1721 struct i2c_payload payload = {0};
1723 memset(&payload, 0, sizeof(payload));
1724 memset(&cmd, 0, sizeof(cmd));
1726 cmd.number_of_payloads = 1;
1727 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
1728 cmd.speed = pipe_ctx->stream->ctx->dc->caps.i2c_speed_in_khz;
1730 payload.address = address;
1731 payload.data = buffer;
1732 payload.length = length;
1733 payload.write = true;
1734 cmd.payloads = &payload;
1736 if (dm_helpers_submit_i2c(pipe_ctx->stream->ctx,
1737 pipe_ctx->stream->link, &cmd))
1743 static void write_i2c_retimer_setting(
1744 struct pipe_ctx *pipe_ctx,
1746 bool is_over_340mhz,
1747 struct ext_hdmi_settings *settings)
1749 uint8_t slave_address = (settings->slv_addr >> 1);
1751 const uint8_t apply_rx_tx_change = 0x4;
1752 uint8_t offset = 0xA;
1755 bool i2c_success = false;
1756 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1758 memset(&buffer, 0, sizeof(buffer));
1760 /* Start Ext-Hdmi programming*/
1762 for (i = 0; i < settings->reg_num; i++) {
1763 /* Apply 3G settings */
1764 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
1766 buffer[0] = settings->reg_settings[i].i2c_reg_index;
1767 buffer[1] = settings->reg_settings[i].i2c_reg_val;
1768 i2c_success = i2c_write(pipe_ctx, slave_address,
1769 buffer, sizeof(buffer));
1770 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1771 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
1772 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1776 ASSERT(i2c_success);
1778 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1779 * needs to be set to 1 on every 0xA-0xC write.
1781 if (settings->reg_settings[i].i2c_reg_index == 0xA ||
1782 settings->reg_settings[i].i2c_reg_index == 0xB ||
1783 settings->reg_settings[i].i2c_reg_index == 0xC) {
1785 /* Query current value from offset 0xA */
1786 if (settings->reg_settings[i].i2c_reg_index == 0xA)
1787 value = settings->reg_settings[i].i2c_reg_val;
1790 dal_ddc_service_query_ddc_data(
1791 pipe_ctx->stream->link->ddc,
1792 slave_address, &offset, 1, &value, 1);
1795 ASSERT(i2c_success);
1799 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1800 buffer[1] = value | apply_rx_tx_change;
1801 i2c_success = i2c_write(pipe_ctx, slave_address,
1802 buffer, sizeof(buffer));
1803 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1804 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1805 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1808 ASSERT(i2c_success);
1813 /* Apply 3G settings */
1814 if (is_over_340mhz) {
1815 for (i = 0; i < settings->reg_num_6g; i++) {
1816 /* Apply 3G settings */
1817 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
1819 buffer[0] = settings->reg_settings_6g[i].i2c_reg_index;
1820 buffer[1] = settings->reg_settings_6g[i].i2c_reg_val;
1821 i2c_success = i2c_write(pipe_ctx, slave_address,
1822 buffer, sizeof(buffer));
1823 RETIMER_REDRIVER_INFO("above 340Mhz: retimer write to slave_address = 0x%x,\
1824 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1825 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1829 ASSERT(i2c_success);
1831 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1832 * needs to be set to 1 on every 0xA-0xC write.
1834 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA ||
1835 settings->reg_settings_6g[i].i2c_reg_index == 0xB ||
1836 settings->reg_settings_6g[i].i2c_reg_index == 0xC) {
1838 /* Query current value from offset 0xA */
1839 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA)
1840 value = settings->reg_settings_6g[i].i2c_reg_val;
1843 dal_ddc_service_query_ddc_data(
1844 pipe_ctx->stream->link->ddc,
1845 slave_address, &offset, 1, &value, 1);
1848 ASSERT(i2c_success);
1852 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1853 buffer[1] = value | apply_rx_tx_change;
1854 i2c_success = i2c_write(pipe_ctx, slave_address,
1855 buffer, sizeof(buffer));
1856 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1857 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1858 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1861 ASSERT(i2c_success);
1868 /* Program additional settings if using 640x480 resolution */
1870 /* Write offset 0xFF to 0x01 */
1873 i2c_success = i2c_write(pipe_ctx, slave_address,
1874 buffer, sizeof(buffer));
1875 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1876 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1877 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1880 ASSERT(i2c_success);
1882 /* Write offset 0x00 to 0x23 */
1885 i2c_success = i2c_write(pipe_ctx, slave_address,
1886 buffer, sizeof(buffer));
1887 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1888 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1889 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1892 ASSERT(i2c_success);
1894 /* Write offset 0xff to 0x00 */
1897 i2c_success = i2c_write(pipe_ctx, slave_address,
1898 buffer, sizeof(buffer));
1899 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1900 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1901 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1904 ASSERT(i2c_success);
1909 static void write_i2c_default_retimer_setting(
1910 struct pipe_ctx *pipe_ctx,
1912 bool is_over_340mhz)
1914 uint8_t slave_address = (0xBA >> 1);
1916 bool i2c_success = false;
1917 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1919 memset(&buffer, 0, sizeof(buffer));
1921 /* Program Slave Address for tuning single integrity */
1922 /* Write offset 0x0A to 0x13 */
1925 i2c_success = i2c_write(pipe_ctx, slave_address,
1926 buffer, sizeof(buffer));
1927 RETIMER_REDRIVER_INFO("retimer writes default setting to slave_address = 0x%x,\
1928 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1929 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1932 ASSERT(i2c_success);
1934 /* Write offset 0x0A to 0x17 */
1937 i2c_success = i2c_write(pipe_ctx, slave_address,
1938 buffer, sizeof(buffer));
1939 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1940 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1941 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1944 ASSERT(i2c_success);
1946 /* Write offset 0x0B to 0xDA or 0xD8 */
1948 buffer[1] = is_over_340mhz ? 0xDA : 0xD8;
1949 i2c_success = i2c_write(pipe_ctx, slave_address,
1950 buffer, sizeof(buffer));
1951 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1952 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1953 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1956 ASSERT(i2c_success);
1958 /* Write offset 0x0A to 0x17 */
1961 i2c_success = i2c_write(pipe_ctx, slave_address,
1962 buffer, sizeof(buffer));
1963 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1964 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
1965 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1968 ASSERT(i2c_success);
1970 /* Write offset 0x0C to 0x1D or 0x91 */
1972 buffer[1] = is_over_340mhz ? 0x1D : 0x91;
1973 i2c_success = i2c_write(pipe_ctx, slave_address,
1974 buffer, sizeof(buffer));
1975 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1976 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1977 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1980 ASSERT(i2c_success);
1982 /* Write offset 0x0A to 0x17 */
1985 i2c_success = i2c_write(pipe_ctx, slave_address,
1986 buffer, sizeof(buffer));
1987 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 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);
1992 ASSERT(i2c_success);
1996 /* Program additional settings if using 640x480 resolution */
1998 /* Write offset 0xFF to 0x01 */
2001 i2c_success = i2c_write(pipe_ctx, slave_address,
2002 buffer, sizeof(buffer));
2003 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2004 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
2005 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2008 ASSERT(i2c_success);
2010 /* Write offset 0x00 to 0x23 */
2013 i2c_success = i2c_write(pipe_ctx, slave_address,
2014 buffer, sizeof(buffer));
2015 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
2016 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
2017 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2020 ASSERT(i2c_success);
2022 /* Write offset 0xff to 0x00 */
2025 i2c_success = i2c_write(pipe_ctx, slave_address,
2026 buffer, sizeof(buffer));
2027 RETIMER_REDRIVER_INFO("retimer write default setting to slave_addr = 0x%x,\
2028 offset = 0x%x, reg_val= 0x%x, i2c_success = %d end here\n",
2029 slave_address, buffer[0], buffer[1], i2c_success?1:0);
2032 ASSERT(i2c_success);
2036 static void write_i2c_redriver_setting(
2037 struct pipe_ctx *pipe_ctx,
2038 bool is_over_340mhz)
2040 uint8_t slave_address = (0xF0 >> 1);
2042 bool i2c_success = false;
2043 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2045 memset(&buffer, 0, sizeof(buffer));
2047 // Program Slave Address for tuning single integrity
2051 buffer[6] = is_over_340mhz ? 0x4E : 0x4A;
2053 i2c_success = i2c_write(pipe_ctx, slave_address,
2054 buffer, sizeof(buffer));
2055 RETIMER_REDRIVER_INFO("redriver write 0 to all 16 reg offset expect following:\n\
2056 \t slave_addr = 0x%x, offset[3] = 0x%x, offset[4] = 0x%x,\
2057 offset[5] = 0x%x,offset[6] is_over_340mhz = 0x%x,\
2058 i2c_success = %d\n",
2059 slave_address, buffer[3], buffer[4], buffer[5], buffer[6], i2c_success?1:0);
2063 ASSERT(i2c_success);
2066 static void enable_link_hdmi(struct pipe_ctx *pipe_ctx)
2068 struct dc_stream_state *stream = pipe_ctx->stream;
2069 struct dc_link *link = stream->link;
2070 enum dc_color_depth display_color_depth;
2071 enum engine_id eng_id;
2072 struct ext_hdmi_settings settings = {0};
2073 bool is_over_340mhz = false;
2074 bool is_vga_mode = (stream->timing.h_addressable == 640)
2075 && (stream->timing.v_addressable == 480);
2077 if (stream->phy_pix_clk == 0)
2078 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2079 if (stream->phy_pix_clk > 340000)
2080 is_over_340mhz = true;
2082 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2083 unsigned short masked_chip_caps = pipe_ctx->stream->link->chip_caps &
2084 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
2085 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
2086 /* DP159, Retimer settings */
2087 eng_id = pipe_ctx->stream_res.stream_enc->id;
2089 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings)) {
2090 write_i2c_retimer_setting(pipe_ctx,
2091 is_vga_mode, is_over_340mhz, &settings);
2093 write_i2c_default_retimer_setting(pipe_ctx,
2094 is_vga_mode, is_over_340mhz);
2096 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
2097 /* PI3EQX1204, Redriver settings */
2098 write_i2c_redriver_setting(pipe_ctx, is_over_340mhz);
2102 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2103 dal_ddc_service_write_scdc_data(
2105 stream->phy_pix_clk,
2106 stream->timing.flags.LTE_340MCSC_SCRAMBLE);
2108 memset(&stream->link->cur_link_settings, 0,
2109 sizeof(struct dc_link_settings));
2111 display_color_depth = stream->timing.display_color_depth;
2112 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
2113 display_color_depth = COLOR_DEPTH_888;
2115 link->link_enc->funcs->enable_tmds_output(
2117 pipe_ctx->clock_source->id,
2118 display_color_depth,
2119 pipe_ctx->stream->signal,
2120 stream->phy_pix_clk);
2122 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2123 dal_ddc_service_read_scdc_data(link->ddc);
2126 static void enable_link_lvds(struct pipe_ctx *pipe_ctx)
2128 struct dc_stream_state *stream = pipe_ctx->stream;
2129 struct dc_link *link = stream->link;
2131 if (stream->phy_pix_clk == 0)
2132 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2134 memset(&stream->link->cur_link_settings, 0,
2135 sizeof(struct dc_link_settings));
2137 link->link_enc->funcs->enable_lvds_output(
2139 pipe_ctx->clock_source->id,
2140 stream->phy_pix_clk);
2144 /****************************enable_link***********************************/
2145 static enum dc_status enable_link(
2146 struct dc_state *state,
2147 struct pipe_ctx *pipe_ctx)
2149 enum dc_status status = DC_ERROR_UNEXPECTED;
2150 switch (pipe_ctx->stream->signal) {
2151 case SIGNAL_TYPE_DISPLAY_PORT:
2152 status = enable_link_dp(state, pipe_ctx);
2154 case SIGNAL_TYPE_EDP:
2155 status = enable_link_edp(state, pipe_ctx);
2157 case SIGNAL_TYPE_DISPLAY_PORT_MST:
2158 status = enable_link_dp_mst(state, pipe_ctx);
2161 case SIGNAL_TYPE_DVI_SINGLE_LINK:
2162 case SIGNAL_TYPE_DVI_DUAL_LINK:
2163 case SIGNAL_TYPE_HDMI_TYPE_A:
2164 enable_link_hdmi(pipe_ctx);
2167 case SIGNAL_TYPE_LVDS:
2168 enable_link_lvds(pipe_ctx);
2171 case SIGNAL_TYPE_VIRTUAL:
2178 if (status == DC_OK)
2179 pipe_ctx->stream->link->link_status.link_active = true;
2184 static void disable_link(struct dc_link *link, enum signal_type signal)
2187 * TODO: implement call for dp_set_hw_test_pattern
2188 * it is needed for compliance testing
2191 /* here we need to specify that encoder output settings
2192 * need to be calculated as for the set mode,
2193 * it will lead to querying dynamic link capabilities
2194 * which should be done before enable output */
2196 if (dc_is_dp_signal(signal)) {
2198 if (dc_is_dp_sst_signal(signal))
2199 dp_disable_link_phy(link, signal);
2201 dp_disable_link_phy_mst(link, signal);
2202 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
2204 if (dc_is_dp_sst_signal(signal) ||
2205 link->mst_stream_alloc_table.stream_count == 0) {
2206 dp_set_fec_enable(link, false);
2207 dp_set_fec_ready(link, false);
2211 if (signal != SIGNAL_TYPE_VIRTUAL)
2212 link->link_enc->funcs->disable_output(link->link_enc, signal);
2215 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2216 /* MST disable link only when no stream use the link */
2217 if (link->mst_stream_alloc_table.stream_count <= 0)
2218 link->link_status.link_active = false;
2220 link->link_status.link_active = false;
2224 static uint32_t get_timing_pixel_clock_100hz(const struct dc_crtc_timing *timing)
2227 uint32_t pxl_clk = timing->pix_clk_100hz;
2229 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
2231 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
2232 pxl_clk = pxl_clk * 2 / 3;
2234 if (timing->display_color_depth == COLOR_DEPTH_101010)
2235 pxl_clk = pxl_clk * 10 / 8;
2236 else if (timing->display_color_depth == COLOR_DEPTH_121212)
2237 pxl_clk = pxl_clk * 12 / 8;
2242 static bool dp_active_dongle_validate_timing(
2243 const struct dc_crtc_timing *timing,
2244 const struct dpcd_caps *dpcd_caps)
2246 const struct dc_dongle_caps *dongle_caps = &dpcd_caps->dongle_caps;
2248 switch (dpcd_caps->dongle_type) {
2249 case DISPLAY_DONGLE_DP_VGA_CONVERTER:
2250 case DISPLAY_DONGLE_DP_DVI_CONVERTER:
2251 case DISPLAY_DONGLE_DP_DVI_DONGLE:
2252 if (timing->pixel_encoding == PIXEL_ENCODING_RGB)
2260 if (dpcd_caps->dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER ||
2261 dongle_caps->extendedCapValid == false)
2264 /* Check Pixel Encoding */
2265 switch (timing->pixel_encoding) {
2266 case PIXEL_ENCODING_RGB:
2267 case PIXEL_ENCODING_YCBCR444:
2269 case PIXEL_ENCODING_YCBCR422:
2270 if (!dongle_caps->is_dp_hdmi_ycbcr422_pass_through)
2273 case PIXEL_ENCODING_YCBCR420:
2274 if (!dongle_caps->is_dp_hdmi_ycbcr420_pass_through)
2278 /* Invalid Pixel Encoding*/
2282 switch (timing->display_color_depth) {
2283 case COLOR_DEPTH_666:
2284 case COLOR_DEPTH_888:
2285 /*888 and 666 should always be supported*/
2287 case COLOR_DEPTH_101010:
2288 if (dongle_caps->dp_hdmi_max_bpc < 10)
2291 case COLOR_DEPTH_121212:
2292 if (dongle_caps->dp_hdmi_max_bpc < 12)
2295 case COLOR_DEPTH_141414:
2296 case COLOR_DEPTH_161616:
2298 /* These color depths are currently not supported */
2302 if (get_timing_pixel_clock_100hz(timing) > (dongle_caps->dp_hdmi_max_pixel_clk_in_khz * 10))
2308 enum dc_status dc_link_validate_mode_timing(
2309 const struct dc_stream_state *stream,
2310 struct dc_link *link,
2311 const struct dc_crtc_timing *timing)
2313 uint32_t max_pix_clk = stream->link->dongle_max_pix_clk * 10;
2314 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
2316 /* A hack to avoid failing any modes for EDID override feature on
2317 * topology change such as lower quality cable for DP or different dongle
2319 if (link->remote_sinks[0])
2322 /* Passive Dongle */
2323 if (max_pix_clk != 0 && get_timing_pixel_clock_100hz(timing) > max_pix_clk)
2324 return DC_EXCEED_DONGLE_CAP;
2327 if (!dp_active_dongle_validate_timing(timing, dpcd_caps))
2328 return DC_EXCEED_DONGLE_CAP;
2330 switch (stream->signal) {
2331 case SIGNAL_TYPE_EDP:
2332 case SIGNAL_TYPE_DISPLAY_PORT:
2333 if (!dp_validate_mode_timing(
2336 return DC_NO_DP_LINK_BANDWIDTH;
2346 int dc_link_get_backlight_level(const struct dc_link *link)
2348 struct abm *abm = link->ctx->dc->res_pool->abm;
2350 if (abm == NULL || abm->funcs->get_current_backlight == NULL)
2351 return DC_ERROR_UNEXPECTED;
2353 return (int) abm->funcs->get_current_backlight(abm);
2356 bool dc_link_set_backlight_level(const struct dc_link *link,
2357 uint32_t backlight_pwm_u16_16,
2358 uint32_t frame_ramp)
2360 struct dc *core_dc = link->ctx->dc;
2361 struct abm *abm = core_dc->res_pool->abm;
2362 struct dmcu *dmcu = core_dc->res_pool->dmcu;
2363 unsigned int controller_id = 0;
2364 bool use_smooth_brightness = true;
2366 DC_LOGGER_INIT(link->ctx->logger);
2368 if ((dmcu == NULL) ||
2370 (abm->funcs->set_backlight_level_pwm == NULL))
2373 use_smooth_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
2375 DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n",
2376 backlight_pwm_u16_16, backlight_pwm_u16_16);
2378 if (dc_is_embedded_signal(link->connector_signal)) {
2379 for (i = 0; i < MAX_PIPES; i++) {
2380 if (core_dc->current_state->res_ctx.pipe_ctx[i].stream) {
2381 if (core_dc->current_state->res_ctx.
2382 pipe_ctx[i].stream->link
2384 /* DMCU -1 for all controller id values,
2388 core_dc->current_state->
2389 res_ctx.pipe_ctx[i].stream_res.tg->inst +
2392 /* Disable brightness ramping when the display is blanked
2393 * as it can hang the DMCU
2395 if (core_dc->current_state->res_ctx.pipe_ctx[i].plane_state == NULL)
2400 abm->funcs->set_backlight_level_pwm(
2402 backlight_pwm_u16_16,
2405 use_smooth_brightness);
2411 bool dc_link_set_abm_disable(const struct dc_link *link)
2413 struct dc *core_dc = link->ctx->dc;
2414 struct abm *abm = core_dc->res_pool->abm;
2416 if ((abm == NULL) || (abm->funcs->set_backlight_level_pwm == NULL))
2419 abm->funcs->set_abm_immediate_disable(abm);
2424 bool dc_link_set_psr_allow_active(struct dc_link *link, bool allow_active, bool wait)
2426 struct dc *core_dc = link->ctx->dc;
2427 struct dmcu *dmcu = core_dc->res_pool->dmcu;
2431 if ((dmcu != NULL && dmcu->funcs->is_dmcu_initialized(dmcu)) && link->psr_feature_enabled)
2432 dmcu->funcs->set_psr_enable(dmcu, allow_active, wait);
2434 link->psr_allow_active = allow_active;
2439 bool dc_link_get_psr_state(const struct dc_link *link, uint32_t *psr_state)
2441 struct dc *core_dc = link->ctx->dc;
2442 struct dmcu *dmcu = core_dc->res_pool->dmcu;
2444 if (dmcu != NULL && link->psr_feature_enabled)
2445 dmcu->funcs->get_psr_state(dmcu, psr_state);
2450 static inline enum physical_phy_id
2451 transmitter_to_phy_id(enum transmitter transmitter_value)
2453 switch (transmitter_value) {
2454 case TRANSMITTER_UNIPHY_A:
2456 case TRANSMITTER_UNIPHY_B:
2458 case TRANSMITTER_UNIPHY_C:
2460 case TRANSMITTER_UNIPHY_D:
2462 case TRANSMITTER_UNIPHY_E:
2464 case TRANSMITTER_UNIPHY_F:
2466 case TRANSMITTER_NUTMEG_CRT:
2468 case TRANSMITTER_TRAVIS_CRT:
2470 case TRANSMITTER_TRAVIS_LCD:
2472 case TRANSMITTER_UNIPHY_G:
2474 case TRANSMITTER_COUNT:
2476 case TRANSMITTER_UNKNOWN:
2477 return PHYLD_UNKNOWN;
2479 WARN_ONCE(1, "Unknown transmitter value %d\n",
2481 return PHYLD_UNKNOWN;
2485 bool dc_link_setup_psr(struct dc_link *link,
2486 const struct dc_stream_state *stream, struct psr_config *psr_config,
2487 struct psr_context *psr_context)
2492 /* updateSinkPsrDpcdConfig*/
2493 union dpcd_psr_configuration psr_configuration;
2495 psr_context->controllerId = CONTROLLER_ID_UNDEFINED;
2500 core_dc = link->ctx->dc;
2501 dmcu = core_dc->res_pool->dmcu;
2507 memset(&psr_configuration, 0, sizeof(psr_configuration));
2509 psr_configuration.bits.ENABLE = 1;
2510 psr_configuration.bits.CRC_VERIFICATION = 1;
2511 psr_configuration.bits.FRAME_CAPTURE_INDICATION =
2512 psr_config->psr_frame_capture_indication_req;
2514 /* Check for PSR v2*/
2515 if (psr_config->psr_version == 0x2) {
2516 /* For PSR v2 selective update.
2517 * Indicates whether sink should start capturing
2518 * immediately following active scan line,
2519 * or starting with the 2nd active scan line.
2521 psr_configuration.bits.LINE_CAPTURE_INDICATION = 0;
2522 /*For PSR v2, determines whether Sink should generate
2523 * IRQ_HPD when CRC mismatch is detected.
2525 psr_configuration.bits.IRQ_HPD_WITH_CRC_ERROR = 1;
2528 dm_helpers_dp_write_dpcd(
2532 &psr_configuration.raw,
2533 sizeof(psr_configuration.raw));
2535 psr_context->channel = link->ddc->ddc_pin->hw_info.ddc_channel;
2536 psr_context->transmitterId = link->link_enc->transmitter;
2537 psr_context->engineId = link->link_enc->preferred_engine;
2539 for (i = 0; i < MAX_PIPES; i++) {
2540 if (core_dc->current_state->res_ctx.pipe_ctx[i].stream
2542 /* dmcu -1 for all controller id values,
2545 psr_context->controllerId =
2546 core_dc->current_state->res_ctx.
2547 pipe_ctx[i].stream_res.tg->inst + 1;
2552 /* Hardcoded for now. Can be Pcie or Uniphy (or Unknown)*/
2553 psr_context->phyType = PHY_TYPE_UNIPHY;
2554 /*PhyId is associated with the transmitter id*/
2555 psr_context->smuPhyId =
2556 transmitter_to_phy_id(link->link_enc->transmitter);
2558 psr_context->crtcTimingVerticalTotal = stream->timing.v_total;
2559 psr_context->vsyncRateHz = div64_u64(div64_u64((stream->
2560 timing.pix_clk_100hz * 100),
2561 stream->timing.v_total),
2562 stream->timing.h_total);
2564 psr_context->psrSupportedDisplayConfig = true;
2565 psr_context->psrExitLinkTrainingRequired =
2566 psr_config->psr_exit_link_training_required;
2567 psr_context->sdpTransmitLineNumDeadline =
2568 psr_config->psr_sdp_transmit_line_num_deadline;
2569 psr_context->psrFrameCaptureIndicationReq =
2570 psr_config->psr_frame_capture_indication_req;
2572 psr_context->skipPsrWaitForPllLock = 0; /* only = 1 in KV */
2574 psr_context->numberOfControllers =
2575 link->dc->res_pool->timing_generator_count;
2577 psr_context->rfb_update_auto_en = true;
2579 /* 2 frames before enter PSR. */
2580 psr_context->timehyst_frames = 2;
2582 * (units in 100 lines, i.e. a value of 1 represents 100 lines)
2584 psr_context->hyst_lines = stream->timing.v_total / 2 / 100;
2585 psr_context->aux_repeats = 10;
2587 psr_context->psr_level.u32all = 0;
2589 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
2590 /*skip power down the single pipe since it blocks the cstate*/
2591 if (ASICREV_IS_RAVEN(link->ctx->asic_id.hw_internal_rev))
2592 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
2595 /* SMU will perform additional powerdown sequence.
2596 * For unsupported ASICs, set psr_level flag to skip PSR
2597 * static screen notification to SMU.
2598 * (Always set for DAL2, did not check ASIC)
2600 psr_context->allow_smu_optimizations = psr_config->allow_smu_optimizations;
2602 /* Complete PSR entry before aborting to prevent intermittent
2603 * freezes on certain eDPs
2605 psr_context->psr_level.bits.DISABLE_PSR_ENTRY_ABORT = 1;
2607 /* Controls additional delay after remote frame capture before
2608 * continuing power down, default = 0
2610 psr_context->frame_delay = 0;
2612 link->psr_feature_enabled = dmcu->funcs->setup_psr(dmcu, link, psr_context);
2614 /* psr_enabled == 0 indicates setup_psr did not succeed, but this
2615 * should not happen since firmware should be running at this point
2617 if (link->psr_feature_enabled == 0)
2624 const struct dc_link_status *dc_link_get_status(const struct dc_link *link)
2626 return &link->link_status;
2629 void core_link_resume(struct dc_link *link)
2631 if (link->connector_signal != SIGNAL_TYPE_VIRTUAL)
2632 program_hpd_filter(link);
2635 static struct fixed31_32 get_pbn_per_slot(struct dc_stream_state *stream)
2637 struct fixed31_32 mbytes_per_sec;
2638 uint32_t link_rate_in_mbytes_per_sec = dc_link_bandwidth_kbps(stream->link,
2639 &stream->link->cur_link_settings);
2640 link_rate_in_mbytes_per_sec /= 8000; /* Kbits to MBytes */
2642 mbytes_per_sec = dc_fixpt_from_int(link_rate_in_mbytes_per_sec);
2644 return dc_fixpt_div_int(mbytes_per_sec, 54);
2647 static int get_color_depth(enum dc_color_depth color_depth)
2649 switch (color_depth) {
2650 case COLOR_DEPTH_666: return 6;
2651 case COLOR_DEPTH_888: return 8;
2652 case COLOR_DEPTH_101010: return 10;
2653 case COLOR_DEPTH_121212: return 12;
2654 case COLOR_DEPTH_141414: return 14;
2655 case COLOR_DEPTH_161616: return 16;
2660 static struct fixed31_32 get_pbn_from_timing(struct pipe_ctx *pipe_ctx)
2664 struct fixed31_32 peak_kbps;
2666 uint32_t denominator;
2668 bpc = get_color_depth(pipe_ctx->stream_res.pix_clk_params.color_depth);
2669 kbps = dc_bandwidth_in_kbps_from_timing(&pipe_ctx->stream->timing);
2672 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
2673 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
2674 * common multiplier to render an integer PBN for all link rate/lane
2675 * counts combinations
2677 * peak_kbps *= (1006/1000)
2678 * peak_kbps *= (64/54)
2679 * peak_kbps *= 8 convert to bytes
2682 numerator = 64 * PEAK_FACTOR_X1000;
2683 denominator = 54 * 8 * 1000 * 1000;
2685 peak_kbps = dc_fixpt_from_fraction(kbps, denominator);
2690 static void update_mst_stream_alloc_table(
2691 struct dc_link *link,
2692 struct stream_encoder *stream_enc,
2693 const struct dp_mst_stream_allocation_table *proposed_table)
2695 struct link_mst_stream_allocation work_table[MAX_CONTROLLER_NUM] = {
2697 struct link_mst_stream_allocation *dc_alloc;
2702 /* if DRM proposed_table has more than one new payload */
2703 ASSERT(proposed_table->stream_count -
2704 link->mst_stream_alloc_table.stream_count < 2);
2706 /* copy proposed_table to link, add stream encoder */
2707 for (i = 0; i < proposed_table->stream_count; i++) {
2709 for (j = 0; j < link->mst_stream_alloc_table.stream_count; j++) {
2711 &link->mst_stream_alloc_table.stream_allocations[j];
2713 if (dc_alloc->vcp_id ==
2714 proposed_table->stream_allocations[i].vcp_id) {
2716 work_table[i] = *dc_alloc;
2717 break; /* exit j loop */
2722 if (j == link->mst_stream_alloc_table.stream_count) {
2723 work_table[i].vcp_id =
2724 proposed_table->stream_allocations[i].vcp_id;
2725 work_table[i].slot_count =
2726 proposed_table->stream_allocations[i].slot_count;
2727 work_table[i].stream_enc = stream_enc;
2731 /* update link->mst_stream_alloc_table with work_table */
2732 link->mst_stream_alloc_table.stream_count =
2733 proposed_table->stream_count;
2734 for (i = 0; i < MAX_CONTROLLER_NUM; i++)
2735 link->mst_stream_alloc_table.stream_allocations[i] =
2739 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
2740 * because stream_encoder is not exposed to dm
2742 enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx)
2744 struct dc_stream_state *stream = pipe_ctx->stream;
2745 struct dc_link *link = stream->link;
2746 struct link_encoder *link_encoder = link->link_enc;
2747 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
2748 struct dp_mst_stream_allocation_table proposed_table = {0};
2749 struct fixed31_32 avg_time_slots_per_mtp;
2750 struct fixed31_32 pbn;
2751 struct fixed31_32 pbn_per_slot;
2753 enum act_return_status ret;
2754 DC_LOGGER_INIT(link->ctx->logger);
2756 /* enable_link_dp_mst already check link->enabled_stream_count
2757 * and stream is in link->stream[]. This is called during set mode,
2758 * stream_enc is available.
2761 /* get calculate VC payload for stream: stream_alloc */
2762 if (dm_helpers_dp_mst_write_payload_allocation_table(
2767 update_mst_stream_alloc_table(
2768 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
2771 DC_LOG_WARNING("Failed to update"
2772 "MST allocation table for"
2774 pipe_ctx->pipe_idx);
2777 "stream_count: %d: \n ",
2779 link->mst_stream_alloc_table.stream_count);
2781 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
2782 DC_LOG_MST("stream_enc[%d]: %p "
2783 "stream[%d].vcp_id: %d "
2784 "stream[%d].slot_count: %d\n",
2786 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
2788 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
2790 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
2793 ASSERT(proposed_table.stream_count > 0);
2795 /* program DP source TX for payload */
2796 link_encoder->funcs->update_mst_stream_allocation_table(
2798 &link->mst_stream_alloc_table);
2800 /* send down message */
2801 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
2805 if (ret != ACT_LINK_LOST) {
2806 dm_helpers_dp_mst_send_payload_allocation(
2812 /* slot X.Y for only current stream */
2813 pbn_per_slot = get_pbn_per_slot(stream);
2814 pbn = get_pbn_from_timing(pipe_ctx);
2815 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
2817 stream_encoder->funcs->set_mst_bandwidth(
2819 avg_time_slots_per_mtp);
2825 static enum dc_status deallocate_mst_payload(struct pipe_ctx *pipe_ctx)
2827 struct dc_stream_state *stream = pipe_ctx->stream;
2828 struct dc_link *link = stream->link;
2829 struct link_encoder *link_encoder = link->link_enc;
2830 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
2831 struct dp_mst_stream_allocation_table proposed_table = {0};
2832 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
2834 bool mst_mode = (link->type == dc_connection_mst_branch);
2835 DC_LOGGER_INIT(link->ctx->logger);
2837 /* deallocate_mst_payload is called before disable link. When mode or
2838 * disable/enable monitor, new stream is created which is not in link
2839 * stream[] yet. For this, payload is not allocated yet, so de-alloc
2840 * should not done. For new mode set, map_resources will get engine
2841 * for new stream, so stream_enc->id should be validated until here.
2845 stream_encoder->funcs->set_mst_bandwidth(
2847 avg_time_slots_per_mtp);
2849 /* TODO: which component is responsible for remove payload table? */
2851 if (dm_helpers_dp_mst_write_payload_allocation_table(
2857 update_mst_stream_alloc_table(
2858 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
2861 DC_LOG_WARNING("Failed to update"
2862 "MST allocation table for"
2864 pipe_ctx->pipe_idx);
2869 "stream_count: %d: ",
2871 link->mst_stream_alloc_table.stream_count);
2873 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
2874 DC_LOG_MST("stream_enc[%d]: %p "
2875 "stream[%d].vcp_id: %d "
2876 "stream[%d].slot_count: %d\n",
2878 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
2880 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
2882 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
2885 link_encoder->funcs->update_mst_stream_allocation_table(
2887 &link->mst_stream_alloc_table);
2890 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
2894 dm_helpers_dp_mst_send_payload_allocation(
2902 #if defined(CONFIG_DRM_AMD_DC_HDCP)
2903 static void update_psp_stream_config(struct pipe_ctx *pipe_ctx, bool dpms_off)
2905 struct cp_psp *cp_psp = &pipe_ctx->stream->ctx->cp_psp;
2906 if (cp_psp && cp_psp->funcs.update_stream_config) {
2907 struct cp_psp_stream_config config;
2909 memset(&config, 0, sizeof(config));
2911 config.otg_inst = (uint8_t) pipe_ctx->stream_res.tg->inst;
2912 config.stream_enc_inst = (uint8_t) pipe_ctx->stream_res.stream_enc->id;
2913 config.link_enc_inst = pipe_ctx->stream->link->link_enc_hw_inst;
2914 config.dpms_off = dpms_off;
2915 config.dm_stream_ctx = pipe_ctx->stream->dm_stream_context;
2916 cp_psp->funcs.update_stream_config(cp_psp->handle, &config);
2921 void core_link_enable_stream(
2922 struct dc_state *state,
2923 struct pipe_ctx *pipe_ctx)
2925 struct dc *core_dc = pipe_ctx->stream->ctx->dc;
2926 struct dc_stream_state *stream = pipe_ctx->stream;
2927 enum dc_status status;
2928 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2930 if (!IS_FPGA_MAXIMUS_DC(core_dc->ctx->dce_environment) &&
2931 dc_is_virtual_signal(pipe_ctx->stream->signal))
2934 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)) {
2935 stream->link->link_enc->funcs->setup(
2936 stream->link->link_enc,
2937 pipe_ctx->stream->signal);
2938 pipe_ctx->stream_res.stream_enc->funcs->setup_stereo_sync(
2939 pipe_ctx->stream_res.stream_enc,
2940 pipe_ctx->stream_res.tg->inst,
2941 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
2944 if (dc_is_dp_signal(pipe_ctx->stream->signal))
2945 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
2946 pipe_ctx->stream_res.stream_enc,
2948 stream->output_color_space,
2949 stream->use_vsc_sdp_for_colorimetry,
2950 stream->link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
2952 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
2953 pipe_ctx->stream_res.stream_enc->funcs->hdmi_set_stream_attribute(
2954 pipe_ctx->stream_res.stream_enc,
2956 stream->phy_pix_clk,
2957 pipe_ctx->stream_res.audio != NULL);
2959 pipe_ctx->stream->link->link_state_valid = true;
2961 if (dc_is_dvi_signal(pipe_ctx->stream->signal))
2962 pipe_ctx->stream_res.stream_enc->funcs->dvi_set_stream_attribute(
2963 pipe_ctx->stream_res.stream_enc,
2965 (pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
2968 if (dc_is_lvds_signal(pipe_ctx->stream->signal))
2969 pipe_ctx->stream_res.stream_enc->funcs->lvds_set_stream_attribute(
2970 pipe_ctx->stream_res.stream_enc,
2973 if (!IS_FPGA_MAXIMUS_DC(core_dc->ctx->dce_environment)) {
2974 bool apply_edp_fast_boot_optimization =
2975 pipe_ctx->stream->apply_edp_fast_boot_optimization;
2977 pipe_ctx->stream->apply_edp_fast_boot_optimization = false;
2979 resource_build_info_frame(pipe_ctx);
2980 core_dc->hwss.update_info_frame(pipe_ctx);
2982 /* Do not touch link on seamless boot optimization. */
2983 if (pipe_ctx->stream->apply_seamless_boot_optimization) {
2984 pipe_ctx->stream->dpms_off = false;
2985 #if defined(CONFIG_DRM_AMD_DC_HDCP)
2986 update_psp_stream_config(pipe_ctx, false);
2991 /* eDP lit up by bios already, no need to enable again. */
2992 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
2993 apply_edp_fast_boot_optimization) {
2994 pipe_ctx->stream->dpms_off = false;
2995 #if defined(CONFIG_DRM_AMD_DC_HDCP)
2996 update_psp_stream_config(pipe_ctx, false);
3001 if (pipe_ctx->stream->dpms_off)
3004 status = enable_link(state, pipe_ctx);
3006 if (status != DC_OK) {
3007 DC_LOG_WARNING("enabling link %u failed: %d\n",
3008 pipe_ctx->stream->link->link_index,
3011 /* Abort stream enable *unless* the failure was due to
3012 * DP link training - some DP monitors will recover and
3013 * show the stream anyway. But MST displays can't proceed
3014 * without link training.
3016 if (status != DC_FAIL_DP_LINK_TRAINING ||
3017 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3018 BREAK_TO_DEBUGGER();
3023 core_dc->hwss.enable_audio_stream(pipe_ctx);
3025 /* turn off otg test pattern if enable */
3026 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
3027 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
3028 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
3029 COLOR_DEPTH_UNDEFINED);
3031 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
3032 if (pipe_ctx->stream->timing.flags.DSC) {
3033 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3034 dc_is_virtual_signal(pipe_ctx->stream->signal))
3035 dp_set_dsc_enable(pipe_ctx, true);
3038 core_dc->hwss.enable_stream(pipe_ctx);
3040 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
3041 /* Set DPS PPS SDP (AKA "info frames") */
3042 if (pipe_ctx->stream->timing.flags.DSC) {
3043 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3044 dc_is_virtual_signal(pipe_ctx->stream->signal))
3045 dp_set_dsc_pps_sdp(pipe_ctx, true);
3049 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
3050 dc_link_allocate_mst_payload(pipe_ctx);
3052 core_dc->hwss.unblank_stream(pipe_ctx,
3053 &pipe_ctx->stream->link->cur_link_settings);
3055 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3056 enable_stream_features(pipe_ctx);
3057 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3058 update_psp_stream_config(pipe_ctx, false);
3061 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
3062 else { // if (IS_FPGA_MAXIMUS_DC(core_dc->ctx->dce_environment))
3063 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
3064 dc_is_virtual_signal(pipe_ctx->stream->signal))
3065 dp_set_dsc_enable(pipe_ctx, true);
3071 void core_link_disable_stream(struct pipe_ctx *pipe_ctx)
3073 struct dc *core_dc = pipe_ctx->stream->ctx->dc;
3074 struct dc_stream_state *stream = pipe_ctx->stream;
3075 struct dc_link *link = stream->sink->link;
3077 if (!IS_FPGA_MAXIMUS_DC(core_dc->ctx->dce_environment) &&
3078 dc_is_virtual_signal(pipe_ctx->stream->signal))
3081 #if defined(CONFIG_DRM_AMD_DC_HDCP)
3082 update_psp_stream_config(pipe_ctx, true);
3085 core_dc->hwss.blank_stream(pipe_ctx);
3087 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
3088 deallocate_mst_payload(pipe_ctx);
3090 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
3091 struct ext_hdmi_settings settings = {0};
3092 enum engine_id eng_id = pipe_ctx->stream_res.stream_enc->id;
3094 unsigned short masked_chip_caps = link->chip_caps &
3095 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
3096 //Need to inform that sink is going to use legacy HDMI mode.
3097 dal_ddc_service_write_scdc_data(
3099 165000,//vbios only handles 165Mhz.
3101 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
3102 /* DP159, Retimer settings */
3103 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings))
3104 write_i2c_retimer_setting(pipe_ctx,
3105 false, false, &settings);
3107 write_i2c_default_retimer_setting(pipe_ctx,
3109 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
3110 /* PI3EQX1204, Redriver settings */
3111 write_i2c_redriver_setting(pipe_ctx, false);
3114 core_dc->hwss.disable_stream(pipe_ctx);
3116 disable_link(pipe_ctx->stream->link, pipe_ctx->stream->signal);
3117 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
3118 if (pipe_ctx->stream->timing.flags.DSC) {
3119 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3120 dp_set_dsc_enable(pipe_ctx, false);
3125 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
3127 struct dc *core_dc = pipe_ctx->stream->ctx->dc;
3129 if (!dc_is_hdmi_signal(pipe_ctx->stream->signal))
3132 core_dc->hwss.set_avmute(pipe_ctx, enable);
3136 *****************************************************************************
3137 * Function: dc_link_enable_hpd_filter
3140 * If enable is true, programs HPD filter on associated HPD line using
3141 * delay_on_disconnect/delay_on_connect values dependent on
3142 * link->connector_signal
3144 * If enable is false, programs HPD filter on associated HPD line with no
3145 * delays on connect or disconnect
3147 * @param [in] link: pointer to the dc link
3148 * @param [in] enable: boolean specifying whether to enable hbd
3149 *****************************************************************************
3151 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
3156 link->is_hpd_filter_disabled = false;
3157 program_hpd_filter(link);
3159 link->is_hpd_filter_disabled = true;
3160 /* Obtain HPD handle */
3161 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
3166 /* Setup HPD filtering */
3167 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
3168 struct gpio_hpd_config config;
3170 config.delay_on_connect = 0;
3171 config.delay_on_disconnect = 0;
3173 dal_irq_setup_hpd_filter(hpd, &config);
3175 dal_gpio_close(hpd);
3177 ASSERT_CRITICAL(false);
3179 /* Release HPD handle */
3180 dal_gpio_destroy_irq(&hpd);
3184 uint32_t dc_bandwidth_in_kbps_from_timing(
3185 const struct dc_crtc_timing *timing)
3187 uint32_t bits_per_channel = 0;
3190 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
3191 if (timing->flags.DSC) {
3192 kbps = (timing->pix_clk_100hz * timing->dsc_cfg.bits_per_pixel);
3193 kbps = kbps / 160 + ((kbps % 160) ? 1 : 0);
3198 switch (timing->display_color_depth) {
3199 case COLOR_DEPTH_666:
3200 bits_per_channel = 6;
3202 case COLOR_DEPTH_888:
3203 bits_per_channel = 8;
3205 case COLOR_DEPTH_101010:
3206 bits_per_channel = 10;
3208 case COLOR_DEPTH_121212:
3209 bits_per_channel = 12;
3211 case COLOR_DEPTH_141414:
3212 bits_per_channel = 14;
3214 case COLOR_DEPTH_161616:
3215 bits_per_channel = 16;
3221 ASSERT(bits_per_channel != 0);
3223 kbps = timing->pix_clk_100hz / 10;
3224 kbps *= bits_per_channel;
3226 if (timing->flags.Y_ONLY != 1) {
3227 /*Only YOnly make reduce bandwidth by 1/3 compares to RGB*/
3229 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
3231 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
3232 kbps = kbps * 2 / 3;
3239 void dc_link_set_drive_settings(struct dc *dc,
3240 struct link_training_settings *lt_settings,
3241 const struct dc_link *link)
3246 for (i = 0; i < dc->link_count; i++) {
3247 if (dc->links[i] == link)
3251 if (i >= dc->link_count)
3252 ASSERT_CRITICAL(false);
3254 dc_link_dp_set_drive_settings(dc->links[i], lt_settings);
3257 void dc_link_perform_link_training(struct dc *dc,
3258 struct dc_link_settings *link_setting,
3259 bool skip_video_pattern)
3263 for (i = 0; i < dc->link_count; i++)
3264 dc_link_dp_perform_link_training(
3267 skip_video_pattern);
3270 void dc_link_set_preferred_link_settings(struct dc *dc,
3271 struct dc_link_settings *link_setting,
3272 struct dc_link *link)
3275 struct pipe_ctx *pipe;
3276 struct dc_stream_state *link_stream;
3277 struct dc_link_settings store_settings = *link_setting;
3279 link->preferred_link_setting = store_settings;
3281 /* Retrain with preferred link settings only relevant for
3283 * Check for non-DP signal or if passive dongle present
3285 if (!dc_is_dp_signal(link->connector_signal) ||
3286 link->dongle_max_pix_clk > 0)
3289 for (i = 0; i < MAX_PIPES; i++) {
3290 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
3291 if (pipe->stream && pipe->stream->link) {
3292 if (pipe->stream->link == link) {
3293 link_stream = pipe->stream;
3299 /* Stream not found */
3303 /* Cannot retrain link if backend is off */
3304 if (link_stream->dpms_off)
3307 decide_link_settings(link_stream, &store_settings);
3309 if ((store_settings.lane_count != LANE_COUNT_UNKNOWN) &&
3310 (store_settings.link_rate != LINK_RATE_UNKNOWN))
3311 dp_retrain_link_dp_test(link, &store_settings, false);
3314 void dc_link_set_preferred_training_settings(struct dc *dc,
3315 struct dc_link_settings *link_setting,
3316 struct dc_link_training_overrides *lt_overrides,
3317 struct dc_link *link,
3318 bool skip_immediate_retrain)
3320 if (lt_overrides != NULL)
3321 link->preferred_training_settings = *lt_overrides;
3323 memset(&link->preferred_training_settings, 0, sizeof(link->preferred_training_settings));
3325 if (link_setting != NULL) {
3326 link->preferred_link_setting = *link_setting;
3328 link->preferred_link_setting.lane_count = LANE_COUNT_UNKNOWN;
3329 link->preferred_link_setting.link_rate = LINK_RATE_UNKNOWN;
3332 /* Retrain now, or wait until next stream update to apply */
3333 if (skip_immediate_retrain == false)
3334 dc_link_set_preferred_link_settings(dc, &link->preferred_link_setting, link);
3337 void dc_link_enable_hpd(const struct dc_link *link)
3339 dc_link_dp_enable_hpd(link);
3342 void dc_link_disable_hpd(const struct dc_link *link)
3344 dc_link_dp_disable_hpd(link);
3347 void dc_link_set_test_pattern(struct dc_link *link,
3348 enum dp_test_pattern test_pattern,
3349 const struct link_training_settings *p_link_settings,
3350 const unsigned char *p_custom_pattern,
3351 unsigned int cust_pattern_size)
3354 dc_link_dp_set_test_pattern(
3362 uint32_t dc_link_bandwidth_kbps(
3363 const struct dc_link *link,
3364 const struct dc_link_settings *link_setting)
3366 uint32_t link_bw_kbps =
3367 link_setting->link_rate * LINK_RATE_REF_FREQ_IN_KHZ; /* bytes per sec */
3369 link_bw_kbps *= 8; /* 8 bits per byte*/
3370 link_bw_kbps *= link_setting->lane_count;
3372 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
3373 if (link->dpcd_caps.fec_cap.bits.FEC_CAPABLE) {
3374 /* Account for FEC overhead.
3375 * We have to do it based on caps,
3376 * and not based on FEC being set ready,
3377 * because FEC is set ready too late in
3378 * the process to correctly be picked up
3379 * by mode enumeration.
3381 * There's enough zeros at the end of 'kbps'
3382 * that make the below operation 100% precise
3384 * 'long long' makes it work even for HDMI 2.1
3385 * max bandwidth (and much, much bigger bandwidths
3386 * than that, actually).
3388 * NOTE: Reducing link BW by 3% may not be precise
3389 * because it may be a stream BT that increases by 3%, and so
3390 * 1/1.03 = 0.970873 factor should have been used instead,
3391 * but the difference is minimal and is in a safe direction,
3392 * which all works well around potential ambiguity of DP 1.4a spec.
3394 link_bw_kbps = mul_u64_u32_shr(BIT_ULL(32) * 970LL / 1000,
3399 return link_bw_kbps;
3403 const struct dc_link_settings *dc_link_get_link_cap(
3404 const struct dc_link *link)
3406 if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
3407 link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
3408 return &link->preferred_link_setting;
3409 return &link->verified_link_cap;