1 | /* |
2 | * Copyright 2023 Advanced Micro Devices, Inc. |
3 | * |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | * copy of this software and associated documentation files (the "Software"), |
6 | * to deal in the Software without restriction, including without limitation |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8 | * and/or sell copies of the Software, and to permit persons to whom the |
9 | * Software is furnished to do so, subject to the following conditions: |
10 | * |
11 | * The above copyright notice and this permission notice shall be included in |
12 | * all copies or substantial portions of the Software. |
13 | * |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
20 | * OTHER DEALINGS IN THE SOFTWARE. |
21 | * |
22 | * Authors: AMD |
23 | * |
24 | */ |
25 | #include "link_hwss_dio.h" |
26 | #include "link_hwss_dio_fixed_vs_pe_retimer.h" |
27 | #include "link_enc_cfg.h" |
28 | |
29 | uint8_t dp_dio_fixed_vs_pe_retimer_lane_cfg_to_hw_cfg(struct dc_link *link) |
30 | { |
31 | // TODO: Get USB-C cable orientation |
32 | if (link->cur_link_settings.lane_count == LANE_COUNT_FOUR) |
33 | return 0xF2; |
34 | else |
35 | return 0x12; |
36 | } |
37 | |
38 | void dp_dio_fixed_vs_pe_retimer_exit_manual_automation(struct dc_link *link) |
39 | { |
40 | const uint8_t dp_type = dp_dio_fixed_vs_pe_retimer_lane_cfg_to_hw_cfg(link); |
41 | const uint8_t vendor_lttpr_exit_manual_automation_0[4] = {0x1, 0x11, 0x0, 0x06}; |
42 | const uint8_t vendor_lttpr_exit_manual_automation_1[4] = {0x1, 0x50, dp_type, 0x0}; |
43 | const uint8_t vendor_lttpr_exit_manual_automation_2[4] = {0x1, 0x50, 0x50, 0x0}; |
44 | const uint8_t vendor_lttpr_exit_manual_automation_3[4] = {0x1, 0x51, 0x50, 0x0}; |
45 | const uint8_t vendor_lttpr_exit_manual_automation_4[4] = {0x1, 0x10, 0x58, 0x0}; |
46 | const uint8_t vendor_lttpr_exit_manual_automation_5[4] = {0x1, 0x10, 0x59, 0x0}; |
47 | const uint8_t vendor_lttpr_exit_manual_automation_6[4] = {0x1, 0x30, 0x51, 0x0}; |
48 | const uint8_t vendor_lttpr_exit_manual_automation_7[4] = {0x1, 0x30, 0x52, 0x0}; |
49 | const uint8_t vendor_lttpr_exit_manual_automation_8[4] = {0x1, 0x30, 0x54, 0x0}; |
50 | const uint8_t vendor_lttpr_exit_manual_automation_9[4] = {0x1, 0x30, 0x55, 0x0}; |
51 | |
52 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
53 | &vendor_lttpr_exit_manual_automation_0[0], sizeof(vendor_lttpr_exit_manual_automation_0)); |
54 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
55 | &vendor_lttpr_exit_manual_automation_1[0], sizeof(vendor_lttpr_exit_manual_automation_1)); |
56 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
57 | &vendor_lttpr_exit_manual_automation_2[0], sizeof(vendor_lttpr_exit_manual_automation_2)); |
58 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
59 | &vendor_lttpr_exit_manual_automation_3[0], sizeof(vendor_lttpr_exit_manual_automation_3)); |
60 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
61 | &vendor_lttpr_exit_manual_automation_4[0], sizeof(vendor_lttpr_exit_manual_automation_4)); |
62 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
63 | &vendor_lttpr_exit_manual_automation_5[0], sizeof(vendor_lttpr_exit_manual_automation_5)); |
64 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
65 | &vendor_lttpr_exit_manual_automation_6[0], sizeof(vendor_lttpr_exit_manual_automation_6)); |
66 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
67 | &vendor_lttpr_exit_manual_automation_7[0], sizeof(vendor_lttpr_exit_manual_automation_7)); |
68 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
69 | &vendor_lttpr_exit_manual_automation_8[0], sizeof(vendor_lttpr_exit_manual_automation_8)); |
70 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
71 | &vendor_lttpr_exit_manual_automation_9[0], sizeof(vendor_lttpr_exit_manual_automation_9)); |
72 | } |
73 | |
74 | static bool set_dio_fixed_vs_pe_retimer_dp_link_test_pattern_override(struct dc_link *link, |
75 | const struct link_resource *link_res, struct encoder_set_dp_phy_pattern_param *tp_params, |
76 | const struct link_hwss *link_hwss) |
77 | { |
78 | struct encoder_set_dp_phy_pattern_param hw_tp_params = { 0 }; |
79 | const uint8_t pltpat_custom[10] = {0x1F, 0x7C, 0xF0, 0xC1, 0x07, 0x1F, 0x7C, 0xF0, 0xC1, 0x07}; |
80 | const uint8_t vendor_lttpr_write_data_pg0[4] = {0x1, 0x11, 0x0, 0x0}; |
81 | const uint8_t vendor_lttpr_exit_manual_automation_0[4] = {0x1, 0x11, 0x0, 0x06}; |
82 | |
83 | if (!link->dpcd_caps.lttpr_caps.main_link_channel_coding.bits.DP_128b_132b_SUPPORTED) |
84 | return false; |
85 | |
86 | if (tp_params == NULL) |
87 | return false; |
88 | |
89 | if (IS_DP_PHY_SQUARE_PATTERN(link->current_test_pattern)) |
90 | // Deprogram overrides from previous test pattern |
91 | dp_dio_fixed_vs_pe_retimer_exit_manual_automation(link); |
92 | |
93 | switch (tp_params->dp_phy_pattern) { |
94 | case DP_TEST_PATTERN_80BIT_CUSTOM: |
95 | if (tp_params->custom_pattern_size == 0 || memcmp(p: tp_params->custom_pattern, |
96 | q: pltpat_custom, size: tp_params->custom_pattern_size) != 0) |
97 | return false; |
98 | hw_tp_params.custom_pattern = tp_params->custom_pattern; |
99 | hw_tp_params.custom_pattern_size = tp_params->custom_pattern_size; |
100 | break; |
101 | case DP_TEST_PATTERN_D102: |
102 | break; |
103 | default: |
104 | if (link->current_test_pattern == DP_TEST_PATTERN_80BIT_CUSTOM || |
105 | link->current_test_pattern == DP_TEST_PATTERN_D102) |
106 | // Deprogram overrides from previous test pattern |
107 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
108 | &vendor_lttpr_exit_manual_automation_0[0], |
109 | sizeof(vendor_lttpr_exit_manual_automation_0)); |
110 | |
111 | return false; |
112 | } |
113 | |
114 | hw_tp_params.dp_phy_pattern = tp_params->dp_phy_pattern; |
115 | hw_tp_params.dp_panel_mode = tp_params->dp_panel_mode; |
116 | |
117 | if (link_hwss->ext.set_dp_link_test_pattern) |
118 | link_hwss->ext.set_dp_link_test_pattern(link, link_res, &hw_tp_params); |
119 | |
120 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
121 | &vendor_lttpr_write_data_pg0[0], sizeof(vendor_lttpr_write_data_pg0)); |
122 | |
123 | return true; |
124 | } |
125 | |
126 | static void set_dio_fixed_vs_pe_retimer_dp_link_test_pattern(struct dc_link *link, |
127 | const struct link_resource *link_res, |
128 | struct encoder_set_dp_phy_pattern_param *tp_params) |
129 | { |
130 | struct link_encoder *link_enc = link_enc_cfg_get_link_enc(link); |
131 | |
132 | if (!set_dio_fixed_vs_pe_retimer_dp_link_test_pattern_override( |
133 | link, link_res, tp_params, link_hwss: get_dio_link_hwss())) { |
134 | link_enc->funcs->dp_set_phy_pattern(link_enc, tp_params); |
135 | } |
136 | link->dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_SET_SOURCE_PATTERN); |
137 | } |
138 | |
139 | void enable_dio_fixed_vs_pe_retimer_program_4lane_output(struct dc_link *link) |
140 | { |
141 | const uint8_t vendor_lttpr_write_data_4lane_1[4] = {0x1, 0x6E, 0xF2, 0x19}; |
142 | const uint8_t vendor_lttpr_write_data_4lane_2[4] = {0x1, 0x6B, 0xF2, 0x01}; |
143 | const uint8_t vendor_lttpr_write_data_4lane_3[4] = {0x1, 0x6D, 0xF2, 0x18}; |
144 | const uint8_t vendor_lttpr_write_data_4lane_4[4] = {0x1, 0x6C, 0xF2, 0x03}; |
145 | const uint8_t vendor_lttpr_write_data_4lane_5[4] = {0x1, 0x03, 0xF3, 0x06}; |
146 | |
147 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
148 | &vendor_lttpr_write_data_4lane_1[0], sizeof(vendor_lttpr_write_data_4lane_1)); |
149 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
150 | &vendor_lttpr_write_data_4lane_2[0], sizeof(vendor_lttpr_write_data_4lane_2)); |
151 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
152 | &vendor_lttpr_write_data_4lane_3[0], sizeof(vendor_lttpr_write_data_4lane_3)); |
153 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
154 | &vendor_lttpr_write_data_4lane_4[0], sizeof(vendor_lttpr_write_data_4lane_4)); |
155 | link->dc->link_srv->configure_fixed_vs_pe_retimer(link->ddc, |
156 | &vendor_lttpr_write_data_4lane_5[0], sizeof(vendor_lttpr_write_data_4lane_5)); |
157 | } |
158 | |
159 | static void enable_dio_fixed_vs_pe_retimer_dp_link_output(struct dc_link *link, |
160 | const struct link_resource *link_res, |
161 | enum signal_type signal, |
162 | enum clock_source_id clock_source, |
163 | const struct dc_link_settings *link_settings) |
164 | { |
165 | if (link_settings->lane_count == LANE_COUNT_FOUR) |
166 | enable_dio_fixed_vs_pe_retimer_program_4lane_output(link); |
167 | |
168 | enable_dio_dp_link_output(link, link_res, signal, clock_source, link_settings); |
169 | } |
170 | |
171 | static const struct link_hwss dio_fixed_vs_pe_retimer_link_hwss = { |
172 | .setup_stream_encoder = setup_dio_stream_encoder, |
173 | .reset_stream_encoder = reset_dio_stream_encoder, |
174 | .setup_stream_attribute = setup_dio_stream_attribute, |
175 | .disable_link_output = disable_dio_link_output, |
176 | .setup_audio_output = setup_dio_audio_output, |
177 | .enable_audio_packet = enable_dio_audio_packet, |
178 | .disable_audio_packet = disable_dio_audio_packet, |
179 | .ext = { |
180 | .set_throttled_vcp_size = set_dio_throttled_vcp_size, |
181 | .enable_dp_link_output = enable_dio_fixed_vs_pe_retimer_dp_link_output, |
182 | .set_dp_link_test_pattern = set_dio_fixed_vs_pe_retimer_dp_link_test_pattern, |
183 | .set_dp_lane_settings = set_dio_dp_lane_settings, |
184 | .update_stream_allocation_table = update_dio_stream_allocation_table, |
185 | }, |
186 | }; |
187 | |
188 | bool requires_fixed_vs_pe_retimer_dio_link_hwss(const struct dc_link *link) |
189 | { |
190 | return (link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN); |
191 | } |
192 | |
193 | const struct link_hwss *get_dio_fixed_vs_pe_retimer_link_hwss(void) |
194 | { |
195 | return &dio_fixed_vs_pe_retimer_link_hwss; |
196 | } |
197 | |