drm/amd/display: create accessories, hwss and protocols sub folders in link
authorWenjing Liu <wenjing.liu@amd.com>
Fri, 16 Dec 2022 22:16:19 +0000 (17:16 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 24 Jan 2023 18:26:25 +0000 (13:26 -0500)
[why]
link component contains three sub folders:

accessories - utilities for improving testability, logging or tracing, doesn't impact
end user use cases.

protocols - specs defined protocols used in end user use cases

hwss - hwss owned link_hwss object, served as an abstraction layer in hwss to
access various types of encoder/phy/dpia endpoints in a unified interface.

sooner we will have files directly under link folder one for the implementation of
each major link behavior such as link_create, link_detect, link_validate
and link_set_dpms.

Reviewed-by: George Shen <George.Shen@amd.com>
Reviewed-by: Jun Lei <Jun.Lei@amd.com>
Acked-by: Alan Liu <HaoPing.Liu@amd.com>
Signed-off-by: Wenjing Liu <wenjing.liu@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
79 files changed:
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
drivers/gpu/drm/amd/display/dc/core/dc_link.c
drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c
drivers/gpu/drm/amd/display/dc/core/dc_resource.c
drivers/gpu/drm/amd/display/dc/dc_link.h
drivers/gpu/drm/amd/display/dc/dce110/dce110_hw_sequencer.c
drivers/gpu/drm/amd/display/dc/hdcp/hdcp_msg.c
drivers/gpu/drm/amd/display/dc/inc/dc_link_dp.h
drivers/gpu/drm/amd/display/dc/inc/link.h
drivers/gpu/drm/amd/display/dc/link/Makefile
drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_trace.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_trace.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dio.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dio.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dpia.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dpia.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_hpo_dp.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_hpo_dp.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/link_ddc.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_ddc.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_capability.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_capability.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_dpia.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_dpia.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_dpia_bw.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_dpia_bw.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_phy.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_phy.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_trace.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_trace.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_128b_132b.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_128b_132b.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_8b_10b.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_8b_10b.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_auxless.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_auxless.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_dpia.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_dpia.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_fixed_vs_pe_retimer.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dp_training_fixed_vs_pe_retimer.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dpcd.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_dpcd.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hpd.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hpd.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hwss_dio.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hwss_dio.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hwss_dpia.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hwss_dpia.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_dp.c [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_dp.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_frl.h [deleted file]
drivers/gpu/drm/amd/display/dc/link/protocols/link_ddc.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_ddc.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_128b_132b.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_128b_132b.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_8b_10b.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_8b_10b.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_auxless.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_auxless.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_fixed_vs_pe_retimer.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_fixed_vs_pe_retimer.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_hpd.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/link/protocols/link_hpd.h [new file with mode: 0644]

index 4c0d3ab37906c245d38588c57d7273251470cf72..2e7ae42388484b0f291c7bed59e97be393b69ca3 100644 (file)
@@ -40,7 +40,7 @@
 #include "dc/dc_stat.h"
 #include "amdgpu_dm_trace.h"
 #include "dpcd_defs.h"
-#include "link/link_dpcd.h"
+#include "link/protocols/link_dpcd.h"
 #include "link_service_types.h"
 
 #include "vid.h"
index bf5a31e2be8a290a82f592ad59571ed3cefd5c59..94dc53d592f0d3ef5134e65fe636c21820d9f22e 100644 (file)
@@ -33,8 +33,8 @@
 #include "gpio_service_interface.h"
 #include "core_status.h"
 #include "dc_link_dp.h"
-#include "link/link_dp_dpia.h"
-#include "link/link_ddc.h"
+#include "link/protocols/link_dp_dpia.h"
+#include "link/protocols/link_ddc.h"
 #include "link_hwss.h"
 #include "link.h"
 #include "opp.h"
 #include "dmub/dmub_srv.h"
 #include "inc/hw/panel_cntl.h"
 #include "inc/link_enc_cfg.h"
-#include "link/link_dpcd.h"
-#include "link/link_dp_trace.h"
-#include "link/link_hpd.h"
-#include "link/link_dp_training.h"
-#include "link/link_dp_phy.h"
-#include "link/link_dp_capability.h"
+#include "link/protocols/link_dpcd.h"
+#include "link/accessories/link_dp_trace.h"
+#include "link/protocols/link_hpd.h"
+#include "link/protocols/link_dp_training.h"
+#include "link/protocols/link_dp_phy.h"
+#include "link/protocols/link_dp_capability.h"
 
 #include "dc/dcn30/dcn30_vpg.h"
 
@@ -4567,7 +4567,7 @@ void dc_link_set_drive_settings(struct dc *dc,
                ASSERT_CRITICAL(false);
 
        dc_link_get_cur_link_res(link, &link_res);
-       dc_link_dp_set_drive_settings(dc->links[i], &link_res, lt_settings);
+       dp_set_drive_settings(dc->links[i], &link_res, lt_settings);
 }
 
 void dc_link_set_preferred_link_settings(struct dc *dc,
index ab09df7f6d107fe0108803343b080cd32c2968d5..8f7505bbe8983b72979debc077f96b2e751a7f97 100644 (file)
 
 #include "inc/core_types.h"
 #include "link_hwss.h"
-#include "link/link_ddc.h"
+#include "link/protocols/link_ddc.h"
 #include "core_status.h"
 #include "dpcd_defs.h"
 
 #include "dc_dmub_srv.h"
 #include "dce/dmub_hw_lock_mgr.h"
-#include "link/link_dp_dpia.h"
+#include "link/protocols/link_dp_dpia.h"
 #include "inc/link_enc_cfg.h"
 #include "clk_mgr.h"
-#include "link/link_dp_trace.h"
-#include "link/link_dp_training.h"
-#include "link/link_dp_training_fixed_vs_pe_retimer.h"
-#include "link/link_dp_training_dpia.h"
-#include "link/link_dp_training_auxless.h"
-#include "link/link_dp_phy.h"
-#include "link/link_dp_capability.h"
+#include "link/accessories/link_dp_trace.h"
+#include "link/protocols/link_dp_training.h"
+#include "link/protocols/link_dp_training_fixed_vs_pe_retimer.h"
+#include "link/protocols/link_dp_training_dpia.h"
+#include "link/protocols/link_dp_training_auxless.h"
+#include "link/protocols/link_dp_phy.h"
+#include "link/protocols/link_dp_capability.h"
 #define DC_LOGGER \
        link->ctx->logger
 
 #define DC_TRACE_LEVEL_MESSAGE(...) /* do nothing */
-#include "link/link_dpcd.h"
+#include "link/protocols/link_dpcd.h"
 
 static uint8_t get_nibble_at_index(const uint8_t *buf,
        uint32_t index)
index a5b5f8592c1b80b8d0ce1ef44b016954d0e1a892..2a46f2869b54a74f7ae0b2bd4decfd63c6c1d420 100644 (file)
@@ -43,9 +43,9 @@
 #include "dc_link_dp.h"
 #include "link.h"
 #include "virtual/virtual_link_hwss.h"
-#include "link/link_hwss_dio.h"
-#include "link/link_hwss_dpia.h"
-#include "link/link_hwss_hpo_dp.h"
+#include "link/hwss/link_hwss_dio.h"
+#include "link/hwss/link_hwss_dpia.h"
+#include "link/hwss/link_hwss_hpo_dp.h"
 
 #if defined(CONFIG_DRM_AMD_DC_SI)
 #include "dce60/dce60_resource.h"
index 48f6a5b0933611ab3fabd607fd429ee3be065644..d86e84f417cc4cb823f2150cfeba1e0b9f7fdab2 100644 (file)
@@ -456,11 +456,6 @@ void dc_link_remove_remote_sink(
 
 /* Used by diagnostics for virtual link at the moment */
 
-void dc_link_dp_set_drive_settings(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings);
-
 bool dc_link_dp_set_test_pattern(
        struct dc_link *link,
        enum dp_test_pattern test_pattern,
index a51bd21a796f974499255e9a3802af5903c18f43..926963a993a9cc4b528b0563045ccf9bdb78640b 100644 (file)
@@ -65,7 +65,6 @@
 
 #include "dcn10/dcn10_hw_sequencer.h"
 
-#include "link/link_dp_trace.h"
 #include "dce110_hw_sequencer.h"
 
 #define GAMMA_HW_POINTS_NUM 256
@@ -807,19 +806,19 @@ void dce110_edp_power_control(
                                div64_u64(dm_get_elapse_time_in_ns(
                                                ctx,
                                                current_ts,
-                                               dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
+                                               link_dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
                unsigned long long time_since_edp_poweron_ms =
                                div64_u64(dm_get_elapse_time_in_ns(
                                                ctx,
                                                current_ts,
-                                               dp_trace_get_edp_poweron_timestamp(link)), 1000000);
+                                               link_dp_trace_get_edp_poweron_timestamp(link)), 1000000);
                DC_LOG_HW_RESUME_S3(
                                "%s: transition: power_up=%d current_ts=%llu edp_poweroff=%llu edp_poweron=%llu time_since_edp_poweroff_ms=%llu time_since_edp_poweron_ms=%llu",
                                __func__,
                                power_up,
                                current_ts,
-                               dp_trace_get_edp_poweroff_timestamp(link),
-                               dp_trace_get_edp_poweron_timestamp(link),
+                               link_dp_trace_get_edp_poweroff_timestamp(link),
+                               link_dp_trace_get_edp_poweron_timestamp(link),
                                time_since_edp_poweroff_ms,
                                time_since_edp_poweron_ms);
 
@@ -834,7 +833,7 @@ void dce110_edp_power_control(
                                        link->panel_config.pps.extra_t12_ms;
 
                        /* Adjust remaining_min_edp_poweroff_time_ms if this is not the first time. */
-                       if (dp_trace_get_edp_poweroff_timestamp(link) != 0) {
+                       if (link_dp_trace_get_edp_poweroff_timestamp(link) != 0) {
                                if (time_since_edp_poweroff_ms < remaining_min_edp_poweroff_time_ms)
                                        remaining_min_edp_poweroff_time_ms =
                                                remaining_min_edp_poweroff_time_ms - time_since_edp_poweroff_ms;
@@ -894,13 +893,13 @@ void dce110_edp_power_control(
                                __func__, (power_up ? "On":"Off"),
                                bp_result);
 
-               dp_trace_set_edp_power_timestamp(link, power_up);
+               link_dp_trace_set_edp_power_timestamp(link, power_up);
 
                DC_LOG_HW_RESUME_S3(
                                "%s: updated values: edp_poweroff=%llu edp_poweron=%llu\n",
                                __func__,
-                               dp_trace_get_edp_poweroff_timestamp(link),
-                               dp_trace_get_edp_poweron_timestamp(link));
+                               link_dp_trace_get_edp_poweroff_timestamp(link),
+                               link_dp_trace_get_edp_poweron_timestamp(link));
 
                if (bp_result != BP_RESULT_OK)
                        DC_LOG_ERROR(
@@ -928,14 +927,14 @@ void dce110_edp_wait_for_T12(
                return;
 
        if (!link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl) &&
-                       dp_trace_get_edp_poweroff_timestamp(link) != 0) {
+                       link_dp_trace_get_edp_poweroff_timestamp(link) != 0) {
                unsigned int t12_duration = 500; // Default T12 as per spec
                unsigned long long current_ts = dm_get_timestamp(ctx);
                unsigned long long time_since_edp_poweroff_ms =
                                div64_u64(dm_get_elapse_time_in_ns(
                                                ctx,
                                                current_ts,
-                                               dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
+                                               link_dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
 
                t12_duration += link->panel_config.pps.extra_t12_ms; // Add extra T12
 
index 906a43e85f6dbadfef123f0df1c0f61f36ad6e9a..e1422e5e86c92e57573ddc43de405b90caa3c492 100644 (file)
@@ -32,7 +32,7 @@
 #include "core_types.h"
 #include "link.h"
 #include "link_hwss.h"
-#include "link/link_dpcd.h"
+#include "link/protocols/link_dpcd.h"
 
 #define DC_LOGGER \
        link->ctx->logger
index 52e1aad1fce8917abe4f1e821f42d88e2df4823e..31613c58e5eb0481bc00cf9e0be423edd1bda022 100644 (file)
@@ -47,12 +47,6 @@ enum {
        PEAK_FACTOR_X1000 = 1006,
 };
 
-
-bool dp_verify_link_cap_with_retries(
-       struct dc_link *link,
-       struct dc_link_settings *known_limit_link_setting,
-       int attempts);
-
 bool dp_validate_mode_timing(
        struct dc_link *link,
        const struct dc_crtc_timing *timing);
@@ -70,8 +64,6 @@ void dp_enable_mst_on_sink(struct dc_link *link, bool enable);
 enum dp_panel_mode dp_get_panel_mode(struct dc_link *link);
 void dp_set_panel_mode(struct dc_link *link, enum dp_panel_mode panel_mode);
 
-void dpcd_write_cable_id_to_dprx(struct dc_link *link);
-
 enum dc_status dp_set_fec_ready(struct dc_link *link, const struct link_resource *link_res, bool ready);
 void dp_set_fec_enable(struct dc_link *link, bool enable);
 bool dp_set_dsc_enable(struct pipe_ctx *pipe_ctx, bool enable);
@@ -80,12 +72,6 @@ void dp_set_dsc_on_stream(struct pipe_ctx *pipe_ctx, bool enable);
 bool dp_update_dsc_config(struct pipe_ctx *pipe_ctx);
 bool dp_set_dsc_on_rx(struct pipe_ctx *pipe_ctx, bool enable);
 
-/* Initialize output parameter lt_settings. */
-void dp_decide_training_settings(
-       struct dc_link *link,
-       const struct dc_link_settings *link_setting,
-       struct link_training_settings *lt_settings);
-
 bool dpcd_write_128b_132b_sst_payload_allocation_table(
                const struct dc_stream_state *stream,
                struct dc_link *link,
@@ -97,12 +83,6 @@ bool dpcd_poll_for_allocation_change_trigger(struct dc_link *link);
 struct fixed31_32 calculate_sst_avg_time_slots_per_mtp(
                const struct dc_stream_state *stream,
                const struct dc_link *link);
-void enable_dp_hpo_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct dc_link_settings *link_settings);
-void disable_dp_hpo_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal);
 void setup_dp_hpo_stream(struct pipe_ctx *pipe_ctx, bool enable);
 void edp_panel_backlight_power_on(struct dc_link *link, bool wait_for_hpd);
 void dp_source_sequence_trace(struct dc_link *link, uint8_t dp_test_mode);
index 3945522fb798213b68b95b1663349424d8d320e6..b176dcfa1469010be33795029e5da01adbfa9f12 100644 (file)
@@ -89,4 +89,9 @@ bool link_decide_link_settings(
        struct dc_stream_state *stream,
        struct dc_link_settings *link_setting);
 
+void link_dp_trace_set_edp_power_timestamp(struct dc_link *link,
+               bool power_up);
+uint64_t link_dp_trace_get_edp_poweron_timestamp(struct dc_link *link);
+uint64_t link_dp_trace_get_edp_poweroff_timestamp(struct dc_link *link);
+
 #endif /* __DC_LINK_HPD_H__ */
index 4dee0e6248b1df9058be35116a7235f9a88889e9..abfd79ba361748b432d70ef0edc6cf306f4863b0 100644 (file)
 # It abstracts the control and status of back end pipe such as DIO, HPO, DPIA,
 # PHY, HPD, DDC and etc).
 
-LINK = link_hwss_dio.o link_hwss_dpia.o link_hwss_hpo_dp.o link_dp_trace.o \
-link_hpd.o link_ddc.o link_dpcd.o link_dp_dpia.o link_dp_training.o \
-link_dp_training_8b_10b.o link_dp_training_128b_132b.o link_dp_training_dpia.o \
-link_dp_training_auxless.o link_dp_training_fixed_vs_pe_retimer.o link_dp_phy.o \
-link_dp_capability.o
+###############################################################################
+# accessories
+###############################################################################
+LINK_ACCESSORIES = link_dp_trace.o
 
-AMD_DAL_LINK = $(addprefix $(AMDDALPATH)/dc/link/,$(LINK))
+AMD_DAL_LINK_ACCESSORIES = $(addprefix $(AMDDALPATH)/dc/link/accessories/, \
+$(LINK_ACCESSORIES))
 
-AMD_DISPLAY_FILES += $(AMD_DAL_LINK)
+AMD_DISPLAY_FILES += $(AMD_DAL_LINK_ACCESSORIES)
+###############################################################################
+# hwss
+###############################################################################
+LINK_HWSS = link_hwss_dio.o link_hwss_dpia.o link_hwss_hpo_dp.o
+
+AMD_DAL_LINK_HWSS = $(addprefix $(AMDDALPATH)/dc/link/hwss/, \
+$(LINK_HWSS))
+
+AMD_DISPLAY_FILES += $(AMD_DAL_LINK_HWSS)
+###############################################################################
+# protocols
+###############################################################################
+LINK_PROTOCOLS = link_hpd.o link_ddc.o link_dpcd.o link_dp_dpia.o \
+link_dp_training.o link_dp_training_8b_10b.o link_dp_training_128b_132b.o \
+link_dp_training_dpia.o link_dp_training_auxless.o \
+link_dp_training_fixed_vs_pe_retimer.o link_dp_phy.o link_dp_capability.o
+
+AMD_DAL_LINK_PROTOCOLS = $(addprefix $(AMDDALPATH)/dc/link/protocols/, \
+$(LINK_PROTOCOLS))
+
+AMD_DISPLAY_FILES += $(AMD_DAL_LINK_PROTOCOLS)
\ No newline at end of file
diff --git a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_trace.c b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_trace.c
new file mode 100644 (file)
index 0000000..04838a3
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#include "dc_link.h"
+#include "link_dp_trace.h"
+
+void dp_trace_init(struct dc_link *link)
+{
+       memset(&link->dp_trace, 0, sizeof(link->dp_trace));
+       link->dp_trace.is_initialized = true;
+}
+
+void dp_trace_reset(struct dc_link *link)
+{
+       memset(&link->dp_trace, 0, sizeof(link->dp_trace));
+}
+
+bool dc_dp_trace_is_initialized(struct dc_link *link)
+{
+       return link->dp_trace.is_initialized;
+}
+
+void dp_trace_detect_lt_init(struct dc_link *link)
+{
+       memset(&link->dp_trace.detect_lt_trace, 0, sizeof(link->dp_trace.detect_lt_trace));
+}
+
+void dp_trace_commit_lt_init(struct dc_link *link)
+{
+       memset(&link->dp_trace.commit_lt_trace, 0, sizeof(link->dp_trace.commit_lt_trace));
+}
+
+void dp_trace_link_loss_increment(struct dc_link *link)
+{
+       link->dp_trace.link_loss_count++;
+}
+
+void dp_trace_lt_fail_count_update(struct dc_link *link,
+               unsigned int fail_count,
+               bool in_detection)
+{
+       if (in_detection)
+               link->dp_trace.detect_lt_trace.counts.fail = fail_count;
+       else
+               link->dp_trace.commit_lt_trace.counts.fail = fail_count;
+}
+
+void dp_trace_lt_total_count_increment(struct dc_link *link,
+               bool in_detection)
+{
+       if (in_detection)
+               link->dp_trace.detect_lt_trace.counts.total++;
+       else
+               link->dp_trace.commit_lt_trace.counts.total++;
+}
+
+void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
+               bool in_detection,
+               bool is_logged)
+{
+       if (in_detection)
+               link->dp_trace.detect_lt_trace.is_logged = is_logged;
+       else
+               link->dp_trace.commit_lt_trace.is_logged = is_logged;
+}
+
+bool dc_dp_trace_is_logged(struct dc_link *link,
+               bool in_detection)
+{
+       if (in_detection)
+               return link->dp_trace.detect_lt_trace.is_logged;
+       else
+               return link->dp_trace.commit_lt_trace.is_logged;
+}
+
+void dp_trace_lt_result_update(struct dc_link *link,
+               enum link_training_result result,
+               bool in_detection)
+{
+       if (in_detection)
+               link->dp_trace.detect_lt_trace.result = result;
+       else
+               link->dp_trace.commit_lt_trace.result = result;
+}
+
+void dp_trace_set_lt_start_timestamp(struct dc_link *link,
+               bool in_detection)
+{
+       if (in_detection)
+               link->dp_trace.detect_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx);
+       else
+               link->dp_trace.commit_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx);
+}
+
+void dp_trace_set_lt_end_timestamp(struct dc_link *link,
+               bool in_detection)
+{
+       if (in_detection)
+               link->dp_trace.detect_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx);
+       else
+               link->dp_trace.commit_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx);
+}
+
+unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
+               bool in_detection)
+{
+       if (in_detection)
+               return link->dp_trace.detect_lt_trace.timestamps.end;
+       else
+               return link->dp_trace.commit_lt_trace.timestamps.end;
+}
+
+struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
+               bool in_detection)
+{
+       if (in_detection)
+               return &link->dp_trace.detect_lt_trace.counts;
+       else
+               return &link->dp_trace.commit_lt_trace.counts;
+}
+
+unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link)
+{
+       return link->dp_trace.link_loss_count;
+}
+
+void link_dp_trace_set_edp_power_timestamp(struct dc_link *link,
+               bool power_up)
+{
+       if (!power_up)
+               /*save driver power off time stamp*/
+               link->dp_trace.edp_trace_power_timestamps.poweroff = dm_get_timestamp(link->dc->ctx);
+       else
+               link->dp_trace.edp_trace_power_timestamps.poweron = dm_get_timestamp(link->dc->ctx);
+}
+
+uint64_t link_dp_trace_get_edp_poweron_timestamp(struct dc_link *link)
+{
+       return link->dp_trace.edp_trace_power_timestamps.poweron;
+}
+
+uint64_t link_dp_trace_get_edp_poweroff_timestamp(struct dc_link *link)
+{
+       return link->dp_trace.edp_trace_power_timestamps.poweroff;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_trace.h b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_trace.h
new file mode 100644 (file)
index 0000000..702f97c
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#ifndef __LINK_DP_TRACE_H__
+#define __LINK_DP_TRACE_H__
+
+void dp_trace_init(struct dc_link *link);
+void dp_trace_reset(struct dc_link *link);
+bool dc_dp_trace_is_initialized(struct dc_link *link);
+void dp_trace_detect_lt_init(struct dc_link *link);
+void dp_trace_commit_lt_init(struct dc_link *link);
+void dp_trace_link_loss_increment(struct dc_link *link);
+void dp_trace_lt_fail_count_update(struct dc_link *link,
+               unsigned int fail_count,
+               bool in_detection);
+void dp_trace_lt_total_count_increment(struct dc_link *link,
+               bool in_detection);
+void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
+               bool in_detection,
+               bool is_logged);
+bool dc_dp_trace_is_logged(struct dc_link *link,
+               bool in_detection);
+void dp_trace_lt_result_update(struct dc_link *link,
+               enum link_training_result result,
+               bool in_detection);
+void dp_trace_set_lt_start_timestamp(struct dc_link *link,
+               bool in_detection);
+void dp_trace_set_lt_end_timestamp(struct dc_link *link,
+               bool in_detection);
+unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
+               bool in_detection);
+struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
+               bool in_detection);
+unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link);
+
+#endif /* __LINK_DP_TRACE_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dio.c b/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dio.c
new file mode 100644 (file)
index 0000000..33148b7
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#include "link_hwss_dio.h"
+#include "core_types.h"
+#include "dc_link_dp.h"
+#include "link_enc_cfg.h"
+
+void set_dio_throttled_vcp_size(struct pipe_ctx *pipe_ctx,
+               struct fixed31_32 throttled_vcp_size)
+{
+       struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
+
+       stream_encoder->funcs->set_throttled_vcp_size(
+                               stream_encoder,
+                               throttled_vcp_size);
+}
+
+void setup_dio_stream_encoder(struct pipe_ctx *pipe_ctx)
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
+       struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
+
+       link_enc->funcs->connect_dig_be_to_fe(link_enc,
+                       pipe_ctx->stream_res.stream_enc->id, true);
+       if (dc_is_dp_signal(pipe_ctx->stream->signal))
+               dp_source_sequence_trace(pipe_ctx->stream->link,
+                               DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_BE);
+       if (stream_enc->funcs->enable_fifo)
+               stream_enc->funcs->enable_fifo(stream_enc);
+}
+
+void reset_dio_stream_encoder(struct pipe_ctx *pipe_ctx)
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
+       struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
+
+       if (stream_enc && stream_enc->funcs->disable_fifo)
+               stream_enc->funcs->disable_fifo(stream_enc);
+
+       link_enc->funcs->connect_dig_be_to_fe(
+                       link_enc,
+                       pipe_ctx->stream_res.stream_enc->id,
+                       false);
+       if (dc_is_dp_signal(pipe_ctx->stream->signal))
+               dp_source_sequence_trace(pipe_ctx->stream->link,
+                               DPCD_SOURCE_SEQ_AFTER_DISCONNECT_DIG_FE_BE);
+
+}
+
+void setup_dio_stream_attribute(struct pipe_ctx *pipe_ctx)
+{
+       struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
+       struct dc_stream_state *stream = pipe_ctx->stream;
+       struct dc_link *link = stream->link;
+
+       if (!dc_is_virtual_signal(stream->signal))
+               stream_encoder->funcs->setup_stereo_sync(
+                               stream_encoder,
+                               pipe_ctx->stream_res.tg->inst,
+                               stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
+
+       if (dc_is_dp_signal(stream->signal))
+               stream_encoder->funcs->dp_set_stream_attribute(
+                               stream_encoder,
+                               &stream->timing,
+                               stream->output_color_space,
+                               stream->use_vsc_sdp_for_colorimetry,
+                               link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
+       else if (dc_is_hdmi_tmds_signal(stream->signal))
+               stream_encoder->funcs->hdmi_set_stream_attribute(
+                               stream_encoder,
+                               &stream->timing,
+                               stream->phy_pix_clk,
+                               pipe_ctx->stream_res.audio != NULL);
+       else if (dc_is_dvi_signal(stream->signal))
+               stream_encoder->funcs->dvi_set_stream_attribute(
+                               stream_encoder,
+                               &stream->timing,
+                               (stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
+                                               true : false);
+       else if (dc_is_lvds_signal(stream->signal))
+               stream_encoder->funcs->lvds_set_stream_attribute(
+                               stream_encoder,
+                               &stream->timing);
+
+       if (dc_is_dp_signal(stream->signal))
+               dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
+}
+
+void enable_dio_dp_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal,
+               enum clock_source_id clock_source,
+               const struct dc_link_settings *link_settings)
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
+
+       if (dc_is_dp_sst_signal(signal))
+               link_enc->funcs->enable_dp_output(
+                               link_enc,
+                               link_settings,
+                               clock_source);
+       else
+               link_enc->funcs->enable_dp_mst_output(
+                               link_enc,
+                               link_settings,
+                               clock_source);
+       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_ENABLE_LINK_PHY);
+}
+
+void disable_dio_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal)
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
+
+       link_enc->funcs->disable_output(link_enc, signal);
+       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
+}
+
+void set_dio_dp_link_test_pattern(struct dc_link *link,
+               const struct link_resource *link_res,
+               struct encoder_set_dp_phy_pattern_param *tp_params)
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
+
+       link_enc->funcs->dp_set_phy_pattern(link_enc, tp_params);
+       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN);
+}
+
+void set_dio_dp_lane_settings(struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct dc_link_settings *link_settings,
+               const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
+
+       link_enc->funcs->dp_set_lane_settings(link_enc, link_settings, lane_settings);
+}
+
+static void update_dio_stream_allocation_table(struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct link_mst_stream_allocation_table *table)
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
+
+       ASSERT(link_enc);
+       link_enc->funcs->update_mst_stream_allocation_table(link_enc, table);
+}
+
+void setup_dio_audio_output(struct pipe_ctx *pipe_ctx,
+               struct audio_output *audio_output, uint32_t audio_inst)
+{
+       if (dc_is_dp_signal(pipe_ctx->stream->signal))
+               pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
+                               pipe_ctx->stream_res.stream_enc,
+                               audio_inst,
+                               &pipe_ctx->stream->audio_info);
+       else
+               pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
+                               pipe_ctx->stream_res.stream_enc,
+                               audio_inst,
+                               &pipe_ctx->stream->audio_info,
+                               &audio_output->crtc_info);
+}
+
+void enable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
+{
+       if (dc_is_dp_signal(pipe_ctx->stream->signal))
+               pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(
+                               pipe_ctx->stream_res.stream_enc);
+
+       pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
+                       pipe_ctx->stream_res.stream_enc, false);
+
+       if (dc_is_dp_signal(pipe_ctx->stream->signal))
+               dp_source_sequence_trace(pipe_ctx->stream->link,
+                               DPCD_SOURCE_SEQ_AFTER_ENABLE_AUDIO_STREAM);
+}
+
+void disable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
+{
+       pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
+                       pipe_ctx->stream_res.stream_enc, true);
+
+       if (pipe_ctx->stream_res.audio) {
+               if (dc_is_dp_signal(pipe_ctx->stream->signal))
+                       pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
+                                       pipe_ctx->stream_res.stream_enc);
+               else
+                       pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
+                                       pipe_ctx->stream_res.stream_enc);
+       }
+
+       if (dc_is_dp_signal(pipe_ctx->stream->signal))
+               dp_source_sequence_trace(pipe_ctx->stream->link,
+                               DPCD_SOURCE_SEQ_AFTER_DISABLE_AUDIO_STREAM);
+}
+
+static const struct link_hwss dio_link_hwss = {
+       .setup_stream_encoder = setup_dio_stream_encoder,
+       .reset_stream_encoder = reset_dio_stream_encoder,
+       .setup_stream_attribute = setup_dio_stream_attribute,
+       .disable_link_output = disable_dio_link_output,
+       .setup_audio_output = setup_dio_audio_output,
+       .enable_audio_packet = enable_dio_audio_packet,
+       .disable_audio_packet = disable_dio_audio_packet,
+       .ext = {
+               .set_throttled_vcp_size = set_dio_throttled_vcp_size,
+               .enable_dp_link_output = enable_dio_dp_link_output,
+               .set_dp_link_test_pattern = set_dio_dp_link_test_pattern,
+               .set_dp_lane_settings = set_dio_dp_lane_settings,
+               .update_stream_allocation_table = update_dio_stream_allocation_table,
+       },
+};
+
+bool can_use_dio_link_hwss(const struct dc_link *link,
+               const struct link_resource *link_res)
+{
+       return link->link_enc != NULL;
+}
+
+const struct link_hwss *get_dio_link_hwss(void)
+{
+       return &dio_link_hwss;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dio.h b/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dio.h
new file mode 100644 (file)
index 0000000..9a108c3
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#ifndef __LINK_HWSS_DIO_H__
+#define __LINK_HWSS_DIO_H__
+
+#include "link_hwss.h"
+
+const struct link_hwss *get_dio_link_hwss(void);
+bool can_use_dio_link_hwss(const struct dc_link *link,
+               const struct link_resource *link_res);
+void set_dio_throttled_vcp_size(struct pipe_ctx *pipe_ctx,
+               struct fixed31_32 throttled_vcp_size);
+void setup_dio_stream_encoder(struct pipe_ctx *pipe_ctx);
+void reset_dio_stream_encoder(struct pipe_ctx *pipe_ctx);
+void setup_dio_stream_attribute(struct pipe_ctx *pipe_ctx);
+void enable_dio_dp_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal,
+               enum clock_source_id clock_source,
+               const struct dc_link_settings *link_settings);
+void disable_dio_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal);
+void set_dio_dp_link_test_pattern(struct dc_link *link,
+               const struct link_resource *link_res,
+               struct encoder_set_dp_phy_pattern_param *tp_params);
+void set_dio_dp_lane_settings(struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct dc_link_settings *link_settings,
+               const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX]);
+void setup_dio_audio_output(struct pipe_ctx *pipe_ctx,
+               struct audio_output *audio_output, uint32_t audio_inst);
+void enable_dio_audio_packet(struct pipe_ctx *pipe_ctx);
+void disable_dio_audio_packet(struct pipe_ctx *pipe_ctx);
+
+#endif /* __LINK_HWSS_DIO_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dpia.c b/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dpia.c
new file mode 100644 (file)
index 0000000..861f3cd
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#include "link_hwss_dpia.h"
+#include "core_types.h"
+#include "link_hwss_dio.h"
+#include "link_enc_cfg.h"
+
+#define DC_LOGGER_INIT(logger)
+
+static void update_dpia_stream_allocation_table(struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct link_mst_stream_allocation_table *table)
+{
+       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
+       static enum dc_status status;
+       uint8_t mst_alloc_slots = 0, prev_mst_slots_in_use = 0xFF;
+       int i;
+       DC_LOGGER_INIT(link->ctx->logger);
+
+       for (i = 0; i < table->stream_count; i++)
+               mst_alloc_slots += table->stream_allocations[i].slot_count;
+
+       status = dc_process_dmub_set_mst_slots(link->dc, link->link_index,
+                       mst_alloc_slots, &prev_mst_slots_in_use);
+       ASSERT(status == DC_OK);
+       DC_LOG_MST("dpia : status[%d]: alloc_slots[%d]: used_slots[%d]\n",
+                       status, mst_alloc_slots, prev_mst_slots_in_use);
+
+       ASSERT(link_enc);
+       link_enc->funcs->update_mst_stream_allocation_table(link_enc, table);
+}
+
+static const struct link_hwss dpia_link_hwss = {
+       .setup_stream_encoder = setup_dio_stream_encoder,
+       .reset_stream_encoder = reset_dio_stream_encoder,
+       .setup_stream_attribute = setup_dio_stream_attribute,
+       .disable_link_output = disable_dio_link_output,
+       .setup_audio_output = setup_dio_audio_output,
+       .enable_audio_packet = enable_dio_audio_packet,
+       .disable_audio_packet = disable_dio_audio_packet,
+       .ext = {
+               .set_throttled_vcp_size = set_dio_throttled_vcp_size,
+               .enable_dp_link_output = enable_dio_dp_link_output,
+               .set_dp_link_test_pattern = set_dio_dp_link_test_pattern,
+               .set_dp_lane_settings = set_dio_dp_lane_settings,
+               .update_stream_allocation_table = update_dpia_stream_allocation_table,
+       },
+};
+
+bool can_use_dpia_link_hwss(const struct dc_link *link,
+               const struct link_resource *link_res)
+{
+       return link->is_dig_mapping_flexible &&
+                       link->dc->res_pool->funcs->link_encs_assign;
+}
+
+const struct link_hwss *get_dpia_link_hwss(void)
+{
+       return &dpia_link_hwss;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dpia.h b/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_dpia.h
new file mode 100644 (file)
index 0000000..ad16ec5
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#ifndef __LINK_HWSS_DPIA_H__
+#define __LINK_HWSS_DPIA_H__
+
+#include "link_hwss.h"
+
+const struct link_hwss *get_dpia_link_hwss(void);
+bool can_use_dpia_link_hwss(const struct dc_link *link,
+               const struct link_resource *link_res);
+
+#endif /* __LINK_HWSS_DPIA_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_hpo_dp.c b/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_hpo_dp.c
new file mode 100644 (file)
index 0000000..164d631
--- /dev/null
@@ -0,0 +1,278 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#include "link_hwss_hpo_dp.h"
+#include "dm_helpers.h"
+#include "core_types.h"
+#include "dccg.h"
+#include "dc_link_dp.h"
+#include "clk_mgr.h"
+
+static enum phyd32clk_clock_source get_phyd32clk_src(struct dc_link *link)
+{
+       switch (link->link_enc->transmitter) {
+       case TRANSMITTER_UNIPHY_A:
+               return PHYD32CLKA;
+       case TRANSMITTER_UNIPHY_B:
+               return PHYD32CLKB;
+       case TRANSMITTER_UNIPHY_C:
+               return PHYD32CLKC;
+       case TRANSMITTER_UNIPHY_D:
+               return PHYD32CLKD;
+       case TRANSMITTER_UNIPHY_E:
+               return PHYD32CLKE;
+       default:
+               return PHYD32CLKA;
+       }
+}
+
+static void set_hpo_dp_throttled_vcp_size(struct pipe_ctx *pipe_ctx,
+               struct fixed31_32 throttled_vcp_size)
+{
+       struct hpo_dp_stream_encoder *hpo_dp_stream_encoder =
+                       pipe_ctx->stream_res.hpo_dp_stream_enc;
+       struct hpo_dp_link_encoder *hpo_dp_link_encoder =
+                       pipe_ctx->link_res.hpo_dp_link_enc;
+
+       hpo_dp_link_encoder->funcs->set_throttled_vcp_size(hpo_dp_link_encoder,
+                       hpo_dp_stream_encoder->inst,
+                       throttled_vcp_size);
+}
+
+static void set_hpo_dp_hblank_min_symbol_width(struct pipe_ctx *pipe_ctx,
+               const struct dc_link_settings *link_settings,
+               struct fixed31_32 throttled_vcp_size)
+{
+       struct hpo_dp_stream_encoder *hpo_dp_stream_encoder =
+                       pipe_ctx->stream_res.hpo_dp_stream_enc;
+       struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
+       struct fixed31_32 h_blank_in_ms, time_slot_in_ms, mtp_cnt_per_h_blank;
+       uint32_t link_bw_in_kbps =
+                       dc_link_bandwidth_kbps(pipe_ctx->stream->link, link_settings);
+       uint16_t hblank_min_symbol_width = 0;
+
+       if (link_bw_in_kbps > 0) {
+               h_blank_in_ms = dc_fixpt_div(dc_fixpt_from_int(
+                               timing->h_total - timing->h_addressable),
+                               dc_fixpt_from_fraction(timing->pix_clk_100hz, 10));
+               time_slot_in_ms = dc_fixpt_from_fraction(32 * 4, link_bw_in_kbps);
+               mtp_cnt_per_h_blank = dc_fixpt_div(h_blank_in_ms,
+                               dc_fixpt_mul_int(time_slot_in_ms, 64));
+               hblank_min_symbol_width = dc_fixpt_floor(
+                               dc_fixpt_mul(mtp_cnt_per_h_blank, throttled_vcp_size));
+       }
+
+       hpo_dp_stream_encoder->funcs->set_hblank_min_symbol_width(hpo_dp_stream_encoder,
+                       hblank_min_symbol_width);
+}
+
+static void setup_hpo_dp_stream_encoder(struct pipe_ctx *pipe_ctx)
+{
+       struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
+       struct hpo_dp_link_encoder *link_enc = pipe_ctx->link_res.hpo_dp_link_enc;
+
+       stream_enc->funcs->enable_stream(stream_enc);
+       stream_enc->funcs->map_stream_to_link(stream_enc, stream_enc->inst, link_enc->inst);
+}
+
+static void reset_hpo_dp_stream_encoder(struct pipe_ctx *pipe_ctx)
+{
+       struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
+
+       stream_enc->funcs->disable(stream_enc);
+}
+
+static void setup_hpo_dp_stream_attribute(struct pipe_ctx *pipe_ctx)
+{
+       struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
+       struct dc_stream_state *stream = pipe_ctx->stream;
+       struct dc_link *link = stream->link;
+
+       stream_enc->funcs->set_stream_attribute(
+                       stream_enc,
+                       &stream->timing,
+                       stream->output_color_space,
+                       stream->use_vsc_sdp_for_colorimetry,
+                       stream->timing.flags.DSC,
+                       false);
+       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
+}
+
+static void enable_hpo_dp_fpga_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal,
+               enum clock_source_id clock_source,
+               const struct dc_link_settings *link_settings)
+{
+       const struct dc *dc = link->dc;
+       enum phyd32clk_clock_source phyd32clk = get_phyd32clk_src(link);
+       int phyd32clk_freq_khz = link_settings->link_rate == LINK_RATE_UHBR10 ? 312500 :
+                       link_settings->link_rate == LINK_RATE_UHBR13_5 ? 412875 :
+                       link_settings->link_rate == LINK_RATE_UHBR20 ? 625000 : 0;
+
+       dm_set_phyd32clk(dc->ctx, phyd32clk_freq_khz);
+       dc->res_pool->dccg->funcs->set_physymclk(
+                       dc->res_pool->dccg,
+                       link->link_enc_hw_inst,
+                       PHYSYMCLK_FORCE_SRC_PHYD32CLK,
+                       true);
+       dc->res_pool->dccg->funcs->enable_symclk32_le(
+                       dc->res_pool->dccg,
+                       link_res->hpo_dp_link_enc->inst,
+                       phyd32clk);
+       link_res->hpo_dp_link_enc->funcs->link_enable(
+                       link_res->hpo_dp_link_enc,
+                       link_settings->lane_count);
+
+}
+
+static void enable_hpo_dp_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal,
+               enum clock_source_id clock_source,
+               const struct dc_link_settings *link_settings)
+{
+       if (IS_FPGA_MAXIMUS_DC(link->dc->ctx->dce_environment))
+               enable_hpo_dp_fpga_link_output(link, link_res, signal,
+                               clock_source, link_settings);
+       else
+               link_res->hpo_dp_link_enc->funcs->enable_link_phy(
+                               link_res->hpo_dp_link_enc,
+                               link_settings,
+                               link->link_enc->transmitter,
+                               link->link_enc->hpd_source);
+}
+
+
+static void disable_hpo_dp_fpga_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal)
+{
+       const struct dc *dc = link->dc;
+
+       link_res->hpo_dp_link_enc->funcs->link_disable(link_res->hpo_dp_link_enc);
+       dc->res_pool->dccg->funcs->disable_symclk32_le(
+                       dc->res_pool->dccg,
+                       link_res->hpo_dp_link_enc->inst);
+       dc->res_pool->dccg->funcs->set_physymclk(
+                       dc->res_pool->dccg,
+                       link->link_enc_hw_inst,
+                       PHYSYMCLK_FORCE_SRC_SYMCLK,
+                       false);
+       dm_set_phyd32clk(dc->ctx, 0);
+}
+
+static void disable_hpo_dp_link_output(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal)
+{
+       if (IS_FPGA_MAXIMUS_DC(link->dc->ctx->dce_environment)) {
+               disable_hpo_dp_fpga_link_output(link, link_res, signal);
+       } else {
+               link_res->hpo_dp_link_enc->funcs->link_disable(link_res->hpo_dp_link_enc);
+               link_res->hpo_dp_link_enc->funcs->disable_link_phy(
+                               link_res->hpo_dp_link_enc, signal);
+       }
+}
+
+static void set_hpo_dp_link_test_pattern(struct dc_link *link,
+               const struct link_resource *link_res,
+               struct encoder_set_dp_phy_pattern_param *tp_params)
+{
+       link_res->hpo_dp_link_enc->funcs->set_link_test_pattern(
+                       link_res->hpo_dp_link_enc, tp_params);
+       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN);
+}
+
+static void set_hpo_dp_lane_settings(struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct dc_link_settings *link_settings,
+               const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
+{
+       link_res->hpo_dp_link_enc->funcs->set_ffe(
+                       link_res->hpo_dp_link_enc,
+                       link_settings,
+                       lane_settings[0].FFE_PRESET.raw);
+}
+
+static void update_hpo_dp_stream_allocation_table(struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct link_mst_stream_allocation_table *table)
+{
+       link_res->hpo_dp_link_enc->funcs->update_stream_allocation_table(
+                       link_res->hpo_dp_link_enc,
+                       table);
+}
+
+static void setup_hpo_dp_audio_output(struct pipe_ctx *pipe_ctx,
+               struct audio_output *audio_output, uint32_t audio_inst)
+{
+       pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_setup(
+                       pipe_ctx->stream_res.hpo_dp_stream_enc,
+                       audio_inst,
+                       &pipe_ctx->stream->audio_info);
+}
+
+static void enable_hpo_dp_audio_packet(struct pipe_ctx *pipe_ctx)
+{
+       pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_enable(
+                       pipe_ctx->stream_res.hpo_dp_stream_enc);
+}
+
+static void disable_hpo_dp_audio_packet(struct pipe_ctx *pipe_ctx)
+{
+       if (pipe_ctx->stream_res.audio)
+               pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_disable(
+                               pipe_ctx->stream_res.hpo_dp_stream_enc);
+}
+
+static const struct link_hwss hpo_dp_link_hwss = {
+       .setup_stream_encoder = setup_hpo_dp_stream_encoder,
+       .reset_stream_encoder = reset_hpo_dp_stream_encoder,
+       .setup_stream_attribute = setup_hpo_dp_stream_attribute,
+       .disable_link_output = disable_hpo_dp_link_output,
+       .setup_audio_output = setup_hpo_dp_audio_output,
+       .enable_audio_packet = enable_hpo_dp_audio_packet,
+       .disable_audio_packet = disable_hpo_dp_audio_packet,
+       .ext = {
+               .set_throttled_vcp_size = set_hpo_dp_throttled_vcp_size,
+               .set_hblank_min_symbol_width = set_hpo_dp_hblank_min_symbol_width,
+               .enable_dp_link_output = enable_hpo_dp_link_output,
+               .set_dp_link_test_pattern  = set_hpo_dp_link_test_pattern,
+               .set_dp_lane_settings = set_hpo_dp_lane_settings,
+               .update_stream_allocation_table = update_hpo_dp_stream_allocation_table,
+       },
+};
+
+bool can_use_hpo_dp_link_hwss(const struct dc_link *link,
+               const struct link_resource *link_res)
+{
+       return link_res->hpo_dp_link_enc != NULL;
+}
+
+const struct link_hwss *get_hpo_dp_link_hwss(void)
+{
+       return &hpo_dp_link_hwss;
+}
+
diff --git a/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_hpo_dp.h b/drivers/gpu/drm/amd/display/dc/link/hwss/link_hwss_hpo_dp.h
new file mode 100644 (file)
index 0000000..57d447e
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+#ifndef __LINK_HWSS_HPO_DP_H__
+#define __LINK_HWSS_HPO_DP_H__
+
+#include "link_hwss.h"
+
+bool can_use_hpo_dp_link_hwss(const struct dc_link *link,
+               const struct link_resource *link_res);
+const struct link_hwss *get_hpo_dp_link_hwss(void);
+
+
+#endif /* __LINK_HWSS_HPO_DP_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_ddc.c b/drivers/gpu/drm/amd/display/dc/link/link_ddc.c
deleted file mode 100644 (file)
index 5269125..0000000
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- * Copyright 2012-15 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- *
- * This file implements generic display communication protocols such as i2c, aux
- * and scdc. The file should not contain any specific applications of these
- * protocols such as display capability query, detection, or handshaking such as
- * link training.
- */
-#include "link_ddc.h"
-#include "vector.h"
-#include "dce/dce_aux.h"
-#include "dal_asic_id.h"
-#include "link_dpcd.h"
-#include "dm_helpers.h"
-#include "atomfirmware.h"
-
-#define DC_LOGGER_INIT(logger)
-
-static const uint8_t DP_VGA_DONGLE_BRANCH_DEV_NAME[] = "DpVga";
-/* DP to Dual link DVI converter */
-static const uint8_t DP_DVI_CONVERTER_ID_4[] = "m2DVIa";
-static const uint8_t DP_DVI_CONVERTER_ID_5[] = "3393N2";
-
-struct i2c_payloads {
-       struct vector payloads;
-};
-
-struct aux_payloads {
-       struct vector payloads;
-};
-
-static bool dal_ddc_i2c_payloads_create(
-               struct dc_context *ctx,
-               struct i2c_payloads *payloads,
-               uint32_t count)
-{
-       if (dal_vector_construct(
-               &payloads->payloads, ctx, count, sizeof(struct i2c_payload)))
-               return true;
-
-       return false;
-}
-
-static struct i2c_payload *dal_ddc_i2c_payloads_get(struct i2c_payloads *p)
-{
-       return (struct i2c_payload *)p->payloads.container;
-}
-
-static uint32_t dal_ddc_i2c_payloads_get_count(struct i2c_payloads *p)
-{
-       return p->payloads.count;
-}
-
-#define DDC_MIN(a, b) (((a) < (b)) ? (a) : (b))
-
-static void i2c_payloads_add(
-       struct i2c_payloads *payloads,
-       uint32_t address,
-       uint32_t len,
-       uint8_t *data,
-       bool write)
-{
-       uint32_t payload_size = EDID_SEGMENT_SIZE;
-       uint32_t pos;
-
-       for (pos = 0; pos < len; pos += payload_size) {
-               struct i2c_payload payload = {
-                       .write = write,
-                       .address = address,
-                       .length = DDC_MIN(payload_size, len - pos),
-                       .data = data + pos };
-               dal_vector_append(&payloads->payloads, &payload);
-       }
-
-}
-
-static void ddc_service_construct(
-       struct ddc_service *ddc_service,
-       struct ddc_service_init_data *init_data)
-{
-       enum connector_id connector_id =
-               dal_graphics_object_id_get_connector_id(init_data->id);
-
-       struct gpio_service *gpio_service = init_data->ctx->gpio_service;
-       struct graphics_object_i2c_info i2c_info;
-       struct gpio_ddc_hw_info hw_info;
-       struct dc_bios *dcb = init_data->ctx->dc_bios;
-
-       ddc_service->link = init_data->link;
-       ddc_service->ctx = init_data->ctx;
-
-       if (init_data->is_dpia_link ||
-           dcb->funcs->get_i2c_info(dcb, init_data->id, &i2c_info) != BP_RESULT_OK) {
-               ddc_service->ddc_pin = NULL;
-       } else {
-               DC_LOGGER_INIT(ddc_service->ctx->logger);
-               DC_LOG_DC("BIOS object table - i2c_line: %d", i2c_info.i2c_line);
-               DC_LOG_DC("BIOS object table - i2c_engine_id: %d", i2c_info.i2c_engine_id);
-
-               hw_info.ddc_channel = i2c_info.i2c_line;
-               if (ddc_service->link != NULL)
-                       hw_info.hw_supported = i2c_info.i2c_hw_assist;
-               else
-                       hw_info.hw_supported = false;
-
-               ddc_service->ddc_pin = dal_gpio_create_ddc(
-                       gpio_service,
-                       i2c_info.gpio_info.clk_a_register_index,
-                       1 << i2c_info.gpio_info.clk_a_shift,
-                       &hw_info);
-       }
-
-       ddc_service->flags.EDID_QUERY_DONE_ONCE = false;
-       ddc_service->flags.FORCE_READ_REPEATED_START = false;
-       ddc_service->flags.EDID_STRESS_READ = false;
-
-       ddc_service->flags.IS_INTERNAL_DISPLAY =
-               connector_id == CONNECTOR_ID_EDP ||
-               connector_id == CONNECTOR_ID_LVDS;
-
-       ddc_service->wa.raw = 0;
-}
-
-struct ddc_service *link_create_ddc_service(
-       struct ddc_service_init_data *init_data)
-{
-       struct ddc_service *ddc_service;
-
-       ddc_service = kzalloc(sizeof(struct ddc_service), GFP_KERNEL);
-
-       if (!ddc_service)
-               return NULL;
-
-       ddc_service_construct(ddc_service, init_data);
-       return ddc_service;
-}
-
-static void ddc_service_destruct(struct ddc_service *ddc)
-{
-       if (ddc->ddc_pin)
-               dal_gpio_destroy_ddc(&ddc->ddc_pin);
-}
-
-void link_destroy_ddc_service(struct ddc_service **ddc)
-{
-       if (!ddc || !*ddc) {
-               BREAK_TO_DEBUGGER();
-               return;
-       }
-       ddc_service_destruct(*ddc);
-       kfree(*ddc);
-       *ddc = NULL;
-}
-
-void set_ddc_transaction_type(
-       struct ddc_service *ddc,
-       enum ddc_transaction_type type)
-{
-       ddc->transaction_type = type;
-}
-
-bool link_is_in_aux_transaction_mode(struct ddc_service *ddc)
-{
-       switch (ddc->transaction_type) {
-       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX:
-       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_WITH_DEFER:
-       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_RETRY_DEFER:
-               return true;
-       default:
-               break;
-       }
-       return false;
-}
-
-void set_dongle_type(struct ddc_service *ddc,
-               enum display_dongle_type dongle_type)
-{
-       ddc->dongle_type = dongle_type;
-}
-
-static uint32_t defer_delay_converter_wa(
-       struct ddc_service *ddc,
-       uint32_t defer_delay)
-{
-       struct dc_link *link = ddc->link;
-
-       if (link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_VGA_CONVERTER &&
-               link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_0080E1 &&
-               (link->dpcd_caps.branch_fw_revision[0] < 0x01 ||
-                               (link->dpcd_caps.branch_fw_revision[0] == 0x01 &&
-                               link->dpcd_caps.branch_fw_revision[1] < 0x40)) &&
-               !memcmp(link->dpcd_caps.branch_dev_name,
-                   DP_VGA_DONGLE_BRANCH_DEV_NAME,
-                       sizeof(link->dpcd_caps.branch_dev_name)))
-
-               return defer_delay > DPVGA_DONGLE_AUX_DEFER_WA_DELAY ?
-                       defer_delay : DPVGA_DONGLE_AUX_DEFER_WA_DELAY;
-
-       if (link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_0080E1 &&
-           !memcmp(link->dpcd_caps.branch_dev_name,
-                   DP_DVI_CONVERTER_ID_4,
-                   sizeof(link->dpcd_caps.branch_dev_name)))
-               return defer_delay > I2C_OVER_AUX_DEFER_WA_DELAY ?
-                       defer_delay : I2C_OVER_AUX_DEFER_WA_DELAY;
-       if (link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_006037 &&
-           !memcmp(link->dpcd_caps.branch_dev_name,
-                   DP_DVI_CONVERTER_ID_5,
-                   sizeof(link->dpcd_caps.branch_dev_name)))
-               return defer_delay > I2C_OVER_AUX_DEFER_WA_DELAY_1MS ?
-                       I2C_OVER_AUX_DEFER_WA_DELAY_1MS : defer_delay;
-
-       return defer_delay;
-}
-
-#define DP_TRANSLATOR_DELAY 5
-
-uint32_t link_get_aux_defer_delay(struct ddc_service *ddc)
-{
-       uint32_t defer_delay = 0;
-
-       switch (ddc->transaction_type) {
-       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX:
-               if ((DISPLAY_DONGLE_DP_VGA_CONVERTER == ddc->dongle_type) ||
-                       (DISPLAY_DONGLE_DP_DVI_CONVERTER == ddc->dongle_type) ||
-                       (DISPLAY_DONGLE_DP_HDMI_CONVERTER ==
-                               ddc->dongle_type)) {
-
-                       defer_delay = DP_TRANSLATOR_DELAY;
-
-                       defer_delay =
-                               defer_delay_converter_wa(ddc, defer_delay);
-
-               } else /*sink has a delay different from an Active Converter*/
-                       defer_delay = 0;
-               break;
-       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_WITH_DEFER:
-               defer_delay = DP_TRANSLATOR_DELAY;
-               break;
-       default:
-               break;
-       }
-       return defer_delay;
-}
-
-static bool submit_aux_command(struct ddc_service *ddc,
-               struct aux_payload *payload)
-{
-       uint32_t retrieved = 0;
-       bool ret = false;
-
-       if (!ddc)
-               return false;
-
-       if (!payload)
-               return false;
-
-       do {
-               struct aux_payload current_payload;
-               bool is_end_of_payload = (retrieved + DEFAULT_AUX_MAX_DATA_SIZE) >=
-                               payload->length;
-               uint32_t payload_length = is_end_of_payload ?
-                               payload->length - retrieved : DEFAULT_AUX_MAX_DATA_SIZE;
-
-               current_payload.address = payload->address;
-               current_payload.data = &payload->data[retrieved];
-               current_payload.defer_delay = payload->defer_delay;
-               current_payload.i2c_over_aux = payload->i2c_over_aux;
-               current_payload.length = payload_length;
-               /* set mot (middle of transaction) to false if it is the last payload */
-               current_payload.mot = is_end_of_payload ? payload->mot:true;
-               current_payload.write_status_update = false;
-               current_payload.reply = payload->reply;
-               current_payload.write = payload->write;
-
-               ret = link_aux_transfer_with_retries_no_mutex(ddc, &current_payload);
-
-               retrieved += payload_length;
-       } while (retrieved < payload->length && ret == true);
-
-       return ret;
-}
-
-bool link_query_ddc_data(
-       struct ddc_service *ddc,
-       uint32_t address,
-       uint8_t *write_buf,
-       uint32_t write_size,
-       uint8_t *read_buf,
-       uint32_t read_size)
-{
-       bool success = true;
-       uint32_t payload_size =
-               link_is_in_aux_transaction_mode(ddc) ?
-                       DEFAULT_AUX_MAX_DATA_SIZE : EDID_SEGMENT_SIZE;
-
-       uint32_t write_payloads =
-               (write_size + payload_size - 1) / payload_size;
-
-       uint32_t read_payloads =
-               (read_size + payload_size - 1) / payload_size;
-
-       uint32_t payloads_num = write_payloads + read_payloads;
-
-       if (!payloads_num)
-               return false;
-
-       if (link_is_in_aux_transaction_mode(ddc)) {
-               struct aux_payload payload;
-
-               payload.i2c_over_aux = true;
-               payload.address = address;
-               payload.reply = NULL;
-               payload.defer_delay = link_get_aux_defer_delay(ddc);
-               payload.write_status_update = false;
-
-               if (write_size != 0) {
-                       payload.write = true;
-                       /* should not set mot (middle of transaction) to 0
-                        * if there are pending read payloads
-                        */
-                       payload.mot = !(read_size == 0);
-                       payload.length = write_size;
-                       payload.data = write_buf;
-
-                       success = submit_aux_command(ddc, &payload);
-               }
-
-               if (read_size != 0 && success) {
-                       payload.write = false;
-                       /* should set mot (middle of transaction) to 0
-                        * since it is the last payload to send
-                        */
-                       payload.mot = false;
-                       payload.length = read_size;
-                       payload.data = read_buf;
-
-                       success = submit_aux_command(ddc, &payload);
-               }
-       } else {
-               struct i2c_command command = {0};
-               struct i2c_payloads payloads;
-
-               if (!dal_ddc_i2c_payloads_create(ddc->ctx, &payloads, payloads_num))
-                       return false;
-
-               command.payloads = dal_ddc_i2c_payloads_get(&payloads);
-               command.number_of_payloads = 0;
-               command.engine = DDC_I2C_COMMAND_ENGINE;
-               command.speed = ddc->ctx->dc->caps.i2c_speed_in_khz;
-
-               i2c_payloads_add(
-                       &payloads, address, write_size, write_buf, true);
-
-               i2c_payloads_add(
-                       &payloads, address, read_size, read_buf, false);
-
-               command.number_of_payloads =
-                       dal_ddc_i2c_payloads_get_count(&payloads);
-
-               success = dm_helpers_submit_i2c(
-                               ddc->ctx,
-                               ddc->link,
-                               &command);
-
-               dal_vector_destruct(&payloads.payloads);
-       }
-
-       return success;
-}
-
-int dc_link_aux_transfer_raw(struct ddc_service *ddc,
-               struct aux_payload *payload,
-               enum aux_return_code_type *operation_result)
-{
-       if (ddc->ctx->dc->debug.enable_dmub_aux_for_legacy_ddc ||
-           !ddc->ddc_pin) {
-               return dce_aux_transfer_dmub_raw(ddc, payload, operation_result);
-       } else {
-               return dce_aux_transfer_raw(ddc, payload, operation_result);
-       }
-}
-
-bool link_aux_transfer_with_retries_no_mutex(struct ddc_service *ddc,
-               struct aux_payload *payload)
-{
-       return dce_aux_transfer_with_retries(ddc, payload);
-}
-
-
-bool try_to_configure_aux_timeout(struct ddc_service *ddc,
-               uint32_t timeout)
-{
-       bool result = false;
-       struct ddc *ddc_pin = ddc->ddc_pin;
-
-       if ((ddc->link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
-                       !ddc->link->dc->debug.disable_fixed_vs_aux_timeout_wa &&
-                       ASICREV_IS_YELLOW_CARP(ddc->ctx->asic_id.hw_internal_rev)) {
-               /* Fixed VS workaround for AUX timeout */
-               const uint32_t fixed_vs_address = 0xF004F;
-               const uint8_t fixed_vs_data[4] = {0x1, 0x22, 0x63, 0xc};
-
-               core_link_write_dpcd(ddc->link,
-                               fixed_vs_address,
-                               fixed_vs_data,
-                               sizeof(fixed_vs_data));
-
-               timeout = 3072;
-       }
-
-       /* Do not try to access nonexistent DDC pin. */
-       if (ddc->link->ep_type != DISPLAY_ENDPOINT_PHY)
-               return true;
-
-       if (ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]->funcs->configure_timeout) {
-               ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]->funcs->configure_timeout(ddc, timeout);
-               result = true;
-       }
-
-       return result;
-}
-
-struct ddc *get_ddc_pin(struct ddc_service *ddc_service)
-{
-       return ddc_service->ddc_pin;
-}
-
-void write_scdc_data(struct ddc_service *ddc_service,
-               uint32_t pix_clk,
-               bool lte_340_scramble)
-{
-       bool over_340_mhz = pix_clk > 340000 ? 1 : 0;
-       uint8_t slave_address = HDMI_SCDC_ADDRESS;
-       uint8_t offset = HDMI_SCDC_SINK_VERSION;
-       uint8_t sink_version = 0;
-       uint8_t write_buffer[2] = {0};
-       /*Lower than 340 Scramble bit from SCDC caps*/
-
-       if (ddc_service->link->local_sink &&
-               ddc_service->link->local_sink->edid_caps.panel_patch.skip_scdc_overwrite)
-               return;
-
-       link_query_ddc_data(ddc_service, slave_address, &offset,
-                       sizeof(offset), &sink_version, sizeof(sink_version));
-       if (sink_version == 1) {
-               /*Source Version = 1*/
-               write_buffer[0] = HDMI_SCDC_SOURCE_VERSION;
-               write_buffer[1] = 1;
-               link_query_ddc_data(ddc_service, slave_address,
-                               write_buffer, sizeof(write_buffer), NULL, 0);
-               /*Read Request from SCDC caps*/
-       }
-       write_buffer[0] = HDMI_SCDC_TMDS_CONFIG;
-
-       if (over_340_mhz) {
-               write_buffer[1] = 3;
-       } else if (lte_340_scramble) {
-               write_buffer[1] = 1;
-       } else {
-               write_buffer[1] = 0;
-       }
-       link_query_ddc_data(ddc_service, slave_address, write_buffer,
-                       sizeof(write_buffer), NULL, 0);
-}
-
-void read_scdc_data(struct ddc_service *ddc_service)
-{
-       uint8_t slave_address = HDMI_SCDC_ADDRESS;
-       uint8_t offset = HDMI_SCDC_TMDS_CONFIG;
-       uint8_t tmds_config = 0;
-
-       if (ddc_service->link->local_sink &&
-               ddc_service->link->local_sink->edid_caps.panel_patch.skip_scdc_overwrite)
-               return;
-
-       link_query_ddc_data(ddc_service, slave_address, &offset,
-                       sizeof(offset), &tmds_config, sizeof(tmds_config));
-       if (tmds_config & 0x1) {
-               union hdmi_scdc_status_flags_data status_data = {0};
-               uint8_t scramble_status = 0;
-
-               offset = HDMI_SCDC_SCRAMBLER_STATUS;
-               link_query_ddc_data(ddc_service, slave_address,
-                               &offset, sizeof(offset), &scramble_status,
-                               sizeof(scramble_status));
-               offset = HDMI_SCDC_STATUS_FLAGS;
-               link_query_ddc_data(ddc_service, slave_address,
-                               &offset, sizeof(offset), &status_data.byte,
-                               sizeof(status_data.byte));
-       }
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_ddc.h b/drivers/gpu/drm/amd/display/dc/link/link_ddc.h
deleted file mode 100644 (file)
index 86e9d2e..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2012-15 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-#ifndef __DAL_DDC_SERVICE_H__
-#define __DAL_DDC_SERVICE_H__
-
-#include "link.h"
-
-#define AUX_POWER_UP_WA_DELAY 500
-#define I2C_OVER_AUX_DEFER_WA_DELAY 70
-#define DPVGA_DONGLE_AUX_DEFER_WA_DELAY 40
-#define I2C_OVER_AUX_DEFER_WA_DELAY_1MS 1
-#define LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD 3200 /*us*/
-
-#define EDID_SEGMENT_SIZE 256
-
-void set_ddc_transaction_type(
-               struct ddc_service *ddc,
-               enum ddc_transaction_type type);
-
-bool try_to_configure_aux_timeout(struct ddc_service *ddc,
-               uint32_t timeout);
-
-void write_scdc_data(
-               struct ddc_service *ddc_service,
-               uint32_t pix_clk,
-               bool lte_340_scramble);
-
-void read_scdc_data(
-               struct ddc_service *ddc_service);
-
-void set_dongle_type(struct ddc_service *ddc,
-               enum display_dongle_type dongle_type);
-
-struct ddc *get_ddc_pin(struct ddc_service *ddc_service);
-
-#endif /* __DAL_DDC_SERVICE_H__ */
-
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_capability.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_capability.c
deleted file mode 100644 (file)
index 21fd927..0000000
+++ /dev/null
@@ -1,2169 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- * This file implements dp specific link capability retrieval sequence. It is
- * responsible for retrieving, parsing, overriding, deciding capability obtained
- * from dp link. Link capability consists of encoders, DPRXs, cables, retimers,
- * usb and all other possible backend capabilities. Other components should
- * include this header file in order to access link capability. Accessing link
- * capability by dereferencing dc_link outside dp_link_capability is not a
- * recommended method as it makes the component dependent on the underlying data
- * structure used to represent link capability instead of function interfaces.
- */
-
-#include "link_dp_capability.h"
-#include "link_ddc.h"
-#include "link_dpcd.h"
-#include "link_dp_dpia.h"
-#include "link_dp_phy.h"
-#include "link_dp_trace.h"
-#include "link_dp_training.h"
-#include "atomfirmware.h"
-#include "resource.h"
-#include "link_enc_cfg.h"
-#include "dc_link_dp.h"
-#include "dc_dmub_srv.h"
-
-#define DC_LOGGER \
-       link->ctx->logger
-#define DC_TRACE_LEVEL_MESSAGE(...) /* do nothing */
-
-#ifndef MAX
-#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
-#endif
-#ifndef MIN
-#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
-#endif
-
-#define LINK_AUX_DEFAULT_TIMEOUT_PERIOD 552 /*us*/
-
-struct dp_lt_fallback_entry {
-       enum dc_lane_count lane_count;
-       enum dc_link_rate link_rate;
-};
-
-static const struct dp_lt_fallback_entry dp_lt_fallbacks[] = {
-               /* This link training fallback array is ordered by
-                * link bandwidth from highest to lowest.
-                * DP specs makes it a normative policy to always
-                * choose the next highest link bandwidth during
-                * link training fallback.
-                */
-               {LANE_COUNT_FOUR, LINK_RATE_UHBR20},
-               {LANE_COUNT_FOUR, LINK_RATE_UHBR13_5},
-               {LANE_COUNT_TWO, LINK_RATE_UHBR20},
-               {LANE_COUNT_FOUR, LINK_RATE_UHBR10},
-               {LANE_COUNT_TWO, LINK_RATE_UHBR13_5},
-               {LANE_COUNT_FOUR, LINK_RATE_HIGH3},
-               {LANE_COUNT_ONE, LINK_RATE_UHBR20},
-               {LANE_COUNT_TWO, LINK_RATE_UHBR10},
-               {LANE_COUNT_FOUR, LINK_RATE_HIGH2},
-               {LANE_COUNT_ONE, LINK_RATE_UHBR13_5},
-               {LANE_COUNT_TWO, LINK_RATE_HIGH3},
-               {LANE_COUNT_ONE, LINK_RATE_UHBR10},
-               {LANE_COUNT_TWO, LINK_RATE_HIGH2},
-               {LANE_COUNT_FOUR, LINK_RATE_HIGH},
-               {LANE_COUNT_ONE, LINK_RATE_HIGH3},
-               {LANE_COUNT_FOUR, LINK_RATE_LOW},
-               {LANE_COUNT_ONE, LINK_RATE_HIGH2},
-               {LANE_COUNT_TWO, LINK_RATE_HIGH},
-               {LANE_COUNT_TWO, LINK_RATE_LOW},
-               {LANE_COUNT_ONE, LINK_RATE_HIGH},
-               {LANE_COUNT_ONE, LINK_RATE_LOW},
-};
-
-static const struct dc_link_settings fail_safe_link_settings = {
-               .lane_count = LANE_COUNT_ONE,
-               .link_rate = LINK_RATE_LOW,
-               .link_spread = LINK_SPREAD_DISABLED,
-};
-
-bool is_dp_active_dongle(const struct dc_link *link)
-{
-       return (link->dpcd_caps.dongle_type >= DISPLAY_DONGLE_DP_VGA_CONVERTER) &&
-                               (link->dpcd_caps.dongle_type <= DISPLAY_DONGLE_DP_HDMI_CONVERTER);
-}
-
-bool is_dp_branch_device(const struct dc_link *link)
-{
-       return link->dpcd_caps.is_branch_dev;
-}
-
-static int translate_dpcd_max_bpc(enum dpcd_downstream_port_max_bpc bpc)
-{
-       switch (bpc) {
-       case DOWN_STREAM_MAX_8BPC:
-               return 8;
-       case DOWN_STREAM_MAX_10BPC:
-               return 10;
-       case DOWN_STREAM_MAX_12BPC:
-               return 12;
-       case DOWN_STREAM_MAX_16BPC:
-               return 16;
-       default:
-               break;
-       }
-
-       return -1;
-}
-
-uint8_t dp_parse_lttpr_repeater_count(uint8_t lttpr_repeater_count)
-{
-       switch (lttpr_repeater_count) {
-       case 0x80: // 1 lttpr repeater
-               return 1;
-       case 0x40: // 2 lttpr repeaters
-               return 2;
-       case 0x20: // 3 lttpr repeaters
-               return 3;
-       case 0x10: // 4 lttpr repeaters
-               return 4;
-       case 0x08: // 5 lttpr repeaters
-               return 5;
-       case 0x04: // 6 lttpr repeaters
-               return 6;
-       case 0x02: // 7 lttpr repeaters
-               return 7;
-       case 0x01: // 8 lttpr repeaters
-               return 8;
-       default:
-               break;
-       }
-       return 0; // invalid value
-}
-
-uint32_t dc_link_bw_kbps_from_raw_frl_link_rate_data(uint8_t bw)
-{
-       switch (bw) {
-       case 0b001:
-               return 9000000;
-       case 0b010:
-               return 18000000;
-       case 0b011:
-               return 24000000;
-       case 0b100:
-               return 32000000;
-       case 0b101:
-               return 40000000;
-       case 0b110:
-               return 48000000;
-       }
-
-       return 0;
-}
-
-static enum dc_link_rate linkRateInKHzToLinkRateMultiplier(uint32_t link_rate_in_khz)
-{
-       enum dc_link_rate link_rate;
-       // LinkRate is normally stored as a multiplier of 0.27 Gbps per lane. Do the translation.
-       switch (link_rate_in_khz) {
-       case 1620000:
-               link_rate = LINK_RATE_LOW;      // Rate_1 (RBR) - 1.62 Gbps/Lane
-               break;
-       case 2160000:
-               link_rate = LINK_RATE_RATE_2;   // Rate_2       - 2.16 Gbps/Lane
-               break;
-       case 2430000:
-               link_rate = LINK_RATE_RATE_3;   // Rate_3       - 2.43 Gbps/Lane
-               break;
-       case 2700000:
-               link_rate = LINK_RATE_HIGH;     // Rate_4 (HBR) - 2.70 Gbps/Lane
-               break;
-       case 3240000:
-               link_rate = LINK_RATE_RBR2;     // Rate_5 (RBR2)- 3.24 Gbps/Lane
-               break;
-       case 4320000:
-               link_rate = LINK_RATE_RATE_6;   // Rate_6       - 4.32 Gbps/Lane
-               break;
-       case 5400000:
-               link_rate = LINK_RATE_HIGH2;    // Rate_7 (HBR2)- 5.40 Gbps/Lane
-               break;
-       case 8100000:
-               link_rate = LINK_RATE_HIGH3;    // Rate_8 (HBR3)- 8.10 Gbps/Lane
-               break;
-       default:
-               link_rate = LINK_RATE_UNKNOWN;
-               break;
-       }
-       return link_rate;
-}
-
-static union dp_cable_id intersect_cable_id(
-               union dp_cable_id *a, union dp_cable_id *b)
-{
-       union dp_cable_id out;
-
-       out.bits.UHBR10_20_CAPABILITY = MIN(a->bits.UHBR10_20_CAPABILITY,
-                       b->bits.UHBR10_20_CAPABILITY);
-       out.bits.UHBR13_5_CAPABILITY = MIN(a->bits.UHBR13_5_CAPABILITY,
-                       b->bits.UHBR13_5_CAPABILITY);
-       out.bits.CABLE_TYPE = MAX(a->bits.CABLE_TYPE, b->bits.CABLE_TYPE);
-
-       return out;
-}
-
-/*
- * Return PCON's post FRL link training supported BW if its non-zero, otherwise return max_supported_frl_bw.
- */
-static uint32_t intersect_frl_link_bw_support(
-       const uint32_t max_supported_frl_bw_in_kbps,
-       const union hdmi_encoded_link_bw hdmi_encoded_link_bw)
-{
-       uint32_t supported_bw_in_kbps = max_supported_frl_bw_in_kbps;
-
-       // HDMI_ENCODED_LINK_BW bits are only valid if HDMI Link Configuration bit is 1 (FRL mode)
-       if (hdmi_encoded_link_bw.bits.FRL_MODE) {
-               if (hdmi_encoded_link_bw.bits.BW_48Gbps)
-                       supported_bw_in_kbps = 48000000;
-               else if (hdmi_encoded_link_bw.bits.BW_40Gbps)
-                       supported_bw_in_kbps = 40000000;
-               else if (hdmi_encoded_link_bw.bits.BW_32Gbps)
-                       supported_bw_in_kbps = 32000000;
-               else if (hdmi_encoded_link_bw.bits.BW_24Gbps)
-                       supported_bw_in_kbps = 24000000;
-               else if (hdmi_encoded_link_bw.bits.BW_18Gbps)
-                       supported_bw_in_kbps = 18000000;
-               else if (hdmi_encoded_link_bw.bits.BW_9Gbps)
-                       supported_bw_in_kbps = 9000000;
-       }
-
-       return supported_bw_in_kbps;
-}
-
-static enum clock_source_id get_clock_source_id(struct dc_link *link)
-{
-       enum clock_source_id dp_cs_id = CLOCK_SOURCE_ID_UNDEFINED;
-       struct clock_source *dp_cs = link->dc->res_pool->dp_clock_source;
-
-       if (dp_cs != NULL) {
-               dp_cs_id = dp_cs->id;
-       } else {
-               /*
-                * dp clock source is not initialized for some reason.
-                * Should not happen, CLOCK_SOURCE_ID_EXTERNAL will be used
-                */
-               ASSERT(dp_cs);
-       }
-
-       return dp_cs_id;
-}
-
-static void dp_wa_power_up_0010FA(struct dc_link *link, uint8_t *dpcd_data,
-               int length)
-{
-       int retry = 0;
-       union dp_downstream_port_present ds_port = { 0 };
-
-       if (!link->dpcd_caps.dpcd_rev.raw) {
-               do {
-                       dc_link_dp_receiver_power_ctrl(link, true);
-                       core_link_read_dpcd(link, DP_DPCD_REV,
-                                                       dpcd_data, length);
-                       link->dpcd_caps.dpcd_rev.raw = dpcd_data[
-                               DP_DPCD_REV -
-                               DP_DPCD_REV];
-               } while (retry++ < 4 && !link->dpcd_caps.dpcd_rev.raw);
-       }
-
-       ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
-                                DP_DPCD_REV];
-
-       if (link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_VGA_CONVERTER) {
-               switch (link->dpcd_caps.branch_dev_id) {
-               /* 0010FA active dongles (DP-VGA, DP-DLDVI converters) power down
-                * all internal circuits including AUX communication preventing
-                * reading DPCD table and EDID (spec violation).
-                * Encoder will skip DP RX power down on disable_output to
-                * keep receiver powered all the time.*/
-               case DP_BRANCH_DEVICE_ID_0010FA:
-               case DP_BRANCH_DEVICE_ID_0080E1:
-               case DP_BRANCH_DEVICE_ID_00E04C:
-                       link->wa_flags.dp_keep_receiver_powered = true;
-                       break;
-
-               /* TODO: May need work around for other dongles. */
-               default:
-                       link->wa_flags.dp_keep_receiver_powered = false;
-                       break;
-               }
-       } else
-               link->wa_flags.dp_keep_receiver_powered = false;
-}
-
-bool dc_link_is_fec_supported(const struct dc_link *link)
-{
-       /* TODO - use asic cap instead of link_enc->features
-        * we no longer know which link enc to use for this link before commit
-        */
-       struct link_encoder *link_enc = NULL;
-
-       link_enc = link_enc_cfg_get_link_enc(link);
-       ASSERT(link_enc);
-
-       return (dc_is_dp_signal(link->connector_signal) && link_enc &&
-                       link_enc->features.fec_supported &&
-                       link->dpcd_caps.fec_cap.bits.FEC_CAPABLE &&
-                       !IS_FPGA_MAXIMUS_DC(link->ctx->dce_environment));
-}
-
-bool dc_link_should_enable_fec(const struct dc_link *link)
-{
-       bool force_disable = false;
-
-       if (link->fec_state == dc_link_fec_enabled)
-               force_disable = false;
-       else if (link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT_MST &&
-                       link->local_sink &&
-                       link->local_sink->edid_caps.panel_patch.disable_fec)
-               force_disable = true;
-       else if (link->connector_signal == SIGNAL_TYPE_EDP
-                       && (link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.
-                        dsc_support.DSC_SUPPORT == false
-                               || link->panel_config.dsc.disable_dsc_edp
-                               || !link->dc->caps.edp_dsc_support))
-               force_disable = true;
-
-       return !force_disable && dc_link_is_fec_supported(link);
-}
-
-bool link_is_dp_128b_132b_signal(struct pipe_ctx *pipe_ctx)
-{
-       /* If this assert is hit then we have a link encoder dynamic management issue */
-       ASSERT(pipe_ctx->stream_res.hpo_dp_stream_enc ? pipe_ctx->link_res.hpo_dp_link_enc != NULL : true);
-       return (pipe_ctx->stream_res.hpo_dp_stream_enc &&
-                       pipe_ctx->link_res.hpo_dp_link_enc &&
-                       dc_is_dp_signal(pipe_ctx->stream->signal));
-}
-
-bool dp_is_lttpr_present(struct dc_link *link)
-{
-       return (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) != 0 &&
-                       link->dpcd_caps.lttpr_caps.max_lane_count > 0 &&
-                       link->dpcd_caps.lttpr_caps.max_lane_count <= 4 &&
-                       link->dpcd_caps.lttpr_caps.revision.raw >= 0x14);
-}
-
-/* in DP compliance test, DPR-120 may have
- * a random value in its MAX_LINK_BW dpcd field.
- * We map it to the maximum supported link rate that
- * is smaller than MAX_LINK_BW in this case.
- */
-static enum dc_link_rate get_link_rate_from_max_link_bw(
-                uint8_t max_link_bw)
-{
-       enum dc_link_rate link_rate;
-
-       if (max_link_bw >= LINK_RATE_HIGH3) {
-               link_rate = LINK_RATE_HIGH3;
-       } else if (max_link_bw < LINK_RATE_HIGH3
-                       && max_link_bw >= LINK_RATE_HIGH2) {
-               link_rate = LINK_RATE_HIGH2;
-       } else if (max_link_bw < LINK_RATE_HIGH2
-                       && max_link_bw >= LINK_RATE_HIGH) {
-               link_rate = LINK_RATE_HIGH;
-       } else if (max_link_bw < LINK_RATE_HIGH
-                       && max_link_bw >= LINK_RATE_LOW) {
-               link_rate = LINK_RATE_LOW;
-       } else {
-               link_rate = LINK_RATE_UNKNOWN;
-       }
-
-       return link_rate;
-}
-
-static enum dc_link_rate get_lttpr_max_link_rate(struct dc_link *link)
-{
-       enum dc_link_rate lttpr_max_link_rate = link->dpcd_caps.lttpr_caps.max_link_rate;
-
-       if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR20)
-               lttpr_max_link_rate = LINK_RATE_UHBR20;
-       else if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR13_5)
-               lttpr_max_link_rate = LINK_RATE_UHBR13_5;
-       else if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR10)
-               lttpr_max_link_rate = LINK_RATE_UHBR10;
-
-       return lttpr_max_link_rate;
-}
-
-static enum dc_link_rate get_cable_max_link_rate(struct dc_link *link)
-{
-       enum dc_link_rate cable_max_link_rate = LINK_RATE_UNKNOWN;
-
-       if (link->dpcd_caps.cable_id.bits.UHBR10_20_CAPABILITY & DP_UHBR20)
-               cable_max_link_rate = LINK_RATE_UHBR20;
-       else if (link->dpcd_caps.cable_id.bits.UHBR13_5_CAPABILITY)
-               cable_max_link_rate = LINK_RATE_UHBR13_5;
-       else if (link->dpcd_caps.cable_id.bits.UHBR10_20_CAPABILITY & DP_UHBR10)
-               cable_max_link_rate = LINK_RATE_UHBR10;
-
-       return cable_max_link_rate;
-}
-
-static inline bool reached_minimum_lane_count(enum dc_lane_count lane_count)
-{
-       return lane_count <= LANE_COUNT_ONE;
-}
-
-static inline bool reached_minimum_link_rate(enum dc_link_rate link_rate)
-{
-       return link_rate <= LINK_RATE_LOW;
-}
-
-static enum dc_lane_count reduce_lane_count(enum dc_lane_count lane_count)
-{
-       switch (lane_count) {
-       case LANE_COUNT_FOUR:
-               return LANE_COUNT_TWO;
-       case LANE_COUNT_TWO:
-               return LANE_COUNT_ONE;
-       case LANE_COUNT_ONE:
-               return LANE_COUNT_UNKNOWN;
-       default:
-               return LANE_COUNT_UNKNOWN;
-       }
-}
-
-static enum dc_link_rate reduce_link_rate(enum dc_link_rate link_rate)
-{
-       switch (link_rate) {
-       case LINK_RATE_UHBR20:
-               return LINK_RATE_UHBR13_5;
-       case LINK_RATE_UHBR13_5:
-               return LINK_RATE_UHBR10;
-       case LINK_RATE_UHBR10:
-               return LINK_RATE_HIGH3;
-       case LINK_RATE_HIGH3:
-               return LINK_RATE_HIGH2;
-       case LINK_RATE_HIGH2:
-               return LINK_RATE_HIGH;
-       case LINK_RATE_HIGH:
-               return LINK_RATE_LOW;
-       case LINK_RATE_LOW:
-               return LINK_RATE_UNKNOWN;
-       default:
-               return LINK_RATE_UNKNOWN;
-       }
-}
-
-static enum dc_lane_count increase_lane_count(enum dc_lane_count lane_count)
-{
-       switch (lane_count) {
-       case LANE_COUNT_ONE:
-               return LANE_COUNT_TWO;
-       case LANE_COUNT_TWO:
-               return LANE_COUNT_FOUR;
-       default:
-               return LANE_COUNT_UNKNOWN;
-       }
-}
-
-static enum dc_link_rate increase_link_rate(struct dc_link *link,
-               enum dc_link_rate link_rate)
-{
-       switch (link_rate) {
-       case LINK_RATE_LOW:
-               return LINK_RATE_HIGH;
-       case LINK_RATE_HIGH:
-               return LINK_RATE_HIGH2;
-       case LINK_RATE_HIGH2:
-               return LINK_RATE_HIGH3;
-       case LINK_RATE_HIGH3:
-               return LINK_RATE_UHBR10;
-       case LINK_RATE_UHBR10:
-               /* upto DP2.x specs UHBR13.5 is the only link rate that could be
-                * not supported by DPRX when higher link rate is supported.
-                * so we treat it as a special case for code simplicity. When we
-                * have new specs with more link rates like this, we should
-                * consider a more generic solution to handle discrete link
-                * rate capabilities.
-                */
-               return link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5 ?
-                               LINK_RATE_UHBR13_5 : LINK_RATE_UHBR20;
-       case LINK_RATE_UHBR13_5:
-               return LINK_RATE_UHBR20;
-       default:
-               return LINK_RATE_UNKNOWN;
-       }
-}
-
-static bool decide_fallback_link_setting_max_bw_policy(
-               struct dc_link *link,
-               const struct dc_link_settings *max,
-               struct dc_link_settings *cur,
-               enum link_training_result training_result)
-{
-       uint8_t cur_idx = 0, next_idx;
-       bool found = false;
-
-       if (training_result == LINK_TRAINING_ABORT)
-               return false;
-
-       while (cur_idx < ARRAY_SIZE(dp_lt_fallbacks))
-               /* find current index */
-               if (dp_lt_fallbacks[cur_idx].lane_count == cur->lane_count &&
-                               dp_lt_fallbacks[cur_idx].link_rate == cur->link_rate)
-                       break;
-               else
-                       cur_idx++;
-
-       next_idx = cur_idx + 1;
-
-       while (next_idx < ARRAY_SIZE(dp_lt_fallbacks))
-               /* find next index */
-               if (dp_lt_fallbacks[next_idx].lane_count > max->lane_count ||
-                               dp_lt_fallbacks[next_idx].link_rate > max->link_rate)
-                       next_idx++;
-               else if (dp_lt_fallbacks[next_idx].link_rate == LINK_RATE_UHBR13_5 &&
-                               link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5 == 0)
-                       /* upto DP2.x specs UHBR13.5 is the only link rate that
-                        * could be not supported by DPRX when higher link rate
-                        * is supported. so we treat it as a special case for
-                        * code simplicity. When we have new specs with more
-                        * link rates like this, we should consider a more
-                        * generic solution to handle discrete link rate
-                        * capabilities.
-                        */
-                       next_idx++;
-               else
-                       break;
-
-       if (next_idx < ARRAY_SIZE(dp_lt_fallbacks)) {
-               cur->lane_count = dp_lt_fallbacks[next_idx].lane_count;
-               cur->link_rate = dp_lt_fallbacks[next_idx].link_rate;
-               found = true;
-       }
-
-       return found;
-}
-
-/*
- * function: set link rate and lane count fallback based
- * on current link setting and last link training result
- * return value:
- *                     true - link setting could be set
- *                     false - has reached minimum setting
- *                                     and no further fallback could be done
- */
-bool decide_fallback_link_setting(
-               struct dc_link *link,
-               struct dc_link_settings *max,
-               struct dc_link_settings *cur,
-               enum link_training_result training_result)
-{
-       if (link_dp_get_encoding_format(max) == DP_128b_132b_ENCODING ||
-                       link->dc->debug.force_dp2_lt_fallback_method)
-               return decide_fallback_link_setting_max_bw_policy(link, max,
-                               cur, training_result);
-
-       switch (training_result) {
-       case LINK_TRAINING_CR_FAIL_LANE0:
-       case LINK_TRAINING_CR_FAIL_LANE1:
-       case LINK_TRAINING_CR_FAIL_LANE23:
-       case LINK_TRAINING_LQA_FAIL:
-       {
-               if (!reached_minimum_link_rate(cur->link_rate)) {
-                       cur->link_rate = reduce_link_rate(cur->link_rate);
-               } else if (!reached_minimum_lane_count(cur->lane_count)) {
-                       cur->link_rate = max->link_rate;
-                       if (training_result == LINK_TRAINING_CR_FAIL_LANE0)
-                               return false;
-                       else if (training_result == LINK_TRAINING_CR_FAIL_LANE1)
-                               cur->lane_count = LANE_COUNT_ONE;
-                       else if (training_result == LINK_TRAINING_CR_FAIL_LANE23)
-                               cur->lane_count = LANE_COUNT_TWO;
-                       else
-                               cur->lane_count = reduce_lane_count(cur->lane_count);
-               } else {
-                       return false;
-               }
-               break;
-       }
-       case LINK_TRAINING_EQ_FAIL_EQ:
-       case LINK_TRAINING_EQ_FAIL_CR_PARTIAL:
-       {
-               if (!reached_minimum_lane_count(cur->lane_count)) {
-                       cur->lane_count = reduce_lane_count(cur->lane_count);
-               } else if (!reached_minimum_link_rate(cur->link_rate)) {
-                       cur->link_rate = reduce_link_rate(cur->link_rate);
-                       /* Reduce max link rate to avoid potential infinite loop.
-                        * Needed so that any subsequent CR_FAIL fallback can't
-                        * re-set the link rate higher than the link rate from
-                        * the latest EQ_FAIL fallback.
-                        */
-                       max->link_rate = cur->link_rate;
-                       cur->lane_count = max->lane_count;
-               } else {
-                       return false;
-               }
-               break;
-       }
-       case LINK_TRAINING_EQ_FAIL_CR:
-       {
-               if (!reached_minimum_link_rate(cur->link_rate)) {
-                       cur->link_rate = reduce_link_rate(cur->link_rate);
-                       /* Reduce max link rate to avoid potential infinite loop.
-                        * Needed so that any subsequent CR_FAIL fallback can't
-                        * re-set the link rate higher than the link rate from
-                        * the latest EQ_FAIL fallback.
-                        */
-                       max->link_rate = cur->link_rate;
-                       cur->lane_count = max->lane_count;
-               } else {
-                       return false;
-               }
-               break;
-       }
-       default:
-               return false;
-       }
-       return true;
-}
-static bool decide_dp_link_settings(struct dc_link *link, struct dc_link_settings *link_setting, uint32_t req_bw)
-{
-       struct dc_link_settings initial_link_setting = {
-               LANE_COUNT_ONE, LINK_RATE_LOW, LINK_SPREAD_DISABLED, false, 0};
-       struct dc_link_settings current_link_setting =
-                       initial_link_setting;
-       uint32_t link_bw;
-
-       if (req_bw > dc_link_bandwidth_kbps(link, &link->verified_link_cap))
-               return false;
-
-       /* search for the minimum link setting that:
-        * 1. is supported according to the link training result
-        * 2. could support the b/w requested by the timing
-        */
-       while (current_link_setting.link_rate <=
-                       link->verified_link_cap.link_rate) {
-               link_bw = dc_link_bandwidth_kbps(
-                               link,
-                               &current_link_setting);
-               if (req_bw <= link_bw) {
-                       *link_setting = current_link_setting;
-                       return true;
-               }
-
-               if (current_link_setting.lane_count <
-                               link->verified_link_cap.lane_count) {
-                       current_link_setting.lane_count =
-                                       increase_lane_count(
-                                                       current_link_setting.lane_count);
-               } else {
-                       current_link_setting.link_rate =
-                                       increase_link_rate(link,
-                                                       current_link_setting.link_rate);
-                       current_link_setting.lane_count =
-                                       initial_link_setting.lane_count;
-               }
-       }
-
-       return false;
-}
-
-bool dc_link_decide_edp_link_settings(struct dc_link *link, struct dc_link_settings *link_setting, uint32_t req_bw)
-{
-       struct dc_link_settings initial_link_setting;
-       struct dc_link_settings current_link_setting;
-       uint32_t link_bw;
-
-       /*
-        * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
-        * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
-        */
-       if (link->dpcd_caps.dpcd_rev.raw < DPCD_REV_13 ||
-                       link->dpcd_caps.edp_supported_link_rates_count == 0) {
-               *link_setting = link->verified_link_cap;
-               return true;
-       }
-
-       memset(&initial_link_setting, 0, sizeof(initial_link_setting));
-       initial_link_setting.lane_count = LANE_COUNT_ONE;
-       initial_link_setting.link_rate = link->dpcd_caps.edp_supported_link_rates[0];
-       initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
-       initial_link_setting.use_link_rate_set = true;
-       initial_link_setting.link_rate_set = 0;
-       current_link_setting = initial_link_setting;
-
-       /* search for the minimum link setting that:
-        * 1. is supported according to the link training result
-        * 2. could support the b/w requested by the timing
-        */
-       while (current_link_setting.link_rate <=
-                       link->verified_link_cap.link_rate) {
-               link_bw = dc_link_bandwidth_kbps(
-                               link,
-                               &current_link_setting);
-               if (req_bw <= link_bw) {
-                       *link_setting = current_link_setting;
-                       return true;
-               }
-
-               if (current_link_setting.lane_count <
-                               link->verified_link_cap.lane_count) {
-                       current_link_setting.lane_count =
-                                       increase_lane_count(
-                                                       current_link_setting.lane_count);
-               } else {
-                       if (current_link_setting.link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
-                               current_link_setting.link_rate_set++;
-                               current_link_setting.link_rate =
-                                       link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
-                               current_link_setting.lane_count =
-                                                                       initial_link_setting.lane_count;
-                       } else
-                               break;
-               }
-       }
-       return false;
-}
-
-bool decide_edp_link_settings_with_dsc(struct dc_link *link,
-               struct dc_link_settings *link_setting,
-               uint32_t req_bw,
-               enum dc_link_rate max_link_rate)
-{
-       struct dc_link_settings initial_link_setting;
-       struct dc_link_settings current_link_setting;
-       uint32_t link_bw;
-
-       unsigned int policy = 0;
-
-       policy = link->panel_config.dsc.force_dsc_edp_policy;
-       if (max_link_rate == LINK_RATE_UNKNOWN)
-               max_link_rate = link->verified_link_cap.link_rate;
-       /*
-        * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
-        * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
-        */
-       if ((link->dpcd_caps.dpcd_rev.raw < DPCD_REV_13 ||
-                       link->dpcd_caps.edp_supported_link_rates_count == 0)) {
-               /* for DSC enabled case, we search for minimum lane count */
-               memset(&initial_link_setting, 0, sizeof(initial_link_setting));
-               initial_link_setting.lane_count = LANE_COUNT_ONE;
-               initial_link_setting.link_rate = LINK_RATE_LOW;
-               initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
-               initial_link_setting.use_link_rate_set = false;
-               initial_link_setting.link_rate_set = 0;
-               current_link_setting = initial_link_setting;
-               if (req_bw > dc_link_bandwidth_kbps(link, &link->verified_link_cap))
-                       return false;
-
-               /* search for the minimum link setting that:
-                * 1. is supported according to the link training result
-                * 2. could support the b/w requested by the timing
-                */
-               while (current_link_setting.link_rate <=
-                               max_link_rate) {
-                       link_bw = dc_link_bandwidth_kbps(
-                                       link,
-                                       &current_link_setting);
-                       if (req_bw <= link_bw) {
-                               *link_setting = current_link_setting;
-                               return true;
-                       }
-                       if (policy) {
-                               /* minimize lane */
-                               if (current_link_setting.link_rate < max_link_rate) {
-                                       current_link_setting.link_rate =
-                                                       increase_link_rate(link,
-                                                                       current_link_setting.link_rate);
-                               } else {
-                                       if (current_link_setting.lane_count <
-                                                                       link->verified_link_cap.lane_count) {
-                                               current_link_setting.lane_count =
-                                                               increase_lane_count(
-                                                                               current_link_setting.lane_count);
-                                               current_link_setting.link_rate = initial_link_setting.link_rate;
-                                       } else
-                                               break;
-                               }
-                       } else {
-                               /* minimize link rate */
-                               if (current_link_setting.lane_count <
-                                               link->verified_link_cap.lane_count) {
-                                       current_link_setting.lane_count =
-                                                       increase_lane_count(
-                                                                       current_link_setting.lane_count);
-                               } else {
-                                       current_link_setting.link_rate =
-                                                       increase_link_rate(link,
-                                                                       current_link_setting.link_rate);
-                                       current_link_setting.lane_count =
-                                                       initial_link_setting.lane_count;
-                               }
-                       }
-               }
-               return false;
-       }
-
-       /* if optimize edp link is supported */
-       memset(&initial_link_setting, 0, sizeof(initial_link_setting));
-       initial_link_setting.lane_count = LANE_COUNT_ONE;
-       initial_link_setting.link_rate = link->dpcd_caps.edp_supported_link_rates[0];
-       initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
-       initial_link_setting.use_link_rate_set = true;
-       initial_link_setting.link_rate_set = 0;
-       current_link_setting = initial_link_setting;
-
-       /* search for the minimum link setting that:
-        * 1. is supported according to the link training result
-        * 2. could support the b/w requested by the timing
-        */
-       while (current_link_setting.link_rate <=
-                       max_link_rate) {
-               link_bw = dc_link_bandwidth_kbps(
-                               link,
-                               &current_link_setting);
-               if (req_bw <= link_bw) {
-                       *link_setting = current_link_setting;
-                       return true;
-               }
-               if (policy) {
-                       /* minimize lane */
-                       if (current_link_setting.link_rate_set <
-                                       link->dpcd_caps.edp_supported_link_rates_count
-                                       && current_link_setting.link_rate < max_link_rate) {
-                               current_link_setting.link_rate_set++;
-                               current_link_setting.link_rate =
-                                       link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
-                       } else {
-                               if (current_link_setting.lane_count < link->verified_link_cap.lane_count) {
-                                       current_link_setting.lane_count =
-                                                       increase_lane_count(
-                                                                       current_link_setting.lane_count);
-                                       current_link_setting.link_rate_set = initial_link_setting.link_rate_set;
-                                       current_link_setting.link_rate =
-                                               link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
-                               } else
-                                       break;
-                       }
-               } else {
-                       /* minimize link rate */
-                       if (current_link_setting.lane_count <
-                                       link->verified_link_cap.lane_count) {
-                               current_link_setting.lane_count =
-                                               increase_lane_count(
-                                                               current_link_setting.lane_count);
-                       } else {
-                               if (current_link_setting.link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
-                                       current_link_setting.link_rate_set++;
-                                       current_link_setting.link_rate =
-                                               link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
-                                       current_link_setting.lane_count =
-                                               initial_link_setting.lane_count;
-                               } else
-                                       break;
-                       }
-               }
-       }
-       return false;
-}
-
-static bool decide_mst_link_settings(const struct dc_link *link, struct dc_link_settings *link_setting)
-{
-       *link_setting = link->verified_link_cap;
-       return true;
-}
-
-bool link_decide_link_settings(struct dc_stream_state *stream,
-       struct dc_link_settings *link_setting)
-{
-       struct dc_link *link = stream->link;
-       uint32_t req_bw = dc_bandwidth_in_kbps_from_timing(&stream->timing);
-
-       memset(link_setting, 0, sizeof(*link_setting));
-
-       /* if preferred is specified through AMDDP, use it, if it's enough
-        * to drive the mode
-        */
-       if (link->preferred_link_setting.lane_count !=
-                       LANE_COUNT_UNKNOWN &&
-                       link->preferred_link_setting.link_rate !=
-                                       LINK_RATE_UNKNOWN) {
-               *link_setting = link->preferred_link_setting;
-               return true;
-       }
-
-       /* MST doesn't perform link training for now
-        * TODO: add MST specific link training routine
-        */
-       if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
-               decide_mst_link_settings(link, link_setting);
-       } else if (link->connector_signal == SIGNAL_TYPE_EDP) {
-               /* enable edp link optimization for DSC eDP case */
-               if (stream->timing.flags.DSC) {
-                       enum dc_link_rate max_link_rate = LINK_RATE_UNKNOWN;
-
-                       if (link->panel_config.dsc.force_dsc_edp_policy) {
-                               /* calculate link max link rate cap*/
-                               struct dc_link_settings tmp_link_setting;
-                               struct dc_crtc_timing tmp_timing = stream->timing;
-                               uint32_t orig_req_bw;
-
-                               tmp_link_setting.link_rate = LINK_RATE_UNKNOWN;
-                               tmp_timing.flags.DSC = 0;
-                               orig_req_bw = dc_bandwidth_in_kbps_from_timing(&tmp_timing);
-                               dc_link_decide_edp_link_settings(link, &tmp_link_setting, orig_req_bw);
-                               max_link_rate = tmp_link_setting.link_rate;
-                       }
-                       decide_edp_link_settings_with_dsc(link, link_setting, req_bw, max_link_rate);
-               } else {
-                       dc_link_decide_edp_link_settings(link, link_setting, req_bw);
-               }
-       } else {
-               decide_dp_link_settings(link, link_setting, req_bw);
-       }
-
-       return link_setting->lane_count != LANE_COUNT_UNKNOWN &&
-                       link_setting->link_rate != LINK_RATE_UNKNOWN;
-}
-
-enum dp_link_encoding link_dp_get_encoding_format(const struct dc_link_settings *link_settings)
-{
-       if ((link_settings->link_rate >= LINK_RATE_LOW) &&
-                       (link_settings->link_rate <= LINK_RATE_HIGH3))
-               return DP_8b_10b_ENCODING;
-       else if ((link_settings->link_rate >= LINK_RATE_UHBR10) &&
-                       (link_settings->link_rate <= LINK_RATE_UHBR20))
-               return DP_128b_132b_ENCODING;
-       return DP_UNKNOWN_ENCODING;
-}
-
-enum dp_link_encoding dc_link_dp_mst_decide_link_encoding_format(const struct dc_link *link)
-{
-       struct dc_link_settings link_settings = {0};
-
-       if (!dc_is_dp_signal(link->connector_signal))
-               return DP_UNKNOWN_ENCODING;
-
-       if (link->preferred_link_setting.lane_count !=
-                       LANE_COUNT_UNKNOWN &&
-                       link->preferred_link_setting.link_rate !=
-                                       LINK_RATE_UNKNOWN) {
-               link_settings = link->preferred_link_setting;
-       } else {
-               decide_mst_link_settings(link, &link_settings);
-       }
-
-       return link_dp_get_encoding_format(&link_settings);
-}
-
-static void read_dp_device_vendor_id(struct dc_link *link)
-{
-       struct dp_device_vendor_id dp_id;
-
-       /* read IEEE branch device id */
-       core_link_read_dpcd(
-               link,
-               DP_BRANCH_OUI,
-               (uint8_t *)&dp_id,
-               sizeof(dp_id));
-
-       link->dpcd_caps.branch_dev_id =
-               (dp_id.ieee_oui[0] << 16) +
-               (dp_id.ieee_oui[1] << 8) +
-               dp_id.ieee_oui[2];
-
-       memmove(
-               link->dpcd_caps.branch_dev_name,
-               dp_id.ieee_device_id,
-               sizeof(dp_id.ieee_device_id));
-}
-
-static enum dc_status wake_up_aux_channel(struct dc_link *link)
-{
-       enum dc_status status = DC_ERROR_UNEXPECTED;
-       uint32_t aux_channel_retry_cnt = 0;
-       uint8_t dpcd_power_state = '\0';
-
-       while (status != DC_OK && aux_channel_retry_cnt < 10) {
-               status = core_link_read_dpcd(link, DP_SET_POWER,
-                               &dpcd_power_state, sizeof(dpcd_power_state));
-
-               /* Delay 1 ms if AUX CH is in power down state. Based on spec
-                * section 2.3.1.2, if AUX CH may be powered down due to
-                * write to DPCD 600h = 2. Sink AUX CH is monitoring differential
-                * signal and may need up to 1 ms before being able to reply.
-                */
-               if (status != DC_OK || dpcd_power_state == DP_SET_POWER_D3) {
-                       udelay(1000);
-                       aux_channel_retry_cnt++;
-               }
-       }
-
-       if (status != DC_OK) {
-               dpcd_power_state = DP_SET_POWER_D0;
-               status = core_link_write_dpcd(
-                               link,
-                               DP_SET_POWER,
-                               &dpcd_power_state,
-                               sizeof(dpcd_power_state));
-
-               dpcd_power_state = DP_SET_POWER_D3;
-               status = core_link_write_dpcd(
-                               link,
-                               DP_SET_POWER,
-                               &dpcd_power_state,
-                               sizeof(dpcd_power_state));
-               return DC_ERROR_UNEXPECTED;
-       }
-
-       return DC_OK;
-}
-
-static void get_active_converter_info(
-       uint8_t data, struct dc_link *link)
-{
-       union dp_downstream_port_present ds_port = { .byte = data };
-       memset(&link->dpcd_caps.dongle_caps, 0, sizeof(link->dpcd_caps.dongle_caps));
-
-       /* decode converter info*/
-       if (!ds_port.fields.PORT_PRESENT) {
-               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
-               set_dongle_type(link->ddc,
-                               link->dpcd_caps.dongle_type);
-               link->dpcd_caps.is_branch_dev = false;
-               return;
-       }
-
-       /* DPCD 0x5 bit 0 = 1, it indicate it's branch device */
-       link->dpcd_caps.is_branch_dev = ds_port.fields.PORT_PRESENT;
-
-       switch (ds_port.fields.PORT_TYPE) {
-       case DOWNSTREAM_VGA:
-               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_VGA_CONVERTER;
-               break;
-       case DOWNSTREAM_DVI_HDMI_DP_PLUS_PLUS:
-               /* At this point we don't know is it DVI or HDMI or DP++,
-                * assume DVI.*/
-               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_DVI_CONVERTER;
-               break;
-       default:
-               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
-               break;
-       }
-
-       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_11) {
-               uint8_t det_caps[16]; /* CTS 4.2.2.7 expects source to read Detailed Capabilities Info : 00080h-0008F.*/
-               union dwnstream_port_caps_byte0 *port_caps =
-                       (union dwnstream_port_caps_byte0 *)det_caps;
-               if (core_link_read_dpcd(link, DP_DOWNSTREAM_PORT_0,
-                               det_caps, sizeof(det_caps)) == DC_OK) {
-
-                       switch (port_caps->bits.DWN_STRM_PORTX_TYPE) {
-                       /*Handle DP case as DONGLE_NONE*/
-                       case DOWN_STREAM_DETAILED_DP:
-                               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
-                               break;
-                       case DOWN_STREAM_DETAILED_VGA:
-                               link->dpcd_caps.dongle_type =
-                                       DISPLAY_DONGLE_DP_VGA_CONVERTER;
-                               break;
-                       case DOWN_STREAM_DETAILED_DVI:
-                               link->dpcd_caps.dongle_type =
-                                       DISPLAY_DONGLE_DP_DVI_CONVERTER;
-                               break;
-                       case DOWN_STREAM_DETAILED_HDMI:
-                       case DOWN_STREAM_DETAILED_DP_PLUS_PLUS:
-                               /*Handle DP++ active converter case, process DP++ case as HDMI case according DP1.4 spec*/
-                               link->dpcd_caps.dongle_type =
-                                       DISPLAY_DONGLE_DP_HDMI_CONVERTER;
-
-                               link->dpcd_caps.dongle_caps.dongle_type = link->dpcd_caps.dongle_type;
-                               if (ds_port.fields.DETAILED_CAPS) {
-
-                                       union dwnstream_port_caps_byte3_hdmi
-                                               hdmi_caps = {.raw = det_caps[3] };
-                                       union dwnstream_port_caps_byte2
-                                               hdmi_color_caps = {.raw = det_caps[2] };
-                                       link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz =
-                                               det_caps[1] * 2500;
-
-                                       link->dpcd_caps.dongle_caps.is_dp_hdmi_s3d_converter =
-                                               hdmi_caps.bits.FRAME_SEQ_TO_FRAME_PACK;
-                                       /*YCBCR capability only for HDMI case*/
-                                       if (port_caps->bits.DWN_STRM_PORTX_TYPE
-                                                       == DOWN_STREAM_DETAILED_HDMI) {
-                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_pass_through =
-                                                               hdmi_caps.bits.YCrCr422_PASS_THROUGH;
-                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_pass_through =
-                                                               hdmi_caps.bits.YCrCr420_PASS_THROUGH;
-                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_converter =
-                                                               hdmi_caps.bits.YCrCr422_CONVERSION;
-                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_converter =
-                                                               hdmi_caps.bits.YCrCr420_CONVERSION;
-                                       }
-
-                                       link->dpcd_caps.dongle_caps.dp_hdmi_max_bpc =
-                                               translate_dpcd_max_bpc(
-                                                       hdmi_color_caps.bits.MAX_BITS_PER_COLOR_COMPONENT);
-
-                                       if (link->dc->caps.dp_hdmi21_pcon_support) {
-                                               union hdmi_encoded_link_bw hdmi_encoded_link_bw;
-
-                                               link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps =
-                                                               dc_link_bw_kbps_from_raw_frl_link_rate_data(
-                                                                               hdmi_color_caps.bits.MAX_ENCODED_LINK_BW_SUPPORT);
-
-                                               // Intersect reported max link bw support with the supported link rate post FRL link training
-                                               if (core_link_read_dpcd(link, DP_PCON_HDMI_POST_FRL_STATUS,
-                                                               &hdmi_encoded_link_bw.raw, sizeof(hdmi_encoded_link_bw)) == DC_OK) {
-                                                       link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps = intersect_frl_link_bw_support(
-                                                                       link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps,
-                                                                       hdmi_encoded_link_bw);
-                                               }
-
-                                               if (link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps > 0)
-                                                       link->dpcd_caps.dongle_caps.extendedCapValid = true;
-                                       }
-
-                                       if (link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz != 0)
-                                               link->dpcd_caps.dongle_caps.extendedCapValid = true;
-                               }
-
-                               break;
-                       }
-               }
-       }
-
-       set_dongle_type(link->ddc, link->dpcd_caps.dongle_type);
-
-       {
-               struct dp_sink_hw_fw_revision dp_hw_fw_revision;
-
-               core_link_read_dpcd(
-                       link,
-                       DP_BRANCH_REVISION_START,
-                       (uint8_t *)&dp_hw_fw_revision,
-                       sizeof(dp_hw_fw_revision));
-
-               link->dpcd_caps.branch_hw_revision =
-                       dp_hw_fw_revision.ieee_hw_rev;
-
-               memmove(
-                       link->dpcd_caps.branch_fw_revision,
-                       dp_hw_fw_revision.ieee_fw_rev,
-                       sizeof(dp_hw_fw_revision.ieee_fw_rev));
-       }
-       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14 &&
-                       link->dpcd_caps.dongle_type != DISPLAY_DONGLE_NONE) {
-               union dp_dfp_cap_ext dfp_cap_ext;
-               memset(&dfp_cap_ext, '\0', sizeof (dfp_cap_ext));
-               core_link_read_dpcd(
-                               link,
-                               DP_DFP_CAPABILITY_EXTENSION_SUPPORT,
-                               dfp_cap_ext.raw,
-                               sizeof(dfp_cap_ext.raw));
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.supported = dfp_cap_ext.fields.supported;
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.max_pixel_rate_in_mps =
-                               dfp_cap_ext.fields.max_pixel_rate_in_mps[0] +
-                               (dfp_cap_ext.fields.max_pixel_rate_in_mps[1] << 8);
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_h_active_width =
-                               dfp_cap_ext.fields.max_video_h_active_width[0] +
-                               (dfp_cap_ext.fields.max_video_h_active_width[1] << 8);
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_v_active_height =
-                               dfp_cap_ext.fields.max_video_v_active_height[0] +
-                               (dfp_cap_ext.fields.max_video_v_active_height[1] << 8);
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.encoding_format_caps =
-                               dfp_cap_ext.fields.encoding_format_caps;
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.rgb_color_depth_caps =
-                               dfp_cap_ext.fields.rgb_color_depth_caps;
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr444_color_depth_caps =
-                               dfp_cap_ext.fields.ycbcr444_color_depth_caps;
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr422_color_depth_caps =
-                               dfp_cap_ext.fields.ycbcr422_color_depth_caps;
-               link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr420_color_depth_caps =
-                               dfp_cap_ext.fields.ycbcr420_color_depth_caps;
-               DC_LOG_DP2("DFP capability extension is read at link %d", link->link_index);
-               DC_LOG_DP2("\tdfp_cap_ext.supported = %s", link->dpcd_caps.dongle_caps.dfp_cap_ext.supported ? "true" : "false");
-               DC_LOG_DP2("\tdfp_cap_ext.max_pixel_rate_in_mps = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_pixel_rate_in_mps);
-               DC_LOG_DP2("\tdfp_cap_ext.max_video_h_active_width = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_h_active_width);
-               DC_LOG_DP2("\tdfp_cap_ext.max_video_v_active_height = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_v_active_height);
-       }
-}
-
-static void apply_usbc_combo_phy_reset_wa(struct dc_link *link,
-               struct dc_link_settings *link_settings)
-{
-       /* Temporary Renoir-specific workaround PHY will sometimes be in bad
-        * state on hotplugging display from certain USB-C dongle, so add extra
-        * cycle of enabling and disabling the PHY before first link training.
-        */
-       struct link_resource link_res = {0};
-       enum clock_source_id dp_cs_id = get_clock_source_id(link);
-
-       dp_enable_link_phy(link, &link_res, link->connector_signal,
-                       dp_cs_id, link_settings);
-       dp_disable_link_phy(link, &link_res, link->connector_signal);
-}
-
-static bool dp_overwrite_extended_receiver_cap(struct dc_link *link)
-{
-       uint8_t dpcd_data[16];
-       uint32_t read_dpcd_retry_cnt = 3;
-       enum dc_status status = DC_ERROR_UNEXPECTED;
-       union dp_downstream_port_present ds_port = { 0 };
-       union down_stream_port_count down_strm_port_count;
-       union edp_configuration_cap edp_config_cap;
-
-       int i;
-
-       for (i = 0; i < read_dpcd_retry_cnt; i++) {
-               status = core_link_read_dpcd(
-                               link,
-                               DP_DPCD_REV,
-                               dpcd_data,
-                               sizeof(dpcd_data));
-               if (status == DC_OK)
-                       break;
-       }
-
-       link->dpcd_caps.dpcd_rev.raw =
-               dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
-
-       if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
-               return false;
-
-       ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
-                       DP_DPCD_REV];
-
-       get_active_converter_info(ds_port.byte, link);
-
-       down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
-                       DP_DPCD_REV];
-
-       link->dpcd_caps.allow_invalid_MSA_timing_param =
-               down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
-
-       link->dpcd_caps.max_ln_count.raw = dpcd_data[
-               DP_MAX_LANE_COUNT - DP_DPCD_REV];
-
-       link->dpcd_caps.max_down_spread.raw = dpcd_data[
-               DP_MAX_DOWNSPREAD - DP_DPCD_REV];
-
-       link->reported_link_cap.lane_count =
-               link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
-       link->reported_link_cap.link_rate = dpcd_data[
-               DP_MAX_LINK_RATE - DP_DPCD_REV];
-       link->reported_link_cap.link_spread =
-               link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
-               LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
-
-       edp_config_cap.raw = dpcd_data[
-               DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
-       link->dpcd_caps.panel_mode_edp =
-               edp_config_cap.bits.ALT_SCRAMBLER_RESET;
-       link->dpcd_caps.dpcd_display_control_capable =
-               edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
-
-       return true;
-}
-
-void dc_link_overwrite_extended_receiver_cap(
-               struct dc_link *link)
-{
-       dp_overwrite_extended_receiver_cap(link);
-}
-
-void dpcd_set_source_specific_data(struct dc_link *link)
-{
-       if (!link->dc->vendor_signature.is_valid) {
-               enum dc_status result_write_min_hblank = DC_NOT_SUPPORTED;
-               struct dpcd_amd_signature amd_signature = {0};
-               struct dpcd_amd_device_id amd_device_id = {0};
-
-               amd_device_id.device_id_byte1 =
-                               (uint8_t)(link->ctx->asic_id.chip_id);
-               amd_device_id.device_id_byte2 =
-                               (uint8_t)(link->ctx->asic_id.chip_id >> 8);
-               amd_device_id.dce_version =
-                               (uint8_t)(link->ctx->dce_version);
-               amd_device_id.dal_version_byte1 = 0x0; // needed? where to get?
-               amd_device_id.dal_version_byte2 = 0x0; // needed? where to get?
-
-               core_link_read_dpcd(link, DP_SOURCE_OUI,
-                               (uint8_t *)(&amd_signature),
-                               sizeof(amd_signature));
-
-               if (!((amd_signature.AMD_IEEE_TxSignature_byte1 == 0x0) &&
-                       (amd_signature.AMD_IEEE_TxSignature_byte2 == 0x0) &&
-                       (amd_signature.AMD_IEEE_TxSignature_byte3 == 0x1A))) {
-
-                       amd_signature.AMD_IEEE_TxSignature_byte1 = 0x0;
-                       amd_signature.AMD_IEEE_TxSignature_byte2 = 0x0;
-                       amd_signature.AMD_IEEE_TxSignature_byte3 = 0x1A;
-
-                       core_link_write_dpcd(link, DP_SOURCE_OUI,
-                               (uint8_t *)(&amd_signature),
-                               sizeof(amd_signature));
-               }
-
-               core_link_write_dpcd(link, DP_SOURCE_OUI+0x03,
-                               (uint8_t *)(&amd_device_id),
-                               sizeof(amd_device_id));
-
-               if (link->ctx->dce_version >= DCN_VERSION_2_0 &&
-                       link->dc->caps.min_horizontal_blanking_period != 0) {
-
-                       uint8_t hblank_size = (uint8_t)link->dc->caps.min_horizontal_blanking_period;
-
-                       result_write_min_hblank = core_link_write_dpcd(link,
-                               DP_SOURCE_MINIMUM_HBLANK_SUPPORTED, (uint8_t *)(&hblank_size),
-                               sizeof(hblank_size));
-               }
-               DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION,
-                                                       WPP_BIT_FLAG_DC_DETECTION_DP_CAPS,
-                                                       "result=%u link_index=%u enum dce_version=%d DPCD=0x%04X min_hblank=%u branch_dev_id=0x%x branch_dev_name='%c%c%c%c%c%c'",
-                                                       result_write_min_hblank,
-                                                       link->link_index,
-                                                       link->ctx->dce_version,
-                                                       DP_SOURCE_MINIMUM_HBLANK_SUPPORTED,
-                                                       link->dc->caps.min_horizontal_blanking_period,
-                                                       link->dpcd_caps.branch_dev_id,
-                                                       link->dpcd_caps.branch_dev_name[0],
-                                                       link->dpcd_caps.branch_dev_name[1],
-                                                       link->dpcd_caps.branch_dev_name[2],
-                                                       link->dpcd_caps.branch_dev_name[3],
-                                                       link->dpcd_caps.branch_dev_name[4],
-                                                       link->dpcd_caps.branch_dev_name[5]);
-       } else {
-               core_link_write_dpcd(link, DP_SOURCE_OUI,
-                               link->dc->vendor_signature.data.raw,
-                               sizeof(link->dc->vendor_signature.data.raw));
-       }
-}
-
-void dpcd_write_cable_id_to_dprx(struct dc_link *link)
-{
-       if (!link->dpcd_caps.channel_coding_cap.bits.DP_128b_132b_SUPPORTED ||
-                       link->dpcd_caps.cable_id.raw == 0 ||
-                       link->dprx_states.cable_id_written)
-               return;
-
-       core_link_write_dpcd(link, DP_CABLE_ATTRIBUTES_UPDATED_BY_DPTX,
-                       &link->dpcd_caps.cable_id.raw,
-                       sizeof(link->dpcd_caps.cable_id.raw));
-
-       link->dprx_states.cable_id_written = 1;
-}
-
-static bool get_usbc_cable_id(struct dc_link *link, union dp_cable_id *cable_id)
-{
-       union dmub_rb_cmd cmd;
-
-       if (!link->ctx->dmub_srv ||
-                       link->ep_type != DISPLAY_ENDPOINT_PHY ||
-                       link->link_enc->features.flags.bits.DP_IS_USB_C == 0)
-               return false;
-
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.cable_id.header.type = DMUB_CMD_GET_USBC_CABLE_ID;
-       cmd.cable_id.header.payload_bytes = sizeof(cmd.cable_id.data);
-       cmd.cable_id.data.input.phy_inst = resource_transmitter_to_phy_idx(
-                       link->dc, link->link_enc->transmitter);
-       if (dc_dmub_srv_cmd_with_reply_data(link->ctx->dmub_srv, &cmd) &&
-                       cmd.cable_id.header.ret_status == 1) {
-               cable_id->raw = cmd.cable_id.data.output_raw;
-               DC_LOG_DC("usbc_cable_id = %d.\n", cable_id->raw);
-       }
-       return cmd.cable_id.header.ret_status == 1;
-}
-
-static void retrieve_cable_id(struct dc_link *link)
-{
-       union dp_cable_id usbc_cable_id;
-
-       link->dpcd_caps.cable_id.raw = 0;
-       core_link_read_dpcd(link, DP_CABLE_ATTRIBUTES_UPDATED_BY_DPRX,
-                       &link->dpcd_caps.cable_id.raw, sizeof(uint8_t));
-
-       if (get_usbc_cable_id(link, &usbc_cable_id))
-               link->dpcd_caps.cable_id = intersect_cable_id(
-                               &link->dpcd_caps.cable_id, &usbc_cable_id);
-}
-
-bool read_is_mst_supported(struct dc_link *link)
-{
-       bool mst          = false;
-       enum dc_status st = DC_OK;
-       union dpcd_rev rev;
-       union mstm_cap cap;
-
-       if (link->preferred_training_settings.mst_enable &&
-               *link->preferred_training_settings.mst_enable == false) {
-               return false;
-       }
-
-       rev.raw  = 0;
-       cap.raw  = 0;
-
-       st = core_link_read_dpcd(link, DP_DPCD_REV, &rev.raw,
-                       sizeof(rev));
-
-       if (st == DC_OK && rev.raw >= DPCD_REV_12) {
-
-               st = core_link_read_dpcd(link, DP_MSTM_CAP,
-                               &cap.raw, sizeof(cap));
-               if (st == DC_OK && cap.bits.MST_CAP == 1)
-                       mst = true;
-       }
-       return mst;
-
-}
-
-/* Read additional sink caps defined in source specific DPCD area
- * This function currently only reads from SinkCapability address (DP_SOURCE_SINK_CAP)
- * TODO: Add FS caps and read from DP_SOURCE_SINK_FS_CAP as well
- */
-static bool dpcd_read_sink_ext_caps(struct dc_link *link)
-{
-       uint8_t dpcd_data;
-
-       if (!link)
-               return false;
-
-       if (core_link_read_dpcd(link, DP_SOURCE_SINK_CAP, &dpcd_data, 1) != DC_OK)
-               return false;
-
-       link->dpcd_sink_ext_caps.raw = dpcd_data;
-       return true;
-}
-
-enum dc_status dp_retrieve_lttpr_cap(struct dc_link *link)
-{
-       uint8_t lttpr_dpcd_data[8];
-       enum dc_status status;
-       bool is_lttpr_present;
-
-       /* Logic to determine LTTPR support*/
-       bool vbios_lttpr_interop = link->dc->caps.vbios_lttpr_aware;
-
-       if (!vbios_lttpr_interop || !link->dc->caps.extended_aux_timeout_support)
-               return DC_NOT_SUPPORTED;
-
-       /* By reading LTTPR capability, RX assumes that we will enable
-        * LTTPR extended aux timeout if LTTPR is present.
-        */
-       status = core_link_read_dpcd(
-                       link,
-                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV,
-                       lttpr_dpcd_data,
-                       sizeof(lttpr_dpcd_data));
-
-       link->dpcd_caps.lttpr_caps.revision.raw =
-                       lttpr_dpcd_data[DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-
-       link->dpcd_caps.lttpr_caps.max_link_rate =
-                       lttpr_dpcd_data[DP_MAX_LINK_RATE_PHY_REPEATER -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-
-       link->dpcd_caps.lttpr_caps.phy_repeater_cnt =
-                       lttpr_dpcd_data[DP_PHY_REPEATER_CNT -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-
-       link->dpcd_caps.lttpr_caps.max_lane_count =
-                       lttpr_dpcd_data[DP_MAX_LANE_COUNT_PHY_REPEATER -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-
-       link->dpcd_caps.lttpr_caps.mode =
-                       lttpr_dpcd_data[DP_PHY_REPEATER_MODE -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-
-       link->dpcd_caps.lttpr_caps.max_ext_timeout =
-                       lttpr_dpcd_data[DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-       link->dpcd_caps.lttpr_caps.main_link_channel_coding.raw =
-                       lttpr_dpcd_data[DP_MAIN_LINK_CHANNEL_CODING_PHY_REPEATER -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-
-       link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.raw =
-                       lttpr_dpcd_data[DP_PHY_REPEATER_128B132B_RATES -
-                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
-
-       /* If this chip cap is set, at least one retimer must exist in the chain
-        * Override count to 1 if we receive a known bad count (0 or an invalid value) */
-       if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
-                       (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) == 0)) {
-               ASSERT(0);
-               link->dpcd_caps.lttpr_caps.phy_repeater_cnt = 0x80;
-               DC_LOG_DC("lttpr_caps forced phy_repeater_cnt = %d\n", link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-       }
-
-       /* Attempt to train in LTTPR transparent mode if repeater count exceeds 8. */
-       is_lttpr_present = dp_is_lttpr_present(link);
-
-       if (is_lttpr_present)
-               CONN_DATA_DETECT(link, lttpr_dpcd_data, sizeof(lttpr_dpcd_data), "LTTPR Caps: ");
-
-       DC_LOG_DC("is_lttpr_present = %d\n", is_lttpr_present);
-       return status;
-}
-
-static bool retrieve_link_cap(struct dc_link *link)
-{
-       /* DP_ADAPTER_CAP - DP_DPCD_REV + 1 == 16 and also DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT + 1 == 16,
-        * which means size 16 will be good for both of those DPCD register block reads
-        */
-       uint8_t dpcd_data[16];
-       /*Only need to read 1 byte starting from DP_DPRX_FEATURE_ENUMERATION_LIST.
-        */
-       uint8_t dpcd_dprx_data = '\0';
-
-       struct dp_device_vendor_id sink_id;
-       union down_stream_port_count down_strm_port_count;
-       union edp_configuration_cap edp_config_cap;
-       union dp_downstream_port_present ds_port = { 0 };
-       enum dc_status status = DC_ERROR_UNEXPECTED;
-       uint32_t read_dpcd_retry_cnt = 3;
-       int i;
-       struct dp_sink_hw_fw_revision dp_hw_fw_revision;
-       const uint32_t post_oui_delay = 30; // 30ms
-
-       memset(dpcd_data, '\0', sizeof(dpcd_data));
-       memset(&down_strm_port_count,
-               '\0', sizeof(union down_stream_port_count));
-       memset(&edp_config_cap, '\0',
-               sizeof(union edp_configuration_cap));
-
-       /* if extended timeout is supported in hardware,
-        * default to LTTPR timeout (3.2ms) first as a W/A for DP link layer
-        * CTS 4.2.1.1 regression introduced by CTS specs requirement update.
-        */
-       try_to_configure_aux_timeout(link->ddc,
-                       LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD);
-
-       status = dp_retrieve_lttpr_cap(link);
-
-       if (status != DC_OK) {
-               status = wake_up_aux_channel(link);
-               if (status == DC_OK)
-                       dp_retrieve_lttpr_cap(link);
-               else
-                       return false;
-       }
-
-       if (dp_is_lttpr_present(link))
-               configure_lttpr_mode_transparent(link);
-
-       /* Read DP tunneling information. */
-       status = dpcd_get_tunneling_device_data(link);
-
-       dpcd_set_source_specific_data(link);
-       /* Sink may need to configure internals based on vendor, so allow some
-        * time before proceeding with possibly vendor specific transactions
-        */
-       msleep(post_oui_delay);
-
-       for (i = 0; i < read_dpcd_retry_cnt; i++) {
-               status = core_link_read_dpcd(
-                               link,
-                               DP_DPCD_REV,
-                               dpcd_data,
-                               sizeof(dpcd_data));
-               if (status == DC_OK)
-                       break;
-       }
-
-
-       if (status != DC_OK) {
-               dm_error("%s: Read receiver caps dpcd data failed.\n", __func__);
-               return false;
-       }
-
-       if (!dp_is_lttpr_present(link))
-               try_to_configure_aux_timeout(link->ddc, LINK_AUX_DEFAULT_TIMEOUT_PERIOD);
-
-
-       {
-               union training_aux_rd_interval aux_rd_interval;
-
-               aux_rd_interval.raw =
-                       dpcd_data[DP_TRAINING_AUX_RD_INTERVAL];
-
-               link->dpcd_caps.ext_receiver_cap_field_present =
-                               aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1 ? true:false;
-
-               if (aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1) {
-                       uint8_t ext_cap_data[16];
-
-                       memset(ext_cap_data, '\0', sizeof(ext_cap_data));
-                       for (i = 0; i < read_dpcd_retry_cnt; i++) {
-                               status = core_link_read_dpcd(
-                               link,
-                               DP_DP13_DPCD_REV,
-                               ext_cap_data,
-                               sizeof(ext_cap_data));
-                               if (status == DC_OK) {
-                                       memcpy(dpcd_data, ext_cap_data, sizeof(dpcd_data));
-                                       break;
-                               }
-                       }
-                       if (status != DC_OK)
-                               dm_error("%s: Read extend caps data failed, use cap from dpcd 0.\n", __func__);
-               }
-       }
-
-       link->dpcd_caps.dpcd_rev.raw =
-                       dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
-
-       if (link->dpcd_caps.ext_receiver_cap_field_present) {
-               for (i = 0; i < read_dpcd_retry_cnt; i++) {
-                       status = core_link_read_dpcd(
-                                       link,
-                                       DP_DPRX_FEATURE_ENUMERATION_LIST,
-                                       &dpcd_dprx_data,
-                                       sizeof(dpcd_dprx_data));
-                       if (status == DC_OK)
-                               break;
-               }
-
-               link->dpcd_caps.dprx_feature.raw = dpcd_dprx_data;
-
-               if (status != DC_OK)
-                       dm_error("%s: Read DPRX caps data failed.\n", __func__);
-       }
-
-       else {
-               link->dpcd_caps.dprx_feature.raw = 0;
-       }
-
-
-       /* Error condition checking...
-        * It is impossible for Sink to report Max Lane Count = 0.
-        * It is possible for Sink to report Max Link Rate = 0, if it is
-        * an eDP device that is reporting specialized link rates in the
-        * SUPPORTED_LINK_RATE table.
-        */
-       if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
-               return false;
-
-       ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
-                                DP_DPCD_REV];
-
-       read_dp_device_vendor_id(link);
-
-       /* TODO - decouple raw mst capability from policy decision */
-       link->dpcd_caps.is_mst_capable = read_is_mst_supported(link);
-
-       get_active_converter_info(ds_port.byte, link);
-
-       dp_wa_power_up_0010FA(link, dpcd_data, sizeof(dpcd_data));
-
-       down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
-                                DP_DPCD_REV];
-
-       link->dpcd_caps.allow_invalid_MSA_timing_param =
-               down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
-
-       link->dpcd_caps.max_ln_count.raw = dpcd_data[
-               DP_MAX_LANE_COUNT - DP_DPCD_REV];
-
-       link->dpcd_caps.max_down_spread.raw = dpcd_data[
-               DP_MAX_DOWNSPREAD - DP_DPCD_REV];
-
-       link->reported_link_cap.lane_count =
-               link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
-       link->reported_link_cap.link_rate = get_link_rate_from_max_link_bw(
-                       dpcd_data[DP_MAX_LINK_RATE - DP_DPCD_REV]);
-       link->reported_link_cap.link_spread =
-               link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
-               LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
-
-       edp_config_cap.raw = dpcd_data[
-               DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
-       link->dpcd_caps.panel_mode_edp =
-               edp_config_cap.bits.ALT_SCRAMBLER_RESET;
-       link->dpcd_caps.dpcd_display_control_capable =
-               edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
-       link->dpcd_caps.channel_coding_cap.raw =
-                       dpcd_data[DP_MAIN_LINK_CHANNEL_CODING - DP_DPCD_REV];
-       link->test_pattern_enabled = false;
-       link->compliance_test_state.raw = 0;
-
-       /* read sink count */
-       core_link_read_dpcd(link,
-                       DP_SINK_COUNT,
-                       &link->dpcd_caps.sink_count.raw,
-                       sizeof(link->dpcd_caps.sink_count.raw));
-
-       /* read sink ieee oui */
-       core_link_read_dpcd(link,
-                       DP_SINK_OUI,
-                       (uint8_t *)(&sink_id),
-                       sizeof(sink_id));
-
-       link->dpcd_caps.sink_dev_id =
-                       (sink_id.ieee_oui[0] << 16) +
-                       (sink_id.ieee_oui[1] << 8) +
-                       (sink_id.ieee_oui[2]);
-
-       memmove(
-               link->dpcd_caps.sink_dev_id_str,
-               sink_id.ieee_device_id,
-               sizeof(sink_id.ieee_device_id));
-
-       core_link_read_dpcd(
-               link,
-               DP_SINK_HW_REVISION_START,
-               (uint8_t *)&dp_hw_fw_revision,
-               sizeof(dp_hw_fw_revision));
-
-       link->dpcd_caps.sink_hw_revision =
-               dp_hw_fw_revision.ieee_hw_rev;
-
-       memmove(
-               link->dpcd_caps.sink_fw_revision,
-               dp_hw_fw_revision.ieee_fw_rev,
-               sizeof(dp_hw_fw_revision.ieee_fw_rev));
-
-       /* Quirk for Retina panels: wrong DP_MAX_LINK_RATE */
-       {
-               uint8_t str_mbp_2018[] = { 101, 68, 21, 103, 98, 97 };
-               uint8_t fwrev_mbp_2018[] = { 7, 4 };
-               uint8_t fwrev_mbp_2018_vega[] = { 8, 4 };
-
-               /* We also check for the firmware revision as 16,1 models have an
-                * identical device id and are incorrectly quirked otherwise.
-                */
-               if ((link->dpcd_caps.sink_dev_id == 0x0010fa) &&
-                   !memcmp(link->dpcd_caps.sink_dev_id_str, str_mbp_2018,
-                            sizeof(str_mbp_2018)) &&
-                   (!memcmp(link->dpcd_caps.sink_fw_revision, fwrev_mbp_2018,
-                            sizeof(fwrev_mbp_2018)) ||
-                   !memcmp(link->dpcd_caps.sink_fw_revision, fwrev_mbp_2018_vega,
-                            sizeof(fwrev_mbp_2018_vega)))) {
-                       link->reported_link_cap.link_rate = LINK_RATE_RBR2;
-               }
-       }
-
-       memset(&link->dpcd_caps.dsc_caps, '\0',
-                       sizeof(link->dpcd_caps.dsc_caps));
-       memset(&link->dpcd_caps.fec_cap, '\0', sizeof(link->dpcd_caps.fec_cap));
-       /* Read DSC and FEC sink capabilities if DP revision is 1.4 and up */
-       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14) {
-               status = core_link_read_dpcd(
-                               link,
-                               DP_FEC_CAPABILITY,
-                               &link->dpcd_caps.fec_cap.raw,
-                               sizeof(link->dpcd_caps.fec_cap.raw));
-               status = core_link_read_dpcd(
-                               link,
-                               DP_DSC_SUPPORT,
-                               link->dpcd_caps.dsc_caps.dsc_basic_caps.raw,
-                               sizeof(link->dpcd_caps.dsc_caps.dsc_basic_caps.raw));
-               if (link->dpcd_caps.dongle_type != DISPLAY_DONGLE_NONE) {
-                       status = core_link_read_dpcd(
-                                       link,
-                                       DP_DSC_BRANCH_OVERALL_THROUGHPUT_0,
-                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw,
-                                       sizeof(link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw));
-                       DC_LOG_DSC("DSC branch decoder capability is read at link %d", link->link_index);
-                       DC_LOG_DSC("\tBRANCH_OVERALL_THROUGHPUT_0 = 0x%02x",
-                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_OVERALL_THROUGHPUT_0);
-                       DC_LOG_DSC("\tBRANCH_OVERALL_THROUGHPUT_1 = 0x%02x",
-                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_OVERALL_THROUGHPUT_1);
-                       DC_LOG_DSC("\tBRANCH_MAX_LINE_WIDTH 0x%02x",
-                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_MAX_LINE_WIDTH);
-               }
-
-               /* Apply work around to disable FEC and DSC for USB4 tunneling in TBT3 compatibility mode
-                * only if required.
-                */
-               if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA &&
-                               link->dc->debug.dpia_debug.bits.enable_force_tbt3_work_around &&
-                               link->dpcd_caps.is_branch_dev &&
-                               link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_90CC24 &&
-                               link->dpcd_caps.branch_hw_revision == DP_BRANCH_HW_REV_10 &&
-                               (link->dpcd_caps.fec_cap.bits.FEC_CAPABLE ||
-                               link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT)) {
-                       /* A TBT3 device is expected to report no support for FEC or DSC to a USB4 DPIA.
-                        * Clear FEC and DSC capabilities as a work around if that is not the case.
-                        */
-                       link->wa_flags.dpia_forced_tbt3_mode = true;
-                       memset(&link->dpcd_caps.dsc_caps, '\0', sizeof(link->dpcd_caps.dsc_caps));
-                       memset(&link->dpcd_caps.fec_cap, '\0', sizeof(link->dpcd_caps.fec_cap));
-                       DC_LOG_DSC("Clear DSC SUPPORT for USB4 link(%d) in TBT3 compatibility mode", link->link_index);
-               } else
-                       link->wa_flags.dpia_forced_tbt3_mode = false;
-       }
-
-       if (!dpcd_read_sink_ext_caps(link))
-               link->dpcd_sink_ext_caps.raw = 0;
-
-       if (link->dpcd_caps.channel_coding_cap.bits.DP_128b_132b_SUPPORTED) {
-               DC_LOG_DP2("128b/132b encoding is supported at link %d", link->link_index);
-
-               core_link_read_dpcd(link,
-                               DP_128B132B_SUPPORTED_LINK_RATES,
-                               &link->dpcd_caps.dp_128b_132b_supported_link_rates.raw,
-                               sizeof(link->dpcd_caps.dp_128b_132b_supported_link_rates.raw));
-               if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR20)
-                       link->reported_link_cap.link_rate = LINK_RATE_UHBR20;
-               else if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5)
-                       link->reported_link_cap.link_rate = LINK_RATE_UHBR13_5;
-               else if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR10)
-                       link->reported_link_cap.link_rate = LINK_RATE_UHBR10;
-               else
-                       dm_error("%s: Invalid RX 128b_132b_supported_link_rates\n", __func__);
-               DC_LOG_DP2("128b/132b supported link rates is read at link %d", link->link_index);
-               DC_LOG_DP2("\tmax 128b/132b link rate support is %d.%d GHz",
-                               link->reported_link_cap.link_rate / 100,
-                               link->reported_link_cap.link_rate % 100);
-
-               core_link_read_dpcd(link,
-                               DP_SINK_VIDEO_FALLBACK_FORMATS,
-                               &link->dpcd_caps.fallback_formats.raw,
-                               sizeof(link->dpcd_caps.fallback_formats.raw));
-               DC_LOG_DP2("sink video fallback format is read at link %d", link->link_index);
-               if (link->dpcd_caps.fallback_formats.bits.dp_1920x1080_60Hz_24bpp_support)
-                       DC_LOG_DP2("\t1920x1080@60Hz 24bpp fallback format supported");
-               if (link->dpcd_caps.fallback_formats.bits.dp_1280x720_60Hz_24bpp_support)
-                       DC_LOG_DP2("\t1280x720@60Hz 24bpp fallback format supported");
-               if (link->dpcd_caps.fallback_formats.bits.dp_1024x768_60Hz_24bpp_support)
-                       DC_LOG_DP2("\t1024x768@60Hz 24bpp fallback format supported");
-               if (link->dpcd_caps.fallback_formats.raw == 0) {
-                       DC_LOG_DP2("\tno supported fallback formats, assume 1920x1080@60Hz 24bpp is supported");
-                       link->dpcd_caps.fallback_formats.bits.dp_1920x1080_60Hz_24bpp_support = 1;
-               }
-
-               core_link_read_dpcd(link,
-                               DP_FEC_CAPABILITY_1,
-                               &link->dpcd_caps.fec_cap1.raw,
-                               sizeof(link->dpcd_caps.fec_cap1.raw));
-               DC_LOG_DP2("FEC CAPABILITY 1 is read at link %d", link->link_index);
-               if (link->dpcd_caps.fec_cap1.bits.AGGREGATED_ERROR_COUNTERS_CAPABLE)
-                       DC_LOG_DP2("\tFEC aggregated error counters are supported");
-       }
-
-       retrieve_cable_id(link);
-       dpcd_write_cable_id_to_dprx(link);
-
-       /* Connectivity log: detection */
-       CONN_DATA_DETECT(link, dpcd_data, sizeof(dpcd_data), "Rx Caps: ");
-
-       return true;
-}
-
-bool detect_dp_sink_caps(struct dc_link *link)
-{
-       return retrieve_link_cap(link);
-}
-
-void detect_edp_sink_caps(struct dc_link *link)
-{
-       uint8_t supported_link_rates[16];
-       uint32_t entry;
-       uint32_t link_rate_in_khz;
-       enum dc_link_rate link_rate = LINK_RATE_UNKNOWN;
-       uint8_t backlight_adj_cap;
-       uint8_t general_edp_cap;
-
-       retrieve_link_cap(link);
-       link->dpcd_caps.edp_supported_link_rates_count = 0;
-       memset(supported_link_rates, 0, sizeof(supported_link_rates));
-
-       /*
-        * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
-        * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
-        */
-       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_13 &&
-                       (link->panel_config.ilr.optimize_edp_link_rate ||
-                       link->reported_link_cap.link_rate == LINK_RATE_UNKNOWN)) {
-               // Read DPCD 00010h - 0001Fh 16 bytes at one shot
-               core_link_read_dpcd(link, DP_SUPPORTED_LINK_RATES,
-                                                       supported_link_rates, sizeof(supported_link_rates));
-
-               for (entry = 0; entry < 16; entry += 2) {
-                       // DPCD register reports per-lane link rate = 16-bit link rate capability
-                       // value X 200 kHz. Need multiplier to find link rate in kHz.
-                       link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
-                                                                               supported_link_rates[entry]) * 200;
-
-                       if (link_rate_in_khz != 0) {
-                               link_rate = linkRateInKHzToLinkRateMultiplier(link_rate_in_khz);
-                               link->dpcd_caps.edp_supported_link_rates[link->dpcd_caps.edp_supported_link_rates_count] = link_rate;
-                               link->dpcd_caps.edp_supported_link_rates_count++;
-
-                               if (link->reported_link_cap.link_rate < link_rate)
-                                       link->reported_link_cap.link_rate = link_rate;
-                       }
-               }
-       }
-       core_link_read_dpcd(link, DP_EDP_BACKLIGHT_ADJUSTMENT_CAP,
-                                               &backlight_adj_cap, sizeof(backlight_adj_cap));
-
-       link->dpcd_caps.dynamic_backlight_capable_edp =
-                               (backlight_adj_cap & DP_EDP_DYNAMIC_BACKLIGHT_CAP) ? true:false;
-
-       core_link_read_dpcd(link, DP_EDP_GENERAL_CAP_1,
-                                               &general_edp_cap, sizeof(general_edp_cap));
-
-       link->dpcd_caps.set_power_state_capable_edp =
-                               (general_edp_cap & DP_EDP_SET_POWER_CAP) ? true:false;
-
-       dc_link_set_default_brightness_aux(link);
-
-       core_link_read_dpcd(link, DP_EDP_DPCD_REV,
-               &link->dpcd_caps.edp_rev,
-               sizeof(link->dpcd_caps.edp_rev));
-       /*
-        * PSR is only valid for eDP v1.3 or higher.
-        */
-       if (link->dpcd_caps.edp_rev >= DP_EDP_13) {
-               core_link_read_dpcd(link, DP_PSR_SUPPORT,
-                       &link->dpcd_caps.psr_info.psr_version,
-                       sizeof(link->dpcd_caps.psr_info.psr_version));
-               if (link->dpcd_caps.sink_dev_id == DP_BRANCH_DEVICE_ID_001CF8)
-                       core_link_read_dpcd(link, DP_FORCE_PSRSU_CAPABILITY,
-                                               &link->dpcd_caps.psr_info.force_psrsu_cap,
-                                               sizeof(link->dpcd_caps.psr_info.force_psrsu_cap));
-               core_link_read_dpcd(link, DP_PSR_CAPS,
-                       &link->dpcd_caps.psr_info.psr_dpcd_caps.raw,
-                       sizeof(link->dpcd_caps.psr_info.psr_dpcd_caps.raw));
-               if (link->dpcd_caps.psr_info.psr_dpcd_caps.bits.Y_COORDINATE_REQUIRED) {
-                       core_link_read_dpcd(link, DP_PSR2_SU_Y_GRANULARITY,
-                               &link->dpcd_caps.psr_info.psr2_su_y_granularity_cap,
-                               sizeof(link->dpcd_caps.psr_info.psr2_su_y_granularity_cap));
-               }
-       }
-
-       /*
-        * ALPM is only valid for eDP v1.4 or higher.
-        */
-       if (link->dpcd_caps.dpcd_rev.raw >= DP_EDP_14)
-               core_link_read_dpcd(link, DP_RECEIVER_ALPM_CAP,
-                       &link->dpcd_caps.alpm_caps.raw,
-                       sizeof(link->dpcd_caps.alpm_caps.raw));
-}
-
-bool dc_link_dp_get_max_link_enc_cap(const struct dc_link *link, struct dc_link_settings *max_link_enc_cap)
-{
-       struct link_encoder *link_enc = NULL;
-
-       if (!max_link_enc_cap) {
-               DC_LOG_ERROR("%s: Could not return max link encoder caps", __func__);
-               return false;
-       }
-
-       link_enc = link_enc_cfg_get_link_enc(link);
-       ASSERT(link_enc);
-
-       if (link_enc && link_enc->funcs->get_max_link_cap) {
-               link_enc->funcs->get_max_link_cap(link_enc, max_link_enc_cap);
-               return true;
-       }
-
-       DC_LOG_ERROR("%s: Max link encoder caps unknown", __func__);
-       max_link_enc_cap->lane_count = 1;
-       max_link_enc_cap->link_rate = 6;
-       return false;
-}
-
-const struct dc_link_settings *dc_link_get_link_cap(
-               const struct dc_link *link)
-{
-       if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
-                       link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
-               return &link->preferred_link_setting;
-       return &link->verified_link_cap;
-}
-
-struct dc_link_settings dp_get_max_link_cap(struct dc_link *link)
-{
-       struct dc_link_settings max_link_cap = {0};
-       enum dc_link_rate lttpr_max_link_rate;
-       enum dc_link_rate cable_max_link_rate;
-       struct link_encoder *link_enc = NULL;
-
-
-       link_enc = link_enc_cfg_get_link_enc(link);
-       ASSERT(link_enc);
-
-       /* get max link encoder capability */
-       if (link_enc)
-               link_enc->funcs->get_max_link_cap(link_enc, &max_link_cap);
-
-       /* Lower link settings based on sink's link cap */
-       if (link->reported_link_cap.lane_count < max_link_cap.lane_count)
-               max_link_cap.lane_count =
-                               link->reported_link_cap.lane_count;
-       if (link->reported_link_cap.link_rate < max_link_cap.link_rate)
-               max_link_cap.link_rate =
-                               link->reported_link_cap.link_rate;
-       if (link->reported_link_cap.link_spread <
-                       max_link_cap.link_spread)
-               max_link_cap.link_spread =
-                               link->reported_link_cap.link_spread;
-
-       /* Lower link settings based on cable attributes
-        * Cable ID is a DP2 feature to identify max certified link rate that
-        * a cable can carry. The cable identification method requires both
-        * cable and display hardware support. Since the specs comes late, it is
-        * anticipated that the first round of DP2 cables and displays may not
-        * be fully compatible to reliably return cable ID data. Therefore the
-        * decision of our cable id policy is that if the cable can return non
-        * zero cable id data, we will take cable's link rate capability into
-        * account. However if we get zero data, the cable link rate capability
-        * is considered inconclusive. In this case, we will not take cable's
-        * capability into account to avoid of over limiting hardware capability
-        * from users. The max overall link rate capability is still determined
-        * after actual dp pre-training. Cable id is considered as an auxiliary
-        * method of determining max link bandwidth capability.
-        */
-       cable_max_link_rate = get_cable_max_link_rate(link);
-
-       if (!link->dc->debug.ignore_cable_id &&
-                       cable_max_link_rate != LINK_RATE_UNKNOWN &&
-                       cable_max_link_rate < max_link_cap.link_rate)
-               max_link_cap.link_rate = cable_max_link_rate;
-
-       /* account for lttpr repeaters cap
-        * notes: repeaters do not snoop in the DPRX Capabilities addresses (3.6.3).
-        */
-       if (dp_is_lttpr_present(link)) {
-               if (link->dpcd_caps.lttpr_caps.max_lane_count < max_link_cap.lane_count)
-                       max_link_cap.lane_count = link->dpcd_caps.lttpr_caps.max_lane_count;
-               lttpr_max_link_rate = get_lttpr_max_link_rate(link);
-
-               if (lttpr_max_link_rate < max_link_cap.link_rate)
-                       max_link_cap.link_rate = lttpr_max_link_rate;
-
-               DC_LOG_HW_LINK_TRAINING("%s\n Training with LTTPR,  max_lane count %d max_link rate %d \n",
-                                               __func__,
-                                               max_link_cap.lane_count,
-                                               max_link_cap.link_rate);
-       }
-
-       if (link_dp_get_encoding_format(&max_link_cap) == DP_128b_132b_ENCODING &&
-                       link->dc->debug.disable_uhbr)
-               max_link_cap.link_rate = LINK_RATE_HIGH3;
-
-       return max_link_cap;
-}
-
-static bool dp_verify_link_cap(
-       struct dc_link *link,
-       struct dc_link_settings *known_limit_link_setting,
-       int *fail_count)
-{
-       struct dc_link_settings cur_link_settings = {0};
-       struct dc_link_settings max_link_settings = *known_limit_link_setting;
-       bool success = false;
-       bool skip_video_pattern;
-       enum clock_source_id dp_cs_id = get_clock_source_id(link);
-       enum link_training_result status = LINK_TRAINING_SUCCESS;
-       union hpd_irq_data irq_data;
-       struct link_resource link_res;
-
-       memset(&irq_data, 0, sizeof(irq_data));
-       cur_link_settings = max_link_settings;
-
-       /* Grant extended timeout request */
-       if (dp_is_lttpr_present(link) && link->dpcd_caps.lttpr_caps.max_ext_timeout > 0) {
-               uint8_t grant = link->dpcd_caps.lttpr_caps.max_ext_timeout & 0x80;
-
-               core_link_write_dpcd(link, DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT, &grant, sizeof(grant));
-       }
-
-       do {
-               if (!get_temp_dp_link_res(link, &link_res, &cur_link_settings))
-                       continue;
-
-               skip_video_pattern = cur_link_settings.link_rate != LINK_RATE_LOW;
-               dp_enable_link_phy(
-                               link,
-                               &link_res,
-                               link->connector_signal,
-                               dp_cs_id,
-                               &cur_link_settings);
-
-               status = dp_perform_link_training(
-                               link,
-                               &link_res,
-                               &cur_link_settings,
-                               skip_video_pattern);
-
-               if (status == LINK_TRAINING_SUCCESS) {
-                       success = true;
-                       udelay(1000);
-                       if (read_hpd_rx_irq_data(link, &irq_data) == DC_OK &&
-                                       hpd_rx_irq_check_link_loss_status(
-                                                       link,
-                                                       &irq_data))
-                               (*fail_count)++;
-
-               } else {
-                       (*fail_count)++;
-               }
-               dp_trace_lt_total_count_increment(link, true);
-               dp_trace_lt_result_update(link, status, true);
-               dp_disable_link_phy(link, &link_res, link->connector_signal);
-       } while (!success && decide_fallback_link_setting(link,
-                       &max_link_settings, &cur_link_settings, status));
-
-       link->verified_link_cap = success ?
-                       cur_link_settings : fail_safe_link_settings;
-       return success;
-}
-
-bool dp_verify_link_cap_with_retries(
-       struct dc_link *link,
-       struct dc_link_settings *known_limit_link_setting,
-       int attempts)
-{
-       int i = 0;
-       bool success = false;
-       int fail_count = 0;
-
-       dp_trace_detect_lt_init(link);
-
-       if (link->link_enc && link->link_enc->features.flags.bits.DP_IS_USB_C &&
-                       link->dc->debug.usbc_combo_phy_reset_wa)
-               apply_usbc_combo_phy_reset_wa(link, known_limit_link_setting);
-
-       dp_trace_set_lt_start_timestamp(link, false);
-       for (i = 0; i < attempts; i++) {
-               enum dc_connection_type type = dc_connection_none;
-
-               memset(&link->verified_link_cap, 0,
-                               sizeof(struct dc_link_settings));
-               if (!dc_link_detect_sink(link, &type) || type == dc_connection_none) {
-                       link->verified_link_cap = fail_safe_link_settings;
-                       break;
-               } else if (dp_verify_link_cap(link, known_limit_link_setting,
-                               &fail_count) && fail_count == 0) {
-                       success = true;
-                       break;
-               }
-               msleep(10);
-       }
-
-       dp_trace_lt_fail_count_update(link, fail_count, true);
-       dp_trace_set_lt_end_timestamp(link, true);
-
-       return success;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_capability.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_capability.h
deleted file mode 100644 (file)
index 5500744..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-#ifndef __DC_LINK_DP_CAPABILITY_H__
-#define __DC_LINK_DP_CAPABILITY_H__
-
-#include "link.h"
-
-bool detect_dp_sink_caps(struct dc_link *link);
-
-void detect_edp_sink_caps(struct dc_link *link);
-
-struct dc_link_settings dp_get_max_link_cap(struct dc_link *link);
-
-
-enum dc_status dp_retrieve_lttpr_cap(struct dc_link *link);
-
-/* Convert PHY repeater count read from DPCD uint8_t. */
-uint8_t dp_parse_lttpr_repeater_count(uint8_t lttpr_repeater_count);
-
-bool dp_is_lttpr_present(struct dc_link *link);
-
-bool is_dp_active_dongle(const struct dc_link *link);
-
-bool is_dp_branch_device(const struct dc_link *link);
-
-bool decide_edp_link_settings_with_dsc(struct dc_link *link,
-               struct dc_link_settings *link_setting,
-               uint32_t req_bw,
-               enum dc_link_rate max_link_rate);
-
-void dpcd_set_source_specific_data(struct dc_link *link);
-
-/*query dpcd for version and mst cap addresses*/
-bool read_is_mst_supported(struct dc_link *link);
-
-bool decide_fallback_link_setting(
-               struct dc_link *link,
-               struct dc_link_settings *max,
-               struct dc_link_settings *cur,
-               enum link_training_result training_result);
-
-
-#endif /* __DC_LINK_DP_CAPABILITY_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia.c
deleted file mode 100644 (file)
index 6136db3..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-// SPDX-License-Identifier: MIT
-/*
- * Copyright 2021 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-#include "dc.h"
-#include "inc/core_status.h"
-#include "dc_link.h"
-#include "dc_link_dp.h"
-#include "dpcd_defs.h"
-
-#include "link_dp_dpia.h"
-#include "link_hwss.h"
-#include "dm_helpers.h"
-#include "dmub/inc/dmub_cmd.h"
-#include "link_dpcd.h"
-#include "link_dp_training.h"
-#include "dc_dmub_srv.h"
-
-#define DC_LOGGER \
-       link->ctx->logger
-
-/** @note Can remove once DP tunneling registers in upstream include/drm/drm_dp_helper.h */
-/* DPCD DP Tunneling over USB4 */
-#define DP_TUNNELING_CAPABILITIES_SUPPORT 0xe000d
-#define DP_IN_ADAPTER_INFO                0xe000e
-#define DP_USB4_DRIVER_ID                 0xe000f
-#define DP_USB4_ROUTER_TOPOLOGY_ID        0xe001b
-
-enum dc_status dpcd_get_tunneling_device_data(struct dc_link *link)
-{
-       enum dc_status status = DC_OK;
-       uint8_t dpcd_dp_tun_data[3] = {0};
-       uint8_t dpcd_topology_data[DPCD_USB4_TOPOLOGY_ID_LEN] = {0};
-       uint8_t i = 0;
-
-       status = core_link_read_dpcd(
-                       link,
-                       DP_TUNNELING_CAPABILITIES_SUPPORT,
-                       dpcd_dp_tun_data,
-                       sizeof(dpcd_dp_tun_data));
-
-       status = core_link_read_dpcd(
-                       link,
-                       DP_USB4_ROUTER_TOPOLOGY_ID,
-                       dpcd_topology_data,
-                       sizeof(dpcd_topology_data));
-
-       link->dpcd_caps.usb4_dp_tun_info.dp_tun_cap.raw =
-                       dpcd_dp_tun_data[DP_TUNNELING_CAPABILITIES_SUPPORT - DP_TUNNELING_CAPABILITIES_SUPPORT];
-       link->dpcd_caps.usb4_dp_tun_info.dpia_info.raw =
-                       dpcd_dp_tun_data[DP_IN_ADAPTER_INFO - DP_TUNNELING_CAPABILITIES_SUPPORT];
-       link->dpcd_caps.usb4_dp_tun_info.usb4_driver_id =
-                       dpcd_dp_tun_data[DP_USB4_DRIVER_ID - DP_TUNNELING_CAPABILITIES_SUPPORT];
-
-       for (i = 0; i < DPCD_USB4_TOPOLOGY_ID_LEN; i++)
-               link->dpcd_caps.usb4_dp_tun_info.usb4_topology_id[i] = dpcd_topology_data[i];
-
-       return status;
-}
-
-bool dc_link_dpia_query_hpd_status(struct dc_link *link)
-{
-       union dmub_rb_cmd cmd = {0};
-       struct dc_dmub_srv *dmub_srv = link->ctx->dmub_srv;
-       bool is_hpd_high = false;
-
-       /* prepare QUERY_HPD command */
-       cmd.query_hpd.header.type = DMUB_CMD__QUERY_HPD_STATE;
-       cmd.query_hpd.data.instance = link->link_id.enum_id - ENUM_ID_1;
-       cmd.query_hpd.data.ch_type = AUX_CHANNEL_DPIA;
-
-       /* Return HPD status reported by DMUB if query successfully executed. */
-       if (dc_dmub_srv_cmd_with_reply_data(dmub_srv, &cmd) && cmd.query_hpd.data.status == AUX_RET_SUCCESS)
-               is_hpd_high = cmd.query_hpd.data.result;
-
-       DC_LOG_DEBUG("%s: link(%d) dpia(%d) cmd_status(%d) result(%d)\n",
-               __func__,
-               link->link_index,
-               link->link_id.enum_id - ENUM_ID_1,
-               cmd.query_hpd.data.status,
-               cmd.query_hpd.data.result);
-
-       return is_hpd_high;
-}
-
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia.h
deleted file mode 100644 (file)
index 98935cc..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-/*
- * Copyright 2021 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-#ifndef __DC_LINK_DPIA_H__
-#define __DC_LINK_DPIA_H__
-
-#include "link.h"
-
-/* Read tunneling device capability from DPCD and update link capability
- * accordingly.
- */
-enum dc_status dpcd_get_tunneling_device_data(struct dc_link *link);
-
-/* Query hot plug status of USB4 DP tunnel.
- * Returns true if HPD high.
- */
-bool dc_link_dpia_query_hpd_status(struct dc_link *link);
-
-
-#endif /* __DC_LINK_DPIA_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia_bw.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia_bw.c
deleted file mode 100644 (file)
index 801a95b..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-/*********************************************************************/
-//                             USB4 DPIA BANDWIDTH ALLOCATION LOGIC
-/*********************************************************************/
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia_bw.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_dpia_bw.h
deleted file mode 100644 (file)
index 58eb7b5..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright 2021 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-#ifndef DC_INC_LINK_DP_DPIA_BW_H_
-#define DC_INC_LINK_DP_DPIA_BW_H_
-
-/*
- * Host Router BW type
- */
-enum bw_type {
-       HOST_ROUTER_BW_ESTIMATED,
-       HOST_ROUTER_BW_ALLOCATED,
-       HOST_ROUTER_BW_INVALID,
-};
-
-/*
- * Enable BW Allocation Mode Support from the DP-Tx side
- *
- * @link: pointer to the dc_link struct instance
- *
- * return: SUCCESS or FAILURE
- */
-bool set_dptx_usb4_bw_alloc_support(struct dc_link *link);
-
-/*
- * Send a request from DP-Tx requesting to allocate BW remotely after
- * allocating it locally. This will get processed by CM and a CB function
- * will be called.
- *
- * @link: pointer to the dc_link struct instance
- * @req_bw: The requested bw in Kbyte to allocated
- *
- * return: none
- */
-void set_usb4_req_bw_req(struct dc_link *link, int req_bw);
-
-/*
- * CB function for when the status of the Req above is complete. We will
- * find out the result of allocating on CM and update structs accordingly
- *
- * @link: pointer to the dc_link struct instance
- * @bw: Allocated or Estimated BW depending on the result
- * @result: Response type
- *
- * return: none
- */
-void get_usb4_req_bw_resp(struct dc_link *link, uint8_t bw, uint8_t result);
-
-/*
- * Return the response_ready flag from dc_link struct
- *
- * @link: pointer to the dc_link struct instance
- *
- * return: response_ready flag from dc_link struct
- */
-bool get_cm_response_ready_flag(struct dc_link *link);
-
-/*
- * Get the Max Available BW or Max Estimated BW for each Host Router
- *
- * @link: pointer to the dc_link struct instance
- * @type: ESTIMATD BW or MAX AVAILABLE BW
- *
- * return: response_ready flag from dc_link struct
- */
-int get_host_router_total_bw(struct dc_link *link, uint8_t type);
-
-/*
- * Cleanup function for when the dpia is unplugged to reset struct
- * and perform any required clean up
- *
- * @link: pointer to the dc_link struct instance
- *
- * return: none
- */
-bool dpia_bw_alloc_unplug(struct dc_link *link);
-
-#endif /* DC_INC_LINK_DP_DPIA_BW_H_ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_phy.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_phy.c
deleted file mode 100644 (file)
index afe3b21..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- * This file implements basic dp phy functionality such as enable/disable phy
- * output and set lane/drive settings. This file is responsible for maintaining
- * and update software state representing current phy status such as current
- * link settings.
- */
-
-#include "link_dp_phy.h"
-#include "link_dpcd.h"
-#include "link_dp_training.h"
-#include "link_dp_capability.h"
-#include "clk_mgr.h"
-#include "resource.h"
-#include "dc_link_dp.h"
-
-#define DC_LOGGER \
-       link->ctx->logger
-
-void dc_link_dp_set_drive_settings(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings)
-{
-       /* program ASIC PHY settings*/
-       dp_set_hw_lane_settings(link, link_res, lt_settings, DPRX);
-
-       dp_hw_to_dpcd_lane_settings(lt_settings,
-                       lt_settings->hw_lane_settings,
-                       lt_settings->dpcd_lane_settings);
-
-       /* Notify DP sink the PHY settings from source */
-       dpcd_set_lane_settings(link, lt_settings, DPRX);
-}
-
-void dc_link_dp_receiver_power_ctrl(struct dc_link *link, bool on)
-{
-       uint8_t state;
-
-       state = on ? DP_POWER_STATE_D0 : DP_POWER_STATE_D3;
-
-       if (link->sync_lt_in_progress)
-               return;
-
-       core_link_write_dpcd(link, DP_SET_POWER, &state,
-                                                sizeof(state));
-
-}
-
-void dp_enable_link_phy(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       enum signal_type signal,
-       enum clock_source_id clock_source,
-       const struct dc_link_settings *link_settings)
-{
-       link->cur_link_settings = *link_settings;
-       link->dc->hwss.enable_dp_link_output(link, link_res, signal,
-                       clock_source, link_settings);
-       dc_link_dp_receiver_power_ctrl(link, true);
-}
-
-void dp_disable_link_phy(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal)
-{
-       struct dc  *dc = link->ctx->dc;
-
-       if (!link->wa_flags.dp_keep_receiver_powered)
-               dc_link_dp_receiver_power_ctrl(link, false);
-
-       dc->hwss.disable_link_output(link, link_res, signal);
-       /* Clear current link setting.*/
-       memset(&link->cur_link_settings, 0,
-                       sizeof(link->cur_link_settings));
-
-       if (dc->clk_mgr->funcs->notify_link_rate_change)
-               dc->clk_mgr->funcs->notify_link_rate_change(dc->clk_mgr, link);
-}
-
-void dp_disable_link_phy_mst(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal)
-{
-       /* MST disable link only when no stream use the link */
-       if (link->mst_stream_alloc_table.stream_count > 0)
-               return;
-
-       dp_disable_link_phy(link, link_res, signal);
-
-       /* set the sink to SST mode after disabling the link */
-       dp_enable_mst_on_sink(link, false);
-}
-
-static inline bool is_immediate_downstream(struct dc_link *link, uint32_t offset)
-{
-       return (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) ==
-                       offset);
-}
-
-void dp_set_hw_lane_settings(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       const struct link_training_settings *link_settings,
-       uint32_t offset)
-{
-       const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
-
-       if ((link_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) &&
-                       !is_immediate_downstream(link, offset))
-               return;
-
-       if (link_hwss->ext.set_dp_lane_settings)
-               link_hwss->ext.set_dp_lane_settings(link, link_res,
-                               &link_settings->link_settings,
-                               link_settings->hw_lane_settings);
-
-       memmove(link->cur_lane_setting,
-                       link_settings->hw_lane_settings,
-                       sizeof(link->cur_lane_setting));
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_phy.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_phy.h
deleted file mode 100644 (file)
index 717e078..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-#ifndef __DC_LINK_DP_PHY_H__
-#define __DC_LINK_DP_PHY_H__
-
-#include "link.h"
-void dp_enable_link_phy(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       enum signal_type signal,
-       enum clock_source_id clock_source,
-       const struct dc_link_settings *link_settings);
-
-void dp_disable_link_phy(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal);
-
-void dp_disable_link_phy_mst(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal);
-
-void dp_set_hw_lane_settings(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct link_training_settings *link_settings,
-               uint32_t offset);
-
-#endif /* __DC_LINK_DP_PHY_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_trace.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_trace.c
deleted file mode 100644 (file)
index 2c1a3bf..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#include "dc_link.h"
-#include "link_dp_trace.h"
-
-void dp_trace_init(struct dc_link *link)
-{
-       memset(&link->dp_trace, 0, sizeof(link->dp_trace));
-       link->dp_trace.is_initialized = true;
-}
-
-void dp_trace_reset(struct dc_link *link)
-{
-       memset(&link->dp_trace, 0, sizeof(link->dp_trace));
-}
-
-bool dc_dp_trace_is_initialized(struct dc_link *link)
-{
-       return link->dp_trace.is_initialized;
-}
-
-void dp_trace_detect_lt_init(struct dc_link *link)
-{
-       memset(&link->dp_trace.detect_lt_trace, 0, sizeof(link->dp_trace.detect_lt_trace));
-}
-
-void dp_trace_commit_lt_init(struct dc_link *link)
-{
-       memset(&link->dp_trace.commit_lt_trace, 0, sizeof(link->dp_trace.commit_lt_trace));
-}
-
-void dp_trace_link_loss_increment(struct dc_link *link)
-{
-       link->dp_trace.link_loss_count++;
-}
-
-void dp_trace_lt_fail_count_update(struct dc_link *link,
-               unsigned int fail_count,
-               bool in_detection)
-{
-       if (in_detection)
-               link->dp_trace.detect_lt_trace.counts.fail = fail_count;
-       else
-               link->dp_trace.commit_lt_trace.counts.fail = fail_count;
-}
-
-void dp_trace_lt_total_count_increment(struct dc_link *link,
-               bool in_detection)
-{
-       if (in_detection)
-               link->dp_trace.detect_lt_trace.counts.total++;
-       else
-               link->dp_trace.commit_lt_trace.counts.total++;
-}
-
-void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
-               bool in_detection,
-               bool is_logged)
-{
-       if (in_detection)
-               link->dp_trace.detect_lt_trace.is_logged = is_logged;
-       else
-               link->dp_trace.commit_lt_trace.is_logged = is_logged;
-}
-
-bool dc_dp_trace_is_logged(struct dc_link *link,
-               bool in_detection)
-{
-       if (in_detection)
-               return link->dp_trace.detect_lt_trace.is_logged;
-       else
-               return link->dp_trace.commit_lt_trace.is_logged;
-}
-
-void dp_trace_lt_result_update(struct dc_link *link,
-               enum link_training_result result,
-               bool in_detection)
-{
-       if (in_detection)
-               link->dp_trace.detect_lt_trace.result = result;
-       else
-               link->dp_trace.commit_lt_trace.result = result;
-}
-
-void dp_trace_set_lt_start_timestamp(struct dc_link *link,
-               bool in_detection)
-{
-       if (in_detection)
-               link->dp_trace.detect_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx);
-       else
-               link->dp_trace.commit_lt_trace.timestamps.start = dm_get_timestamp(link->dc->ctx);
-}
-
-void dp_trace_set_lt_end_timestamp(struct dc_link *link,
-               bool in_detection)
-{
-       if (in_detection)
-               link->dp_trace.detect_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx);
-       else
-               link->dp_trace.commit_lt_trace.timestamps.end = dm_get_timestamp(link->dc->ctx);
-}
-
-unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
-               bool in_detection)
-{
-       if (in_detection)
-               return link->dp_trace.detect_lt_trace.timestamps.end;
-       else
-               return link->dp_trace.commit_lt_trace.timestamps.end;
-}
-
-struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
-               bool in_detection)
-{
-       if (in_detection)
-               return &link->dp_trace.detect_lt_trace.counts;
-       else
-               return &link->dp_trace.commit_lt_trace.counts;
-}
-
-unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link)
-{
-       return link->dp_trace.link_loss_count;
-}
-
-void dp_trace_set_edp_power_timestamp(struct dc_link *link,
-               bool power_up)
-{
-       if (!power_up)
-               /*save driver power off time stamp*/
-               link->dp_trace.edp_trace_power_timestamps.poweroff = dm_get_timestamp(link->dc->ctx);
-       else
-               link->dp_trace.edp_trace_power_timestamps.poweron = dm_get_timestamp(link->dc->ctx);
-}
-
-uint64_t dp_trace_get_edp_poweron_timestamp(struct dc_link *link)
-{
-       return link->dp_trace.edp_trace_power_timestamps.poweron;
-}
-
-uint64_t dp_trace_get_edp_poweroff_timestamp(struct dc_link *link)
-{
-       return link->dp_trace.edp_trace_power_timestamps.poweroff;
-}
\ No newline at end of file
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_trace.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_trace.h
deleted file mode 100644 (file)
index 26700e3..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#ifndef __LINK_DP_TRACE_H__
-#define __LINK_DP_TRACE_H__
-
-void dp_trace_init(struct dc_link *link);
-void dp_trace_reset(struct dc_link *link);
-bool dc_dp_trace_is_initialized(struct dc_link *link);
-void dp_trace_detect_lt_init(struct dc_link *link);
-void dp_trace_commit_lt_init(struct dc_link *link);
-void dp_trace_link_loss_increment(struct dc_link *link);
-void dp_trace_lt_fail_count_update(struct dc_link *link,
-               unsigned int fail_count,
-               bool in_detection);
-void dp_trace_lt_total_count_increment(struct dc_link *link,
-               bool in_detection);
-void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
-               bool in_detection,
-               bool is_logged);
-bool dc_dp_trace_is_logged(struct dc_link *link,
-               bool in_detection);
-void dp_trace_lt_result_update(struct dc_link *link,
-               enum link_training_result result,
-               bool in_detection);
-void dp_trace_set_lt_start_timestamp(struct dc_link *link,
-               bool in_detection);
-void dp_trace_set_lt_end_timestamp(struct dc_link *link,
-               bool in_detection);
-unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
-               bool in_detection);
-struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
-               bool in_detection);
-unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link);
-
-void dp_trace_set_edp_power_timestamp(struct dc_link *link,
-               bool power_up);
-uint64_t dp_trace_get_edp_poweron_timestamp(struct dc_link *link);
-uint64_t dp_trace_get_edp_poweroff_timestamp(struct dc_link *link);
-
-#endif /* __LINK_DP_TRACE_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_training.c
deleted file mode 100644 (file)
index e49e025..0000000
+++ /dev/null
@@ -1,1700 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- * This file implements all generic dp link training helper functions and top
- * level generic training sequence. All variations of dp link training sequence
- * should be called inside the top level training functions in this file to
- * ensure the integrity of our overall training procedure across different types
- * of link encoding and back end hardware.
- */
-#include "link_dp_training.h"
-#include "link_dp_training_8b_10b.h"
-#include "link_dp_training_128b_132b.h"
-#include "link_dp_training_auxless.h"
-#include "link_dp_training_dpia.h"
-#include "link_dp_training_fixed_vs_pe_retimer.h"
-#include "link_dpcd.h"
-#include "link_dp_trace.h"
-#include "link_dp_phy.h"
-#include "link_dp_capability.h"
-#include "dc_link_dp.h"
-#include "atomfirmware.h"
-#include "link_enc_cfg.h"
-#include "resource.h"
-#include "dm_helpers.h"
-
-#define DC_LOGGER \
-       link->ctx->logger
-
-#define POST_LT_ADJ_REQ_LIMIT 6
-#define POST_LT_ADJ_REQ_TIMEOUT 200
-
-void dp_log_training_result(
-       struct dc_link *link,
-       const struct link_training_settings *lt_settings,
-       enum link_training_result status)
-{
-       char *link_rate = "Unknown";
-       char *lt_result = "Unknown";
-       char *lt_spread = "Disabled";
-
-       switch (lt_settings->link_settings.link_rate) {
-       case LINK_RATE_LOW:
-               link_rate = "RBR";
-               break;
-       case LINK_RATE_RATE_2:
-               link_rate = "R2";
-               break;
-       case LINK_RATE_RATE_3:
-               link_rate = "R3";
-               break;
-       case LINK_RATE_HIGH:
-               link_rate = "HBR";
-               break;
-       case LINK_RATE_RBR2:
-               link_rate = "RBR2";
-               break;
-       case LINK_RATE_RATE_6:
-               link_rate = "R6";
-               break;
-       case LINK_RATE_HIGH2:
-               link_rate = "HBR2";
-               break;
-       case LINK_RATE_HIGH3:
-               link_rate = "HBR3";
-               break;
-       case LINK_RATE_UHBR10:
-               link_rate = "UHBR10";
-               break;
-       case LINK_RATE_UHBR13_5:
-               link_rate = "UHBR13.5";
-               break;
-       case LINK_RATE_UHBR20:
-               link_rate = "UHBR20";
-               break;
-       default:
-               break;
-       }
-
-       switch (status) {
-       case LINK_TRAINING_SUCCESS:
-               lt_result = "pass";
-               break;
-       case LINK_TRAINING_CR_FAIL_LANE0:
-               lt_result = "CR failed lane0";
-               break;
-       case LINK_TRAINING_CR_FAIL_LANE1:
-               lt_result = "CR failed lane1";
-               break;
-       case LINK_TRAINING_CR_FAIL_LANE23:
-               lt_result = "CR failed lane23";
-               break;
-       case LINK_TRAINING_EQ_FAIL_CR:
-               lt_result = "CR failed in EQ";
-               break;
-       case LINK_TRAINING_EQ_FAIL_CR_PARTIAL:
-               lt_result = "CR failed in EQ partially";
-               break;
-       case LINK_TRAINING_EQ_FAIL_EQ:
-               lt_result = "EQ failed";
-               break;
-       case LINK_TRAINING_LQA_FAIL:
-               lt_result = "LQA failed";
-               break;
-       case LINK_TRAINING_LINK_LOSS:
-               lt_result = "Link loss";
-               break;
-       case DP_128b_132b_LT_FAILED:
-               lt_result = "LT_FAILED received";
-               break;
-       case DP_128b_132b_MAX_LOOP_COUNT_REACHED:
-               lt_result = "max loop count reached";
-               break;
-       case DP_128b_132b_CHANNEL_EQ_DONE_TIMEOUT:
-               lt_result = "channel EQ timeout";
-               break;
-       case DP_128b_132b_CDS_DONE_TIMEOUT:
-               lt_result = "CDS timeout";
-               break;
-       default:
-               break;
-       }
-
-       switch (lt_settings->link_settings.link_spread) {
-       case LINK_SPREAD_DISABLED:
-               lt_spread = "Disabled";
-               break;
-       case LINK_SPREAD_05_DOWNSPREAD_30KHZ:
-               lt_spread = "0.5% 30KHz";
-               break;
-       case LINK_SPREAD_05_DOWNSPREAD_33KHZ:
-               lt_spread = "0.5% 33KHz";
-               break;
-       default:
-               break;
-       }
-
-       /* Connectivity log: link training */
-
-       /* TODO - DP2.0 Log: add connectivity log for FFE PRESET */
-
-       CONN_MSG_LT(link, "%sx%d %s VS=%d, PE=%d, DS=%s",
-                               link_rate,
-                               lt_settings->link_settings.lane_count,
-                               lt_result,
-                               lt_settings->hw_lane_settings[0].VOLTAGE_SWING,
-                               lt_settings->hw_lane_settings[0].PRE_EMPHASIS,
-                               lt_spread);
-}
-
-uint8_t dp_initialize_scrambling_data_symbols(
-       struct dc_link *link,
-       enum dc_dp_training_pattern pattern)
-{
-       uint8_t disable_scrabled_data_symbols = 0;
-
-       switch (pattern) {
-       case DP_TRAINING_PATTERN_SEQUENCE_1:
-       case DP_TRAINING_PATTERN_SEQUENCE_2:
-       case DP_TRAINING_PATTERN_SEQUENCE_3:
-               disable_scrabled_data_symbols = 1;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_4:
-       case DP_128b_132b_TPS1:
-       case DP_128b_132b_TPS2:
-               disable_scrabled_data_symbols = 0;
-               break;
-       default:
-               ASSERT(0);
-               DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
-                       __func__, pattern);
-               break;
-       }
-       return disable_scrabled_data_symbols;
-}
-
-enum dpcd_training_patterns
-       dp_training_pattern_to_dpcd_training_pattern(
-       struct dc_link *link,
-       enum dc_dp_training_pattern pattern)
-{
-       enum dpcd_training_patterns dpcd_tr_pattern =
-       DPCD_TRAINING_PATTERN_VIDEOIDLE;
-
-       switch (pattern) {
-       case DP_TRAINING_PATTERN_SEQUENCE_1:
-               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_1;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_2:
-               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_2;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_3:
-               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_3;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_4:
-               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_4;
-               break;
-       case DP_128b_132b_TPS1:
-               dpcd_tr_pattern = DPCD_128b_132b_TPS1;
-               break;
-       case DP_128b_132b_TPS2:
-               dpcd_tr_pattern = DPCD_128b_132b_TPS2;
-               break;
-       case DP_128b_132b_TPS2_CDS:
-               dpcd_tr_pattern = DPCD_128b_132b_TPS2_CDS;
-               break;
-       case DP_TRAINING_PATTERN_VIDEOIDLE:
-               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_VIDEOIDLE;
-               break;
-       default:
-               ASSERT(0);
-               DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
-                       __func__, pattern);
-               break;
-       }
-
-       return dpcd_tr_pattern;
-}
-
-static uint8_t get_nibble_at_index(const uint8_t *buf,
-       uint32_t index)
-{
-       uint8_t nibble;
-       nibble = buf[index / 2];
-
-       if (index % 2)
-               nibble >>= 4;
-       else
-               nibble &= 0x0F;
-
-       return nibble;
-}
-
-void dp_wait_for_training_aux_rd_interval(
-       struct dc_link *link,
-       uint32_t wait_in_micro_secs)
-{
-       if (wait_in_micro_secs > 1000)
-               msleep(wait_in_micro_secs/1000);
-       else
-               udelay(wait_in_micro_secs);
-
-       DC_LOG_HW_LINK_TRAINING("%s:\n wait = %d\n",
-               __func__,
-               wait_in_micro_secs);
-}
-
-/* maximum pre emphasis level allowed for each voltage swing level*/
-static const enum dc_pre_emphasis voltage_swing_to_pre_emphasis[] = {
-               PRE_EMPHASIS_LEVEL3,
-               PRE_EMPHASIS_LEVEL2,
-               PRE_EMPHASIS_LEVEL1,
-               PRE_EMPHASIS_DISABLED };
-
-static enum dc_pre_emphasis get_max_pre_emphasis_for_voltage_swing(
-       enum dc_voltage_swing voltage)
-{
-       enum dc_pre_emphasis pre_emphasis;
-       pre_emphasis = PRE_EMPHASIS_MAX_LEVEL;
-
-       if (voltage <= VOLTAGE_SWING_MAX_LEVEL)
-               pre_emphasis = voltage_swing_to_pre_emphasis[voltage];
-
-       return pre_emphasis;
-
-}
-
-static void maximize_lane_settings(const struct link_training_settings *lt_settings,
-               struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
-{
-       uint32_t lane;
-       struct dc_lane_settings max_requested;
-
-       max_requested.VOLTAGE_SWING = lane_settings[0].VOLTAGE_SWING;
-       max_requested.PRE_EMPHASIS = lane_settings[0].PRE_EMPHASIS;
-       max_requested.FFE_PRESET = lane_settings[0].FFE_PRESET;
-
-       /* Determine what the maximum of the requested settings are*/
-       for (lane = 1; lane < lt_settings->link_settings.lane_count; lane++) {
-               if (lane_settings[lane].VOLTAGE_SWING > max_requested.VOLTAGE_SWING)
-                       max_requested.VOLTAGE_SWING = lane_settings[lane].VOLTAGE_SWING;
-
-               if (lane_settings[lane].PRE_EMPHASIS > max_requested.PRE_EMPHASIS)
-                       max_requested.PRE_EMPHASIS = lane_settings[lane].PRE_EMPHASIS;
-               if (lane_settings[lane].FFE_PRESET.settings.level >
-                               max_requested.FFE_PRESET.settings.level)
-                       max_requested.FFE_PRESET.settings.level =
-                                       lane_settings[lane].FFE_PRESET.settings.level;
-       }
-
-       /* make sure the requested settings are
-        * not higher than maximum settings*/
-       if (max_requested.VOLTAGE_SWING > VOLTAGE_SWING_MAX_LEVEL)
-               max_requested.VOLTAGE_SWING = VOLTAGE_SWING_MAX_LEVEL;
-
-       if (max_requested.PRE_EMPHASIS > PRE_EMPHASIS_MAX_LEVEL)
-               max_requested.PRE_EMPHASIS = PRE_EMPHASIS_MAX_LEVEL;
-       if (max_requested.FFE_PRESET.settings.level > DP_FFE_PRESET_MAX_LEVEL)
-               max_requested.FFE_PRESET.settings.level = DP_FFE_PRESET_MAX_LEVEL;
-
-       /* make sure the pre-emphasis matches the voltage swing*/
-       if (max_requested.PRE_EMPHASIS >
-               get_max_pre_emphasis_for_voltage_swing(
-                       max_requested.VOLTAGE_SWING))
-               max_requested.PRE_EMPHASIS =
-               get_max_pre_emphasis_for_voltage_swing(
-                       max_requested.VOLTAGE_SWING);
-
-       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-               lane_settings[lane].VOLTAGE_SWING = max_requested.VOLTAGE_SWING;
-               lane_settings[lane].PRE_EMPHASIS = max_requested.PRE_EMPHASIS;
-               lane_settings[lane].FFE_PRESET = max_requested.FFE_PRESET;
-       }
-}
-
-void dp_hw_to_dpcd_lane_settings(
-               const struct link_training_settings *lt_settings,
-               const struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
-               union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX])
-{
-       uint8_t lane = 0;
-
-       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_8b_10b_ENCODING) {
-                       dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET =
-                                       (uint8_t)(hw_lane_settings[lane].VOLTAGE_SWING);
-                       dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET =
-                                       (uint8_t)(hw_lane_settings[lane].PRE_EMPHASIS);
-                       dpcd_lane_settings[lane].bits.MAX_SWING_REACHED =
-                                       (hw_lane_settings[lane].VOLTAGE_SWING ==
-                                                       VOLTAGE_SWING_MAX_LEVEL ? 1 : 0);
-                       dpcd_lane_settings[lane].bits.MAX_PRE_EMPHASIS_REACHED =
-                                       (hw_lane_settings[lane].PRE_EMPHASIS ==
-                                                       PRE_EMPHASIS_MAX_LEVEL ? 1 : 0);
-               } else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_128b_132b_ENCODING) {
-                       dpcd_lane_settings[lane].tx_ffe.PRESET_VALUE =
-                                       hw_lane_settings[lane].FFE_PRESET.settings.level;
-               }
-       }
-}
-
-uint8_t get_dpcd_link_rate(const struct dc_link_settings *link_settings)
-{
-       uint8_t link_rate = 0;
-       enum dp_link_encoding encoding = link_dp_get_encoding_format(link_settings);
-
-       if (encoding == DP_128b_132b_ENCODING)
-               switch (link_settings->link_rate) {
-               case LINK_RATE_UHBR10:
-                       link_rate = 0x1;
-                       break;
-               case LINK_RATE_UHBR20:
-                       link_rate = 0x2;
-                       break;
-               case LINK_RATE_UHBR13_5:
-                       link_rate = 0x4;
-                       break;
-               default:
-                       link_rate = 0;
-                       break;
-               }
-       else if (encoding == DP_8b_10b_ENCODING)
-               link_rate = (uint8_t) link_settings->link_rate;
-       else
-               link_rate = 0;
-
-       return link_rate;
-}
-
-/* Only used for channel equalization */
-uint32_t dp_translate_training_aux_read_interval(uint32_t dpcd_aux_read_interval)
-{
-       unsigned int aux_rd_interval_us = 400;
-
-       switch (dpcd_aux_read_interval) {
-       case 0x01:
-               aux_rd_interval_us = 4000;
-               break;
-       case 0x02:
-               aux_rd_interval_us = 8000;
-               break;
-       case 0x03:
-               aux_rd_interval_us = 12000;
-               break;
-       case 0x04:
-               aux_rd_interval_us = 16000;
-               break;
-       case 0x05:
-               aux_rd_interval_us = 32000;
-               break;
-       case 0x06:
-               aux_rd_interval_us = 64000;
-               break;
-       default:
-               break;
-       }
-
-       return aux_rd_interval_us;
-}
-
-enum link_training_result dp_get_cr_failure(enum dc_lane_count ln_count,
-                                       union lane_status *dpcd_lane_status)
-{
-       enum link_training_result result = LINK_TRAINING_SUCCESS;
-
-       if (ln_count >= LANE_COUNT_ONE && !dpcd_lane_status[0].bits.CR_DONE_0)
-               result = LINK_TRAINING_CR_FAIL_LANE0;
-       else if (ln_count >= LANE_COUNT_TWO && !dpcd_lane_status[1].bits.CR_DONE_0)
-               result = LINK_TRAINING_CR_FAIL_LANE1;
-       else if (ln_count >= LANE_COUNT_FOUR && !dpcd_lane_status[2].bits.CR_DONE_0)
-               result = LINK_TRAINING_CR_FAIL_LANE23;
-       else if (ln_count >= LANE_COUNT_FOUR && !dpcd_lane_status[3].bits.CR_DONE_0)
-               result = LINK_TRAINING_CR_FAIL_LANE23;
-       return result;
-}
-
-bool is_repeater(const struct link_training_settings *lt_settings, uint32_t offset)
-{
-       return (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) && (offset != 0);
-}
-
-bool dp_is_max_vs_reached(
-       const struct link_training_settings *lt_settings)
-{
-       uint32_t lane;
-       for (lane = 0; lane <
-               (uint32_t)(lt_settings->link_settings.lane_count);
-               lane++) {
-               if (lt_settings->dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET
-                       == VOLTAGE_SWING_MAX_LEVEL)
-                       return true;
-       }
-       return false;
-
-}
-
-bool dp_is_cr_done(enum dc_lane_count ln_count,
-       union lane_status *dpcd_lane_status)
-{
-       bool done = true;
-       uint32_t lane;
-       /*LANEx_CR_DONE bits All 1's?*/
-       for (lane = 0; lane < (uint32_t)(ln_count); lane++) {
-               if (!dpcd_lane_status[lane].bits.CR_DONE_0)
-                       done = false;
-       }
-       return done;
-
-}
-
-bool dp_is_ch_eq_done(enum dc_lane_count ln_count,
-               union lane_status *dpcd_lane_status)
-{
-       bool done = true;
-       uint32_t lane;
-       for (lane = 0; lane < (uint32_t)(ln_count); lane++)
-               if (!dpcd_lane_status[lane].bits.CHANNEL_EQ_DONE_0)
-                       done = false;
-       return done;
-}
-
-bool dp_is_symbol_locked(enum dc_lane_count ln_count,
-               union lane_status *dpcd_lane_status)
-{
-       bool locked = true;
-       uint32_t lane;
-       for (lane = 0; lane < (uint32_t)(ln_count); lane++)
-               if (!dpcd_lane_status[lane].bits.SYMBOL_LOCKED_0)
-                       locked = false;
-       return locked;
-}
-
-bool dp_is_interlane_aligned(union lane_align_status_updated align_status)
-{
-       return align_status.bits.INTERLANE_ALIGN_DONE == 1;
-}
-
-enum link_training_result dp_check_link_loss_status(
-       struct dc_link *link,
-       const struct link_training_settings *link_training_setting)
-{
-       enum link_training_result status = LINK_TRAINING_SUCCESS;
-       union lane_status lane_status;
-       uint8_t dpcd_buf[6] = {0};
-       uint32_t lane;
-
-       core_link_read_dpcd(
-                       link,
-                       DP_SINK_COUNT,
-                       (uint8_t *)(dpcd_buf),
-                       sizeof(dpcd_buf));
-
-       /*parse lane status*/
-       for (lane = 0; lane < link->cur_link_settings.lane_count; lane++) {
-               /*
-                * check lanes status
-                */
-               lane_status.raw = get_nibble_at_index(&dpcd_buf[2], lane);
-
-               if (!lane_status.bits.CHANNEL_EQ_DONE_0 ||
-                       !lane_status.bits.CR_DONE_0 ||
-                       !lane_status.bits.SYMBOL_LOCKED_0) {
-                       /* if one of the channel equalization, clock
-                        * recovery or symbol lock is dropped
-                        * consider it as (link has been
-                        * dropped) dp sink status has changed
-                        */
-                       status = LINK_TRAINING_LINK_LOSS;
-                       break;
-               }
-       }
-
-       return status;
-}
-
-enum dc_status dp_get_lane_status_and_lane_adjust(
-       struct dc_link *link,
-       const struct link_training_settings *link_training_setting,
-       union lane_status ln_status[LANE_COUNT_DP_MAX],
-       union lane_align_status_updated *ln_align,
-       union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
-       uint32_t offset)
-{
-       unsigned int lane01_status_address = DP_LANE0_1_STATUS;
-       uint8_t lane_adjust_offset = 4;
-       unsigned int lane01_adjust_address;
-       uint8_t dpcd_buf[6] = {0};
-       uint32_t lane;
-       enum dc_status status;
-
-       if (is_repeater(link_training_setting, offset)) {
-               lane01_status_address =
-                               DP_LANE0_1_STATUS_PHY_REPEATER1 +
-                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-               lane_adjust_offset = 3;
-       }
-
-       status = core_link_read_dpcd(
-               link,
-               lane01_status_address,
-               (uint8_t *)(dpcd_buf),
-               sizeof(dpcd_buf));
-
-       if (status != DC_OK) {
-               DC_LOG_HW_LINK_TRAINING("%s:\n Failed to read from address 0x%X,"
-                       " keep current lane status and lane adjust unchanged",
-                       __func__,
-                       lane01_status_address);
-               return status;
-       }
-
-       for (lane = 0; lane <
-               (uint32_t)(link_training_setting->link_settings.lane_count);
-               lane++) {
-
-               ln_status[lane].raw =
-                       get_nibble_at_index(&dpcd_buf[0], lane);
-               ln_adjust[lane].raw =
-                       get_nibble_at_index(&dpcd_buf[lane_adjust_offset], lane);
-       }
-
-       ln_align->raw = dpcd_buf[2];
-
-       if (is_repeater(link_training_setting, offset)) {
-               DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
-                               " 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
-                       __func__,
-                       offset,
-                       lane01_status_address, dpcd_buf[0],
-                       lane01_status_address + 1, dpcd_buf[1]);
-
-               lane01_adjust_address = DP_ADJUST_REQUEST_LANE0_1_PHY_REPEATER1 +
-                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-
-               DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
-                               " 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
-                                       __func__,
-                                       offset,
-                                       lane01_adjust_address,
-                                       dpcd_buf[lane_adjust_offset],
-                                       lane01_adjust_address + 1,
-                                       dpcd_buf[lane_adjust_offset + 1]);
-       } else {
-               DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
-                       __func__,
-                       lane01_status_address, dpcd_buf[0],
-                       lane01_status_address + 1, dpcd_buf[1]);
-
-               lane01_adjust_address = DP_ADJUST_REQUEST_LANE0_1;
-
-               DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
-                       __func__,
-                       lane01_adjust_address,
-                       dpcd_buf[lane_adjust_offset],
-                       lane01_adjust_address + 1,
-                       dpcd_buf[lane_adjust_offset + 1]);
-       }
-
-       return status;
-}
-
-static void override_lane_settings(const struct link_training_settings *lt_settings,
-               struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
-{
-       uint32_t lane;
-
-       if (lt_settings->voltage_swing == NULL &&
-                       lt_settings->pre_emphasis == NULL &&
-                       lt_settings->ffe_preset == NULL &&
-                       lt_settings->post_cursor2 == NULL)
-
-               return;
-
-       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-               if (lt_settings->voltage_swing)
-                       lane_settings[lane].VOLTAGE_SWING = *lt_settings->voltage_swing;
-               if (lt_settings->pre_emphasis)
-                       lane_settings[lane].PRE_EMPHASIS = *lt_settings->pre_emphasis;
-               if (lt_settings->post_cursor2)
-                       lane_settings[lane].POST_CURSOR2 = *lt_settings->post_cursor2;
-               if (lt_settings->ffe_preset)
-                       lane_settings[lane].FFE_PRESET = *lt_settings->ffe_preset;
-       }
-}
-
-void dp_get_lttpr_mode_override(struct dc_link *link, enum lttpr_mode *override)
-{
-       if (!dp_is_lttpr_present(link))
-               return;
-
-       if (link->dc->debug.lttpr_mode_override == LTTPR_MODE_TRANSPARENT) {
-               *override = LTTPR_MODE_TRANSPARENT;
-       } else if (link->dc->debug.lttpr_mode_override == LTTPR_MODE_NON_TRANSPARENT) {
-               *override = LTTPR_MODE_NON_TRANSPARENT;
-       } else if (link->dc->debug.lttpr_mode_override == LTTPR_MODE_NON_LTTPR) {
-               *override = LTTPR_MODE_NON_LTTPR;
-       }
-       DC_LOG_DC("lttpr_mode_override chose LTTPR_MODE = %d\n", (uint8_t)(*override));
-}
-
-void override_training_settings(
-               struct dc_link *link,
-               const struct dc_link_training_overrides *overrides,
-               struct link_training_settings *lt_settings)
-{
-       uint32_t lane;
-
-       /* Override link spread */
-       if (!link->dp_ss_off && overrides->downspread != NULL)
-               lt_settings->link_settings.link_spread = *overrides->downspread ?
-                               LINK_SPREAD_05_DOWNSPREAD_30KHZ
-                               : LINK_SPREAD_DISABLED;
-
-       /* Override lane settings */
-       if (overrides->voltage_swing != NULL)
-               lt_settings->voltage_swing = overrides->voltage_swing;
-       if (overrides->pre_emphasis != NULL)
-               lt_settings->pre_emphasis = overrides->pre_emphasis;
-       if (overrides->post_cursor2 != NULL)
-               lt_settings->post_cursor2 = overrides->post_cursor2;
-       if (overrides->ffe_preset != NULL)
-               lt_settings->ffe_preset = overrides->ffe_preset;
-       /* Override HW lane settings with BIOS forced values if present */
-       if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
-                       lt_settings->lttpr_mode == LTTPR_MODE_TRANSPARENT) {
-               lt_settings->voltage_swing = &link->bios_forced_drive_settings.VOLTAGE_SWING;
-               lt_settings->pre_emphasis = &link->bios_forced_drive_settings.PRE_EMPHASIS;
-               lt_settings->always_match_dpcd_with_hw_lane_settings = false;
-       }
-       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-               lt_settings->hw_lane_settings[lane].VOLTAGE_SWING =
-                       lt_settings->voltage_swing != NULL ?
-                       *lt_settings->voltage_swing :
-                       VOLTAGE_SWING_LEVEL0;
-               lt_settings->hw_lane_settings[lane].PRE_EMPHASIS =
-                       lt_settings->pre_emphasis != NULL ?
-                       *lt_settings->pre_emphasis
-                       : PRE_EMPHASIS_DISABLED;
-               lt_settings->hw_lane_settings[lane].POST_CURSOR2 =
-                       lt_settings->post_cursor2 != NULL ?
-                       *lt_settings->post_cursor2
-                       : POST_CURSOR2_DISABLED;
-       }
-
-       if (lt_settings->always_match_dpcd_with_hw_lane_settings)
-               dp_hw_to_dpcd_lane_settings(lt_settings,
-                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-
-       /* Override training timings */
-       if (overrides->cr_pattern_time != NULL)
-               lt_settings->cr_pattern_time = *overrides->cr_pattern_time;
-       if (overrides->eq_pattern_time != NULL)
-               lt_settings->eq_pattern_time = *overrides->eq_pattern_time;
-       if (overrides->pattern_for_cr != NULL)
-               lt_settings->pattern_for_cr = *overrides->pattern_for_cr;
-       if (overrides->pattern_for_eq != NULL)
-               lt_settings->pattern_for_eq = *overrides->pattern_for_eq;
-       if (overrides->enhanced_framing != NULL)
-               lt_settings->enhanced_framing = *overrides->enhanced_framing;
-       if (link->preferred_training_settings.fec_enable != NULL)
-               lt_settings->should_set_fec_ready = *link->preferred_training_settings.fec_enable;
-
-#if defined(CONFIG_DRM_AMD_DC_DCN)
-       /* Check DP tunnel LTTPR mode debug option. */
-       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA && link->dc->debug.dpia_debug.bits.force_non_lttpr)
-               lt_settings->lttpr_mode = LTTPR_MODE_NON_LTTPR;
-
-#endif
-       dp_get_lttpr_mode_override(link, &lt_settings->lttpr_mode);
-
-}
-
-enum dc_dp_training_pattern decide_cr_training_pattern(
-               const struct dc_link_settings *link_settings)
-{
-       switch (link_dp_get_encoding_format(link_settings)) {
-       case DP_8b_10b_ENCODING:
-       default:
-               return DP_TRAINING_PATTERN_SEQUENCE_1;
-       case DP_128b_132b_ENCODING:
-               return DP_128b_132b_TPS1;
-       }
-}
-
-enum dc_dp_training_pattern decide_eq_training_pattern(struct dc_link *link,
-               const struct dc_link_settings *link_settings)
-{
-       struct link_encoder *link_enc;
-       struct encoder_feature_support *enc_caps;
-       struct dpcd_caps *rx_caps = &link->dpcd_caps;
-       enum dc_dp_training_pattern pattern = DP_TRAINING_PATTERN_SEQUENCE_2;
-
-       link_enc = link_enc_cfg_get_link_enc(link);
-       ASSERT(link_enc);
-       enc_caps = &link_enc->features;
-
-       switch (link_dp_get_encoding_format(link_settings)) {
-       case DP_8b_10b_ENCODING:
-               if (enc_caps->flags.bits.IS_TPS4_CAPABLE &&
-                               rx_caps->max_down_spread.bits.TPS4_SUPPORTED)
-                       pattern = DP_TRAINING_PATTERN_SEQUENCE_4;
-               else if (enc_caps->flags.bits.IS_TPS3_CAPABLE &&
-                               rx_caps->max_ln_count.bits.TPS3_SUPPORTED)
-                       pattern = DP_TRAINING_PATTERN_SEQUENCE_3;
-               else
-                       pattern = DP_TRAINING_PATTERN_SEQUENCE_2;
-               break;
-       case DP_128b_132b_ENCODING:
-               pattern = DP_128b_132b_TPS2;
-               break;
-       default:
-               pattern = DP_TRAINING_PATTERN_SEQUENCE_2;
-               break;
-       }
-       return pattern;
-}
-
-enum lttpr_mode dc_link_decide_lttpr_mode(struct dc_link *link,
-               struct dc_link_settings *link_setting)
-{
-       enum dp_link_encoding encoding = link_dp_get_encoding_format(link_setting);
-
-       if (encoding == DP_8b_10b_ENCODING)
-               return dp_decide_8b_10b_lttpr_mode(link);
-       else if (encoding == DP_128b_132b_ENCODING)
-               return dp_decide_128b_132b_lttpr_mode(link);
-
-       ASSERT(0);
-       return LTTPR_MODE_NON_LTTPR;
-}
-
-void dp_decide_lane_settings(
-               const struct link_training_settings *lt_settings,
-               const union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
-               struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
-               union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX])
-{
-       uint32_t lane;
-
-       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_8b_10b_ENCODING) {
-                       hw_lane_settings[lane].VOLTAGE_SWING =
-                                       (enum dc_voltage_swing)(ln_adjust[lane].bits.
-                                                       VOLTAGE_SWING_LANE);
-                       hw_lane_settings[lane].PRE_EMPHASIS =
-                                       (enum dc_pre_emphasis)(ln_adjust[lane].bits.
-                                                       PRE_EMPHASIS_LANE);
-               } else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_128b_132b_ENCODING) {
-                       hw_lane_settings[lane].FFE_PRESET.raw =
-                                       ln_adjust[lane].tx_ffe.PRESET_VALUE;
-               }
-       }
-       dp_hw_to_dpcd_lane_settings(lt_settings, hw_lane_settings, dpcd_lane_settings);
-
-       if (lt_settings->disallow_per_lane_settings) {
-               /* we find the maximum of the requested settings across all lanes*/
-               /* and set this maximum for all lanes*/
-               maximize_lane_settings(lt_settings, hw_lane_settings);
-               override_lane_settings(lt_settings, hw_lane_settings);
-
-               if (lt_settings->always_match_dpcd_with_hw_lane_settings)
-                       dp_hw_to_dpcd_lane_settings(lt_settings, hw_lane_settings, dpcd_lane_settings);
-       }
-
-}
-
-void dp_decide_training_settings(
-               struct dc_link *link,
-               const struct dc_link_settings *link_settings,
-               struct link_training_settings *lt_settings)
-{
-       if (link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING)
-               decide_8b_10b_training_settings(link, link_settings, lt_settings);
-       else if (link_dp_get_encoding_format(link_settings) == DP_128b_132b_ENCODING)
-               decide_128b_132b_training_settings(link, link_settings, lt_settings);
-}
-
-
-enum dc_status configure_lttpr_mode_transparent(struct dc_link *link)
-{
-       uint8_t repeater_mode = DP_PHY_REPEATER_MODE_TRANSPARENT;
-
-       DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Transparent Mode\n", __func__);
-       return core_link_write_dpcd(link,
-                       DP_PHY_REPEATER_MODE,
-                       (uint8_t *)&repeater_mode,
-                       sizeof(repeater_mode));
-}
-
-static enum dc_status configure_lttpr_mode_non_transparent(
-               struct dc_link *link,
-               const struct link_training_settings *lt_settings)
-{
-       /* aux timeout is already set to extended */
-       /* RESET/SET lttpr mode to enable non transparent mode */
-       uint8_t repeater_cnt;
-       uint32_t aux_interval_address;
-       uint8_t repeater_id;
-       enum dc_status result = DC_ERROR_UNEXPECTED;
-       uint8_t repeater_mode = DP_PHY_REPEATER_MODE_TRANSPARENT;
-
-       enum dp_link_encoding encoding = link_dp_get_encoding_format(&lt_settings->link_settings);
-
-       if (encoding == DP_8b_10b_ENCODING) {
-               DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Transparent Mode\n", __func__);
-               result = core_link_write_dpcd(link,
-                               DP_PHY_REPEATER_MODE,
-                               (uint8_t *)&repeater_mode,
-                               sizeof(repeater_mode));
-
-       }
-
-       if (result == DC_OK) {
-               link->dpcd_caps.lttpr_caps.mode = repeater_mode;
-       }
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
-
-               DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Non Transparent Mode\n", __func__);
-
-               repeater_mode = DP_PHY_REPEATER_MODE_NON_TRANSPARENT;
-               result = core_link_write_dpcd(link,
-                               DP_PHY_REPEATER_MODE,
-                               (uint8_t *)&repeater_mode,
-                               sizeof(repeater_mode));
-
-               if (result == DC_OK) {
-                       link->dpcd_caps.lttpr_caps.mode = repeater_mode;
-               }
-
-               if (encoding == DP_8b_10b_ENCODING) {
-                       repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-
-                       /* Driver does not need to train the first hop. Skip DPCD read and clear
-                        * AUX_RD_INTERVAL for DPTX-to-DPIA hop.
-                        */
-                       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
-                               link->dpcd_caps.lttpr_caps.aux_rd_interval[--repeater_cnt] = 0;
-
-                       for (repeater_id = repeater_cnt; repeater_id > 0; repeater_id--) {
-                               aux_interval_address = DP_TRAINING_AUX_RD_INTERVAL_PHY_REPEATER1 +
-                                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (repeater_id - 1));
-                               core_link_read_dpcd(
-                                               link,
-                                               aux_interval_address,
-                                               (uint8_t *)&link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1],
-                                               sizeof(link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1]));
-                               link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1] &= 0x7F;
-                       }
-               }
-       }
-
-       return result;
-}
-
-enum dc_status dpcd_configure_lttpr_mode(struct dc_link *link, struct link_training_settings *lt_settings)
-{
-       enum dc_status status = DC_OK;
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_TRANSPARENT)
-               status = configure_lttpr_mode_transparent(link);
-
-       else if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
-               status = configure_lttpr_mode_non_transparent(link, lt_settings);
-
-       return status;
-}
-
-void repeater_training_done(struct dc_link *link, uint32_t offset)
-{
-       union dpcd_training_pattern dpcd_pattern = {0};
-
-       const uint32_t dpcd_base_lt_offset =
-                       DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
-                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-       /* Set training not in progress*/
-       dpcd_pattern.v1_4.TRAINING_PATTERN_SET = DPCD_TRAINING_PATTERN_VIDEOIDLE;
-
-       core_link_write_dpcd(
-               link,
-               dpcd_base_lt_offset,
-               &dpcd_pattern.raw,
-               1);
-
-       DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Id: %d 0x%X pattern = %x\n",
-               __func__,
-               offset,
-               dpcd_base_lt_offset,
-               dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
-}
-
-static void dpcd_exit_training_mode(struct dc_link *link, enum dp_link_encoding encoding)
-{
-       uint8_t sink_status = 0;
-       uint8_t i;
-
-       /* clear training pattern set */
-       dpcd_set_training_pattern(link, DP_TRAINING_PATTERN_VIDEOIDLE);
-
-       if (encoding == DP_128b_132b_ENCODING) {
-               /* poll for intra-hop disable */
-               for (i = 0; i < 10; i++) {
-                       if ((core_link_read_dpcd(link, DP_SINK_STATUS, &sink_status, 1) == DC_OK) &&
-                                       (sink_status & DP_INTRA_HOP_AUX_REPLY_INDICATION) == 0)
-                               break;
-                       udelay(1000);
-               }
-       }
-}
-
-enum dc_status dpcd_configure_channel_coding(struct dc_link *link,
-               struct link_training_settings *lt_settings)
-{
-       enum dp_link_encoding encoding =
-                       link_dp_get_encoding_format(
-                                       &lt_settings->link_settings);
-       enum dc_status status;
-
-       status = core_link_write_dpcd(
-                       link,
-                       DP_MAIN_LINK_CHANNEL_CODING_SET,
-                       (uint8_t *) &encoding,
-                       1);
-       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X MAIN_LINK_CHANNEL_CODING_SET = %x\n",
-                                       __func__,
-                                       DP_MAIN_LINK_CHANNEL_CODING_SET,
-                                       encoding);
-
-       return status;
-}
-
-void dpcd_set_training_pattern(
-       struct dc_link *link,
-       enum dc_dp_training_pattern training_pattern)
-{
-       union dpcd_training_pattern dpcd_pattern = {0};
-
-       dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
-                       dp_training_pattern_to_dpcd_training_pattern(
-                                       link, training_pattern);
-
-       core_link_write_dpcd(
-               link,
-               DP_TRAINING_PATTERN_SET,
-               &dpcd_pattern.raw,
-               1);
-
-       DC_LOG_HW_LINK_TRAINING("%s\n %x pattern = %x\n",
-               __func__,
-               DP_TRAINING_PATTERN_SET,
-               dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
-}
-
-enum dc_status dpcd_set_link_settings(
-       struct dc_link *link,
-       const struct link_training_settings *lt_settings)
-{
-       uint8_t rate;
-       enum dc_status status;
-
-       union down_spread_ctrl downspread = {0};
-       union lane_count_set lane_count_set = {0};
-
-       downspread.raw = (uint8_t)
-       (lt_settings->link_settings.link_spread);
-
-       lane_count_set.bits.LANE_COUNT_SET =
-       lt_settings->link_settings.lane_count;
-
-       lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
-       lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
-
-
-       if (link->ep_type == DISPLAY_ENDPOINT_PHY &&
-                       lt_settings->pattern_for_eq < DP_TRAINING_PATTERN_SEQUENCE_4) {
-               lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED =
-                               link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED;
-       }
-
-       status = core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
-               &downspread.raw, sizeof(downspread));
-
-       status = core_link_write_dpcd(link, DP_LANE_COUNT_SET,
-               &lane_count_set.raw, 1);
-
-       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_13 &&
-                       lt_settings->link_settings.use_link_rate_set == true) {
-               rate = 0;
-               /* WA for some MUX chips that will power down with eDP and lose supported
-                * link rate set for eDP 1.4. Source reads DPCD 0x010 again to ensure
-                * MUX chip gets link rate set back before link training.
-                */
-               if (link->connector_signal == SIGNAL_TYPE_EDP) {
-                       uint8_t supported_link_rates[16];
-
-                       core_link_read_dpcd(link, DP_SUPPORTED_LINK_RATES,
-                                       supported_link_rates, sizeof(supported_link_rates));
-               }
-               status = core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
-               status = core_link_write_dpcd(link, DP_LINK_RATE_SET,
-                               &lt_settings->link_settings.link_rate_set, 1);
-       } else {
-               rate = get_dpcd_link_rate(&lt_settings->link_settings);
-
-               status = core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
-       }
-
-       if (rate) {
-               DC_LOG_HW_LINK_TRAINING("%s\n %x rate = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
-                       __func__,
-                       DP_LINK_BW_SET,
-                       lt_settings->link_settings.link_rate,
-                       DP_LANE_COUNT_SET,
-                       lt_settings->link_settings.lane_count,
-                       lt_settings->enhanced_framing,
-                       DP_DOWNSPREAD_CTRL,
-                       lt_settings->link_settings.link_spread);
-       } else {
-               DC_LOG_HW_LINK_TRAINING("%s\n %x rate set = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
-                       __func__,
-                       DP_LINK_RATE_SET,
-                       lt_settings->link_settings.link_rate_set,
-                       DP_LANE_COUNT_SET,
-                       lt_settings->link_settings.lane_count,
-                       lt_settings->enhanced_framing,
-                       DP_DOWNSPREAD_CTRL,
-                       lt_settings->link_settings.link_spread);
-       }
-
-       return status;
-}
-
-enum dc_status dpcd_set_lane_settings(
-       struct dc_link *link,
-       const struct link_training_settings *link_training_setting,
-       uint32_t offset)
-{
-       unsigned int lane0_set_address;
-       enum dc_status status;
-       lane0_set_address = DP_TRAINING_LANE0_SET;
-
-       if (is_repeater(link_training_setting, offset))
-               lane0_set_address = DP_TRAINING_LANE0_SET_PHY_REPEATER1 +
-               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-
-       status = core_link_write_dpcd(link,
-               lane0_set_address,
-               (uint8_t *)(link_training_setting->dpcd_lane_settings),
-               link_training_setting->link_settings.lane_count);
-
-       if (is_repeater(link_training_setting, offset)) {
-               DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n"
-                               " 0x%X VS set = %x  PE set = %x max VS Reached = %x  max PE Reached = %x\n",
-                       __func__,
-                       offset,
-                       lane0_set_address,
-                       link_training_setting->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
-                       link_training_setting->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
-                       link_training_setting->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
-                       link_training_setting->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
-
-       } else {
-               DC_LOG_HW_LINK_TRAINING("%s\n 0x%X VS set = %x  PE set = %x max VS Reached = %x  max PE Reached = %x\n",
-                       __func__,
-                       lane0_set_address,
-                       link_training_setting->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
-                       link_training_setting->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
-                       link_training_setting->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
-                       link_training_setting->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
-       }
-
-       return status;
-}
-
-void dpcd_set_lt_pattern_and_lane_settings(
-       struct dc_link *link,
-       const struct link_training_settings *lt_settings,
-       enum dc_dp_training_pattern pattern,
-       uint32_t offset)
-{
-       uint32_t dpcd_base_lt_offset;
-       uint8_t dpcd_lt_buffer[5] = {0};
-       union dpcd_training_pattern dpcd_pattern = {0};
-       uint32_t size_in_bytes;
-       bool edp_workaround = false; /* TODO link_prop.INTERNAL */
-       dpcd_base_lt_offset = DP_TRAINING_PATTERN_SET;
-
-       if (is_repeater(lt_settings, offset))
-               dpcd_base_lt_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
-                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-
-       /*****************************************************************
-       * DpcdAddress_TrainingPatternSet
-       *****************************************************************/
-       dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
-               dp_training_pattern_to_dpcd_training_pattern(link, pattern);
-
-       dpcd_pattern.v1_4.SCRAMBLING_DISABLE =
-               dp_initialize_scrambling_data_symbols(link, pattern);
-
-       dpcd_lt_buffer[DP_TRAINING_PATTERN_SET - DP_TRAINING_PATTERN_SET]
-               = dpcd_pattern.raw;
-
-       if (is_repeater(lt_settings, offset)) {
-               DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n 0x%X pattern = %x\n",
-                       __func__,
-                       offset,
-                       dpcd_base_lt_offset,
-                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
-       } else {
-               DC_LOG_HW_LINK_TRAINING("%s\n 0x%X pattern = %x\n",
-                       __func__,
-                       dpcd_base_lt_offset,
-                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
-       }
-
-       /* concatenate everything into one buffer*/
-       size_in_bytes = lt_settings->link_settings.lane_count *
-                       sizeof(lt_settings->dpcd_lane_settings[0]);
-
-        // 0x00103 - 0x00102
-       memmove(
-               &dpcd_lt_buffer[DP_TRAINING_LANE0_SET - DP_TRAINING_PATTERN_SET],
-               lt_settings->dpcd_lane_settings,
-               size_in_bytes);
-
-       if (is_repeater(lt_settings, offset)) {
-               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_128b_132b_ENCODING)
-                       DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
-                                       " 0x%X TX_FFE_PRESET_VALUE = %x\n",
-                                       __func__,
-                                       offset,
-                                       dpcd_base_lt_offset,
-                                       lt_settings->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE);
-               else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_8b_10b_ENCODING)
-               DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
-                               " 0x%X VS set = %x PE set = %x max VS Reached = %x  max PE Reached = %x\n",
-                       __func__,
-                       offset,
-                       dpcd_base_lt_offset,
-                       lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
-                       lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
-                       lt_settings->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
-                       lt_settings->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
-       } else {
-               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_128b_132b_ENCODING)
-                       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X TX_FFE_PRESET_VALUE = %x\n",
-                                       __func__,
-                                       dpcd_base_lt_offset,
-                                       lt_settings->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE);
-               else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_8b_10b_ENCODING)
-                       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X VS set = %x  PE set = %x max VS Reached = %x  max PE Reached = %x\n",
-                                       __func__,
-                                       dpcd_base_lt_offset,
-                                       lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
-                                       lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
-                                       lt_settings->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
-                                       lt_settings->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
-       }
-       if (edp_workaround) {
-               /* for eDP write in 2 parts because the 5-byte burst is
-               * causing issues on some eDP panels (EPR#366724)
-               */
-               core_link_write_dpcd(
-                       link,
-                       DP_TRAINING_PATTERN_SET,
-                       &dpcd_pattern.raw,
-                       sizeof(dpcd_pattern.raw));
-
-               core_link_write_dpcd(
-                       link,
-                       DP_TRAINING_LANE0_SET,
-                       (uint8_t *)(lt_settings->dpcd_lane_settings),
-                       size_in_bytes);
-
-       } else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                       DP_128b_132b_ENCODING) {
-               core_link_write_dpcd(
-                               link,
-                               dpcd_base_lt_offset,
-                               dpcd_lt_buffer,
-                               sizeof(dpcd_lt_buffer));
-       } else
-               /* write it all in (1 + number-of-lanes)-byte burst*/
-               core_link_write_dpcd(
-                               link,
-                               dpcd_base_lt_offset,
-                               dpcd_lt_buffer,
-                               size_in_bytes + sizeof(dpcd_pattern.raw));
-}
-
-void start_clock_recovery_pattern_early(struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings,
-               uint32_t offset)
-{
-       DC_LOG_HW_LINK_TRAINING("%s\n GPU sends TPS1. Wait 400us.\n",
-                       __func__);
-       dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_cr, offset);
-       dp_set_hw_lane_settings(link, link_res, lt_settings, offset);
-       udelay(400);
-}
-
-void dp_set_hw_test_pattern(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       enum dp_test_pattern test_pattern,
-       uint8_t *custom_pattern,
-       uint32_t custom_pattern_size)
-{
-       const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
-       struct encoder_set_dp_phy_pattern_param pattern_param = {0};
-
-       pattern_param.dp_phy_pattern = test_pattern;
-       pattern_param.custom_pattern = custom_pattern;
-       pattern_param.custom_pattern_size = custom_pattern_size;
-       pattern_param.dp_panel_mode = dp_get_panel_mode(link);
-
-       if (link_hwss->ext.set_dp_link_test_pattern)
-               link_hwss->ext.set_dp_link_test_pattern(link, link_res, &pattern_param);
-}
-
-bool dp_set_hw_training_pattern(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       enum dc_dp_training_pattern pattern,
-       uint32_t offset)
-{
-       enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
-
-       switch (pattern) {
-       case DP_TRAINING_PATTERN_SEQUENCE_1:
-               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN1;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_2:
-               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN2;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_3:
-               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN3;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_4:
-               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN4;
-               break;
-       case DP_128b_132b_TPS1:
-               test_pattern = DP_TEST_PATTERN_128b_132b_TPS1_TRAINING_MODE;
-               break;
-       case DP_128b_132b_TPS2:
-               test_pattern = DP_TEST_PATTERN_128b_132b_TPS2_TRAINING_MODE;
-               break;
-       default:
-               break;
-       }
-
-       dp_set_hw_test_pattern(link, link_res, test_pattern, NULL, 0);
-
-       return true;
-}
-
-static bool perform_post_lt_adj_req_sequence(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       enum dc_lane_count lane_count =
-       lt_settings->link_settings.lane_count;
-
-       uint32_t adj_req_count;
-       uint32_t adj_req_timer;
-       bool req_drv_setting_changed;
-       uint32_t lane;
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-
-       req_drv_setting_changed = false;
-       for (adj_req_count = 0; adj_req_count < POST_LT_ADJ_REQ_LIMIT;
-       adj_req_count++) {
-
-               req_drv_setting_changed = false;
-
-               for (adj_req_timer = 0;
-                       adj_req_timer < POST_LT_ADJ_REQ_TIMEOUT;
-                       adj_req_timer++) {
-
-                       dp_get_lane_status_and_lane_adjust(
-                               link,
-                               lt_settings,
-                               dpcd_lane_status,
-                               &dpcd_lane_status_updated,
-                               dpcd_lane_adjust,
-                               DPRX);
-
-                       if (dpcd_lane_status_updated.bits.
-                                       POST_LT_ADJ_REQ_IN_PROGRESS == 0)
-                               return true;
-
-                       if (!dp_is_cr_done(lane_count, dpcd_lane_status))
-                               return false;
-
-                       if (!dp_is_ch_eq_done(lane_count, dpcd_lane_status) ||
-                                       !dp_is_symbol_locked(lane_count, dpcd_lane_status) ||
-                                       !dp_is_interlane_aligned(dpcd_lane_status_updated))
-                               return false;
-
-                       for (lane = 0; lane < (uint32_t)(lane_count); lane++) {
-
-                               if (lt_settings->
-                               dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET !=
-                               dpcd_lane_adjust[lane].bits.VOLTAGE_SWING_LANE ||
-                               lt_settings->dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET !=
-                               dpcd_lane_adjust[lane].bits.PRE_EMPHASIS_LANE) {
-
-                                       req_drv_setting_changed = true;
-                                       break;
-                               }
-                       }
-
-                       if (req_drv_setting_changed) {
-                               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-
-                               dc_link_dp_set_drive_settings(link,
-                                               link_res,
-                                               lt_settings);
-                               break;
-                       }
-
-                       msleep(1);
-               }
-
-               if (!req_drv_setting_changed) {
-                       DC_LOG_WARNING("%s: Post Link Training Adjust Request Timed out\n",
-                               __func__);
-
-                       ASSERT(0);
-                       return true;
-               }
-       }
-       DC_LOG_WARNING("%s: Post Link Training Adjust Request limit reached\n",
-               __func__);
-
-       ASSERT(0);
-       return true;
-
-}
-
-static enum link_training_result dp_transition_to_video_idle(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings,
-       enum link_training_result status)
-{
-       union lane_count_set lane_count_set = {0};
-
-       /* 4. mainlink output idle pattern*/
-       dp_set_hw_test_pattern(link, link_res, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
-
-       /*
-        * 5. post training adjust if required
-        * If the upstream DPTX and downstream DPRX both support TPS4,
-        * TPS4 must be used instead of POST_LT_ADJ_REQ.
-        */
-       if (link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED != 1 ||
-                       lt_settings->pattern_for_eq >= DP_TRAINING_PATTERN_SEQUENCE_4) {
-               /* delay 5ms after Main Link output idle pattern and then check
-                * DPCD 0202h.
-                */
-               if (link->connector_signal != SIGNAL_TYPE_EDP && status == LINK_TRAINING_SUCCESS) {
-                       msleep(5);
-                       status = dp_check_link_loss_status(link, lt_settings);
-               }
-               return status;
-       }
-
-       if (status == LINK_TRAINING_SUCCESS &&
-               perform_post_lt_adj_req_sequence(link, link_res, lt_settings) == false)
-               status = LINK_TRAINING_LQA_FAIL;
-
-       lane_count_set.bits.LANE_COUNT_SET = lt_settings->link_settings.lane_count;
-       lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
-       lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
-
-       core_link_write_dpcd(
-               link,
-               DP_LANE_COUNT_SET,
-               &lane_count_set.raw,
-               sizeof(lane_count_set));
-
-       return status;
-}
-
-enum link_training_result dp_perform_link_training(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       const struct dc_link_settings *link_settings,
-       bool skip_video_pattern)
-{
-       enum link_training_result status = LINK_TRAINING_SUCCESS;
-       struct link_training_settings lt_settings = {0};
-       enum dp_link_encoding encoding =
-                       link_dp_get_encoding_format(link_settings);
-
-       /* decide training settings */
-       dp_decide_training_settings(
-                       link,
-                       link_settings,
-                       &lt_settings);
-
-       override_training_settings(
-                       link,
-                       &link->preferred_training_settings,
-                       &lt_settings);
-
-       /* reset previous training states */
-       dpcd_exit_training_mode(link, encoding);
-
-       /* configure link prior to entering training mode */
-       dpcd_configure_lttpr_mode(link, &lt_settings);
-       dp_set_fec_ready(link, link_res, lt_settings.should_set_fec_ready);
-       dpcd_configure_channel_coding(link, &lt_settings);
-
-       /* enter training mode:
-        * Per DP specs starting from here, DPTX device shall not issue
-        * Non-LT AUX transactions inside training mode.
-        */
-       if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) && encoding == DP_8b_10b_ENCODING)
-               status = dp_perform_fixed_vs_pe_training_sequence(link, link_res, &lt_settings);
-       else if (encoding == DP_8b_10b_ENCODING)
-               status = dp_perform_8b_10b_link_training(link, link_res, &lt_settings);
-       else if (encoding == DP_128b_132b_ENCODING)
-               status = dp_perform_128b_132b_link_training(link, link_res, &lt_settings);
-       else
-               ASSERT(0);
-
-       /* exit training mode */
-       dpcd_exit_training_mode(link, encoding);
-
-       /* switch to video idle */
-       if ((status == LINK_TRAINING_SUCCESS) || !skip_video_pattern)
-               status = dp_transition_to_video_idle(link,
-                               link_res,
-                               &lt_settings,
-                               status);
-
-       /* dump debug data */
-       dp_log_training_result(link, &lt_settings, status);
-       if (status != LINK_TRAINING_SUCCESS)
-               link->ctx->dc->debug_data.ltFailCount++;
-       return status;
-}
-
-bool perform_link_training_with_retries(
-       const struct dc_link_settings *link_setting,
-       bool skip_video_pattern,
-       int attempts,
-       struct pipe_ctx *pipe_ctx,
-       enum signal_type signal,
-       bool do_fallback)
-{
-       int j;
-       uint8_t delay_between_attempts = LINK_TRAINING_RETRY_DELAY;
-       struct dc_stream_state *stream = pipe_ctx->stream;
-       struct dc_link *link = stream->link;
-       enum dp_panel_mode panel_mode = dp_get_panel_mode(link);
-       enum link_training_result status = LINK_TRAINING_CR_FAIL_LANE0;
-       struct dc_link_settings cur_link_settings = *link_setting;
-       struct dc_link_settings max_link_settings = *link_setting;
-       const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
-       int fail_count = 0;
-       bool is_link_bw_low = false; /* link bandwidth < stream bandwidth */
-       bool is_link_bw_min = /* RBR x 1 */
-               (cur_link_settings.link_rate <= LINK_RATE_LOW) &&
-               (cur_link_settings.lane_count <= LANE_COUNT_ONE);
-
-       dp_trace_commit_lt_init(link);
-
-
-       if (link_dp_get_encoding_format(&cur_link_settings) == DP_8b_10b_ENCODING)
-               /* We need to do this before the link training to ensure the idle
-                * pattern in SST mode will be sent right after the link training
-                */
-               link_hwss->setup_stream_encoder(pipe_ctx);
-
-       dp_trace_set_lt_start_timestamp(link, false);
-       j = 0;
-       while (j < attempts && fail_count < (attempts * 10)) {
-
-               DC_LOG_HW_LINK_TRAINING("%s: Beginning link(%d) training attempt %u of %d @ rate(%d) x lane(%d)\n",
-                       __func__, link->link_index, (unsigned int)j + 1, attempts, cur_link_settings.link_rate,
-                       cur_link_settings.lane_count);
-
-               dp_enable_link_phy(
-                       link,
-                       &pipe_ctx->link_res,
-                       signal,
-                       pipe_ctx->clock_source->id,
-                       &cur_link_settings);
-
-               if (stream->sink_patches.dppowerup_delay > 0) {
-                       int delay_dp_power_up_in_ms = stream->sink_patches.dppowerup_delay;
-
-                       msleep(delay_dp_power_up_in_ms);
-               }
-
-#ifdef CONFIG_DRM_AMD_DC_HDCP
-               if (panel_mode == DP_PANEL_MODE_EDP) {
-                       struct cp_psp *cp_psp = &stream->ctx->cp_psp;
-
-                       if (cp_psp && cp_psp->funcs.enable_assr) {
-                               /* ASSR is bound to fail with unsigned PSP
-                                * verstage used during devlopment phase.
-                                * Report and continue with eDP panel mode to
-                                * perform eDP link training with right settings
-                                */
-                               bool result;
-                               result = cp_psp->funcs.enable_assr(cp_psp->handle, link);
-                       }
-               }
-#endif
-
-               dp_set_panel_mode(link, panel_mode);
-
-               if (link->aux_access_disabled) {
-                       dc_link_dp_perform_link_training_skip_aux(link, &pipe_ctx->link_res, &cur_link_settings);
-                       return true;
-               } else {
-                       /** @todo Consolidate USB4 DP and DPx.x training. */
-                       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) {
-                               status = dc_link_dpia_perform_link_training(
-                                               link,
-                                               &pipe_ctx->link_res,
-                                               &cur_link_settings,
-                                               skip_video_pattern);
-
-                               /* Transmit idle pattern once training successful. */
-                               if (status == LINK_TRAINING_SUCCESS && !is_link_bw_low) {
-                                       dp_set_hw_test_pattern(link, &pipe_ctx->link_res, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
-                                       // Update verified link settings to current one
-                                       // Because DPIA LT might fallback to lower link setting.
-                                       if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
-                                               link->verified_link_cap.link_rate = link->cur_link_settings.link_rate;
-                                               link->verified_link_cap.lane_count = link->cur_link_settings.lane_count;
-                                               dm_helpers_dp_mst_update_branch_bandwidth(link->ctx, link);
-                                       }
-                               }
-                       } else {
-                               status = dp_perform_link_training(
-                                               link,
-                                               &pipe_ctx->link_res,
-                                               &cur_link_settings,
-                                               skip_video_pattern);
-                       }
-
-                       dp_trace_lt_total_count_increment(link, false);
-                       dp_trace_lt_result_update(link, status, false);
-                       dp_trace_set_lt_end_timestamp(link, false);
-                       if (status == LINK_TRAINING_SUCCESS && !is_link_bw_low)
-                               return true;
-               }
-
-               fail_count++;
-               dp_trace_lt_fail_count_update(link, fail_count, false);
-               if (link->ep_type == DISPLAY_ENDPOINT_PHY) {
-                       /* latest link training still fail or link training is aborted
-                        * skip delay and keep PHY on
-                        */
-                       if (j == (attempts - 1) || (status == LINK_TRAINING_ABORT))
-                               break;
-               }
-
-               DC_LOG_WARNING("%s: Link(%d) training attempt %u of %d failed @ rate(%d) x lane(%d) : fail reason:(%d)\n",
-                       __func__, link->link_index, (unsigned int)j + 1, attempts, cur_link_settings.link_rate,
-                       cur_link_settings.lane_count, status);
-
-               dp_disable_link_phy(link, &pipe_ctx->link_res, signal);
-
-               /* Abort link training if failure due to sink being unplugged. */
-               if (status == LINK_TRAINING_ABORT) {
-                       enum dc_connection_type type = dc_connection_none;
-
-                       dc_link_detect_sink(link, &type);
-                       if (type == dc_connection_none) {
-                               DC_LOG_HW_LINK_TRAINING("%s: Aborting training because sink unplugged\n", __func__);
-                               break;
-                       }
-               }
-
-               /* Try to train again at original settings if:
-                * - not falling back between training attempts;
-                * - aborted previous attempt due to reasons other than sink unplug;
-                * - successfully trained but at a link rate lower than that required by stream;
-                * - reached minimum link bandwidth.
-                */
-               if (!do_fallback || (status == LINK_TRAINING_ABORT) ||
-                               (status == LINK_TRAINING_SUCCESS && is_link_bw_low) ||
-                               is_link_bw_min) {
-                       j++;
-                       cur_link_settings = *link_setting;
-                       delay_between_attempts += LINK_TRAINING_RETRY_DELAY;
-                       is_link_bw_low = false;
-                       is_link_bw_min = (cur_link_settings.link_rate <= LINK_RATE_LOW) &&
-                               (cur_link_settings.lane_count <= LANE_COUNT_ONE);
-
-               } else if (do_fallback) { /* Try training at lower link bandwidth if doing fallback. */
-                       uint32_t req_bw;
-                       uint32_t link_bw;
-
-                       decide_fallback_link_setting(link, &max_link_settings,
-                                       &cur_link_settings, status);
-                       /* Flag if reduced link bandwidth no longer meets stream requirements or fallen back to
-                        * minimum link bandwidth.
-                        */
-                       req_bw = dc_bandwidth_in_kbps_from_timing(&stream->timing);
-                       link_bw = dc_link_bandwidth_kbps(link, &cur_link_settings);
-                       is_link_bw_low = (req_bw > link_bw);
-                       is_link_bw_min = ((cur_link_settings.link_rate <= LINK_RATE_LOW) &&
-                               (cur_link_settings.lane_count <= LANE_COUNT_ONE));
-
-                       if (is_link_bw_low)
-                               DC_LOG_WARNING(
-                                       "%s: Link(%d) bandwidth too low after fallback req_bw(%d) > link_bw(%d)\n",
-                                       __func__, link->link_index, req_bw, link_bw);
-               }
-
-               msleep(delay_between_attempts);
-       }
-
-       return false;
-}
-
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_training.h
deleted file mode 100644 (file)
index 376d370..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-
-#ifndef __DC_LINK_DP_TRAINING_H__
-#define __DC_LINK_DP_TRAINING_H__
-#include "link.h"
-
-bool perform_link_training_with_retries(
-       const struct dc_link_settings *link_setting,
-       bool skip_video_pattern,
-       int attempts,
-       struct pipe_ctx *pipe_ctx,
-       enum signal_type signal,
-       bool do_fallback);
-
-enum link_training_result dp_perform_link_training(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct dc_link_settings *link_settings,
-               bool skip_video_pattern);
-
-bool dp_set_hw_training_pattern(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               enum dc_dp_training_pattern pattern,
-               uint32_t offset);
-
-void dp_set_hw_test_pattern(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               enum dp_test_pattern test_pattern,
-               uint8_t *custom_pattern,
-               uint32_t custom_pattern_size);
-
-void dpcd_set_training_pattern(
-       struct dc_link *link,
-       enum dc_dp_training_pattern training_pattern);
-
-/* Write DPCD drive settings. */
-enum dc_status dpcd_set_lane_settings(
-       struct dc_link *link,
-       const struct link_training_settings *link_training_setting,
-       uint32_t offset);
-
-/* Write DPCD link configuration data. */
-enum dc_status dpcd_set_link_settings(
-       struct dc_link *link,
-       const struct link_training_settings *lt_settings);
-
-void dpcd_set_lt_pattern_and_lane_settings(
-       struct dc_link *link,
-       const struct link_training_settings *lt_settings,
-       enum dc_dp_training_pattern pattern,
-       uint32_t offset);
-
-/* Read training status and adjustment requests from DPCD. */
-enum dc_status dp_get_lane_status_and_lane_adjust(
-       struct dc_link *link,
-       const struct link_training_settings *link_training_setting,
-       union lane_status ln_status[LANE_COUNT_DP_MAX],
-       union lane_align_status_updated *ln_align,
-       union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
-       uint32_t offset);
-
-enum dc_status dpcd_configure_lttpr_mode(
-               struct dc_link *link,
-               struct link_training_settings *lt_settings);
-
-enum dc_status configure_lttpr_mode_transparent(struct dc_link *link);
-
-enum dc_status dpcd_configure_channel_coding(
-               struct dc_link *link,
-               struct link_training_settings *lt_settings);
-
-void repeater_training_done(struct dc_link *link, uint32_t offset);
-
-void start_clock_recovery_pattern_early(struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings,
-               uint32_t offset);
-
-void dp_decide_training_settings(
-               struct dc_link *link,
-               const struct dc_link_settings *link_settings,
-               struct link_training_settings *lt_settings);
-
-void dp_decide_lane_settings(
-       const struct link_training_settings *lt_settings,
-       const union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
-       struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
-       union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX]);
-
-enum dc_dp_training_pattern decide_cr_training_pattern(
-               const struct dc_link_settings *link_settings);
-
-enum dc_dp_training_pattern decide_eq_training_pattern(struct dc_link *link,
-               const struct dc_link_settings *link_settings);
-
-void dp_get_lttpr_mode_override(struct dc_link *link,
-               enum lttpr_mode *override);
-
-void override_training_settings(
-               struct dc_link *link,
-               const struct dc_link_training_overrides *overrides,
-               struct link_training_settings *lt_settings);
-
-/* Check DPCD training status registers to detect link loss. */
-enum link_training_result dp_check_link_loss_status(
-               struct dc_link *link,
-               const struct link_training_settings *link_training_setting);
-
-bool dp_is_cr_done(enum dc_lane_count ln_count,
-       union lane_status *dpcd_lane_status);
-
-bool dp_is_ch_eq_done(enum dc_lane_count ln_count,
-       union lane_status *dpcd_lane_status);
-bool dp_is_symbol_locked(enum dc_lane_count ln_count,
-       union lane_status *dpcd_lane_status);
-bool dp_is_interlane_aligned(union lane_align_status_updated align_status);
-
-bool is_repeater(const struct link_training_settings *lt_settings, uint32_t offset);
-
-bool dp_is_max_vs_reached(
-       const struct link_training_settings *lt_settings);
-
-uint8_t get_dpcd_link_rate(const struct dc_link_settings *link_settings);
-
-enum link_training_result dp_get_cr_failure(enum dc_lane_count ln_count,
-       union lane_status *dpcd_lane_status);
-
-void dp_hw_to_dpcd_lane_settings(
-       const struct link_training_settings *lt_settings,
-       const struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
-       union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX]);
-
-void dp_wait_for_training_aux_rd_interval(
-       struct dc_link *link,
-       uint32_t wait_in_micro_secs);
-
-enum dpcd_training_patterns
-       dp_training_pattern_to_dpcd_training_pattern(
-       struct dc_link *link,
-       enum dc_dp_training_pattern pattern);
-
-uint8_t dp_initialize_scrambling_data_symbols(
-       struct dc_link *link,
-       enum dc_dp_training_pattern pattern);
-
-void dp_log_training_result(
-       struct dc_link *link,
-       const struct link_training_settings *lt_settings,
-       enum link_training_result status);
-
-uint32_t dp_translate_training_aux_read_interval(
-               uint32_t dpcd_aux_read_interval);
-#endif /* __DC_LINK_DP_TRAINING_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_128b_132b.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_128b_132b.c
deleted file mode 100644 (file)
index bfabebe..0000000
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- * This file implements dp 128b/132b link training software policies and
- * sequences.
- */
-#include "link_dp_training_128b_132b.h"
-#include "link_dp_training_8b_10b.h"
-#include "link_dpcd.h"
-#include "link_dp_phy.h"
-#include "link_dp_capability.h"
-#include "dc_link_dp.h"
-
-#define DC_LOGGER \
-       link->ctx->logger
-
-static enum dc_status dpcd_128b_132b_set_lane_settings(
-               struct dc_link *link,
-               const struct link_training_settings *link_training_setting)
-{
-       enum dc_status status = core_link_write_dpcd(link,
-                       DP_TRAINING_LANE0_SET,
-                       (uint8_t *)(link_training_setting->dpcd_lane_settings),
-                       sizeof(link_training_setting->dpcd_lane_settings));
-
-       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X TX_FFE_PRESET_VALUE = %x\n",
-                       __func__,
-                       DP_TRAINING_LANE0_SET,
-                       link_training_setting->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE);
-       return status;
-}
-
-static void dpcd_128b_132b_get_aux_rd_interval(struct dc_link *link,
-               uint32_t *interval_in_us)
-{
-       union dp_128b_132b_training_aux_rd_interval dpcd_interval;
-       uint32_t interval_unit = 0;
-
-       dpcd_interval.raw = 0;
-       core_link_read_dpcd(link, DP_128B132B_TRAINING_AUX_RD_INTERVAL,
-                       &dpcd_interval.raw, sizeof(dpcd_interval.raw));
-       interval_unit = dpcd_interval.bits.UNIT ? 1 : 2; /* 0b = 2 ms, 1b = 1 ms */
-       /* (128b/132b_TRAINING_AUX_RD_INTERVAL value + 1) *
-        * INTERVAL_UNIT. The maximum is 256 ms
-        */
-       *interval_in_us = (dpcd_interval.bits.VALUE + 1) * interval_unit * 1000;
-}
-
-static enum link_training_result dp_perform_128b_132b_channel_eq_done_sequence(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       uint8_t loop_count;
-       uint32_t aux_rd_interval = 0;
-       uint32_t wait_time = 0;
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-       enum dc_status status = DC_OK;
-       enum link_training_result result = LINK_TRAINING_SUCCESS;
-
-       /* Transmit 128b/132b_TPS1 over Main-Link */
-       dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_cr, DPRX);
-
-       /* Set TRAINING_PATTERN_SET to 01h */
-       dpcd_set_training_pattern(link, lt_settings->pattern_for_cr);
-
-       /* Adjust TX_FFE_PRESET_VALUE and Transmit 128b/132b_TPS2 over Main-Link */
-       dpcd_128b_132b_get_aux_rd_interval(link, &aux_rd_interval);
-       dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
-                       &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
-       dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-       dp_set_hw_lane_settings(link, link_res, lt_settings, DPRX);
-       dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_eq, DPRX);
-
-       /* Set loop counter to start from 1 */
-       loop_count = 1;
-
-       /* Set TRAINING_PATTERN_SET to 02h and TX_FFE_PRESET_VALUE in one AUX transaction */
-       dpcd_set_lt_pattern_and_lane_settings(link, lt_settings,
-                       lt_settings->pattern_for_eq, DPRX);
-
-       /* poll for channel EQ done */
-       while (result == LINK_TRAINING_SUCCESS) {
-               dp_wait_for_training_aux_rd_interval(link, aux_rd_interval);
-               wait_time += aux_rd_interval;
-               status = dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
-                               &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
-               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-               dpcd_128b_132b_get_aux_rd_interval(link, &aux_rd_interval);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-               } else if (dp_is_ch_eq_done(lt_settings->link_settings.lane_count,
-                               dpcd_lane_status)) {
-                       /* pass */
-                       break;
-               } else if (loop_count >= lt_settings->eq_loop_count_limit) {
-                       result = DP_128b_132b_MAX_LOOP_COUNT_REACHED;
-               } else if (dpcd_lane_status_updated.bits.LT_FAILED_128b_132b) {
-                       result = DP_128b_132b_LT_FAILED;
-               } else {
-                       dp_set_hw_lane_settings(link, link_res, lt_settings, DPRX);
-                       dpcd_128b_132b_set_lane_settings(link, lt_settings);
-               }
-               loop_count++;
-       }
-
-       /* poll for EQ interlane align done */
-       while (result == LINK_TRAINING_SUCCESS) {
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-               } else if (dpcd_lane_status_updated.bits.EQ_INTERLANE_ALIGN_DONE_128b_132b) {
-                       /* pass */
-                       break;
-               } else if (wait_time >= lt_settings->eq_wait_time_limit) {
-                       result = DP_128b_132b_CHANNEL_EQ_DONE_TIMEOUT;
-               } else if (dpcd_lane_status_updated.bits.LT_FAILED_128b_132b) {
-                       result = DP_128b_132b_LT_FAILED;
-               } else {
-                       dp_wait_for_training_aux_rd_interval(link,
-                                       lt_settings->eq_pattern_time);
-                       wait_time += lt_settings->eq_pattern_time;
-                       status = dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
-                                       &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
-               }
-       }
-
-       return result;
-}
-
-static enum link_training_result dp_perform_128b_132b_cds_done_sequence(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       /* Assumption: assume hardware has transmitted eq pattern */
-       enum dc_status status = DC_OK;
-       enum link_training_result result = LINK_TRAINING_SUCCESS;
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-       uint32_t wait_time = 0;
-
-       /* initiate CDS done sequence */
-       dpcd_set_training_pattern(link, lt_settings->pattern_for_cds);
-
-       /* poll for CDS interlane align done and symbol lock */
-       while (result == LINK_TRAINING_SUCCESS) {
-               dp_wait_for_training_aux_rd_interval(link,
-                               lt_settings->cds_pattern_time);
-               wait_time += lt_settings->cds_pattern_time;
-               status = dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
-                                               &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-               } else if (dp_is_symbol_locked(lt_settings->link_settings.lane_count, dpcd_lane_status) &&
-                               dpcd_lane_status_updated.bits.CDS_INTERLANE_ALIGN_DONE_128b_132b) {
-                       /* pass */
-                       break;
-               } else if (dpcd_lane_status_updated.bits.LT_FAILED_128b_132b) {
-                       result = DP_128b_132b_LT_FAILED;
-               } else if (wait_time >= lt_settings->cds_wait_time_limit) {
-                       result = DP_128b_132b_CDS_DONE_TIMEOUT;
-               }
-       }
-
-       return result;
-}
-
-enum link_training_result dp_perform_128b_132b_link_training(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       enum link_training_result result = LINK_TRAINING_SUCCESS;
-
-       /* TODO - DP2.0 Link: remove legacy_dp2_lt logic */
-       if (link->dc->debug.legacy_dp2_lt) {
-               struct link_training_settings legacy_settings;
-
-               decide_8b_10b_training_settings(link,
-                               &lt_settings->link_settings,
-                               &legacy_settings);
-               return dp_perform_8b_10b_link_training(link, link_res, &legacy_settings);
-       }
-
-       dpcd_set_link_settings(link, lt_settings);
-
-       if (result == LINK_TRAINING_SUCCESS)
-               result = dp_perform_128b_132b_channel_eq_done_sequence(link, link_res, lt_settings);
-
-       if (result == LINK_TRAINING_SUCCESS)
-               result = dp_perform_128b_132b_cds_done_sequence(link, link_res, lt_settings);
-
-       return result;
-}
-
-void decide_128b_132b_training_settings(struct dc_link *link,
-               const struct dc_link_settings *link_settings,
-               struct link_training_settings *lt_settings)
-{
-       memset(lt_settings, 0, sizeof(*lt_settings));
-
-       lt_settings->link_settings = *link_settings;
-       /* TODO: should decide link spread when populating link_settings */
-       lt_settings->link_settings.link_spread = link->dp_ss_off ? LINK_SPREAD_DISABLED :
-                       LINK_SPREAD_05_DOWNSPREAD_30KHZ;
-
-       lt_settings->pattern_for_cr = decide_cr_training_pattern(link_settings);
-       lt_settings->pattern_for_eq = decide_eq_training_pattern(link, link_settings);
-       lt_settings->eq_pattern_time = 2500;
-       lt_settings->eq_wait_time_limit = 400000;
-       lt_settings->eq_loop_count_limit = 20;
-       lt_settings->pattern_for_cds = DP_128b_132b_TPS2_CDS;
-       lt_settings->cds_pattern_time = 2500;
-       lt_settings->cds_wait_time_limit = (dp_parse_lttpr_repeater_count(
-                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt) + 1) * 20000;
-       lt_settings->disallow_per_lane_settings = true;
-       lt_settings->lttpr_mode = dp_decide_128b_132b_lttpr_mode(link);
-       dp_hw_to_dpcd_lane_settings(lt_settings,
-                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-}
-
-enum lttpr_mode dp_decide_128b_132b_lttpr_mode(struct dc_link *link)
-{
-       enum lttpr_mode mode = LTTPR_MODE_NON_LTTPR;
-
-       if (dp_is_lttpr_present(link))
-               mode = LTTPR_MODE_NON_TRANSPARENT;
-
-       DC_LOG_DC("128b_132b chose LTTPR_MODE %d.\n", mode);
-       return mode;
-}
-
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_128b_132b.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_128b_132b.h
deleted file mode 100644 (file)
index 2147f24..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-
-#ifndef __DC_LINK_DP_TRAINING_128B_132B_H__
-#define __DC_LINK_DP_TRAINING_128B_132B_H__
-#include "link_dp_training.h"
-
-enum link_training_result dp_perform_128b_132b_link_training(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings);
-
-void decide_128b_132b_training_settings(struct dc_link *link,
-               const struct dc_link_settings *link_settings,
-               struct link_training_settings *lt_settings);
-
-enum lttpr_mode dp_decide_128b_132b_lttpr_mode(struct dc_link *link);
-
-#endif /* __DC_LINK_DP_TRAINING_128B_132B_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_8b_10b.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_8b_10b.c
deleted file mode 100644 (file)
index ec8b619..0000000
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- * This file implements dp 8b/10b link training software policies and
- * sequences.
- */
-#include "link_dp_training_8b_10b.h"
-#include "link_dpcd.h"
-#include "link_dp_phy.h"
-#include "link_dp_capability.h"
-#include "dc_link_dp.h"
-
-#define DC_LOGGER \
-       link->ctx->logger
-
-static int32_t get_cr_training_aux_rd_interval(struct dc_link *link,
-               const struct dc_link_settings *link_settings)
-{
-       union training_aux_rd_interval training_rd_interval;
-       uint32_t wait_in_micro_secs = 100;
-
-       memset(&training_rd_interval, 0, sizeof(training_rd_interval));
-       if (link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING &&
-                       link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_12) {
-               core_link_read_dpcd(
-                               link,
-                               DP_TRAINING_AUX_RD_INTERVAL,
-                               (uint8_t *)&training_rd_interval,
-                               sizeof(training_rd_interval));
-               if (training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL)
-                       wait_in_micro_secs = training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL * 4000;
-       }
-       return wait_in_micro_secs;
-}
-
-static uint32_t get_eq_training_aux_rd_interval(
-       struct dc_link *link,
-       const struct dc_link_settings *link_settings)
-{
-       union training_aux_rd_interval training_rd_interval;
-
-       memset(&training_rd_interval, 0, sizeof(training_rd_interval));
-       if (link_dp_get_encoding_format(link_settings) == DP_128b_132b_ENCODING) {
-               core_link_read_dpcd(
-                               link,
-                               DP_128B132B_TRAINING_AUX_RD_INTERVAL,
-                               (uint8_t *)&training_rd_interval,
-                               sizeof(training_rd_interval));
-       } else if (link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING &&
-                       link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_12) {
-               core_link_read_dpcd(
-                               link,
-                               DP_TRAINING_AUX_RD_INTERVAL,
-                               (uint8_t *)&training_rd_interval,
-                               sizeof(training_rd_interval));
-       }
-
-       switch (training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL) {
-       case 0: return 400;
-       case 1: return 4000;
-       case 2: return 8000;
-       case 3: return 12000;
-       case 4: return 16000;
-       case 5: return 32000;
-       case 6: return 64000;
-       default: return 400;
-       }
-}
-
-void decide_8b_10b_training_settings(
-        struct dc_link *link,
-       const struct dc_link_settings *link_setting,
-       struct link_training_settings *lt_settings)
-{
-       memset(lt_settings, '\0', sizeof(struct link_training_settings));
-
-       /* Initialize link settings */
-       lt_settings->link_settings.use_link_rate_set = link_setting->use_link_rate_set;
-       lt_settings->link_settings.link_rate_set = link_setting->link_rate_set;
-       lt_settings->link_settings.link_rate = link_setting->link_rate;
-       lt_settings->link_settings.lane_count = link_setting->lane_count;
-       /* TODO hard coded to SS for now
-        * lt_settings.link_settings.link_spread =
-        * dal_display_path_is_ss_supported(
-        * path_mode->display_path) ?
-        * LINK_SPREAD_05_DOWNSPREAD_30KHZ :
-        * LINK_SPREAD_DISABLED;
-        */
-       lt_settings->link_settings.link_spread = link->dp_ss_off ?
-                       LINK_SPREAD_DISABLED : LINK_SPREAD_05_DOWNSPREAD_30KHZ;
-       lt_settings->cr_pattern_time = get_cr_training_aux_rd_interval(link, link_setting);
-       lt_settings->eq_pattern_time = get_eq_training_aux_rd_interval(link, link_setting);
-       lt_settings->pattern_for_cr = decide_cr_training_pattern(link_setting);
-       lt_settings->pattern_for_eq = decide_eq_training_pattern(link, link_setting);
-       lt_settings->enhanced_framing = 1;
-       lt_settings->should_set_fec_ready = true;
-       lt_settings->disallow_per_lane_settings = true;
-       lt_settings->always_match_dpcd_with_hw_lane_settings = true;
-       lt_settings->lttpr_mode = dp_decide_8b_10b_lttpr_mode(link);
-       dp_hw_to_dpcd_lane_settings(lt_settings, lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-}
-
-enum lttpr_mode dp_decide_8b_10b_lttpr_mode(struct dc_link *link)
-{
-       bool is_lttpr_present = dp_is_lttpr_present(link);
-       bool vbios_lttpr_force_non_transparent = link->dc->caps.vbios_lttpr_enable;
-       bool vbios_lttpr_aware = link->dc->caps.vbios_lttpr_aware;
-
-       if (!is_lttpr_present)
-               return LTTPR_MODE_NON_LTTPR;
-
-       if (vbios_lttpr_aware) {
-               if (vbios_lttpr_force_non_transparent) {
-                       DC_LOG_DC("chose LTTPR_MODE_NON_TRANSPARENT due to VBIOS DCE_INFO_CAPS_LTTPR_SUPPORT_ENABLE set to 1.\n");
-                       return LTTPR_MODE_NON_TRANSPARENT;
-               } else {
-                       DC_LOG_DC("chose LTTPR_MODE_NON_TRANSPARENT by default due to VBIOS not set DCE_INFO_CAPS_LTTPR_SUPPORT_ENABLE set to 1.\n");
-                       return LTTPR_MODE_TRANSPARENT;
-               }
-       }
-
-       if (link->dc->config.allow_lttpr_non_transparent_mode.bits.DP1_4A &&
-                       link->dc->caps.extended_aux_timeout_support) {
-               DC_LOG_DC("chose LTTPR_MODE_NON_TRANSPARENT by default and dc->config.allow_lttpr_non_transparent_mode.bits.DP1_4A set to 1.\n");
-               return LTTPR_MODE_NON_TRANSPARENT;
-       }
-
-       DC_LOG_DC("chose LTTPR_MODE_NON_LTTPR.\n");
-       return LTTPR_MODE_NON_LTTPR;
-}
-
-enum link_training_result perform_8b_10b_clock_recovery_sequence(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings,
-       uint32_t offset)
-{
-       uint32_t retries_cr;
-       uint32_t retry_count;
-       uint32_t wait_time_microsec;
-       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX];
-       union lane_align_status_updated dpcd_lane_status_updated;
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-
-       retries_cr = 0;
-       retry_count = 0;
-
-       memset(&dpcd_lane_status, '\0', sizeof(dpcd_lane_status));
-       memset(&dpcd_lane_status_updated, '\0',
-       sizeof(dpcd_lane_status_updated));
-
-       if (!link->ctx->dc->work_arounds.lt_early_cr_pattern)
-               dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_cr, offset);
-
-       /* najeeb - The synaptics MST hub can put the LT in
-       * infinite loop by switching the VS
-       */
-       /* between level 0 and level 1 continuously, here
-       * we try for CR lock for LinkTrainingMaxCRRetry count*/
-       while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
-               (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
-
-
-               /* 1. call HWSS to set lane settings*/
-               dp_set_hw_lane_settings(
-                               link,
-                               link_res,
-                               lt_settings,
-                               offset);
-
-               /* 2. update DPCD of the receiver*/
-               if (!retry_count)
-                       /* EPR #361076 - write as a 5-byte burst,
-                        * but only for the 1-st iteration.*/
-                       dpcd_set_lt_pattern_and_lane_settings(
-                                       link,
-                                       lt_settings,
-                                       lt_settings->pattern_for_cr,
-                                       offset);
-               else
-                       dpcd_set_lane_settings(
-                                       link,
-                                       lt_settings,
-                                       offset);
-
-               /* 3. wait receiver to lock-on*/
-               wait_time_microsec = lt_settings->cr_pattern_time;
-
-               dp_wait_for_training_aux_rd_interval(
-                               link,
-                               wait_time_microsec);
-
-               /* 4. Read lane status and requested drive
-               * settings as set by the sink
-               */
-               dp_get_lane_status_and_lane_adjust(
-                               link,
-                               lt_settings,
-                               dpcd_lane_status,
-                               &dpcd_lane_status_updated,
-                               dpcd_lane_adjust,
-                               offset);
-
-               /* 5. check CR done*/
-               if (dp_is_cr_done(lane_count, dpcd_lane_status))
-                       return LINK_TRAINING_SUCCESS;
-
-               /* 6. max VS reached*/
-               if ((link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                               DP_8b_10b_ENCODING) &&
-                               dp_is_max_vs_reached(lt_settings))
-                       break;
-
-               /* 7. same lane settings*/
-               /* Note: settings are the same for all lanes,
-                * so comparing first lane is sufficient*/
-               if ((link_dp_get_encoding_format(&lt_settings->link_settings) == DP_8b_10b_ENCODING) &&
-                               lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
-                                               dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
-                       retries_cr++;
-               else if ((link_dp_get_encoding_format(&lt_settings->link_settings) == DP_128b_132b_ENCODING) &&
-                               lt_settings->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE ==
-                                               dpcd_lane_adjust[0].tx_ffe.PRESET_VALUE)
-                       retries_cr++;
-               else
-                       retries_cr = 0;
-
-               /* 8. update VS/PE/PC2 in lt_settings*/
-               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-               retry_count++;
-       }
-
-       if (retry_count >= LINK_TRAINING_MAX_CR_RETRY) {
-               ASSERT(0);
-               DC_LOG_ERROR("%s: Link Training Error, could not get CR after %d tries. Possibly voltage swing issue",
-                       __func__,
-                       LINK_TRAINING_MAX_CR_RETRY);
-
-       }
-
-       return dp_get_cr_failure(lane_count, dpcd_lane_status);
-}
-
-enum link_training_result perform_8b_10b_channel_equalization_sequence(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings,
-       uint32_t offset)
-{
-       enum dc_dp_training_pattern tr_pattern;
-       uint32_t retries_ch_eq;
-       uint32_t wait_time_microsec;
-       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-
-       /* Note: also check that TPS4 is a supported feature*/
-       tr_pattern = lt_settings->pattern_for_eq;
-
-       if (is_repeater(lt_settings, offset) && link_dp_get_encoding_format(&lt_settings->link_settings) == DP_8b_10b_ENCODING)
-               tr_pattern = DP_TRAINING_PATTERN_SEQUENCE_4;
-
-       dp_set_hw_training_pattern(link, link_res, tr_pattern, offset);
-
-       for (retries_ch_eq = 0; retries_ch_eq <= LINK_TRAINING_MAX_RETRY_COUNT;
-               retries_ch_eq++) {
-
-               dp_set_hw_lane_settings(link, link_res, lt_settings, offset);
-
-               /* 2. update DPCD*/
-               if (!retries_ch_eq)
-                       /* EPR #361076 - write as a 5-byte burst,
-                        * but only for the 1-st iteration
-                        */
-
-                       dpcd_set_lt_pattern_and_lane_settings(
-                               link,
-                               lt_settings,
-                               tr_pattern, offset);
-               else
-                       dpcd_set_lane_settings(link, lt_settings, offset);
-
-               /* 3. wait for receiver to lock-on*/
-               wait_time_microsec = lt_settings->eq_pattern_time;
-
-               if (is_repeater(lt_settings, offset))
-                       wait_time_microsec =
-                                       dp_translate_training_aux_read_interval(
-                                               link->dpcd_caps.lttpr_caps.aux_rd_interval[offset - 1]);
-
-               dp_wait_for_training_aux_rd_interval(
-                               link,
-                               wait_time_microsec);
-
-               /* 4. Read lane status and requested
-                * drive settings as set by the sink*/
-
-               dp_get_lane_status_and_lane_adjust(
-                       link,
-                       lt_settings,
-                       dpcd_lane_status,
-                       &dpcd_lane_status_updated,
-                       dpcd_lane_adjust,
-                       offset);
-
-               /* 5. check CR done*/
-               if (!dp_is_cr_done(lane_count, dpcd_lane_status))
-                       return dpcd_lane_status[0].bits.CR_DONE_0 ?
-                                       LINK_TRAINING_EQ_FAIL_CR_PARTIAL :
-                                       LINK_TRAINING_EQ_FAIL_CR;
-
-               /* 6. check CHEQ done*/
-               if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
-                               dp_is_symbol_locked(lane_count, dpcd_lane_status) &&
-                               dp_is_interlane_aligned(dpcd_lane_status_updated))
-                       return LINK_TRAINING_SUCCESS;
-
-               /* 7. update VS/PE/PC2 in lt_settings*/
-               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-       }
-
-       return LINK_TRAINING_EQ_FAIL_EQ;
-
-}
-
-enum link_training_result dp_perform_8b_10b_link_training(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       enum link_training_result status = LINK_TRAINING_SUCCESS;
-
-       uint8_t repeater_cnt;
-       uint8_t repeater_id;
-       uint8_t lane = 0;
-
-       if (link->ctx->dc->work_arounds.lt_early_cr_pattern)
-               start_clock_recovery_pattern_early(link, link_res, lt_settings, DPRX);
-
-       /* 1. set link rate, lane count and spread. */
-       dpcd_set_link_settings(link, lt_settings);
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
-
-               /* 2. perform link training (set link training done
-                *  to false is done as well)
-                */
-               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-
-               for (repeater_id = repeater_cnt; (repeater_id > 0 && status == LINK_TRAINING_SUCCESS);
-                               repeater_id--) {
-                       status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, repeater_id);
-
-                       if (status != LINK_TRAINING_SUCCESS) {
-                               repeater_training_done(link, repeater_id);
-                               break;
-                       }
-
-                       status = perform_8b_10b_channel_equalization_sequence(link,
-                                       link_res,
-                                       lt_settings,
-                                       repeater_id);
-
-                       repeater_training_done(link, repeater_id);
-
-                       if (status != LINK_TRAINING_SUCCESS)
-                               break;
-
-                       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-                               lt_settings->dpcd_lane_settings[lane].raw = 0;
-                               lt_settings->hw_lane_settings[lane].VOLTAGE_SWING = 0;
-                               lt_settings->hw_lane_settings[lane].PRE_EMPHASIS = 0;
-                       }
-               }
-       }
-
-       if (status == LINK_TRAINING_SUCCESS) {
-               status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, DPRX);
-               if (status == LINK_TRAINING_SUCCESS) {
-                       status = perform_8b_10b_channel_equalization_sequence(link,
-                                       link_res,
-                                       lt_settings,
-                                       DPRX);
-               }
-       }
-
-       return status;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_8b_10b.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_8b_10b.h
deleted file mode 100644 (file)
index d26de15..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-
-#ifndef __DC_LINK_DP_TRAINING_8B_10B_H__
-#define __DC_LINK_DP_TRAINING_8B_10B_H__
-#include "link_dp_training.h"
-
-/* to avoid infinite loop where-in the receiver
- * switches between different VS
- */
-#define LINK_TRAINING_MAX_CR_RETRY 100
-#define LINK_TRAINING_MAX_RETRY_COUNT 5
-
-enum link_training_result dp_perform_8b_10b_link_training(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings);
-
-enum link_training_result perform_8b_10b_clock_recovery_sequence(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings,
-       uint32_t offset);
-
-enum link_training_result perform_8b_10b_channel_equalization_sequence(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings,
-       uint32_t offset);
-
-enum lttpr_mode dp_decide_8b_10b_lttpr_mode(struct dc_link *link);
-
-void decide_8b_10b_training_settings(
-        struct dc_link *link,
-       const struct dc_link_settings *link_setting,
-       struct link_training_settings *lt_settings);
-
-#endif /* __DC_LINK_DP_TRAINING_8B_10B_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_auxless.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_auxless.c
deleted file mode 100644 (file)
index f84b6ea..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- *
- */
-#include "link_dp_training_auxless.h"
-#include "link_dp_phy.h"
-#include "dc_link_dp.h"
-#define DC_LOGGER \
-       link->ctx->logger
-bool dc_link_dp_perform_link_training_skip_aux(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       const struct dc_link_settings *link_setting)
-{
-       struct link_training_settings lt_settings = {0};
-
-       dp_decide_training_settings(
-                       link,
-                       link_setting,
-                       &lt_settings);
-       override_training_settings(
-                       link,
-                       &link->preferred_training_settings,
-                       &lt_settings);
-
-       /* 1. Perform_clock_recovery_sequence. */
-
-       /* transmit training pattern for clock recovery */
-       dp_set_hw_training_pattern(link, link_res, lt_settings.pattern_for_cr, DPRX);
-
-       /* call HWSS to set lane settings*/
-       dp_set_hw_lane_settings(link, link_res, &lt_settings, DPRX);
-
-       /* wait receiver to lock-on*/
-       dp_wait_for_training_aux_rd_interval(link, lt_settings.cr_pattern_time);
-
-       /* 2. Perform_channel_equalization_sequence. */
-
-       /* transmit training pattern for channel equalization. */
-       dp_set_hw_training_pattern(link, link_res, lt_settings.pattern_for_eq, DPRX);
-
-       /* call HWSS to set lane settings*/
-       dp_set_hw_lane_settings(link, link_res, &lt_settings, DPRX);
-
-       /* wait receiver to lock-on. */
-       dp_wait_for_training_aux_rd_interval(link, lt_settings.eq_pattern_time);
-
-       /* 3. Perform_link_training_int. */
-
-       /* Mainlink output idle pattern. */
-       dp_set_hw_test_pattern(link, link_res, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
-
-       dp_log_training_result(link, &lt_settings, LINK_TRAINING_SUCCESS);
-
-       return true;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_auxless.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_auxless.h
deleted file mode 100644 (file)
index 413999c..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-
-#ifndef __DC_LINK_DP_TRAINING_AUXLESS_H__
-#define __DC_LINK_DP_TRAINING_AUXLESS_H__
-#include "link_dp_training.h"
-
-bool dc_link_dp_perform_link_training_skip_aux(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       const struct dc_link_settings *link_setting);
-#endif /* __DC_LINK_DP_TRAINING_AUXLESS_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_dpia.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_dpia.c
deleted file mode 100644 (file)
index cf47db1..0000000
+++ /dev/null
@@ -1,1045 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- * This module implements functionality for training DPIA links.
- */
-#include "link_dp_training_dpia.h"
-#include "dc.h"
-#include "inc/core_status.h"
-#include "dc_link.h"
-#include "dc_link_dp.h"
-#include "dpcd_defs.h"
-
-#include "link_dp_dpia.h"
-#include "link_hwss.h"
-#include "dm_helpers.h"
-#include "dmub/inc/dmub_cmd.h"
-#include "link_dpcd.h"
-#include "link_dp_training_8b_10b.h"
-#include "link_dp_capability.h"
-#include "dc_dmub_srv.h"
-#define DC_LOGGER \
-       link->ctx->logger
-
-/* The approximate time (us) it takes to transmit 9 USB4 DP clock sync packets. */
-#define DPIA_CLK_SYNC_DELAY 16000
-
-/* Extend interval between training status checks for manual testing. */
-#define DPIA_DEBUG_EXTENDED_AUX_RD_INTERVAL_US 60000000
-
-/* SET_CONFIG message types sent by driver. */
-enum dpia_set_config_type {
-       DPIA_SET_CFG_SET_LINK = 0x01,
-       DPIA_SET_CFG_SET_PHY_TEST_MODE = 0x05,
-       DPIA_SET_CFG_SET_TRAINING = 0x18,
-       DPIA_SET_CFG_SET_VSPE = 0x19
-};
-
-/* Training stages (TS) in SET_CONFIG(SET_TRAINING) message. */
-enum dpia_set_config_ts {
-       DPIA_TS_DPRX_DONE = 0x00, /* Done training DPRX. */
-       DPIA_TS_TPS1 = 0x01,
-       DPIA_TS_TPS2 = 0x02,
-       DPIA_TS_TPS3 = 0x03,
-       DPIA_TS_TPS4 = 0x07,
-       DPIA_TS_UFP_DONE = 0xff /* Done training DPTX-to-DPIA hop. */
-};
-
-/* SET_CONFIG message data associated with messages sent by driver. */
-union dpia_set_config_data {
-       struct {
-               uint8_t mode : 1;
-               uint8_t reserved : 7;
-       } set_link;
-       struct {
-               uint8_t stage;
-       } set_training;
-       struct {
-               uint8_t swing : 2;
-               uint8_t max_swing_reached : 1;
-               uint8_t pre_emph : 2;
-               uint8_t max_pre_emph_reached : 1;
-               uint8_t reserved : 2;
-       } set_vspe;
-       uint8_t raw;
-};
-
-
-/* Configure link as prescribed in link_setting; set LTTPR mode; and
- * Initialize link training settings.
- * Abort link training if sink unplug detected.
- *
- * @param link DPIA link being trained.
- * @param[in] link_setting Lane count, link rate and downspread control.
- * @param[out] lt_settings Link settings and drive settings (voltage swing and pre-emphasis).
- */
-static enum link_training_result dpia_configure_link(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct dc_link_settings *link_setting,
-               struct link_training_settings *lt_settings)
-{
-       enum dc_status status;
-       bool fec_enable;
-
-       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) configuring\n - LTTPR mode(%d)\n",
-               __func__,
-               link->link_id.enum_id - ENUM_ID_1,
-               lt_settings->lttpr_mode);
-
-       dp_decide_training_settings(
-               link,
-               link_setting,
-               lt_settings);
-
-       dp_get_lttpr_mode_override(link, &lt_settings->lttpr_mode);
-
-       status = dpcd_configure_channel_coding(link, lt_settings);
-       if (status != DC_OK && link->is_hpd_pending)
-               return LINK_TRAINING_ABORT;
-
-       /* Configure lttpr mode */
-       status = dpcd_configure_lttpr_mode(link, lt_settings);
-       if (status != DC_OK && link->is_hpd_pending)
-               return LINK_TRAINING_ABORT;
-
-       /* Set link rate, lane count and spread. */
-       status = dpcd_set_link_settings(link, lt_settings);
-       if (status != DC_OK && link->is_hpd_pending)
-               return LINK_TRAINING_ABORT;
-
-       if (link->preferred_training_settings.fec_enable != NULL)
-               fec_enable = *link->preferred_training_settings.fec_enable;
-       else
-               fec_enable = true;
-       status = dp_set_fec_ready(link, link_res, fec_enable);
-       if (status != DC_OK && link->is_hpd_pending)
-               return LINK_TRAINING_ABORT;
-
-       return LINK_TRAINING_SUCCESS;
-}
-
-static enum dc_status core_link_send_set_config(
-       struct dc_link *link,
-       uint8_t msg_type,
-       uint8_t msg_data)
-{
-       struct set_config_cmd_payload payload;
-       enum set_config_status set_config_result = SET_CONFIG_PENDING;
-
-       /* prepare set_config payload */
-       payload.msg_type = msg_type;
-       payload.msg_data = msg_data;
-
-       if (!link->ddc->ddc_pin && !link->aux_access_disabled &&
-                       (dm_helpers_dmub_set_config_sync(link->ctx,
-                       link, &payload, &set_config_result) == -1)) {
-               return DC_ERROR_UNEXPECTED;
-       }
-
-       /* set_config should return ACK if successful */
-       return (set_config_result == SET_CONFIG_ACK_RECEIVED) ? DC_OK : DC_ERROR_UNEXPECTED;
-}
-
-/* Build SET_CONFIG message data payload for specified message type. */
-static uint8_t dpia_build_set_config_data(
-               enum dpia_set_config_type type,
-               struct dc_link *link,
-               struct link_training_settings *lt_settings)
-{
-       union dpia_set_config_data data;
-
-       data.raw = 0;
-
-       switch (type) {
-       case DPIA_SET_CFG_SET_LINK:
-               data.set_link.mode = lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT ? 1 : 0;
-               break;
-       case DPIA_SET_CFG_SET_PHY_TEST_MODE:
-               break;
-       case DPIA_SET_CFG_SET_VSPE:
-               /* Assume all lanes have same drive settings. */
-               data.set_vspe.swing = lt_settings->hw_lane_settings[0].VOLTAGE_SWING;
-               data.set_vspe.pre_emph = lt_settings->hw_lane_settings[0].PRE_EMPHASIS;
-               data.set_vspe.max_swing_reached =
-                               lt_settings->hw_lane_settings[0].VOLTAGE_SWING == VOLTAGE_SWING_MAX_LEVEL ? 1 : 0;
-               data.set_vspe.max_pre_emph_reached =
-                               lt_settings->hw_lane_settings[0].PRE_EMPHASIS == PRE_EMPHASIS_MAX_LEVEL ? 1 : 0;
-               break;
-       default:
-               ASSERT(false); /* Message type not supported by helper function. */
-               break;
-       }
-
-       return data.raw;
-}
-
-/* Convert DC training pattern to DPIA training stage. */
-static enum dc_status convert_trng_ptn_to_trng_stg(enum dc_dp_training_pattern tps, enum dpia_set_config_ts *ts)
-{
-       enum dc_status status = DC_OK;
-
-       switch (tps) {
-       case DP_TRAINING_PATTERN_SEQUENCE_1:
-               *ts = DPIA_TS_TPS1;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_2:
-               *ts = DPIA_TS_TPS2;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_3:
-               *ts = DPIA_TS_TPS3;
-               break;
-       case DP_TRAINING_PATTERN_SEQUENCE_4:
-               *ts = DPIA_TS_TPS4;
-               break;
-       case DP_TRAINING_PATTERN_VIDEOIDLE:
-               *ts = DPIA_TS_DPRX_DONE;
-               break;
-       default: /* TPS not supported by helper function. */
-               ASSERT(false);
-               *ts = DPIA_TS_DPRX_DONE;
-               status = DC_UNSUPPORTED_VALUE;
-               break;
-       }
-
-       return status;
-}
-
-/* Write training pattern to DPCD. */
-static enum dc_status dpcd_set_lt_pattern(
-       struct dc_link *link,
-       enum dc_dp_training_pattern pattern,
-       uint32_t hop)
-{
-       union dpcd_training_pattern dpcd_pattern = {0};
-       uint32_t dpcd_tps_offset = DP_TRAINING_PATTERN_SET;
-       enum dc_status status;
-
-       if (hop != DPRX)
-               dpcd_tps_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
-                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (hop - 1));
-
-       /* DpcdAddress_TrainingPatternSet */
-       dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
-               dp_training_pattern_to_dpcd_training_pattern(link, pattern);
-
-       dpcd_pattern.v1_4.SCRAMBLING_DISABLE =
-               dp_initialize_scrambling_data_symbols(link, pattern);
-
-       if (hop != DPRX) {
-               DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n 0x%X pattern = %x\n",
-                       __func__,
-                       hop,
-                       dpcd_tps_offset,
-                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
-       } else {
-               DC_LOG_HW_LINK_TRAINING("%s\n 0x%X pattern = %x\n",
-                       __func__,
-                       dpcd_tps_offset,
-                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
-       }
-
-       status = core_link_write_dpcd(
-                       link,
-                       dpcd_tps_offset,
-                       &dpcd_pattern.raw,
-                       sizeof(dpcd_pattern.raw));
-
-       return status;
-}
-
-/* Execute clock recovery phase of link training for specified hop in display
- * path.in non-transparent mode:
- * - Driver issues both DPCD and SET_CONFIG transactions.
- * - TPS1 is transmitted for any hops downstream of DPOA.
- * - Drive (VS/PE) only transmitted for the hop immediately downstream of DPOA.
- * - CR for the first hop (DPTX-to-DPIA) is assumed to be successful.
- *
- * @param link DPIA link being trained.
- * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
- * @param hop Hop in display path. DPRX = 0.
- */
-static enum link_training_result dpia_training_cr_non_transparent(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings,
-               uint32_t hop)
-{
-       enum link_training_result result = LINK_TRAINING_CR_FAIL_LANE0;
-       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
-       enum dc_status status;
-       uint32_t retries_cr = 0; /* Number of consecutive attempts with same VS or PE. */
-       uint32_t retry_count = 0;
-       uint32_t wait_time_microsec = TRAINING_AUX_RD_INTERVAL; /* From DP spec, CR read interval is always 100us. */
-       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-       uint8_t set_cfg_data;
-       enum dpia_set_config_ts ts;
-
-       repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-
-       /* Cap of LINK_TRAINING_MAX_CR_RETRY attempts at clock recovery.
-        * Fix inherited from perform_clock_recovery_sequence() -
-        * the DP equivalent of this function:
-        * Required for Synaptics MST hub which can put the LT in
-        * infinite loop by switching the VS between level 0 and level 1
-        * continuously.
-        */
-       while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
-                       (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
-
-               /* DPTX-to-DPIA */
-               if (hop == repeater_cnt) {
-                       /* Send SET_CONFIG(SET_LINK:LC,LR,LTTPR) to notify DPOA that
-                        * non-transparent link training has started.
-                        * This also enables the transmission of clk_sync packets.
-                        */
-                       set_cfg_data = dpia_build_set_config_data(
-                                       DPIA_SET_CFG_SET_LINK,
-                                       link,
-                                       lt_settings);
-                       status = core_link_send_set_config(
-                                       link,
-                                       DPIA_SET_CFG_SET_LINK,
-                                       set_cfg_data);
-                       /* CR for this hop is considered successful as long as
-                        * SET_CONFIG message is acknowledged by DPOA.
-                        */
-                       if (status == DC_OK)
-                               result = LINK_TRAINING_SUCCESS;
-                       else
-                               result = LINK_TRAINING_ABORT;
-                       break;
-               }
-
-               /* DPOA-to-x */
-               /* Instruct DPOA to transmit TPS1 then update DPCD. */
-               if (retry_count == 0) {
-                       status = convert_trng_ptn_to_trng_stg(lt_settings->pattern_for_cr, &ts);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-                       status = core_link_send_set_config(
-                                       link,
-                                       DPIA_SET_CFG_SET_TRAINING,
-                                       ts);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-                       status = dpcd_set_lt_pattern(link, lt_settings->pattern_for_cr, hop);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-               }
-
-               /* Update DPOA drive settings then DPCD. DPOA does only adjusts
-                * drive settings for hops immediately downstream.
-                */
-               if (hop == repeater_cnt - 1) {
-                       set_cfg_data = dpia_build_set_config_data(
-                                       DPIA_SET_CFG_SET_VSPE,
-                                       link,
-                                       lt_settings);
-                       status = core_link_send_set_config(
-                                       link,
-                                       DPIA_SET_CFG_SET_VSPE,
-                                       set_cfg_data);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-               }
-               status = dpcd_set_lane_settings(link, lt_settings, hop);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-                       break;
-               }
-
-               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
-
-               /* Read status and adjustment requests from DPCD. */
-               status = dp_get_lane_status_and_lane_adjust(
-                               link,
-                               lt_settings,
-                               dpcd_lane_status,
-                               &dpcd_lane_status_updated,
-                               dpcd_lane_adjust,
-                               hop);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-                       break;
-               }
-
-               /* Check if clock recovery successful. */
-               if (dp_is_cr_done(lane_count, dpcd_lane_status)) {
-                       result = LINK_TRAINING_SUCCESS;
-                       break;
-               }
-
-               result = dp_get_cr_failure(lane_count, dpcd_lane_status);
-
-               if (dp_is_max_vs_reached(lt_settings))
-                       break;
-
-               /* Count number of attempts with same drive settings.
-                * Note: settings are the same for all lanes,
-                * so comparing first lane is sufficient.
-                */
-               if ((lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
-                               dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
-                               && (lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET ==
-                                               dpcd_lane_adjust[0].bits.PRE_EMPHASIS_LANE))
-                       retries_cr++;
-               else
-                       retries_cr = 0;
-
-               /* Update VS/PE. */
-               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                               lt_settings->hw_lane_settings,
-                               lt_settings->dpcd_lane_settings);
-               retry_count++;
-       }
-
-       /* Abort link training if clock recovery failed due to HPD unplug. */
-       if (link->is_hpd_pending)
-               result = LINK_TRAINING_ABORT;
-
-       DC_LOG_HW_LINK_TRAINING(
-               "%s\n DPIA(%d) clock recovery\n -hop(%d)\n - result(%d)\n - retries(%d)\n - status(%d)\n",
-               __func__,
-               link->link_id.enum_id - ENUM_ID_1,
-               hop,
-               result,
-               retry_count,
-               status);
-
-       return result;
-}
-
-/* Execute clock recovery phase of link training in transparent LTTPR mode:
- * - Driver only issues DPCD transactions and leaves USB4 tunneling (SET_CONFIG) messages to DPIA.
- * - Driver writes TPS1 to DPCD to kick off training.
- * - Clock recovery (CR) for link is handled by DPOA, which reports result to DPIA on completion.
- * - DPIA communicates result to driver by updating CR status when driver reads DPCD.
- *
- * @param link DPIA link being trained.
- * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
- */
-static enum link_training_result dpia_training_cr_transparent(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       enum link_training_result result = LINK_TRAINING_CR_FAIL_LANE0;
-       enum dc_status status;
-       uint32_t retries_cr = 0; /* Number of consecutive attempts with same VS or PE. */
-       uint32_t retry_count = 0;
-       uint32_t wait_time_microsec = lt_settings->cr_pattern_time;
-       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-
-       /* Cap of LINK_TRAINING_MAX_CR_RETRY attempts at clock recovery.
-        * Fix inherited from perform_clock_recovery_sequence() -
-        * the DP equivalent of this function:
-        * Required for Synaptics MST hub which can put the LT in
-        * infinite loop by switching the VS between level 0 and level 1
-        * continuously.
-        */
-       while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
-                       (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
-
-               /* Write TPS1 (not VS or PE) to DPCD to start CR phase.
-                * DPIA sends SET_CONFIG(SET_LINK) to notify DPOA to
-                * start link training.
-                */
-               if (retry_count == 0) {
-                       status = dpcd_set_lt_pattern(link, lt_settings->pattern_for_cr, DPRX);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-               }
-
-               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
-
-               /* Read status and adjustment requests from DPCD. */
-               status = dp_get_lane_status_and_lane_adjust(
-                               link,
-                               lt_settings,
-                               dpcd_lane_status,
-                               &dpcd_lane_status_updated,
-                               dpcd_lane_adjust,
-                               DPRX);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-                       break;
-               }
-
-               /* Check if clock recovery successful. */
-               if (dp_is_cr_done(lane_count, dpcd_lane_status)) {
-                       result = LINK_TRAINING_SUCCESS;
-                       break;
-               }
-
-               result = dp_get_cr_failure(lane_count, dpcd_lane_status);
-
-               if (dp_is_max_vs_reached(lt_settings))
-                       break;
-
-               /* Count number of attempts with same drive settings.
-                * Note: settings are the same for all lanes,
-                * so comparing first lane is sufficient.
-                */
-               if ((lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
-                               dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
-                               && (lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET ==
-                                               dpcd_lane_adjust[0].bits.PRE_EMPHASIS_LANE))
-                       retries_cr++;
-               else
-                       retries_cr = 0;
-
-               /* Update VS/PE. */
-               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-               retry_count++;
-       }
-
-       /* Abort link training if clock recovery failed due to HPD unplug. */
-       if (link->is_hpd_pending)
-               result = LINK_TRAINING_ABORT;
-
-       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) clock recovery\n -hop(%d)\n - result(%d)\n - retries(%d)\n",
-               __func__,
-               link->link_id.enum_id - ENUM_ID_1,
-               DPRX,
-               result,
-               retry_count);
-
-       return result;
-}
-
-/* Execute clock recovery phase of link training for specified hop in display
- * path.
- *
- * @param link DPIA link being trained.
- * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
- * @param hop Hop in display path. DPRX = 0.
- */
-static enum link_training_result dpia_training_cr_phase(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings,
-               uint32_t hop)
-{
-       enum link_training_result result = LINK_TRAINING_CR_FAIL_LANE0;
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
-               result = dpia_training_cr_non_transparent(link, link_res, lt_settings, hop);
-       else
-               result = dpia_training_cr_transparent(link, link_res, lt_settings);
-
-       return result;
-}
-
-/* Return status read interval during equalization phase. */
-static uint32_t dpia_get_eq_aux_rd_interval(
-               const struct dc_link *link,
-               const struct link_training_settings *lt_settings,
-               uint32_t hop)
-{
-       uint32_t wait_time_microsec;
-
-       if (hop == DPRX)
-               wait_time_microsec = lt_settings->eq_pattern_time;
-       else
-               wait_time_microsec =
-                               dp_translate_training_aux_read_interval(
-                                       link->dpcd_caps.lttpr_caps.aux_rd_interval[hop - 1]);
-
-       /* Check debug option for extending aux read interval. */
-       if (link->dc->debug.dpia_debug.bits.extend_aux_rd_interval)
-               wait_time_microsec = DPIA_DEBUG_EXTENDED_AUX_RD_INTERVAL_US;
-
-       return wait_time_microsec;
-}
-
-/* Execute equalization phase of link training for specified hop in display
- * path in non-transparent mode:
- * - driver issues both DPCD and SET_CONFIG transactions.
- * - TPSx is transmitted for any hops downstream of DPOA.
- * - Drive (VS/PE) only transmitted for the hop immediately downstream of DPOA.
- * - EQ for the first hop (DPTX-to-DPIA) is assumed to be successful.
- * - DPRX EQ only reported successful when both DPRX and DPIA requirements (clk sync packets sent) fulfilled.
- *
- * @param link DPIA link being trained.
- * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
- * @param hop Hop in display path. DPRX = 0.
- */
-static enum link_training_result dpia_training_eq_non_transparent(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings,
-               uint32_t hop)
-{
-       enum link_training_result result = LINK_TRAINING_EQ_FAIL_EQ;
-       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
-       uint32_t retries_eq = 0;
-       enum dc_status status;
-       enum dc_dp_training_pattern tr_pattern;
-       uint32_t wait_time_microsec;
-       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-       uint8_t set_cfg_data;
-       enum dpia_set_config_ts ts;
-
-       /* Training pattern is TPS4 for repeater;
-        * TPS2/3/4 for DPRX depending on what it supports.
-        */
-       if (hop == DPRX)
-               tr_pattern = lt_settings->pattern_for_eq;
-       else
-               tr_pattern = DP_TRAINING_PATTERN_SEQUENCE_4;
-
-       repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-
-       for (retries_eq = 0; retries_eq < LINK_TRAINING_MAX_RETRY_COUNT; retries_eq++) {
-
-               /* DPTX-to-DPIA equalization always successful. */
-               if (hop == repeater_cnt) {
-                       result = LINK_TRAINING_SUCCESS;
-                       break;
-               }
-
-               /* Instruct DPOA to transmit TPSn then update DPCD. */
-               if (retries_eq == 0) {
-                       status = convert_trng_ptn_to_trng_stg(tr_pattern, &ts);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-                       status = core_link_send_set_config(
-                                       link,
-                                       DPIA_SET_CFG_SET_TRAINING,
-                                       ts);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-                       status = dpcd_set_lt_pattern(link, tr_pattern, hop);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-               }
-
-               /* Update DPOA drive settings then DPCD. DPOA only adjusts
-                * drive settings for hop immediately downstream.
-                */
-               if (hop == repeater_cnt - 1) {
-                       set_cfg_data = dpia_build_set_config_data(
-                                       DPIA_SET_CFG_SET_VSPE,
-                                       link,
-                                       lt_settings);
-                       status = core_link_send_set_config(
-                                       link,
-                                       DPIA_SET_CFG_SET_VSPE,
-                                       set_cfg_data);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-               }
-               status = dpcd_set_lane_settings(link, lt_settings, hop);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-                       break;
-               }
-
-               /* Extend wait time on second equalisation attempt on final hop to
-                * ensure clock sync packets have been sent.
-                */
-               if (hop == DPRX && retries_eq == 1)
-                       wait_time_microsec = max(wait_time_microsec, (uint32_t) DPIA_CLK_SYNC_DELAY);
-               else
-                       wait_time_microsec = dpia_get_eq_aux_rd_interval(link, lt_settings, hop);
-
-               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
-
-               /* Read status and adjustment requests from DPCD. */
-               status = dp_get_lane_status_and_lane_adjust(
-                               link,
-                               lt_settings,
-                               dpcd_lane_status,
-                               &dpcd_lane_status_updated,
-                               dpcd_lane_adjust,
-                               hop);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-                       break;
-               }
-
-               /* CR can still fail during EQ phase. Fail training if CR fails. */
-               if (!dp_is_cr_done(lane_count, dpcd_lane_status)) {
-                       result = LINK_TRAINING_EQ_FAIL_CR;
-                       break;
-               }
-
-               if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
-                               dp_is_symbol_locked(link->cur_link_settings.lane_count, dpcd_lane_status) &&
-                               dp_is_interlane_aligned(dpcd_lane_status_updated)) {
-                       result =  LINK_TRAINING_SUCCESS;
-                       break;
-               }
-
-               /* Update VS/PE. */
-               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-       }
-
-       /* Abort link training if equalization failed due to HPD unplug. */
-       if (link->is_hpd_pending)
-               result = LINK_TRAINING_ABORT;
-
-       DC_LOG_HW_LINK_TRAINING(
-               "%s\n DPIA(%d) equalization\n - hop(%d)\n - result(%d)\n - retries(%d)\n - status(%d)\n",
-               __func__,
-               link->link_id.enum_id - ENUM_ID_1,
-               hop,
-               result,
-               retries_eq,
-               status);
-
-       return result;
-}
-
-/* Execute equalization phase of link training for specified hop in display
- * path in transparent LTTPR mode:
- * - driver only issues DPCD transactions leaves USB4 tunneling (SET_CONFIG) messages to DPIA.
- * - driver writes TPSx to DPCD to notify DPIA that is in equalization phase.
- * - equalization (EQ) for link is handled by DPOA, which reports result to DPIA on completion.
- * - DPIA communicates result to driver by updating EQ status when driver reads DPCD.
- *
- * @param link DPIA link being trained.
- * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
- * @param hop Hop in display path. DPRX = 0.
- */
-static enum link_training_result dpia_training_eq_transparent(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       enum link_training_result result = LINK_TRAINING_EQ_FAIL_EQ;
-       uint32_t retries_eq = 0;
-       enum dc_status status;
-       enum dc_dp_training_pattern tr_pattern = lt_settings->pattern_for_eq;
-       uint32_t wait_time_microsec;
-       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-       union lane_align_status_updated dpcd_lane_status_updated = {0};
-       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-
-       wait_time_microsec = dpia_get_eq_aux_rd_interval(link, lt_settings, DPRX);
-
-       for (retries_eq = 0; retries_eq < LINK_TRAINING_MAX_RETRY_COUNT; retries_eq++) {
-
-               if (retries_eq == 0) {
-                       status = dpcd_set_lt_pattern(link, tr_pattern, DPRX);
-                       if (status != DC_OK) {
-                               result = LINK_TRAINING_ABORT;
-                               break;
-                       }
-               }
-
-               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
-
-               /* Read status and adjustment requests from DPCD. */
-               status = dp_get_lane_status_and_lane_adjust(
-                               link,
-                               lt_settings,
-                               dpcd_lane_status,
-                               &dpcd_lane_status_updated,
-                               dpcd_lane_adjust,
-                               DPRX);
-               if (status != DC_OK) {
-                       result = LINK_TRAINING_ABORT;
-                       break;
-               }
-
-               /* CR can still fail during EQ phase. Fail training if CR fails. */
-               if (!dp_is_cr_done(lane_count, dpcd_lane_status)) {
-                       result = LINK_TRAINING_EQ_FAIL_CR;
-                       break;
-               }
-
-               if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
-                               dp_is_symbol_locked(link->cur_link_settings.lane_count, dpcd_lane_status)) {
-                       /* Take into consideration corner case for DP 1.4a LL Compliance CTS as USB4
-                        * has to share encoders unlike DP and USBC
-                        */
-                       if (dp_is_interlane_aligned(dpcd_lane_status_updated) || (link->is_automated && retries_eq)) {
-                               result =  LINK_TRAINING_SUCCESS;
-                               break;
-                       }
-               }
-
-               /* Update VS/PE. */
-               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-       }
-
-       /* Abort link training if equalization failed due to HPD unplug. */
-       if (link->is_hpd_pending)
-               result = LINK_TRAINING_ABORT;
-
-       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) equalization\n - hop(%d)\n - result(%d)\n - retries(%d)\n",
-               __func__,
-               link->link_id.enum_id - ENUM_ID_1,
-               DPRX,
-               result,
-               retries_eq);
-
-       return result;
-}
-
-/* Execute equalization phase of link training for specified hop in display
- * path.
- *
- * @param link DPIA link being trained.
- * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
- * @param hop Hop in display path. DPRX = 0.
- */
-static enum link_training_result dpia_training_eq_phase(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings,
-               uint32_t hop)
-{
-       enum link_training_result result;
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
-               result = dpia_training_eq_non_transparent(link, link_res, lt_settings, hop);
-       else
-               result = dpia_training_eq_transparent(link, link_res, lt_settings);
-
-       return result;
-}
-
-/* End training of specified hop in display path. */
-static enum dc_status dpcd_clear_lt_pattern(
-       struct dc_link *link,
-       uint32_t hop)
-{
-       union dpcd_training_pattern dpcd_pattern = {0};
-       uint32_t dpcd_tps_offset = DP_TRAINING_PATTERN_SET;
-       enum dc_status status;
-
-       if (hop != DPRX)
-               dpcd_tps_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
-                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (hop - 1));
-
-       status = core_link_write_dpcd(
-                       link,
-                       dpcd_tps_offset,
-                       &dpcd_pattern.raw,
-                       sizeof(dpcd_pattern.raw));
-
-       return status;
-}
-
-/* End training of specified hop in display path.
- *
- * In transparent LTTPR mode:
- * - driver clears training pattern for the specified hop in DPCD.
- * In non-transparent LTTPR mode:
- * - in addition to clearing training pattern, driver issues USB4 tunneling
- * (SET_CONFIG) messages to notify DPOA when training is done for first hop
- * (DPTX-to-DPIA) and last hop (DPRX).
- *
- * @param link DPIA link being trained.
- * @param hop Hop in display path. DPRX = 0.
- */
-static enum link_training_result dpia_training_end(
-               struct dc_link *link,
-               struct link_training_settings *lt_settings,
-               uint32_t hop)
-{
-       enum link_training_result result = LINK_TRAINING_SUCCESS;
-       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
-       enum dc_status status;
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
-
-               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-
-               if (hop == repeater_cnt) { /* DPTX-to-DPIA */
-                       /* Send SET_CONFIG(SET_TRAINING:0xff) to notify DPOA that
-                        * DPTX-to-DPIA hop trained. No DPCD write needed for first hop.
-                        */
-                       status = core_link_send_set_config(
-                                       link,
-                                       DPIA_SET_CFG_SET_TRAINING,
-                                       DPIA_TS_UFP_DONE);
-                       if (status != DC_OK)
-                               result = LINK_TRAINING_ABORT;
-               } else { /* DPOA-to-x */
-                       /* Write 0x0 to TRAINING_PATTERN_SET */
-                       status = dpcd_clear_lt_pattern(link, hop);
-                       if (status != DC_OK)
-                               result = LINK_TRAINING_ABORT;
-               }
-
-               /* Notify DPOA that non-transparent link training of DPRX done. */
-               if (hop == DPRX && result != LINK_TRAINING_ABORT) {
-                       status = core_link_send_set_config(
-                                       link,
-                                       DPIA_SET_CFG_SET_TRAINING,
-                                       DPIA_TS_DPRX_DONE);
-                       if (status != DC_OK)
-                               result = LINK_TRAINING_ABORT;
-               }
-
-       } else { /* non-LTTPR or transparent LTTPR. */
-
-               /* Write 0x0 to TRAINING_PATTERN_SET */
-               status = dpcd_clear_lt_pattern(link, hop);
-               if (status != DC_OK)
-                       result = LINK_TRAINING_ABORT;
-
-       }
-
-       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) end\n - hop(%d)\n - result(%d)\n - LTTPR mode(%d)\n",
-               __func__,
-               link->link_id.enum_id - ENUM_ID_1,
-               hop,
-               result,
-               lt_settings->lttpr_mode);
-
-       return result;
-}
-
-/* When aborting training of specified hop in display path, clean up by:
- * - Attempting to clear DPCD TRAINING_PATTERN_SET, LINK_BW_SET and LANE_COUNT_SET.
- * - Sending SET_CONFIG(SET_LINK) with lane count and link rate set to 0.
- *
- * @param link DPIA link being trained.
- * @param hop Hop in display path. DPRX = 0.
- */
-static void dpia_training_abort(
-               struct dc_link *link,
-               struct link_training_settings *lt_settings,
-               uint32_t hop)
-{
-       uint8_t data = 0;
-       uint32_t dpcd_tps_offset = DP_TRAINING_PATTERN_SET;
-
-       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) aborting\n - LTTPR mode(%d)\n - HPD(%d)\n",
-               __func__,
-               link->link_id.enum_id - ENUM_ID_1,
-               lt_settings->lttpr_mode,
-               link->is_hpd_pending);
-
-       /* Abandon clean-up if sink unplugged. */
-       if (link->is_hpd_pending)
-               return;
-
-       if (hop != DPRX)
-               dpcd_tps_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
-                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (hop - 1));
-
-       core_link_write_dpcd(link, dpcd_tps_offset, &data, 1);
-       core_link_write_dpcd(link, DP_LINK_BW_SET, &data, 1);
-       core_link_write_dpcd(link, DP_LANE_COUNT_SET, &data, 1);
-       core_link_send_set_config(link, DPIA_SET_CFG_SET_LINK, data);
-}
-
-enum link_training_result dc_link_dpia_perform_link_training(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       const struct dc_link_settings *link_setting,
-       bool skip_video_pattern)
-{
-       enum link_training_result result;
-       struct link_training_settings lt_settings = {0};
-       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
-       int8_t repeater_id; /* Current hop. */
-
-       struct dc_link_settings link_settings = *link_setting; // non-const copy to pass in
-
-       lt_settings.lttpr_mode = dc_link_decide_lttpr_mode(link, &link_settings);
-
-       /* Configure link as prescribed in link_setting and set LTTPR mode. */
-       result = dpia_configure_link(link, link_res, link_setting, &lt_settings);
-       if (result != LINK_TRAINING_SUCCESS)
-               return result;
-
-       if (lt_settings.lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
-               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-
-       /* Train each hop in turn starting with the one closest to DPTX.
-        * In transparent or non-LTTPR mode, train only the final hop (DPRX).
-        */
-       for (repeater_id = repeater_cnt; repeater_id >= 0; repeater_id--) {
-               /* Clock recovery. */
-               result = dpia_training_cr_phase(link, link_res, &lt_settings, repeater_id);
-               if (result != LINK_TRAINING_SUCCESS)
-                       break;
-
-               /* Equalization. */
-               result = dpia_training_eq_phase(link, link_res, &lt_settings, repeater_id);
-               if (result != LINK_TRAINING_SUCCESS)
-                       break;
-
-               /* Stop training hop. */
-               result = dpia_training_end(link, &lt_settings, repeater_id);
-               if (result != LINK_TRAINING_SUCCESS)
-                       break;
-       }
-
-       /* Double-check link status if training successful; gracefully abort
-        * training of current hop if training failed due to message tunneling
-        * failure; end training of hop if training ended conventionally and
-        * falling back to lower bandwidth settings possible.
-        */
-       if (result == LINK_TRAINING_SUCCESS) {
-               msleep(5);
-               if (!link->is_automated)
-                       result = dp_check_link_loss_status(link, &lt_settings);
-       } else if (result == LINK_TRAINING_ABORT)
-               dpia_training_abort(link, &lt_settings, repeater_id);
-       else
-               dpia_training_end(link, &lt_settings, repeater_id);
-
-       return result;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_dpia.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_dpia.h
deleted file mode 100644 (file)
index 0150f29..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-
-#ifndef __DC_LINK_DP_TRAINING_DPIA_H__
-#define __DC_LINK_DP_TRAINING_DPIA_H__
-#include "link_dp_training.h"
-
-/* Train DP tunneling link for USB4 DPIA display endpoint.
- * DPIA equivalent of dc_link_dp_perfrorm_link_training.
- * Aborts link training upon detection of sink unplug.
- */
-enum link_training_result dc_link_dpia_perform_link_training(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       const struct dc_link_settings *link_setting,
-       bool skip_video_pattern);
-
-#endif /* __DC_LINK_DP_TRAINING_DPIA_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_fixed_vs_pe_retimer.c b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_fixed_vs_pe_retimer.c
deleted file mode 100644 (file)
index 860b5ee..0000000
+++ /dev/null
@@ -1,580 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- * This file implements 8b/10b link training specially modified to support an
- * embedded retimer chip. This retimer chip is referred as fixed vs pe retimer.
- * Unlike native dp connection this chip requires a modified link training
- * protocol based on 8b/10b link training. Since this is a non standard sequence
- * and we must support this hardware, we decided to isolate it in its own
- * training sequence inside its own file.
- */
-#include "link_dp_training_fixed_vs_pe_retimer.h"
-#include "link_dp_training_8b_10b.h"
-#include "link_dpcd.h"
-#include "link_dp_phy.h"
-#include "link_dp_capability.h"
-#include "dc_link_dp.h"
-
-#define DC_LOGGER \
-       link->ctx->logger
-
-void dp_fixed_vs_pe_read_lane_adjust(
-       struct dc_link *link,
-       union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX])
-{
-       const uint8_t vendor_lttpr_write_data_vs[3] = {0x0, 0x53, 0x63};
-       const uint8_t vendor_lttpr_write_data_pe[3] = {0x0, 0x54, 0x63};
-       const uint8_t offset = dp_parse_lttpr_repeater_count(
-                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-       uint32_t vendor_lttpr_write_address = 0xF004F;
-       uint32_t vendor_lttpr_read_address = 0xF0053;
-       uint8_t dprx_vs = 0;
-       uint8_t dprx_pe = 0;
-       uint8_t lane;
-
-       if (offset != 0xFF) {
-               vendor_lttpr_write_address +=
-                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-               vendor_lttpr_read_address +=
-                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-       }
-
-       /* W/A to read lane settings requested by DPRX */
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_vs[0],
-                       sizeof(vendor_lttpr_write_data_vs));
-       core_link_read_dpcd(
-                       link,
-                       vendor_lttpr_read_address,
-                       &dprx_vs,
-                       1);
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_pe[0],
-                       sizeof(vendor_lttpr_write_data_pe));
-       core_link_read_dpcd(
-                       link,
-                       vendor_lttpr_read_address,
-                       &dprx_pe,
-                       1);
-
-       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-               dpcd_lane_adjust[lane].bits.VOLTAGE_SWING_SET  = (dprx_vs >> (2 * lane)) & 0x3;
-               dpcd_lane_adjust[lane].bits.PRE_EMPHASIS_SET = (dprx_pe >> (2 * lane)) & 0x3;
-       }
-}
-
-
-void dp_fixed_vs_pe_set_retimer_lane_settings(
-       struct dc_link *link,
-       const union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX],
-       uint8_t lane_count)
-{
-       const uint8_t offset = dp_parse_lttpr_repeater_count(
-                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-       const uint8_t vendor_lttpr_write_data_reset[4] = {0x1, 0x50, 0x63, 0xFF};
-       uint32_t vendor_lttpr_write_address = 0xF004F;
-       uint8_t vendor_lttpr_write_data_vs[4] = {0x1, 0x51, 0x63, 0x0};
-       uint8_t vendor_lttpr_write_data_pe[4] = {0x1, 0x52, 0x63, 0x0};
-       uint8_t lane = 0;
-
-       if (offset != 0xFF) {
-               vendor_lttpr_write_address +=
-                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-       }
-
-       for (lane = 0; lane < lane_count; lane++) {
-               vendor_lttpr_write_data_vs[3] |=
-                               dpcd_lane_adjust[lane].bits.VOLTAGE_SWING_SET << (2 * lane);
-               vendor_lttpr_write_data_pe[3] |=
-                               dpcd_lane_adjust[lane].bits.PRE_EMPHASIS_SET << (2 * lane);
-       }
-
-       /* Force LTTPR to output desired VS and PE */
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_reset[0],
-                       sizeof(vendor_lttpr_write_data_reset));
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_vs[0],
-                       sizeof(vendor_lttpr_write_data_vs));
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_pe[0],
-                       sizeof(vendor_lttpr_write_data_pe));
-}
-
-static enum link_training_result perform_fixed_vs_pe_nontransparent_training_sequence(
-               struct dc_link *link,
-               const struct link_resource *link_res,
-               struct link_training_settings *lt_settings)
-{
-       enum link_training_result status = LINK_TRAINING_SUCCESS;
-       uint8_t lane = 0;
-       uint8_t toggle_rate = 0x6;
-       uint8_t target_rate = 0x6;
-       bool apply_toggle_rate_wa = false;
-       uint8_t repeater_cnt;
-       uint8_t repeater_id;
-
-       /* Fixed VS/PE specific: Force CR AUX RD Interval to at least 16ms */
-       if (lt_settings->cr_pattern_time < 16000)
-               lt_settings->cr_pattern_time = 16000;
-
-       /* Fixed VS/PE specific: Toggle link rate */
-       apply_toggle_rate_wa = (link->vendor_specific_lttpr_link_rate_wa == target_rate);
-       target_rate = get_dpcd_link_rate(&lt_settings->link_settings);
-       toggle_rate = (target_rate == 0x6) ? 0xA : 0x6;
-
-       if (apply_toggle_rate_wa)
-               lt_settings->link_settings.link_rate = toggle_rate;
-
-       if (link->ctx->dc->work_arounds.lt_early_cr_pattern)
-               start_clock_recovery_pattern_early(link, link_res, lt_settings, DPRX);
-
-       /* 1. set link rate, lane count and spread. */
-       dpcd_set_link_settings(link, lt_settings);
-
-       /* Fixed VS/PE specific: Toggle link rate back*/
-       if (apply_toggle_rate_wa) {
-               core_link_write_dpcd(
-                               link,
-                               DP_LINK_BW_SET,
-                               &target_rate,
-                               1);
-       }
-
-       link->vendor_specific_lttpr_link_rate_wa = target_rate;
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
-
-               /* 2. perform link training (set link training done
-                *  to false is done as well)
-                */
-               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-
-               for (repeater_id = repeater_cnt; (repeater_id > 0 && status == LINK_TRAINING_SUCCESS);
-                               repeater_id--) {
-                       status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, repeater_id);
-
-                       if (status != LINK_TRAINING_SUCCESS) {
-                               repeater_training_done(link, repeater_id);
-                               break;
-                       }
-
-                       status = perform_8b_10b_channel_equalization_sequence(link,
-                                       link_res,
-                                       lt_settings,
-                                       repeater_id);
-
-                       repeater_training_done(link, repeater_id);
-
-                       if (status != LINK_TRAINING_SUCCESS)
-                               break;
-
-                       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
-                               lt_settings->dpcd_lane_settings[lane].raw = 0;
-                               lt_settings->hw_lane_settings[lane].VOLTAGE_SWING = 0;
-                               lt_settings->hw_lane_settings[lane].PRE_EMPHASIS = 0;
-                       }
-               }
-       }
-
-       if (status == LINK_TRAINING_SUCCESS) {
-               status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, DPRX);
-               if (status == LINK_TRAINING_SUCCESS) {
-                       status = perform_8b_10b_channel_equalization_sequence(link,
-                                                                      link_res,
-                                                                      lt_settings,
-                                                                      DPRX);
-               }
-       }
-
-       return status;
-}
-
-
-enum link_training_result dp_perform_fixed_vs_pe_training_sequence(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings)
-{
-       const uint8_t vendor_lttpr_write_data_reset[4] = {0x1, 0x50, 0x63, 0xFF};
-       const uint8_t offset = dp_parse_lttpr_repeater_count(
-                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
-       const uint8_t vendor_lttpr_write_data_intercept_en[4] = {0x1, 0x55, 0x63, 0x0};
-       const uint8_t vendor_lttpr_write_data_intercept_dis[4] = {0x1, 0x55, 0x63, 0x68};
-       uint32_t pre_disable_intercept_delay_ms = link->dc->debug.fixed_vs_aux_delay_config_wa;
-       uint8_t vendor_lttpr_write_data_vs[4] = {0x1, 0x51, 0x63, 0x0};
-       uint8_t vendor_lttpr_write_data_pe[4] = {0x1, 0x52, 0x63, 0x0};
-       uint32_t vendor_lttpr_write_address = 0xF004F;
-       enum link_training_result status = LINK_TRAINING_SUCCESS;
-       uint8_t lane = 0;
-       union down_spread_ctrl downspread = {0};
-       union lane_count_set lane_count_set = {0};
-       uint8_t toggle_rate;
-       uint8_t rate;
-
-       /* Only 8b/10b is supported */
-       ASSERT(link_dp_get_encoding_format(&lt_settings->link_settings) ==
-                       DP_8b_10b_ENCODING);
-
-       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
-               status = perform_fixed_vs_pe_nontransparent_training_sequence(link, link_res, lt_settings);
-               return status;
-       }
-
-       if (offset != 0xFF) {
-               vendor_lttpr_write_address +=
-                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
-
-               /* Certain display and cable configuration require extra delay */
-               if (offset > 2)
-                       pre_disable_intercept_delay_ms = link->dc->debug.fixed_vs_aux_delay_config_wa * 2;
-       }
-
-       /* Vendor specific: Reset lane settings */
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_reset[0],
-                       sizeof(vendor_lttpr_write_data_reset));
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_vs[0],
-                       sizeof(vendor_lttpr_write_data_vs));
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_pe[0],
-                       sizeof(vendor_lttpr_write_data_pe));
-
-       /* Vendor specific: Enable intercept */
-       core_link_write_dpcd(
-                       link,
-                       vendor_lttpr_write_address,
-                       &vendor_lttpr_write_data_intercept_en[0],
-                       sizeof(vendor_lttpr_write_data_intercept_en));
-
-       /* 1. set link rate, lane count and spread. */
-
-       downspread.raw = (uint8_t)(lt_settings->link_settings.link_spread);
-
-       lane_count_set.bits.LANE_COUNT_SET =
-       lt_settings->link_settings.lane_count;
-
-       lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
-       lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
-
-
-       if (lt_settings->pattern_for_eq < DP_TRAINING_PATTERN_SEQUENCE_4) {
-               lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED =
-                               link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED;
-       }
-
-       core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
-               &downspread.raw, sizeof(downspread));
-
-       core_link_write_dpcd(link, DP_LANE_COUNT_SET,
-               &lane_count_set.raw, 1);
-
-       rate = get_dpcd_link_rate(&lt_settings->link_settings);
-
-       /* Vendor specific: Toggle link rate */
-       toggle_rate = (rate == 0x6) ? 0xA : 0x6;
-
-       if (link->vendor_specific_lttpr_link_rate_wa == rate) {
-               core_link_write_dpcd(
-                               link,
-                               DP_LINK_BW_SET,
-                               &toggle_rate,
-                               1);
-       }
-
-       link->vendor_specific_lttpr_link_rate_wa = rate;
-
-       core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
-
-       DC_LOG_HW_LINK_TRAINING("%s\n %x rate = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
-               __func__,
-               DP_LINK_BW_SET,
-               lt_settings->link_settings.link_rate,
-               DP_LANE_COUNT_SET,
-               lt_settings->link_settings.lane_count,
-               lt_settings->enhanced_framing,
-               DP_DOWNSPREAD_CTRL,
-               lt_settings->link_settings.link_spread);
-
-       /* 2. Perform link training */
-
-       /* Perform Clock Recovery Sequence */
-       if (status == LINK_TRAINING_SUCCESS) {
-               const uint8_t max_vendor_dpcd_retries = 10;
-               uint32_t retries_cr;
-               uint32_t retry_count;
-               uint32_t wait_time_microsec;
-               enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-               union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX];
-               union lane_align_status_updated dpcd_lane_status_updated;
-               union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-               enum dc_status dpcd_status = DC_OK;
-               uint8_t i = 0;
-
-               retries_cr = 0;
-               retry_count = 0;
-
-               memset(&dpcd_lane_status, '\0', sizeof(dpcd_lane_status));
-               memset(&dpcd_lane_status_updated, '\0',
-               sizeof(dpcd_lane_status_updated));
-
-               while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
-                       (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
-
-
-                       /* 1. call HWSS to set lane settings */
-                       dp_set_hw_lane_settings(
-                                       link,
-                                       link_res,
-                                       lt_settings,
-                                       0);
-
-                       /* 2. update DPCD of the receiver */
-                       if (!retry_count) {
-                               /* EPR #361076 - write as a 5-byte burst,
-                                * but only for the 1-st iteration.
-                                */
-                               dpcd_set_lt_pattern_and_lane_settings(
-                                               link,
-                                               lt_settings,
-                                               lt_settings->pattern_for_cr,
-                                               0);
-                               /* Vendor specific: Disable intercept */
-                               for (i = 0; i < max_vendor_dpcd_retries; i++) {
-                                       msleep(pre_disable_intercept_delay_ms);
-                                       dpcd_status = core_link_write_dpcd(
-                                                       link,
-                                                       vendor_lttpr_write_address,
-                                                       &vendor_lttpr_write_data_intercept_dis[0],
-                                                       sizeof(vendor_lttpr_write_data_intercept_dis));
-
-                                       if (dpcd_status == DC_OK)
-                                               break;
-
-                                       core_link_write_dpcd(
-                                                       link,
-                                                       vendor_lttpr_write_address,
-                                                       &vendor_lttpr_write_data_intercept_en[0],
-                                                       sizeof(vendor_lttpr_write_data_intercept_en));
-                               }
-                       } else {
-                               vendor_lttpr_write_data_vs[3] = 0;
-                               vendor_lttpr_write_data_pe[3] = 0;
-
-                               for (lane = 0; lane < lane_count; lane++) {
-                                       vendor_lttpr_write_data_vs[3] |=
-                                                       lt_settings->dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET << (2 * lane);
-                                       vendor_lttpr_write_data_pe[3] |=
-                                                       lt_settings->dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET << (2 * lane);
-                               }
-
-                               /* Vendor specific: Update VS and PE to DPRX requested value */
-                               core_link_write_dpcd(
-                                               link,
-                                               vendor_lttpr_write_address,
-                                               &vendor_lttpr_write_data_vs[0],
-                                               sizeof(vendor_lttpr_write_data_vs));
-                               core_link_write_dpcd(
-                                               link,
-                                               vendor_lttpr_write_address,
-                                               &vendor_lttpr_write_data_pe[0],
-                                               sizeof(vendor_lttpr_write_data_pe));
-
-                               dpcd_set_lane_settings(
-                                               link,
-                                               lt_settings,
-                                               0);
-                       }
-
-                       /* 3. wait receiver to lock-on*/
-                       wait_time_microsec = lt_settings->cr_pattern_time;
-
-                       dp_wait_for_training_aux_rd_interval(
-                                       link,
-                                       wait_time_microsec);
-
-                       /* 4. Read lane status and requested drive
-                        * settings as set by the sink
-                        */
-                       dp_get_lane_status_and_lane_adjust(
-                                       link,
-                                       lt_settings,
-                                       dpcd_lane_status,
-                                       &dpcd_lane_status_updated,
-                                       dpcd_lane_adjust,
-                                       0);
-
-                       /* 5. check CR done*/
-                       if (dp_is_cr_done(lane_count, dpcd_lane_status)) {
-                               status = LINK_TRAINING_SUCCESS;
-                               break;
-                       }
-
-                       /* 6. max VS reached*/
-                       if (dp_is_max_vs_reached(lt_settings))
-                               break;
-
-                       /* 7. same lane settings */
-                       /* Note: settings are the same for all lanes,
-                        * so comparing first lane is sufficient
-                        */
-                       if (lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
-                                       dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
-                               retries_cr++;
-                       else
-                               retries_cr = 0;
-
-                       /* 8. update VS/PE/PC2 in lt_settings*/
-                       dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-                       retry_count++;
-               }
-
-               if (retry_count >= LINK_TRAINING_MAX_CR_RETRY) {
-                       ASSERT(0);
-                       DC_LOG_ERROR("%s: Link Training Error, could not get CR after %d tries. Possibly voltage swing issue",
-                               __func__,
-                               LINK_TRAINING_MAX_CR_RETRY);
-
-               }
-
-               status = dp_get_cr_failure(lane_count, dpcd_lane_status);
-       }
-
-       /* Perform Channel EQ Sequence */
-       if (status == LINK_TRAINING_SUCCESS) {
-               enum dc_dp_training_pattern tr_pattern;
-               uint32_t retries_ch_eq;
-               uint32_t wait_time_microsec;
-               enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
-               union lane_align_status_updated dpcd_lane_status_updated = {0};
-               union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
-               union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
-
-               /* Note: also check that TPS4 is a supported feature*/
-               tr_pattern = lt_settings->pattern_for_eq;
-
-               dp_set_hw_training_pattern(link, link_res, tr_pattern, 0);
-
-               status = LINK_TRAINING_EQ_FAIL_EQ;
-
-               for (retries_ch_eq = 0; retries_ch_eq <= LINK_TRAINING_MAX_RETRY_COUNT;
-                       retries_ch_eq++) {
-
-                       dp_set_hw_lane_settings(link, link_res, lt_settings, 0);
-
-                       vendor_lttpr_write_data_vs[3] = 0;
-                       vendor_lttpr_write_data_pe[3] = 0;
-
-                       for (lane = 0; lane < lane_count; lane++) {
-                               vendor_lttpr_write_data_vs[3] |=
-                                               lt_settings->dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET << (2 * lane);
-                               vendor_lttpr_write_data_pe[3] |=
-                                               lt_settings->dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET << (2 * lane);
-                       }
-
-                       /* Vendor specific: Update VS and PE to DPRX requested value */
-                       core_link_write_dpcd(
-                                       link,
-                                       vendor_lttpr_write_address,
-                                       &vendor_lttpr_write_data_vs[0],
-                                       sizeof(vendor_lttpr_write_data_vs));
-                       core_link_write_dpcd(
-                                       link,
-                                       vendor_lttpr_write_address,
-                                       &vendor_lttpr_write_data_pe[0],
-                                       sizeof(vendor_lttpr_write_data_pe));
-
-                       /* 2. update DPCD*/
-                       if (!retries_ch_eq)
-                               /* EPR #361076 - write as a 5-byte burst,
-                                * but only for the 1-st iteration
-                                */
-
-                               dpcd_set_lt_pattern_and_lane_settings(
-                                       link,
-                                       lt_settings,
-                                       tr_pattern, 0);
-                       else
-                               dpcd_set_lane_settings(link, lt_settings, 0);
-
-                       /* 3. wait for receiver to lock-on*/
-                       wait_time_microsec = lt_settings->eq_pattern_time;
-
-                       dp_wait_for_training_aux_rd_interval(
-                                       link,
-                                       wait_time_microsec);
-
-                       /* 4. Read lane status and requested
-                        * drive settings as set by the sink
-                        */
-                       dp_get_lane_status_and_lane_adjust(
-                               link,
-                               lt_settings,
-                               dpcd_lane_status,
-                               &dpcd_lane_status_updated,
-                               dpcd_lane_adjust,
-                               0);
-
-                       /* 5. check CR done*/
-                       if (!dp_is_cr_done(lane_count, dpcd_lane_status)) {
-                               status = LINK_TRAINING_EQ_FAIL_CR;
-                               break;
-                       }
-
-                       /* 6. check CHEQ done*/
-                       if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
-                                       dp_is_symbol_locked(lane_count, dpcd_lane_status) &&
-                                       dp_is_interlane_aligned(dpcd_lane_status_updated)) {
-                               status = LINK_TRAINING_SUCCESS;
-                               break;
-                       }
-
-                       /* 7. update VS/PE/PC2 in lt_settings*/
-                       dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
-                                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
-               }
-       }
-
-       return status;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dp_training_fixed_vs_pe_retimer.h b/drivers/gpu/drm/amd/display/dc/link/link_dp_training_fixed_vs_pe_retimer.h
deleted file mode 100644 (file)
index e61970e..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-
-#ifndef __DC_LINK_DP_FIXED_VS_PE_RETIMER_H__
-#define __DC_LINK_DP_FIXED_VS_PE_RETIMER_H__
-#include "link_dp_training.h"
-
-enum link_training_result dp_perform_fixed_vs_pe_training_sequence(
-       struct dc_link *link,
-       const struct link_resource *link_res,
-       struct link_training_settings *lt_settings);
-
-void dp_fixed_vs_pe_set_retimer_lane_settings(
-       struct dc_link *link,
-       const union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX],
-       uint8_t lane_count);
-
-void dp_fixed_vs_pe_read_lane_adjust(
-       struct dc_link *link,
-       union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX]);
-
-#endif /* __DC_LINK_DP_FIXED_VS_PE_RETIMER_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dpcd.c b/drivers/gpu/drm/amd/display/dc/link/link_dpcd.c
deleted file mode 100644 (file)
index 5c9a302..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Copyright 2021 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- *
- * This file implements basic dpcd read/write functionality. It also does basic
- * dpcd range check to ensure that every dpcd request is compliant with specs
- * range requirements.
- */
-
-#include "link_dpcd.h"
-#include <drm/display/drm_dp_helper.h>
-#include "dm_helpers.h"
-
-#define END_ADDRESS(start, size) (start + size - 1)
-#define ADDRESS_RANGE_SIZE(start, end) (end - start + 1)
-struct dpcd_address_range {
-       uint32_t start;
-       uint32_t end;
-};
-
-static enum dc_status internal_link_read_dpcd(
-       struct dc_link *link,
-       uint32_t address,
-       uint8_t *data,
-       uint32_t size)
-{
-       if (!link->aux_access_disabled &&
-                       !dm_helpers_dp_read_dpcd(link->ctx,
-                       link, address, data, size)) {
-               return DC_ERROR_UNEXPECTED;
-       }
-
-       return DC_OK;
-}
-
-static enum dc_status internal_link_write_dpcd(
-       struct dc_link *link,
-       uint32_t address,
-       const uint8_t *data,
-       uint32_t size)
-{
-       if (!link->aux_access_disabled &&
-                       !dm_helpers_dp_write_dpcd(link->ctx,
-                       link, address, data, size)) {
-               return DC_ERROR_UNEXPECTED;
-       }
-
-       return DC_OK;
-}
-
-/*
- * Partition the entire DPCD address space
- * XXX: This partitioning must cover the entire DPCD address space,
- * and must contain no gaps or overlapping address ranges.
- */
-static const struct dpcd_address_range mandatory_dpcd_partitions[] = {
-       { 0, DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR1) - 1},
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR1), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR2) - 1 },
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR2), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR3) - 1 },
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR3), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR4) - 1 },
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR4), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR5) - 1 },
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR5), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR6) - 1 },
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR6), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR7) - 1 },
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR7), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR8) - 1 },
-       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR8), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR1) - 1 },
-       /*
-        * The FEC registers are contiguous
-        */
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR1), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR1) - 1 },
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR2), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR2) - 1 },
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR3), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR3) - 1 },
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR4), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR4) - 1 },
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR5), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR5) - 1 },
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR6), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR6) - 1 },
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR7), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR7) - 1 },
-       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR8), DP_LTTPR_MAX_ADD },
-       /* all remaining DPCD addresses */
-       { DP_LTTPR_MAX_ADD + 1, DP_DPCD_MAX_ADD } };
-
-static inline bool do_addresses_intersect_with_range(
-               const struct dpcd_address_range *range,
-               const uint32_t start_address,
-               const uint32_t end_address)
-{
-       return start_address <= range->end && end_address >= range->start;
-}
-
-static uint32_t dpcd_get_next_partition_size(const uint32_t address, const uint32_t size)
-{
-       const uint32_t end_address = END_ADDRESS(address, size);
-       uint32_t partition_iterator = 0;
-
-       /*
-        * find current partition
-        * this loop spins forever if partition map above is not surjective
-        */
-       while (!do_addresses_intersect_with_range(&mandatory_dpcd_partitions[partition_iterator],
-                               address, end_address))
-               partition_iterator++;
-       if (end_address < mandatory_dpcd_partitions[partition_iterator].end)
-               return size;
-       return ADDRESS_RANGE_SIZE(address, mandatory_dpcd_partitions[partition_iterator].end);
-}
-
-/*
- * Ranges of DPCD addresses that must be read in a single transaction
- * XXX: Do not allow any two address ranges in this array to overlap
- */
-static const struct dpcd_address_range mandatory_dpcd_blocks[] = {
-       { DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV, DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT }};
-
-/*
- * extend addresses to read all mandatory blocks together
- */
-static void dpcd_extend_address_range(
-               const uint32_t in_address,
-               uint8_t * const in_data,
-               const uint32_t in_size,
-               uint32_t *out_address,
-               uint8_t **out_data,
-               uint32_t *out_size)
-{
-       const uint32_t end_address = END_ADDRESS(in_address, in_size);
-       const struct dpcd_address_range *addr_range;
-       struct dpcd_address_range new_addr_range;
-       uint32_t i;
-
-       new_addr_range.start = in_address;
-       new_addr_range.end = end_address;
-       for (i = 0; i < ARRAY_SIZE(mandatory_dpcd_blocks); i++) {
-               addr_range = &mandatory_dpcd_blocks[i];
-               if (addr_range->start <= in_address && addr_range->end >= in_address)
-                       new_addr_range.start = addr_range->start;
-
-               if (addr_range->start <= end_address && addr_range->end >= end_address)
-                       new_addr_range.end = addr_range->end;
-       }
-       *out_address = in_address;
-       *out_size = in_size;
-       *out_data = in_data;
-       if (new_addr_range.start != in_address || new_addr_range.end != end_address) {
-               *out_address = new_addr_range.start;
-               *out_size = ADDRESS_RANGE_SIZE(new_addr_range.start, new_addr_range.end);
-               *out_data = kzalloc(*out_size * sizeof(**out_data), GFP_KERNEL);
-       }
-}
-
-/*
- * Reduce the AUX reply down to the values the caller requested
- */
-static void dpcd_reduce_address_range(
-               const uint32_t extended_address,
-               uint8_t * const extended_data,
-               const uint32_t extended_size,
-               const uint32_t reduced_address,
-               uint8_t * const reduced_data,
-               const uint32_t reduced_size)
-{
-       const uint32_t offset = reduced_address - extended_address;
-
-       /*
-        * If the address is same, address was not extended.
-        * So we do not need to free any memory.
-        * The data is in original buffer(reduced_data).
-        */
-       if (extended_data == reduced_data)
-               return;
-
-       memcpy(&extended_data[offset], reduced_data, reduced_size);
-       kfree(extended_data);
-}
-
-enum dc_status core_link_read_dpcd(
-       struct dc_link *link,
-       uint32_t address,
-       uint8_t *data,
-       uint32_t size)
-{
-       uint32_t extended_address;
-       uint32_t partitioned_address;
-       uint8_t *extended_data;
-       uint32_t extended_size;
-       /* size of the remaining partitioned address space */
-       uint32_t size_left_to_read;
-       enum dc_status status;
-       /* size of the next partition to be read from */
-       uint32_t partition_size;
-       uint32_t data_index = 0;
-
-       dpcd_extend_address_range(address, data, size, &extended_address, &extended_data, &extended_size);
-       partitioned_address = extended_address;
-       size_left_to_read = extended_size;
-       while (size_left_to_read) {
-               partition_size = dpcd_get_next_partition_size(partitioned_address, size_left_to_read);
-               status = internal_link_read_dpcd(link, partitioned_address, &extended_data[data_index], partition_size);
-               if (status != DC_OK)
-                       break;
-               partitioned_address += partition_size;
-               data_index += partition_size;
-               size_left_to_read -= partition_size;
-       }
-       dpcd_reduce_address_range(extended_address, extended_data, extended_size, address, data, size);
-       return status;
-}
-
-enum dc_status core_link_write_dpcd(
-       struct dc_link *link,
-       uint32_t address,
-       const uint8_t *data,
-       uint32_t size)
-{
-       uint32_t partition_size;
-       uint32_t data_index = 0;
-       enum dc_status status;
-
-       while (size) {
-               partition_size = dpcd_get_next_partition_size(address, size);
-               status = internal_link_write_dpcd(link, address, &data[data_index], partition_size);
-               if (status != DC_OK)
-                       break;
-               address += partition_size;
-               data_index += partition_size;
-               size -= partition_size;
-       }
-       return status;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dpcd.h b/drivers/gpu/drm/amd/display/dc/link/link_dpcd.h
deleted file mode 100644 (file)
index 08d787a..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2021 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-#ifndef __LINK_DPCD_H__
-#define __LINK_DPCD_H__
-#include "link.h"
-#include "dpcd_defs.h"
-
-enum dc_status core_link_read_dpcd(
-               struct dc_link *link,
-               uint32_t address,
-               uint8_t *data,
-               uint32_t size);
-
-enum dc_status core_link_write_dpcd(
-               struct dc_link *link,
-               uint32_t address,
-               const uint8_t *data,
-               uint32_t size);
-#endif
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hpd.c b/drivers/gpu/drm/amd/display/dc/link/link_hpd.c
deleted file mode 100644 (file)
index 5f39dfe..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-/* FILE POLICY AND INTENDED USAGE:
- *
- * This file implements functions that manage basic HPD components such as gpio.
- * It also provides wrapper functions to execute HPD related programming. This
- * file only manages basic HPD functionality. It doesn't manage detection or
- * feature or signal specific HPD behaviors.
- */
-#include "link_hpd.h"
-#include "gpio_service_interface.h"
-
-bool dc_link_get_hpd_state(struct dc_link *dc_link)
-{
-       uint32_t state;
-
-       dal_gpio_lock_pin(dc_link->hpd_gpio);
-       dal_gpio_get_value(dc_link->hpd_gpio, &state);
-       dal_gpio_unlock_pin(dc_link->hpd_gpio);
-
-       return state;
-}
-
-void dc_link_enable_hpd(const struct dc_link *link)
-{
-       struct link_encoder *encoder = link->link_enc;
-
-       if (encoder != NULL && encoder->funcs->enable_hpd != NULL)
-               encoder->funcs->enable_hpd(encoder);
-}
-
-void dc_link_disable_hpd(const struct dc_link *link)
-{
-       struct link_encoder *encoder = link->link_enc;
-
-       if (encoder != NULL && encoder->funcs->enable_hpd != NULL)
-               encoder->funcs->disable_hpd(encoder);
-}
-
-void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
-{
-       struct gpio *hpd;
-
-       if (enable) {
-               link->is_hpd_filter_disabled = false;
-               program_hpd_filter(link);
-       } else {
-               link->is_hpd_filter_disabled = true;
-               /* Obtain HPD handle */
-               hpd = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
-
-               if (!hpd)
-                       return;
-
-               /* Setup HPD filtering */
-               if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
-                       struct gpio_hpd_config config;
-
-                       config.delay_on_connect = 0;
-                       config.delay_on_disconnect = 0;
-
-                       dal_irq_setup_hpd_filter(hpd, &config);
-
-                       dal_gpio_close(hpd);
-               } else {
-                       ASSERT_CRITICAL(false);
-               }
-               /* Release HPD handle */
-               dal_gpio_destroy_irq(&hpd);
-       }
-}
-
-struct gpio *link_get_hpd_gpio(struct dc_bios *dcb,
-                         struct graphics_object_id link_id,
-                         struct gpio_service *gpio_service)
-{
-       enum bp_result bp_result;
-       struct graphics_object_hpd_info hpd_info;
-       struct gpio_pin_info pin_info;
-
-       if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
-               return NULL;
-
-       bp_result = dcb->funcs->get_gpio_pin_info(dcb,
-               hpd_info.hpd_int_gpio_uid, &pin_info);
-
-       if (bp_result != BP_RESULT_OK) {
-               ASSERT(bp_result == BP_RESULT_NORECORD);
-               return NULL;
-       }
-
-       return dal_gpio_service_create_irq(gpio_service,
-                                          pin_info.offset,
-                                          pin_info.mask);
-}
-
-bool query_hpd_status(struct dc_link *link, uint32_t *is_hpd_high)
-{
-       struct gpio *hpd_pin = link_get_hpd_gpio(
-                       link->ctx->dc_bios, link->link_id,
-                       link->ctx->gpio_service);
-       if (!hpd_pin)
-               return false;
-
-       dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
-       dal_gpio_get_value(hpd_pin, is_hpd_high);
-       dal_gpio_close(hpd_pin);
-       dal_gpio_destroy_irq(&hpd_pin);
-       return true;
-}
-
-enum hpd_source_id get_hpd_line(struct dc_link *link)
-{
-       struct gpio *hpd;
-       enum hpd_source_id hpd_id;
-
-               hpd_id = HPD_SOURCEID_UNKNOWN;
-
-       hpd = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id,
-                          link->ctx->gpio_service);
-
-       if (hpd) {
-               switch (dal_irq_get_source(hpd)) {
-               case DC_IRQ_SOURCE_HPD1:
-                       hpd_id = HPD_SOURCEID1;
-               break;
-               case DC_IRQ_SOURCE_HPD2:
-                       hpd_id = HPD_SOURCEID2;
-               break;
-               case DC_IRQ_SOURCE_HPD3:
-                       hpd_id = HPD_SOURCEID3;
-               break;
-               case DC_IRQ_SOURCE_HPD4:
-                       hpd_id = HPD_SOURCEID4;
-               break;
-               case DC_IRQ_SOURCE_HPD5:
-                       hpd_id = HPD_SOURCEID5;
-               break;
-               case DC_IRQ_SOURCE_HPD6:
-                       hpd_id = HPD_SOURCEID6;
-               break;
-               default:
-                       BREAK_TO_DEBUGGER();
-               break;
-               }
-
-               dal_gpio_destroy_irq(&hpd);
-       }
-
-       return hpd_id;
-}
-
-bool program_hpd_filter(const struct dc_link *link)
-{
-       bool result = false;
-       struct gpio *hpd;
-       int delay_on_connect_in_ms = 0;
-       int delay_on_disconnect_in_ms = 0;
-
-       if (link->is_hpd_filter_disabled)
-               return false;
-       /* Verify feature is supported */
-       switch (link->connector_signal) {
-       case SIGNAL_TYPE_DVI_SINGLE_LINK:
-       case SIGNAL_TYPE_DVI_DUAL_LINK:
-       case SIGNAL_TYPE_HDMI_TYPE_A:
-               /* Program hpd filter */
-               delay_on_connect_in_ms = 500;
-               delay_on_disconnect_in_ms = 100;
-               break;
-       case SIGNAL_TYPE_DISPLAY_PORT:
-       case SIGNAL_TYPE_DISPLAY_PORT_MST:
-               /* Program hpd filter to allow DP signal to settle */
-               /* 500: not able to detect MST <-> SST switch as HPD is low for
-                * only 100ms on DELL U2413
-                * 0: some passive dongle still show aux mode instead of i2c
-                * 20-50: not enough to hide bouncing HPD with passive dongle.
-                * also see intermittent i2c read issues.
-                */
-               delay_on_connect_in_ms = 80;
-               delay_on_disconnect_in_ms = 0;
-               break;
-       case SIGNAL_TYPE_LVDS:
-       case SIGNAL_TYPE_EDP:
-       default:
-               /* Don't program hpd filter */
-               return false;
-       }
-
-       /* Obtain HPD handle */
-       hpd = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id,
-                          link->ctx->gpio_service);
-
-       if (!hpd)
-               return result;
-
-       /* Setup HPD filtering */
-       if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
-               struct gpio_hpd_config config;
-
-               config.delay_on_connect = delay_on_connect_in_ms;
-               config.delay_on_disconnect = delay_on_disconnect_in_ms;
-
-               dal_irq_setup_hpd_filter(hpd, &config);
-
-               dal_gpio_close(hpd);
-
-               result = true;
-       } else {
-               ASSERT_CRITICAL(false);
-       }
-
-       /* Release HPD handle */
-       dal_gpio_destroy_irq(&hpd);
-
-       return result;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hpd.h b/drivers/gpu/drm/amd/display/dc/link/link_hpd.h
deleted file mode 100644 (file)
index 3d122de..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-
-
-#ifndef __DC_LINK_HPD_H__
-#define __DC_LINK_HPD_H__
-#include "link.h"
-
-enum hpd_source_id get_hpd_line(struct dc_link *link);
-/*
- *  Function: program_hpd_filter
- *
- *  @brief
- *     Programs HPD filter on associated HPD line to default values.
- *
- *  @return
- *     true on success, false otherwise
- */
-bool program_hpd_filter(const struct dc_link *link);
-/* Query hot plug status of USB4 DP tunnel.
- * Returns true if HPD high.
- */
-bool dpia_query_hpd_status(struct dc_link *link);
-bool query_hpd_status(struct dc_link *link, uint32_t *is_hpd_high);
-#endif /* __DC_LINK_HPD_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hwss_dio.c b/drivers/gpu/drm/amd/display/dc/link/link_hwss_dio.c
deleted file mode 100644 (file)
index 33148b7..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#include "link_hwss_dio.h"
-#include "core_types.h"
-#include "dc_link_dp.h"
-#include "link_enc_cfg.h"
-
-void set_dio_throttled_vcp_size(struct pipe_ctx *pipe_ctx,
-               struct fixed31_32 throttled_vcp_size)
-{
-       struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
-
-       stream_encoder->funcs->set_throttled_vcp_size(
-                               stream_encoder,
-                               throttled_vcp_size);
-}
-
-void setup_dio_stream_encoder(struct pipe_ctx *pipe_ctx)
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
-       struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
-
-       link_enc->funcs->connect_dig_be_to_fe(link_enc,
-                       pipe_ctx->stream_res.stream_enc->id, true);
-       if (dc_is_dp_signal(pipe_ctx->stream->signal))
-               dp_source_sequence_trace(pipe_ctx->stream->link,
-                               DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_BE);
-       if (stream_enc->funcs->enable_fifo)
-               stream_enc->funcs->enable_fifo(stream_enc);
-}
-
-void reset_dio_stream_encoder(struct pipe_ctx *pipe_ctx)
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
-       struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
-
-       if (stream_enc && stream_enc->funcs->disable_fifo)
-               stream_enc->funcs->disable_fifo(stream_enc);
-
-       link_enc->funcs->connect_dig_be_to_fe(
-                       link_enc,
-                       pipe_ctx->stream_res.stream_enc->id,
-                       false);
-       if (dc_is_dp_signal(pipe_ctx->stream->signal))
-               dp_source_sequence_trace(pipe_ctx->stream->link,
-                               DPCD_SOURCE_SEQ_AFTER_DISCONNECT_DIG_FE_BE);
-
-}
-
-void setup_dio_stream_attribute(struct pipe_ctx *pipe_ctx)
-{
-       struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
-       struct dc_stream_state *stream = pipe_ctx->stream;
-       struct dc_link *link = stream->link;
-
-       if (!dc_is_virtual_signal(stream->signal))
-               stream_encoder->funcs->setup_stereo_sync(
-                               stream_encoder,
-                               pipe_ctx->stream_res.tg->inst,
-                               stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
-
-       if (dc_is_dp_signal(stream->signal))
-               stream_encoder->funcs->dp_set_stream_attribute(
-                               stream_encoder,
-                               &stream->timing,
-                               stream->output_color_space,
-                               stream->use_vsc_sdp_for_colorimetry,
-                               link->dpcd_caps.dprx_feature.bits.SST_SPLIT_SDP_CAP);
-       else if (dc_is_hdmi_tmds_signal(stream->signal))
-               stream_encoder->funcs->hdmi_set_stream_attribute(
-                               stream_encoder,
-                               &stream->timing,
-                               stream->phy_pix_clk,
-                               pipe_ctx->stream_res.audio != NULL);
-       else if (dc_is_dvi_signal(stream->signal))
-               stream_encoder->funcs->dvi_set_stream_attribute(
-                               stream_encoder,
-                               &stream->timing,
-                               (stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
-                                               true : false);
-       else if (dc_is_lvds_signal(stream->signal))
-               stream_encoder->funcs->lvds_set_stream_attribute(
-                               stream_encoder,
-                               &stream->timing);
-
-       if (dc_is_dp_signal(stream->signal))
-               dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
-}
-
-void enable_dio_dp_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal,
-               enum clock_source_id clock_source,
-               const struct dc_link_settings *link_settings)
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
-
-       if (dc_is_dp_sst_signal(signal))
-               link_enc->funcs->enable_dp_output(
-                               link_enc,
-                               link_settings,
-                               clock_source);
-       else
-               link_enc->funcs->enable_dp_mst_output(
-                               link_enc,
-                               link_settings,
-                               clock_source);
-       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_ENABLE_LINK_PHY);
-}
-
-void disable_dio_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal)
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
-
-       link_enc->funcs->disable_output(link_enc, signal);
-       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
-}
-
-void set_dio_dp_link_test_pattern(struct dc_link *link,
-               const struct link_resource *link_res,
-               struct encoder_set_dp_phy_pattern_param *tp_params)
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
-
-       link_enc->funcs->dp_set_phy_pattern(link_enc, tp_params);
-       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN);
-}
-
-void set_dio_dp_lane_settings(struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct dc_link_settings *link_settings,
-               const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
-
-       link_enc->funcs->dp_set_lane_settings(link_enc, link_settings, lane_settings);
-}
-
-static void update_dio_stream_allocation_table(struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct link_mst_stream_allocation_table *table)
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
-
-       ASSERT(link_enc);
-       link_enc->funcs->update_mst_stream_allocation_table(link_enc, table);
-}
-
-void setup_dio_audio_output(struct pipe_ctx *pipe_ctx,
-               struct audio_output *audio_output, uint32_t audio_inst)
-{
-       if (dc_is_dp_signal(pipe_ctx->stream->signal))
-               pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
-                               pipe_ctx->stream_res.stream_enc,
-                               audio_inst,
-                               &pipe_ctx->stream->audio_info);
-       else
-               pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
-                               pipe_ctx->stream_res.stream_enc,
-                               audio_inst,
-                               &pipe_ctx->stream->audio_info,
-                               &audio_output->crtc_info);
-}
-
-void enable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
-{
-       if (dc_is_dp_signal(pipe_ctx->stream->signal))
-               pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(
-                               pipe_ctx->stream_res.stream_enc);
-
-       pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
-                       pipe_ctx->stream_res.stream_enc, false);
-
-       if (dc_is_dp_signal(pipe_ctx->stream->signal))
-               dp_source_sequence_trace(pipe_ctx->stream->link,
-                               DPCD_SOURCE_SEQ_AFTER_ENABLE_AUDIO_STREAM);
-}
-
-void disable_dio_audio_packet(struct pipe_ctx *pipe_ctx)
-{
-       pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
-                       pipe_ctx->stream_res.stream_enc, true);
-
-       if (pipe_ctx->stream_res.audio) {
-               if (dc_is_dp_signal(pipe_ctx->stream->signal))
-                       pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
-                                       pipe_ctx->stream_res.stream_enc);
-               else
-                       pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
-                                       pipe_ctx->stream_res.stream_enc);
-       }
-
-       if (dc_is_dp_signal(pipe_ctx->stream->signal))
-               dp_source_sequence_trace(pipe_ctx->stream->link,
-                               DPCD_SOURCE_SEQ_AFTER_DISABLE_AUDIO_STREAM);
-}
-
-static const struct link_hwss dio_link_hwss = {
-       .setup_stream_encoder = setup_dio_stream_encoder,
-       .reset_stream_encoder = reset_dio_stream_encoder,
-       .setup_stream_attribute = setup_dio_stream_attribute,
-       .disable_link_output = disable_dio_link_output,
-       .setup_audio_output = setup_dio_audio_output,
-       .enable_audio_packet = enable_dio_audio_packet,
-       .disable_audio_packet = disable_dio_audio_packet,
-       .ext = {
-               .set_throttled_vcp_size = set_dio_throttled_vcp_size,
-               .enable_dp_link_output = enable_dio_dp_link_output,
-               .set_dp_link_test_pattern = set_dio_dp_link_test_pattern,
-               .set_dp_lane_settings = set_dio_dp_lane_settings,
-               .update_stream_allocation_table = update_dio_stream_allocation_table,
-       },
-};
-
-bool can_use_dio_link_hwss(const struct dc_link *link,
-               const struct link_resource *link_res)
-{
-       return link->link_enc != NULL;
-}
-
-const struct link_hwss *get_dio_link_hwss(void)
-{
-       return &dio_link_hwss;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hwss_dio.h b/drivers/gpu/drm/amd/display/dc/link/link_hwss_dio.h
deleted file mode 100644 (file)
index 9a108c3..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#ifndef __LINK_HWSS_DIO_H__
-#define __LINK_HWSS_DIO_H__
-
-#include "link_hwss.h"
-
-const struct link_hwss *get_dio_link_hwss(void);
-bool can_use_dio_link_hwss(const struct dc_link *link,
-               const struct link_resource *link_res);
-void set_dio_throttled_vcp_size(struct pipe_ctx *pipe_ctx,
-               struct fixed31_32 throttled_vcp_size);
-void setup_dio_stream_encoder(struct pipe_ctx *pipe_ctx);
-void reset_dio_stream_encoder(struct pipe_ctx *pipe_ctx);
-void setup_dio_stream_attribute(struct pipe_ctx *pipe_ctx);
-void enable_dio_dp_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal,
-               enum clock_source_id clock_source,
-               const struct dc_link_settings *link_settings);
-void disable_dio_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal);
-void set_dio_dp_link_test_pattern(struct dc_link *link,
-               const struct link_resource *link_res,
-               struct encoder_set_dp_phy_pattern_param *tp_params);
-void set_dio_dp_lane_settings(struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct dc_link_settings *link_settings,
-               const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX]);
-void setup_dio_audio_output(struct pipe_ctx *pipe_ctx,
-               struct audio_output *audio_output, uint32_t audio_inst);
-void enable_dio_audio_packet(struct pipe_ctx *pipe_ctx);
-void disable_dio_audio_packet(struct pipe_ctx *pipe_ctx);
-
-#endif /* __LINK_HWSS_DIO_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hwss_dpia.c b/drivers/gpu/drm/amd/display/dc/link/link_hwss_dpia.c
deleted file mode 100644 (file)
index 861f3cd..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#include "link_hwss_dpia.h"
-#include "core_types.h"
-#include "link_hwss_dio.h"
-#include "link_enc_cfg.h"
-
-#define DC_LOGGER_INIT(logger)
-
-static void update_dpia_stream_allocation_table(struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct link_mst_stream_allocation_table *table)
-{
-       struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link);
-       static enum dc_status status;
-       uint8_t mst_alloc_slots = 0, prev_mst_slots_in_use = 0xFF;
-       int i;
-       DC_LOGGER_INIT(link->ctx->logger);
-
-       for (i = 0; i < table->stream_count; i++)
-               mst_alloc_slots += table->stream_allocations[i].slot_count;
-
-       status = dc_process_dmub_set_mst_slots(link->dc, link->link_index,
-                       mst_alloc_slots, &prev_mst_slots_in_use);
-       ASSERT(status == DC_OK);
-       DC_LOG_MST("dpia : status[%d]: alloc_slots[%d]: used_slots[%d]\n",
-                       status, mst_alloc_slots, prev_mst_slots_in_use);
-
-       ASSERT(link_enc);
-       link_enc->funcs->update_mst_stream_allocation_table(link_enc, table);
-}
-
-static const struct link_hwss dpia_link_hwss = {
-       .setup_stream_encoder = setup_dio_stream_encoder,
-       .reset_stream_encoder = reset_dio_stream_encoder,
-       .setup_stream_attribute = setup_dio_stream_attribute,
-       .disable_link_output = disable_dio_link_output,
-       .setup_audio_output = setup_dio_audio_output,
-       .enable_audio_packet = enable_dio_audio_packet,
-       .disable_audio_packet = disable_dio_audio_packet,
-       .ext = {
-               .set_throttled_vcp_size = set_dio_throttled_vcp_size,
-               .enable_dp_link_output = enable_dio_dp_link_output,
-               .set_dp_link_test_pattern = set_dio_dp_link_test_pattern,
-               .set_dp_lane_settings = set_dio_dp_lane_settings,
-               .update_stream_allocation_table = update_dpia_stream_allocation_table,
-       },
-};
-
-bool can_use_dpia_link_hwss(const struct dc_link *link,
-               const struct link_resource *link_res)
-{
-       return link->is_dig_mapping_flexible &&
-                       link->dc->res_pool->funcs->link_encs_assign;
-}
-
-const struct link_hwss *get_dpia_link_hwss(void)
-{
-       return &dpia_link_hwss;
-}
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hwss_dpia.h b/drivers/gpu/drm/amd/display/dc/link/link_hwss_dpia.h
deleted file mode 100644 (file)
index ad16ec5..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#ifndef __LINK_HWSS_DPIA_H__
-#define __LINK_HWSS_DPIA_H__
-
-#include "link_hwss.h"
-
-const struct link_hwss *get_dpia_link_hwss(void);
-bool can_use_dpia_link_hwss(const struct dc_link *link,
-               const struct link_resource *link_res);
-
-#endif /* __LINK_HWSS_DPIA_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_dp.c b/drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_dp.c
deleted file mode 100644 (file)
index 164d631..0000000
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#include "link_hwss_hpo_dp.h"
-#include "dm_helpers.h"
-#include "core_types.h"
-#include "dccg.h"
-#include "dc_link_dp.h"
-#include "clk_mgr.h"
-
-static enum phyd32clk_clock_source get_phyd32clk_src(struct dc_link *link)
-{
-       switch (link->link_enc->transmitter) {
-       case TRANSMITTER_UNIPHY_A:
-               return PHYD32CLKA;
-       case TRANSMITTER_UNIPHY_B:
-               return PHYD32CLKB;
-       case TRANSMITTER_UNIPHY_C:
-               return PHYD32CLKC;
-       case TRANSMITTER_UNIPHY_D:
-               return PHYD32CLKD;
-       case TRANSMITTER_UNIPHY_E:
-               return PHYD32CLKE;
-       default:
-               return PHYD32CLKA;
-       }
-}
-
-static void set_hpo_dp_throttled_vcp_size(struct pipe_ctx *pipe_ctx,
-               struct fixed31_32 throttled_vcp_size)
-{
-       struct hpo_dp_stream_encoder *hpo_dp_stream_encoder =
-                       pipe_ctx->stream_res.hpo_dp_stream_enc;
-       struct hpo_dp_link_encoder *hpo_dp_link_encoder =
-                       pipe_ctx->link_res.hpo_dp_link_enc;
-
-       hpo_dp_link_encoder->funcs->set_throttled_vcp_size(hpo_dp_link_encoder,
-                       hpo_dp_stream_encoder->inst,
-                       throttled_vcp_size);
-}
-
-static void set_hpo_dp_hblank_min_symbol_width(struct pipe_ctx *pipe_ctx,
-               const struct dc_link_settings *link_settings,
-               struct fixed31_32 throttled_vcp_size)
-{
-       struct hpo_dp_stream_encoder *hpo_dp_stream_encoder =
-                       pipe_ctx->stream_res.hpo_dp_stream_enc;
-       struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
-       struct fixed31_32 h_blank_in_ms, time_slot_in_ms, mtp_cnt_per_h_blank;
-       uint32_t link_bw_in_kbps =
-                       dc_link_bandwidth_kbps(pipe_ctx->stream->link, link_settings);
-       uint16_t hblank_min_symbol_width = 0;
-
-       if (link_bw_in_kbps > 0) {
-               h_blank_in_ms = dc_fixpt_div(dc_fixpt_from_int(
-                               timing->h_total - timing->h_addressable),
-                               dc_fixpt_from_fraction(timing->pix_clk_100hz, 10));
-               time_slot_in_ms = dc_fixpt_from_fraction(32 * 4, link_bw_in_kbps);
-               mtp_cnt_per_h_blank = dc_fixpt_div(h_blank_in_ms,
-                               dc_fixpt_mul_int(time_slot_in_ms, 64));
-               hblank_min_symbol_width = dc_fixpt_floor(
-                               dc_fixpt_mul(mtp_cnt_per_h_blank, throttled_vcp_size));
-       }
-
-       hpo_dp_stream_encoder->funcs->set_hblank_min_symbol_width(hpo_dp_stream_encoder,
-                       hblank_min_symbol_width);
-}
-
-static void setup_hpo_dp_stream_encoder(struct pipe_ctx *pipe_ctx)
-{
-       struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
-       struct hpo_dp_link_encoder *link_enc = pipe_ctx->link_res.hpo_dp_link_enc;
-
-       stream_enc->funcs->enable_stream(stream_enc);
-       stream_enc->funcs->map_stream_to_link(stream_enc, stream_enc->inst, link_enc->inst);
-}
-
-static void reset_hpo_dp_stream_encoder(struct pipe_ctx *pipe_ctx)
-{
-       struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
-
-       stream_enc->funcs->disable(stream_enc);
-}
-
-static void setup_hpo_dp_stream_attribute(struct pipe_ctx *pipe_ctx)
-{
-       struct hpo_dp_stream_encoder *stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
-       struct dc_stream_state *stream = pipe_ctx->stream;
-       struct dc_link *link = stream->link;
-
-       stream_enc->funcs->set_stream_attribute(
-                       stream_enc,
-                       &stream->timing,
-                       stream->output_color_space,
-                       stream->use_vsc_sdp_for_colorimetry,
-                       stream->timing.flags.DSC,
-                       false);
-       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DP_STREAM_ATTR);
-}
-
-static void enable_hpo_dp_fpga_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal,
-               enum clock_source_id clock_source,
-               const struct dc_link_settings *link_settings)
-{
-       const struct dc *dc = link->dc;
-       enum phyd32clk_clock_source phyd32clk = get_phyd32clk_src(link);
-       int phyd32clk_freq_khz = link_settings->link_rate == LINK_RATE_UHBR10 ? 312500 :
-                       link_settings->link_rate == LINK_RATE_UHBR13_5 ? 412875 :
-                       link_settings->link_rate == LINK_RATE_UHBR20 ? 625000 : 0;
-
-       dm_set_phyd32clk(dc->ctx, phyd32clk_freq_khz);
-       dc->res_pool->dccg->funcs->set_physymclk(
-                       dc->res_pool->dccg,
-                       link->link_enc_hw_inst,
-                       PHYSYMCLK_FORCE_SRC_PHYD32CLK,
-                       true);
-       dc->res_pool->dccg->funcs->enable_symclk32_le(
-                       dc->res_pool->dccg,
-                       link_res->hpo_dp_link_enc->inst,
-                       phyd32clk);
-       link_res->hpo_dp_link_enc->funcs->link_enable(
-                       link_res->hpo_dp_link_enc,
-                       link_settings->lane_count);
-
-}
-
-static void enable_hpo_dp_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal,
-               enum clock_source_id clock_source,
-               const struct dc_link_settings *link_settings)
-{
-       if (IS_FPGA_MAXIMUS_DC(link->dc->ctx->dce_environment))
-               enable_hpo_dp_fpga_link_output(link, link_res, signal,
-                               clock_source, link_settings);
-       else
-               link_res->hpo_dp_link_enc->funcs->enable_link_phy(
-                               link_res->hpo_dp_link_enc,
-                               link_settings,
-                               link->link_enc->transmitter,
-                               link->link_enc->hpd_source);
-}
-
-
-static void disable_hpo_dp_fpga_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal)
-{
-       const struct dc *dc = link->dc;
-
-       link_res->hpo_dp_link_enc->funcs->link_disable(link_res->hpo_dp_link_enc);
-       dc->res_pool->dccg->funcs->disable_symclk32_le(
-                       dc->res_pool->dccg,
-                       link_res->hpo_dp_link_enc->inst);
-       dc->res_pool->dccg->funcs->set_physymclk(
-                       dc->res_pool->dccg,
-                       link->link_enc_hw_inst,
-                       PHYSYMCLK_FORCE_SRC_SYMCLK,
-                       false);
-       dm_set_phyd32clk(dc->ctx, 0);
-}
-
-static void disable_hpo_dp_link_output(struct dc_link *link,
-               const struct link_resource *link_res,
-               enum signal_type signal)
-{
-       if (IS_FPGA_MAXIMUS_DC(link->dc->ctx->dce_environment)) {
-               disable_hpo_dp_fpga_link_output(link, link_res, signal);
-       } else {
-               link_res->hpo_dp_link_enc->funcs->link_disable(link_res->hpo_dp_link_enc);
-               link_res->hpo_dp_link_enc->funcs->disable_link_phy(
-                               link_res->hpo_dp_link_enc, signal);
-       }
-}
-
-static void set_hpo_dp_link_test_pattern(struct dc_link *link,
-               const struct link_resource *link_res,
-               struct encoder_set_dp_phy_pattern_param *tp_params)
-{
-       link_res->hpo_dp_link_enc->funcs->set_link_test_pattern(
-                       link_res->hpo_dp_link_enc, tp_params);
-       dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN);
-}
-
-static void set_hpo_dp_lane_settings(struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct dc_link_settings *link_settings,
-               const struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
-{
-       link_res->hpo_dp_link_enc->funcs->set_ffe(
-                       link_res->hpo_dp_link_enc,
-                       link_settings,
-                       lane_settings[0].FFE_PRESET.raw);
-}
-
-static void update_hpo_dp_stream_allocation_table(struct dc_link *link,
-               const struct link_resource *link_res,
-               const struct link_mst_stream_allocation_table *table)
-{
-       link_res->hpo_dp_link_enc->funcs->update_stream_allocation_table(
-                       link_res->hpo_dp_link_enc,
-                       table);
-}
-
-static void setup_hpo_dp_audio_output(struct pipe_ctx *pipe_ctx,
-               struct audio_output *audio_output, uint32_t audio_inst)
-{
-       pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_setup(
-                       pipe_ctx->stream_res.hpo_dp_stream_enc,
-                       audio_inst,
-                       &pipe_ctx->stream->audio_info);
-}
-
-static void enable_hpo_dp_audio_packet(struct pipe_ctx *pipe_ctx)
-{
-       pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_enable(
-                       pipe_ctx->stream_res.hpo_dp_stream_enc);
-}
-
-static void disable_hpo_dp_audio_packet(struct pipe_ctx *pipe_ctx)
-{
-       if (pipe_ctx->stream_res.audio)
-               pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_disable(
-                               pipe_ctx->stream_res.hpo_dp_stream_enc);
-}
-
-static const struct link_hwss hpo_dp_link_hwss = {
-       .setup_stream_encoder = setup_hpo_dp_stream_encoder,
-       .reset_stream_encoder = reset_hpo_dp_stream_encoder,
-       .setup_stream_attribute = setup_hpo_dp_stream_attribute,
-       .disable_link_output = disable_hpo_dp_link_output,
-       .setup_audio_output = setup_hpo_dp_audio_output,
-       .enable_audio_packet = enable_hpo_dp_audio_packet,
-       .disable_audio_packet = disable_hpo_dp_audio_packet,
-       .ext = {
-               .set_throttled_vcp_size = set_hpo_dp_throttled_vcp_size,
-               .set_hblank_min_symbol_width = set_hpo_dp_hblank_min_symbol_width,
-               .enable_dp_link_output = enable_hpo_dp_link_output,
-               .set_dp_link_test_pattern  = set_hpo_dp_link_test_pattern,
-               .set_dp_lane_settings = set_hpo_dp_lane_settings,
-               .update_stream_allocation_table = update_hpo_dp_stream_allocation_table,
-       },
-};
-
-bool can_use_hpo_dp_link_hwss(const struct dc_link *link,
-               const struct link_resource *link_res)
-{
-       return link_res->hpo_dp_link_enc != NULL;
-}
-
-const struct link_hwss *get_hpo_dp_link_hwss(void)
-{
-       return &hpo_dp_link_hwss;
-}
-
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_dp.h b/drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_dp.h
deleted file mode 100644 (file)
index 57d447e..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#ifndef __LINK_HWSS_HPO_DP_H__
-#define __LINK_HWSS_HPO_DP_H__
-
-#include "link_hwss.h"
-
-bool can_use_hpo_dp_link_hwss(const struct dc_link *link,
-               const struct link_resource *link_res);
-const struct link_hwss *get_hpo_dp_link_hwss(void);
-
-
-#endif /* __LINK_HWSS_HPO_DP_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_frl.h b/drivers/gpu/drm/amd/display/dc/link/link_hwss_hpo_frl.h
deleted file mode 100644 (file)
index ea8d976..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2022 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors: AMD
- *
- */
-#ifndef __LINK_HWSS_HPO_FRL_H__
-#define __LINK_HWSS_HPO_FRL_H__
-
-#include "link_hwss.h"
-
-bool can_use_hpo_frl_link_hwss(const struct dc_link *link,
-               const struct link_resource *link_res);
-const struct link_hwss *get_hpo_frl_link_hwss(void);
-
-#endif /* __LINK_HWSS_HPO_FRL_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_ddc.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_ddc.c
new file mode 100644 (file)
index 0000000..5269125
--- /dev/null
@@ -0,0 +1,515 @@
+/*
+ * Copyright 2012-15 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ *
+ * This file implements generic display communication protocols such as i2c, aux
+ * and scdc. The file should not contain any specific applications of these
+ * protocols such as display capability query, detection, or handshaking such as
+ * link training.
+ */
+#include "link_ddc.h"
+#include "vector.h"
+#include "dce/dce_aux.h"
+#include "dal_asic_id.h"
+#include "link_dpcd.h"
+#include "dm_helpers.h"
+#include "atomfirmware.h"
+
+#define DC_LOGGER_INIT(logger)
+
+static const uint8_t DP_VGA_DONGLE_BRANCH_DEV_NAME[] = "DpVga";
+/* DP to Dual link DVI converter */
+static const uint8_t DP_DVI_CONVERTER_ID_4[] = "m2DVIa";
+static const uint8_t DP_DVI_CONVERTER_ID_5[] = "3393N2";
+
+struct i2c_payloads {
+       struct vector payloads;
+};
+
+struct aux_payloads {
+       struct vector payloads;
+};
+
+static bool dal_ddc_i2c_payloads_create(
+               struct dc_context *ctx,
+               struct i2c_payloads *payloads,
+               uint32_t count)
+{
+       if (dal_vector_construct(
+               &payloads->payloads, ctx, count, sizeof(struct i2c_payload)))
+               return true;
+
+       return false;
+}
+
+static struct i2c_payload *dal_ddc_i2c_payloads_get(struct i2c_payloads *p)
+{
+       return (struct i2c_payload *)p->payloads.container;
+}
+
+static uint32_t dal_ddc_i2c_payloads_get_count(struct i2c_payloads *p)
+{
+       return p->payloads.count;
+}
+
+#define DDC_MIN(a, b) (((a) < (b)) ? (a) : (b))
+
+static void i2c_payloads_add(
+       struct i2c_payloads *payloads,
+       uint32_t address,
+       uint32_t len,
+       uint8_t *data,
+       bool write)
+{
+       uint32_t payload_size = EDID_SEGMENT_SIZE;
+       uint32_t pos;
+
+       for (pos = 0; pos < len; pos += payload_size) {
+               struct i2c_payload payload = {
+                       .write = write,
+                       .address = address,
+                       .length = DDC_MIN(payload_size, len - pos),
+                       .data = data + pos };
+               dal_vector_append(&payloads->payloads, &payload);
+       }
+
+}
+
+static void ddc_service_construct(
+       struct ddc_service *ddc_service,
+       struct ddc_service_init_data *init_data)
+{
+       enum connector_id connector_id =
+               dal_graphics_object_id_get_connector_id(init_data->id);
+
+       struct gpio_service *gpio_service = init_data->ctx->gpio_service;
+       struct graphics_object_i2c_info i2c_info;
+       struct gpio_ddc_hw_info hw_info;
+       struct dc_bios *dcb = init_data->ctx->dc_bios;
+
+       ddc_service->link = init_data->link;
+       ddc_service->ctx = init_data->ctx;
+
+       if (init_data->is_dpia_link ||
+           dcb->funcs->get_i2c_info(dcb, init_data->id, &i2c_info) != BP_RESULT_OK) {
+               ddc_service->ddc_pin = NULL;
+       } else {
+               DC_LOGGER_INIT(ddc_service->ctx->logger);
+               DC_LOG_DC("BIOS object table - i2c_line: %d", i2c_info.i2c_line);
+               DC_LOG_DC("BIOS object table - i2c_engine_id: %d", i2c_info.i2c_engine_id);
+
+               hw_info.ddc_channel = i2c_info.i2c_line;
+               if (ddc_service->link != NULL)
+                       hw_info.hw_supported = i2c_info.i2c_hw_assist;
+               else
+                       hw_info.hw_supported = false;
+
+               ddc_service->ddc_pin = dal_gpio_create_ddc(
+                       gpio_service,
+                       i2c_info.gpio_info.clk_a_register_index,
+                       1 << i2c_info.gpio_info.clk_a_shift,
+                       &hw_info);
+       }
+
+       ddc_service->flags.EDID_QUERY_DONE_ONCE = false;
+       ddc_service->flags.FORCE_READ_REPEATED_START = false;
+       ddc_service->flags.EDID_STRESS_READ = false;
+
+       ddc_service->flags.IS_INTERNAL_DISPLAY =
+               connector_id == CONNECTOR_ID_EDP ||
+               connector_id == CONNECTOR_ID_LVDS;
+
+       ddc_service->wa.raw = 0;
+}
+
+struct ddc_service *link_create_ddc_service(
+       struct ddc_service_init_data *init_data)
+{
+       struct ddc_service *ddc_service;
+
+       ddc_service = kzalloc(sizeof(struct ddc_service), GFP_KERNEL);
+
+       if (!ddc_service)
+               return NULL;
+
+       ddc_service_construct(ddc_service, init_data);
+       return ddc_service;
+}
+
+static void ddc_service_destruct(struct ddc_service *ddc)
+{
+       if (ddc->ddc_pin)
+               dal_gpio_destroy_ddc(&ddc->ddc_pin);
+}
+
+void link_destroy_ddc_service(struct ddc_service **ddc)
+{
+       if (!ddc || !*ddc) {
+               BREAK_TO_DEBUGGER();
+               return;
+       }
+       ddc_service_destruct(*ddc);
+       kfree(*ddc);
+       *ddc = NULL;
+}
+
+void set_ddc_transaction_type(
+       struct ddc_service *ddc,
+       enum ddc_transaction_type type)
+{
+       ddc->transaction_type = type;
+}
+
+bool link_is_in_aux_transaction_mode(struct ddc_service *ddc)
+{
+       switch (ddc->transaction_type) {
+       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX:
+       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_WITH_DEFER:
+       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_RETRY_DEFER:
+               return true;
+       default:
+               break;
+       }
+       return false;
+}
+
+void set_dongle_type(struct ddc_service *ddc,
+               enum display_dongle_type dongle_type)
+{
+       ddc->dongle_type = dongle_type;
+}
+
+static uint32_t defer_delay_converter_wa(
+       struct ddc_service *ddc,
+       uint32_t defer_delay)
+{
+       struct dc_link *link = ddc->link;
+
+       if (link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_VGA_CONVERTER &&
+               link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_0080E1 &&
+               (link->dpcd_caps.branch_fw_revision[0] < 0x01 ||
+                               (link->dpcd_caps.branch_fw_revision[0] == 0x01 &&
+                               link->dpcd_caps.branch_fw_revision[1] < 0x40)) &&
+               !memcmp(link->dpcd_caps.branch_dev_name,
+                   DP_VGA_DONGLE_BRANCH_DEV_NAME,
+                       sizeof(link->dpcd_caps.branch_dev_name)))
+
+               return defer_delay > DPVGA_DONGLE_AUX_DEFER_WA_DELAY ?
+                       defer_delay : DPVGA_DONGLE_AUX_DEFER_WA_DELAY;
+
+       if (link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_0080E1 &&
+           !memcmp(link->dpcd_caps.branch_dev_name,
+                   DP_DVI_CONVERTER_ID_4,
+                   sizeof(link->dpcd_caps.branch_dev_name)))
+               return defer_delay > I2C_OVER_AUX_DEFER_WA_DELAY ?
+                       defer_delay : I2C_OVER_AUX_DEFER_WA_DELAY;
+       if (link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_006037 &&
+           !memcmp(link->dpcd_caps.branch_dev_name,
+                   DP_DVI_CONVERTER_ID_5,
+                   sizeof(link->dpcd_caps.branch_dev_name)))
+               return defer_delay > I2C_OVER_AUX_DEFER_WA_DELAY_1MS ?
+                       I2C_OVER_AUX_DEFER_WA_DELAY_1MS : defer_delay;
+
+       return defer_delay;
+}
+
+#define DP_TRANSLATOR_DELAY 5
+
+uint32_t link_get_aux_defer_delay(struct ddc_service *ddc)
+{
+       uint32_t defer_delay = 0;
+
+       switch (ddc->transaction_type) {
+       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX:
+               if ((DISPLAY_DONGLE_DP_VGA_CONVERTER == ddc->dongle_type) ||
+                       (DISPLAY_DONGLE_DP_DVI_CONVERTER == ddc->dongle_type) ||
+                       (DISPLAY_DONGLE_DP_HDMI_CONVERTER ==
+                               ddc->dongle_type)) {
+
+                       defer_delay = DP_TRANSLATOR_DELAY;
+
+                       defer_delay =
+                               defer_delay_converter_wa(ddc, defer_delay);
+
+               } else /*sink has a delay different from an Active Converter*/
+                       defer_delay = 0;
+               break;
+       case DDC_TRANSACTION_TYPE_I2C_OVER_AUX_WITH_DEFER:
+               defer_delay = DP_TRANSLATOR_DELAY;
+               break;
+       default:
+               break;
+       }
+       return defer_delay;
+}
+
+static bool submit_aux_command(struct ddc_service *ddc,
+               struct aux_payload *payload)
+{
+       uint32_t retrieved = 0;
+       bool ret = false;
+
+       if (!ddc)
+               return false;
+
+       if (!payload)
+               return false;
+
+       do {
+               struct aux_payload current_payload;
+               bool is_end_of_payload = (retrieved + DEFAULT_AUX_MAX_DATA_SIZE) >=
+                               payload->length;
+               uint32_t payload_length = is_end_of_payload ?
+                               payload->length - retrieved : DEFAULT_AUX_MAX_DATA_SIZE;
+
+               current_payload.address = payload->address;
+               current_payload.data = &payload->data[retrieved];
+               current_payload.defer_delay = payload->defer_delay;
+               current_payload.i2c_over_aux = payload->i2c_over_aux;
+               current_payload.length = payload_length;
+               /* set mot (middle of transaction) to false if it is the last payload */
+               current_payload.mot = is_end_of_payload ? payload->mot:true;
+               current_payload.write_status_update = false;
+               current_payload.reply = payload->reply;
+               current_payload.write = payload->write;
+
+               ret = link_aux_transfer_with_retries_no_mutex(ddc, &current_payload);
+
+               retrieved += payload_length;
+       } while (retrieved < payload->length && ret == true);
+
+       return ret;
+}
+
+bool link_query_ddc_data(
+       struct ddc_service *ddc,
+       uint32_t address,
+       uint8_t *write_buf,
+       uint32_t write_size,
+       uint8_t *read_buf,
+       uint32_t read_size)
+{
+       bool success = true;
+       uint32_t payload_size =
+               link_is_in_aux_transaction_mode(ddc) ?
+                       DEFAULT_AUX_MAX_DATA_SIZE : EDID_SEGMENT_SIZE;
+
+       uint32_t write_payloads =
+               (write_size + payload_size - 1) / payload_size;
+
+       uint32_t read_payloads =
+               (read_size + payload_size - 1) / payload_size;
+
+       uint32_t payloads_num = write_payloads + read_payloads;
+
+       if (!payloads_num)
+               return false;
+
+       if (link_is_in_aux_transaction_mode(ddc)) {
+               struct aux_payload payload;
+
+               payload.i2c_over_aux = true;
+               payload.address = address;
+               payload.reply = NULL;
+               payload.defer_delay = link_get_aux_defer_delay(ddc);
+               payload.write_status_update = false;
+
+               if (write_size != 0) {
+                       payload.write = true;
+                       /* should not set mot (middle of transaction) to 0
+                        * if there are pending read payloads
+                        */
+                       payload.mot = !(read_size == 0);
+                       payload.length = write_size;
+                       payload.data = write_buf;
+
+                       success = submit_aux_command(ddc, &payload);
+               }
+
+               if (read_size != 0 && success) {
+                       payload.write = false;
+                       /* should set mot (middle of transaction) to 0
+                        * since it is the last payload to send
+                        */
+                       payload.mot = false;
+                       payload.length = read_size;
+                       payload.data = read_buf;
+
+                       success = submit_aux_command(ddc, &payload);
+               }
+       } else {
+               struct i2c_command command = {0};
+               struct i2c_payloads payloads;
+
+               if (!dal_ddc_i2c_payloads_create(ddc->ctx, &payloads, payloads_num))
+                       return false;
+
+               command.payloads = dal_ddc_i2c_payloads_get(&payloads);
+               command.number_of_payloads = 0;
+               command.engine = DDC_I2C_COMMAND_ENGINE;
+               command.speed = ddc->ctx->dc->caps.i2c_speed_in_khz;
+
+               i2c_payloads_add(
+                       &payloads, address, write_size, write_buf, true);
+
+               i2c_payloads_add(
+                       &payloads, address, read_size, read_buf, false);
+
+               command.number_of_payloads =
+                       dal_ddc_i2c_payloads_get_count(&payloads);
+
+               success = dm_helpers_submit_i2c(
+                               ddc->ctx,
+                               ddc->link,
+                               &command);
+
+               dal_vector_destruct(&payloads.payloads);
+       }
+
+       return success;
+}
+
+int dc_link_aux_transfer_raw(struct ddc_service *ddc,
+               struct aux_payload *payload,
+               enum aux_return_code_type *operation_result)
+{
+       if (ddc->ctx->dc->debug.enable_dmub_aux_for_legacy_ddc ||
+           !ddc->ddc_pin) {
+               return dce_aux_transfer_dmub_raw(ddc, payload, operation_result);
+       } else {
+               return dce_aux_transfer_raw(ddc, payload, operation_result);
+       }
+}
+
+bool link_aux_transfer_with_retries_no_mutex(struct ddc_service *ddc,
+               struct aux_payload *payload)
+{
+       return dce_aux_transfer_with_retries(ddc, payload);
+}
+
+
+bool try_to_configure_aux_timeout(struct ddc_service *ddc,
+               uint32_t timeout)
+{
+       bool result = false;
+       struct ddc *ddc_pin = ddc->ddc_pin;
+
+       if ((ddc->link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
+                       !ddc->link->dc->debug.disable_fixed_vs_aux_timeout_wa &&
+                       ASICREV_IS_YELLOW_CARP(ddc->ctx->asic_id.hw_internal_rev)) {
+               /* Fixed VS workaround for AUX timeout */
+               const uint32_t fixed_vs_address = 0xF004F;
+               const uint8_t fixed_vs_data[4] = {0x1, 0x22, 0x63, 0xc};
+
+               core_link_write_dpcd(ddc->link,
+                               fixed_vs_address,
+                               fixed_vs_data,
+                               sizeof(fixed_vs_data));
+
+               timeout = 3072;
+       }
+
+       /* Do not try to access nonexistent DDC pin. */
+       if (ddc->link->ep_type != DISPLAY_ENDPOINT_PHY)
+               return true;
+
+       if (ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]->funcs->configure_timeout) {
+               ddc->ctx->dc->res_pool->engines[ddc_pin->pin_data->en]->funcs->configure_timeout(ddc, timeout);
+               result = true;
+       }
+
+       return result;
+}
+
+struct ddc *get_ddc_pin(struct ddc_service *ddc_service)
+{
+       return ddc_service->ddc_pin;
+}
+
+void write_scdc_data(struct ddc_service *ddc_service,
+               uint32_t pix_clk,
+               bool lte_340_scramble)
+{
+       bool over_340_mhz = pix_clk > 340000 ? 1 : 0;
+       uint8_t slave_address = HDMI_SCDC_ADDRESS;
+       uint8_t offset = HDMI_SCDC_SINK_VERSION;
+       uint8_t sink_version = 0;
+       uint8_t write_buffer[2] = {0};
+       /*Lower than 340 Scramble bit from SCDC caps*/
+
+       if (ddc_service->link->local_sink &&
+               ddc_service->link->local_sink->edid_caps.panel_patch.skip_scdc_overwrite)
+               return;
+
+       link_query_ddc_data(ddc_service, slave_address, &offset,
+                       sizeof(offset), &sink_version, sizeof(sink_version));
+       if (sink_version == 1) {
+               /*Source Version = 1*/
+               write_buffer[0] = HDMI_SCDC_SOURCE_VERSION;
+               write_buffer[1] = 1;
+               link_query_ddc_data(ddc_service, slave_address,
+                               write_buffer, sizeof(write_buffer), NULL, 0);
+               /*Read Request from SCDC caps*/
+       }
+       write_buffer[0] = HDMI_SCDC_TMDS_CONFIG;
+
+       if (over_340_mhz) {
+               write_buffer[1] = 3;
+       } else if (lte_340_scramble) {
+               write_buffer[1] = 1;
+       } else {
+               write_buffer[1] = 0;
+       }
+       link_query_ddc_data(ddc_service, slave_address, write_buffer,
+                       sizeof(write_buffer), NULL, 0);
+}
+
+void read_scdc_data(struct ddc_service *ddc_service)
+{
+       uint8_t slave_address = HDMI_SCDC_ADDRESS;
+       uint8_t offset = HDMI_SCDC_TMDS_CONFIG;
+       uint8_t tmds_config = 0;
+
+       if (ddc_service->link->local_sink &&
+               ddc_service->link->local_sink->edid_caps.panel_patch.skip_scdc_overwrite)
+               return;
+
+       link_query_ddc_data(ddc_service, slave_address, &offset,
+                       sizeof(offset), &tmds_config, sizeof(tmds_config));
+       if (tmds_config & 0x1) {
+               union hdmi_scdc_status_flags_data status_data = {0};
+               uint8_t scramble_status = 0;
+
+               offset = HDMI_SCDC_SCRAMBLER_STATUS;
+               link_query_ddc_data(ddc_service, slave_address,
+                               &offset, sizeof(offset), &scramble_status,
+                               sizeof(scramble_status));
+               offset = HDMI_SCDC_STATUS_FLAGS;
+               link_query_ddc_data(ddc_service, slave_address,
+                               &offset, sizeof(offset), &status_data.byte,
+                               sizeof(status_data.byte));
+       }
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_ddc.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_ddc.h
new file mode 100644 (file)
index 0000000..86e9d2e
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012-15 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#ifndef __DAL_DDC_SERVICE_H__
+#define __DAL_DDC_SERVICE_H__
+
+#include "link.h"
+
+#define AUX_POWER_UP_WA_DELAY 500
+#define I2C_OVER_AUX_DEFER_WA_DELAY 70
+#define DPVGA_DONGLE_AUX_DEFER_WA_DELAY 40
+#define I2C_OVER_AUX_DEFER_WA_DELAY_1MS 1
+#define LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD 3200 /*us*/
+
+#define EDID_SEGMENT_SIZE 256
+
+void set_ddc_transaction_type(
+               struct ddc_service *ddc,
+               enum ddc_transaction_type type);
+
+bool try_to_configure_aux_timeout(struct ddc_service *ddc,
+               uint32_t timeout);
+
+void write_scdc_data(
+               struct ddc_service *ddc_service,
+               uint32_t pix_clk,
+               bool lte_340_scramble);
+
+void read_scdc_data(
+               struct ddc_service *ddc_service);
+
+void set_dongle_type(struct ddc_service *ddc,
+               enum display_dongle_type dongle_type);
+
+struct ddc *get_ddc_pin(struct ddc_service *ddc_service);
+
+#endif /* __DAL_DDC_SERVICE_H__ */
+
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.c
new file mode 100644 (file)
index 0000000..ccc0638
--- /dev/null
@@ -0,0 +1,2169 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ * This file implements dp specific link capability retrieval sequence. It is
+ * responsible for retrieving, parsing, overriding, deciding capability obtained
+ * from dp link. Link capability consists of encoders, DPRXs, cables, retimers,
+ * usb and all other possible backend capabilities. Other components should
+ * include this header file in order to access link capability. Accessing link
+ * capability by dereferencing dc_link outside dp_link_capability is not a
+ * recommended method as it makes the component dependent on the underlying data
+ * structure used to represent link capability instead of function interfaces.
+ */
+
+#include "link_dp_capability.h"
+#include "link_ddc.h"
+#include "link_dpcd.h"
+#include "link_dp_dpia.h"
+#include "link_dp_phy.h"
+#include "link/accessories/link_dp_trace.h"
+#include "link_dp_training.h"
+#include "atomfirmware.h"
+#include "resource.h"
+#include "link_enc_cfg.h"
+#include "dc_link_dp.h"
+#include "dc_dmub_srv.h"
+
+#define DC_LOGGER \
+       link->ctx->logger
+#define DC_TRACE_LEVEL_MESSAGE(...) /* do nothing */
+
+#ifndef MAX
+#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+#endif
+#ifndef MIN
+#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
+#endif
+
+#define LINK_AUX_DEFAULT_TIMEOUT_PERIOD 552 /*us*/
+
+struct dp_lt_fallback_entry {
+       enum dc_lane_count lane_count;
+       enum dc_link_rate link_rate;
+};
+
+static const struct dp_lt_fallback_entry dp_lt_fallbacks[] = {
+               /* This link training fallback array is ordered by
+                * link bandwidth from highest to lowest.
+                * DP specs makes it a normative policy to always
+                * choose the next highest link bandwidth during
+                * link training fallback.
+                */
+               {LANE_COUNT_FOUR, LINK_RATE_UHBR20},
+               {LANE_COUNT_FOUR, LINK_RATE_UHBR13_5},
+               {LANE_COUNT_TWO, LINK_RATE_UHBR20},
+               {LANE_COUNT_FOUR, LINK_RATE_UHBR10},
+               {LANE_COUNT_TWO, LINK_RATE_UHBR13_5},
+               {LANE_COUNT_FOUR, LINK_RATE_HIGH3},
+               {LANE_COUNT_ONE, LINK_RATE_UHBR20},
+               {LANE_COUNT_TWO, LINK_RATE_UHBR10},
+               {LANE_COUNT_FOUR, LINK_RATE_HIGH2},
+               {LANE_COUNT_ONE, LINK_RATE_UHBR13_5},
+               {LANE_COUNT_TWO, LINK_RATE_HIGH3},
+               {LANE_COUNT_ONE, LINK_RATE_UHBR10},
+               {LANE_COUNT_TWO, LINK_RATE_HIGH2},
+               {LANE_COUNT_FOUR, LINK_RATE_HIGH},
+               {LANE_COUNT_ONE, LINK_RATE_HIGH3},
+               {LANE_COUNT_FOUR, LINK_RATE_LOW},
+               {LANE_COUNT_ONE, LINK_RATE_HIGH2},
+               {LANE_COUNT_TWO, LINK_RATE_HIGH},
+               {LANE_COUNT_TWO, LINK_RATE_LOW},
+               {LANE_COUNT_ONE, LINK_RATE_HIGH},
+               {LANE_COUNT_ONE, LINK_RATE_LOW},
+};
+
+static const struct dc_link_settings fail_safe_link_settings = {
+               .lane_count = LANE_COUNT_ONE,
+               .link_rate = LINK_RATE_LOW,
+               .link_spread = LINK_SPREAD_DISABLED,
+};
+
+bool is_dp_active_dongle(const struct dc_link *link)
+{
+       return (link->dpcd_caps.dongle_type >= DISPLAY_DONGLE_DP_VGA_CONVERTER) &&
+                               (link->dpcd_caps.dongle_type <= DISPLAY_DONGLE_DP_HDMI_CONVERTER);
+}
+
+bool is_dp_branch_device(const struct dc_link *link)
+{
+       return link->dpcd_caps.is_branch_dev;
+}
+
+static int translate_dpcd_max_bpc(enum dpcd_downstream_port_max_bpc bpc)
+{
+       switch (bpc) {
+       case DOWN_STREAM_MAX_8BPC:
+               return 8;
+       case DOWN_STREAM_MAX_10BPC:
+               return 10;
+       case DOWN_STREAM_MAX_12BPC:
+               return 12;
+       case DOWN_STREAM_MAX_16BPC:
+               return 16;
+       default:
+               break;
+       }
+
+       return -1;
+}
+
+uint8_t dp_parse_lttpr_repeater_count(uint8_t lttpr_repeater_count)
+{
+       switch (lttpr_repeater_count) {
+       case 0x80: // 1 lttpr repeater
+               return 1;
+       case 0x40: // 2 lttpr repeaters
+               return 2;
+       case 0x20: // 3 lttpr repeaters
+               return 3;
+       case 0x10: // 4 lttpr repeaters
+               return 4;
+       case 0x08: // 5 lttpr repeaters
+               return 5;
+       case 0x04: // 6 lttpr repeaters
+               return 6;
+       case 0x02: // 7 lttpr repeaters
+               return 7;
+       case 0x01: // 8 lttpr repeaters
+               return 8;
+       default:
+               break;
+       }
+       return 0; // invalid value
+}
+
+uint32_t dc_link_bw_kbps_from_raw_frl_link_rate_data(uint8_t bw)
+{
+       switch (bw) {
+       case 0b001:
+               return 9000000;
+       case 0b010:
+               return 18000000;
+       case 0b011:
+               return 24000000;
+       case 0b100:
+               return 32000000;
+       case 0b101:
+               return 40000000;
+       case 0b110:
+               return 48000000;
+       }
+
+       return 0;
+}
+
+static enum dc_link_rate linkRateInKHzToLinkRateMultiplier(uint32_t link_rate_in_khz)
+{
+       enum dc_link_rate link_rate;
+       // LinkRate is normally stored as a multiplier of 0.27 Gbps per lane. Do the translation.
+       switch (link_rate_in_khz) {
+       case 1620000:
+               link_rate = LINK_RATE_LOW;      // Rate_1 (RBR) - 1.62 Gbps/Lane
+               break;
+       case 2160000:
+               link_rate = LINK_RATE_RATE_2;   // Rate_2       - 2.16 Gbps/Lane
+               break;
+       case 2430000:
+               link_rate = LINK_RATE_RATE_3;   // Rate_3       - 2.43 Gbps/Lane
+               break;
+       case 2700000:
+               link_rate = LINK_RATE_HIGH;     // Rate_4 (HBR) - 2.70 Gbps/Lane
+               break;
+       case 3240000:
+               link_rate = LINK_RATE_RBR2;     // Rate_5 (RBR2)- 3.24 Gbps/Lane
+               break;
+       case 4320000:
+               link_rate = LINK_RATE_RATE_6;   // Rate_6       - 4.32 Gbps/Lane
+               break;
+       case 5400000:
+               link_rate = LINK_RATE_HIGH2;    // Rate_7 (HBR2)- 5.40 Gbps/Lane
+               break;
+       case 8100000:
+               link_rate = LINK_RATE_HIGH3;    // Rate_8 (HBR3)- 8.10 Gbps/Lane
+               break;
+       default:
+               link_rate = LINK_RATE_UNKNOWN;
+               break;
+       }
+       return link_rate;
+}
+
+static union dp_cable_id intersect_cable_id(
+               union dp_cable_id *a, union dp_cable_id *b)
+{
+       union dp_cable_id out;
+
+       out.bits.UHBR10_20_CAPABILITY = MIN(a->bits.UHBR10_20_CAPABILITY,
+                       b->bits.UHBR10_20_CAPABILITY);
+       out.bits.UHBR13_5_CAPABILITY = MIN(a->bits.UHBR13_5_CAPABILITY,
+                       b->bits.UHBR13_5_CAPABILITY);
+       out.bits.CABLE_TYPE = MAX(a->bits.CABLE_TYPE, b->bits.CABLE_TYPE);
+
+       return out;
+}
+
+/*
+ * Return PCON's post FRL link training supported BW if its non-zero, otherwise return max_supported_frl_bw.
+ */
+static uint32_t intersect_frl_link_bw_support(
+       const uint32_t max_supported_frl_bw_in_kbps,
+       const union hdmi_encoded_link_bw hdmi_encoded_link_bw)
+{
+       uint32_t supported_bw_in_kbps = max_supported_frl_bw_in_kbps;
+
+       // HDMI_ENCODED_LINK_BW bits are only valid if HDMI Link Configuration bit is 1 (FRL mode)
+       if (hdmi_encoded_link_bw.bits.FRL_MODE) {
+               if (hdmi_encoded_link_bw.bits.BW_48Gbps)
+                       supported_bw_in_kbps = 48000000;
+               else if (hdmi_encoded_link_bw.bits.BW_40Gbps)
+                       supported_bw_in_kbps = 40000000;
+               else if (hdmi_encoded_link_bw.bits.BW_32Gbps)
+                       supported_bw_in_kbps = 32000000;
+               else if (hdmi_encoded_link_bw.bits.BW_24Gbps)
+                       supported_bw_in_kbps = 24000000;
+               else if (hdmi_encoded_link_bw.bits.BW_18Gbps)
+                       supported_bw_in_kbps = 18000000;
+               else if (hdmi_encoded_link_bw.bits.BW_9Gbps)
+                       supported_bw_in_kbps = 9000000;
+       }
+
+       return supported_bw_in_kbps;
+}
+
+static enum clock_source_id get_clock_source_id(struct dc_link *link)
+{
+       enum clock_source_id dp_cs_id = CLOCK_SOURCE_ID_UNDEFINED;
+       struct clock_source *dp_cs = link->dc->res_pool->dp_clock_source;
+
+       if (dp_cs != NULL) {
+               dp_cs_id = dp_cs->id;
+       } else {
+               /*
+                * dp clock source is not initialized for some reason.
+                * Should not happen, CLOCK_SOURCE_ID_EXTERNAL will be used
+                */
+               ASSERT(dp_cs);
+       }
+
+       return dp_cs_id;
+}
+
+static void dp_wa_power_up_0010FA(struct dc_link *link, uint8_t *dpcd_data,
+               int length)
+{
+       int retry = 0;
+       union dp_downstream_port_present ds_port = { 0 };
+
+       if (!link->dpcd_caps.dpcd_rev.raw) {
+               do {
+                       dc_link_dp_receiver_power_ctrl(link, true);
+                       core_link_read_dpcd(link, DP_DPCD_REV,
+                                                       dpcd_data, length);
+                       link->dpcd_caps.dpcd_rev.raw = dpcd_data[
+                               DP_DPCD_REV -
+                               DP_DPCD_REV];
+               } while (retry++ < 4 && !link->dpcd_caps.dpcd_rev.raw);
+       }
+
+       ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
+                                DP_DPCD_REV];
+
+       if (link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_VGA_CONVERTER) {
+               switch (link->dpcd_caps.branch_dev_id) {
+               /* 0010FA active dongles (DP-VGA, DP-DLDVI converters) power down
+                * all internal circuits including AUX communication preventing
+                * reading DPCD table and EDID (spec violation).
+                * Encoder will skip DP RX power down on disable_output to
+                * keep receiver powered all the time.*/
+               case DP_BRANCH_DEVICE_ID_0010FA:
+               case DP_BRANCH_DEVICE_ID_0080E1:
+               case DP_BRANCH_DEVICE_ID_00E04C:
+                       link->wa_flags.dp_keep_receiver_powered = true;
+                       break;
+
+               /* TODO: May need work around for other dongles. */
+               default:
+                       link->wa_flags.dp_keep_receiver_powered = false;
+                       break;
+               }
+       } else
+               link->wa_flags.dp_keep_receiver_powered = false;
+}
+
+bool dc_link_is_fec_supported(const struct dc_link *link)
+{
+       /* TODO - use asic cap instead of link_enc->features
+        * we no longer know which link enc to use for this link before commit
+        */
+       struct link_encoder *link_enc = NULL;
+
+       link_enc = link_enc_cfg_get_link_enc(link);
+       ASSERT(link_enc);
+
+       return (dc_is_dp_signal(link->connector_signal) && link_enc &&
+                       link_enc->features.fec_supported &&
+                       link->dpcd_caps.fec_cap.bits.FEC_CAPABLE &&
+                       !IS_FPGA_MAXIMUS_DC(link->ctx->dce_environment));
+}
+
+bool dc_link_should_enable_fec(const struct dc_link *link)
+{
+       bool force_disable = false;
+
+       if (link->fec_state == dc_link_fec_enabled)
+               force_disable = false;
+       else if (link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT_MST &&
+                       link->local_sink &&
+                       link->local_sink->edid_caps.panel_patch.disable_fec)
+               force_disable = true;
+       else if (link->connector_signal == SIGNAL_TYPE_EDP
+                       && (link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.
+                        dsc_support.DSC_SUPPORT == false
+                               || link->panel_config.dsc.disable_dsc_edp
+                               || !link->dc->caps.edp_dsc_support))
+               force_disable = true;
+
+       return !force_disable && dc_link_is_fec_supported(link);
+}
+
+bool link_is_dp_128b_132b_signal(struct pipe_ctx *pipe_ctx)
+{
+       /* If this assert is hit then we have a link encoder dynamic management issue */
+       ASSERT(pipe_ctx->stream_res.hpo_dp_stream_enc ? pipe_ctx->link_res.hpo_dp_link_enc != NULL : true);
+       return (pipe_ctx->stream_res.hpo_dp_stream_enc &&
+                       pipe_ctx->link_res.hpo_dp_link_enc &&
+                       dc_is_dp_signal(pipe_ctx->stream->signal));
+}
+
+bool dp_is_lttpr_present(struct dc_link *link)
+{
+       return (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) != 0 &&
+                       link->dpcd_caps.lttpr_caps.max_lane_count > 0 &&
+                       link->dpcd_caps.lttpr_caps.max_lane_count <= 4 &&
+                       link->dpcd_caps.lttpr_caps.revision.raw >= 0x14);
+}
+
+/* in DP compliance test, DPR-120 may have
+ * a random value in its MAX_LINK_BW dpcd field.
+ * We map it to the maximum supported link rate that
+ * is smaller than MAX_LINK_BW in this case.
+ */
+static enum dc_link_rate get_link_rate_from_max_link_bw(
+                uint8_t max_link_bw)
+{
+       enum dc_link_rate link_rate;
+
+       if (max_link_bw >= LINK_RATE_HIGH3) {
+               link_rate = LINK_RATE_HIGH3;
+       } else if (max_link_bw < LINK_RATE_HIGH3
+                       && max_link_bw >= LINK_RATE_HIGH2) {
+               link_rate = LINK_RATE_HIGH2;
+       } else if (max_link_bw < LINK_RATE_HIGH2
+                       && max_link_bw >= LINK_RATE_HIGH) {
+               link_rate = LINK_RATE_HIGH;
+       } else if (max_link_bw < LINK_RATE_HIGH
+                       && max_link_bw >= LINK_RATE_LOW) {
+               link_rate = LINK_RATE_LOW;
+       } else {
+               link_rate = LINK_RATE_UNKNOWN;
+       }
+
+       return link_rate;
+}
+
+static enum dc_link_rate get_lttpr_max_link_rate(struct dc_link *link)
+{
+       enum dc_link_rate lttpr_max_link_rate = link->dpcd_caps.lttpr_caps.max_link_rate;
+
+       if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR20)
+               lttpr_max_link_rate = LINK_RATE_UHBR20;
+       else if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR13_5)
+               lttpr_max_link_rate = LINK_RATE_UHBR13_5;
+       else if (link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.bits.UHBR10)
+               lttpr_max_link_rate = LINK_RATE_UHBR10;
+
+       return lttpr_max_link_rate;
+}
+
+static enum dc_link_rate get_cable_max_link_rate(struct dc_link *link)
+{
+       enum dc_link_rate cable_max_link_rate = LINK_RATE_UNKNOWN;
+
+       if (link->dpcd_caps.cable_id.bits.UHBR10_20_CAPABILITY & DP_UHBR20)
+               cable_max_link_rate = LINK_RATE_UHBR20;
+       else if (link->dpcd_caps.cable_id.bits.UHBR13_5_CAPABILITY)
+               cable_max_link_rate = LINK_RATE_UHBR13_5;
+       else if (link->dpcd_caps.cable_id.bits.UHBR10_20_CAPABILITY & DP_UHBR10)
+               cable_max_link_rate = LINK_RATE_UHBR10;
+
+       return cable_max_link_rate;
+}
+
+static inline bool reached_minimum_lane_count(enum dc_lane_count lane_count)
+{
+       return lane_count <= LANE_COUNT_ONE;
+}
+
+static inline bool reached_minimum_link_rate(enum dc_link_rate link_rate)
+{
+       return link_rate <= LINK_RATE_LOW;
+}
+
+static enum dc_lane_count reduce_lane_count(enum dc_lane_count lane_count)
+{
+       switch (lane_count) {
+       case LANE_COUNT_FOUR:
+               return LANE_COUNT_TWO;
+       case LANE_COUNT_TWO:
+               return LANE_COUNT_ONE;
+       case LANE_COUNT_ONE:
+               return LANE_COUNT_UNKNOWN;
+       default:
+               return LANE_COUNT_UNKNOWN;
+       }
+}
+
+static enum dc_link_rate reduce_link_rate(enum dc_link_rate link_rate)
+{
+       switch (link_rate) {
+       case LINK_RATE_UHBR20:
+               return LINK_RATE_UHBR13_5;
+       case LINK_RATE_UHBR13_5:
+               return LINK_RATE_UHBR10;
+       case LINK_RATE_UHBR10:
+               return LINK_RATE_HIGH3;
+       case LINK_RATE_HIGH3:
+               return LINK_RATE_HIGH2;
+       case LINK_RATE_HIGH2:
+               return LINK_RATE_HIGH;
+       case LINK_RATE_HIGH:
+               return LINK_RATE_LOW;
+       case LINK_RATE_LOW:
+               return LINK_RATE_UNKNOWN;
+       default:
+               return LINK_RATE_UNKNOWN;
+       }
+}
+
+static enum dc_lane_count increase_lane_count(enum dc_lane_count lane_count)
+{
+       switch (lane_count) {
+       case LANE_COUNT_ONE:
+               return LANE_COUNT_TWO;
+       case LANE_COUNT_TWO:
+               return LANE_COUNT_FOUR;
+       default:
+               return LANE_COUNT_UNKNOWN;
+       }
+}
+
+static enum dc_link_rate increase_link_rate(struct dc_link *link,
+               enum dc_link_rate link_rate)
+{
+       switch (link_rate) {
+       case LINK_RATE_LOW:
+               return LINK_RATE_HIGH;
+       case LINK_RATE_HIGH:
+               return LINK_RATE_HIGH2;
+       case LINK_RATE_HIGH2:
+               return LINK_RATE_HIGH3;
+       case LINK_RATE_HIGH3:
+               return LINK_RATE_UHBR10;
+       case LINK_RATE_UHBR10:
+               /* upto DP2.x specs UHBR13.5 is the only link rate that could be
+                * not supported by DPRX when higher link rate is supported.
+                * so we treat it as a special case for code simplicity. When we
+                * have new specs with more link rates like this, we should
+                * consider a more generic solution to handle discrete link
+                * rate capabilities.
+                */
+               return link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5 ?
+                               LINK_RATE_UHBR13_5 : LINK_RATE_UHBR20;
+       case LINK_RATE_UHBR13_5:
+               return LINK_RATE_UHBR20;
+       default:
+               return LINK_RATE_UNKNOWN;
+       }
+}
+
+static bool decide_fallback_link_setting_max_bw_policy(
+               struct dc_link *link,
+               const struct dc_link_settings *max,
+               struct dc_link_settings *cur,
+               enum link_training_result training_result)
+{
+       uint8_t cur_idx = 0, next_idx;
+       bool found = false;
+
+       if (training_result == LINK_TRAINING_ABORT)
+               return false;
+
+       while (cur_idx < ARRAY_SIZE(dp_lt_fallbacks))
+               /* find current index */
+               if (dp_lt_fallbacks[cur_idx].lane_count == cur->lane_count &&
+                               dp_lt_fallbacks[cur_idx].link_rate == cur->link_rate)
+                       break;
+               else
+                       cur_idx++;
+
+       next_idx = cur_idx + 1;
+
+       while (next_idx < ARRAY_SIZE(dp_lt_fallbacks))
+               /* find next index */
+               if (dp_lt_fallbacks[next_idx].lane_count > max->lane_count ||
+                               dp_lt_fallbacks[next_idx].link_rate > max->link_rate)
+                       next_idx++;
+               else if (dp_lt_fallbacks[next_idx].link_rate == LINK_RATE_UHBR13_5 &&
+                               link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5 == 0)
+                       /* upto DP2.x specs UHBR13.5 is the only link rate that
+                        * could be not supported by DPRX when higher link rate
+                        * is supported. so we treat it as a special case for
+                        * code simplicity. When we have new specs with more
+                        * link rates like this, we should consider a more
+                        * generic solution to handle discrete link rate
+                        * capabilities.
+                        */
+                       next_idx++;
+               else
+                       break;
+
+       if (next_idx < ARRAY_SIZE(dp_lt_fallbacks)) {
+               cur->lane_count = dp_lt_fallbacks[next_idx].lane_count;
+               cur->link_rate = dp_lt_fallbacks[next_idx].link_rate;
+               found = true;
+       }
+
+       return found;
+}
+
+/*
+ * function: set link rate and lane count fallback based
+ * on current link setting and last link training result
+ * return value:
+ *                     true - link setting could be set
+ *                     false - has reached minimum setting
+ *                                     and no further fallback could be done
+ */
+bool decide_fallback_link_setting(
+               struct dc_link *link,
+               struct dc_link_settings *max,
+               struct dc_link_settings *cur,
+               enum link_training_result training_result)
+{
+       if (link_dp_get_encoding_format(max) == DP_128b_132b_ENCODING ||
+                       link->dc->debug.force_dp2_lt_fallback_method)
+               return decide_fallback_link_setting_max_bw_policy(link, max,
+                               cur, training_result);
+
+       switch (training_result) {
+       case LINK_TRAINING_CR_FAIL_LANE0:
+       case LINK_TRAINING_CR_FAIL_LANE1:
+       case LINK_TRAINING_CR_FAIL_LANE23:
+       case LINK_TRAINING_LQA_FAIL:
+       {
+               if (!reached_minimum_link_rate(cur->link_rate)) {
+                       cur->link_rate = reduce_link_rate(cur->link_rate);
+               } else if (!reached_minimum_lane_count(cur->lane_count)) {
+                       cur->link_rate = max->link_rate;
+                       if (training_result == LINK_TRAINING_CR_FAIL_LANE0)
+                               return false;
+                       else if (training_result == LINK_TRAINING_CR_FAIL_LANE1)
+                               cur->lane_count = LANE_COUNT_ONE;
+                       else if (training_result == LINK_TRAINING_CR_FAIL_LANE23)
+                               cur->lane_count = LANE_COUNT_TWO;
+                       else
+                               cur->lane_count = reduce_lane_count(cur->lane_count);
+               } else {
+                       return false;
+               }
+               break;
+       }
+       case LINK_TRAINING_EQ_FAIL_EQ:
+       case LINK_TRAINING_EQ_FAIL_CR_PARTIAL:
+       {
+               if (!reached_minimum_lane_count(cur->lane_count)) {
+                       cur->lane_count = reduce_lane_count(cur->lane_count);
+               } else if (!reached_minimum_link_rate(cur->link_rate)) {
+                       cur->link_rate = reduce_link_rate(cur->link_rate);
+                       /* Reduce max link rate to avoid potential infinite loop.
+                        * Needed so that any subsequent CR_FAIL fallback can't
+                        * re-set the link rate higher than the link rate from
+                        * the latest EQ_FAIL fallback.
+                        */
+                       max->link_rate = cur->link_rate;
+                       cur->lane_count = max->lane_count;
+               } else {
+                       return false;
+               }
+               break;
+       }
+       case LINK_TRAINING_EQ_FAIL_CR:
+       {
+               if (!reached_minimum_link_rate(cur->link_rate)) {
+                       cur->link_rate = reduce_link_rate(cur->link_rate);
+                       /* Reduce max link rate to avoid potential infinite loop.
+                        * Needed so that any subsequent CR_FAIL fallback can't
+                        * re-set the link rate higher than the link rate from
+                        * the latest EQ_FAIL fallback.
+                        */
+                       max->link_rate = cur->link_rate;
+                       cur->lane_count = max->lane_count;
+               } else {
+                       return false;
+               }
+               break;
+       }
+       default:
+               return false;
+       }
+       return true;
+}
+static bool decide_dp_link_settings(struct dc_link *link, struct dc_link_settings *link_setting, uint32_t req_bw)
+{
+       struct dc_link_settings initial_link_setting = {
+               LANE_COUNT_ONE, LINK_RATE_LOW, LINK_SPREAD_DISABLED, false, 0};
+       struct dc_link_settings current_link_setting =
+                       initial_link_setting;
+       uint32_t link_bw;
+
+       if (req_bw > dc_link_bandwidth_kbps(link, &link->verified_link_cap))
+               return false;
+
+       /* search for the minimum link setting that:
+        * 1. is supported according to the link training result
+        * 2. could support the b/w requested by the timing
+        */
+       while (current_link_setting.link_rate <=
+                       link->verified_link_cap.link_rate) {
+               link_bw = dc_link_bandwidth_kbps(
+                               link,
+                               &current_link_setting);
+               if (req_bw <= link_bw) {
+                       *link_setting = current_link_setting;
+                       return true;
+               }
+
+               if (current_link_setting.lane_count <
+                               link->verified_link_cap.lane_count) {
+                       current_link_setting.lane_count =
+                                       increase_lane_count(
+                                                       current_link_setting.lane_count);
+               } else {
+                       current_link_setting.link_rate =
+                                       increase_link_rate(link,
+                                                       current_link_setting.link_rate);
+                       current_link_setting.lane_count =
+                                       initial_link_setting.lane_count;
+               }
+       }
+
+       return false;
+}
+
+bool dc_link_decide_edp_link_settings(struct dc_link *link, struct dc_link_settings *link_setting, uint32_t req_bw)
+{
+       struct dc_link_settings initial_link_setting;
+       struct dc_link_settings current_link_setting;
+       uint32_t link_bw;
+
+       /*
+        * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
+        * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
+        */
+       if (link->dpcd_caps.dpcd_rev.raw < DPCD_REV_13 ||
+                       link->dpcd_caps.edp_supported_link_rates_count == 0) {
+               *link_setting = link->verified_link_cap;
+               return true;
+       }
+
+       memset(&initial_link_setting, 0, sizeof(initial_link_setting));
+       initial_link_setting.lane_count = LANE_COUNT_ONE;
+       initial_link_setting.link_rate = link->dpcd_caps.edp_supported_link_rates[0];
+       initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
+       initial_link_setting.use_link_rate_set = true;
+       initial_link_setting.link_rate_set = 0;
+       current_link_setting = initial_link_setting;
+
+       /* search for the minimum link setting that:
+        * 1. is supported according to the link training result
+        * 2. could support the b/w requested by the timing
+        */
+       while (current_link_setting.link_rate <=
+                       link->verified_link_cap.link_rate) {
+               link_bw = dc_link_bandwidth_kbps(
+                               link,
+                               &current_link_setting);
+               if (req_bw <= link_bw) {
+                       *link_setting = current_link_setting;
+                       return true;
+               }
+
+               if (current_link_setting.lane_count <
+                               link->verified_link_cap.lane_count) {
+                       current_link_setting.lane_count =
+                                       increase_lane_count(
+                                                       current_link_setting.lane_count);
+               } else {
+                       if (current_link_setting.link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
+                               current_link_setting.link_rate_set++;
+                               current_link_setting.link_rate =
+                                       link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
+                               current_link_setting.lane_count =
+                                                                       initial_link_setting.lane_count;
+                       } else
+                               break;
+               }
+       }
+       return false;
+}
+
+bool decide_edp_link_settings_with_dsc(struct dc_link *link,
+               struct dc_link_settings *link_setting,
+               uint32_t req_bw,
+               enum dc_link_rate max_link_rate)
+{
+       struct dc_link_settings initial_link_setting;
+       struct dc_link_settings current_link_setting;
+       uint32_t link_bw;
+
+       unsigned int policy = 0;
+
+       policy = link->panel_config.dsc.force_dsc_edp_policy;
+       if (max_link_rate == LINK_RATE_UNKNOWN)
+               max_link_rate = link->verified_link_cap.link_rate;
+       /*
+        * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
+        * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
+        */
+       if ((link->dpcd_caps.dpcd_rev.raw < DPCD_REV_13 ||
+                       link->dpcd_caps.edp_supported_link_rates_count == 0)) {
+               /* for DSC enabled case, we search for minimum lane count */
+               memset(&initial_link_setting, 0, sizeof(initial_link_setting));
+               initial_link_setting.lane_count = LANE_COUNT_ONE;
+               initial_link_setting.link_rate = LINK_RATE_LOW;
+               initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
+               initial_link_setting.use_link_rate_set = false;
+               initial_link_setting.link_rate_set = 0;
+               current_link_setting = initial_link_setting;
+               if (req_bw > dc_link_bandwidth_kbps(link, &link->verified_link_cap))
+                       return false;
+
+               /* search for the minimum link setting that:
+                * 1. is supported according to the link training result
+                * 2. could support the b/w requested by the timing
+                */
+               while (current_link_setting.link_rate <=
+                               max_link_rate) {
+                       link_bw = dc_link_bandwidth_kbps(
+                                       link,
+                                       &current_link_setting);
+                       if (req_bw <= link_bw) {
+                               *link_setting = current_link_setting;
+                               return true;
+                       }
+                       if (policy) {
+                               /* minimize lane */
+                               if (current_link_setting.link_rate < max_link_rate) {
+                                       current_link_setting.link_rate =
+                                                       increase_link_rate(link,
+                                                                       current_link_setting.link_rate);
+                               } else {
+                                       if (current_link_setting.lane_count <
+                                                                       link->verified_link_cap.lane_count) {
+                                               current_link_setting.lane_count =
+                                                               increase_lane_count(
+                                                                               current_link_setting.lane_count);
+                                               current_link_setting.link_rate = initial_link_setting.link_rate;
+                                       } else
+                                               break;
+                               }
+                       } else {
+                               /* minimize link rate */
+                               if (current_link_setting.lane_count <
+                                               link->verified_link_cap.lane_count) {
+                                       current_link_setting.lane_count =
+                                                       increase_lane_count(
+                                                                       current_link_setting.lane_count);
+                               } else {
+                                       current_link_setting.link_rate =
+                                                       increase_link_rate(link,
+                                                                       current_link_setting.link_rate);
+                                       current_link_setting.lane_count =
+                                                       initial_link_setting.lane_count;
+                               }
+                       }
+               }
+               return false;
+       }
+
+       /* if optimize edp link is supported */
+       memset(&initial_link_setting, 0, sizeof(initial_link_setting));
+       initial_link_setting.lane_count = LANE_COUNT_ONE;
+       initial_link_setting.link_rate = link->dpcd_caps.edp_supported_link_rates[0];
+       initial_link_setting.link_spread = LINK_SPREAD_DISABLED;
+       initial_link_setting.use_link_rate_set = true;
+       initial_link_setting.link_rate_set = 0;
+       current_link_setting = initial_link_setting;
+
+       /* search for the minimum link setting that:
+        * 1. is supported according to the link training result
+        * 2. could support the b/w requested by the timing
+        */
+       while (current_link_setting.link_rate <=
+                       max_link_rate) {
+               link_bw = dc_link_bandwidth_kbps(
+                               link,
+                               &current_link_setting);
+               if (req_bw <= link_bw) {
+                       *link_setting = current_link_setting;
+                       return true;
+               }
+               if (policy) {
+                       /* minimize lane */
+                       if (current_link_setting.link_rate_set <
+                                       link->dpcd_caps.edp_supported_link_rates_count
+                                       && current_link_setting.link_rate < max_link_rate) {
+                               current_link_setting.link_rate_set++;
+                               current_link_setting.link_rate =
+                                       link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
+                       } else {
+                               if (current_link_setting.lane_count < link->verified_link_cap.lane_count) {
+                                       current_link_setting.lane_count =
+                                                       increase_lane_count(
+                                                                       current_link_setting.lane_count);
+                                       current_link_setting.link_rate_set = initial_link_setting.link_rate_set;
+                                       current_link_setting.link_rate =
+                                               link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
+                               } else
+                                       break;
+                       }
+               } else {
+                       /* minimize link rate */
+                       if (current_link_setting.lane_count <
+                                       link->verified_link_cap.lane_count) {
+                               current_link_setting.lane_count =
+                                               increase_lane_count(
+                                                               current_link_setting.lane_count);
+                       } else {
+                               if (current_link_setting.link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) {
+                                       current_link_setting.link_rate_set++;
+                                       current_link_setting.link_rate =
+                                               link->dpcd_caps.edp_supported_link_rates[current_link_setting.link_rate_set];
+                                       current_link_setting.lane_count =
+                                               initial_link_setting.lane_count;
+                               } else
+                                       break;
+                       }
+               }
+       }
+       return false;
+}
+
+static bool decide_mst_link_settings(const struct dc_link *link, struct dc_link_settings *link_setting)
+{
+       *link_setting = link->verified_link_cap;
+       return true;
+}
+
+bool link_decide_link_settings(struct dc_stream_state *stream,
+       struct dc_link_settings *link_setting)
+{
+       struct dc_link *link = stream->link;
+       uint32_t req_bw = dc_bandwidth_in_kbps_from_timing(&stream->timing);
+
+       memset(link_setting, 0, sizeof(*link_setting));
+
+       /* if preferred is specified through AMDDP, use it, if it's enough
+        * to drive the mode
+        */
+       if (link->preferred_link_setting.lane_count !=
+                       LANE_COUNT_UNKNOWN &&
+                       link->preferred_link_setting.link_rate !=
+                                       LINK_RATE_UNKNOWN) {
+               *link_setting = link->preferred_link_setting;
+               return true;
+       }
+
+       /* MST doesn't perform link training for now
+        * TODO: add MST specific link training routine
+        */
+       if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
+               decide_mst_link_settings(link, link_setting);
+       } else if (link->connector_signal == SIGNAL_TYPE_EDP) {
+               /* enable edp link optimization for DSC eDP case */
+               if (stream->timing.flags.DSC) {
+                       enum dc_link_rate max_link_rate = LINK_RATE_UNKNOWN;
+
+                       if (link->panel_config.dsc.force_dsc_edp_policy) {
+                               /* calculate link max link rate cap*/
+                               struct dc_link_settings tmp_link_setting;
+                               struct dc_crtc_timing tmp_timing = stream->timing;
+                               uint32_t orig_req_bw;
+
+                               tmp_link_setting.link_rate = LINK_RATE_UNKNOWN;
+                               tmp_timing.flags.DSC = 0;
+                               orig_req_bw = dc_bandwidth_in_kbps_from_timing(&tmp_timing);
+                               dc_link_decide_edp_link_settings(link, &tmp_link_setting, orig_req_bw);
+                               max_link_rate = tmp_link_setting.link_rate;
+                       }
+                       decide_edp_link_settings_with_dsc(link, link_setting, req_bw, max_link_rate);
+               } else {
+                       dc_link_decide_edp_link_settings(link, link_setting, req_bw);
+               }
+       } else {
+               decide_dp_link_settings(link, link_setting, req_bw);
+       }
+
+       return link_setting->lane_count != LANE_COUNT_UNKNOWN &&
+                       link_setting->link_rate != LINK_RATE_UNKNOWN;
+}
+
+enum dp_link_encoding link_dp_get_encoding_format(const struct dc_link_settings *link_settings)
+{
+       if ((link_settings->link_rate >= LINK_RATE_LOW) &&
+                       (link_settings->link_rate <= LINK_RATE_HIGH3))
+               return DP_8b_10b_ENCODING;
+       else if ((link_settings->link_rate >= LINK_RATE_UHBR10) &&
+                       (link_settings->link_rate <= LINK_RATE_UHBR20))
+               return DP_128b_132b_ENCODING;
+       return DP_UNKNOWN_ENCODING;
+}
+
+enum dp_link_encoding dc_link_dp_mst_decide_link_encoding_format(const struct dc_link *link)
+{
+       struct dc_link_settings link_settings = {0};
+
+       if (!dc_is_dp_signal(link->connector_signal))
+               return DP_UNKNOWN_ENCODING;
+
+       if (link->preferred_link_setting.lane_count !=
+                       LANE_COUNT_UNKNOWN &&
+                       link->preferred_link_setting.link_rate !=
+                                       LINK_RATE_UNKNOWN) {
+               link_settings = link->preferred_link_setting;
+       } else {
+               decide_mst_link_settings(link, &link_settings);
+       }
+
+       return link_dp_get_encoding_format(&link_settings);
+}
+
+static void read_dp_device_vendor_id(struct dc_link *link)
+{
+       struct dp_device_vendor_id dp_id;
+
+       /* read IEEE branch device id */
+       core_link_read_dpcd(
+               link,
+               DP_BRANCH_OUI,
+               (uint8_t *)&dp_id,
+               sizeof(dp_id));
+
+       link->dpcd_caps.branch_dev_id =
+               (dp_id.ieee_oui[0] << 16) +
+               (dp_id.ieee_oui[1] << 8) +
+               dp_id.ieee_oui[2];
+
+       memmove(
+               link->dpcd_caps.branch_dev_name,
+               dp_id.ieee_device_id,
+               sizeof(dp_id.ieee_device_id));
+}
+
+static enum dc_status wake_up_aux_channel(struct dc_link *link)
+{
+       enum dc_status status = DC_ERROR_UNEXPECTED;
+       uint32_t aux_channel_retry_cnt = 0;
+       uint8_t dpcd_power_state = '\0';
+
+       while (status != DC_OK && aux_channel_retry_cnt < 10) {
+               status = core_link_read_dpcd(link, DP_SET_POWER,
+                               &dpcd_power_state, sizeof(dpcd_power_state));
+
+               /* Delay 1 ms if AUX CH is in power down state. Based on spec
+                * section 2.3.1.2, if AUX CH may be powered down due to
+                * write to DPCD 600h = 2. Sink AUX CH is monitoring differential
+                * signal and may need up to 1 ms before being able to reply.
+                */
+               if (status != DC_OK || dpcd_power_state == DP_SET_POWER_D3) {
+                       udelay(1000);
+                       aux_channel_retry_cnt++;
+               }
+       }
+
+       if (status != DC_OK) {
+               dpcd_power_state = DP_SET_POWER_D0;
+               status = core_link_write_dpcd(
+                               link,
+                               DP_SET_POWER,
+                               &dpcd_power_state,
+                               sizeof(dpcd_power_state));
+
+               dpcd_power_state = DP_SET_POWER_D3;
+               status = core_link_write_dpcd(
+                               link,
+                               DP_SET_POWER,
+                               &dpcd_power_state,
+                               sizeof(dpcd_power_state));
+               return DC_ERROR_UNEXPECTED;
+       }
+
+       return DC_OK;
+}
+
+static void get_active_converter_info(
+       uint8_t data, struct dc_link *link)
+{
+       union dp_downstream_port_present ds_port = { .byte = data };
+       memset(&link->dpcd_caps.dongle_caps, 0, sizeof(link->dpcd_caps.dongle_caps));
+
+       /* decode converter info*/
+       if (!ds_port.fields.PORT_PRESENT) {
+               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
+               set_dongle_type(link->ddc,
+                               link->dpcd_caps.dongle_type);
+               link->dpcd_caps.is_branch_dev = false;
+               return;
+       }
+
+       /* DPCD 0x5 bit 0 = 1, it indicate it's branch device */
+       link->dpcd_caps.is_branch_dev = ds_port.fields.PORT_PRESENT;
+
+       switch (ds_port.fields.PORT_TYPE) {
+       case DOWNSTREAM_VGA:
+               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_VGA_CONVERTER;
+               break;
+       case DOWNSTREAM_DVI_HDMI_DP_PLUS_PLUS:
+               /* At this point we don't know is it DVI or HDMI or DP++,
+                * assume DVI.*/
+               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_DP_DVI_CONVERTER;
+               break;
+       default:
+               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
+               break;
+       }
+
+       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_11) {
+               uint8_t det_caps[16]; /* CTS 4.2.2.7 expects source to read Detailed Capabilities Info : 00080h-0008F.*/
+               union dwnstream_port_caps_byte0 *port_caps =
+                       (union dwnstream_port_caps_byte0 *)det_caps;
+               if (core_link_read_dpcd(link, DP_DOWNSTREAM_PORT_0,
+                               det_caps, sizeof(det_caps)) == DC_OK) {
+
+                       switch (port_caps->bits.DWN_STRM_PORTX_TYPE) {
+                       /*Handle DP case as DONGLE_NONE*/
+                       case DOWN_STREAM_DETAILED_DP:
+                               link->dpcd_caps.dongle_type = DISPLAY_DONGLE_NONE;
+                               break;
+                       case DOWN_STREAM_DETAILED_VGA:
+                               link->dpcd_caps.dongle_type =
+                                       DISPLAY_DONGLE_DP_VGA_CONVERTER;
+                               break;
+                       case DOWN_STREAM_DETAILED_DVI:
+                               link->dpcd_caps.dongle_type =
+                                       DISPLAY_DONGLE_DP_DVI_CONVERTER;
+                               break;
+                       case DOWN_STREAM_DETAILED_HDMI:
+                       case DOWN_STREAM_DETAILED_DP_PLUS_PLUS:
+                               /*Handle DP++ active converter case, process DP++ case as HDMI case according DP1.4 spec*/
+                               link->dpcd_caps.dongle_type =
+                                       DISPLAY_DONGLE_DP_HDMI_CONVERTER;
+
+                               link->dpcd_caps.dongle_caps.dongle_type = link->dpcd_caps.dongle_type;
+                               if (ds_port.fields.DETAILED_CAPS) {
+
+                                       union dwnstream_port_caps_byte3_hdmi
+                                               hdmi_caps = {.raw = det_caps[3] };
+                                       union dwnstream_port_caps_byte2
+                                               hdmi_color_caps = {.raw = det_caps[2] };
+                                       link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz =
+                                               det_caps[1] * 2500;
+
+                                       link->dpcd_caps.dongle_caps.is_dp_hdmi_s3d_converter =
+                                               hdmi_caps.bits.FRAME_SEQ_TO_FRAME_PACK;
+                                       /*YCBCR capability only for HDMI case*/
+                                       if (port_caps->bits.DWN_STRM_PORTX_TYPE
+                                                       == DOWN_STREAM_DETAILED_HDMI) {
+                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_pass_through =
+                                                               hdmi_caps.bits.YCrCr422_PASS_THROUGH;
+                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_pass_through =
+                                                               hdmi_caps.bits.YCrCr420_PASS_THROUGH;
+                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr422_converter =
+                                                               hdmi_caps.bits.YCrCr422_CONVERSION;
+                                               link->dpcd_caps.dongle_caps.is_dp_hdmi_ycbcr420_converter =
+                                                               hdmi_caps.bits.YCrCr420_CONVERSION;
+                                       }
+
+                                       link->dpcd_caps.dongle_caps.dp_hdmi_max_bpc =
+                                               translate_dpcd_max_bpc(
+                                                       hdmi_color_caps.bits.MAX_BITS_PER_COLOR_COMPONENT);
+
+                                       if (link->dc->caps.dp_hdmi21_pcon_support) {
+                                               union hdmi_encoded_link_bw hdmi_encoded_link_bw;
+
+                                               link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps =
+                                                               dc_link_bw_kbps_from_raw_frl_link_rate_data(
+                                                                               hdmi_color_caps.bits.MAX_ENCODED_LINK_BW_SUPPORT);
+
+                                               // Intersect reported max link bw support with the supported link rate post FRL link training
+                                               if (core_link_read_dpcd(link, DP_PCON_HDMI_POST_FRL_STATUS,
+                                                               &hdmi_encoded_link_bw.raw, sizeof(hdmi_encoded_link_bw)) == DC_OK) {
+                                                       link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps = intersect_frl_link_bw_support(
+                                                                       link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps,
+                                                                       hdmi_encoded_link_bw);
+                                               }
+
+                                               if (link->dpcd_caps.dongle_caps.dp_hdmi_frl_max_link_bw_in_kbps > 0)
+                                                       link->dpcd_caps.dongle_caps.extendedCapValid = true;
+                                       }
+
+                                       if (link->dpcd_caps.dongle_caps.dp_hdmi_max_pixel_clk_in_khz != 0)
+                                               link->dpcd_caps.dongle_caps.extendedCapValid = true;
+                               }
+
+                               break;
+                       }
+               }
+       }
+
+       set_dongle_type(link->ddc, link->dpcd_caps.dongle_type);
+
+       {
+               struct dp_sink_hw_fw_revision dp_hw_fw_revision;
+
+               core_link_read_dpcd(
+                       link,
+                       DP_BRANCH_REVISION_START,
+                       (uint8_t *)&dp_hw_fw_revision,
+                       sizeof(dp_hw_fw_revision));
+
+               link->dpcd_caps.branch_hw_revision =
+                       dp_hw_fw_revision.ieee_hw_rev;
+
+               memmove(
+                       link->dpcd_caps.branch_fw_revision,
+                       dp_hw_fw_revision.ieee_fw_rev,
+                       sizeof(dp_hw_fw_revision.ieee_fw_rev));
+       }
+       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14 &&
+                       link->dpcd_caps.dongle_type != DISPLAY_DONGLE_NONE) {
+               union dp_dfp_cap_ext dfp_cap_ext;
+               memset(&dfp_cap_ext, '\0', sizeof (dfp_cap_ext));
+               core_link_read_dpcd(
+                               link,
+                               DP_DFP_CAPABILITY_EXTENSION_SUPPORT,
+                               dfp_cap_ext.raw,
+                               sizeof(dfp_cap_ext.raw));
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.supported = dfp_cap_ext.fields.supported;
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.max_pixel_rate_in_mps =
+                               dfp_cap_ext.fields.max_pixel_rate_in_mps[0] +
+                               (dfp_cap_ext.fields.max_pixel_rate_in_mps[1] << 8);
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_h_active_width =
+                               dfp_cap_ext.fields.max_video_h_active_width[0] +
+                               (dfp_cap_ext.fields.max_video_h_active_width[1] << 8);
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_v_active_height =
+                               dfp_cap_ext.fields.max_video_v_active_height[0] +
+                               (dfp_cap_ext.fields.max_video_v_active_height[1] << 8);
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.encoding_format_caps =
+                               dfp_cap_ext.fields.encoding_format_caps;
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.rgb_color_depth_caps =
+                               dfp_cap_ext.fields.rgb_color_depth_caps;
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr444_color_depth_caps =
+                               dfp_cap_ext.fields.ycbcr444_color_depth_caps;
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr422_color_depth_caps =
+                               dfp_cap_ext.fields.ycbcr422_color_depth_caps;
+               link->dpcd_caps.dongle_caps.dfp_cap_ext.ycbcr420_color_depth_caps =
+                               dfp_cap_ext.fields.ycbcr420_color_depth_caps;
+               DC_LOG_DP2("DFP capability extension is read at link %d", link->link_index);
+               DC_LOG_DP2("\tdfp_cap_ext.supported = %s", link->dpcd_caps.dongle_caps.dfp_cap_ext.supported ? "true" : "false");
+               DC_LOG_DP2("\tdfp_cap_ext.max_pixel_rate_in_mps = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_pixel_rate_in_mps);
+               DC_LOG_DP2("\tdfp_cap_ext.max_video_h_active_width = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_h_active_width);
+               DC_LOG_DP2("\tdfp_cap_ext.max_video_v_active_height = %d", link->dpcd_caps.dongle_caps.dfp_cap_ext.max_video_v_active_height);
+       }
+}
+
+static void apply_usbc_combo_phy_reset_wa(struct dc_link *link,
+               struct dc_link_settings *link_settings)
+{
+       /* Temporary Renoir-specific workaround PHY will sometimes be in bad
+        * state on hotplugging display from certain USB-C dongle, so add extra
+        * cycle of enabling and disabling the PHY before first link training.
+        */
+       struct link_resource link_res = {0};
+       enum clock_source_id dp_cs_id = get_clock_source_id(link);
+
+       dp_enable_link_phy(link, &link_res, link->connector_signal,
+                       dp_cs_id, link_settings);
+       dp_disable_link_phy(link, &link_res, link->connector_signal);
+}
+
+static bool dp_overwrite_extended_receiver_cap(struct dc_link *link)
+{
+       uint8_t dpcd_data[16];
+       uint32_t read_dpcd_retry_cnt = 3;
+       enum dc_status status = DC_ERROR_UNEXPECTED;
+       union dp_downstream_port_present ds_port = { 0 };
+       union down_stream_port_count down_strm_port_count;
+       union edp_configuration_cap edp_config_cap;
+
+       int i;
+
+       for (i = 0; i < read_dpcd_retry_cnt; i++) {
+               status = core_link_read_dpcd(
+                               link,
+                               DP_DPCD_REV,
+                               dpcd_data,
+                               sizeof(dpcd_data));
+               if (status == DC_OK)
+                       break;
+       }
+
+       link->dpcd_caps.dpcd_rev.raw =
+               dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
+
+       if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
+               return false;
+
+       ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
+                       DP_DPCD_REV];
+
+       get_active_converter_info(ds_port.byte, link);
+
+       down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
+                       DP_DPCD_REV];
+
+       link->dpcd_caps.allow_invalid_MSA_timing_param =
+               down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
+
+       link->dpcd_caps.max_ln_count.raw = dpcd_data[
+               DP_MAX_LANE_COUNT - DP_DPCD_REV];
+
+       link->dpcd_caps.max_down_spread.raw = dpcd_data[
+               DP_MAX_DOWNSPREAD - DP_DPCD_REV];
+
+       link->reported_link_cap.lane_count =
+               link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
+       link->reported_link_cap.link_rate = dpcd_data[
+               DP_MAX_LINK_RATE - DP_DPCD_REV];
+       link->reported_link_cap.link_spread =
+               link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
+               LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
+
+       edp_config_cap.raw = dpcd_data[
+               DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
+       link->dpcd_caps.panel_mode_edp =
+               edp_config_cap.bits.ALT_SCRAMBLER_RESET;
+       link->dpcd_caps.dpcd_display_control_capable =
+               edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
+
+       return true;
+}
+
+void dc_link_overwrite_extended_receiver_cap(
+               struct dc_link *link)
+{
+       dp_overwrite_extended_receiver_cap(link);
+}
+
+void dpcd_set_source_specific_data(struct dc_link *link)
+{
+       if (!link->dc->vendor_signature.is_valid) {
+               enum dc_status result_write_min_hblank = DC_NOT_SUPPORTED;
+               struct dpcd_amd_signature amd_signature = {0};
+               struct dpcd_amd_device_id amd_device_id = {0};
+
+               amd_device_id.device_id_byte1 =
+                               (uint8_t)(link->ctx->asic_id.chip_id);
+               amd_device_id.device_id_byte2 =
+                               (uint8_t)(link->ctx->asic_id.chip_id >> 8);
+               amd_device_id.dce_version =
+                               (uint8_t)(link->ctx->dce_version);
+               amd_device_id.dal_version_byte1 = 0x0; // needed? where to get?
+               amd_device_id.dal_version_byte2 = 0x0; // needed? where to get?
+
+               core_link_read_dpcd(link, DP_SOURCE_OUI,
+                               (uint8_t *)(&amd_signature),
+                               sizeof(amd_signature));
+
+               if (!((amd_signature.AMD_IEEE_TxSignature_byte1 == 0x0) &&
+                       (amd_signature.AMD_IEEE_TxSignature_byte2 == 0x0) &&
+                       (amd_signature.AMD_IEEE_TxSignature_byte3 == 0x1A))) {
+
+                       amd_signature.AMD_IEEE_TxSignature_byte1 = 0x0;
+                       amd_signature.AMD_IEEE_TxSignature_byte2 = 0x0;
+                       amd_signature.AMD_IEEE_TxSignature_byte3 = 0x1A;
+
+                       core_link_write_dpcd(link, DP_SOURCE_OUI,
+                               (uint8_t *)(&amd_signature),
+                               sizeof(amd_signature));
+               }
+
+               core_link_write_dpcd(link, DP_SOURCE_OUI+0x03,
+                               (uint8_t *)(&amd_device_id),
+                               sizeof(amd_device_id));
+
+               if (link->ctx->dce_version >= DCN_VERSION_2_0 &&
+                       link->dc->caps.min_horizontal_blanking_period != 0) {
+
+                       uint8_t hblank_size = (uint8_t)link->dc->caps.min_horizontal_blanking_period;
+
+                       result_write_min_hblank = core_link_write_dpcd(link,
+                               DP_SOURCE_MINIMUM_HBLANK_SUPPORTED, (uint8_t *)(&hblank_size),
+                               sizeof(hblank_size));
+               }
+               DC_TRACE_LEVEL_MESSAGE(DAL_TRACE_LEVEL_INFORMATION,
+                                                       WPP_BIT_FLAG_DC_DETECTION_DP_CAPS,
+                                                       "result=%u link_index=%u enum dce_version=%d DPCD=0x%04X min_hblank=%u branch_dev_id=0x%x branch_dev_name='%c%c%c%c%c%c'",
+                                                       result_write_min_hblank,
+                                                       link->link_index,
+                                                       link->ctx->dce_version,
+                                                       DP_SOURCE_MINIMUM_HBLANK_SUPPORTED,
+                                                       link->dc->caps.min_horizontal_blanking_period,
+                                                       link->dpcd_caps.branch_dev_id,
+                                                       link->dpcd_caps.branch_dev_name[0],
+                                                       link->dpcd_caps.branch_dev_name[1],
+                                                       link->dpcd_caps.branch_dev_name[2],
+                                                       link->dpcd_caps.branch_dev_name[3],
+                                                       link->dpcd_caps.branch_dev_name[4],
+                                                       link->dpcd_caps.branch_dev_name[5]);
+       } else {
+               core_link_write_dpcd(link, DP_SOURCE_OUI,
+                               link->dc->vendor_signature.data.raw,
+                               sizeof(link->dc->vendor_signature.data.raw));
+       }
+}
+
+void dpcd_write_cable_id_to_dprx(struct dc_link *link)
+{
+       if (!link->dpcd_caps.channel_coding_cap.bits.DP_128b_132b_SUPPORTED ||
+                       link->dpcd_caps.cable_id.raw == 0 ||
+                       link->dprx_states.cable_id_written)
+               return;
+
+       core_link_write_dpcd(link, DP_CABLE_ATTRIBUTES_UPDATED_BY_DPTX,
+                       &link->dpcd_caps.cable_id.raw,
+                       sizeof(link->dpcd_caps.cable_id.raw));
+
+       link->dprx_states.cable_id_written = 1;
+}
+
+static bool get_usbc_cable_id(struct dc_link *link, union dp_cable_id *cable_id)
+{
+       union dmub_rb_cmd cmd;
+
+       if (!link->ctx->dmub_srv ||
+                       link->ep_type != DISPLAY_ENDPOINT_PHY ||
+                       link->link_enc->features.flags.bits.DP_IS_USB_C == 0)
+               return false;
+
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.cable_id.header.type = DMUB_CMD_GET_USBC_CABLE_ID;
+       cmd.cable_id.header.payload_bytes = sizeof(cmd.cable_id.data);
+       cmd.cable_id.data.input.phy_inst = resource_transmitter_to_phy_idx(
+                       link->dc, link->link_enc->transmitter);
+       if (dc_dmub_srv_cmd_with_reply_data(link->ctx->dmub_srv, &cmd) &&
+                       cmd.cable_id.header.ret_status == 1) {
+               cable_id->raw = cmd.cable_id.data.output_raw;
+               DC_LOG_DC("usbc_cable_id = %d.\n", cable_id->raw);
+       }
+       return cmd.cable_id.header.ret_status == 1;
+}
+
+static void retrieve_cable_id(struct dc_link *link)
+{
+       union dp_cable_id usbc_cable_id;
+
+       link->dpcd_caps.cable_id.raw = 0;
+       core_link_read_dpcd(link, DP_CABLE_ATTRIBUTES_UPDATED_BY_DPRX,
+                       &link->dpcd_caps.cable_id.raw, sizeof(uint8_t));
+
+       if (get_usbc_cable_id(link, &usbc_cable_id))
+               link->dpcd_caps.cable_id = intersect_cable_id(
+                               &link->dpcd_caps.cable_id, &usbc_cable_id);
+}
+
+bool read_is_mst_supported(struct dc_link *link)
+{
+       bool mst          = false;
+       enum dc_status st = DC_OK;
+       union dpcd_rev rev;
+       union mstm_cap cap;
+
+       if (link->preferred_training_settings.mst_enable &&
+               *link->preferred_training_settings.mst_enable == false) {
+               return false;
+       }
+
+       rev.raw  = 0;
+       cap.raw  = 0;
+
+       st = core_link_read_dpcd(link, DP_DPCD_REV, &rev.raw,
+                       sizeof(rev));
+
+       if (st == DC_OK && rev.raw >= DPCD_REV_12) {
+
+               st = core_link_read_dpcd(link, DP_MSTM_CAP,
+                               &cap.raw, sizeof(cap));
+               if (st == DC_OK && cap.bits.MST_CAP == 1)
+                       mst = true;
+       }
+       return mst;
+
+}
+
+/* Read additional sink caps defined in source specific DPCD area
+ * This function currently only reads from SinkCapability address (DP_SOURCE_SINK_CAP)
+ * TODO: Add FS caps and read from DP_SOURCE_SINK_FS_CAP as well
+ */
+static bool dpcd_read_sink_ext_caps(struct dc_link *link)
+{
+       uint8_t dpcd_data;
+
+       if (!link)
+               return false;
+
+       if (core_link_read_dpcd(link, DP_SOURCE_SINK_CAP, &dpcd_data, 1) != DC_OK)
+               return false;
+
+       link->dpcd_sink_ext_caps.raw = dpcd_data;
+       return true;
+}
+
+enum dc_status dp_retrieve_lttpr_cap(struct dc_link *link)
+{
+       uint8_t lttpr_dpcd_data[8];
+       enum dc_status status;
+       bool is_lttpr_present;
+
+       /* Logic to determine LTTPR support*/
+       bool vbios_lttpr_interop = link->dc->caps.vbios_lttpr_aware;
+
+       if (!vbios_lttpr_interop || !link->dc->caps.extended_aux_timeout_support)
+               return DC_NOT_SUPPORTED;
+
+       /* By reading LTTPR capability, RX assumes that we will enable
+        * LTTPR extended aux timeout if LTTPR is present.
+        */
+       status = core_link_read_dpcd(
+                       link,
+                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV,
+                       lttpr_dpcd_data,
+                       sizeof(lttpr_dpcd_data));
+
+       link->dpcd_caps.lttpr_caps.revision.raw =
+                       lttpr_dpcd_data[DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+
+       link->dpcd_caps.lttpr_caps.max_link_rate =
+                       lttpr_dpcd_data[DP_MAX_LINK_RATE_PHY_REPEATER -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+
+       link->dpcd_caps.lttpr_caps.phy_repeater_cnt =
+                       lttpr_dpcd_data[DP_PHY_REPEATER_CNT -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+
+       link->dpcd_caps.lttpr_caps.max_lane_count =
+                       lttpr_dpcd_data[DP_MAX_LANE_COUNT_PHY_REPEATER -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+
+       link->dpcd_caps.lttpr_caps.mode =
+                       lttpr_dpcd_data[DP_PHY_REPEATER_MODE -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+
+       link->dpcd_caps.lttpr_caps.max_ext_timeout =
+                       lttpr_dpcd_data[DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+       link->dpcd_caps.lttpr_caps.main_link_channel_coding.raw =
+                       lttpr_dpcd_data[DP_MAIN_LINK_CHANNEL_CODING_PHY_REPEATER -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+
+       link->dpcd_caps.lttpr_caps.supported_128b_132b_rates.raw =
+                       lttpr_dpcd_data[DP_PHY_REPEATER_128B132B_RATES -
+                                                       DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV];
+
+       /* If this chip cap is set, at least one retimer must exist in the chain
+        * Override count to 1 if we receive a known bad count (0 or an invalid value) */
+       if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
+                       (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) == 0)) {
+               ASSERT(0);
+               link->dpcd_caps.lttpr_caps.phy_repeater_cnt = 0x80;
+               DC_LOG_DC("lttpr_caps forced phy_repeater_cnt = %d\n", link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+       }
+
+       /* Attempt to train in LTTPR transparent mode if repeater count exceeds 8. */
+       is_lttpr_present = dp_is_lttpr_present(link);
+
+       if (is_lttpr_present)
+               CONN_DATA_DETECT(link, lttpr_dpcd_data, sizeof(lttpr_dpcd_data), "LTTPR Caps: ");
+
+       DC_LOG_DC("is_lttpr_present = %d\n", is_lttpr_present);
+       return status;
+}
+
+static bool retrieve_link_cap(struct dc_link *link)
+{
+       /* DP_ADAPTER_CAP - DP_DPCD_REV + 1 == 16 and also DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT + 1 == 16,
+        * which means size 16 will be good for both of those DPCD register block reads
+        */
+       uint8_t dpcd_data[16];
+       /*Only need to read 1 byte starting from DP_DPRX_FEATURE_ENUMERATION_LIST.
+        */
+       uint8_t dpcd_dprx_data = '\0';
+
+       struct dp_device_vendor_id sink_id;
+       union down_stream_port_count down_strm_port_count;
+       union edp_configuration_cap edp_config_cap;
+       union dp_downstream_port_present ds_port = { 0 };
+       enum dc_status status = DC_ERROR_UNEXPECTED;
+       uint32_t read_dpcd_retry_cnt = 3;
+       int i;
+       struct dp_sink_hw_fw_revision dp_hw_fw_revision;
+       const uint32_t post_oui_delay = 30; // 30ms
+
+       memset(dpcd_data, '\0', sizeof(dpcd_data));
+       memset(&down_strm_port_count,
+               '\0', sizeof(union down_stream_port_count));
+       memset(&edp_config_cap, '\0',
+               sizeof(union edp_configuration_cap));
+
+       /* if extended timeout is supported in hardware,
+        * default to LTTPR timeout (3.2ms) first as a W/A for DP link layer
+        * CTS 4.2.1.1 regression introduced by CTS specs requirement update.
+        */
+       try_to_configure_aux_timeout(link->ddc,
+                       LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD);
+
+       status = dp_retrieve_lttpr_cap(link);
+
+       if (status != DC_OK) {
+               status = wake_up_aux_channel(link);
+               if (status == DC_OK)
+                       dp_retrieve_lttpr_cap(link);
+               else
+                       return false;
+       }
+
+       if (dp_is_lttpr_present(link))
+               configure_lttpr_mode_transparent(link);
+
+       /* Read DP tunneling information. */
+       status = dpcd_get_tunneling_device_data(link);
+
+       dpcd_set_source_specific_data(link);
+       /* Sink may need to configure internals based on vendor, so allow some
+        * time before proceeding with possibly vendor specific transactions
+        */
+       msleep(post_oui_delay);
+
+       for (i = 0; i < read_dpcd_retry_cnt; i++) {
+               status = core_link_read_dpcd(
+                               link,
+                               DP_DPCD_REV,
+                               dpcd_data,
+                               sizeof(dpcd_data));
+               if (status == DC_OK)
+                       break;
+       }
+
+
+       if (status != DC_OK) {
+               dm_error("%s: Read receiver caps dpcd data failed.\n", __func__);
+               return false;
+       }
+
+       if (!dp_is_lttpr_present(link))
+               try_to_configure_aux_timeout(link->ddc, LINK_AUX_DEFAULT_TIMEOUT_PERIOD);
+
+
+       {
+               union training_aux_rd_interval aux_rd_interval;
+
+               aux_rd_interval.raw =
+                       dpcd_data[DP_TRAINING_AUX_RD_INTERVAL];
+
+               link->dpcd_caps.ext_receiver_cap_field_present =
+                               aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1 ? true:false;
+
+               if (aux_rd_interval.bits.EXT_RECEIVER_CAP_FIELD_PRESENT == 1) {
+                       uint8_t ext_cap_data[16];
+
+                       memset(ext_cap_data, '\0', sizeof(ext_cap_data));
+                       for (i = 0; i < read_dpcd_retry_cnt; i++) {
+                               status = core_link_read_dpcd(
+                               link,
+                               DP_DP13_DPCD_REV,
+                               ext_cap_data,
+                               sizeof(ext_cap_data));
+                               if (status == DC_OK) {
+                                       memcpy(dpcd_data, ext_cap_data, sizeof(dpcd_data));
+                                       break;
+                               }
+                       }
+                       if (status != DC_OK)
+                               dm_error("%s: Read extend caps data failed, use cap from dpcd 0.\n", __func__);
+               }
+       }
+
+       link->dpcd_caps.dpcd_rev.raw =
+                       dpcd_data[DP_DPCD_REV - DP_DPCD_REV];
+
+       if (link->dpcd_caps.ext_receiver_cap_field_present) {
+               for (i = 0; i < read_dpcd_retry_cnt; i++) {
+                       status = core_link_read_dpcd(
+                                       link,
+                                       DP_DPRX_FEATURE_ENUMERATION_LIST,
+                                       &dpcd_dprx_data,
+                                       sizeof(dpcd_dprx_data));
+                       if (status == DC_OK)
+                               break;
+               }
+
+               link->dpcd_caps.dprx_feature.raw = dpcd_dprx_data;
+
+               if (status != DC_OK)
+                       dm_error("%s: Read DPRX caps data failed.\n", __func__);
+       }
+
+       else {
+               link->dpcd_caps.dprx_feature.raw = 0;
+       }
+
+
+       /* Error condition checking...
+        * It is impossible for Sink to report Max Lane Count = 0.
+        * It is possible for Sink to report Max Link Rate = 0, if it is
+        * an eDP device that is reporting specialized link rates in the
+        * SUPPORTED_LINK_RATE table.
+        */
+       if (dpcd_data[DP_MAX_LANE_COUNT - DP_DPCD_REV] == 0)
+               return false;
+
+       ds_port.byte = dpcd_data[DP_DOWNSTREAMPORT_PRESENT -
+                                DP_DPCD_REV];
+
+       read_dp_device_vendor_id(link);
+
+       /* TODO - decouple raw mst capability from policy decision */
+       link->dpcd_caps.is_mst_capable = read_is_mst_supported(link);
+
+       get_active_converter_info(ds_port.byte, link);
+
+       dp_wa_power_up_0010FA(link, dpcd_data, sizeof(dpcd_data));
+
+       down_strm_port_count.raw = dpcd_data[DP_DOWN_STREAM_PORT_COUNT -
+                                DP_DPCD_REV];
+
+       link->dpcd_caps.allow_invalid_MSA_timing_param =
+               down_strm_port_count.bits.IGNORE_MSA_TIMING_PARAM;
+
+       link->dpcd_caps.max_ln_count.raw = dpcd_data[
+               DP_MAX_LANE_COUNT - DP_DPCD_REV];
+
+       link->dpcd_caps.max_down_spread.raw = dpcd_data[
+               DP_MAX_DOWNSPREAD - DP_DPCD_REV];
+
+       link->reported_link_cap.lane_count =
+               link->dpcd_caps.max_ln_count.bits.MAX_LANE_COUNT;
+       link->reported_link_cap.link_rate = get_link_rate_from_max_link_bw(
+                       dpcd_data[DP_MAX_LINK_RATE - DP_DPCD_REV]);
+       link->reported_link_cap.link_spread =
+               link->dpcd_caps.max_down_spread.bits.MAX_DOWN_SPREAD ?
+               LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED;
+
+       edp_config_cap.raw = dpcd_data[
+               DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV];
+       link->dpcd_caps.panel_mode_edp =
+               edp_config_cap.bits.ALT_SCRAMBLER_RESET;
+       link->dpcd_caps.dpcd_display_control_capable =
+               edp_config_cap.bits.DPCD_DISPLAY_CONTROL_CAPABLE;
+       link->dpcd_caps.channel_coding_cap.raw =
+                       dpcd_data[DP_MAIN_LINK_CHANNEL_CODING - DP_DPCD_REV];
+       link->test_pattern_enabled = false;
+       link->compliance_test_state.raw = 0;
+
+       /* read sink count */
+       core_link_read_dpcd(link,
+                       DP_SINK_COUNT,
+                       &link->dpcd_caps.sink_count.raw,
+                       sizeof(link->dpcd_caps.sink_count.raw));
+
+       /* read sink ieee oui */
+       core_link_read_dpcd(link,
+                       DP_SINK_OUI,
+                       (uint8_t *)(&sink_id),
+                       sizeof(sink_id));
+
+       link->dpcd_caps.sink_dev_id =
+                       (sink_id.ieee_oui[0] << 16) +
+                       (sink_id.ieee_oui[1] << 8) +
+                       (sink_id.ieee_oui[2]);
+
+       memmove(
+               link->dpcd_caps.sink_dev_id_str,
+               sink_id.ieee_device_id,
+               sizeof(sink_id.ieee_device_id));
+
+       core_link_read_dpcd(
+               link,
+               DP_SINK_HW_REVISION_START,
+               (uint8_t *)&dp_hw_fw_revision,
+               sizeof(dp_hw_fw_revision));
+
+       link->dpcd_caps.sink_hw_revision =
+               dp_hw_fw_revision.ieee_hw_rev;
+
+       memmove(
+               link->dpcd_caps.sink_fw_revision,
+               dp_hw_fw_revision.ieee_fw_rev,
+               sizeof(dp_hw_fw_revision.ieee_fw_rev));
+
+       /* Quirk for Retina panels: wrong DP_MAX_LINK_RATE */
+       {
+               uint8_t str_mbp_2018[] = { 101, 68, 21, 103, 98, 97 };
+               uint8_t fwrev_mbp_2018[] = { 7, 4 };
+               uint8_t fwrev_mbp_2018_vega[] = { 8, 4 };
+
+               /* We also check for the firmware revision as 16,1 models have an
+                * identical device id and are incorrectly quirked otherwise.
+                */
+               if ((link->dpcd_caps.sink_dev_id == 0x0010fa) &&
+                   !memcmp(link->dpcd_caps.sink_dev_id_str, str_mbp_2018,
+                            sizeof(str_mbp_2018)) &&
+                   (!memcmp(link->dpcd_caps.sink_fw_revision, fwrev_mbp_2018,
+                            sizeof(fwrev_mbp_2018)) ||
+                   !memcmp(link->dpcd_caps.sink_fw_revision, fwrev_mbp_2018_vega,
+                            sizeof(fwrev_mbp_2018_vega)))) {
+                       link->reported_link_cap.link_rate = LINK_RATE_RBR2;
+               }
+       }
+
+       memset(&link->dpcd_caps.dsc_caps, '\0',
+                       sizeof(link->dpcd_caps.dsc_caps));
+       memset(&link->dpcd_caps.fec_cap, '\0', sizeof(link->dpcd_caps.fec_cap));
+       /* Read DSC and FEC sink capabilities if DP revision is 1.4 and up */
+       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_14) {
+               status = core_link_read_dpcd(
+                               link,
+                               DP_FEC_CAPABILITY,
+                               &link->dpcd_caps.fec_cap.raw,
+                               sizeof(link->dpcd_caps.fec_cap.raw));
+               status = core_link_read_dpcd(
+                               link,
+                               DP_DSC_SUPPORT,
+                               link->dpcd_caps.dsc_caps.dsc_basic_caps.raw,
+                               sizeof(link->dpcd_caps.dsc_caps.dsc_basic_caps.raw));
+               if (link->dpcd_caps.dongle_type != DISPLAY_DONGLE_NONE) {
+                       status = core_link_read_dpcd(
+                                       link,
+                                       DP_DSC_BRANCH_OVERALL_THROUGHPUT_0,
+                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw,
+                                       sizeof(link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw));
+                       DC_LOG_DSC("DSC branch decoder capability is read at link %d", link->link_index);
+                       DC_LOG_DSC("\tBRANCH_OVERALL_THROUGHPUT_0 = 0x%02x",
+                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_OVERALL_THROUGHPUT_0);
+                       DC_LOG_DSC("\tBRANCH_OVERALL_THROUGHPUT_1 = 0x%02x",
+                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_OVERALL_THROUGHPUT_1);
+                       DC_LOG_DSC("\tBRANCH_MAX_LINE_WIDTH 0x%02x",
+                                       link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.fields.BRANCH_MAX_LINE_WIDTH);
+               }
+
+               /* Apply work around to disable FEC and DSC for USB4 tunneling in TBT3 compatibility mode
+                * only if required.
+                */
+               if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA &&
+                               link->dc->debug.dpia_debug.bits.enable_force_tbt3_work_around &&
+                               link->dpcd_caps.is_branch_dev &&
+                               link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_90CC24 &&
+                               link->dpcd_caps.branch_hw_revision == DP_BRANCH_HW_REV_10 &&
+                               (link->dpcd_caps.fec_cap.bits.FEC_CAPABLE ||
+                               link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT)) {
+                       /* A TBT3 device is expected to report no support for FEC or DSC to a USB4 DPIA.
+                        * Clear FEC and DSC capabilities as a work around if that is not the case.
+                        */
+                       link->wa_flags.dpia_forced_tbt3_mode = true;
+                       memset(&link->dpcd_caps.dsc_caps, '\0', sizeof(link->dpcd_caps.dsc_caps));
+                       memset(&link->dpcd_caps.fec_cap, '\0', sizeof(link->dpcd_caps.fec_cap));
+                       DC_LOG_DSC("Clear DSC SUPPORT for USB4 link(%d) in TBT3 compatibility mode", link->link_index);
+               } else
+                       link->wa_flags.dpia_forced_tbt3_mode = false;
+       }
+
+       if (!dpcd_read_sink_ext_caps(link))
+               link->dpcd_sink_ext_caps.raw = 0;
+
+       if (link->dpcd_caps.channel_coding_cap.bits.DP_128b_132b_SUPPORTED) {
+               DC_LOG_DP2("128b/132b encoding is supported at link %d", link->link_index);
+
+               core_link_read_dpcd(link,
+                               DP_128B132B_SUPPORTED_LINK_RATES,
+                               &link->dpcd_caps.dp_128b_132b_supported_link_rates.raw,
+                               sizeof(link->dpcd_caps.dp_128b_132b_supported_link_rates.raw));
+               if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR20)
+                       link->reported_link_cap.link_rate = LINK_RATE_UHBR20;
+               else if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR13_5)
+                       link->reported_link_cap.link_rate = LINK_RATE_UHBR13_5;
+               else if (link->dpcd_caps.dp_128b_132b_supported_link_rates.bits.UHBR10)
+                       link->reported_link_cap.link_rate = LINK_RATE_UHBR10;
+               else
+                       dm_error("%s: Invalid RX 128b_132b_supported_link_rates\n", __func__);
+               DC_LOG_DP2("128b/132b supported link rates is read at link %d", link->link_index);
+               DC_LOG_DP2("\tmax 128b/132b link rate support is %d.%d GHz",
+                               link->reported_link_cap.link_rate / 100,
+                               link->reported_link_cap.link_rate % 100);
+
+               core_link_read_dpcd(link,
+                               DP_SINK_VIDEO_FALLBACK_FORMATS,
+                               &link->dpcd_caps.fallback_formats.raw,
+                               sizeof(link->dpcd_caps.fallback_formats.raw));
+               DC_LOG_DP2("sink video fallback format is read at link %d", link->link_index);
+               if (link->dpcd_caps.fallback_formats.bits.dp_1920x1080_60Hz_24bpp_support)
+                       DC_LOG_DP2("\t1920x1080@60Hz 24bpp fallback format supported");
+               if (link->dpcd_caps.fallback_formats.bits.dp_1280x720_60Hz_24bpp_support)
+                       DC_LOG_DP2("\t1280x720@60Hz 24bpp fallback format supported");
+               if (link->dpcd_caps.fallback_formats.bits.dp_1024x768_60Hz_24bpp_support)
+                       DC_LOG_DP2("\t1024x768@60Hz 24bpp fallback format supported");
+               if (link->dpcd_caps.fallback_formats.raw == 0) {
+                       DC_LOG_DP2("\tno supported fallback formats, assume 1920x1080@60Hz 24bpp is supported");
+                       link->dpcd_caps.fallback_formats.bits.dp_1920x1080_60Hz_24bpp_support = 1;
+               }
+
+               core_link_read_dpcd(link,
+                               DP_FEC_CAPABILITY_1,
+                               &link->dpcd_caps.fec_cap1.raw,
+                               sizeof(link->dpcd_caps.fec_cap1.raw));
+               DC_LOG_DP2("FEC CAPABILITY 1 is read at link %d", link->link_index);
+               if (link->dpcd_caps.fec_cap1.bits.AGGREGATED_ERROR_COUNTERS_CAPABLE)
+                       DC_LOG_DP2("\tFEC aggregated error counters are supported");
+       }
+
+       retrieve_cable_id(link);
+       dpcd_write_cable_id_to_dprx(link);
+
+       /* Connectivity log: detection */
+       CONN_DATA_DETECT(link, dpcd_data, sizeof(dpcd_data), "Rx Caps: ");
+
+       return true;
+}
+
+bool detect_dp_sink_caps(struct dc_link *link)
+{
+       return retrieve_link_cap(link);
+}
+
+void detect_edp_sink_caps(struct dc_link *link)
+{
+       uint8_t supported_link_rates[16];
+       uint32_t entry;
+       uint32_t link_rate_in_khz;
+       enum dc_link_rate link_rate = LINK_RATE_UNKNOWN;
+       uint8_t backlight_adj_cap;
+       uint8_t general_edp_cap;
+
+       retrieve_link_cap(link);
+       link->dpcd_caps.edp_supported_link_rates_count = 0;
+       memset(supported_link_rates, 0, sizeof(supported_link_rates));
+
+       /*
+        * edp_supported_link_rates_count is only valid for eDP v1.4 or higher.
+        * Per VESA eDP spec, "The DPCD revision for eDP v1.4 is 13h"
+        */
+       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_13 &&
+                       (link->panel_config.ilr.optimize_edp_link_rate ||
+                       link->reported_link_cap.link_rate == LINK_RATE_UNKNOWN)) {
+               // Read DPCD 00010h - 0001Fh 16 bytes at one shot
+               core_link_read_dpcd(link, DP_SUPPORTED_LINK_RATES,
+                                                       supported_link_rates, sizeof(supported_link_rates));
+
+               for (entry = 0; entry < 16; entry += 2) {
+                       // DPCD register reports per-lane link rate = 16-bit link rate capability
+                       // value X 200 kHz. Need multiplier to find link rate in kHz.
+                       link_rate_in_khz = (supported_link_rates[entry+1] * 0x100 +
+                                                                               supported_link_rates[entry]) * 200;
+
+                       if (link_rate_in_khz != 0) {
+                               link_rate = linkRateInKHzToLinkRateMultiplier(link_rate_in_khz);
+                               link->dpcd_caps.edp_supported_link_rates[link->dpcd_caps.edp_supported_link_rates_count] = link_rate;
+                               link->dpcd_caps.edp_supported_link_rates_count++;
+
+                               if (link->reported_link_cap.link_rate < link_rate)
+                                       link->reported_link_cap.link_rate = link_rate;
+                       }
+               }
+       }
+       core_link_read_dpcd(link, DP_EDP_BACKLIGHT_ADJUSTMENT_CAP,
+                                               &backlight_adj_cap, sizeof(backlight_adj_cap));
+
+       link->dpcd_caps.dynamic_backlight_capable_edp =
+                               (backlight_adj_cap & DP_EDP_DYNAMIC_BACKLIGHT_CAP) ? true:false;
+
+       core_link_read_dpcd(link, DP_EDP_GENERAL_CAP_1,
+                                               &general_edp_cap, sizeof(general_edp_cap));
+
+       link->dpcd_caps.set_power_state_capable_edp =
+                               (general_edp_cap & DP_EDP_SET_POWER_CAP) ? true:false;
+
+       dc_link_set_default_brightness_aux(link);
+
+       core_link_read_dpcd(link, DP_EDP_DPCD_REV,
+               &link->dpcd_caps.edp_rev,
+               sizeof(link->dpcd_caps.edp_rev));
+       /*
+        * PSR is only valid for eDP v1.3 or higher.
+        */
+       if (link->dpcd_caps.edp_rev >= DP_EDP_13) {
+               core_link_read_dpcd(link, DP_PSR_SUPPORT,
+                       &link->dpcd_caps.psr_info.psr_version,
+                       sizeof(link->dpcd_caps.psr_info.psr_version));
+               if (link->dpcd_caps.sink_dev_id == DP_BRANCH_DEVICE_ID_001CF8)
+                       core_link_read_dpcd(link, DP_FORCE_PSRSU_CAPABILITY,
+                                               &link->dpcd_caps.psr_info.force_psrsu_cap,
+                                               sizeof(link->dpcd_caps.psr_info.force_psrsu_cap));
+               core_link_read_dpcd(link, DP_PSR_CAPS,
+                       &link->dpcd_caps.psr_info.psr_dpcd_caps.raw,
+                       sizeof(link->dpcd_caps.psr_info.psr_dpcd_caps.raw));
+               if (link->dpcd_caps.psr_info.psr_dpcd_caps.bits.Y_COORDINATE_REQUIRED) {
+                       core_link_read_dpcd(link, DP_PSR2_SU_Y_GRANULARITY,
+                               &link->dpcd_caps.psr_info.psr2_su_y_granularity_cap,
+                               sizeof(link->dpcd_caps.psr_info.psr2_su_y_granularity_cap));
+               }
+       }
+
+       /*
+        * ALPM is only valid for eDP v1.4 or higher.
+        */
+       if (link->dpcd_caps.dpcd_rev.raw >= DP_EDP_14)
+               core_link_read_dpcd(link, DP_RECEIVER_ALPM_CAP,
+                       &link->dpcd_caps.alpm_caps.raw,
+                       sizeof(link->dpcd_caps.alpm_caps.raw));
+}
+
+bool dc_link_dp_get_max_link_enc_cap(const struct dc_link *link, struct dc_link_settings *max_link_enc_cap)
+{
+       struct link_encoder *link_enc = NULL;
+
+       if (!max_link_enc_cap) {
+               DC_LOG_ERROR("%s: Could not return max link encoder caps", __func__);
+               return false;
+       }
+
+       link_enc = link_enc_cfg_get_link_enc(link);
+       ASSERT(link_enc);
+
+       if (link_enc && link_enc->funcs->get_max_link_cap) {
+               link_enc->funcs->get_max_link_cap(link_enc, max_link_enc_cap);
+               return true;
+       }
+
+       DC_LOG_ERROR("%s: Max link encoder caps unknown", __func__);
+       max_link_enc_cap->lane_count = 1;
+       max_link_enc_cap->link_rate = 6;
+       return false;
+}
+
+const struct dc_link_settings *dc_link_get_link_cap(
+               const struct dc_link *link)
+{
+       if (link->preferred_link_setting.lane_count != LANE_COUNT_UNKNOWN &&
+                       link->preferred_link_setting.link_rate != LINK_RATE_UNKNOWN)
+               return &link->preferred_link_setting;
+       return &link->verified_link_cap;
+}
+
+struct dc_link_settings dp_get_max_link_cap(struct dc_link *link)
+{
+       struct dc_link_settings max_link_cap = {0};
+       enum dc_link_rate lttpr_max_link_rate;
+       enum dc_link_rate cable_max_link_rate;
+       struct link_encoder *link_enc = NULL;
+
+
+       link_enc = link_enc_cfg_get_link_enc(link);
+       ASSERT(link_enc);
+
+       /* get max link encoder capability */
+       if (link_enc)
+               link_enc->funcs->get_max_link_cap(link_enc, &max_link_cap);
+
+       /* Lower link settings based on sink's link cap */
+       if (link->reported_link_cap.lane_count < max_link_cap.lane_count)
+               max_link_cap.lane_count =
+                               link->reported_link_cap.lane_count;
+       if (link->reported_link_cap.link_rate < max_link_cap.link_rate)
+               max_link_cap.link_rate =
+                               link->reported_link_cap.link_rate;
+       if (link->reported_link_cap.link_spread <
+                       max_link_cap.link_spread)
+               max_link_cap.link_spread =
+                               link->reported_link_cap.link_spread;
+
+       /* Lower link settings based on cable attributes
+        * Cable ID is a DP2 feature to identify max certified link rate that
+        * a cable can carry. The cable identification method requires both
+        * cable and display hardware support. Since the specs comes late, it is
+        * anticipated that the first round of DP2 cables and displays may not
+        * be fully compatible to reliably return cable ID data. Therefore the
+        * decision of our cable id policy is that if the cable can return non
+        * zero cable id data, we will take cable's link rate capability into
+        * account. However if we get zero data, the cable link rate capability
+        * is considered inconclusive. In this case, we will not take cable's
+        * capability into account to avoid of over limiting hardware capability
+        * from users. The max overall link rate capability is still determined
+        * after actual dp pre-training. Cable id is considered as an auxiliary
+        * method of determining max link bandwidth capability.
+        */
+       cable_max_link_rate = get_cable_max_link_rate(link);
+
+       if (!link->dc->debug.ignore_cable_id &&
+                       cable_max_link_rate != LINK_RATE_UNKNOWN &&
+                       cable_max_link_rate < max_link_cap.link_rate)
+               max_link_cap.link_rate = cable_max_link_rate;
+
+       /* account for lttpr repeaters cap
+        * notes: repeaters do not snoop in the DPRX Capabilities addresses (3.6.3).
+        */
+       if (dp_is_lttpr_present(link)) {
+               if (link->dpcd_caps.lttpr_caps.max_lane_count < max_link_cap.lane_count)
+                       max_link_cap.lane_count = link->dpcd_caps.lttpr_caps.max_lane_count;
+               lttpr_max_link_rate = get_lttpr_max_link_rate(link);
+
+               if (lttpr_max_link_rate < max_link_cap.link_rate)
+                       max_link_cap.link_rate = lttpr_max_link_rate;
+
+               DC_LOG_HW_LINK_TRAINING("%s\n Training with LTTPR,  max_lane count %d max_link rate %d \n",
+                                               __func__,
+                                               max_link_cap.lane_count,
+                                               max_link_cap.link_rate);
+       }
+
+       if (link_dp_get_encoding_format(&max_link_cap) == DP_128b_132b_ENCODING &&
+                       link->dc->debug.disable_uhbr)
+               max_link_cap.link_rate = LINK_RATE_HIGH3;
+
+       return max_link_cap;
+}
+
+static bool dp_verify_link_cap(
+       struct dc_link *link,
+       struct dc_link_settings *known_limit_link_setting,
+       int *fail_count)
+{
+       struct dc_link_settings cur_link_settings = {0};
+       struct dc_link_settings max_link_settings = *known_limit_link_setting;
+       bool success = false;
+       bool skip_video_pattern;
+       enum clock_source_id dp_cs_id = get_clock_source_id(link);
+       enum link_training_result status = LINK_TRAINING_SUCCESS;
+       union hpd_irq_data irq_data;
+       struct link_resource link_res;
+
+       memset(&irq_data, 0, sizeof(irq_data));
+       cur_link_settings = max_link_settings;
+
+       /* Grant extended timeout request */
+       if (dp_is_lttpr_present(link) && link->dpcd_caps.lttpr_caps.max_ext_timeout > 0) {
+               uint8_t grant = link->dpcd_caps.lttpr_caps.max_ext_timeout & 0x80;
+
+               core_link_write_dpcd(link, DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT, &grant, sizeof(grant));
+       }
+
+       do {
+               if (!get_temp_dp_link_res(link, &link_res, &cur_link_settings))
+                       continue;
+
+               skip_video_pattern = cur_link_settings.link_rate != LINK_RATE_LOW;
+               dp_enable_link_phy(
+                               link,
+                               &link_res,
+                               link->connector_signal,
+                               dp_cs_id,
+                               &cur_link_settings);
+
+               status = dp_perform_link_training(
+                               link,
+                               &link_res,
+                               &cur_link_settings,
+                               skip_video_pattern);
+
+               if (status == LINK_TRAINING_SUCCESS) {
+                       success = true;
+                       udelay(1000);
+                       if (read_hpd_rx_irq_data(link, &irq_data) == DC_OK &&
+                                       hpd_rx_irq_check_link_loss_status(
+                                                       link,
+                                                       &irq_data))
+                               (*fail_count)++;
+
+               } else {
+                       (*fail_count)++;
+               }
+               dp_trace_lt_total_count_increment(link, true);
+               dp_trace_lt_result_update(link, status, true);
+               dp_disable_link_phy(link, &link_res, link->connector_signal);
+       } while (!success && decide_fallback_link_setting(link,
+                       &max_link_settings, &cur_link_settings, status));
+
+       link->verified_link_cap = success ?
+                       cur_link_settings : fail_safe_link_settings;
+       return success;
+}
+
+bool dp_verify_link_cap_with_retries(
+       struct dc_link *link,
+       struct dc_link_settings *known_limit_link_setting,
+       int attempts)
+{
+       int i = 0;
+       bool success = false;
+       int fail_count = 0;
+
+       dp_trace_detect_lt_init(link);
+
+       if (link->link_enc && link->link_enc->features.flags.bits.DP_IS_USB_C &&
+                       link->dc->debug.usbc_combo_phy_reset_wa)
+               apply_usbc_combo_phy_reset_wa(link, known_limit_link_setting);
+
+       dp_trace_set_lt_start_timestamp(link, false);
+       for (i = 0; i < attempts; i++) {
+               enum dc_connection_type type = dc_connection_none;
+
+               memset(&link->verified_link_cap, 0,
+                               sizeof(struct dc_link_settings));
+               if (!dc_link_detect_sink(link, &type) || type == dc_connection_none) {
+                       link->verified_link_cap = fail_safe_link_settings;
+                       break;
+               } else if (dp_verify_link_cap(link, known_limit_link_setting,
+                               &fail_count) && fail_count == 0) {
+                       success = true;
+                       break;
+               }
+               msleep(10);
+       }
+
+       dp_trace_lt_fail_count_update(link, fail_count, true);
+       dp_trace_set_lt_end_timestamp(link, true);
+
+       return success;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_capability.h
new file mode 100644 (file)
index 0000000..f79e4a4
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#ifndef __DC_LINK_DP_CAPABILITY_H__
+#define __DC_LINK_DP_CAPABILITY_H__
+
+#include "link.h"
+
+bool detect_dp_sink_caps(struct dc_link *link);
+
+void detect_edp_sink_caps(struct dc_link *link);
+
+struct dc_link_settings dp_get_max_link_cap(struct dc_link *link);
+
+
+enum dc_status dp_retrieve_lttpr_cap(struct dc_link *link);
+
+/* Convert PHY repeater count read from DPCD uint8_t. */
+uint8_t dp_parse_lttpr_repeater_count(uint8_t lttpr_repeater_count);
+
+bool dp_is_lttpr_present(struct dc_link *link);
+
+bool is_dp_active_dongle(const struct dc_link *link);
+
+bool is_dp_branch_device(const struct dc_link *link);
+
+void dpcd_write_cable_id_to_dprx(struct dc_link *link);
+
+/* Initialize output parameter lt_settings. */
+void dp_decide_training_settings(
+       struct dc_link *link,
+       const struct dc_link_settings *link_setting,
+       struct link_training_settings *lt_settings);
+
+
+bool decide_edp_link_settings_with_dsc(struct dc_link *link,
+               struct dc_link_settings *link_setting,
+               uint32_t req_bw,
+               enum dc_link_rate max_link_rate);
+
+void dpcd_set_source_specific_data(struct dc_link *link);
+
+/*query dpcd for version and mst cap addresses*/
+bool read_is_mst_supported(struct dc_link *link);
+
+bool decide_fallback_link_setting(
+               struct dc_link *link,
+               struct dc_link_settings *max,
+               struct dc_link_settings *cur,
+               enum link_training_result training_result);
+
+bool dp_verify_link_cap_with_retries(
+       struct dc_link *link,
+       struct dc_link_settings *known_limit_link_setting,
+       int attempts);
+
+#endif /* __DC_LINK_DP_CAPABILITY_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia.c
new file mode 100644 (file)
index 0000000..6136db3
--- /dev/null
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#include "dc.h"
+#include "inc/core_status.h"
+#include "dc_link.h"
+#include "dc_link_dp.h"
+#include "dpcd_defs.h"
+
+#include "link_dp_dpia.h"
+#include "link_hwss.h"
+#include "dm_helpers.h"
+#include "dmub/inc/dmub_cmd.h"
+#include "link_dpcd.h"
+#include "link_dp_training.h"
+#include "dc_dmub_srv.h"
+
+#define DC_LOGGER \
+       link->ctx->logger
+
+/** @note Can remove once DP tunneling registers in upstream include/drm/drm_dp_helper.h */
+/* DPCD DP Tunneling over USB4 */
+#define DP_TUNNELING_CAPABILITIES_SUPPORT 0xe000d
+#define DP_IN_ADAPTER_INFO                0xe000e
+#define DP_USB4_DRIVER_ID                 0xe000f
+#define DP_USB4_ROUTER_TOPOLOGY_ID        0xe001b
+
+enum dc_status dpcd_get_tunneling_device_data(struct dc_link *link)
+{
+       enum dc_status status = DC_OK;
+       uint8_t dpcd_dp_tun_data[3] = {0};
+       uint8_t dpcd_topology_data[DPCD_USB4_TOPOLOGY_ID_LEN] = {0};
+       uint8_t i = 0;
+
+       status = core_link_read_dpcd(
+                       link,
+                       DP_TUNNELING_CAPABILITIES_SUPPORT,
+                       dpcd_dp_tun_data,
+                       sizeof(dpcd_dp_tun_data));
+
+       status = core_link_read_dpcd(
+                       link,
+                       DP_USB4_ROUTER_TOPOLOGY_ID,
+                       dpcd_topology_data,
+                       sizeof(dpcd_topology_data));
+
+       link->dpcd_caps.usb4_dp_tun_info.dp_tun_cap.raw =
+                       dpcd_dp_tun_data[DP_TUNNELING_CAPABILITIES_SUPPORT - DP_TUNNELING_CAPABILITIES_SUPPORT];
+       link->dpcd_caps.usb4_dp_tun_info.dpia_info.raw =
+                       dpcd_dp_tun_data[DP_IN_ADAPTER_INFO - DP_TUNNELING_CAPABILITIES_SUPPORT];
+       link->dpcd_caps.usb4_dp_tun_info.usb4_driver_id =
+                       dpcd_dp_tun_data[DP_USB4_DRIVER_ID - DP_TUNNELING_CAPABILITIES_SUPPORT];
+
+       for (i = 0; i < DPCD_USB4_TOPOLOGY_ID_LEN; i++)
+               link->dpcd_caps.usb4_dp_tun_info.usb4_topology_id[i] = dpcd_topology_data[i];
+
+       return status;
+}
+
+bool dc_link_dpia_query_hpd_status(struct dc_link *link)
+{
+       union dmub_rb_cmd cmd = {0};
+       struct dc_dmub_srv *dmub_srv = link->ctx->dmub_srv;
+       bool is_hpd_high = false;
+
+       /* prepare QUERY_HPD command */
+       cmd.query_hpd.header.type = DMUB_CMD__QUERY_HPD_STATE;
+       cmd.query_hpd.data.instance = link->link_id.enum_id - ENUM_ID_1;
+       cmd.query_hpd.data.ch_type = AUX_CHANNEL_DPIA;
+
+       /* Return HPD status reported by DMUB if query successfully executed. */
+       if (dc_dmub_srv_cmd_with_reply_data(dmub_srv, &cmd) && cmd.query_hpd.data.status == AUX_RET_SUCCESS)
+               is_hpd_high = cmd.query_hpd.data.result;
+
+       DC_LOG_DEBUG("%s: link(%d) dpia(%d) cmd_status(%d) result(%d)\n",
+               __func__,
+               link->link_index,
+               link->link_id.enum_id - ENUM_ID_1,
+               cmd.query_hpd.data.status,
+               cmd.query_hpd.data.result);
+
+       return is_hpd_high;
+}
+
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia.h
new file mode 100644 (file)
index 0000000..98935cc
--- /dev/null
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#ifndef __DC_LINK_DPIA_H__
+#define __DC_LINK_DPIA_H__
+
+#include "link.h"
+
+/* Read tunneling device capability from DPCD and update link capability
+ * accordingly.
+ */
+enum dc_status dpcd_get_tunneling_device_data(struct dc_link *link);
+
+/* Query hot plug status of USB4 DP tunnel.
+ * Returns true if HPD high.
+ */
+bool dc_link_dpia_query_hpd_status(struct dc_link *link);
+
+
+#endif /* __DC_LINK_DPIA_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c
new file mode 100644 (file)
index 0000000..801a95b
--- /dev/null
@@ -0,0 +1,28 @@
+
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+/*********************************************************************/
+//                             USB4 DPIA BANDWIDTH ALLOCATION LOGIC
+/*********************************************************************/
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.h
new file mode 100644 (file)
index 0000000..58eb7b5
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#ifndef DC_INC_LINK_DP_DPIA_BW_H_
+#define DC_INC_LINK_DP_DPIA_BW_H_
+
+/*
+ * Host Router BW type
+ */
+enum bw_type {
+       HOST_ROUTER_BW_ESTIMATED,
+       HOST_ROUTER_BW_ALLOCATED,
+       HOST_ROUTER_BW_INVALID,
+};
+
+/*
+ * Enable BW Allocation Mode Support from the DP-Tx side
+ *
+ * @link: pointer to the dc_link struct instance
+ *
+ * return: SUCCESS or FAILURE
+ */
+bool set_dptx_usb4_bw_alloc_support(struct dc_link *link);
+
+/*
+ * Send a request from DP-Tx requesting to allocate BW remotely after
+ * allocating it locally. This will get processed by CM and a CB function
+ * will be called.
+ *
+ * @link: pointer to the dc_link struct instance
+ * @req_bw: The requested bw in Kbyte to allocated
+ *
+ * return: none
+ */
+void set_usb4_req_bw_req(struct dc_link *link, int req_bw);
+
+/*
+ * CB function for when the status of the Req above is complete. We will
+ * find out the result of allocating on CM and update structs accordingly
+ *
+ * @link: pointer to the dc_link struct instance
+ * @bw: Allocated or Estimated BW depending on the result
+ * @result: Response type
+ *
+ * return: none
+ */
+void get_usb4_req_bw_resp(struct dc_link *link, uint8_t bw, uint8_t result);
+
+/*
+ * Return the response_ready flag from dc_link struct
+ *
+ * @link: pointer to the dc_link struct instance
+ *
+ * return: response_ready flag from dc_link struct
+ */
+bool get_cm_response_ready_flag(struct dc_link *link);
+
+/*
+ * Get the Max Available BW or Max Estimated BW for each Host Router
+ *
+ * @link: pointer to the dc_link struct instance
+ * @type: ESTIMATD BW or MAX AVAILABLE BW
+ *
+ * return: response_ready flag from dc_link struct
+ */
+int get_host_router_total_bw(struct dc_link *link, uint8_t type);
+
+/*
+ * Cleanup function for when the dpia is unplugged to reset struct
+ * and perform any required clean up
+ *
+ * @link: pointer to the dc_link struct instance
+ *
+ * return: none
+ */
+bool dpia_bw_alloc_unplug(struct dc_link *link);
+
+#endif /* DC_INC_LINK_DP_DPIA_BW_H_ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.c
new file mode 100644 (file)
index 0000000..b7f7ff4
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ * This file implements basic dp phy functionality such as enable/disable phy
+ * output and set lane/drive settings. This file is responsible for maintaining
+ * and update software state representing current phy status such as current
+ * link settings.
+ */
+
+#include "link_dp_phy.h"
+#include "link_dpcd.h"
+#include "link_dp_training.h"
+#include "link_dp_capability.h"
+#include "clk_mgr.h"
+#include "resource.h"
+#include "dc_link_dp.h"
+
+#define DC_LOGGER \
+       link->ctx->logger
+
+void dc_link_dp_receiver_power_ctrl(struct dc_link *link, bool on)
+{
+       uint8_t state;
+
+       state = on ? DP_POWER_STATE_D0 : DP_POWER_STATE_D3;
+
+       if (link->sync_lt_in_progress)
+               return;
+
+       core_link_write_dpcd(link, DP_SET_POWER, &state,
+                                                sizeof(state));
+
+}
+
+void dp_enable_link_phy(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       enum signal_type signal,
+       enum clock_source_id clock_source,
+       const struct dc_link_settings *link_settings)
+{
+       link->cur_link_settings = *link_settings;
+       link->dc->hwss.enable_dp_link_output(link, link_res, signal,
+                       clock_source, link_settings);
+       dc_link_dp_receiver_power_ctrl(link, true);
+}
+
+void dp_disable_link_phy(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal)
+{
+       struct dc  *dc = link->ctx->dc;
+
+       if (!link->wa_flags.dp_keep_receiver_powered)
+               dc_link_dp_receiver_power_ctrl(link, false);
+
+       dc->hwss.disable_link_output(link, link_res, signal);
+       /* Clear current link setting.*/
+       memset(&link->cur_link_settings, 0,
+                       sizeof(link->cur_link_settings));
+
+       if (dc->clk_mgr->funcs->notify_link_rate_change)
+               dc->clk_mgr->funcs->notify_link_rate_change(dc->clk_mgr, link);
+}
+
+void dp_disable_link_phy_mst(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal)
+{
+       /* MST disable link only when no stream use the link */
+       if (link->mst_stream_alloc_table.stream_count > 0)
+               return;
+
+       dp_disable_link_phy(link, link_res, signal);
+
+       /* set the sink to SST mode after disabling the link */
+       dp_enable_mst_on_sink(link, false);
+}
+
+static inline bool is_immediate_downstream(struct dc_link *link, uint32_t offset)
+{
+       return (dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt) ==
+                       offset);
+}
+
+void dp_set_hw_lane_settings(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       const struct link_training_settings *link_settings,
+       uint32_t offset)
+{
+       const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
+
+       if ((link_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) &&
+                       !is_immediate_downstream(link, offset))
+               return;
+
+       if (link_hwss->ext.set_dp_lane_settings)
+               link_hwss->ext.set_dp_lane_settings(link, link_res,
+                               &link_settings->link_settings,
+                               link_settings->hw_lane_settings);
+
+       memmove(link->cur_lane_setting,
+                       link_settings->hw_lane_settings,
+                       sizeof(link->cur_lane_setting));
+}
+
+void dp_set_drive_settings(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings)
+{
+       /* program ASIC PHY settings*/
+       dp_set_hw_lane_settings(link, link_res, lt_settings, DPRX);
+
+       dp_hw_to_dpcd_lane_settings(lt_settings,
+                       lt_settings->hw_lane_settings,
+                       lt_settings->dpcd_lane_settings);
+
+       /* Notify DP sink the PHY settings from source */
+       dpcd_set_lane_settings(link, lt_settings, DPRX);
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.h
new file mode 100644 (file)
index 0000000..850da64
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#ifndef __DC_LINK_DP_PHY_H__
+#define __DC_LINK_DP_PHY_H__
+
+#include "link.h"
+void dp_enable_link_phy(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       enum signal_type signal,
+       enum clock_source_id clock_source,
+       const struct dc_link_settings *link_settings);
+
+void dp_disable_link_phy(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal);
+
+void dp_disable_link_phy_mst(struct dc_link *link,
+               const struct link_resource *link_res,
+               enum signal_type signal);
+
+void dp_set_hw_lane_settings(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct link_training_settings *link_settings,
+               uint32_t offset);
+
+void dp_set_drive_settings(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings);
+
+#endif /* __DC_LINK_DP_PHY_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c
new file mode 100644 (file)
index 0000000..9dbaeb2
--- /dev/null
@@ -0,0 +1,1700 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ * This file implements all generic dp link training helper functions and top
+ * level generic training sequence. All variations of dp link training sequence
+ * should be called inside the top level training functions in this file to
+ * ensure the integrity of our overall training procedure across different types
+ * of link encoding and back end hardware.
+ */
+#include "link_dp_training.h"
+#include "link_dp_training_8b_10b.h"
+#include "link_dp_training_128b_132b.h"
+#include "link_dp_training_auxless.h"
+#include "link_dp_training_dpia.h"
+#include "link_dp_training_fixed_vs_pe_retimer.h"
+#include "link_dpcd.h"
+#include "link/accessories/link_dp_trace.h"
+#include "link_dp_phy.h"
+#include "link_dp_capability.h"
+#include "dc_link_dp.h"
+#include "atomfirmware.h"
+#include "link_enc_cfg.h"
+#include "resource.h"
+#include "dm_helpers.h"
+
+#define DC_LOGGER \
+       link->ctx->logger
+
+#define POST_LT_ADJ_REQ_LIMIT 6
+#define POST_LT_ADJ_REQ_TIMEOUT 200
+
+void dp_log_training_result(
+       struct dc_link *link,
+       const struct link_training_settings *lt_settings,
+       enum link_training_result status)
+{
+       char *link_rate = "Unknown";
+       char *lt_result = "Unknown";
+       char *lt_spread = "Disabled";
+
+       switch (lt_settings->link_settings.link_rate) {
+       case LINK_RATE_LOW:
+               link_rate = "RBR";
+               break;
+       case LINK_RATE_RATE_2:
+               link_rate = "R2";
+               break;
+       case LINK_RATE_RATE_3:
+               link_rate = "R3";
+               break;
+       case LINK_RATE_HIGH:
+               link_rate = "HBR";
+               break;
+       case LINK_RATE_RBR2:
+               link_rate = "RBR2";
+               break;
+       case LINK_RATE_RATE_6:
+               link_rate = "R6";
+               break;
+       case LINK_RATE_HIGH2:
+               link_rate = "HBR2";
+               break;
+       case LINK_RATE_HIGH3:
+               link_rate = "HBR3";
+               break;
+       case LINK_RATE_UHBR10:
+               link_rate = "UHBR10";
+               break;
+       case LINK_RATE_UHBR13_5:
+               link_rate = "UHBR13.5";
+               break;
+       case LINK_RATE_UHBR20:
+               link_rate = "UHBR20";
+               break;
+       default:
+               break;
+       }
+
+       switch (status) {
+       case LINK_TRAINING_SUCCESS:
+               lt_result = "pass";
+               break;
+       case LINK_TRAINING_CR_FAIL_LANE0:
+               lt_result = "CR failed lane0";
+               break;
+       case LINK_TRAINING_CR_FAIL_LANE1:
+               lt_result = "CR failed lane1";
+               break;
+       case LINK_TRAINING_CR_FAIL_LANE23:
+               lt_result = "CR failed lane23";
+               break;
+       case LINK_TRAINING_EQ_FAIL_CR:
+               lt_result = "CR failed in EQ";
+               break;
+       case LINK_TRAINING_EQ_FAIL_CR_PARTIAL:
+               lt_result = "CR failed in EQ partially";
+               break;
+       case LINK_TRAINING_EQ_FAIL_EQ:
+               lt_result = "EQ failed";
+               break;
+       case LINK_TRAINING_LQA_FAIL:
+               lt_result = "LQA failed";
+               break;
+       case LINK_TRAINING_LINK_LOSS:
+               lt_result = "Link loss";
+               break;
+       case DP_128b_132b_LT_FAILED:
+               lt_result = "LT_FAILED received";
+               break;
+       case DP_128b_132b_MAX_LOOP_COUNT_REACHED:
+               lt_result = "max loop count reached";
+               break;
+       case DP_128b_132b_CHANNEL_EQ_DONE_TIMEOUT:
+               lt_result = "channel EQ timeout";
+               break;
+       case DP_128b_132b_CDS_DONE_TIMEOUT:
+               lt_result = "CDS timeout";
+               break;
+       default:
+               break;
+       }
+
+       switch (lt_settings->link_settings.link_spread) {
+       case LINK_SPREAD_DISABLED:
+               lt_spread = "Disabled";
+               break;
+       case LINK_SPREAD_05_DOWNSPREAD_30KHZ:
+               lt_spread = "0.5% 30KHz";
+               break;
+       case LINK_SPREAD_05_DOWNSPREAD_33KHZ:
+               lt_spread = "0.5% 33KHz";
+               break;
+       default:
+               break;
+       }
+
+       /* Connectivity log: link training */
+
+       /* TODO - DP2.0 Log: add connectivity log for FFE PRESET */
+
+       CONN_MSG_LT(link, "%sx%d %s VS=%d, PE=%d, DS=%s",
+                               link_rate,
+                               lt_settings->link_settings.lane_count,
+                               lt_result,
+                               lt_settings->hw_lane_settings[0].VOLTAGE_SWING,
+                               lt_settings->hw_lane_settings[0].PRE_EMPHASIS,
+                               lt_spread);
+}
+
+uint8_t dp_initialize_scrambling_data_symbols(
+       struct dc_link *link,
+       enum dc_dp_training_pattern pattern)
+{
+       uint8_t disable_scrabled_data_symbols = 0;
+
+       switch (pattern) {
+       case DP_TRAINING_PATTERN_SEQUENCE_1:
+       case DP_TRAINING_PATTERN_SEQUENCE_2:
+       case DP_TRAINING_PATTERN_SEQUENCE_3:
+               disable_scrabled_data_symbols = 1;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_4:
+       case DP_128b_132b_TPS1:
+       case DP_128b_132b_TPS2:
+               disable_scrabled_data_symbols = 0;
+               break;
+       default:
+               ASSERT(0);
+               DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
+                       __func__, pattern);
+               break;
+       }
+       return disable_scrabled_data_symbols;
+}
+
+enum dpcd_training_patterns
+       dp_training_pattern_to_dpcd_training_pattern(
+       struct dc_link *link,
+       enum dc_dp_training_pattern pattern)
+{
+       enum dpcd_training_patterns dpcd_tr_pattern =
+       DPCD_TRAINING_PATTERN_VIDEOIDLE;
+
+       switch (pattern) {
+       case DP_TRAINING_PATTERN_SEQUENCE_1:
+               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_1;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_2:
+               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_2;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_3:
+               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_3;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_4:
+               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_4;
+               break;
+       case DP_128b_132b_TPS1:
+               dpcd_tr_pattern = DPCD_128b_132b_TPS1;
+               break;
+       case DP_128b_132b_TPS2:
+               dpcd_tr_pattern = DPCD_128b_132b_TPS2;
+               break;
+       case DP_128b_132b_TPS2_CDS:
+               dpcd_tr_pattern = DPCD_128b_132b_TPS2_CDS;
+               break;
+       case DP_TRAINING_PATTERN_VIDEOIDLE:
+               dpcd_tr_pattern = DPCD_TRAINING_PATTERN_VIDEOIDLE;
+               break;
+       default:
+               ASSERT(0);
+               DC_LOG_HW_LINK_TRAINING("%s: Invalid HW Training pattern: %d\n",
+                       __func__, pattern);
+               break;
+       }
+
+       return dpcd_tr_pattern;
+}
+
+static uint8_t get_nibble_at_index(const uint8_t *buf,
+       uint32_t index)
+{
+       uint8_t nibble;
+       nibble = buf[index / 2];
+
+       if (index % 2)
+               nibble >>= 4;
+       else
+               nibble &= 0x0F;
+
+       return nibble;
+}
+
+void dp_wait_for_training_aux_rd_interval(
+       struct dc_link *link,
+       uint32_t wait_in_micro_secs)
+{
+       if (wait_in_micro_secs > 1000)
+               msleep(wait_in_micro_secs/1000);
+       else
+               udelay(wait_in_micro_secs);
+
+       DC_LOG_HW_LINK_TRAINING("%s:\n wait = %d\n",
+               __func__,
+               wait_in_micro_secs);
+}
+
+/* maximum pre emphasis level allowed for each voltage swing level*/
+static const enum dc_pre_emphasis voltage_swing_to_pre_emphasis[] = {
+               PRE_EMPHASIS_LEVEL3,
+               PRE_EMPHASIS_LEVEL2,
+               PRE_EMPHASIS_LEVEL1,
+               PRE_EMPHASIS_DISABLED };
+
+static enum dc_pre_emphasis get_max_pre_emphasis_for_voltage_swing(
+       enum dc_voltage_swing voltage)
+{
+       enum dc_pre_emphasis pre_emphasis;
+       pre_emphasis = PRE_EMPHASIS_MAX_LEVEL;
+
+       if (voltage <= VOLTAGE_SWING_MAX_LEVEL)
+               pre_emphasis = voltage_swing_to_pre_emphasis[voltage];
+
+       return pre_emphasis;
+
+}
+
+static void maximize_lane_settings(const struct link_training_settings *lt_settings,
+               struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
+{
+       uint32_t lane;
+       struct dc_lane_settings max_requested;
+
+       max_requested.VOLTAGE_SWING = lane_settings[0].VOLTAGE_SWING;
+       max_requested.PRE_EMPHASIS = lane_settings[0].PRE_EMPHASIS;
+       max_requested.FFE_PRESET = lane_settings[0].FFE_PRESET;
+
+       /* Determine what the maximum of the requested settings are*/
+       for (lane = 1; lane < lt_settings->link_settings.lane_count; lane++) {
+               if (lane_settings[lane].VOLTAGE_SWING > max_requested.VOLTAGE_SWING)
+                       max_requested.VOLTAGE_SWING = lane_settings[lane].VOLTAGE_SWING;
+
+               if (lane_settings[lane].PRE_EMPHASIS > max_requested.PRE_EMPHASIS)
+                       max_requested.PRE_EMPHASIS = lane_settings[lane].PRE_EMPHASIS;
+               if (lane_settings[lane].FFE_PRESET.settings.level >
+                               max_requested.FFE_PRESET.settings.level)
+                       max_requested.FFE_PRESET.settings.level =
+                                       lane_settings[lane].FFE_PRESET.settings.level;
+       }
+
+       /* make sure the requested settings are
+        * not higher than maximum settings*/
+       if (max_requested.VOLTAGE_SWING > VOLTAGE_SWING_MAX_LEVEL)
+               max_requested.VOLTAGE_SWING = VOLTAGE_SWING_MAX_LEVEL;
+
+       if (max_requested.PRE_EMPHASIS > PRE_EMPHASIS_MAX_LEVEL)
+               max_requested.PRE_EMPHASIS = PRE_EMPHASIS_MAX_LEVEL;
+       if (max_requested.FFE_PRESET.settings.level > DP_FFE_PRESET_MAX_LEVEL)
+               max_requested.FFE_PRESET.settings.level = DP_FFE_PRESET_MAX_LEVEL;
+
+       /* make sure the pre-emphasis matches the voltage swing*/
+       if (max_requested.PRE_EMPHASIS >
+               get_max_pre_emphasis_for_voltage_swing(
+                       max_requested.VOLTAGE_SWING))
+               max_requested.PRE_EMPHASIS =
+               get_max_pre_emphasis_for_voltage_swing(
+                       max_requested.VOLTAGE_SWING);
+
+       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+               lane_settings[lane].VOLTAGE_SWING = max_requested.VOLTAGE_SWING;
+               lane_settings[lane].PRE_EMPHASIS = max_requested.PRE_EMPHASIS;
+               lane_settings[lane].FFE_PRESET = max_requested.FFE_PRESET;
+       }
+}
+
+void dp_hw_to_dpcd_lane_settings(
+               const struct link_training_settings *lt_settings,
+               const struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
+               union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX])
+{
+       uint8_t lane = 0;
+
+       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_8b_10b_ENCODING) {
+                       dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET =
+                                       (uint8_t)(hw_lane_settings[lane].VOLTAGE_SWING);
+                       dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET =
+                                       (uint8_t)(hw_lane_settings[lane].PRE_EMPHASIS);
+                       dpcd_lane_settings[lane].bits.MAX_SWING_REACHED =
+                                       (hw_lane_settings[lane].VOLTAGE_SWING ==
+                                                       VOLTAGE_SWING_MAX_LEVEL ? 1 : 0);
+                       dpcd_lane_settings[lane].bits.MAX_PRE_EMPHASIS_REACHED =
+                                       (hw_lane_settings[lane].PRE_EMPHASIS ==
+                                                       PRE_EMPHASIS_MAX_LEVEL ? 1 : 0);
+               } else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_128b_132b_ENCODING) {
+                       dpcd_lane_settings[lane].tx_ffe.PRESET_VALUE =
+                                       hw_lane_settings[lane].FFE_PRESET.settings.level;
+               }
+       }
+}
+
+uint8_t get_dpcd_link_rate(const struct dc_link_settings *link_settings)
+{
+       uint8_t link_rate = 0;
+       enum dp_link_encoding encoding = link_dp_get_encoding_format(link_settings);
+
+       if (encoding == DP_128b_132b_ENCODING)
+               switch (link_settings->link_rate) {
+               case LINK_RATE_UHBR10:
+                       link_rate = 0x1;
+                       break;
+               case LINK_RATE_UHBR20:
+                       link_rate = 0x2;
+                       break;
+               case LINK_RATE_UHBR13_5:
+                       link_rate = 0x4;
+                       break;
+               default:
+                       link_rate = 0;
+                       break;
+               }
+       else if (encoding == DP_8b_10b_ENCODING)
+               link_rate = (uint8_t) link_settings->link_rate;
+       else
+               link_rate = 0;
+
+       return link_rate;
+}
+
+/* Only used for channel equalization */
+uint32_t dp_translate_training_aux_read_interval(uint32_t dpcd_aux_read_interval)
+{
+       unsigned int aux_rd_interval_us = 400;
+
+       switch (dpcd_aux_read_interval) {
+       case 0x01:
+               aux_rd_interval_us = 4000;
+               break;
+       case 0x02:
+               aux_rd_interval_us = 8000;
+               break;
+       case 0x03:
+               aux_rd_interval_us = 12000;
+               break;
+       case 0x04:
+               aux_rd_interval_us = 16000;
+               break;
+       case 0x05:
+               aux_rd_interval_us = 32000;
+               break;
+       case 0x06:
+               aux_rd_interval_us = 64000;
+               break;
+       default:
+               break;
+       }
+
+       return aux_rd_interval_us;
+}
+
+enum link_training_result dp_get_cr_failure(enum dc_lane_count ln_count,
+                                       union lane_status *dpcd_lane_status)
+{
+       enum link_training_result result = LINK_TRAINING_SUCCESS;
+
+       if (ln_count >= LANE_COUNT_ONE && !dpcd_lane_status[0].bits.CR_DONE_0)
+               result = LINK_TRAINING_CR_FAIL_LANE0;
+       else if (ln_count >= LANE_COUNT_TWO && !dpcd_lane_status[1].bits.CR_DONE_0)
+               result = LINK_TRAINING_CR_FAIL_LANE1;
+       else if (ln_count >= LANE_COUNT_FOUR && !dpcd_lane_status[2].bits.CR_DONE_0)
+               result = LINK_TRAINING_CR_FAIL_LANE23;
+       else if (ln_count >= LANE_COUNT_FOUR && !dpcd_lane_status[3].bits.CR_DONE_0)
+               result = LINK_TRAINING_CR_FAIL_LANE23;
+       return result;
+}
+
+bool is_repeater(const struct link_training_settings *lt_settings, uint32_t offset)
+{
+       return (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) && (offset != 0);
+}
+
+bool dp_is_max_vs_reached(
+       const struct link_training_settings *lt_settings)
+{
+       uint32_t lane;
+       for (lane = 0; lane <
+               (uint32_t)(lt_settings->link_settings.lane_count);
+               lane++) {
+               if (lt_settings->dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET
+                       == VOLTAGE_SWING_MAX_LEVEL)
+                       return true;
+       }
+       return false;
+
+}
+
+bool dp_is_cr_done(enum dc_lane_count ln_count,
+       union lane_status *dpcd_lane_status)
+{
+       bool done = true;
+       uint32_t lane;
+       /*LANEx_CR_DONE bits All 1's?*/
+       for (lane = 0; lane < (uint32_t)(ln_count); lane++) {
+               if (!dpcd_lane_status[lane].bits.CR_DONE_0)
+                       done = false;
+       }
+       return done;
+
+}
+
+bool dp_is_ch_eq_done(enum dc_lane_count ln_count,
+               union lane_status *dpcd_lane_status)
+{
+       bool done = true;
+       uint32_t lane;
+       for (lane = 0; lane < (uint32_t)(ln_count); lane++)
+               if (!dpcd_lane_status[lane].bits.CHANNEL_EQ_DONE_0)
+                       done = false;
+       return done;
+}
+
+bool dp_is_symbol_locked(enum dc_lane_count ln_count,
+               union lane_status *dpcd_lane_status)
+{
+       bool locked = true;
+       uint32_t lane;
+       for (lane = 0; lane < (uint32_t)(ln_count); lane++)
+               if (!dpcd_lane_status[lane].bits.SYMBOL_LOCKED_0)
+                       locked = false;
+       return locked;
+}
+
+bool dp_is_interlane_aligned(union lane_align_status_updated align_status)
+{
+       return align_status.bits.INTERLANE_ALIGN_DONE == 1;
+}
+
+enum link_training_result dp_check_link_loss_status(
+       struct dc_link *link,
+       const struct link_training_settings *link_training_setting)
+{
+       enum link_training_result status = LINK_TRAINING_SUCCESS;
+       union lane_status lane_status;
+       uint8_t dpcd_buf[6] = {0};
+       uint32_t lane;
+
+       core_link_read_dpcd(
+                       link,
+                       DP_SINK_COUNT,
+                       (uint8_t *)(dpcd_buf),
+                       sizeof(dpcd_buf));
+
+       /*parse lane status*/
+       for (lane = 0; lane < link->cur_link_settings.lane_count; lane++) {
+               /*
+                * check lanes status
+                */
+               lane_status.raw = get_nibble_at_index(&dpcd_buf[2], lane);
+
+               if (!lane_status.bits.CHANNEL_EQ_DONE_0 ||
+                       !lane_status.bits.CR_DONE_0 ||
+                       !lane_status.bits.SYMBOL_LOCKED_0) {
+                       /* if one of the channel equalization, clock
+                        * recovery or symbol lock is dropped
+                        * consider it as (link has been
+                        * dropped) dp sink status has changed
+                        */
+                       status = LINK_TRAINING_LINK_LOSS;
+                       break;
+               }
+       }
+
+       return status;
+}
+
+enum dc_status dp_get_lane_status_and_lane_adjust(
+       struct dc_link *link,
+       const struct link_training_settings *link_training_setting,
+       union lane_status ln_status[LANE_COUNT_DP_MAX],
+       union lane_align_status_updated *ln_align,
+       union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
+       uint32_t offset)
+{
+       unsigned int lane01_status_address = DP_LANE0_1_STATUS;
+       uint8_t lane_adjust_offset = 4;
+       unsigned int lane01_adjust_address;
+       uint8_t dpcd_buf[6] = {0};
+       uint32_t lane;
+       enum dc_status status;
+
+       if (is_repeater(link_training_setting, offset)) {
+               lane01_status_address =
+                               DP_LANE0_1_STATUS_PHY_REPEATER1 +
+                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+               lane_adjust_offset = 3;
+       }
+
+       status = core_link_read_dpcd(
+               link,
+               lane01_status_address,
+               (uint8_t *)(dpcd_buf),
+               sizeof(dpcd_buf));
+
+       if (status != DC_OK) {
+               DC_LOG_HW_LINK_TRAINING("%s:\n Failed to read from address 0x%X,"
+                       " keep current lane status and lane adjust unchanged",
+                       __func__,
+                       lane01_status_address);
+               return status;
+       }
+
+       for (lane = 0; lane <
+               (uint32_t)(link_training_setting->link_settings.lane_count);
+               lane++) {
+
+               ln_status[lane].raw =
+                       get_nibble_at_index(&dpcd_buf[0], lane);
+               ln_adjust[lane].raw =
+                       get_nibble_at_index(&dpcd_buf[lane_adjust_offset], lane);
+       }
+
+       ln_align->raw = dpcd_buf[2];
+
+       if (is_repeater(link_training_setting, offset)) {
+               DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
+                               " 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
+                       __func__,
+                       offset,
+                       lane01_status_address, dpcd_buf[0],
+                       lane01_status_address + 1, dpcd_buf[1]);
+
+               lane01_adjust_address = DP_ADJUST_REQUEST_LANE0_1_PHY_REPEATER1 +
+                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+
+               DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
+                               " 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
+                                       __func__,
+                                       offset,
+                                       lane01_adjust_address,
+                                       dpcd_buf[lane_adjust_offset],
+                                       lane01_adjust_address + 1,
+                                       dpcd_buf[lane_adjust_offset + 1]);
+       } else {
+               DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01Status = %x\n 0x%X Lane23Status = %x\n ",
+                       __func__,
+                       lane01_status_address, dpcd_buf[0],
+                       lane01_status_address + 1, dpcd_buf[1]);
+
+               lane01_adjust_address = DP_ADJUST_REQUEST_LANE0_1;
+
+               DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X Lane01AdjustRequest = %x\n 0x%X Lane23AdjustRequest = %x\n",
+                       __func__,
+                       lane01_adjust_address,
+                       dpcd_buf[lane_adjust_offset],
+                       lane01_adjust_address + 1,
+                       dpcd_buf[lane_adjust_offset + 1]);
+       }
+
+       return status;
+}
+
+static void override_lane_settings(const struct link_training_settings *lt_settings,
+               struct dc_lane_settings lane_settings[LANE_COUNT_DP_MAX])
+{
+       uint32_t lane;
+
+       if (lt_settings->voltage_swing == NULL &&
+                       lt_settings->pre_emphasis == NULL &&
+                       lt_settings->ffe_preset == NULL &&
+                       lt_settings->post_cursor2 == NULL)
+
+               return;
+
+       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+               if (lt_settings->voltage_swing)
+                       lane_settings[lane].VOLTAGE_SWING = *lt_settings->voltage_swing;
+               if (lt_settings->pre_emphasis)
+                       lane_settings[lane].PRE_EMPHASIS = *lt_settings->pre_emphasis;
+               if (lt_settings->post_cursor2)
+                       lane_settings[lane].POST_CURSOR2 = *lt_settings->post_cursor2;
+               if (lt_settings->ffe_preset)
+                       lane_settings[lane].FFE_PRESET = *lt_settings->ffe_preset;
+       }
+}
+
+void dp_get_lttpr_mode_override(struct dc_link *link, enum lttpr_mode *override)
+{
+       if (!dp_is_lttpr_present(link))
+               return;
+
+       if (link->dc->debug.lttpr_mode_override == LTTPR_MODE_TRANSPARENT) {
+               *override = LTTPR_MODE_TRANSPARENT;
+       } else if (link->dc->debug.lttpr_mode_override == LTTPR_MODE_NON_TRANSPARENT) {
+               *override = LTTPR_MODE_NON_TRANSPARENT;
+       } else if (link->dc->debug.lttpr_mode_override == LTTPR_MODE_NON_LTTPR) {
+               *override = LTTPR_MODE_NON_LTTPR;
+       }
+       DC_LOG_DC("lttpr_mode_override chose LTTPR_MODE = %d\n", (uint8_t)(*override));
+}
+
+void override_training_settings(
+               struct dc_link *link,
+               const struct dc_link_training_overrides *overrides,
+               struct link_training_settings *lt_settings)
+{
+       uint32_t lane;
+
+       /* Override link spread */
+       if (!link->dp_ss_off && overrides->downspread != NULL)
+               lt_settings->link_settings.link_spread = *overrides->downspread ?
+                               LINK_SPREAD_05_DOWNSPREAD_30KHZ
+                               : LINK_SPREAD_DISABLED;
+
+       /* Override lane settings */
+       if (overrides->voltage_swing != NULL)
+               lt_settings->voltage_swing = overrides->voltage_swing;
+       if (overrides->pre_emphasis != NULL)
+               lt_settings->pre_emphasis = overrides->pre_emphasis;
+       if (overrides->post_cursor2 != NULL)
+               lt_settings->post_cursor2 = overrides->post_cursor2;
+       if (overrides->ffe_preset != NULL)
+               lt_settings->ffe_preset = overrides->ffe_preset;
+       /* Override HW lane settings with BIOS forced values if present */
+       if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
+                       lt_settings->lttpr_mode == LTTPR_MODE_TRANSPARENT) {
+               lt_settings->voltage_swing = &link->bios_forced_drive_settings.VOLTAGE_SWING;
+               lt_settings->pre_emphasis = &link->bios_forced_drive_settings.PRE_EMPHASIS;
+               lt_settings->always_match_dpcd_with_hw_lane_settings = false;
+       }
+       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+               lt_settings->hw_lane_settings[lane].VOLTAGE_SWING =
+                       lt_settings->voltage_swing != NULL ?
+                       *lt_settings->voltage_swing :
+                       VOLTAGE_SWING_LEVEL0;
+               lt_settings->hw_lane_settings[lane].PRE_EMPHASIS =
+                       lt_settings->pre_emphasis != NULL ?
+                       *lt_settings->pre_emphasis
+                       : PRE_EMPHASIS_DISABLED;
+               lt_settings->hw_lane_settings[lane].POST_CURSOR2 =
+                       lt_settings->post_cursor2 != NULL ?
+                       *lt_settings->post_cursor2
+                       : POST_CURSOR2_DISABLED;
+       }
+
+       if (lt_settings->always_match_dpcd_with_hw_lane_settings)
+               dp_hw_to_dpcd_lane_settings(lt_settings,
+                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+
+       /* Override training timings */
+       if (overrides->cr_pattern_time != NULL)
+               lt_settings->cr_pattern_time = *overrides->cr_pattern_time;
+       if (overrides->eq_pattern_time != NULL)
+               lt_settings->eq_pattern_time = *overrides->eq_pattern_time;
+       if (overrides->pattern_for_cr != NULL)
+               lt_settings->pattern_for_cr = *overrides->pattern_for_cr;
+       if (overrides->pattern_for_eq != NULL)
+               lt_settings->pattern_for_eq = *overrides->pattern_for_eq;
+       if (overrides->enhanced_framing != NULL)
+               lt_settings->enhanced_framing = *overrides->enhanced_framing;
+       if (link->preferred_training_settings.fec_enable != NULL)
+               lt_settings->should_set_fec_ready = *link->preferred_training_settings.fec_enable;
+
+#if defined(CONFIG_DRM_AMD_DC_DCN)
+       /* Check DP tunnel LTTPR mode debug option. */
+       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA && link->dc->debug.dpia_debug.bits.force_non_lttpr)
+               lt_settings->lttpr_mode = LTTPR_MODE_NON_LTTPR;
+
+#endif
+       dp_get_lttpr_mode_override(link, &lt_settings->lttpr_mode);
+
+}
+
+enum dc_dp_training_pattern decide_cr_training_pattern(
+               const struct dc_link_settings *link_settings)
+{
+       switch (link_dp_get_encoding_format(link_settings)) {
+       case DP_8b_10b_ENCODING:
+       default:
+               return DP_TRAINING_PATTERN_SEQUENCE_1;
+       case DP_128b_132b_ENCODING:
+               return DP_128b_132b_TPS1;
+       }
+}
+
+enum dc_dp_training_pattern decide_eq_training_pattern(struct dc_link *link,
+               const struct dc_link_settings *link_settings)
+{
+       struct link_encoder *link_enc;
+       struct encoder_feature_support *enc_caps;
+       struct dpcd_caps *rx_caps = &link->dpcd_caps;
+       enum dc_dp_training_pattern pattern = DP_TRAINING_PATTERN_SEQUENCE_2;
+
+       link_enc = link_enc_cfg_get_link_enc(link);
+       ASSERT(link_enc);
+       enc_caps = &link_enc->features;
+
+       switch (link_dp_get_encoding_format(link_settings)) {
+       case DP_8b_10b_ENCODING:
+               if (enc_caps->flags.bits.IS_TPS4_CAPABLE &&
+                               rx_caps->max_down_spread.bits.TPS4_SUPPORTED)
+                       pattern = DP_TRAINING_PATTERN_SEQUENCE_4;
+               else if (enc_caps->flags.bits.IS_TPS3_CAPABLE &&
+                               rx_caps->max_ln_count.bits.TPS3_SUPPORTED)
+                       pattern = DP_TRAINING_PATTERN_SEQUENCE_3;
+               else
+                       pattern = DP_TRAINING_PATTERN_SEQUENCE_2;
+               break;
+       case DP_128b_132b_ENCODING:
+               pattern = DP_128b_132b_TPS2;
+               break;
+       default:
+               pattern = DP_TRAINING_PATTERN_SEQUENCE_2;
+               break;
+       }
+       return pattern;
+}
+
+enum lttpr_mode dc_link_decide_lttpr_mode(struct dc_link *link,
+               struct dc_link_settings *link_setting)
+{
+       enum dp_link_encoding encoding = link_dp_get_encoding_format(link_setting);
+
+       if (encoding == DP_8b_10b_ENCODING)
+               return dp_decide_8b_10b_lttpr_mode(link);
+       else if (encoding == DP_128b_132b_ENCODING)
+               return dp_decide_128b_132b_lttpr_mode(link);
+
+       ASSERT(0);
+       return LTTPR_MODE_NON_LTTPR;
+}
+
+void dp_decide_lane_settings(
+               const struct link_training_settings *lt_settings,
+               const union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
+               struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
+               union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX])
+{
+       uint32_t lane;
+
+       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_8b_10b_ENCODING) {
+                       hw_lane_settings[lane].VOLTAGE_SWING =
+                                       (enum dc_voltage_swing)(ln_adjust[lane].bits.
+                                                       VOLTAGE_SWING_LANE);
+                       hw_lane_settings[lane].PRE_EMPHASIS =
+                                       (enum dc_pre_emphasis)(ln_adjust[lane].bits.
+                                                       PRE_EMPHASIS_LANE);
+               } else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_128b_132b_ENCODING) {
+                       hw_lane_settings[lane].FFE_PRESET.raw =
+                                       ln_adjust[lane].tx_ffe.PRESET_VALUE;
+               }
+       }
+       dp_hw_to_dpcd_lane_settings(lt_settings, hw_lane_settings, dpcd_lane_settings);
+
+       if (lt_settings->disallow_per_lane_settings) {
+               /* we find the maximum of the requested settings across all lanes*/
+               /* and set this maximum for all lanes*/
+               maximize_lane_settings(lt_settings, hw_lane_settings);
+               override_lane_settings(lt_settings, hw_lane_settings);
+
+               if (lt_settings->always_match_dpcd_with_hw_lane_settings)
+                       dp_hw_to_dpcd_lane_settings(lt_settings, hw_lane_settings, dpcd_lane_settings);
+       }
+
+}
+
+void dp_decide_training_settings(
+               struct dc_link *link,
+               const struct dc_link_settings *link_settings,
+               struct link_training_settings *lt_settings)
+{
+       if (link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING)
+               decide_8b_10b_training_settings(link, link_settings, lt_settings);
+       else if (link_dp_get_encoding_format(link_settings) == DP_128b_132b_ENCODING)
+               decide_128b_132b_training_settings(link, link_settings, lt_settings);
+}
+
+
+enum dc_status configure_lttpr_mode_transparent(struct dc_link *link)
+{
+       uint8_t repeater_mode = DP_PHY_REPEATER_MODE_TRANSPARENT;
+
+       DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Transparent Mode\n", __func__);
+       return core_link_write_dpcd(link,
+                       DP_PHY_REPEATER_MODE,
+                       (uint8_t *)&repeater_mode,
+                       sizeof(repeater_mode));
+}
+
+static enum dc_status configure_lttpr_mode_non_transparent(
+               struct dc_link *link,
+               const struct link_training_settings *lt_settings)
+{
+       /* aux timeout is already set to extended */
+       /* RESET/SET lttpr mode to enable non transparent mode */
+       uint8_t repeater_cnt;
+       uint32_t aux_interval_address;
+       uint8_t repeater_id;
+       enum dc_status result = DC_ERROR_UNEXPECTED;
+       uint8_t repeater_mode = DP_PHY_REPEATER_MODE_TRANSPARENT;
+
+       enum dp_link_encoding encoding = link_dp_get_encoding_format(&lt_settings->link_settings);
+
+       if (encoding == DP_8b_10b_ENCODING) {
+               DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Transparent Mode\n", __func__);
+               result = core_link_write_dpcd(link,
+                               DP_PHY_REPEATER_MODE,
+                               (uint8_t *)&repeater_mode,
+                               sizeof(repeater_mode));
+
+       }
+
+       if (result == DC_OK) {
+               link->dpcd_caps.lttpr_caps.mode = repeater_mode;
+       }
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
+
+               DC_LOG_HW_LINK_TRAINING("%s\n Set LTTPR to Non Transparent Mode\n", __func__);
+
+               repeater_mode = DP_PHY_REPEATER_MODE_NON_TRANSPARENT;
+               result = core_link_write_dpcd(link,
+                               DP_PHY_REPEATER_MODE,
+                               (uint8_t *)&repeater_mode,
+                               sizeof(repeater_mode));
+
+               if (result == DC_OK) {
+                       link->dpcd_caps.lttpr_caps.mode = repeater_mode;
+               }
+
+               if (encoding == DP_8b_10b_ENCODING) {
+                       repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+
+                       /* Driver does not need to train the first hop. Skip DPCD read and clear
+                        * AUX_RD_INTERVAL for DPTX-to-DPIA hop.
+                        */
+                       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
+                               link->dpcd_caps.lttpr_caps.aux_rd_interval[--repeater_cnt] = 0;
+
+                       for (repeater_id = repeater_cnt; repeater_id > 0; repeater_id--) {
+                               aux_interval_address = DP_TRAINING_AUX_RD_INTERVAL_PHY_REPEATER1 +
+                                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (repeater_id - 1));
+                               core_link_read_dpcd(
+                                               link,
+                                               aux_interval_address,
+                                               (uint8_t *)&link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1],
+                                               sizeof(link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1]));
+                               link->dpcd_caps.lttpr_caps.aux_rd_interval[repeater_id - 1] &= 0x7F;
+                       }
+               }
+       }
+
+       return result;
+}
+
+enum dc_status dpcd_configure_lttpr_mode(struct dc_link *link, struct link_training_settings *lt_settings)
+{
+       enum dc_status status = DC_OK;
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_TRANSPARENT)
+               status = configure_lttpr_mode_transparent(link);
+
+       else if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
+               status = configure_lttpr_mode_non_transparent(link, lt_settings);
+
+       return status;
+}
+
+void repeater_training_done(struct dc_link *link, uint32_t offset)
+{
+       union dpcd_training_pattern dpcd_pattern = {0};
+
+       const uint32_t dpcd_base_lt_offset =
+                       DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
+                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+       /* Set training not in progress*/
+       dpcd_pattern.v1_4.TRAINING_PATTERN_SET = DPCD_TRAINING_PATTERN_VIDEOIDLE;
+
+       core_link_write_dpcd(
+               link,
+               dpcd_base_lt_offset,
+               &dpcd_pattern.raw,
+               1);
+
+       DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Id: %d 0x%X pattern = %x\n",
+               __func__,
+               offset,
+               dpcd_base_lt_offset,
+               dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
+}
+
+static void dpcd_exit_training_mode(struct dc_link *link, enum dp_link_encoding encoding)
+{
+       uint8_t sink_status = 0;
+       uint8_t i;
+
+       /* clear training pattern set */
+       dpcd_set_training_pattern(link, DP_TRAINING_PATTERN_VIDEOIDLE);
+
+       if (encoding == DP_128b_132b_ENCODING) {
+               /* poll for intra-hop disable */
+               for (i = 0; i < 10; i++) {
+                       if ((core_link_read_dpcd(link, DP_SINK_STATUS, &sink_status, 1) == DC_OK) &&
+                                       (sink_status & DP_INTRA_HOP_AUX_REPLY_INDICATION) == 0)
+                               break;
+                       udelay(1000);
+               }
+       }
+}
+
+enum dc_status dpcd_configure_channel_coding(struct dc_link *link,
+               struct link_training_settings *lt_settings)
+{
+       enum dp_link_encoding encoding =
+                       link_dp_get_encoding_format(
+                                       &lt_settings->link_settings);
+       enum dc_status status;
+
+       status = core_link_write_dpcd(
+                       link,
+                       DP_MAIN_LINK_CHANNEL_CODING_SET,
+                       (uint8_t *) &encoding,
+                       1);
+       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X MAIN_LINK_CHANNEL_CODING_SET = %x\n",
+                                       __func__,
+                                       DP_MAIN_LINK_CHANNEL_CODING_SET,
+                                       encoding);
+
+       return status;
+}
+
+void dpcd_set_training_pattern(
+       struct dc_link *link,
+       enum dc_dp_training_pattern training_pattern)
+{
+       union dpcd_training_pattern dpcd_pattern = {0};
+
+       dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
+                       dp_training_pattern_to_dpcd_training_pattern(
+                                       link, training_pattern);
+
+       core_link_write_dpcd(
+               link,
+               DP_TRAINING_PATTERN_SET,
+               &dpcd_pattern.raw,
+               1);
+
+       DC_LOG_HW_LINK_TRAINING("%s\n %x pattern = %x\n",
+               __func__,
+               DP_TRAINING_PATTERN_SET,
+               dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
+}
+
+enum dc_status dpcd_set_link_settings(
+       struct dc_link *link,
+       const struct link_training_settings *lt_settings)
+{
+       uint8_t rate;
+       enum dc_status status;
+
+       union down_spread_ctrl downspread = {0};
+       union lane_count_set lane_count_set = {0};
+
+       downspread.raw = (uint8_t)
+       (lt_settings->link_settings.link_spread);
+
+       lane_count_set.bits.LANE_COUNT_SET =
+       lt_settings->link_settings.lane_count;
+
+       lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
+       lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
+
+
+       if (link->ep_type == DISPLAY_ENDPOINT_PHY &&
+                       lt_settings->pattern_for_eq < DP_TRAINING_PATTERN_SEQUENCE_4) {
+               lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED =
+                               link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED;
+       }
+
+       status = core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
+               &downspread.raw, sizeof(downspread));
+
+       status = core_link_write_dpcd(link, DP_LANE_COUNT_SET,
+               &lane_count_set.raw, 1);
+
+       if (link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_13 &&
+                       lt_settings->link_settings.use_link_rate_set == true) {
+               rate = 0;
+               /* WA for some MUX chips that will power down with eDP and lose supported
+                * link rate set for eDP 1.4. Source reads DPCD 0x010 again to ensure
+                * MUX chip gets link rate set back before link training.
+                */
+               if (link->connector_signal == SIGNAL_TYPE_EDP) {
+                       uint8_t supported_link_rates[16];
+
+                       core_link_read_dpcd(link, DP_SUPPORTED_LINK_RATES,
+                                       supported_link_rates, sizeof(supported_link_rates));
+               }
+               status = core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
+               status = core_link_write_dpcd(link, DP_LINK_RATE_SET,
+                               &lt_settings->link_settings.link_rate_set, 1);
+       } else {
+               rate = get_dpcd_link_rate(&lt_settings->link_settings);
+
+               status = core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
+       }
+
+       if (rate) {
+               DC_LOG_HW_LINK_TRAINING("%s\n %x rate = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
+                       __func__,
+                       DP_LINK_BW_SET,
+                       lt_settings->link_settings.link_rate,
+                       DP_LANE_COUNT_SET,
+                       lt_settings->link_settings.lane_count,
+                       lt_settings->enhanced_framing,
+                       DP_DOWNSPREAD_CTRL,
+                       lt_settings->link_settings.link_spread);
+       } else {
+               DC_LOG_HW_LINK_TRAINING("%s\n %x rate set = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
+                       __func__,
+                       DP_LINK_RATE_SET,
+                       lt_settings->link_settings.link_rate_set,
+                       DP_LANE_COUNT_SET,
+                       lt_settings->link_settings.lane_count,
+                       lt_settings->enhanced_framing,
+                       DP_DOWNSPREAD_CTRL,
+                       lt_settings->link_settings.link_spread);
+       }
+
+       return status;
+}
+
+enum dc_status dpcd_set_lane_settings(
+       struct dc_link *link,
+       const struct link_training_settings *link_training_setting,
+       uint32_t offset)
+{
+       unsigned int lane0_set_address;
+       enum dc_status status;
+       lane0_set_address = DP_TRAINING_LANE0_SET;
+
+       if (is_repeater(link_training_setting, offset))
+               lane0_set_address = DP_TRAINING_LANE0_SET_PHY_REPEATER1 +
+               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+
+       status = core_link_write_dpcd(link,
+               lane0_set_address,
+               (uint8_t *)(link_training_setting->dpcd_lane_settings),
+               link_training_setting->link_settings.lane_count);
+
+       if (is_repeater(link_training_setting, offset)) {
+               DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n"
+                               " 0x%X VS set = %x  PE set = %x max VS Reached = %x  max PE Reached = %x\n",
+                       __func__,
+                       offset,
+                       lane0_set_address,
+                       link_training_setting->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
+                       link_training_setting->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
+                       link_training_setting->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
+                       link_training_setting->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
+
+       } else {
+               DC_LOG_HW_LINK_TRAINING("%s\n 0x%X VS set = %x  PE set = %x max VS Reached = %x  max PE Reached = %x\n",
+                       __func__,
+                       lane0_set_address,
+                       link_training_setting->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
+                       link_training_setting->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
+                       link_training_setting->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
+                       link_training_setting->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
+       }
+
+       return status;
+}
+
+void dpcd_set_lt_pattern_and_lane_settings(
+       struct dc_link *link,
+       const struct link_training_settings *lt_settings,
+       enum dc_dp_training_pattern pattern,
+       uint32_t offset)
+{
+       uint32_t dpcd_base_lt_offset;
+       uint8_t dpcd_lt_buffer[5] = {0};
+       union dpcd_training_pattern dpcd_pattern = {0};
+       uint32_t size_in_bytes;
+       bool edp_workaround = false; /* TODO link_prop.INTERNAL */
+       dpcd_base_lt_offset = DP_TRAINING_PATTERN_SET;
+
+       if (is_repeater(lt_settings, offset))
+               dpcd_base_lt_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
+                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+
+       /*****************************************************************
+       * DpcdAddress_TrainingPatternSet
+       *****************************************************************/
+       dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
+               dp_training_pattern_to_dpcd_training_pattern(link, pattern);
+
+       dpcd_pattern.v1_4.SCRAMBLING_DISABLE =
+               dp_initialize_scrambling_data_symbols(link, pattern);
+
+       dpcd_lt_buffer[DP_TRAINING_PATTERN_SET - DP_TRAINING_PATTERN_SET]
+               = dpcd_pattern.raw;
+
+       if (is_repeater(lt_settings, offset)) {
+               DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n 0x%X pattern = %x\n",
+                       __func__,
+                       offset,
+                       dpcd_base_lt_offset,
+                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
+       } else {
+               DC_LOG_HW_LINK_TRAINING("%s\n 0x%X pattern = %x\n",
+                       __func__,
+                       dpcd_base_lt_offset,
+                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
+       }
+
+       /* concatenate everything into one buffer*/
+       size_in_bytes = lt_settings->link_settings.lane_count *
+                       sizeof(lt_settings->dpcd_lane_settings[0]);
+
+        // 0x00103 - 0x00102
+       memmove(
+               &dpcd_lt_buffer[DP_TRAINING_LANE0_SET - DP_TRAINING_PATTERN_SET],
+               lt_settings->dpcd_lane_settings,
+               size_in_bytes);
+
+       if (is_repeater(lt_settings, offset)) {
+               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_128b_132b_ENCODING)
+                       DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
+                                       " 0x%X TX_FFE_PRESET_VALUE = %x\n",
+                                       __func__,
+                                       offset,
+                                       dpcd_base_lt_offset,
+                                       lt_settings->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE);
+               else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_8b_10b_ENCODING)
+               DC_LOG_HW_LINK_TRAINING("%s:\n LTTPR Repeater ID: %d\n"
+                               " 0x%X VS set = %x PE set = %x max VS Reached = %x  max PE Reached = %x\n",
+                       __func__,
+                       offset,
+                       dpcd_base_lt_offset,
+                       lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
+                       lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
+                       lt_settings->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
+                       lt_settings->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
+       } else {
+               if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_128b_132b_ENCODING)
+                       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X TX_FFE_PRESET_VALUE = %x\n",
+                                       __func__,
+                                       dpcd_base_lt_offset,
+                                       lt_settings->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE);
+               else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_8b_10b_ENCODING)
+                       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X VS set = %x  PE set = %x max VS Reached = %x  max PE Reached = %x\n",
+                                       __func__,
+                                       dpcd_base_lt_offset,
+                                       lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET,
+                                       lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET,
+                                       lt_settings->dpcd_lane_settings[0].bits.MAX_SWING_REACHED,
+                                       lt_settings->dpcd_lane_settings[0].bits.MAX_PRE_EMPHASIS_REACHED);
+       }
+       if (edp_workaround) {
+               /* for eDP write in 2 parts because the 5-byte burst is
+               * causing issues on some eDP panels (EPR#366724)
+               */
+               core_link_write_dpcd(
+                       link,
+                       DP_TRAINING_PATTERN_SET,
+                       &dpcd_pattern.raw,
+                       sizeof(dpcd_pattern.raw));
+
+               core_link_write_dpcd(
+                       link,
+                       DP_TRAINING_LANE0_SET,
+                       (uint8_t *)(lt_settings->dpcd_lane_settings),
+                       size_in_bytes);
+
+       } else if (link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                       DP_128b_132b_ENCODING) {
+               core_link_write_dpcd(
+                               link,
+                               dpcd_base_lt_offset,
+                               dpcd_lt_buffer,
+                               sizeof(dpcd_lt_buffer));
+       } else
+               /* write it all in (1 + number-of-lanes)-byte burst*/
+               core_link_write_dpcd(
+                               link,
+                               dpcd_base_lt_offset,
+                               dpcd_lt_buffer,
+                               size_in_bytes + sizeof(dpcd_pattern.raw));
+}
+
+void start_clock_recovery_pattern_early(struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings,
+               uint32_t offset)
+{
+       DC_LOG_HW_LINK_TRAINING("%s\n GPU sends TPS1. Wait 400us.\n",
+                       __func__);
+       dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_cr, offset);
+       dp_set_hw_lane_settings(link, link_res, lt_settings, offset);
+       udelay(400);
+}
+
+void dp_set_hw_test_pattern(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       enum dp_test_pattern test_pattern,
+       uint8_t *custom_pattern,
+       uint32_t custom_pattern_size)
+{
+       const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
+       struct encoder_set_dp_phy_pattern_param pattern_param = {0};
+
+       pattern_param.dp_phy_pattern = test_pattern;
+       pattern_param.custom_pattern = custom_pattern;
+       pattern_param.custom_pattern_size = custom_pattern_size;
+       pattern_param.dp_panel_mode = dp_get_panel_mode(link);
+
+       if (link_hwss->ext.set_dp_link_test_pattern)
+               link_hwss->ext.set_dp_link_test_pattern(link, link_res, &pattern_param);
+}
+
+bool dp_set_hw_training_pattern(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       enum dc_dp_training_pattern pattern,
+       uint32_t offset)
+{
+       enum dp_test_pattern test_pattern = DP_TEST_PATTERN_UNSUPPORTED;
+
+       switch (pattern) {
+       case DP_TRAINING_PATTERN_SEQUENCE_1:
+               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN1;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_2:
+               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN2;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_3:
+               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN3;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_4:
+               test_pattern = DP_TEST_PATTERN_TRAINING_PATTERN4;
+               break;
+       case DP_128b_132b_TPS1:
+               test_pattern = DP_TEST_PATTERN_128b_132b_TPS1_TRAINING_MODE;
+               break;
+       case DP_128b_132b_TPS2:
+               test_pattern = DP_TEST_PATTERN_128b_132b_TPS2_TRAINING_MODE;
+               break;
+       default:
+               break;
+       }
+
+       dp_set_hw_test_pattern(link, link_res, test_pattern, NULL, 0);
+
+       return true;
+}
+
+static bool perform_post_lt_adj_req_sequence(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       enum dc_lane_count lane_count =
+       lt_settings->link_settings.lane_count;
+
+       uint32_t adj_req_count;
+       uint32_t adj_req_timer;
+       bool req_drv_setting_changed;
+       uint32_t lane;
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+
+       req_drv_setting_changed = false;
+       for (adj_req_count = 0; adj_req_count < POST_LT_ADJ_REQ_LIMIT;
+       adj_req_count++) {
+
+               req_drv_setting_changed = false;
+
+               for (adj_req_timer = 0;
+                       adj_req_timer < POST_LT_ADJ_REQ_TIMEOUT;
+                       adj_req_timer++) {
+
+                       dp_get_lane_status_and_lane_adjust(
+                               link,
+                               lt_settings,
+                               dpcd_lane_status,
+                               &dpcd_lane_status_updated,
+                               dpcd_lane_adjust,
+                               DPRX);
+
+                       if (dpcd_lane_status_updated.bits.
+                                       POST_LT_ADJ_REQ_IN_PROGRESS == 0)
+                               return true;
+
+                       if (!dp_is_cr_done(lane_count, dpcd_lane_status))
+                               return false;
+
+                       if (!dp_is_ch_eq_done(lane_count, dpcd_lane_status) ||
+                                       !dp_is_symbol_locked(lane_count, dpcd_lane_status) ||
+                                       !dp_is_interlane_aligned(dpcd_lane_status_updated))
+                               return false;
+
+                       for (lane = 0; lane < (uint32_t)(lane_count); lane++) {
+
+                               if (lt_settings->
+                               dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET !=
+                               dpcd_lane_adjust[lane].bits.VOLTAGE_SWING_LANE ||
+                               lt_settings->dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET !=
+                               dpcd_lane_adjust[lane].bits.PRE_EMPHASIS_LANE) {
+
+                                       req_drv_setting_changed = true;
+                                       break;
+                               }
+                       }
+
+                       if (req_drv_setting_changed) {
+                               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+
+                               dp_set_drive_settings(link,
+                                               link_res,
+                                               lt_settings);
+                               break;
+                       }
+
+                       msleep(1);
+               }
+
+               if (!req_drv_setting_changed) {
+                       DC_LOG_WARNING("%s: Post Link Training Adjust Request Timed out\n",
+                               __func__);
+
+                       ASSERT(0);
+                       return true;
+               }
+       }
+       DC_LOG_WARNING("%s: Post Link Training Adjust Request limit reached\n",
+               __func__);
+
+       ASSERT(0);
+       return true;
+
+}
+
+static enum link_training_result dp_transition_to_video_idle(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings,
+       enum link_training_result status)
+{
+       union lane_count_set lane_count_set = {0};
+
+       /* 4. mainlink output idle pattern*/
+       dp_set_hw_test_pattern(link, link_res, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
+
+       /*
+        * 5. post training adjust if required
+        * If the upstream DPTX and downstream DPRX both support TPS4,
+        * TPS4 must be used instead of POST_LT_ADJ_REQ.
+        */
+       if (link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED != 1 ||
+                       lt_settings->pattern_for_eq >= DP_TRAINING_PATTERN_SEQUENCE_4) {
+               /* delay 5ms after Main Link output idle pattern and then check
+                * DPCD 0202h.
+                */
+               if (link->connector_signal != SIGNAL_TYPE_EDP && status == LINK_TRAINING_SUCCESS) {
+                       msleep(5);
+                       status = dp_check_link_loss_status(link, lt_settings);
+               }
+               return status;
+       }
+
+       if (status == LINK_TRAINING_SUCCESS &&
+               perform_post_lt_adj_req_sequence(link, link_res, lt_settings) == false)
+               status = LINK_TRAINING_LQA_FAIL;
+
+       lane_count_set.bits.LANE_COUNT_SET = lt_settings->link_settings.lane_count;
+       lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
+       lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
+
+       core_link_write_dpcd(
+               link,
+               DP_LANE_COUNT_SET,
+               &lane_count_set.raw,
+               sizeof(lane_count_set));
+
+       return status;
+}
+
+enum link_training_result dp_perform_link_training(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       const struct dc_link_settings *link_settings,
+       bool skip_video_pattern)
+{
+       enum link_training_result status = LINK_TRAINING_SUCCESS;
+       struct link_training_settings lt_settings = {0};
+       enum dp_link_encoding encoding =
+                       link_dp_get_encoding_format(link_settings);
+
+       /* decide training settings */
+       dp_decide_training_settings(
+                       link,
+                       link_settings,
+                       &lt_settings);
+
+       override_training_settings(
+                       link,
+                       &link->preferred_training_settings,
+                       &lt_settings);
+
+       /* reset previous training states */
+       dpcd_exit_training_mode(link, encoding);
+
+       /* configure link prior to entering training mode */
+       dpcd_configure_lttpr_mode(link, &lt_settings);
+       dp_set_fec_ready(link, link_res, lt_settings.should_set_fec_ready);
+       dpcd_configure_channel_coding(link, &lt_settings);
+
+       /* enter training mode:
+        * Per DP specs starting from here, DPTX device shall not issue
+        * Non-LT AUX transactions inside training mode.
+        */
+       if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) && encoding == DP_8b_10b_ENCODING)
+               status = dp_perform_fixed_vs_pe_training_sequence(link, link_res, &lt_settings);
+       else if (encoding == DP_8b_10b_ENCODING)
+               status = dp_perform_8b_10b_link_training(link, link_res, &lt_settings);
+       else if (encoding == DP_128b_132b_ENCODING)
+               status = dp_perform_128b_132b_link_training(link, link_res, &lt_settings);
+       else
+               ASSERT(0);
+
+       /* exit training mode */
+       dpcd_exit_training_mode(link, encoding);
+
+       /* switch to video idle */
+       if ((status == LINK_TRAINING_SUCCESS) || !skip_video_pattern)
+               status = dp_transition_to_video_idle(link,
+                               link_res,
+                               &lt_settings,
+                               status);
+
+       /* dump debug data */
+       dp_log_training_result(link, &lt_settings, status);
+       if (status != LINK_TRAINING_SUCCESS)
+               link->ctx->dc->debug_data.ltFailCount++;
+       return status;
+}
+
+bool perform_link_training_with_retries(
+       const struct dc_link_settings *link_setting,
+       bool skip_video_pattern,
+       int attempts,
+       struct pipe_ctx *pipe_ctx,
+       enum signal_type signal,
+       bool do_fallback)
+{
+       int j;
+       uint8_t delay_between_attempts = LINK_TRAINING_RETRY_DELAY;
+       struct dc_stream_state *stream = pipe_ctx->stream;
+       struct dc_link *link = stream->link;
+       enum dp_panel_mode panel_mode = dp_get_panel_mode(link);
+       enum link_training_result status = LINK_TRAINING_CR_FAIL_LANE0;
+       struct dc_link_settings cur_link_settings = *link_setting;
+       struct dc_link_settings max_link_settings = *link_setting;
+       const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
+       int fail_count = 0;
+       bool is_link_bw_low = false; /* link bandwidth < stream bandwidth */
+       bool is_link_bw_min = /* RBR x 1 */
+               (cur_link_settings.link_rate <= LINK_RATE_LOW) &&
+               (cur_link_settings.lane_count <= LANE_COUNT_ONE);
+
+       dp_trace_commit_lt_init(link);
+
+
+       if (link_dp_get_encoding_format(&cur_link_settings) == DP_8b_10b_ENCODING)
+               /* We need to do this before the link training to ensure the idle
+                * pattern in SST mode will be sent right after the link training
+                */
+               link_hwss->setup_stream_encoder(pipe_ctx);
+
+       dp_trace_set_lt_start_timestamp(link, false);
+       j = 0;
+       while (j < attempts && fail_count < (attempts * 10)) {
+
+               DC_LOG_HW_LINK_TRAINING("%s: Beginning link(%d) training attempt %u of %d @ rate(%d) x lane(%d)\n",
+                       __func__, link->link_index, (unsigned int)j + 1, attempts, cur_link_settings.link_rate,
+                       cur_link_settings.lane_count);
+
+               dp_enable_link_phy(
+                       link,
+                       &pipe_ctx->link_res,
+                       signal,
+                       pipe_ctx->clock_source->id,
+                       &cur_link_settings);
+
+               if (stream->sink_patches.dppowerup_delay > 0) {
+                       int delay_dp_power_up_in_ms = stream->sink_patches.dppowerup_delay;
+
+                       msleep(delay_dp_power_up_in_ms);
+               }
+
+#ifdef CONFIG_DRM_AMD_DC_HDCP
+               if (panel_mode == DP_PANEL_MODE_EDP) {
+                       struct cp_psp *cp_psp = &stream->ctx->cp_psp;
+
+                       if (cp_psp && cp_psp->funcs.enable_assr) {
+                               /* ASSR is bound to fail with unsigned PSP
+                                * verstage used during devlopment phase.
+                                * Report and continue with eDP panel mode to
+                                * perform eDP link training with right settings
+                                */
+                               bool result;
+                               result = cp_psp->funcs.enable_assr(cp_psp->handle, link);
+                       }
+               }
+#endif
+
+               dp_set_panel_mode(link, panel_mode);
+
+               if (link->aux_access_disabled) {
+                       dc_link_dp_perform_link_training_skip_aux(link, &pipe_ctx->link_res, &cur_link_settings);
+                       return true;
+               } else {
+                       /** @todo Consolidate USB4 DP and DPx.x training. */
+                       if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) {
+                               status = dc_link_dpia_perform_link_training(
+                                               link,
+                                               &pipe_ctx->link_res,
+                                               &cur_link_settings,
+                                               skip_video_pattern);
+
+                               /* Transmit idle pattern once training successful. */
+                               if (status == LINK_TRAINING_SUCCESS && !is_link_bw_low) {
+                                       dp_set_hw_test_pattern(link, &pipe_ctx->link_res, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
+                                       // Update verified link settings to current one
+                                       // Because DPIA LT might fallback to lower link setting.
+                                       if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
+                                               link->verified_link_cap.link_rate = link->cur_link_settings.link_rate;
+                                               link->verified_link_cap.lane_count = link->cur_link_settings.lane_count;
+                                               dm_helpers_dp_mst_update_branch_bandwidth(link->ctx, link);
+                                       }
+                               }
+                       } else {
+                               status = dp_perform_link_training(
+                                               link,
+                                               &pipe_ctx->link_res,
+                                               &cur_link_settings,
+                                               skip_video_pattern);
+                       }
+
+                       dp_trace_lt_total_count_increment(link, false);
+                       dp_trace_lt_result_update(link, status, false);
+                       dp_trace_set_lt_end_timestamp(link, false);
+                       if (status == LINK_TRAINING_SUCCESS && !is_link_bw_low)
+                               return true;
+               }
+
+               fail_count++;
+               dp_trace_lt_fail_count_update(link, fail_count, false);
+               if (link->ep_type == DISPLAY_ENDPOINT_PHY) {
+                       /* latest link training still fail or link training is aborted
+                        * skip delay and keep PHY on
+                        */
+                       if (j == (attempts - 1) || (status == LINK_TRAINING_ABORT))
+                               break;
+               }
+
+               DC_LOG_WARNING("%s: Link(%d) training attempt %u of %d failed @ rate(%d) x lane(%d) : fail reason:(%d)\n",
+                       __func__, link->link_index, (unsigned int)j + 1, attempts, cur_link_settings.link_rate,
+                       cur_link_settings.lane_count, status);
+
+               dp_disable_link_phy(link, &pipe_ctx->link_res, signal);
+
+               /* Abort link training if failure due to sink being unplugged. */
+               if (status == LINK_TRAINING_ABORT) {
+                       enum dc_connection_type type = dc_connection_none;
+
+                       dc_link_detect_sink(link, &type);
+                       if (type == dc_connection_none) {
+                               DC_LOG_HW_LINK_TRAINING("%s: Aborting training because sink unplugged\n", __func__);
+                               break;
+                       }
+               }
+
+               /* Try to train again at original settings if:
+                * - not falling back between training attempts;
+                * - aborted previous attempt due to reasons other than sink unplug;
+                * - successfully trained but at a link rate lower than that required by stream;
+                * - reached minimum link bandwidth.
+                */
+               if (!do_fallback || (status == LINK_TRAINING_ABORT) ||
+                               (status == LINK_TRAINING_SUCCESS && is_link_bw_low) ||
+                               is_link_bw_min) {
+                       j++;
+                       cur_link_settings = *link_setting;
+                       delay_between_attempts += LINK_TRAINING_RETRY_DELAY;
+                       is_link_bw_low = false;
+                       is_link_bw_min = (cur_link_settings.link_rate <= LINK_RATE_LOW) &&
+                               (cur_link_settings.lane_count <= LANE_COUNT_ONE);
+
+               } else if (do_fallback) { /* Try training at lower link bandwidth if doing fallback. */
+                       uint32_t req_bw;
+                       uint32_t link_bw;
+
+                       decide_fallback_link_setting(link, &max_link_settings,
+                                       &cur_link_settings, status);
+                       /* Flag if reduced link bandwidth no longer meets stream requirements or fallen back to
+                        * minimum link bandwidth.
+                        */
+                       req_bw = dc_bandwidth_in_kbps_from_timing(&stream->timing);
+                       link_bw = dc_link_bandwidth_kbps(link, &cur_link_settings);
+                       is_link_bw_low = (req_bw > link_bw);
+                       is_link_bw_min = ((cur_link_settings.link_rate <= LINK_RATE_LOW) &&
+                               (cur_link_settings.lane_count <= LANE_COUNT_ONE));
+
+                       if (is_link_bw_low)
+                               DC_LOG_WARNING(
+                                       "%s: Link(%d) bandwidth too low after fallback req_bw(%d) > link_bw(%d)\n",
+                                       __func__, link->link_index, req_bw, link_bw);
+               }
+
+               msleep(delay_between_attempts);
+       }
+
+       return false;
+}
+
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.h
new file mode 100644 (file)
index 0000000..376d370
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+
+#ifndef __DC_LINK_DP_TRAINING_H__
+#define __DC_LINK_DP_TRAINING_H__
+#include "link.h"
+
+bool perform_link_training_with_retries(
+       const struct dc_link_settings *link_setting,
+       bool skip_video_pattern,
+       int attempts,
+       struct pipe_ctx *pipe_ctx,
+       enum signal_type signal,
+       bool do_fallback);
+
+enum link_training_result dp_perform_link_training(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct dc_link_settings *link_settings,
+               bool skip_video_pattern);
+
+bool dp_set_hw_training_pattern(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               enum dc_dp_training_pattern pattern,
+               uint32_t offset);
+
+void dp_set_hw_test_pattern(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               enum dp_test_pattern test_pattern,
+               uint8_t *custom_pattern,
+               uint32_t custom_pattern_size);
+
+void dpcd_set_training_pattern(
+       struct dc_link *link,
+       enum dc_dp_training_pattern training_pattern);
+
+/* Write DPCD drive settings. */
+enum dc_status dpcd_set_lane_settings(
+       struct dc_link *link,
+       const struct link_training_settings *link_training_setting,
+       uint32_t offset);
+
+/* Write DPCD link configuration data. */
+enum dc_status dpcd_set_link_settings(
+       struct dc_link *link,
+       const struct link_training_settings *lt_settings);
+
+void dpcd_set_lt_pattern_and_lane_settings(
+       struct dc_link *link,
+       const struct link_training_settings *lt_settings,
+       enum dc_dp_training_pattern pattern,
+       uint32_t offset);
+
+/* Read training status and adjustment requests from DPCD. */
+enum dc_status dp_get_lane_status_and_lane_adjust(
+       struct dc_link *link,
+       const struct link_training_settings *link_training_setting,
+       union lane_status ln_status[LANE_COUNT_DP_MAX],
+       union lane_align_status_updated *ln_align,
+       union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
+       uint32_t offset);
+
+enum dc_status dpcd_configure_lttpr_mode(
+               struct dc_link *link,
+               struct link_training_settings *lt_settings);
+
+enum dc_status configure_lttpr_mode_transparent(struct dc_link *link);
+
+enum dc_status dpcd_configure_channel_coding(
+               struct dc_link *link,
+               struct link_training_settings *lt_settings);
+
+void repeater_training_done(struct dc_link *link, uint32_t offset);
+
+void start_clock_recovery_pattern_early(struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings,
+               uint32_t offset);
+
+void dp_decide_training_settings(
+               struct dc_link *link,
+               const struct dc_link_settings *link_settings,
+               struct link_training_settings *lt_settings);
+
+void dp_decide_lane_settings(
+       const struct link_training_settings *lt_settings,
+       const union lane_adjust ln_adjust[LANE_COUNT_DP_MAX],
+       struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
+       union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX]);
+
+enum dc_dp_training_pattern decide_cr_training_pattern(
+               const struct dc_link_settings *link_settings);
+
+enum dc_dp_training_pattern decide_eq_training_pattern(struct dc_link *link,
+               const struct dc_link_settings *link_settings);
+
+void dp_get_lttpr_mode_override(struct dc_link *link,
+               enum lttpr_mode *override);
+
+void override_training_settings(
+               struct dc_link *link,
+               const struct dc_link_training_overrides *overrides,
+               struct link_training_settings *lt_settings);
+
+/* Check DPCD training status registers to detect link loss. */
+enum link_training_result dp_check_link_loss_status(
+               struct dc_link *link,
+               const struct link_training_settings *link_training_setting);
+
+bool dp_is_cr_done(enum dc_lane_count ln_count,
+       union lane_status *dpcd_lane_status);
+
+bool dp_is_ch_eq_done(enum dc_lane_count ln_count,
+       union lane_status *dpcd_lane_status);
+bool dp_is_symbol_locked(enum dc_lane_count ln_count,
+       union lane_status *dpcd_lane_status);
+bool dp_is_interlane_aligned(union lane_align_status_updated align_status);
+
+bool is_repeater(const struct link_training_settings *lt_settings, uint32_t offset);
+
+bool dp_is_max_vs_reached(
+       const struct link_training_settings *lt_settings);
+
+uint8_t get_dpcd_link_rate(const struct dc_link_settings *link_settings);
+
+enum link_training_result dp_get_cr_failure(enum dc_lane_count ln_count,
+       union lane_status *dpcd_lane_status);
+
+void dp_hw_to_dpcd_lane_settings(
+       const struct link_training_settings *lt_settings,
+       const struct dc_lane_settings hw_lane_settings[LANE_COUNT_DP_MAX],
+       union dpcd_training_lane dpcd_lane_settings[LANE_COUNT_DP_MAX]);
+
+void dp_wait_for_training_aux_rd_interval(
+       struct dc_link *link,
+       uint32_t wait_in_micro_secs);
+
+enum dpcd_training_patterns
+       dp_training_pattern_to_dpcd_training_pattern(
+       struct dc_link *link,
+       enum dc_dp_training_pattern pattern);
+
+uint8_t dp_initialize_scrambling_data_symbols(
+       struct dc_link *link,
+       enum dc_dp_training_pattern pattern);
+
+void dp_log_training_result(
+       struct dc_link *link,
+       const struct link_training_settings *lt_settings,
+       enum link_training_result status);
+
+uint32_t dp_translate_training_aux_read_interval(
+               uint32_t dpcd_aux_read_interval);
+#endif /* __DC_LINK_DP_TRAINING_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_128b_132b.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_128b_132b.c
new file mode 100644 (file)
index 0000000..bfabebe
--- /dev/null
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ * This file implements dp 128b/132b link training software policies and
+ * sequences.
+ */
+#include "link_dp_training_128b_132b.h"
+#include "link_dp_training_8b_10b.h"
+#include "link_dpcd.h"
+#include "link_dp_phy.h"
+#include "link_dp_capability.h"
+#include "dc_link_dp.h"
+
+#define DC_LOGGER \
+       link->ctx->logger
+
+static enum dc_status dpcd_128b_132b_set_lane_settings(
+               struct dc_link *link,
+               const struct link_training_settings *link_training_setting)
+{
+       enum dc_status status = core_link_write_dpcd(link,
+                       DP_TRAINING_LANE0_SET,
+                       (uint8_t *)(link_training_setting->dpcd_lane_settings),
+                       sizeof(link_training_setting->dpcd_lane_settings));
+
+       DC_LOG_HW_LINK_TRAINING("%s:\n 0x%X TX_FFE_PRESET_VALUE = %x\n",
+                       __func__,
+                       DP_TRAINING_LANE0_SET,
+                       link_training_setting->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE);
+       return status;
+}
+
+static void dpcd_128b_132b_get_aux_rd_interval(struct dc_link *link,
+               uint32_t *interval_in_us)
+{
+       union dp_128b_132b_training_aux_rd_interval dpcd_interval;
+       uint32_t interval_unit = 0;
+
+       dpcd_interval.raw = 0;
+       core_link_read_dpcd(link, DP_128B132B_TRAINING_AUX_RD_INTERVAL,
+                       &dpcd_interval.raw, sizeof(dpcd_interval.raw));
+       interval_unit = dpcd_interval.bits.UNIT ? 1 : 2; /* 0b = 2 ms, 1b = 1 ms */
+       /* (128b/132b_TRAINING_AUX_RD_INTERVAL value + 1) *
+        * INTERVAL_UNIT. The maximum is 256 ms
+        */
+       *interval_in_us = (dpcd_interval.bits.VALUE + 1) * interval_unit * 1000;
+}
+
+static enum link_training_result dp_perform_128b_132b_channel_eq_done_sequence(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       uint8_t loop_count;
+       uint32_t aux_rd_interval = 0;
+       uint32_t wait_time = 0;
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+       enum dc_status status = DC_OK;
+       enum link_training_result result = LINK_TRAINING_SUCCESS;
+
+       /* Transmit 128b/132b_TPS1 over Main-Link */
+       dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_cr, DPRX);
+
+       /* Set TRAINING_PATTERN_SET to 01h */
+       dpcd_set_training_pattern(link, lt_settings->pattern_for_cr);
+
+       /* Adjust TX_FFE_PRESET_VALUE and Transmit 128b/132b_TPS2 over Main-Link */
+       dpcd_128b_132b_get_aux_rd_interval(link, &aux_rd_interval);
+       dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
+                       &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
+       dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+       dp_set_hw_lane_settings(link, link_res, lt_settings, DPRX);
+       dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_eq, DPRX);
+
+       /* Set loop counter to start from 1 */
+       loop_count = 1;
+
+       /* Set TRAINING_PATTERN_SET to 02h and TX_FFE_PRESET_VALUE in one AUX transaction */
+       dpcd_set_lt_pattern_and_lane_settings(link, lt_settings,
+                       lt_settings->pattern_for_eq, DPRX);
+
+       /* poll for channel EQ done */
+       while (result == LINK_TRAINING_SUCCESS) {
+               dp_wait_for_training_aux_rd_interval(link, aux_rd_interval);
+               wait_time += aux_rd_interval;
+               status = dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
+                               &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
+               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+               dpcd_128b_132b_get_aux_rd_interval(link, &aux_rd_interval);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+               } else if (dp_is_ch_eq_done(lt_settings->link_settings.lane_count,
+                               dpcd_lane_status)) {
+                       /* pass */
+                       break;
+               } else if (loop_count >= lt_settings->eq_loop_count_limit) {
+                       result = DP_128b_132b_MAX_LOOP_COUNT_REACHED;
+               } else if (dpcd_lane_status_updated.bits.LT_FAILED_128b_132b) {
+                       result = DP_128b_132b_LT_FAILED;
+               } else {
+                       dp_set_hw_lane_settings(link, link_res, lt_settings, DPRX);
+                       dpcd_128b_132b_set_lane_settings(link, lt_settings);
+               }
+               loop_count++;
+       }
+
+       /* poll for EQ interlane align done */
+       while (result == LINK_TRAINING_SUCCESS) {
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+               } else if (dpcd_lane_status_updated.bits.EQ_INTERLANE_ALIGN_DONE_128b_132b) {
+                       /* pass */
+                       break;
+               } else if (wait_time >= lt_settings->eq_wait_time_limit) {
+                       result = DP_128b_132b_CHANNEL_EQ_DONE_TIMEOUT;
+               } else if (dpcd_lane_status_updated.bits.LT_FAILED_128b_132b) {
+                       result = DP_128b_132b_LT_FAILED;
+               } else {
+                       dp_wait_for_training_aux_rd_interval(link,
+                                       lt_settings->eq_pattern_time);
+                       wait_time += lt_settings->eq_pattern_time;
+                       status = dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
+                                       &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
+               }
+       }
+
+       return result;
+}
+
+static enum link_training_result dp_perform_128b_132b_cds_done_sequence(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       /* Assumption: assume hardware has transmitted eq pattern */
+       enum dc_status status = DC_OK;
+       enum link_training_result result = LINK_TRAINING_SUCCESS;
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+       uint32_t wait_time = 0;
+
+       /* initiate CDS done sequence */
+       dpcd_set_training_pattern(link, lt_settings->pattern_for_cds);
+
+       /* poll for CDS interlane align done and symbol lock */
+       while (result == LINK_TRAINING_SUCCESS) {
+               dp_wait_for_training_aux_rd_interval(link,
+                               lt_settings->cds_pattern_time);
+               wait_time += lt_settings->cds_pattern_time;
+               status = dp_get_lane_status_and_lane_adjust(link, lt_settings, dpcd_lane_status,
+                                               &dpcd_lane_status_updated, dpcd_lane_adjust, DPRX);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+               } else if (dp_is_symbol_locked(lt_settings->link_settings.lane_count, dpcd_lane_status) &&
+                               dpcd_lane_status_updated.bits.CDS_INTERLANE_ALIGN_DONE_128b_132b) {
+                       /* pass */
+                       break;
+               } else if (dpcd_lane_status_updated.bits.LT_FAILED_128b_132b) {
+                       result = DP_128b_132b_LT_FAILED;
+               } else if (wait_time >= lt_settings->cds_wait_time_limit) {
+                       result = DP_128b_132b_CDS_DONE_TIMEOUT;
+               }
+       }
+
+       return result;
+}
+
+enum link_training_result dp_perform_128b_132b_link_training(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       enum link_training_result result = LINK_TRAINING_SUCCESS;
+
+       /* TODO - DP2.0 Link: remove legacy_dp2_lt logic */
+       if (link->dc->debug.legacy_dp2_lt) {
+               struct link_training_settings legacy_settings;
+
+               decide_8b_10b_training_settings(link,
+                               &lt_settings->link_settings,
+                               &legacy_settings);
+               return dp_perform_8b_10b_link_training(link, link_res, &legacy_settings);
+       }
+
+       dpcd_set_link_settings(link, lt_settings);
+
+       if (result == LINK_TRAINING_SUCCESS)
+               result = dp_perform_128b_132b_channel_eq_done_sequence(link, link_res, lt_settings);
+
+       if (result == LINK_TRAINING_SUCCESS)
+               result = dp_perform_128b_132b_cds_done_sequence(link, link_res, lt_settings);
+
+       return result;
+}
+
+void decide_128b_132b_training_settings(struct dc_link *link,
+               const struct dc_link_settings *link_settings,
+               struct link_training_settings *lt_settings)
+{
+       memset(lt_settings, 0, sizeof(*lt_settings));
+
+       lt_settings->link_settings = *link_settings;
+       /* TODO: should decide link spread when populating link_settings */
+       lt_settings->link_settings.link_spread = link->dp_ss_off ? LINK_SPREAD_DISABLED :
+                       LINK_SPREAD_05_DOWNSPREAD_30KHZ;
+
+       lt_settings->pattern_for_cr = decide_cr_training_pattern(link_settings);
+       lt_settings->pattern_for_eq = decide_eq_training_pattern(link, link_settings);
+       lt_settings->eq_pattern_time = 2500;
+       lt_settings->eq_wait_time_limit = 400000;
+       lt_settings->eq_loop_count_limit = 20;
+       lt_settings->pattern_for_cds = DP_128b_132b_TPS2_CDS;
+       lt_settings->cds_pattern_time = 2500;
+       lt_settings->cds_wait_time_limit = (dp_parse_lttpr_repeater_count(
+                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt) + 1) * 20000;
+       lt_settings->disallow_per_lane_settings = true;
+       lt_settings->lttpr_mode = dp_decide_128b_132b_lttpr_mode(link);
+       dp_hw_to_dpcd_lane_settings(lt_settings,
+                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+}
+
+enum lttpr_mode dp_decide_128b_132b_lttpr_mode(struct dc_link *link)
+{
+       enum lttpr_mode mode = LTTPR_MODE_NON_LTTPR;
+
+       if (dp_is_lttpr_present(link))
+               mode = LTTPR_MODE_NON_TRANSPARENT;
+
+       DC_LOG_DC("128b_132b chose LTTPR_MODE %d.\n", mode);
+       return mode;
+}
+
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_128b_132b.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_128b_132b.h
new file mode 100644 (file)
index 0000000..2147f24
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+
+#ifndef __DC_LINK_DP_TRAINING_128B_132B_H__
+#define __DC_LINK_DP_TRAINING_128B_132B_H__
+#include "link_dp_training.h"
+
+enum link_training_result dp_perform_128b_132b_link_training(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings);
+
+void decide_128b_132b_training_settings(struct dc_link *link,
+               const struct dc_link_settings *link_settings,
+               struct link_training_settings *lt_settings);
+
+enum lttpr_mode dp_decide_128b_132b_lttpr_mode(struct dc_link *link);
+
+#endif /* __DC_LINK_DP_TRAINING_128B_132B_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_8b_10b.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_8b_10b.c
new file mode 100644 (file)
index 0000000..ec8b619
--- /dev/null
@@ -0,0 +1,415 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ * This file implements dp 8b/10b link training software policies and
+ * sequences.
+ */
+#include "link_dp_training_8b_10b.h"
+#include "link_dpcd.h"
+#include "link_dp_phy.h"
+#include "link_dp_capability.h"
+#include "dc_link_dp.h"
+
+#define DC_LOGGER \
+       link->ctx->logger
+
+static int32_t get_cr_training_aux_rd_interval(struct dc_link *link,
+               const struct dc_link_settings *link_settings)
+{
+       union training_aux_rd_interval training_rd_interval;
+       uint32_t wait_in_micro_secs = 100;
+
+       memset(&training_rd_interval, 0, sizeof(training_rd_interval));
+       if (link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING &&
+                       link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_12) {
+               core_link_read_dpcd(
+                               link,
+                               DP_TRAINING_AUX_RD_INTERVAL,
+                               (uint8_t *)&training_rd_interval,
+                               sizeof(training_rd_interval));
+               if (training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL)
+                       wait_in_micro_secs = training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL * 4000;
+       }
+       return wait_in_micro_secs;
+}
+
+static uint32_t get_eq_training_aux_rd_interval(
+       struct dc_link *link,
+       const struct dc_link_settings *link_settings)
+{
+       union training_aux_rd_interval training_rd_interval;
+
+       memset(&training_rd_interval, 0, sizeof(training_rd_interval));
+       if (link_dp_get_encoding_format(link_settings) == DP_128b_132b_ENCODING) {
+               core_link_read_dpcd(
+                               link,
+                               DP_128B132B_TRAINING_AUX_RD_INTERVAL,
+                               (uint8_t *)&training_rd_interval,
+                               sizeof(training_rd_interval));
+       } else if (link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING &&
+                       link->dpcd_caps.dpcd_rev.raw >= DPCD_REV_12) {
+               core_link_read_dpcd(
+                               link,
+                               DP_TRAINING_AUX_RD_INTERVAL,
+                               (uint8_t *)&training_rd_interval,
+                               sizeof(training_rd_interval));
+       }
+
+       switch (training_rd_interval.bits.TRAINIG_AUX_RD_INTERVAL) {
+       case 0: return 400;
+       case 1: return 4000;
+       case 2: return 8000;
+       case 3: return 12000;
+       case 4: return 16000;
+       case 5: return 32000;
+       case 6: return 64000;
+       default: return 400;
+       }
+}
+
+void decide_8b_10b_training_settings(
+        struct dc_link *link,
+       const struct dc_link_settings *link_setting,
+       struct link_training_settings *lt_settings)
+{
+       memset(lt_settings, '\0', sizeof(struct link_training_settings));
+
+       /* Initialize link settings */
+       lt_settings->link_settings.use_link_rate_set = link_setting->use_link_rate_set;
+       lt_settings->link_settings.link_rate_set = link_setting->link_rate_set;
+       lt_settings->link_settings.link_rate = link_setting->link_rate;
+       lt_settings->link_settings.lane_count = link_setting->lane_count;
+       /* TODO hard coded to SS for now
+        * lt_settings.link_settings.link_spread =
+        * dal_display_path_is_ss_supported(
+        * path_mode->display_path) ?
+        * LINK_SPREAD_05_DOWNSPREAD_30KHZ :
+        * LINK_SPREAD_DISABLED;
+        */
+       lt_settings->link_settings.link_spread = link->dp_ss_off ?
+                       LINK_SPREAD_DISABLED : LINK_SPREAD_05_DOWNSPREAD_30KHZ;
+       lt_settings->cr_pattern_time = get_cr_training_aux_rd_interval(link, link_setting);
+       lt_settings->eq_pattern_time = get_eq_training_aux_rd_interval(link, link_setting);
+       lt_settings->pattern_for_cr = decide_cr_training_pattern(link_setting);
+       lt_settings->pattern_for_eq = decide_eq_training_pattern(link, link_setting);
+       lt_settings->enhanced_framing = 1;
+       lt_settings->should_set_fec_ready = true;
+       lt_settings->disallow_per_lane_settings = true;
+       lt_settings->always_match_dpcd_with_hw_lane_settings = true;
+       lt_settings->lttpr_mode = dp_decide_8b_10b_lttpr_mode(link);
+       dp_hw_to_dpcd_lane_settings(lt_settings, lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+}
+
+enum lttpr_mode dp_decide_8b_10b_lttpr_mode(struct dc_link *link)
+{
+       bool is_lttpr_present = dp_is_lttpr_present(link);
+       bool vbios_lttpr_force_non_transparent = link->dc->caps.vbios_lttpr_enable;
+       bool vbios_lttpr_aware = link->dc->caps.vbios_lttpr_aware;
+
+       if (!is_lttpr_present)
+               return LTTPR_MODE_NON_LTTPR;
+
+       if (vbios_lttpr_aware) {
+               if (vbios_lttpr_force_non_transparent) {
+                       DC_LOG_DC("chose LTTPR_MODE_NON_TRANSPARENT due to VBIOS DCE_INFO_CAPS_LTTPR_SUPPORT_ENABLE set to 1.\n");
+                       return LTTPR_MODE_NON_TRANSPARENT;
+               } else {
+                       DC_LOG_DC("chose LTTPR_MODE_NON_TRANSPARENT by default due to VBIOS not set DCE_INFO_CAPS_LTTPR_SUPPORT_ENABLE set to 1.\n");
+                       return LTTPR_MODE_TRANSPARENT;
+               }
+       }
+
+       if (link->dc->config.allow_lttpr_non_transparent_mode.bits.DP1_4A &&
+                       link->dc->caps.extended_aux_timeout_support) {
+               DC_LOG_DC("chose LTTPR_MODE_NON_TRANSPARENT by default and dc->config.allow_lttpr_non_transparent_mode.bits.DP1_4A set to 1.\n");
+               return LTTPR_MODE_NON_TRANSPARENT;
+       }
+
+       DC_LOG_DC("chose LTTPR_MODE_NON_LTTPR.\n");
+       return LTTPR_MODE_NON_LTTPR;
+}
+
+enum link_training_result perform_8b_10b_clock_recovery_sequence(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings,
+       uint32_t offset)
+{
+       uint32_t retries_cr;
+       uint32_t retry_count;
+       uint32_t wait_time_microsec;
+       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX];
+       union lane_align_status_updated dpcd_lane_status_updated;
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+
+       retries_cr = 0;
+       retry_count = 0;
+
+       memset(&dpcd_lane_status, '\0', sizeof(dpcd_lane_status));
+       memset(&dpcd_lane_status_updated, '\0',
+       sizeof(dpcd_lane_status_updated));
+
+       if (!link->ctx->dc->work_arounds.lt_early_cr_pattern)
+               dp_set_hw_training_pattern(link, link_res, lt_settings->pattern_for_cr, offset);
+
+       /* najeeb - The synaptics MST hub can put the LT in
+       * infinite loop by switching the VS
+       */
+       /* between level 0 and level 1 continuously, here
+       * we try for CR lock for LinkTrainingMaxCRRetry count*/
+       while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
+               (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
+
+
+               /* 1. call HWSS to set lane settings*/
+               dp_set_hw_lane_settings(
+                               link,
+                               link_res,
+                               lt_settings,
+                               offset);
+
+               /* 2. update DPCD of the receiver*/
+               if (!retry_count)
+                       /* EPR #361076 - write as a 5-byte burst,
+                        * but only for the 1-st iteration.*/
+                       dpcd_set_lt_pattern_and_lane_settings(
+                                       link,
+                                       lt_settings,
+                                       lt_settings->pattern_for_cr,
+                                       offset);
+               else
+                       dpcd_set_lane_settings(
+                                       link,
+                                       lt_settings,
+                                       offset);
+
+               /* 3. wait receiver to lock-on*/
+               wait_time_microsec = lt_settings->cr_pattern_time;
+
+               dp_wait_for_training_aux_rd_interval(
+                               link,
+                               wait_time_microsec);
+
+               /* 4. Read lane status and requested drive
+               * settings as set by the sink
+               */
+               dp_get_lane_status_and_lane_adjust(
+                               link,
+                               lt_settings,
+                               dpcd_lane_status,
+                               &dpcd_lane_status_updated,
+                               dpcd_lane_adjust,
+                               offset);
+
+               /* 5. check CR done*/
+               if (dp_is_cr_done(lane_count, dpcd_lane_status))
+                       return LINK_TRAINING_SUCCESS;
+
+               /* 6. max VS reached*/
+               if ((link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                               DP_8b_10b_ENCODING) &&
+                               dp_is_max_vs_reached(lt_settings))
+                       break;
+
+               /* 7. same lane settings*/
+               /* Note: settings are the same for all lanes,
+                * so comparing first lane is sufficient*/
+               if ((link_dp_get_encoding_format(&lt_settings->link_settings) == DP_8b_10b_ENCODING) &&
+                               lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
+                                               dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
+                       retries_cr++;
+               else if ((link_dp_get_encoding_format(&lt_settings->link_settings) == DP_128b_132b_ENCODING) &&
+                               lt_settings->dpcd_lane_settings[0].tx_ffe.PRESET_VALUE ==
+                                               dpcd_lane_adjust[0].tx_ffe.PRESET_VALUE)
+                       retries_cr++;
+               else
+                       retries_cr = 0;
+
+               /* 8. update VS/PE/PC2 in lt_settings*/
+               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+               retry_count++;
+       }
+
+       if (retry_count >= LINK_TRAINING_MAX_CR_RETRY) {
+               ASSERT(0);
+               DC_LOG_ERROR("%s: Link Training Error, could not get CR after %d tries. Possibly voltage swing issue",
+                       __func__,
+                       LINK_TRAINING_MAX_CR_RETRY);
+
+       }
+
+       return dp_get_cr_failure(lane_count, dpcd_lane_status);
+}
+
+enum link_training_result perform_8b_10b_channel_equalization_sequence(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings,
+       uint32_t offset)
+{
+       enum dc_dp_training_pattern tr_pattern;
+       uint32_t retries_ch_eq;
+       uint32_t wait_time_microsec;
+       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+
+       /* Note: also check that TPS4 is a supported feature*/
+       tr_pattern = lt_settings->pattern_for_eq;
+
+       if (is_repeater(lt_settings, offset) && link_dp_get_encoding_format(&lt_settings->link_settings) == DP_8b_10b_ENCODING)
+               tr_pattern = DP_TRAINING_PATTERN_SEQUENCE_4;
+
+       dp_set_hw_training_pattern(link, link_res, tr_pattern, offset);
+
+       for (retries_ch_eq = 0; retries_ch_eq <= LINK_TRAINING_MAX_RETRY_COUNT;
+               retries_ch_eq++) {
+
+               dp_set_hw_lane_settings(link, link_res, lt_settings, offset);
+
+               /* 2. update DPCD*/
+               if (!retries_ch_eq)
+                       /* EPR #361076 - write as a 5-byte burst,
+                        * but only for the 1-st iteration
+                        */
+
+                       dpcd_set_lt_pattern_and_lane_settings(
+                               link,
+                               lt_settings,
+                               tr_pattern, offset);
+               else
+                       dpcd_set_lane_settings(link, lt_settings, offset);
+
+               /* 3. wait for receiver to lock-on*/
+               wait_time_microsec = lt_settings->eq_pattern_time;
+
+               if (is_repeater(lt_settings, offset))
+                       wait_time_microsec =
+                                       dp_translate_training_aux_read_interval(
+                                               link->dpcd_caps.lttpr_caps.aux_rd_interval[offset - 1]);
+
+               dp_wait_for_training_aux_rd_interval(
+                               link,
+                               wait_time_microsec);
+
+               /* 4. Read lane status and requested
+                * drive settings as set by the sink*/
+
+               dp_get_lane_status_and_lane_adjust(
+                       link,
+                       lt_settings,
+                       dpcd_lane_status,
+                       &dpcd_lane_status_updated,
+                       dpcd_lane_adjust,
+                       offset);
+
+               /* 5. check CR done*/
+               if (!dp_is_cr_done(lane_count, dpcd_lane_status))
+                       return dpcd_lane_status[0].bits.CR_DONE_0 ?
+                                       LINK_TRAINING_EQ_FAIL_CR_PARTIAL :
+                                       LINK_TRAINING_EQ_FAIL_CR;
+
+               /* 6. check CHEQ done*/
+               if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
+                               dp_is_symbol_locked(lane_count, dpcd_lane_status) &&
+                               dp_is_interlane_aligned(dpcd_lane_status_updated))
+                       return LINK_TRAINING_SUCCESS;
+
+               /* 7. update VS/PE/PC2 in lt_settings*/
+               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+       }
+
+       return LINK_TRAINING_EQ_FAIL_EQ;
+
+}
+
+enum link_training_result dp_perform_8b_10b_link_training(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       enum link_training_result status = LINK_TRAINING_SUCCESS;
+
+       uint8_t repeater_cnt;
+       uint8_t repeater_id;
+       uint8_t lane = 0;
+
+       if (link->ctx->dc->work_arounds.lt_early_cr_pattern)
+               start_clock_recovery_pattern_early(link, link_res, lt_settings, DPRX);
+
+       /* 1. set link rate, lane count and spread. */
+       dpcd_set_link_settings(link, lt_settings);
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
+
+               /* 2. perform link training (set link training done
+                *  to false is done as well)
+                */
+               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+
+               for (repeater_id = repeater_cnt; (repeater_id > 0 && status == LINK_TRAINING_SUCCESS);
+                               repeater_id--) {
+                       status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, repeater_id);
+
+                       if (status != LINK_TRAINING_SUCCESS) {
+                               repeater_training_done(link, repeater_id);
+                               break;
+                       }
+
+                       status = perform_8b_10b_channel_equalization_sequence(link,
+                                       link_res,
+                                       lt_settings,
+                                       repeater_id);
+
+                       repeater_training_done(link, repeater_id);
+
+                       if (status != LINK_TRAINING_SUCCESS)
+                               break;
+
+                       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+                               lt_settings->dpcd_lane_settings[lane].raw = 0;
+                               lt_settings->hw_lane_settings[lane].VOLTAGE_SWING = 0;
+                               lt_settings->hw_lane_settings[lane].PRE_EMPHASIS = 0;
+                       }
+               }
+       }
+
+       if (status == LINK_TRAINING_SUCCESS) {
+               status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, DPRX);
+               if (status == LINK_TRAINING_SUCCESS) {
+                       status = perform_8b_10b_channel_equalization_sequence(link,
+                                       link_res,
+                                       lt_settings,
+                                       DPRX);
+               }
+       }
+
+       return status;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_8b_10b.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_8b_10b.h
new file mode 100644 (file)
index 0000000..d26de15
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+
+#ifndef __DC_LINK_DP_TRAINING_8B_10B_H__
+#define __DC_LINK_DP_TRAINING_8B_10B_H__
+#include "link_dp_training.h"
+
+/* to avoid infinite loop where-in the receiver
+ * switches between different VS
+ */
+#define LINK_TRAINING_MAX_CR_RETRY 100
+#define LINK_TRAINING_MAX_RETRY_COUNT 5
+
+enum link_training_result dp_perform_8b_10b_link_training(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings);
+
+enum link_training_result perform_8b_10b_clock_recovery_sequence(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings,
+       uint32_t offset);
+
+enum link_training_result perform_8b_10b_channel_equalization_sequence(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings,
+       uint32_t offset);
+
+enum lttpr_mode dp_decide_8b_10b_lttpr_mode(struct dc_link *link);
+
+void decide_8b_10b_training_settings(
+        struct dc_link *link,
+       const struct dc_link_settings *link_setting,
+       struct link_training_settings *lt_settings);
+
+#endif /* __DC_LINK_DP_TRAINING_8B_10B_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_auxless.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_auxless.c
new file mode 100644 (file)
index 0000000..f84b6ea
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ *
+ */
+#include "link_dp_training_auxless.h"
+#include "link_dp_phy.h"
+#include "dc_link_dp.h"
+#define DC_LOGGER \
+       link->ctx->logger
+bool dc_link_dp_perform_link_training_skip_aux(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       const struct dc_link_settings *link_setting)
+{
+       struct link_training_settings lt_settings = {0};
+
+       dp_decide_training_settings(
+                       link,
+                       link_setting,
+                       &lt_settings);
+       override_training_settings(
+                       link,
+                       &link->preferred_training_settings,
+                       &lt_settings);
+
+       /* 1. Perform_clock_recovery_sequence. */
+
+       /* transmit training pattern for clock recovery */
+       dp_set_hw_training_pattern(link, link_res, lt_settings.pattern_for_cr, DPRX);
+
+       /* call HWSS to set lane settings*/
+       dp_set_hw_lane_settings(link, link_res, &lt_settings, DPRX);
+
+       /* wait receiver to lock-on*/
+       dp_wait_for_training_aux_rd_interval(link, lt_settings.cr_pattern_time);
+
+       /* 2. Perform_channel_equalization_sequence. */
+
+       /* transmit training pattern for channel equalization. */
+       dp_set_hw_training_pattern(link, link_res, lt_settings.pattern_for_eq, DPRX);
+
+       /* call HWSS to set lane settings*/
+       dp_set_hw_lane_settings(link, link_res, &lt_settings, DPRX);
+
+       /* wait receiver to lock-on. */
+       dp_wait_for_training_aux_rd_interval(link, lt_settings.eq_pattern_time);
+
+       /* 3. Perform_link_training_int. */
+
+       /* Mainlink output idle pattern. */
+       dp_set_hw_test_pattern(link, link_res, DP_TEST_PATTERN_VIDEO_MODE, NULL, 0);
+
+       dp_log_training_result(link, &lt_settings, LINK_TRAINING_SUCCESS);
+
+       return true;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_auxless.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_auxless.h
new file mode 100644 (file)
index 0000000..413999c
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+
+#ifndef __DC_LINK_DP_TRAINING_AUXLESS_H__
+#define __DC_LINK_DP_TRAINING_AUXLESS_H__
+#include "link_dp_training.h"
+
+bool dc_link_dp_perform_link_training_skip_aux(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       const struct dc_link_settings *link_setting);
+#endif /* __DC_LINK_DP_TRAINING_AUXLESS_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.c
new file mode 100644 (file)
index 0000000..cf47db1
--- /dev/null
@@ -0,0 +1,1045 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ * This module implements functionality for training DPIA links.
+ */
+#include "link_dp_training_dpia.h"
+#include "dc.h"
+#include "inc/core_status.h"
+#include "dc_link.h"
+#include "dc_link_dp.h"
+#include "dpcd_defs.h"
+
+#include "link_dp_dpia.h"
+#include "link_hwss.h"
+#include "dm_helpers.h"
+#include "dmub/inc/dmub_cmd.h"
+#include "link_dpcd.h"
+#include "link_dp_training_8b_10b.h"
+#include "link_dp_capability.h"
+#include "dc_dmub_srv.h"
+#define DC_LOGGER \
+       link->ctx->logger
+
+/* The approximate time (us) it takes to transmit 9 USB4 DP clock sync packets. */
+#define DPIA_CLK_SYNC_DELAY 16000
+
+/* Extend interval between training status checks for manual testing. */
+#define DPIA_DEBUG_EXTENDED_AUX_RD_INTERVAL_US 60000000
+
+/* SET_CONFIG message types sent by driver. */
+enum dpia_set_config_type {
+       DPIA_SET_CFG_SET_LINK = 0x01,
+       DPIA_SET_CFG_SET_PHY_TEST_MODE = 0x05,
+       DPIA_SET_CFG_SET_TRAINING = 0x18,
+       DPIA_SET_CFG_SET_VSPE = 0x19
+};
+
+/* Training stages (TS) in SET_CONFIG(SET_TRAINING) message. */
+enum dpia_set_config_ts {
+       DPIA_TS_DPRX_DONE = 0x00, /* Done training DPRX. */
+       DPIA_TS_TPS1 = 0x01,
+       DPIA_TS_TPS2 = 0x02,
+       DPIA_TS_TPS3 = 0x03,
+       DPIA_TS_TPS4 = 0x07,
+       DPIA_TS_UFP_DONE = 0xff /* Done training DPTX-to-DPIA hop. */
+};
+
+/* SET_CONFIG message data associated with messages sent by driver. */
+union dpia_set_config_data {
+       struct {
+               uint8_t mode : 1;
+               uint8_t reserved : 7;
+       } set_link;
+       struct {
+               uint8_t stage;
+       } set_training;
+       struct {
+               uint8_t swing : 2;
+               uint8_t max_swing_reached : 1;
+               uint8_t pre_emph : 2;
+               uint8_t max_pre_emph_reached : 1;
+               uint8_t reserved : 2;
+       } set_vspe;
+       uint8_t raw;
+};
+
+
+/* Configure link as prescribed in link_setting; set LTTPR mode; and
+ * Initialize link training settings.
+ * Abort link training if sink unplug detected.
+ *
+ * @param link DPIA link being trained.
+ * @param[in] link_setting Lane count, link rate and downspread control.
+ * @param[out] lt_settings Link settings and drive settings (voltage swing and pre-emphasis).
+ */
+static enum link_training_result dpia_configure_link(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               const struct dc_link_settings *link_setting,
+               struct link_training_settings *lt_settings)
+{
+       enum dc_status status;
+       bool fec_enable;
+
+       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) configuring\n - LTTPR mode(%d)\n",
+               __func__,
+               link->link_id.enum_id - ENUM_ID_1,
+               lt_settings->lttpr_mode);
+
+       dp_decide_training_settings(
+               link,
+               link_setting,
+               lt_settings);
+
+       dp_get_lttpr_mode_override(link, &lt_settings->lttpr_mode);
+
+       status = dpcd_configure_channel_coding(link, lt_settings);
+       if (status != DC_OK && link->is_hpd_pending)
+               return LINK_TRAINING_ABORT;
+
+       /* Configure lttpr mode */
+       status = dpcd_configure_lttpr_mode(link, lt_settings);
+       if (status != DC_OK && link->is_hpd_pending)
+               return LINK_TRAINING_ABORT;
+
+       /* Set link rate, lane count and spread. */
+       status = dpcd_set_link_settings(link, lt_settings);
+       if (status != DC_OK && link->is_hpd_pending)
+               return LINK_TRAINING_ABORT;
+
+       if (link->preferred_training_settings.fec_enable != NULL)
+               fec_enable = *link->preferred_training_settings.fec_enable;
+       else
+               fec_enable = true;
+       status = dp_set_fec_ready(link, link_res, fec_enable);
+       if (status != DC_OK && link->is_hpd_pending)
+               return LINK_TRAINING_ABORT;
+
+       return LINK_TRAINING_SUCCESS;
+}
+
+static enum dc_status core_link_send_set_config(
+       struct dc_link *link,
+       uint8_t msg_type,
+       uint8_t msg_data)
+{
+       struct set_config_cmd_payload payload;
+       enum set_config_status set_config_result = SET_CONFIG_PENDING;
+
+       /* prepare set_config payload */
+       payload.msg_type = msg_type;
+       payload.msg_data = msg_data;
+
+       if (!link->ddc->ddc_pin && !link->aux_access_disabled &&
+                       (dm_helpers_dmub_set_config_sync(link->ctx,
+                       link, &payload, &set_config_result) == -1)) {
+               return DC_ERROR_UNEXPECTED;
+       }
+
+       /* set_config should return ACK if successful */
+       return (set_config_result == SET_CONFIG_ACK_RECEIVED) ? DC_OK : DC_ERROR_UNEXPECTED;
+}
+
+/* Build SET_CONFIG message data payload for specified message type. */
+static uint8_t dpia_build_set_config_data(
+               enum dpia_set_config_type type,
+               struct dc_link *link,
+               struct link_training_settings *lt_settings)
+{
+       union dpia_set_config_data data;
+
+       data.raw = 0;
+
+       switch (type) {
+       case DPIA_SET_CFG_SET_LINK:
+               data.set_link.mode = lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT ? 1 : 0;
+               break;
+       case DPIA_SET_CFG_SET_PHY_TEST_MODE:
+               break;
+       case DPIA_SET_CFG_SET_VSPE:
+               /* Assume all lanes have same drive settings. */
+               data.set_vspe.swing = lt_settings->hw_lane_settings[0].VOLTAGE_SWING;
+               data.set_vspe.pre_emph = lt_settings->hw_lane_settings[0].PRE_EMPHASIS;
+               data.set_vspe.max_swing_reached =
+                               lt_settings->hw_lane_settings[0].VOLTAGE_SWING == VOLTAGE_SWING_MAX_LEVEL ? 1 : 0;
+               data.set_vspe.max_pre_emph_reached =
+                               lt_settings->hw_lane_settings[0].PRE_EMPHASIS == PRE_EMPHASIS_MAX_LEVEL ? 1 : 0;
+               break;
+       default:
+               ASSERT(false); /* Message type not supported by helper function. */
+               break;
+       }
+
+       return data.raw;
+}
+
+/* Convert DC training pattern to DPIA training stage. */
+static enum dc_status convert_trng_ptn_to_trng_stg(enum dc_dp_training_pattern tps, enum dpia_set_config_ts *ts)
+{
+       enum dc_status status = DC_OK;
+
+       switch (tps) {
+       case DP_TRAINING_PATTERN_SEQUENCE_1:
+               *ts = DPIA_TS_TPS1;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_2:
+               *ts = DPIA_TS_TPS2;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_3:
+               *ts = DPIA_TS_TPS3;
+               break;
+       case DP_TRAINING_PATTERN_SEQUENCE_4:
+               *ts = DPIA_TS_TPS4;
+               break;
+       case DP_TRAINING_PATTERN_VIDEOIDLE:
+               *ts = DPIA_TS_DPRX_DONE;
+               break;
+       default: /* TPS not supported by helper function. */
+               ASSERT(false);
+               *ts = DPIA_TS_DPRX_DONE;
+               status = DC_UNSUPPORTED_VALUE;
+               break;
+       }
+
+       return status;
+}
+
+/* Write training pattern to DPCD. */
+static enum dc_status dpcd_set_lt_pattern(
+       struct dc_link *link,
+       enum dc_dp_training_pattern pattern,
+       uint32_t hop)
+{
+       union dpcd_training_pattern dpcd_pattern = {0};
+       uint32_t dpcd_tps_offset = DP_TRAINING_PATTERN_SET;
+       enum dc_status status;
+
+       if (hop != DPRX)
+               dpcd_tps_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
+                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (hop - 1));
+
+       /* DpcdAddress_TrainingPatternSet */
+       dpcd_pattern.v1_4.TRAINING_PATTERN_SET =
+               dp_training_pattern_to_dpcd_training_pattern(link, pattern);
+
+       dpcd_pattern.v1_4.SCRAMBLING_DISABLE =
+               dp_initialize_scrambling_data_symbols(link, pattern);
+
+       if (hop != DPRX) {
+               DC_LOG_HW_LINK_TRAINING("%s\n LTTPR Repeater ID: %d\n 0x%X pattern = %x\n",
+                       __func__,
+                       hop,
+                       dpcd_tps_offset,
+                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
+       } else {
+               DC_LOG_HW_LINK_TRAINING("%s\n 0x%X pattern = %x\n",
+                       __func__,
+                       dpcd_tps_offset,
+                       dpcd_pattern.v1_4.TRAINING_PATTERN_SET);
+       }
+
+       status = core_link_write_dpcd(
+                       link,
+                       dpcd_tps_offset,
+                       &dpcd_pattern.raw,
+                       sizeof(dpcd_pattern.raw));
+
+       return status;
+}
+
+/* Execute clock recovery phase of link training for specified hop in display
+ * path.in non-transparent mode:
+ * - Driver issues both DPCD and SET_CONFIG transactions.
+ * - TPS1 is transmitted for any hops downstream of DPOA.
+ * - Drive (VS/PE) only transmitted for the hop immediately downstream of DPOA.
+ * - CR for the first hop (DPTX-to-DPIA) is assumed to be successful.
+ *
+ * @param link DPIA link being trained.
+ * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
+ * @param hop Hop in display path. DPRX = 0.
+ */
+static enum link_training_result dpia_training_cr_non_transparent(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings,
+               uint32_t hop)
+{
+       enum link_training_result result = LINK_TRAINING_CR_FAIL_LANE0;
+       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
+       enum dc_status status;
+       uint32_t retries_cr = 0; /* Number of consecutive attempts with same VS or PE. */
+       uint32_t retry_count = 0;
+       uint32_t wait_time_microsec = TRAINING_AUX_RD_INTERVAL; /* From DP spec, CR read interval is always 100us. */
+       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+       uint8_t set_cfg_data;
+       enum dpia_set_config_ts ts;
+
+       repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+
+       /* Cap of LINK_TRAINING_MAX_CR_RETRY attempts at clock recovery.
+        * Fix inherited from perform_clock_recovery_sequence() -
+        * the DP equivalent of this function:
+        * Required for Synaptics MST hub which can put the LT in
+        * infinite loop by switching the VS between level 0 and level 1
+        * continuously.
+        */
+       while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
+                       (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
+
+               /* DPTX-to-DPIA */
+               if (hop == repeater_cnt) {
+                       /* Send SET_CONFIG(SET_LINK:LC,LR,LTTPR) to notify DPOA that
+                        * non-transparent link training has started.
+                        * This also enables the transmission of clk_sync packets.
+                        */
+                       set_cfg_data = dpia_build_set_config_data(
+                                       DPIA_SET_CFG_SET_LINK,
+                                       link,
+                                       lt_settings);
+                       status = core_link_send_set_config(
+                                       link,
+                                       DPIA_SET_CFG_SET_LINK,
+                                       set_cfg_data);
+                       /* CR for this hop is considered successful as long as
+                        * SET_CONFIG message is acknowledged by DPOA.
+                        */
+                       if (status == DC_OK)
+                               result = LINK_TRAINING_SUCCESS;
+                       else
+                               result = LINK_TRAINING_ABORT;
+                       break;
+               }
+
+               /* DPOA-to-x */
+               /* Instruct DPOA to transmit TPS1 then update DPCD. */
+               if (retry_count == 0) {
+                       status = convert_trng_ptn_to_trng_stg(lt_settings->pattern_for_cr, &ts);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+                       status = core_link_send_set_config(
+                                       link,
+                                       DPIA_SET_CFG_SET_TRAINING,
+                                       ts);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+                       status = dpcd_set_lt_pattern(link, lt_settings->pattern_for_cr, hop);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+               }
+
+               /* Update DPOA drive settings then DPCD. DPOA does only adjusts
+                * drive settings for hops immediately downstream.
+                */
+               if (hop == repeater_cnt - 1) {
+                       set_cfg_data = dpia_build_set_config_data(
+                                       DPIA_SET_CFG_SET_VSPE,
+                                       link,
+                                       lt_settings);
+                       status = core_link_send_set_config(
+                                       link,
+                                       DPIA_SET_CFG_SET_VSPE,
+                                       set_cfg_data);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+               }
+               status = dpcd_set_lane_settings(link, lt_settings, hop);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+                       break;
+               }
+
+               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
+
+               /* Read status and adjustment requests from DPCD. */
+               status = dp_get_lane_status_and_lane_adjust(
+                               link,
+                               lt_settings,
+                               dpcd_lane_status,
+                               &dpcd_lane_status_updated,
+                               dpcd_lane_adjust,
+                               hop);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+                       break;
+               }
+
+               /* Check if clock recovery successful. */
+               if (dp_is_cr_done(lane_count, dpcd_lane_status)) {
+                       result = LINK_TRAINING_SUCCESS;
+                       break;
+               }
+
+               result = dp_get_cr_failure(lane_count, dpcd_lane_status);
+
+               if (dp_is_max_vs_reached(lt_settings))
+                       break;
+
+               /* Count number of attempts with same drive settings.
+                * Note: settings are the same for all lanes,
+                * so comparing first lane is sufficient.
+                */
+               if ((lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
+                               dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
+                               && (lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET ==
+                                               dpcd_lane_adjust[0].bits.PRE_EMPHASIS_LANE))
+                       retries_cr++;
+               else
+                       retries_cr = 0;
+
+               /* Update VS/PE. */
+               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                               lt_settings->hw_lane_settings,
+                               lt_settings->dpcd_lane_settings);
+               retry_count++;
+       }
+
+       /* Abort link training if clock recovery failed due to HPD unplug. */
+       if (link->is_hpd_pending)
+               result = LINK_TRAINING_ABORT;
+
+       DC_LOG_HW_LINK_TRAINING(
+               "%s\n DPIA(%d) clock recovery\n -hop(%d)\n - result(%d)\n - retries(%d)\n - status(%d)\n",
+               __func__,
+               link->link_id.enum_id - ENUM_ID_1,
+               hop,
+               result,
+               retry_count,
+               status);
+
+       return result;
+}
+
+/* Execute clock recovery phase of link training in transparent LTTPR mode:
+ * - Driver only issues DPCD transactions and leaves USB4 tunneling (SET_CONFIG) messages to DPIA.
+ * - Driver writes TPS1 to DPCD to kick off training.
+ * - Clock recovery (CR) for link is handled by DPOA, which reports result to DPIA on completion.
+ * - DPIA communicates result to driver by updating CR status when driver reads DPCD.
+ *
+ * @param link DPIA link being trained.
+ * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
+ */
+static enum link_training_result dpia_training_cr_transparent(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       enum link_training_result result = LINK_TRAINING_CR_FAIL_LANE0;
+       enum dc_status status;
+       uint32_t retries_cr = 0; /* Number of consecutive attempts with same VS or PE. */
+       uint32_t retry_count = 0;
+       uint32_t wait_time_microsec = lt_settings->cr_pattern_time;
+       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+
+       /* Cap of LINK_TRAINING_MAX_CR_RETRY attempts at clock recovery.
+        * Fix inherited from perform_clock_recovery_sequence() -
+        * the DP equivalent of this function:
+        * Required for Synaptics MST hub which can put the LT in
+        * infinite loop by switching the VS between level 0 and level 1
+        * continuously.
+        */
+       while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
+                       (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
+
+               /* Write TPS1 (not VS or PE) to DPCD to start CR phase.
+                * DPIA sends SET_CONFIG(SET_LINK) to notify DPOA to
+                * start link training.
+                */
+               if (retry_count == 0) {
+                       status = dpcd_set_lt_pattern(link, lt_settings->pattern_for_cr, DPRX);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+               }
+
+               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
+
+               /* Read status and adjustment requests from DPCD. */
+               status = dp_get_lane_status_and_lane_adjust(
+                               link,
+                               lt_settings,
+                               dpcd_lane_status,
+                               &dpcd_lane_status_updated,
+                               dpcd_lane_adjust,
+                               DPRX);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+                       break;
+               }
+
+               /* Check if clock recovery successful. */
+               if (dp_is_cr_done(lane_count, dpcd_lane_status)) {
+                       result = LINK_TRAINING_SUCCESS;
+                       break;
+               }
+
+               result = dp_get_cr_failure(lane_count, dpcd_lane_status);
+
+               if (dp_is_max_vs_reached(lt_settings))
+                       break;
+
+               /* Count number of attempts with same drive settings.
+                * Note: settings are the same for all lanes,
+                * so comparing first lane is sufficient.
+                */
+               if ((lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
+                               dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
+                               && (lt_settings->dpcd_lane_settings[0].bits.PRE_EMPHASIS_SET ==
+                                               dpcd_lane_adjust[0].bits.PRE_EMPHASIS_LANE))
+                       retries_cr++;
+               else
+                       retries_cr = 0;
+
+               /* Update VS/PE. */
+               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+               retry_count++;
+       }
+
+       /* Abort link training if clock recovery failed due to HPD unplug. */
+       if (link->is_hpd_pending)
+               result = LINK_TRAINING_ABORT;
+
+       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) clock recovery\n -hop(%d)\n - result(%d)\n - retries(%d)\n",
+               __func__,
+               link->link_id.enum_id - ENUM_ID_1,
+               DPRX,
+               result,
+               retry_count);
+
+       return result;
+}
+
+/* Execute clock recovery phase of link training for specified hop in display
+ * path.
+ *
+ * @param link DPIA link being trained.
+ * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
+ * @param hop Hop in display path. DPRX = 0.
+ */
+static enum link_training_result dpia_training_cr_phase(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings,
+               uint32_t hop)
+{
+       enum link_training_result result = LINK_TRAINING_CR_FAIL_LANE0;
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
+               result = dpia_training_cr_non_transparent(link, link_res, lt_settings, hop);
+       else
+               result = dpia_training_cr_transparent(link, link_res, lt_settings);
+
+       return result;
+}
+
+/* Return status read interval during equalization phase. */
+static uint32_t dpia_get_eq_aux_rd_interval(
+               const struct dc_link *link,
+               const struct link_training_settings *lt_settings,
+               uint32_t hop)
+{
+       uint32_t wait_time_microsec;
+
+       if (hop == DPRX)
+               wait_time_microsec = lt_settings->eq_pattern_time;
+       else
+               wait_time_microsec =
+                               dp_translate_training_aux_read_interval(
+                                       link->dpcd_caps.lttpr_caps.aux_rd_interval[hop - 1]);
+
+       /* Check debug option for extending aux read interval. */
+       if (link->dc->debug.dpia_debug.bits.extend_aux_rd_interval)
+               wait_time_microsec = DPIA_DEBUG_EXTENDED_AUX_RD_INTERVAL_US;
+
+       return wait_time_microsec;
+}
+
+/* Execute equalization phase of link training for specified hop in display
+ * path in non-transparent mode:
+ * - driver issues both DPCD and SET_CONFIG transactions.
+ * - TPSx is transmitted for any hops downstream of DPOA.
+ * - Drive (VS/PE) only transmitted for the hop immediately downstream of DPOA.
+ * - EQ for the first hop (DPTX-to-DPIA) is assumed to be successful.
+ * - DPRX EQ only reported successful when both DPRX and DPIA requirements (clk sync packets sent) fulfilled.
+ *
+ * @param link DPIA link being trained.
+ * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
+ * @param hop Hop in display path. DPRX = 0.
+ */
+static enum link_training_result dpia_training_eq_non_transparent(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings,
+               uint32_t hop)
+{
+       enum link_training_result result = LINK_TRAINING_EQ_FAIL_EQ;
+       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
+       uint32_t retries_eq = 0;
+       enum dc_status status;
+       enum dc_dp_training_pattern tr_pattern;
+       uint32_t wait_time_microsec;
+       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+       uint8_t set_cfg_data;
+       enum dpia_set_config_ts ts;
+
+       /* Training pattern is TPS4 for repeater;
+        * TPS2/3/4 for DPRX depending on what it supports.
+        */
+       if (hop == DPRX)
+               tr_pattern = lt_settings->pattern_for_eq;
+       else
+               tr_pattern = DP_TRAINING_PATTERN_SEQUENCE_4;
+
+       repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+
+       for (retries_eq = 0; retries_eq < LINK_TRAINING_MAX_RETRY_COUNT; retries_eq++) {
+
+               /* DPTX-to-DPIA equalization always successful. */
+               if (hop == repeater_cnt) {
+                       result = LINK_TRAINING_SUCCESS;
+                       break;
+               }
+
+               /* Instruct DPOA to transmit TPSn then update DPCD. */
+               if (retries_eq == 0) {
+                       status = convert_trng_ptn_to_trng_stg(tr_pattern, &ts);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+                       status = core_link_send_set_config(
+                                       link,
+                                       DPIA_SET_CFG_SET_TRAINING,
+                                       ts);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+                       status = dpcd_set_lt_pattern(link, tr_pattern, hop);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+               }
+
+               /* Update DPOA drive settings then DPCD. DPOA only adjusts
+                * drive settings for hop immediately downstream.
+                */
+               if (hop == repeater_cnt - 1) {
+                       set_cfg_data = dpia_build_set_config_data(
+                                       DPIA_SET_CFG_SET_VSPE,
+                                       link,
+                                       lt_settings);
+                       status = core_link_send_set_config(
+                                       link,
+                                       DPIA_SET_CFG_SET_VSPE,
+                                       set_cfg_data);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+               }
+               status = dpcd_set_lane_settings(link, lt_settings, hop);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+                       break;
+               }
+
+               /* Extend wait time on second equalisation attempt on final hop to
+                * ensure clock sync packets have been sent.
+                */
+               if (hop == DPRX && retries_eq == 1)
+                       wait_time_microsec = max(wait_time_microsec, (uint32_t) DPIA_CLK_SYNC_DELAY);
+               else
+                       wait_time_microsec = dpia_get_eq_aux_rd_interval(link, lt_settings, hop);
+
+               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
+
+               /* Read status and adjustment requests from DPCD. */
+               status = dp_get_lane_status_and_lane_adjust(
+                               link,
+                               lt_settings,
+                               dpcd_lane_status,
+                               &dpcd_lane_status_updated,
+                               dpcd_lane_adjust,
+                               hop);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+                       break;
+               }
+
+               /* CR can still fail during EQ phase. Fail training if CR fails. */
+               if (!dp_is_cr_done(lane_count, dpcd_lane_status)) {
+                       result = LINK_TRAINING_EQ_FAIL_CR;
+                       break;
+               }
+
+               if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
+                               dp_is_symbol_locked(link->cur_link_settings.lane_count, dpcd_lane_status) &&
+                               dp_is_interlane_aligned(dpcd_lane_status_updated)) {
+                       result =  LINK_TRAINING_SUCCESS;
+                       break;
+               }
+
+               /* Update VS/PE. */
+               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+       }
+
+       /* Abort link training if equalization failed due to HPD unplug. */
+       if (link->is_hpd_pending)
+               result = LINK_TRAINING_ABORT;
+
+       DC_LOG_HW_LINK_TRAINING(
+               "%s\n DPIA(%d) equalization\n - hop(%d)\n - result(%d)\n - retries(%d)\n - status(%d)\n",
+               __func__,
+               link->link_id.enum_id - ENUM_ID_1,
+               hop,
+               result,
+               retries_eq,
+               status);
+
+       return result;
+}
+
+/* Execute equalization phase of link training for specified hop in display
+ * path in transparent LTTPR mode:
+ * - driver only issues DPCD transactions leaves USB4 tunneling (SET_CONFIG) messages to DPIA.
+ * - driver writes TPSx to DPCD to notify DPIA that is in equalization phase.
+ * - equalization (EQ) for link is handled by DPOA, which reports result to DPIA on completion.
+ * - DPIA communicates result to driver by updating EQ status when driver reads DPCD.
+ *
+ * @param link DPIA link being trained.
+ * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
+ * @param hop Hop in display path. DPRX = 0.
+ */
+static enum link_training_result dpia_training_eq_transparent(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       enum link_training_result result = LINK_TRAINING_EQ_FAIL_EQ;
+       uint32_t retries_eq = 0;
+       enum dc_status status;
+       enum dc_dp_training_pattern tr_pattern = lt_settings->pattern_for_eq;
+       uint32_t wait_time_microsec;
+       enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+       union lane_align_status_updated dpcd_lane_status_updated = {0};
+       union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+       union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+
+       wait_time_microsec = dpia_get_eq_aux_rd_interval(link, lt_settings, DPRX);
+
+       for (retries_eq = 0; retries_eq < LINK_TRAINING_MAX_RETRY_COUNT; retries_eq++) {
+
+               if (retries_eq == 0) {
+                       status = dpcd_set_lt_pattern(link, tr_pattern, DPRX);
+                       if (status != DC_OK) {
+                               result = LINK_TRAINING_ABORT;
+                               break;
+                       }
+               }
+
+               dp_wait_for_training_aux_rd_interval(link, wait_time_microsec);
+
+               /* Read status and adjustment requests from DPCD. */
+               status = dp_get_lane_status_and_lane_adjust(
+                               link,
+                               lt_settings,
+                               dpcd_lane_status,
+                               &dpcd_lane_status_updated,
+                               dpcd_lane_adjust,
+                               DPRX);
+               if (status != DC_OK) {
+                       result = LINK_TRAINING_ABORT;
+                       break;
+               }
+
+               /* CR can still fail during EQ phase. Fail training if CR fails. */
+               if (!dp_is_cr_done(lane_count, dpcd_lane_status)) {
+                       result = LINK_TRAINING_EQ_FAIL_CR;
+                       break;
+               }
+
+               if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
+                               dp_is_symbol_locked(link->cur_link_settings.lane_count, dpcd_lane_status)) {
+                       /* Take into consideration corner case for DP 1.4a LL Compliance CTS as USB4
+                        * has to share encoders unlike DP and USBC
+                        */
+                       if (dp_is_interlane_aligned(dpcd_lane_status_updated) || (link->is_automated && retries_eq)) {
+                               result =  LINK_TRAINING_SUCCESS;
+                               break;
+                       }
+               }
+
+               /* Update VS/PE. */
+               dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                               lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+       }
+
+       /* Abort link training if equalization failed due to HPD unplug. */
+       if (link->is_hpd_pending)
+               result = LINK_TRAINING_ABORT;
+
+       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) equalization\n - hop(%d)\n - result(%d)\n - retries(%d)\n",
+               __func__,
+               link->link_id.enum_id - ENUM_ID_1,
+               DPRX,
+               result,
+               retries_eq);
+
+       return result;
+}
+
+/* Execute equalization phase of link training for specified hop in display
+ * path.
+ *
+ * @param link DPIA link being trained.
+ * @param lt_settings link_setting and drive settings (voltage swing and pre-emphasis).
+ * @param hop Hop in display path. DPRX = 0.
+ */
+static enum link_training_result dpia_training_eq_phase(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings,
+               uint32_t hop)
+{
+       enum link_training_result result;
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
+               result = dpia_training_eq_non_transparent(link, link_res, lt_settings, hop);
+       else
+               result = dpia_training_eq_transparent(link, link_res, lt_settings);
+
+       return result;
+}
+
+/* End training of specified hop in display path. */
+static enum dc_status dpcd_clear_lt_pattern(
+       struct dc_link *link,
+       uint32_t hop)
+{
+       union dpcd_training_pattern dpcd_pattern = {0};
+       uint32_t dpcd_tps_offset = DP_TRAINING_PATTERN_SET;
+       enum dc_status status;
+
+       if (hop != DPRX)
+               dpcd_tps_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
+                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (hop - 1));
+
+       status = core_link_write_dpcd(
+                       link,
+                       dpcd_tps_offset,
+                       &dpcd_pattern.raw,
+                       sizeof(dpcd_pattern.raw));
+
+       return status;
+}
+
+/* End training of specified hop in display path.
+ *
+ * In transparent LTTPR mode:
+ * - driver clears training pattern for the specified hop in DPCD.
+ * In non-transparent LTTPR mode:
+ * - in addition to clearing training pattern, driver issues USB4 tunneling
+ * (SET_CONFIG) messages to notify DPOA when training is done for first hop
+ * (DPTX-to-DPIA) and last hop (DPRX).
+ *
+ * @param link DPIA link being trained.
+ * @param hop Hop in display path. DPRX = 0.
+ */
+static enum link_training_result dpia_training_end(
+               struct dc_link *link,
+               struct link_training_settings *lt_settings,
+               uint32_t hop)
+{
+       enum link_training_result result = LINK_TRAINING_SUCCESS;
+       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
+       enum dc_status status;
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
+
+               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+
+               if (hop == repeater_cnt) { /* DPTX-to-DPIA */
+                       /* Send SET_CONFIG(SET_TRAINING:0xff) to notify DPOA that
+                        * DPTX-to-DPIA hop trained. No DPCD write needed for first hop.
+                        */
+                       status = core_link_send_set_config(
+                                       link,
+                                       DPIA_SET_CFG_SET_TRAINING,
+                                       DPIA_TS_UFP_DONE);
+                       if (status != DC_OK)
+                               result = LINK_TRAINING_ABORT;
+               } else { /* DPOA-to-x */
+                       /* Write 0x0 to TRAINING_PATTERN_SET */
+                       status = dpcd_clear_lt_pattern(link, hop);
+                       if (status != DC_OK)
+                               result = LINK_TRAINING_ABORT;
+               }
+
+               /* Notify DPOA that non-transparent link training of DPRX done. */
+               if (hop == DPRX && result != LINK_TRAINING_ABORT) {
+                       status = core_link_send_set_config(
+                                       link,
+                                       DPIA_SET_CFG_SET_TRAINING,
+                                       DPIA_TS_DPRX_DONE);
+                       if (status != DC_OK)
+                               result = LINK_TRAINING_ABORT;
+               }
+
+       } else { /* non-LTTPR or transparent LTTPR. */
+
+               /* Write 0x0 to TRAINING_PATTERN_SET */
+               status = dpcd_clear_lt_pattern(link, hop);
+               if (status != DC_OK)
+                       result = LINK_TRAINING_ABORT;
+
+       }
+
+       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) end\n - hop(%d)\n - result(%d)\n - LTTPR mode(%d)\n",
+               __func__,
+               link->link_id.enum_id - ENUM_ID_1,
+               hop,
+               result,
+               lt_settings->lttpr_mode);
+
+       return result;
+}
+
+/* When aborting training of specified hop in display path, clean up by:
+ * - Attempting to clear DPCD TRAINING_PATTERN_SET, LINK_BW_SET and LANE_COUNT_SET.
+ * - Sending SET_CONFIG(SET_LINK) with lane count and link rate set to 0.
+ *
+ * @param link DPIA link being trained.
+ * @param hop Hop in display path. DPRX = 0.
+ */
+static void dpia_training_abort(
+               struct dc_link *link,
+               struct link_training_settings *lt_settings,
+               uint32_t hop)
+{
+       uint8_t data = 0;
+       uint32_t dpcd_tps_offset = DP_TRAINING_PATTERN_SET;
+
+       DC_LOG_HW_LINK_TRAINING("%s\n DPIA(%d) aborting\n - LTTPR mode(%d)\n - HPD(%d)\n",
+               __func__,
+               link->link_id.enum_id - ENUM_ID_1,
+               lt_settings->lttpr_mode,
+               link->is_hpd_pending);
+
+       /* Abandon clean-up if sink unplugged. */
+       if (link->is_hpd_pending)
+               return;
+
+       if (hop != DPRX)
+               dpcd_tps_offset = DP_TRAINING_PATTERN_SET_PHY_REPEATER1 +
+                       ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (hop - 1));
+
+       core_link_write_dpcd(link, dpcd_tps_offset, &data, 1);
+       core_link_write_dpcd(link, DP_LINK_BW_SET, &data, 1);
+       core_link_write_dpcd(link, DP_LANE_COUNT_SET, &data, 1);
+       core_link_send_set_config(link, DPIA_SET_CFG_SET_LINK, data);
+}
+
+enum link_training_result dc_link_dpia_perform_link_training(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       const struct dc_link_settings *link_setting,
+       bool skip_video_pattern)
+{
+       enum link_training_result result;
+       struct link_training_settings lt_settings = {0};
+       uint8_t repeater_cnt = 0; /* Number of hops/repeaters in display path. */
+       int8_t repeater_id; /* Current hop. */
+
+       struct dc_link_settings link_settings = *link_setting; // non-const copy to pass in
+
+       lt_settings.lttpr_mode = dc_link_decide_lttpr_mode(link, &link_settings);
+
+       /* Configure link as prescribed in link_setting and set LTTPR mode. */
+       result = dpia_configure_link(link, link_res, link_setting, &lt_settings);
+       if (result != LINK_TRAINING_SUCCESS)
+               return result;
+
+       if (lt_settings.lttpr_mode == LTTPR_MODE_NON_TRANSPARENT)
+               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+
+       /* Train each hop in turn starting with the one closest to DPTX.
+        * In transparent or non-LTTPR mode, train only the final hop (DPRX).
+        */
+       for (repeater_id = repeater_cnt; repeater_id >= 0; repeater_id--) {
+               /* Clock recovery. */
+               result = dpia_training_cr_phase(link, link_res, &lt_settings, repeater_id);
+               if (result != LINK_TRAINING_SUCCESS)
+                       break;
+
+               /* Equalization. */
+               result = dpia_training_eq_phase(link, link_res, &lt_settings, repeater_id);
+               if (result != LINK_TRAINING_SUCCESS)
+                       break;
+
+               /* Stop training hop. */
+               result = dpia_training_end(link, &lt_settings, repeater_id);
+               if (result != LINK_TRAINING_SUCCESS)
+                       break;
+       }
+
+       /* Double-check link status if training successful; gracefully abort
+        * training of current hop if training failed due to message tunneling
+        * failure; end training of hop if training ended conventionally and
+        * falling back to lower bandwidth settings possible.
+        */
+       if (result == LINK_TRAINING_SUCCESS) {
+               msleep(5);
+               if (!link->is_automated)
+                       result = dp_check_link_loss_status(link, &lt_settings);
+       } else if (result == LINK_TRAINING_ABORT)
+               dpia_training_abort(link, &lt_settings, repeater_id);
+       else
+               dpia_training_end(link, &lt_settings, repeater_id);
+
+       return result;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_dpia.h
new file mode 100644 (file)
index 0000000..0150f29
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+
+#ifndef __DC_LINK_DP_TRAINING_DPIA_H__
+#define __DC_LINK_DP_TRAINING_DPIA_H__
+#include "link_dp_training.h"
+
+/* Train DP tunneling link for USB4 DPIA display endpoint.
+ * DPIA equivalent of dc_link_dp_perfrorm_link_training.
+ * Aborts link training upon detection of sink unplug.
+ */
+enum link_training_result dc_link_dpia_perform_link_training(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       const struct dc_link_settings *link_setting,
+       bool skip_video_pattern);
+
+#endif /* __DC_LINK_DP_TRAINING_DPIA_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_fixed_vs_pe_retimer.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_fixed_vs_pe_retimer.c
new file mode 100644 (file)
index 0000000..860b5ee
--- /dev/null
@@ -0,0 +1,580 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ * This file implements 8b/10b link training specially modified to support an
+ * embedded retimer chip. This retimer chip is referred as fixed vs pe retimer.
+ * Unlike native dp connection this chip requires a modified link training
+ * protocol based on 8b/10b link training. Since this is a non standard sequence
+ * and we must support this hardware, we decided to isolate it in its own
+ * training sequence inside its own file.
+ */
+#include "link_dp_training_fixed_vs_pe_retimer.h"
+#include "link_dp_training_8b_10b.h"
+#include "link_dpcd.h"
+#include "link_dp_phy.h"
+#include "link_dp_capability.h"
+#include "dc_link_dp.h"
+
+#define DC_LOGGER \
+       link->ctx->logger
+
+void dp_fixed_vs_pe_read_lane_adjust(
+       struct dc_link *link,
+       union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX])
+{
+       const uint8_t vendor_lttpr_write_data_vs[3] = {0x0, 0x53, 0x63};
+       const uint8_t vendor_lttpr_write_data_pe[3] = {0x0, 0x54, 0x63};
+       const uint8_t offset = dp_parse_lttpr_repeater_count(
+                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+       uint32_t vendor_lttpr_write_address = 0xF004F;
+       uint32_t vendor_lttpr_read_address = 0xF0053;
+       uint8_t dprx_vs = 0;
+       uint8_t dprx_pe = 0;
+       uint8_t lane;
+
+       if (offset != 0xFF) {
+               vendor_lttpr_write_address +=
+                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+               vendor_lttpr_read_address +=
+                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+       }
+
+       /* W/A to read lane settings requested by DPRX */
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_vs[0],
+                       sizeof(vendor_lttpr_write_data_vs));
+       core_link_read_dpcd(
+                       link,
+                       vendor_lttpr_read_address,
+                       &dprx_vs,
+                       1);
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_pe[0],
+                       sizeof(vendor_lttpr_write_data_pe));
+       core_link_read_dpcd(
+                       link,
+                       vendor_lttpr_read_address,
+                       &dprx_pe,
+                       1);
+
+       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+               dpcd_lane_adjust[lane].bits.VOLTAGE_SWING_SET  = (dprx_vs >> (2 * lane)) & 0x3;
+               dpcd_lane_adjust[lane].bits.PRE_EMPHASIS_SET = (dprx_pe >> (2 * lane)) & 0x3;
+       }
+}
+
+
+void dp_fixed_vs_pe_set_retimer_lane_settings(
+       struct dc_link *link,
+       const union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX],
+       uint8_t lane_count)
+{
+       const uint8_t offset = dp_parse_lttpr_repeater_count(
+                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+       const uint8_t vendor_lttpr_write_data_reset[4] = {0x1, 0x50, 0x63, 0xFF};
+       uint32_t vendor_lttpr_write_address = 0xF004F;
+       uint8_t vendor_lttpr_write_data_vs[4] = {0x1, 0x51, 0x63, 0x0};
+       uint8_t vendor_lttpr_write_data_pe[4] = {0x1, 0x52, 0x63, 0x0};
+       uint8_t lane = 0;
+
+       if (offset != 0xFF) {
+               vendor_lttpr_write_address +=
+                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+       }
+
+       for (lane = 0; lane < lane_count; lane++) {
+               vendor_lttpr_write_data_vs[3] |=
+                               dpcd_lane_adjust[lane].bits.VOLTAGE_SWING_SET << (2 * lane);
+               vendor_lttpr_write_data_pe[3] |=
+                               dpcd_lane_adjust[lane].bits.PRE_EMPHASIS_SET << (2 * lane);
+       }
+
+       /* Force LTTPR to output desired VS and PE */
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_reset[0],
+                       sizeof(vendor_lttpr_write_data_reset));
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_vs[0],
+                       sizeof(vendor_lttpr_write_data_vs));
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_pe[0],
+                       sizeof(vendor_lttpr_write_data_pe));
+}
+
+static enum link_training_result perform_fixed_vs_pe_nontransparent_training_sequence(
+               struct dc_link *link,
+               const struct link_resource *link_res,
+               struct link_training_settings *lt_settings)
+{
+       enum link_training_result status = LINK_TRAINING_SUCCESS;
+       uint8_t lane = 0;
+       uint8_t toggle_rate = 0x6;
+       uint8_t target_rate = 0x6;
+       bool apply_toggle_rate_wa = false;
+       uint8_t repeater_cnt;
+       uint8_t repeater_id;
+
+       /* Fixed VS/PE specific: Force CR AUX RD Interval to at least 16ms */
+       if (lt_settings->cr_pattern_time < 16000)
+               lt_settings->cr_pattern_time = 16000;
+
+       /* Fixed VS/PE specific: Toggle link rate */
+       apply_toggle_rate_wa = (link->vendor_specific_lttpr_link_rate_wa == target_rate);
+       target_rate = get_dpcd_link_rate(&lt_settings->link_settings);
+       toggle_rate = (target_rate == 0x6) ? 0xA : 0x6;
+
+       if (apply_toggle_rate_wa)
+               lt_settings->link_settings.link_rate = toggle_rate;
+
+       if (link->ctx->dc->work_arounds.lt_early_cr_pattern)
+               start_clock_recovery_pattern_early(link, link_res, lt_settings, DPRX);
+
+       /* 1. set link rate, lane count and spread. */
+       dpcd_set_link_settings(link, lt_settings);
+
+       /* Fixed VS/PE specific: Toggle link rate back*/
+       if (apply_toggle_rate_wa) {
+               core_link_write_dpcd(
+                               link,
+                               DP_LINK_BW_SET,
+                               &target_rate,
+                               1);
+       }
+
+       link->vendor_specific_lttpr_link_rate_wa = target_rate;
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
+
+               /* 2. perform link training (set link training done
+                *  to false is done as well)
+                */
+               repeater_cnt = dp_parse_lttpr_repeater_count(link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+
+               for (repeater_id = repeater_cnt; (repeater_id > 0 && status == LINK_TRAINING_SUCCESS);
+                               repeater_id--) {
+                       status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, repeater_id);
+
+                       if (status != LINK_TRAINING_SUCCESS) {
+                               repeater_training_done(link, repeater_id);
+                               break;
+                       }
+
+                       status = perform_8b_10b_channel_equalization_sequence(link,
+                                       link_res,
+                                       lt_settings,
+                                       repeater_id);
+
+                       repeater_training_done(link, repeater_id);
+
+                       if (status != LINK_TRAINING_SUCCESS)
+                               break;
+
+                       for (lane = 0; lane < LANE_COUNT_DP_MAX; lane++) {
+                               lt_settings->dpcd_lane_settings[lane].raw = 0;
+                               lt_settings->hw_lane_settings[lane].VOLTAGE_SWING = 0;
+                               lt_settings->hw_lane_settings[lane].PRE_EMPHASIS = 0;
+                       }
+               }
+       }
+
+       if (status == LINK_TRAINING_SUCCESS) {
+               status = perform_8b_10b_clock_recovery_sequence(link, link_res, lt_settings, DPRX);
+               if (status == LINK_TRAINING_SUCCESS) {
+                       status = perform_8b_10b_channel_equalization_sequence(link,
+                                                                      link_res,
+                                                                      lt_settings,
+                                                                      DPRX);
+               }
+       }
+
+       return status;
+}
+
+
+enum link_training_result dp_perform_fixed_vs_pe_training_sequence(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings)
+{
+       const uint8_t vendor_lttpr_write_data_reset[4] = {0x1, 0x50, 0x63, 0xFF};
+       const uint8_t offset = dp_parse_lttpr_repeater_count(
+                       link->dpcd_caps.lttpr_caps.phy_repeater_cnt);
+       const uint8_t vendor_lttpr_write_data_intercept_en[4] = {0x1, 0x55, 0x63, 0x0};
+       const uint8_t vendor_lttpr_write_data_intercept_dis[4] = {0x1, 0x55, 0x63, 0x68};
+       uint32_t pre_disable_intercept_delay_ms = link->dc->debug.fixed_vs_aux_delay_config_wa;
+       uint8_t vendor_lttpr_write_data_vs[4] = {0x1, 0x51, 0x63, 0x0};
+       uint8_t vendor_lttpr_write_data_pe[4] = {0x1, 0x52, 0x63, 0x0};
+       uint32_t vendor_lttpr_write_address = 0xF004F;
+       enum link_training_result status = LINK_TRAINING_SUCCESS;
+       uint8_t lane = 0;
+       union down_spread_ctrl downspread = {0};
+       union lane_count_set lane_count_set = {0};
+       uint8_t toggle_rate;
+       uint8_t rate;
+
+       /* Only 8b/10b is supported */
+       ASSERT(link_dp_get_encoding_format(&lt_settings->link_settings) ==
+                       DP_8b_10b_ENCODING);
+
+       if (lt_settings->lttpr_mode == LTTPR_MODE_NON_TRANSPARENT) {
+               status = perform_fixed_vs_pe_nontransparent_training_sequence(link, link_res, lt_settings);
+               return status;
+       }
+
+       if (offset != 0xFF) {
+               vendor_lttpr_write_address +=
+                               ((DP_REPEATER_CONFIGURATION_AND_STATUS_SIZE) * (offset - 1));
+
+               /* Certain display and cable configuration require extra delay */
+               if (offset > 2)
+                       pre_disable_intercept_delay_ms = link->dc->debug.fixed_vs_aux_delay_config_wa * 2;
+       }
+
+       /* Vendor specific: Reset lane settings */
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_reset[0],
+                       sizeof(vendor_lttpr_write_data_reset));
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_vs[0],
+                       sizeof(vendor_lttpr_write_data_vs));
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_pe[0],
+                       sizeof(vendor_lttpr_write_data_pe));
+
+       /* Vendor specific: Enable intercept */
+       core_link_write_dpcd(
+                       link,
+                       vendor_lttpr_write_address,
+                       &vendor_lttpr_write_data_intercept_en[0],
+                       sizeof(vendor_lttpr_write_data_intercept_en));
+
+       /* 1. set link rate, lane count and spread. */
+
+       downspread.raw = (uint8_t)(lt_settings->link_settings.link_spread);
+
+       lane_count_set.bits.LANE_COUNT_SET =
+       lt_settings->link_settings.lane_count;
+
+       lane_count_set.bits.ENHANCED_FRAMING = lt_settings->enhanced_framing;
+       lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED = 0;
+
+
+       if (lt_settings->pattern_for_eq < DP_TRAINING_PATTERN_SEQUENCE_4) {
+               lane_count_set.bits.POST_LT_ADJ_REQ_GRANTED =
+                               link->dpcd_caps.max_ln_count.bits.POST_LT_ADJ_REQ_SUPPORTED;
+       }
+
+       core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
+               &downspread.raw, sizeof(downspread));
+
+       core_link_write_dpcd(link, DP_LANE_COUNT_SET,
+               &lane_count_set.raw, 1);
+
+       rate = get_dpcd_link_rate(&lt_settings->link_settings);
+
+       /* Vendor specific: Toggle link rate */
+       toggle_rate = (rate == 0x6) ? 0xA : 0x6;
+
+       if (link->vendor_specific_lttpr_link_rate_wa == rate) {
+               core_link_write_dpcd(
+                               link,
+                               DP_LINK_BW_SET,
+                               &toggle_rate,
+                               1);
+       }
+
+       link->vendor_specific_lttpr_link_rate_wa = rate;
+
+       core_link_write_dpcd(link, DP_LINK_BW_SET, &rate, 1);
+
+       DC_LOG_HW_LINK_TRAINING("%s\n %x rate = %x\n %x lane = %x framing = %x\n %x spread = %x\n",
+               __func__,
+               DP_LINK_BW_SET,
+               lt_settings->link_settings.link_rate,
+               DP_LANE_COUNT_SET,
+               lt_settings->link_settings.lane_count,
+               lt_settings->enhanced_framing,
+               DP_DOWNSPREAD_CTRL,
+               lt_settings->link_settings.link_spread);
+
+       /* 2. Perform link training */
+
+       /* Perform Clock Recovery Sequence */
+       if (status == LINK_TRAINING_SUCCESS) {
+               const uint8_t max_vendor_dpcd_retries = 10;
+               uint32_t retries_cr;
+               uint32_t retry_count;
+               uint32_t wait_time_microsec;
+               enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+               union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX];
+               union lane_align_status_updated dpcd_lane_status_updated;
+               union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+               enum dc_status dpcd_status = DC_OK;
+               uint8_t i = 0;
+
+               retries_cr = 0;
+               retry_count = 0;
+
+               memset(&dpcd_lane_status, '\0', sizeof(dpcd_lane_status));
+               memset(&dpcd_lane_status_updated, '\0',
+               sizeof(dpcd_lane_status_updated));
+
+               while ((retries_cr < LINK_TRAINING_MAX_RETRY_COUNT) &&
+                       (retry_count < LINK_TRAINING_MAX_CR_RETRY)) {
+
+
+                       /* 1. call HWSS to set lane settings */
+                       dp_set_hw_lane_settings(
+                                       link,
+                                       link_res,
+                                       lt_settings,
+                                       0);
+
+                       /* 2. update DPCD of the receiver */
+                       if (!retry_count) {
+                               /* EPR #361076 - write as a 5-byte burst,
+                                * but only for the 1-st iteration.
+                                */
+                               dpcd_set_lt_pattern_and_lane_settings(
+                                               link,
+                                               lt_settings,
+                                               lt_settings->pattern_for_cr,
+                                               0);
+                               /* Vendor specific: Disable intercept */
+                               for (i = 0; i < max_vendor_dpcd_retries; i++) {
+                                       msleep(pre_disable_intercept_delay_ms);
+                                       dpcd_status = core_link_write_dpcd(
+                                                       link,
+                                                       vendor_lttpr_write_address,
+                                                       &vendor_lttpr_write_data_intercept_dis[0],
+                                                       sizeof(vendor_lttpr_write_data_intercept_dis));
+
+                                       if (dpcd_status == DC_OK)
+                                               break;
+
+                                       core_link_write_dpcd(
+                                                       link,
+                                                       vendor_lttpr_write_address,
+                                                       &vendor_lttpr_write_data_intercept_en[0],
+                                                       sizeof(vendor_lttpr_write_data_intercept_en));
+                               }
+                       } else {
+                               vendor_lttpr_write_data_vs[3] = 0;
+                               vendor_lttpr_write_data_pe[3] = 0;
+
+                               for (lane = 0; lane < lane_count; lane++) {
+                                       vendor_lttpr_write_data_vs[3] |=
+                                                       lt_settings->dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET << (2 * lane);
+                                       vendor_lttpr_write_data_pe[3] |=
+                                                       lt_settings->dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET << (2 * lane);
+                               }
+
+                               /* Vendor specific: Update VS and PE to DPRX requested value */
+                               core_link_write_dpcd(
+                                               link,
+                                               vendor_lttpr_write_address,
+                                               &vendor_lttpr_write_data_vs[0],
+                                               sizeof(vendor_lttpr_write_data_vs));
+                               core_link_write_dpcd(
+                                               link,
+                                               vendor_lttpr_write_address,
+                                               &vendor_lttpr_write_data_pe[0],
+                                               sizeof(vendor_lttpr_write_data_pe));
+
+                               dpcd_set_lane_settings(
+                                               link,
+                                               lt_settings,
+                                               0);
+                       }
+
+                       /* 3. wait receiver to lock-on*/
+                       wait_time_microsec = lt_settings->cr_pattern_time;
+
+                       dp_wait_for_training_aux_rd_interval(
+                                       link,
+                                       wait_time_microsec);
+
+                       /* 4. Read lane status and requested drive
+                        * settings as set by the sink
+                        */
+                       dp_get_lane_status_and_lane_adjust(
+                                       link,
+                                       lt_settings,
+                                       dpcd_lane_status,
+                                       &dpcd_lane_status_updated,
+                                       dpcd_lane_adjust,
+                                       0);
+
+                       /* 5. check CR done*/
+                       if (dp_is_cr_done(lane_count, dpcd_lane_status)) {
+                               status = LINK_TRAINING_SUCCESS;
+                               break;
+                       }
+
+                       /* 6. max VS reached*/
+                       if (dp_is_max_vs_reached(lt_settings))
+                               break;
+
+                       /* 7. same lane settings */
+                       /* Note: settings are the same for all lanes,
+                        * so comparing first lane is sufficient
+                        */
+                       if (lt_settings->dpcd_lane_settings[0].bits.VOLTAGE_SWING_SET ==
+                                       dpcd_lane_adjust[0].bits.VOLTAGE_SWING_LANE)
+                               retries_cr++;
+                       else
+                               retries_cr = 0;
+
+                       /* 8. update VS/PE/PC2 in lt_settings*/
+                       dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+                       retry_count++;
+               }
+
+               if (retry_count >= LINK_TRAINING_MAX_CR_RETRY) {
+                       ASSERT(0);
+                       DC_LOG_ERROR("%s: Link Training Error, could not get CR after %d tries. Possibly voltage swing issue",
+                               __func__,
+                               LINK_TRAINING_MAX_CR_RETRY);
+
+               }
+
+               status = dp_get_cr_failure(lane_count, dpcd_lane_status);
+       }
+
+       /* Perform Channel EQ Sequence */
+       if (status == LINK_TRAINING_SUCCESS) {
+               enum dc_dp_training_pattern tr_pattern;
+               uint32_t retries_ch_eq;
+               uint32_t wait_time_microsec;
+               enum dc_lane_count lane_count = lt_settings->link_settings.lane_count;
+               union lane_align_status_updated dpcd_lane_status_updated = {0};
+               union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX] = {0};
+               union lane_adjust dpcd_lane_adjust[LANE_COUNT_DP_MAX] = {0};
+
+               /* Note: also check that TPS4 is a supported feature*/
+               tr_pattern = lt_settings->pattern_for_eq;
+
+               dp_set_hw_training_pattern(link, link_res, tr_pattern, 0);
+
+               status = LINK_TRAINING_EQ_FAIL_EQ;
+
+               for (retries_ch_eq = 0; retries_ch_eq <= LINK_TRAINING_MAX_RETRY_COUNT;
+                       retries_ch_eq++) {
+
+                       dp_set_hw_lane_settings(link, link_res, lt_settings, 0);
+
+                       vendor_lttpr_write_data_vs[3] = 0;
+                       vendor_lttpr_write_data_pe[3] = 0;
+
+                       for (lane = 0; lane < lane_count; lane++) {
+                               vendor_lttpr_write_data_vs[3] |=
+                                               lt_settings->dpcd_lane_settings[lane].bits.VOLTAGE_SWING_SET << (2 * lane);
+                               vendor_lttpr_write_data_pe[3] |=
+                                               lt_settings->dpcd_lane_settings[lane].bits.PRE_EMPHASIS_SET << (2 * lane);
+                       }
+
+                       /* Vendor specific: Update VS and PE to DPRX requested value */
+                       core_link_write_dpcd(
+                                       link,
+                                       vendor_lttpr_write_address,
+                                       &vendor_lttpr_write_data_vs[0],
+                                       sizeof(vendor_lttpr_write_data_vs));
+                       core_link_write_dpcd(
+                                       link,
+                                       vendor_lttpr_write_address,
+                                       &vendor_lttpr_write_data_pe[0],
+                                       sizeof(vendor_lttpr_write_data_pe));
+
+                       /* 2. update DPCD*/
+                       if (!retries_ch_eq)
+                               /* EPR #361076 - write as a 5-byte burst,
+                                * but only for the 1-st iteration
+                                */
+
+                               dpcd_set_lt_pattern_and_lane_settings(
+                                       link,
+                                       lt_settings,
+                                       tr_pattern, 0);
+                       else
+                               dpcd_set_lane_settings(link, lt_settings, 0);
+
+                       /* 3. wait for receiver to lock-on*/
+                       wait_time_microsec = lt_settings->eq_pattern_time;
+
+                       dp_wait_for_training_aux_rd_interval(
+                                       link,
+                                       wait_time_microsec);
+
+                       /* 4. Read lane status and requested
+                        * drive settings as set by the sink
+                        */
+                       dp_get_lane_status_and_lane_adjust(
+                               link,
+                               lt_settings,
+                               dpcd_lane_status,
+                               &dpcd_lane_status_updated,
+                               dpcd_lane_adjust,
+                               0);
+
+                       /* 5. check CR done*/
+                       if (!dp_is_cr_done(lane_count, dpcd_lane_status)) {
+                               status = LINK_TRAINING_EQ_FAIL_CR;
+                               break;
+                       }
+
+                       /* 6. check CHEQ done*/
+                       if (dp_is_ch_eq_done(lane_count, dpcd_lane_status) &&
+                                       dp_is_symbol_locked(lane_count, dpcd_lane_status) &&
+                                       dp_is_interlane_aligned(dpcd_lane_status_updated)) {
+                               status = LINK_TRAINING_SUCCESS;
+                               break;
+                       }
+
+                       /* 7. update VS/PE/PC2 in lt_settings*/
+                       dp_decide_lane_settings(lt_settings, dpcd_lane_adjust,
+                                       lt_settings->hw_lane_settings, lt_settings->dpcd_lane_settings);
+               }
+       }
+
+       return status;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_fixed_vs_pe_retimer.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training_fixed_vs_pe_retimer.h
new file mode 100644 (file)
index 0000000..e61970e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+
+#ifndef __DC_LINK_DP_FIXED_VS_PE_RETIMER_H__
+#define __DC_LINK_DP_FIXED_VS_PE_RETIMER_H__
+#include "link_dp_training.h"
+
+enum link_training_result dp_perform_fixed_vs_pe_training_sequence(
+       struct dc_link *link,
+       const struct link_resource *link_res,
+       struct link_training_settings *lt_settings);
+
+void dp_fixed_vs_pe_set_retimer_lane_settings(
+       struct dc_link *link,
+       const union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX],
+       uint8_t lane_count);
+
+void dp_fixed_vs_pe_read_lane_adjust(
+       struct dc_link *link,
+       union dpcd_training_lane dpcd_lane_adjust[LANE_COUNT_DP_MAX]);
+
+#endif /* __DC_LINK_DP_FIXED_VS_PE_RETIMER_H__ */
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c
new file mode 100644 (file)
index 0000000..5c9a302
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ *
+ * This file implements basic dpcd read/write functionality. It also does basic
+ * dpcd range check to ensure that every dpcd request is compliant with specs
+ * range requirements.
+ */
+
+#include "link_dpcd.h"
+#include <drm/display/drm_dp_helper.h>
+#include "dm_helpers.h"
+
+#define END_ADDRESS(start, size) (start + size - 1)
+#define ADDRESS_RANGE_SIZE(start, end) (end - start + 1)
+struct dpcd_address_range {
+       uint32_t start;
+       uint32_t end;
+};
+
+static enum dc_status internal_link_read_dpcd(
+       struct dc_link *link,
+       uint32_t address,
+       uint8_t *data,
+       uint32_t size)
+{
+       if (!link->aux_access_disabled &&
+                       !dm_helpers_dp_read_dpcd(link->ctx,
+                       link, address, data, size)) {
+               return DC_ERROR_UNEXPECTED;
+       }
+
+       return DC_OK;
+}
+
+static enum dc_status internal_link_write_dpcd(
+       struct dc_link *link,
+       uint32_t address,
+       const uint8_t *data,
+       uint32_t size)
+{
+       if (!link->aux_access_disabled &&
+                       !dm_helpers_dp_write_dpcd(link->ctx,
+                       link, address, data, size)) {
+               return DC_ERROR_UNEXPECTED;
+       }
+
+       return DC_OK;
+}
+
+/*
+ * Partition the entire DPCD address space
+ * XXX: This partitioning must cover the entire DPCD address space,
+ * and must contain no gaps or overlapping address ranges.
+ */
+static const struct dpcd_address_range mandatory_dpcd_partitions[] = {
+       { 0, DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR1) - 1},
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR1), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR2) - 1 },
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR2), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR3) - 1 },
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR3), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR4) - 1 },
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR4), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR5) - 1 },
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR5), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR6) - 1 },
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR6), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR7) - 1 },
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR7), DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR8) - 1 },
+       { DP_TRAINING_PATTERN_SET_PHY_REPEATER(DP_PHY_LTTPR8), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR1) - 1 },
+       /*
+        * The FEC registers are contiguous
+        */
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR1), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR1) - 1 },
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR2), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR2) - 1 },
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR3), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR3) - 1 },
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR4), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR4) - 1 },
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR5), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR5) - 1 },
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR6), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR6) - 1 },
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR7), DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR7) - 1 },
+       { DP_FEC_STATUS_PHY_REPEATER(DP_PHY_LTTPR8), DP_LTTPR_MAX_ADD },
+       /* all remaining DPCD addresses */
+       { DP_LTTPR_MAX_ADD + 1, DP_DPCD_MAX_ADD } };
+
+static inline bool do_addresses_intersect_with_range(
+               const struct dpcd_address_range *range,
+               const uint32_t start_address,
+               const uint32_t end_address)
+{
+       return start_address <= range->end && end_address >= range->start;
+}
+
+static uint32_t dpcd_get_next_partition_size(const uint32_t address, const uint32_t size)
+{
+       const uint32_t end_address = END_ADDRESS(address, size);
+       uint32_t partition_iterator = 0;
+
+       /*
+        * find current partition
+        * this loop spins forever if partition map above is not surjective
+        */
+       while (!do_addresses_intersect_with_range(&mandatory_dpcd_partitions[partition_iterator],
+                               address, end_address))
+               partition_iterator++;
+       if (end_address < mandatory_dpcd_partitions[partition_iterator].end)
+               return size;
+       return ADDRESS_RANGE_SIZE(address, mandatory_dpcd_partitions[partition_iterator].end);
+}
+
+/*
+ * Ranges of DPCD addresses that must be read in a single transaction
+ * XXX: Do not allow any two address ranges in this array to overlap
+ */
+static const struct dpcd_address_range mandatory_dpcd_blocks[] = {
+       { DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV, DP_PHY_REPEATER_EXTENDED_WAIT_TIMEOUT }};
+
+/*
+ * extend addresses to read all mandatory blocks together
+ */
+static void dpcd_extend_address_range(
+               const uint32_t in_address,
+               uint8_t * const in_data,
+               const uint32_t in_size,
+               uint32_t *out_address,
+               uint8_t **out_data,
+               uint32_t *out_size)
+{
+       const uint32_t end_address = END_ADDRESS(in_address, in_size);
+       const struct dpcd_address_range *addr_range;
+       struct dpcd_address_range new_addr_range;
+       uint32_t i;
+
+       new_addr_range.start = in_address;
+       new_addr_range.end = end_address;
+       for (i = 0; i < ARRAY_SIZE(mandatory_dpcd_blocks); i++) {
+               addr_range = &mandatory_dpcd_blocks[i];
+               if (addr_range->start <= in_address && addr_range->end >= in_address)
+                       new_addr_range.start = addr_range->start;
+
+               if (addr_range->start <= end_address && addr_range->end >= end_address)
+                       new_addr_range.end = addr_range->end;
+       }
+       *out_address = in_address;
+       *out_size = in_size;
+       *out_data = in_data;
+       if (new_addr_range.start != in_address || new_addr_range.end != end_address) {
+               *out_address = new_addr_range.start;
+               *out_size = ADDRESS_RANGE_SIZE(new_addr_range.start, new_addr_range.end);
+               *out_data = kzalloc(*out_size * sizeof(**out_data), GFP_KERNEL);
+       }
+}
+
+/*
+ * Reduce the AUX reply down to the values the caller requested
+ */
+static void dpcd_reduce_address_range(
+               const uint32_t extended_address,
+               uint8_t * const extended_data,
+               const uint32_t extended_size,
+               const uint32_t reduced_address,
+               uint8_t * const reduced_data,
+               const uint32_t reduced_size)
+{
+       const uint32_t offset = reduced_address - extended_address;
+
+       /*
+        * If the address is same, address was not extended.
+        * So we do not need to free any memory.
+        * The data is in original buffer(reduced_data).
+        */
+       if (extended_data == reduced_data)
+               return;
+
+       memcpy(&extended_data[offset], reduced_data, reduced_size);
+       kfree(extended_data);
+}
+
+enum dc_status core_link_read_dpcd(
+       struct dc_link *link,
+       uint32_t address,
+       uint8_t *data,
+       uint32_t size)
+{
+       uint32_t extended_address;
+       uint32_t partitioned_address;
+       uint8_t *extended_data;
+       uint32_t extended_size;
+       /* size of the remaining partitioned address space */
+       uint32_t size_left_to_read;
+       enum dc_status status;
+       /* size of the next partition to be read from */
+       uint32_t partition_size;
+       uint32_t data_index = 0;
+
+       dpcd_extend_address_range(address, data, size, &extended_address, &extended_data, &extended_size);
+       partitioned_address = extended_address;
+       size_left_to_read = extended_size;
+       while (size_left_to_read) {
+               partition_size = dpcd_get_next_partition_size(partitioned_address, size_left_to_read);
+               status = internal_link_read_dpcd(link, partitioned_address, &extended_data[data_index], partition_size);
+               if (status != DC_OK)
+                       break;
+               partitioned_address += partition_size;
+               data_index += partition_size;
+               size_left_to_read -= partition_size;
+       }
+       dpcd_reduce_address_range(extended_address, extended_data, extended_size, address, data, size);
+       return status;
+}
+
+enum dc_status core_link_write_dpcd(
+       struct dc_link *link,
+       uint32_t address,
+       const uint8_t *data,
+       uint32_t size)
+{
+       uint32_t partition_size;
+       uint32_t data_index = 0;
+       enum dc_status status;
+
+       while (size) {
+               partition_size = dpcd_get_next_partition_size(address, size);
+               status = internal_link_write_dpcd(link, address, &data[data_index], partition_size);
+               if (status != DC_OK)
+                       break;
+               address += partition_size;
+               data_index += partition_size;
+               size -= partition_size;
+       }
+       return status;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.h
new file mode 100644 (file)
index 0000000..08d787a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#ifndef __LINK_DPCD_H__
+#define __LINK_DPCD_H__
+#include "link.h"
+#include "dpcd_defs.h"
+
+enum dc_status core_link_read_dpcd(
+               struct dc_link *link,
+               uint32_t address,
+               uint8_t *data,
+               uint32_t size);
+
+enum dc_status core_link_write_dpcd(
+               struct dc_link *link,
+               uint32_t address,
+               const uint8_t *data,
+               uint32_t size);
+#endif
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_hpd.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_hpd.c
new file mode 100644 (file)
index 0000000..5f39dfe
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+/* FILE POLICY AND INTENDED USAGE:
+ *
+ * This file implements functions that manage basic HPD components such as gpio.
+ * It also provides wrapper functions to execute HPD related programming. This
+ * file only manages basic HPD functionality. It doesn't manage detection or
+ * feature or signal specific HPD behaviors.
+ */
+#include "link_hpd.h"
+#include "gpio_service_interface.h"
+
+bool dc_link_get_hpd_state(struct dc_link *dc_link)
+{
+       uint32_t state;
+
+       dal_gpio_lock_pin(dc_link->hpd_gpio);
+       dal_gpio_get_value(dc_link->hpd_gpio, &state);
+       dal_gpio_unlock_pin(dc_link->hpd_gpio);
+
+       return state;
+}
+
+void dc_link_enable_hpd(const struct dc_link *link)
+{
+       struct link_encoder *encoder = link->link_enc;
+
+       if (encoder != NULL && encoder->funcs->enable_hpd != NULL)
+               encoder->funcs->enable_hpd(encoder);
+}
+
+void dc_link_disable_hpd(const struct dc_link *link)
+{
+       struct link_encoder *encoder = link->link_enc;
+
+       if (encoder != NULL && encoder->funcs->enable_hpd != NULL)
+               encoder->funcs->disable_hpd(encoder);
+}
+
+void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
+{
+       struct gpio *hpd;
+
+       if (enable) {
+               link->is_hpd_filter_disabled = false;
+               program_hpd_filter(link);
+       } else {
+               link->is_hpd_filter_disabled = true;
+               /* Obtain HPD handle */
+               hpd = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
+
+               if (!hpd)
+                       return;
+
+               /* Setup HPD filtering */
+               if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
+                       struct gpio_hpd_config config;
+
+                       config.delay_on_connect = 0;
+                       config.delay_on_disconnect = 0;
+
+                       dal_irq_setup_hpd_filter(hpd, &config);
+
+                       dal_gpio_close(hpd);
+               } else {
+                       ASSERT_CRITICAL(false);
+               }
+               /* Release HPD handle */
+               dal_gpio_destroy_irq(&hpd);
+       }
+}
+
+struct gpio *link_get_hpd_gpio(struct dc_bios *dcb,
+                         struct graphics_object_id link_id,
+                         struct gpio_service *gpio_service)
+{
+       enum bp_result bp_result;
+       struct graphics_object_hpd_info hpd_info;
+       struct gpio_pin_info pin_info;
+
+       if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
+               return NULL;
+
+       bp_result = dcb->funcs->get_gpio_pin_info(dcb,
+               hpd_info.hpd_int_gpio_uid, &pin_info);
+
+       if (bp_result != BP_RESULT_OK) {
+               ASSERT(bp_result == BP_RESULT_NORECORD);
+               return NULL;
+       }
+
+       return dal_gpio_service_create_irq(gpio_service,
+                                          pin_info.offset,
+                                          pin_info.mask);
+}
+
+bool query_hpd_status(struct dc_link *link, uint32_t *is_hpd_high)
+{
+       struct gpio *hpd_pin = link_get_hpd_gpio(
+                       link->ctx->dc_bios, link->link_id,
+                       link->ctx->gpio_service);
+       if (!hpd_pin)
+               return false;
+
+       dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
+       dal_gpio_get_value(hpd_pin, is_hpd_high);
+       dal_gpio_close(hpd_pin);
+       dal_gpio_destroy_irq(&hpd_pin);
+       return true;
+}
+
+enum hpd_source_id get_hpd_line(struct dc_link *link)
+{
+       struct gpio *hpd;
+       enum hpd_source_id hpd_id;
+
+               hpd_id = HPD_SOURCEID_UNKNOWN;
+
+       hpd = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id,
+                          link->ctx->gpio_service);
+
+       if (hpd) {
+               switch (dal_irq_get_source(hpd)) {
+               case DC_IRQ_SOURCE_HPD1:
+                       hpd_id = HPD_SOURCEID1;
+               break;
+               case DC_IRQ_SOURCE_HPD2:
+                       hpd_id = HPD_SOURCEID2;
+               break;
+               case DC_IRQ_SOURCE_HPD3:
+                       hpd_id = HPD_SOURCEID3;
+               break;
+               case DC_IRQ_SOURCE_HPD4:
+                       hpd_id = HPD_SOURCEID4;
+               break;
+               case DC_IRQ_SOURCE_HPD5:
+                       hpd_id = HPD_SOURCEID5;
+               break;
+               case DC_IRQ_SOURCE_HPD6:
+                       hpd_id = HPD_SOURCEID6;
+               break;
+               default:
+                       BREAK_TO_DEBUGGER();
+               break;
+               }
+
+               dal_gpio_destroy_irq(&hpd);
+       }
+
+       return hpd_id;
+}
+
+bool program_hpd_filter(const struct dc_link *link)
+{
+       bool result = false;
+       struct gpio *hpd;
+       int delay_on_connect_in_ms = 0;
+       int delay_on_disconnect_in_ms = 0;
+
+       if (link->is_hpd_filter_disabled)
+               return false;
+       /* Verify feature is supported */
+       switch (link->connector_signal) {
+       case SIGNAL_TYPE_DVI_SINGLE_LINK:
+       case SIGNAL_TYPE_DVI_DUAL_LINK:
+       case SIGNAL_TYPE_HDMI_TYPE_A:
+               /* Program hpd filter */
+               delay_on_connect_in_ms = 500;
+               delay_on_disconnect_in_ms = 100;
+               break;
+       case SIGNAL_TYPE_DISPLAY_PORT:
+       case SIGNAL_TYPE_DISPLAY_PORT_MST:
+               /* Program hpd filter to allow DP signal to settle */
+               /* 500: not able to detect MST <-> SST switch as HPD is low for
+                * only 100ms on DELL U2413
+                * 0: some passive dongle still show aux mode instead of i2c
+                * 20-50: not enough to hide bouncing HPD with passive dongle.
+                * also see intermittent i2c read issues.
+                */
+               delay_on_connect_in_ms = 80;
+               delay_on_disconnect_in_ms = 0;
+               break;
+       case SIGNAL_TYPE_LVDS:
+       case SIGNAL_TYPE_EDP:
+       default:
+               /* Don't program hpd filter */
+               return false;
+       }
+
+       /* Obtain HPD handle */
+       hpd = link_get_hpd_gpio(link->ctx->dc_bios, link->link_id,
+                          link->ctx->gpio_service);
+
+       if (!hpd)
+               return result;
+
+       /* Setup HPD filtering */
+       if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
+               struct gpio_hpd_config config;
+
+               config.delay_on_connect = delay_on_connect_in_ms;
+               config.delay_on_disconnect = delay_on_disconnect_in_ms;
+
+               dal_irq_setup_hpd_filter(hpd, &config);
+
+               dal_gpio_close(hpd);
+
+               result = true;
+       } else {
+               ASSERT_CRITICAL(false);
+       }
+
+       /* Release HPD handle */
+       dal_gpio_destroy_irq(&hpd);
+
+       return result;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_hpd.h b/drivers/gpu/drm/amd/display/dc/link/protocols/link_hpd.h
new file mode 100644 (file)
index 0000000..3d122de
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+
+#ifndef __DC_LINK_HPD_H__
+#define __DC_LINK_HPD_H__
+#include "link.h"
+
+enum hpd_source_id get_hpd_line(struct dc_link *link);
+/*
+ *  Function: program_hpd_filter
+ *
+ *  @brief
+ *     Programs HPD filter on associated HPD line to default values.
+ *
+ *  @return
+ *     true on success, false otherwise
+ */
+bool program_hpd_filter(const struct dc_link *link);
+/* Query hot plug status of USB4 DP tunnel.
+ * Returns true if HPD high.
+ */
+bool dpia_query_hpd_status(struct dc_link *link);
+bool query_hpd_status(struct dc_link *link, uint32_t *is_hpd_high);
+#endif /* __DC_LINK_HPD_H__ */