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
26 /* FILE POLICY AND INTENDED USAGE:
27 * This file owns the programming sequence of stream's dpms state associated
28 * with the link and link's enable/disable sequences as result of the stream's
29 * dpms state change.
30 *
31 * TODO - The reason link owns stream's dpms programming sequence is
32 * because dpms programming sequence is highly dependent on underlying signal
33 * specific link protocols. This unfortunately causes link to own a portion of
34 * stream state programming sequence. This creates a gray area where the
35 * boundary between link and stream is not clearly defined.
36 */
37
38 #include "link_dpms.h"
39 #include "link_hwss.h"
40 #include "link_validation.h"
41 #include "accessories/link_fpga.h"
42 #include "accessories/link_dp_trace.h"
43 #include "protocols/link_dpcd.h"
44 #include "protocols/link_ddc.h"
45 #include "protocols/link_hpd.h"
46 #include "protocols/link_dp_phy.h"
47 #include "protocols/link_dp_capability.h"
48 #include "protocols/link_dp_training.h"
49 #include "protocols/link_edp_panel_control.h"
50 #include "protocols/link_dp_dpia_bw.h"
51
52 #include "dm_helpers.h"
53 #include "link_enc_cfg.h"
54 #include "resource.h"
55 #include "dsc.h"
56 #include "dccg.h"
57 #include "clk_mgr.h"
58 #include "atomfirmware.h"
59 #define DC_LOGGER_INIT(logger)
60
61 #define LINK_INFO(...) \
62 DC_LOG_HW_HOTPLUG( \
63 __VA_ARGS__)
64
65 #define RETIMER_REDRIVER_INFO(...) \
66 DC_LOG_RETIMER_REDRIVER( \
67 __VA_ARGS__)
68 #include "dc/dcn30/dcn30_vpg.h"
69
70 #define MAX_MTP_SLOT_COUNT 64
71 #define LINK_TRAINING_ATTEMPTS 4
72 #define PEAK_FACTOR_X1000 1006
73
link_blank_all_dp_displays(struct dc * dc)74 void link_blank_all_dp_displays(struct dc *dc)
75 {
76 unsigned int i;
77 uint8_t dpcd_power_state = '\0';
78 enum dc_status status = DC_ERROR_UNEXPECTED;
79
80 for (i = 0; i < dc->link_count; i++) {
81 if ((dc->links[i]->connector_signal != SIGNAL_TYPE_DISPLAY_PORT) ||
82 (dc->links[i]->priv == NULL) || (dc->links[i]->local_sink == NULL))
83 continue;
84
85 /* DP 2.0 spec requires that we read LTTPR caps first */
86 dp_retrieve_lttpr_cap(dc->links[i]);
87 /* if any of the displays are lit up turn them off */
88 status = core_link_read_dpcd(dc->links[i], DP_SET_POWER,
89 &dpcd_power_state, sizeof(dpcd_power_state));
90
91 if (status == DC_OK && dpcd_power_state == DP_POWER_STATE_D0)
92 link_blank_dp_stream(dc->links[i], true);
93 }
94
95 }
96
link_blank_all_edp_displays(struct dc * dc)97 void link_blank_all_edp_displays(struct dc *dc)
98 {
99 unsigned int i;
100 uint8_t dpcd_power_state = '\0';
101 enum dc_status status = DC_ERROR_UNEXPECTED;
102
103 for (i = 0; i < dc->link_count; i++) {
104 if ((dc->links[i]->connector_signal != SIGNAL_TYPE_EDP) ||
105 (!dc->links[i]->edp_sink_present))
106 continue;
107
108 /* if any of the displays are lit up turn them off */
109 status = core_link_read_dpcd(dc->links[i], DP_SET_POWER,
110 &dpcd_power_state, sizeof(dpcd_power_state));
111
112 if (status == DC_OK && dpcd_power_state == DP_POWER_STATE_D0)
113 link_blank_dp_stream(dc->links[i], true);
114 }
115 }
116
link_blank_dp_stream(struct dc_link * link,bool hw_init)117 void link_blank_dp_stream(struct dc_link *link, bool hw_init)
118 {
119 unsigned int j;
120 struct dc *dc = link->ctx->dc;
121 enum signal_type signal = link->connector_signal;
122
123 if ((signal == SIGNAL_TYPE_EDP) ||
124 (signal == SIGNAL_TYPE_DISPLAY_PORT)) {
125 if (link->ep_type == DISPLAY_ENDPOINT_PHY &&
126 link->link_enc->funcs->get_dig_frontend &&
127 link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
128 unsigned int fe = link->link_enc->funcs->get_dig_frontend(link->link_enc);
129
130 if (fe != ENGINE_ID_UNKNOWN)
131 for (j = 0; j < dc->res_pool->stream_enc_count; j++) {
132 if (fe == dc->res_pool->stream_enc[j]->id) {
133 dc->res_pool->stream_enc[j]->funcs->dp_blank(link,
134 dc->res_pool->stream_enc[j]);
135 break;
136 }
137 }
138 }
139
140 if ((!link->wa_flags.dp_keep_receiver_powered) || hw_init)
141 dpcd_write_rx_power_ctrl(link, false);
142 }
143 }
144
link_set_all_streams_dpms_off_for_link(struct dc_link * link)145 void link_set_all_streams_dpms_off_for_link(struct dc_link *link)
146 {
147 struct pipe_ctx *pipes[MAX_PIPES];
148 struct dc_stream_state *streams[MAX_PIPES];
149 struct dc_state *state = link->dc->current_state;
150 uint8_t count;
151 int i;
152 struct dc_stream_update stream_update;
153 bool dpms_off = true;
154 struct link_resource link_res = {0};
155
156 memset(&stream_update, 0, sizeof(stream_update));
157 stream_update.dpms_off = &dpms_off;
158
159 link_get_master_pipes_with_dpms_on(link, state, &count, pipes);
160
161 /* The subsequent call to dc_commit_updates_for_stream for a full update
162 * will release the current state and swap to a new state. Releasing the
163 * current state results in the stream pointers in the pipe_ctx structs
164 * to be zero'd. Hence, cache all streams prior to dc_commit_updates_for_stream.
165 */
166 for (i = 0; i < count; i++)
167 streams[i] = pipes[i]->stream;
168
169 for (i = 0; i < count; i++) {
170 stream_update.stream = streams[i];
171 dc_commit_updates_for_stream(link->ctx->dc, NULL, 0,
172 streams[i], &stream_update,
173 state);
174 }
175
176 /* link can be also enabled by vbios. In this case it is not recorded
177 * in pipe_ctx. Disable link phy here to make sure it is completely off
178 */
179 dp_disable_link_phy(link, &link_res, link->connector_signal);
180 }
181
link_resume(struct dc_link * link)182 void link_resume(struct dc_link *link)
183 {
184 if (link->connector_signal != SIGNAL_TYPE_VIRTUAL)
185 program_hpd_filter(link);
186 }
187
188 /* This function returns true if the pipe is used to feed video signal directly
189 * to the link.
190 */
is_master_pipe_for_link(const struct dc_link * link,const struct pipe_ctx * pipe)191 static bool is_master_pipe_for_link(const struct dc_link *link,
192 const struct pipe_ctx *pipe)
193 {
194 return resource_is_pipe_type(pipe, OTG_MASTER) &&
195 pipe->stream->link == link;
196 }
197
198 /*
199 * This function finds all master pipes feeding to a given link with dpms set to
200 * on in given dc state.
201 */
link_get_master_pipes_with_dpms_on(const struct dc_link * link,struct dc_state * state,uint8_t * count,struct pipe_ctx * pipes[MAX_PIPES])202 void link_get_master_pipes_with_dpms_on(const struct dc_link *link,
203 struct dc_state *state,
204 uint8_t *count,
205 struct pipe_ctx *pipes[MAX_PIPES])
206 {
207 int i;
208 struct pipe_ctx *pipe = NULL;
209
210 *count = 0;
211 for (i = 0; i < MAX_PIPES; i++) {
212 pipe = &state->res_ctx.pipe_ctx[i];
213
214 if (is_master_pipe_for_link(link, pipe) &&
215 pipe->stream->dpms_off == false) {
216 pipes[(*count)++] = pipe;
217 }
218 }
219 }
220
get_ext_hdmi_settings(struct pipe_ctx * pipe_ctx,enum engine_id eng_id,struct ext_hdmi_settings * settings)221 static bool get_ext_hdmi_settings(struct pipe_ctx *pipe_ctx,
222 enum engine_id eng_id,
223 struct ext_hdmi_settings *settings)
224 {
225 bool result = false;
226 int i = 0;
227 struct integrated_info *integrated_info =
228 pipe_ctx->stream->ctx->dc_bios->integrated_info;
229
230 if (integrated_info == NULL)
231 return false;
232
233 /*
234 * Get retimer settings from sbios for passing SI eye test for DCE11
235 * The setting values are varied based on board revision and port id
236 * Therefore the setting values of each ports is passed by sbios.
237 */
238
239 // Check if current bios contains ext Hdmi settings
240 if (integrated_info->gpu_cap_info & 0x20) {
241 switch (eng_id) {
242 case ENGINE_ID_DIGA:
243 settings->slv_addr = integrated_info->dp0_ext_hdmi_slv_addr;
244 settings->reg_num = integrated_info->dp0_ext_hdmi_6g_reg_num;
245 settings->reg_num_6g = integrated_info->dp0_ext_hdmi_6g_reg_num;
246 memmove(settings->reg_settings,
247 integrated_info->dp0_ext_hdmi_reg_settings,
248 sizeof(integrated_info->dp0_ext_hdmi_reg_settings));
249 memmove(settings->reg_settings_6g,
250 integrated_info->dp0_ext_hdmi_6g_reg_settings,
251 sizeof(integrated_info->dp0_ext_hdmi_6g_reg_settings));
252 result = true;
253 break;
254 case ENGINE_ID_DIGB:
255 settings->slv_addr = integrated_info->dp1_ext_hdmi_slv_addr;
256 settings->reg_num = integrated_info->dp1_ext_hdmi_6g_reg_num;
257 settings->reg_num_6g = integrated_info->dp1_ext_hdmi_6g_reg_num;
258 memmove(settings->reg_settings,
259 integrated_info->dp1_ext_hdmi_reg_settings,
260 sizeof(integrated_info->dp1_ext_hdmi_reg_settings));
261 memmove(settings->reg_settings_6g,
262 integrated_info->dp1_ext_hdmi_6g_reg_settings,
263 sizeof(integrated_info->dp1_ext_hdmi_6g_reg_settings));
264 result = true;
265 break;
266 case ENGINE_ID_DIGC:
267 settings->slv_addr = integrated_info->dp2_ext_hdmi_slv_addr;
268 settings->reg_num = integrated_info->dp2_ext_hdmi_6g_reg_num;
269 settings->reg_num_6g = integrated_info->dp2_ext_hdmi_6g_reg_num;
270 memmove(settings->reg_settings,
271 integrated_info->dp2_ext_hdmi_reg_settings,
272 sizeof(integrated_info->dp2_ext_hdmi_reg_settings));
273 memmove(settings->reg_settings_6g,
274 integrated_info->dp2_ext_hdmi_6g_reg_settings,
275 sizeof(integrated_info->dp2_ext_hdmi_6g_reg_settings));
276 result = true;
277 break;
278 case ENGINE_ID_DIGD:
279 settings->slv_addr = integrated_info->dp3_ext_hdmi_slv_addr;
280 settings->reg_num = integrated_info->dp3_ext_hdmi_6g_reg_num;
281 settings->reg_num_6g = integrated_info->dp3_ext_hdmi_6g_reg_num;
282 memmove(settings->reg_settings,
283 integrated_info->dp3_ext_hdmi_reg_settings,
284 sizeof(integrated_info->dp3_ext_hdmi_reg_settings));
285 memmove(settings->reg_settings_6g,
286 integrated_info->dp3_ext_hdmi_6g_reg_settings,
287 sizeof(integrated_info->dp3_ext_hdmi_6g_reg_settings));
288 result = true;
289 break;
290 default:
291 break;
292 }
293
294 if (result == true) {
295 // Validate settings from bios integrated info table
296 if (settings->slv_addr == 0)
297 return false;
298 if (settings->reg_num > 9)
299 return false;
300 if (settings->reg_num_6g > 3)
301 return false;
302
303 for (i = 0; i < settings->reg_num; i++) {
304 if (settings->reg_settings[i].i2c_reg_index > 0x20)
305 return false;
306 }
307
308 for (i = 0; i < settings->reg_num_6g; i++) {
309 if (settings->reg_settings_6g[i].i2c_reg_index > 0x20)
310 return false;
311 }
312 }
313 }
314
315 return result;
316 }
317
write_i2c(struct pipe_ctx * pipe_ctx,uint8_t address,uint8_t * buffer,uint32_t length)318 static bool write_i2c(struct pipe_ctx *pipe_ctx,
319 uint8_t address, uint8_t *buffer, uint32_t length)
320 {
321 struct i2c_command cmd = {0};
322 struct i2c_payload payload = {0};
323
324 memset(&payload, 0, sizeof(payload));
325 memset(&cmd, 0, sizeof(cmd));
326
327 cmd.number_of_payloads = 1;
328 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
329 cmd.speed = pipe_ctx->stream->ctx->dc->caps.i2c_speed_in_khz;
330
331 payload.address = address;
332 payload.data = buffer;
333 payload.length = length;
334 payload.write = true;
335 cmd.payloads = &payload;
336
337 if (dm_helpers_submit_i2c(pipe_ctx->stream->ctx,
338 pipe_ctx->stream->link, &cmd))
339 return true;
340
341 return false;
342 }
343
write_i2c_retimer_setting(struct pipe_ctx * pipe_ctx,bool is_vga_mode,bool is_over_340mhz,struct ext_hdmi_settings * settings)344 static void write_i2c_retimer_setting(
345 struct pipe_ctx *pipe_ctx,
346 bool is_vga_mode,
347 bool is_over_340mhz,
348 struct ext_hdmi_settings *settings)
349 {
350 uint8_t slave_address = (settings->slv_addr >> 1);
351 uint8_t buffer[2];
352 const uint8_t apply_rx_tx_change = 0x4;
353 uint8_t offset = 0xA;
354 uint8_t value = 0;
355 int i = 0;
356 bool i2c_success = false;
357 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
358
359 memset(&buffer, 0, sizeof(buffer));
360
361 /* Start Ext-Hdmi programming*/
362
363 for (i = 0; i < settings->reg_num; i++) {
364 /* Apply 3G settings */
365 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
366
367 buffer[0] = settings->reg_settings[i].i2c_reg_index;
368 buffer[1] = settings->reg_settings[i].i2c_reg_val;
369 i2c_success = write_i2c(pipe_ctx, slave_address,
370 buffer, sizeof(buffer));
371 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
372 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
373 slave_address, buffer[0], buffer[1], i2c_success?1:0);
374
375 if (!i2c_success)
376 goto i2c_write_fail;
377
378 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
379 * needs to be set to 1 on every 0xA-0xC write.
380 */
381 if (settings->reg_settings[i].i2c_reg_index == 0xA ||
382 settings->reg_settings[i].i2c_reg_index == 0xB ||
383 settings->reg_settings[i].i2c_reg_index == 0xC) {
384
385 /* Query current value from offset 0xA */
386 if (settings->reg_settings[i].i2c_reg_index == 0xA)
387 value = settings->reg_settings[i].i2c_reg_val;
388 else {
389 i2c_success =
390 link_query_ddc_data(
391 pipe_ctx->stream->link->ddc,
392 slave_address, &offset, 1, &value, 1);
393 if (!i2c_success)
394 goto i2c_write_fail;
395 }
396
397 buffer[0] = offset;
398 /* Set APPLY_RX_TX_CHANGE bit to 1 */
399 buffer[1] = value | apply_rx_tx_change;
400 i2c_success = write_i2c(pipe_ctx, slave_address,
401 buffer, sizeof(buffer));
402 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
403 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
404 slave_address, buffer[0], buffer[1], i2c_success?1:0);
405 if (!i2c_success)
406 goto i2c_write_fail;
407 }
408 }
409 }
410
411 /* Apply 3G settings */
412 if (is_over_340mhz) {
413 for (i = 0; i < settings->reg_num_6g; i++) {
414 /* Apply 3G settings */
415 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
416
417 buffer[0] = settings->reg_settings_6g[i].i2c_reg_index;
418 buffer[1] = settings->reg_settings_6g[i].i2c_reg_val;
419 i2c_success = write_i2c(pipe_ctx, slave_address,
420 buffer, sizeof(buffer));
421 RETIMER_REDRIVER_INFO("above 340Mhz: retimer write to slave_address = 0x%x,\
422 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
423 slave_address, buffer[0], buffer[1], i2c_success?1:0);
424
425 if (!i2c_success)
426 goto i2c_write_fail;
427
428 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
429 * needs to be set to 1 on every 0xA-0xC write.
430 */
431 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA ||
432 settings->reg_settings_6g[i].i2c_reg_index == 0xB ||
433 settings->reg_settings_6g[i].i2c_reg_index == 0xC) {
434
435 /* Query current value from offset 0xA */
436 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA)
437 value = settings->reg_settings_6g[i].i2c_reg_val;
438 else {
439 i2c_success =
440 link_query_ddc_data(
441 pipe_ctx->stream->link->ddc,
442 slave_address, &offset, 1, &value, 1);
443 if (!i2c_success)
444 goto i2c_write_fail;
445 }
446
447 buffer[0] = offset;
448 /* Set APPLY_RX_TX_CHANGE bit to 1 */
449 buffer[1] = value | apply_rx_tx_change;
450 i2c_success = write_i2c(pipe_ctx, slave_address,
451 buffer, sizeof(buffer));
452 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
453 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
454 slave_address, buffer[0], buffer[1], i2c_success?1:0);
455 if (!i2c_success)
456 goto i2c_write_fail;
457 }
458 }
459 }
460 }
461
462 if (is_vga_mode) {
463 /* Program additional settings if using 640x480 resolution */
464
465 /* Write offset 0xFF to 0x01 */
466 buffer[0] = 0xff;
467 buffer[1] = 0x01;
468 i2c_success = write_i2c(pipe_ctx, slave_address,
469 buffer, sizeof(buffer));
470 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
471 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
472 slave_address, buffer[0], buffer[1], i2c_success?1:0);
473 if (!i2c_success)
474 goto i2c_write_fail;
475
476 /* Write offset 0x00 to 0x23 */
477 buffer[0] = 0x00;
478 buffer[1] = 0x23;
479 i2c_success = write_i2c(pipe_ctx, slave_address,
480 buffer, sizeof(buffer));
481 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
482 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
483 slave_address, buffer[0], buffer[1], i2c_success?1:0);
484 if (!i2c_success)
485 goto i2c_write_fail;
486
487 /* Write offset 0xff to 0x00 */
488 buffer[0] = 0xff;
489 buffer[1] = 0x00;
490 i2c_success = write_i2c(pipe_ctx, slave_address,
491 buffer, sizeof(buffer));
492 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
493 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
494 slave_address, buffer[0], buffer[1], i2c_success?1:0);
495 if (!i2c_success)
496 goto i2c_write_fail;
497
498 }
499
500 return;
501
502 i2c_write_fail:
503 DC_LOG_DEBUG("Set retimer failed");
504 }
505
write_i2c_default_retimer_setting(struct pipe_ctx * pipe_ctx,bool is_vga_mode,bool is_over_340mhz)506 static void write_i2c_default_retimer_setting(
507 struct pipe_ctx *pipe_ctx,
508 bool is_vga_mode,
509 bool is_over_340mhz)
510 {
511 uint8_t slave_address = (0xBA >> 1);
512 uint8_t buffer[2];
513 bool i2c_success = false;
514 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
515
516 memset(&buffer, 0, sizeof(buffer));
517
518 /* Program Slave Address for tuning single integrity */
519 /* Write offset 0x0A to 0x13 */
520 buffer[0] = 0x0A;
521 buffer[1] = 0x13;
522 i2c_success = write_i2c(pipe_ctx, slave_address,
523 buffer, sizeof(buffer));
524 RETIMER_REDRIVER_INFO("retimer writes default setting to slave_address = 0x%x,\
525 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
526 slave_address, buffer[0], buffer[1], i2c_success?1:0);
527 if (!i2c_success)
528 goto i2c_write_fail;
529
530 /* Write offset 0x0A to 0x17 */
531 buffer[0] = 0x0A;
532 buffer[1] = 0x17;
533 i2c_success = write_i2c(pipe_ctx, slave_address,
534 buffer, sizeof(buffer));
535 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
536 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
537 slave_address, buffer[0], buffer[1], i2c_success?1:0);
538 if (!i2c_success)
539 goto i2c_write_fail;
540
541 /* Write offset 0x0B to 0xDA or 0xD8 */
542 buffer[0] = 0x0B;
543 buffer[1] = is_over_340mhz ? 0xDA : 0xD8;
544 i2c_success = write_i2c(pipe_ctx, slave_address,
545 buffer, sizeof(buffer));
546 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
547 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
548 slave_address, buffer[0], buffer[1], i2c_success?1:0);
549 if (!i2c_success)
550 goto i2c_write_fail;
551
552 /* Write offset 0x0A to 0x17 */
553 buffer[0] = 0x0A;
554 buffer[1] = 0x17;
555 i2c_success = write_i2c(pipe_ctx, slave_address,
556 buffer, sizeof(buffer));
557 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
558 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
559 slave_address, buffer[0], buffer[1], i2c_success?1:0);
560 if (!i2c_success)
561 goto i2c_write_fail;
562
563 /* Write offset 0x0C to 0x1D or 0x91 */
564 buffer[0] = 0x0C;
565 buffer[1] = is_over_340mhz ? 0x1D : 0x91;
566 i2c_success = write_i2c(pipe_ctx, slave_address,
567 buffer, sizeof(buffer));
568 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
569 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
570 slave_address, buffer[0], buffer[1], i2c_success?1:0);
571 if (!i2c_success)
572 goto i2c_write_fail;
573
574 /* Write offset 0x0A to 0x17 */
575 buffer[0] = 0x0A;
576 buffer[1] = 0x17;
577 i2c_success = write_i2c(pipe_ctx, slave_address,
578 buffer, sizeof(buffer));
579 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
580 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
581 slave_address, buffer[0], buffer[1], i2c_success?1:0);
582 if (!i2c_success)
583 goto i2c_write_fail;
584
585
586 if (is_vga_mode) {
587 /* Program additional settings if using 640x480 resolution */
588
589 /* Write offset 0xFF to 0x01 */
590 buffer[0] = 0xff;
591 buffer[1] = 0x01;
592 i2c_success = write_i2c(pipe_ctx, slave_address,
593 buffer, sizeof(buffer));
594 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
595 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
596 slave_address, buffer[0], buffer[1], i2c_success?1:0);
597 if (!i2c_success)
598 goto i2c_write_fail;
599
600 /* Write offset 0x00 to 0x23 */
601 buffer[0] = 0x00;
602 buffer[1] = 0x23;
603 i2c_success = write_i2c(pipe_ctx, slave_address,
604 buffer, sizeof(buffer));
605 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
606 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
607 slave_address, buffer[0], buffer[1], i2c_success?1:0);
608 if (!i2c_success)
609 goto i2c_write_fail;
610
611 /* Write offset 0xff to 0x00 */
612 buffer[0] = 0xff;
613 buffer[1] = 0x00;
614 i2c_success = write_i2c(pipe_ctx, slave_address,
615 buffer, sizeof(buffer));
616 RETIMER_REDRIVER_INFO("retimer write default setting to slave_addr = 0x%x,\
617 offset = 0x%x, reg_val= 0x%x, i2c_success = %d end here\n",
618 slave_address, buffer[0], buffer[1], i2c_success?1:0);
619 if (!i2c_success)
620 goto i2c_write_fail;
621 }
622
623 return;
624
625 i2c_write_fail:
626 DC_LOG_DEBUG("Set default retimer failed");
627 }
628
write_i2c_redriver_setting(struct pipe_ctx * pipe_ctx,bool is_over_340mhz)629 static void write_i2c_redriver_setting(
630 struct pipe_ctx *pipe_ctx,
631 bool is_over_340mhz)
632 {
633 uint8_t slave_address = (0xF0 >> 1);
634 uint8_t buffer[16];
635 bool i2c_success = false;
636 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
637
638 memset(&buffer, 0, sizeof(buffer));
639
640 // Program Slave Address for tuning single integrity
641 buffer[3] = 0x4E;
642 buffer[4] = 0x4E;
643 buffer[5] = 0x4E;
644 buffer[6] = is_over_340mhz ? 0x4E : 0x4A;
645
646 i2c_success = write_i2c(pipe_ctx, slave_address,
647 buffer, sizeof(buffer));
648 RETIMER_REDRIVER_INFO("redriver write 0 to all 16 reg offset expect following:\n\
649 \t slave_addr = 0x%x, offset[3] = 0x%x, offset[4] = 0x%x,\
650 offset[5] = 0x%x,offset[6] is_over_340mhz = 0x%x,\
651 i2c_success = %d\n",
652 slave_address, buffer[3], buffer[4], buffer[5], buffer[6], i2c_success?1:0);
653
654 if (!i2c_success)
655 DC_LOG_DEBUG("Set redriver failed");
656 }
657
update_psp_stream_config(struct pipe_ctx * pipe_ctx,bool dpms_off)658 static void update_psp_stream_config(struct pipe_ctx *pipe_ctx, bool dpms_off)
659 {
660 struct cp_psp *cp_psp = &pipe_ctx->stream->ctx->cp_psp;
661 struct link_encoder *link_enc = NULL;
662 struct cp_psp_stream_config config = {0};
663 enum dp_panel_mode panel_mode =
664 dp_get_panel_mode(pipe_ctx->stream->link);
665
666 if (cp_psp == NULL || cp_psp->funcs.update_stream_config == NULL)
667 return;
668
669 link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
670 ASSERT(link_enc);
671 if (link_enc == NULL)
672 return;
673
674 /* otg instance */
675 config.otg_inst = (uint8_t) pipe_ctx->stream_res.tg->inst;
676
677 /* dig front end */
678 config.dig_fe = (uint8_t) pipe_ctx->stream_res.stream_enc->stream_enc_inst;
679
680 /* stream encoder index */
681 config.stream_enc_idx = pipe_ctx->stream_res.stream_enc->id - ENGINE_ID_DIGA;
682 if (dp_is_128b_132b_signal(pipe_ctx))
683 config.stream_enc_idx =
684 pipe_ctx->stream_res.hpo_dp_stream_enc->id - ENGINE_ID_HPO_DP_0;
685
686 /* dig back end */
687 config.dig_be = pipe_ctx->stream->link->link_enc_hw_inst;
688
689 /* link encoder index */
690 config.link_enc_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
691 if (dp_is_128b_132b_signal(pipe_ctx))
692 config.link_enc_idx = pipe_ctx->link_res.hpo_dp_link_enc->inst;
693
694 /* dio output index is dpia index for DPIA endpoint & dcio index by default */
695 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
696 config.dio_output_idx = pipe_ctx->stream->link->link_id.enum_id - ENUM_ID_1;
697 else
698 config.dio_output_idx = link_enc->transmitter - TRANSMITTER_UNIPHY_A;
699
700
701 /* phy index */
702 config.phy_idx = resource_transmitter_to_phy_idx(
703 pipe_ctx->stream->link->dc, link_enc->transmitter);
704 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
705 /* USB4 DPIA doesn't use PHY in our soc, initialize it to 0 */
706 config.phy_idx = 0;
707
708 /* stream properties */
709 config.assr_enabled = (panel_mode == DP_PANEL_MODE_EDP) ? 1 : 0;
710 config.mst_enabled = (pipe_ctx->stream->signal ==
711 SIGNAL_TYPE_DISPLAY_PORT_MST) ? 1 : 0;
712 config.dp2_enabled = dp_is_128b_132b_signal(pipe_ctx) ? 1 : 0;
713 config.usb4_enabled = (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) ?
714 1 : 0;
715 config.dpms_off = dpms_off;
716
717 /* dm stream context */
718 config.dm_stream_ctx = pipe_ctx->stream->dm_stream_context;
719
720 cp_psp->funcs.update_stream_config(cp_psp->handle, &config);
721 }
722
set_avmute(struct pipe_ctx * pipe_ctx,bool enable)723 static void set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
724 {
725 struct dc *dc = pipe_ctx->stream->ctx->dc;
726
727 if (!dc_is_hdmi_signal(pipe_ctx->stream->signal))
728 return;
729
730 dc->hwss.set_avmute(pipe_ctx, enable);
731 }
732
enable_mst_on_sink(struct dc_link * link,bool enable)733 static void enable_mst_on_sink(struct dc_link *link, bool enable)
734 {
735 unsigned char mstmCntl;
736
737 core_link_read_dpcd(link, DP_MSTM_CTRL, &mstmCntl, 1);
738 if (enable)
739 mstmCntl |= DP_MST_EN;
740 else
741 mstmCntl &= (~DP_MST_EN);
742
743 core_link_write_dpcd(link, DP_MSTM_CTRL, &mstmCntl, 1);
744 }
745
dsc_optc_config_log(struct display_stream_compressor * dsc,struct dsc_optc_config * config)746 static void dsc_optc_config_log(struct display_stream_compressor *dsc,
747 struct dsc_optc_config *config)
748 {
749 uint32_t precision = 1 << 28;
750 uint32_t bytes_per_pixel_int = config->bytes_per_pixel / precision;
751 uint32_t bytes_per_pixel_mod = config->bytes_per_pixel % precision;
752 uint64_t ll_bytes_per_pix_fraq = bytes_per_pixel_mod;
753 DC_LOGGER_INIT(dsc->ctx->logger);
754
755 /* 7 fractional digits decimal precision for bytes per pixel is enough because DSC
756 * bits per pixel precision is 1/16th of a pixel, which means bytes per pixel precision is
757 * 1/16/8 = 1/128 of a byte, or 0.0078125 decimal
758 */
759 ll_bytes_per_pix_fraq *= 10000000;
760 ll_bytes_per_pix_fraq /= precision;
761
762 DC_LOG_DSC("\tbytes_per_pixel 0x%08x (%d.%07d)",
763 config->bytes_per_pixel, bytes_per_pixel_int, (uint32_t)ll_bytes_per_pix_fraq);
764 DC_LOG_DSC("\tis_pixel_format_444 %d", config->is_pixel_format_444);
765 DC_LOG_DSC("\tslice_width %d", config->slice_width);
766 }
767
dp_set_dsc_on_rx(struct pipe_ctx * pipe_ctx,bool enable)768 static bool dp_set_dsc_on_rx(struct pipe_ctx *pipe_ctx, bool enable)
769 {
770 struct dc *dc = pipe_ctx->stream->ctx->dc;
771 struct dc_stream_state *stream = pipe_ctx->stream;
772 bool result = false;
773
774 if (dc_is_virtual_signal(stream->signal))
775 result = true;
776 else
777 result = dm_helpers_dp_write_dsc_enable(dc->ctx, stream, enable);
778 return result;
779 }
780
781 /* The stream with these settings can be sent (unblanked) only after DSC was enabled on RX first,
782 * i.e. after dp_enable_dsc_on_rx() had been called
783 */
link_set_dsc_on_stream(struct pipe_ctx * pipe_ctx,bool enable)784 void link_set_dsc_on_stream(struct pipe_ctx *pipe_ctx, bool enable)
785 {
786 struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc;
787 struct dc_stream_state *stream = pipe_ctx->stream;
788 struct pipe_ctx *odm_pipe;
789 int opp_cnt = 1;
790 DC_LOGGER_INIT(dsc->ctx->logger);
791
792 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
793 opp_cnt++;
794
795 if (enable) {
796 struct dsc_config dsc_cfg;
797 struct dsc_optc_config dsc_optc_cfg;
798 enum optc_dsc_mode optc_dsc_mode;
799
800 /* Enable DSC hw block */
801 dsc_cfg.pic_width = (stream->timing.h_addressable + stream->timing.h_border_left + stream->timing.h_border_right) / opp_cnt;
802 dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top + stream->timing.v_border_bottom;
803 dsc_cfg.pixel_encoding = stream->timing.pixel_encoding;
804 dsc_cfg.color_depth = stream->timing.display_color_depth;
805 dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false;
806 dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg;
807 ASSERT(dsc_cfg.dc_dsc_cfg.num_slices_h % opp_cnt == 0);
808 dsc_cfg.dc_dsc_cfg.num_slices_h /= opp_cnt;
809
810 dsc->funcs->dsc_set_config(dsc, &dsc_cfg, &dsc_optc_cfg);
811 dsc->funcs->dsc_enable(dsc, pipe_ctx->stream_res.opp->inst);
812 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe) {
813 struct display_stream_compressor *odm_dsc = odm_pipe->stream_res.dsc;
814
815 odm_dsc->funcs->dsc_set_config(odm_dsc, &dsc_cfg, &dsc_optc_cfg);
816 odm_dsc->funcs->dsc_enable(odm_dsc, odm_pipe->stream_res.opp->inst);
817 }
818 dsc_cfg.dc_dsc_cfg.num_slices_h *= opp_cnt;
819 dsc_cfg.pic_width *= opp_cnt;
820
821 optc_dsc_mode = dsc_optc_cfg.is_pixel_format_444 ? OPTC_DSC_ENABLED_444 : OPTC_DSC_ENABLED_NATIVE_SUBSAMPLED;
822
823 /* Enable DSC in encoder */
824 if (dc_is_dp_signal(stream->signal) && !dp_is_128b_132b_signal(pipe_ctx)) {
825 DC_LOG_DSC("Setting stream encoder DSC config for engine %d:", (int)pipe_ctx->stream_res.stream_enc->id);
826 dsc_optc_config_log(dsc, &dsc_optc_cfg);
827 pipe_ctx->stream_res.stream_enc->funcs->dp_set_dsc_config(pipe_ctx->stream_res.stream_enc,
828 optc_dsc_mode,
829 dsc_optc_cfg.bytes_per_pixel,
830 dsc_optc_cfg.slice_width);
831
832 /* PPS SDP is set elsewhere because it has to be done after DIG FE is connected to DIG BE */
833 }
834
835 /* Enable DSC in OPTC */
836 DC_LOG_DSC("Setting optc DSC config for tg instance %d:", pipe_ctx->stream_res.tg->inst);
837 dsc_optc_config_log(dsc, &dsc_optc_cfg);
838 pipe_ctx->stream_res.tg->funcs->set_dsc_config(pipe_ctx->stream_res.tg,
839 optc_dsc_mode,
840 dsc_optc_cfg.bytes_per_pixel,
841 dsc_optc_cfg.slice_width);
842 } else {
843 /* disable DSC in OPTC */
844 pipe_ctx->stream_res.tg->funcs->set_dsc_config(
845 pipe_ctx->stream_res.tg,
846 OPTC_DSC_DISABLED, 0, 0);
847
848 /* disable DSC in stream encoder */
849 if (dc_is_dp_signal(stream->signal)) {
850 if (dp_is_128b_132b_signal(pipe_ctx))
851 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_set_dsc_pps_info_packet(
852 pipe_ctx->stream_res.hpo_dp_stream_enc,
853 false,
854 NULL,
855 true);
856 else {
857 pipe_ctx->stream_res.stream_enc->funcs->dp_set_dsc_config(
858 pipe_ctx->stream_res.stream_enc,
859 OPTC_DSC_DISABLED, 0, 0);
860 pipe_ctx->stream_res.stream_enc->funcs->dp_set_dsc_pps_info_packet(
861 pipe_ctx->stream_res.stream_enc, false, NULL, true);
862 }
863 }
864
865 /* disable DSC block */
866 pipe_ctx->stream_res.dsc->funcs->dsc_disable(pipe_ctx->stream_res.dsc);
867 for (odm_pipe = pipe_ctx->next_odm_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
868 odm_pipe->stream_res.dsc->funcs->dsc_disable(odm_pipe->stream_res.dsc);
869 }
870 }
871
872 /*
873 * For dynamic bpp change case, dsc is programmed with MASTER_UPDATE_LOCK enabled;
874 * hence PPS info packet update need to use frame update instead of immediate update.
875 * Added parameter immediate_update for this purpose.
876 * The decision to use frame update is hard-coded in function dp_update_dsc_config(),
877 * which is the only place where a "false" would be passed in for param immediate_update.
878 *
879 * immediate_update is only applicable when DSC is enabled.
880 */
link_set_dsc_pps_packet(struct pipe_ctx * pipe_ctx,bool enable,bool immediate_update)881 bool link_set_dsc_pps_packet(struct pipe_ctx *pipe_ctx, bool enable, bool immediate_update)
882 {
883 struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc;
884 struct dc_stream_state *stream = pipe_ctx->stream;
885
886 if (!pipe_ctx->stream->timing.flags.DSC)
887 return false;
888
889 if (!dsc)
890 return false;
891
892 DC_LOGGER_INIT(dsc->ctx->logger);
893
894 if (enable) {
895 struct dsc_config dsc_cfg;
896 uint8_t dsc_packed_pps[128];
897
898 memset(&dsc_cfg, 0, sizeof(dsc_cfg));
899 memset(dsc_packed_pps, 0, 128);
900
901 /* Enable DSC hw block */
902 dsc_cfg.pic_width = stream->timing.h_addressable + stream->timing.h_border_left + stream->timing.h_border_right;
903 dsc_cfg.pic_height = stream->timing.v_addressable + stream->timing.v_border_top + stream->timing.v_border_bottom;
904 dsc_cfg.pixel_encoding = stream->timing.pixel_encoding;
905 dsc_cfg.color_depth = stream->timing.display_color_depth;
906 dsc_cfg.is_odm = pipe_ctx->next_odm_pipe ? true : false;
907 dsc_cfg.dc_dsc_cfg = stream->timing.dsc_cfg;
908
909 dsc->funcs->dsc_get_packed_pps(dsc, &dsc_cfg, &dsc_packed_pps[0]);
910 memcpy(&stream->dsc_packed_pps[0], &dsc_packed_pps[0], sizeof(stream->dsc_packed_pps));
911 if (dc_is_dp_signal(stream->signal)) {
912 DC_LOG_DSC("Setting stream encoder DSC PPS SDP for engine %d\n", (int)pipe_ctx->stream_res.stream_enc->id);
913 if (dp_is_128b_132b_signal(pipe_ctx))
914 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_set_dsc_pps_info_packet(
915 pipe_ctx->stream_res.hpo_dp_stream_enc,
916 true,
917 &dsc_packed_pps[0],
918 immediate_update);
919 else
920 pipe_ctx->stream_res.stream_enc->funcs->dp_set_dsc_pps_info_packet(
921 pipe_ctx->stream_res.stream_enc,
922 true,
923 &dsc_packed_pps[0],
924 immediate_update);
925 }
926 } else {
927 /* disable DSC PPS in stream encoder */
928 memset(&stream->dsc_packed_pps[0], 0, sizeof(stream->dsc_packed_pps));
929 if (dc_is_dp_signal(stream->signal)) {
930 if (dp_is_128b_132b_signal(pipe_ctx))
931 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_set_dsc_pps_info_packet(
932 pipe_ctx->stream_res.hpo_dp_stream_enc,
933 false,
934 NULL,
935 true);
936 else
937 pipe_ctx->stream_res.stream_enc->funcs->dp_set_dsc_pps_info_packet(
938 pipe_ctx->stream_res.stream_enc, false, NULL, true);
939 }
940 }
941
942 return true;
943 }
944
link_set_dsc_enable(struct pipe_ctx * pipe_ctx,bool enable)945 bool link_set_dsc_enable(struct pipe_ctx *pipe_ctx, bool enable)
946 {
947 struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc;
948 bool result = false;
949
950 if (!pipe_ctx->stream->timing.flags.DSC)
951 goto out;
952 if (!dsc)
953 goto out;
954
955 if (enable) {
956 {
957 link_set_dsc_on_stream(pipe_ctx, true);
958 result = true;
959 }
960 } else {
961 dp_set_dsc_on_rx(pipe_ctx, false);
962 link_set_dsc_on_stream(pipe_ctx, false);
963 result = true;
964 }
965 out:
966 return result;
967 }
968
link_update_dsc_config(struct pipe_ctx * pipe_ctx)969 bool link_update_dsc_config(struct pipe_ctx *pipe_ctx)
970 {
971 struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc;
972
973 if (!pipe_ctx->stream->timing.flags.DSC)
974 return false;
975 if (!dsc)
976 return false;
977
978 link_set_dsc_on_stream(pipe_ctx, true);
979 link_set_dsc_pps_packet(pipe_ctx, true, false);
980 return true;
981 }
982
enable_stream_features(struct pipe_ctx * pipe_ctx)983 static void enable_stream_features(struct pipe_ctx *pipe_ctx)
984 {
985 struct dc_stream_state *stream = pipe_ctx->stream;
986
987 if (pipe_ctx->stream->signal != SIGNAL_TYPE_DISPLAY_PORT_MST) {
988 struct dc_link *link = stream->link;
989 union down_spread_ctrl old_downspread;
990 union down_spread_ctrl new_downspread;
991
992 memset(&old_downspread, 0, sizeof(old_downspread));
993
994 core_link_read_dpcd(link, DP_DOWNSPREAD_CTRL,
995 &old_downspread.raw, sizeof(old_downspread));
996
997 new_downspread.raw = old_downspread.raw;
998
999 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1000 (stream->ignore_msa_timing_param) ? 1 : 0;
1001
1002 if (new_downspread.raw != old_downspread.raw) {
1003 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
1004 &new_downspread.raw, sizeof(new_downspread));
1005 }
1006
1007 } else {
1008 dm_helpers_mst_enable_stream_features(stream);
1009 }
1010 }
1011
log_vcp_x_y(const struct dc_link * link,struct fixed31_32 avg_time_slots_per_mtp)1012 static void log_vcp_x_y(const struct dc_link *link, struct fixed31_32 avg_time_slots_per_mtp)
1013 {
1014 const uint32_t VCP_Y_PRECISION = 1000;
1015 uint64_t vcp_x, vcp_y;
1016 DC_LOGGER_INIT(link->ctx->logger);
1017
1018 // Add 0.5*(1/VCP_Y_PRECISION) to round up to decimal precision
1019 avg_time_slots_per_mtp = dc_fixpt_add(
1020 avg_time_slots_per_mtp,
1021 dc_fixpt_from_fraction(
1022 1,
1023 2*VCP_Y_PRECISION));
1024
1025 vcp_x = dc_fixpt_floor(
1026 avg_time_slots_per_mtp);
1027 vcp_y = dc_fixpt_floor(
1028 dc_fixpt_mul_int(
1029 dc_fixpt_sub_int(
1030 avg_time_slots_per_mtp,
1031 dc_fixpt_floor(
1032 avg_time_slots_per_mtp)),
1033 VCP_Y_PRECISION));
1034
1035
1036 if (link->type == dc_connection_mst_branch)
1037 DC_LOG_DP2("MST Update Payload: set_throttled_vcp_size slot X.Y for MST stream "
1038 "X: %llu "
1039 "Y: %llu/%d",
1040 vcp_x,
1041 vcp_y,
1042 VCP_Y_PRECISION);
1043 else
1044 DC_LOG_DP2("SST Update Payload: set_throttled_vcp_size slot X.Y for SST stream "
1045 "X: %llu "
1046 "Y: %llu/%d",
1047 vcp_x,
1048 vcp_y,
1049 VCP_Y_PRECISION);
1050 }
1051
get_pbn_per_slot(struct dc_stream_state * stream)1052 static struct fixed31_32 get_pbn_per_slot(struct dc_stream_state *stream)
1053 {
1054 struct fixed31_32 mbytes_per_sec;
1055 uint32_t link_rate_in_mbytes_per_sec = dp_link_bandwidth_kbps(stream->link,
1056 &stream->link->cur_link_settings);
1057 link_rate_in_mbytes_per_sec /= 8000; /* Kbits to MBytes */
1058
1059 mbytes_per_sec = dc_fixpt_from_int(link_rate_in_mbytes_per_sec);
1060
1061 return dc_fixpt_div_int(mbytes_per_sec, 54);
1062 }
1063
get_pbn_from_bw_in_kbps(uint64_t kbps)1064 static struct fixed31_32 get_pbn_from_bw_in_kbps(uint64_t kbps)
1065 {
1066 struct fixed31_32 peak_kbps;
1067 uint32_t numerator = 0;
1068 uint32_t denominator = 1;
1069
1070 /*
1071 * The 1.006 factor (margin 5300ppm + 300ppm ~ 0.6% as per spec) is not
1072 * required when determining PBN/time slot utilization on the link between
1073 * us and the branch, since that overhead is already accounted for in
1074 * the get_pbn_per_slot function.
1075 *
1076 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
1077 * common multiplier to render an integer PBN for all link rate/lane
1078 * counts combinations
1079 * calculate
1080 * peak_kbps *= (64/54)
1081 * peak_kbps /= (8 * 1000) convert to bytes
1082 */
1083
1084 numerator = 64;
1085 denominator = 54 * 8 * 1000;
1086 kbps *= numerator;
1087 peak_kbps = dc_fixpt_from_fraction(kbps, denominator);
1088
1089 return peak_kbps;
1090 }
1091
get_pbn_from_timing(struct pipe_ctx * pipe_ctx)1092 static struct fixed31_32 get_pbn_from_timing(struct pipe_ctx *pipe_ctx)
1093 {
1094 uint64_t kbps;
1095 enum dc_link_encoding_format link_encoding;
1096
1097 if (dp_is_128b_132b_signal(pipe_ctx))
1098 link_encoding = DC_LINK_ENCODING_DP_128b_132b;
1099 else
1100 link_encoding = DC_LINK_ENCODING_DP_8b_10b;
1101
1102 kbps = dc_bandwidth_in_kbps_from_timing(&pipe_ctx->stream->timing, link_encoding);
1103 return get_pbn_from_bw_in_kbps(kbps);
1104 }
1105
1106
1107 // TODO - DP2.0 Link: Fix get_lane_status to handle LTTPR offset (SST and MST)
get_lane_status(struct dc_link * link,uint32_t lane_count,union lane_status * status,union lane_align_status_updated * status_updated)1108 static void get_lane_status(
1109 struct dc_link *link,
1110 uint32_t lane_count,
1111 union lane_status *status,
1112 union lane_align_status_updated *status_updated)
1113 {
1114 unsigned int lane;
1115 uint8_t dpcd_buf[3] = {0};
1116
1117 if (status == NULL || status_updated == NULL) {
1118 return;
1119 }
1120
1121 core_link_read_dpcd(
1122 link,
1123 DP_LANE0_1_STATUS,
1124 dpcd_buf,
1125 sizeof(dpcd_buf));
1126
1127 for (lane = 0; lane < lane_count; lane++) {
1128 status[lane].raw = dp_get_nibble_at_index(&dpcd_buf[0], lane);
1129 }
1130
1131 status_updated->raw = dpcd_buf[2];
1132 }
1133
poll_for_allocation_change_trigger(struct dc_link * link)1134 static bool poll_for_allocation_change_trigger(struct dc_link *link)
1135 {
1136 /*
1137 * wait for ACT handled
1138 */
1139 int i;
1140 const int act_retries = 30;
1141 enum act_return_status result = ACT_FAILED;
1142 union payload_table_update_status update_status = {0};
1143 union lane_status dpcd_lane_status[LANE_COUNT_DP_MAX];
1144 union lane_align_status_updated lane_status_updated;
1145 DC_LOGGER_INIT(link->ctx->logger);
1146
1147 if (link->aux_access_disabled)
1148 return true;
1149 for (i = 0; i < act_retries; i++) {
1150 get_lane_status(link, link->cur_link_settings.lane_count, dpcd_lane_status, &lane_status_updated);
1151
1152 if (!dp_is_cr_done(link->cur_link_settings.lane_count, dpcd_lane_status) ||
1153 !dp_is_ch_eq_done(link->cur_link_settings.lane_count, dpcd_lane_status) ||
1154 !dp_is_symbol_locked(link->cur_link_settings.lane_count, dpcd_lane_status) ||
1155 !dp_is_interlane_aligned(lane_status_updated)) {
1156 DC_LOG_ERROR("SST Update Payload: Link loss occurred while "
1157 "polling for ACT handled.");
1158 result = ACT_LINK_LOST;
1159 break;
1160 }
1161 core_link_read_dpcd(
1162 link,
1163 DP_PAYLOAD_TABLE_UPDATE_STATUS,
1164 &update_status.raw,
1165 1);
1166
1167 if (update_status.bits.ACT_HANDLED == 1) {
1168 DC_LOG_DP2("SST Update Payload: ACT handled by downstream.");
1169 result = ACT_SUCCESS;
1170 break;
1171 }
1172
1173 fsleep(5000);
1174 }
1175
1176 if (result == ACT_FAILED) {
1177 DC_LOG_ERROR("SST Update Payload: ACT still not handled after retries, "
1178 "continue on. Something is wrong with the branch.");
1179 }
1180
1181 return (result == ACT_SUCCESS);
1182 }
1183
update_mst_stream_alloc_table(struct dc_link * link,struct stream_encoder * stream_enc,struct hpo_dp_stream_encoder * hpo_dp_stream_enc,const struct dc_dp_mst_stream_allocation_table * proposed_table)1184 static void update_mst_stream_alloc_table(
1185 struct dc_link *link,
1186 struct stream_encoder *stream_enc,
1187 struct hpo_dp_stream_encoder *hpo_dp_stream_enc, // TODO: Rename stream_enc to dio_stream_enc?
1188 const struct dc_dp_mst_stream_allocation_table *proposed_table)
1189 {
1190 struct link_mst_stream_allocation work_table[MAX_CONTROLLER_NUM] = { 0 };
1191 struct link_mst_stream_allocation *dc_alloc;
1192
1193 int i;
1194 int j;
1195
1196 /* if DRM proposed_table has more than one new payload */
1197 ASSERT(proposed_table->stream_count -
1198 link->mst_stream_alloc_table.stream_count < 2);
1199
1200 /* copy proposed_table to link, add stream encoder */
1201 for (i = 0; i < proposed_table->stream_count; i++) {
1202
1203 for (j = 0; j < link->mst_stream_alloc_table.stream_count; j++) {
1204 dc_alloc =
1205 &link->mst_stream_alloc_table.stream_allocations[j];
1206
1207 if (dc_alloc->vcp_id ==
1208 proposed_table->stream_allocations[i].vcp_id) {
1209
1210 work_table[i] = *dc_alloc;
1211 work_table[i].slot_count = proposed_table->stream_allocations[i].slot_count;
1212 break; /* exit j loop */
1213 }
1214 }
1215
1216 /* new vcp_id */
1217 if (j == link->mst_stream_alloc_table.stream_count) {
1218 work_table[i].vcp_id =
1219 proposed_table->stream_allocations[i].vcp_id;
1220 work_table[i].slot_count =
1221 proposed_table->stream_allocations[i].slot_count;
1222 work_table[i].stream_enc = stream_enc;
1223 work_table[i].hpo_dp_stream_enc = hpo_dp_stream_enc;
1224 }
1225 }
1226
1227 /* update link->mst_stream_alloc_table with work_table */
1228 link->mst_stream_alloc_table.stream_count =
1229 proposed_table->stream_count;
1230 for (i = 0; i < MAX_CONTROLLER_NUM; i++)
1231 link->mst_stream_alloc_table.stream_allocations[i] =
1232 work_table[i];
1233 }
1234
remove_stream_from_alloc_table(struct dc_link * link,struct stream_encoder * dio_stream_enc,struct hpo_dp_stream_encoder * hpo_dp_stream_enc)1235 static void remove_stream_from_alloc_table(
1236 struct dc_link *link,
1237 struct stream_encoder *dio_stream_enc,
1238 struct hpo_dp_stream_encoder *hpo_dp_stream_enc)
1239 {
1240 int i = 0;
1241 struct link_mst_stream_allocation_table *table =
1242 &link->mst_stream_alloc_table;
1243
1244 if (hpo_dp_stream_enc) {
1245 for (; i < table->stream_count; i++)
1246 if (hpo_dp_stream_enc == table->stream_allocations[i].hpo_dp_stream_enc)
1247 break;
1248 } else {
1249 for (; i < table->stream_count; i++)
1250 if (dio_stream_enc == table->stream_allocations[i].stream_enc)
1251 break;
1252 }
1253
1254 if (i < table->stream_count) {
1255 i++;
1256 for (; i < table->stream_count; i++)
1257 table->stream_allocations[i-1] = table->stream_allocations[i];
1258 memset(&table->stream_allocations[table->stream_count-1], 0,
1259 sizeof(struct link_mst_stream_allocation));
1260 table->stream_count--;
1261 }
1262 }
1263
deallocate_mst_payload_with_temp_drm_wa(struct pipe_ctx * pipe_ctx)1264 static enum dc_status deallocate_mst_payload_with_temp_drm_wa(
1265 struct pipe_ctx *pipe_ctx)
1266 {
1267 struct dc_stream_state *stream = pipe_ctx->stream;
1268 struct dc_link *link = stream->link;
1269 struct dc_dp_mst_stream_allocation_table proposed_table = {0};
1270 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
1271 int i;
1272 bool mst_mode = (link->type == dc_connection_mst_branch);
1273 /* adjust for drm changes*/
1274 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1275 const struct dc_link_settings empty_link_settings = {0};
1276 DC_LOGGER_INIT(link->ctx->logger);
1277
1278 if (link_hwss->ext.set_throttled_vcp_size)
1279 link_hwss->ext.set_throttled_vcp_size(pipe_ctx, avg_time_slots_per_mtp);
1280 if (link_hwss->ext.set_hblank_min_symbol_width)
1281 link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
1282 &empty_link_settings,
1283 avg_time_slots_per_mtp);
1284
1285 if (dm_helpers_dp_mst_write_payload_allocation_table(
1286 stream->ctx,
1287 stream,
1288 &proposed_table,
1289 false))
1290 update_mst_stream_alloc_table(
1291 link,
1292 pipe_ctx->stream_res.stream_enc,
1293 pipe_ctx->stream_res.hpo_dp_stream_enc,
1294 &proposed_table);
1295 else
1296 DC_LOG_WARNING("Failed to update"
1297 "MST allocation table for"
1298 "pipe idx:%d\n",
1299 pipe_ctx->pipe_idx);
1300
1301 DC_LOG_MST("%s"
1302 "stream_count: %d: ",
1303 __func__,
1304 link->mst_stream_alloc_table.stream_count);
1305
1306 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
1307 DC_LOG_MST("stream_enc[%d]: %p "
1308 "stream[%d].hpo_dp_stream_enc: %p "
1309 "stream[%d].vcp_id: %d "
1310 "stream[%d].slot_count: %d\n",
1311 i,
1312 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
1313 i,
1314 (void *) link->mst_stream_alloc_table.stream_allocations[i].hpo_dp_stream_enc,
1315 i,
1316 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
1317 i,
1318 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
1319 }
1320
1321 if (link_hwss->ext.update_stream_allocation_table == NULL ||
1322 link_dp_get_encoding_format(&link->cur_link_settings) == DP_UNKNOWN_ENCODING) {
1323 DC_LOG_DEBUG("Unknown encoding format\n");
1324 return DC_ERROR_UNEXPECTED;
1325 }
1326
1327 link_hwss->ext.update_stream_allocation_table(link, &pipe_ctx->link_res,
1328 &link->mst_stream_alloc_table);
1329
1330 if (mst_mode) {
1331 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
1332 stream->ctx,
1333 stream);
1334 }
1335
1336 dm_helpers_dp_mst_send_payload_allocation(
1337 stream->ctx,
1338 stream,
1339 false);
1340
1341 return DC_OK;
1342 }
1343
deallocate_mst_payload(struct pipe_ctx * pipe_ctx)1344 static enum dc_status deallocate_mst_payload(struct pipe_ctx *pipe_ctx)
1345 {
1346 struct dc_stream_state *stream = pipe_ctx->stream;
1347 struct dc_link *link = stream->link;
1348 struct dc_dp_mst_stream_allocation_table proposed_table = {0};
1349 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
1350 int i;
1351 bool mst_mode = (link->type == dc_connection_mst_branch);
1352 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1353 const struct dc_link_settings empty_link_settings = {0};
1354 DC_LOGGER_INIT(link->ctx->logger);
1355
1356 if (link->dc->debug.temp_mst_deallocation_sequence)
1357 return deallocate_mst_payload_with_temp_drm_wa(pipe_ctx);
1358
1359 /* deallocate_mst_payload is called before disable link. When mode or
1360 * disable/enable monitor, new stream is created which is not in link
1361 * stream[] yet. For this, payload is not allocated yet, so de-alloc
1362 * should not done. For new mode set, map_resources will get engine
1363 * for new stream, so stream_enc->id should be validated until here.
1364 */
1365
1366 /* slot X.Y */
1367 if (link_hwss->ext.set_throttled_vcp_size)
1368 link_hwss->ext.set_throttled_vcp_size(pipe_ctx, avg_time_slots_per_mtp);
1369 if (link_hwss->ext.set_hblank_min_symbol_width)
1370 link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
1371 &empty_link_settings,
1372 avg_time_slots_per_mtp);
1373
1374 if (mst_mode) {
1375 /* when link is in mst mode, reply on mst manager to remove
1376 * payload
1377 */
1378 if (dm_helpers_dp_mst_write_payload_allocation_table(
1379 stream->ctx,
1380 stream,
1381 &proposed_table,
1382 false))
1383 update_mst_stream_alloc_table(
1384 link,
1385 pipe_ctx->stream_res.stream_enc,
1386 pipe_ctx->stream_res.hpo_dp_stream_enc,
1387 &proposed_table);
1388 else
1389 DC_LOG_WARNING("Failed to update"
1390 "MST allocation table for"
1391 "pipe idx:%d\n",
1392 pipe_ctx->pipe_idx);
1393 } else {
1394 /* when link is no longer in mst mode (mst hub unplugged),
1395 * remove payload with default dc logic
1396 */
1397 remove_stream_from_alloc_table(link, pipe_ctx->stream_res.stream_enc,
1398 pipe_ctx->stream_res.hpo_dp_stream_enc);
1399 }
1400
1401 DC_LOG_MST("%s"
1402 "stream_count: %d: ",
1403 __func__,
1404 link->mst_stream_alloc_table.stream_count);
1405
1406 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
1407 DC_LOG_MST("stream_enc[%d]: %p "
1408 "stream[%d].hpo_dp_stream_enc: %p "
1409 "stream[%d].vcp_id: %d "
1410 "stream[%d].slot_count: %d\n",
1411 i,
1412 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
1413 i,
1414 (void *) link->mst_stream_alloc_table.stream_allocations[i].hpo_dp_stream_enc,
1415 i,
1416 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
1417 i,
1418 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
1419 }
1420
1421 /* update mst stream allocation table hardware state */
1422 if (link_hwss->ext.update_stream_allocation_table == NULL ||
1423 link_dp_get_encoding_format(&link->cur_link_settings) == DP_UNKNOWN_ENCODING) {
1424 DC_LOG_DEBUG("Unknown encoding format\n");
1425 return DC_ERROR_UNEXPECTED;
1426 }
1427
1428 link_hwss->ext.update_stream_allocation_table(link, &pipe_ctx->link_res,
1429 &link->mst_stream_alloc_table);
1430
1431 if (mst_mode) {
1432 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
1433 stream->ctx,
1434 stream);
1435
1436 dm_helpers_dp_mst_send_payload_allocation(
1437 stream->ctx,
1438 stream,
1439 false);
1440 }
1441
1442 return DC_OK;
1443 }
1444
1445 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
1446 * because stream_encoder is not exposed to dm
1447 */
allocate_mst_payload(struct pipe_ctx * pipe_ctx)1448 static enum dc_status allocate_mst_payload(struct pipe_ctx *pipe_ctx)
1449 {
1450 struct dc_stream_state *stream = pipe_ctx->stream;
1451 struct dc_link *link = stream->link;
1452 struct dc_dp_mst_stream_allocation_table proposed_table = {0};
1453 struct fixed31_32 avg_time_slots_per_mtp;
1454 struct fixed31_32 pbn;
1455 struct fixed31_32 pbn_per_slot;
1456 int i;
1457 enum act_return_status ret;
1458 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1459 DC_LOGGER_INIT(link->ctx->logger);
1460
1461 /* enable_link_dp_mst already check link->enabled_stream_count
1462 * and stream is in link->stream[]. This is called during set mode,
1463 * stream_enc is available.
1464 */
1465
1466 /* get calculate VC payload for stream: stream_alloc */
1467 if (dm_helpers_dp_mst_write_payload_allocation_table(
1468 stream->ctx,
1469 stream,
1470 &proposed_table,
1471 true))
1472 update_mst_stream_alloc_table(
1473 link,
1474 pipe_ctx->stream_res.stream_enc,
1475 pipe_ctx->stream_res.hpo_dp_stream_enc,
1476 &proposed_table);
1477 else
1478 DC_LOG_WARNING("Failed to update"
1479 "MST allocation table for"
1480 "pipe idx:%d\n",
1481 pipe_ctx->pipe_idx);
1482
1483 DC_LOG_MST("%s "
1484 "stream_count: %d: \n ",
1485 __func__,
1486 link->mst_stream_alloc_table.stream_count);
1487
1488 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
1489 DC_LOG_MST("stream_enc[%d]: %p "
1490 "stream[%d].hpo_dp_stream_enc: %p "
1491 "stream[%d].vcp_id: %d "
1492 "stream[%d].slot_count: %d\n",
1493 i,
1494 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
1495 i,
1496 (void *) link->mst_stream_alloc_table.stream_allocations[i].hpo_dp_stream_enc,
1497 i,
1498 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
1499 i,
1500 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
1501 }
1502
1503 ASSERT(proposed_table.stream_count > 0);
1504
1505 /* program DP source TX for payload */
1506 if (link_hwss->ext.update_stream_allocation_table == NULL ||
1507 link_dp_get_encoding_format(&link->cur_link_settings) == DP_UNKNOWN_ENCODING) {
1508 DC_LOG_ERROR("Failure: unknown encoding format\n");
1509 return DC_ERROR_UNEXPECTED;
1510 }
1511
1512 link_hwss->ext.update_stream_allocation_table(link,
1513 &pipe_ctx->link_res,
1514 &link->mst_stream_alloc_table);
1515
1516 /* send down message */
1517 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
1518 stream->ctx,
1519 stream);
1520
1521 if (ret != ACT_LINK_LOST) {
1522 dm_helpers_dp_mst_send_payload_allocation(
1523 stream->ctx,
1524 stream,
1525 true);
1526 }
1527
1528 /* slot X.Y for only current stream */
1529 pbn_per_slot = get_pbn_per_slot(stream);
1530 if (pbn_per_slot.value == 0) {
1531 DC_LOG_ERROR("Failure: pbn_per_slot==0 not allowed. Cannot continue, returning DC_UNSUPPORTED_VALUE.\n");
1532 return DC_UNSUPPORTED_VALUE;
1533 }
1534 pbn = get_pbn_from_timing(pipe_ctx);
1535 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
1536
1537 log_vcp_x_y(link, avg_time_slots_per_mtp);
1538
1539 if (link_hwss->ext.set_throttled_vcp_size)
1540 link_hwss->ext.set_throttled_vcp_size(pipe_ctx, avg_time_slots_per_mtp);
1541 if (link_hwss->ext.set_hblank_min_symbol_width)
1542 link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
1543 &link->cur_link_settings,
1544 avg_time_slots_per_mtp);
1545
1546 return DC_OK;
1547 }
1548
link_calculate_sst_avg_time_slots_per_mtp(const struct dc_stream_state * stream,const struct dc_link * link)1549 struct fixed31_32 link_calculate_sst_avg_time_slots_per_mtp(
1550 const struct dc_stream_state *stream,
1551 const struct dc_link *link)
1552 {
1553 struct fixed31_32 link_bw_effective =
1554 dc_fixpt_from_int(
1555 dp_link_bandwidth_kbps(link, &link->cur_link_settings));
1556 struct fixed31_32 timeslot_bw_effective =
1557 dc_fixpt_div_int(link_bw_effective, MAX_MTP_SLOT_COUNT);
1558 struct fixed31_32 timing_bw =
1559 dc_fixpt_from_int(
1560 dc_bandwidth_in_kbps_from_timing(&stream->timing,
1561 dc_link_get_highest_encoding_format(link)));
1562 struct fixed31_32 avg_time_slots_per_mtp =
1563 dc_fixpt_div(timing_bw, timeslot_bw_effective);
1564
1565 return avg_time_slots_per_mtp;
1566 }
1567
1568
write_128b_132b_sst_payload_allocation_table(const struct dc_stream_state * stream,struct dc_link * link,struct link_mst_stream_allocation_table * proposed_table,bool allocate)1569 static bool write_128b_132b_sst_payload_allocation_table(
1570 const struct dc_stream_state *stream,
1571 struct dc_link *link,
1572 struct link_mst_stream_allocation_table *proposed_table,
1573 bool allocate)
1574 {
1575 const uint8_t vc_id = 1; /// VC ID always 1 for SST
1576 const uint8_t start_time_slot = 0; /// Always start at time slot 0 for SST
1577 bool result = false;
1578 uint8_t req_slot_count = 0;
1579 struct fixed31_32 avg_time_slots_per_mtp = { 0 };
1580 union payload_table_update_status update_status = { 0 };
1581 const uint32_t max_retries = 30;
1582 uint32_t retries = 0;
1583 DC_LOGGER_INIT(link->ctx->logger);
1584
1585 if (allocate) {
1586 avg_time_slots_per_mtp = link_calculate_sst_avg_time_slots_per_mtp(stream, link);
1587 req_slot_count = dc_fixpt_ceil(avg_time_slots_per_mtp);
1588 /// Validation should filter out modes that exceed link BW
1589 ASSERT(req_slot_count <= MAX_MTP_SLOT_COUNT);
1590 if (req_slot_count > MAX_MTP_SLOT_COUNT)
1591 return false;
1592 } else {
1593 /// Leave req_slot_count = 0 if allocate is false.
1594 }
1595
1596 proposed_table->stream_count = 1; /// Always 1 stream for SST
1597 proposed_table->stream_allocations[0].slot_count = req_slot_count;
1598 proposed_table->stream_allocations[0].vcp_id = vc_id;
1599
1600 if (link->aux_access_disabled)
1601 return true;
1602
1603 /// Write DPCD 2C0 = 1 to start updating
1604 update_status.bits.VC_PAYLOAD_TABLE_UPDATED = 1;
1605 core_link_write_dpcd(
1606 link,
1607 DP_PAYLOAD_TABLE_UPDATE_STATUS,
1608 &update_status.raw,
1609 1);
1610
1611 /// Program the changes in DPCD 1C0 - 1C2
1612 ASSERT(vc_id == 1);
1613 core_link_write_dpcd(
1614 link,
1615 DP_PAYLOAD_ALLOCATE_SET,
1616 &vc_id,
1617 1);
1618
1619 ASSERT(start_time_slot == 0);
1620 core_link_write_dpcd(
1621 link,
1622 DP_PAYLOAD_ALLOCATE_START_TIME_SLOT,
1623 &start_time_slot,
1624 1);
1625
1626 core_link_write_dpcd(
1627 link,
1628 DP_PAYLOAD_ALLOCATE_TIME_SLOT_COUNT,
1629 &req_slot_count,
1630 1);
1631
1632 /// Poll till DPCD 2C0 read 1
1633 /// Try for at least 150ms (30 retries, with 5ms delay after each attempt)
1634
1635 while (retries < max_retries) {
1636 if (core_link_read_dpcd(
1637 link,
1638 DP_PAYLOAD_TABLE_UPDATE_STATUS,
1639 &update_status.raw,
1640 1) == DC_OK) {
1641 if (update_status.bits.VC_PAYLOAD_TABLE_UPDATED == 1) {
1642 DC_LOG_DP2("SST Update Payload: downstream payload table updated.");
1643 result = true;
1644 break;
1645 }
1646 } else {
1647 union dpcd_rev dpcdRev;
1648
1649 if (core_link_read_dpcd(
1650 link,
1651 DP_DPCD_REV,
1652 &dpcdRev.raw,
1653 1) != DC_OK) {
1654 DC_LOG_ERROR("SST Update Payload: Unable to read DPCD revision "
1655 "of sink while polling payload table "
1656 "updated status bit.");
1657 break;
1658 }
1659 }
1660 retries++;
1661 fsleep(5000);
1662 }
1663
1664 if (!result && retries == max_retries) {
1665 DC_LOG_ERROR("SST Update Payload: Payload table not updated after retries, "
1666 "continue on. Something is wrong with the branch.");
1667 // TODO - DP2.0 Payload: Read and log the payload table from downstream branch
1668 }
1669
1670 return result;
1671 }
1672
1673 /*
1674 * Payload allocation/deallocation for SST introduced in DP2.0
1675 */
update_sst_payload(struct pipe_ctx * pipe_ctx,bool allocate)1676 static enum dc_status update_sst_payload(struct pipe_ctx *pipe_ctx,
1677 bool allocate)
1678 {
1679 struct dc_stream_state *stream = pipe_ctx->stream;
1680 struct dc_link *link = stream->link;
1681 struct link_mst_stream_allocation_table proposed_table = {0};
1682 struct fixed31_32 avg_time_slots_per_mtp;
1683 const struct dc_link_settings empty_link_settings = {0};
1684 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1685 DC_LOGGER_INIT(link->ctx->logger);
1686
1687 /* slot X.Y for SST payload deallocate */
1688 if (!allocate) {
1689 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
1690
1691 log_vcp_x_y(link, avg_time_slots_per_mtp);
1692
1693 if (link_hwss->ext.set_throttled_vcp_size)
1694 link_hwss->ext.set_throttled_vcp_size(pipe_ctx,
1695 avg_time_slots_per_mtp);
1696 if (link_hwss->ext.set_hblank_min_symbol_width)
1697 link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
1698 &empty_link_settings,
1699 avg_time_slots_per_mtp);
1700 }
1701
1702 /* calculate VC payload and update branch with new payload allocation table*/
1703 if (!write_128b_132b_sst_payload_allocation_table(
1704 stream,
1705 link,
1706 &proposed_table,
1707 allocate)) {
1708 DC_LOG_ERROR("SST Update Payload: Failed to update "
1709 "allocation table for "
1710 "pipe idx: %d\n",
1711 pipe_ctx->pipe_idx);
1712 return DC_FAIL_DP_PAYLOAD_ALLOCATION;
1713 }
1714
1715 proposed_table.stream_allocations[0].hpo_dp_stream_enc = pipe_ctx->stream_res.hpo_dp_stream_enc;
1716
1717 ASSERT(proposed_table.stream_count == 1);
1718
1719 //TODO - DP2.0 Logging: Instead of hpo_dp_stream_enc pointer, log instance id
1720 DC_LOG_DP2("SST Update Payload: hpo_dp_stream_enc: %p "
1721 "vcp_id: %d "
1722 "slot_count: %d\n",
1723 (void *) proposed_table.stream_allocations[0].hpo_dp_stream_enc,
1724 proposed_table.stream_allocations[0].vcp_id,
1725 proposed_table.stream_allocations[0].slot_count);
1726
1727 /* program DP source TX for payload */
1728 link_hwss->ext.update_stream_allocation_table(link, &pipe_ctx->link_res,
1729 &proposed_table);
1730
1731 /* poll for ACT handled */
1732 if (!poll_for_allocation_change_trigger(link)) {
1733 // Failures will result in blackscreen and errors logged
1734 BREAK_TO_DEBUGGER();
1735 }
1736
1737 /* slot X.Y for SST payload allocate */
1738 if (allocate && link_dp_get_encoding_format(&link->cur_link_settings) ==
1739 DP_128b_132b_ENCODING) {
1740 avg_time_slots_per_mtp = link_calculate_sst_avg_time_slots_per_mtp(stream, link);
1741
1742 log_vcp_x_y(link, avg_time_slots_per_mtp);
1743
1744 if (link_hwss->ext.set_throttled_vcp_size)
1745 link_hwss->ext.set_throttled_vcp_size(pipe_ctx,
1746 avg_time_slots_per_mtp);
1747 if (link_hwss->ext.set_hblank_min_symbol_width)
1748 link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
1749 &link->cur_link_settings,
1750 avg_time_slots_per_mtp);
1751 }
1752
1753 /* Always return DC_OK.
1754 * If part of sequence fails, log failure(s) and show blackscreen
1755 */
1756 return DC_OK;
1757 }
1758
link_reduce_mst_payload(struct pipe_ctx * pipe_ctx,uint32_t bw_in_kbps)1759 enum dc_status link_reduce_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t bw_in_kbps)
1760 {
1761 struct dc_stream_state *stream = pipe_ctx->stream;
1762 struct dc_link *link = stream->link;
1763 struct fixed31_32 avg_time_slots_per_mtp;
1764 struct fixed31_32 pbn;
1765 struct fixed31_32 pbn_per_slot;
1766 struct dc_dp_mst_stream_allocation_table proposed_table = {0};
1767 uint8_t i;
1768 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1769 DC_LOGGER_INIT(link->ctx->logger);
1770
1771 /* decrease throttled vcp size */
1772 pbn_per_slot = get_pbn_per_slot(stream);
1773 pbn = get_pbn_from_bw_in_kbps(bw_in_kbps);
1774 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
1775
1776 if (link_hwss->ext.set_throttled_vcp_size)
1777 link_hwss->ext.set_throttled_vcp_size(pipe_ctx, avg_time_slots_per_mtp);
1778 if (link_hwss->ext.set_hblank_min_symbol_width)
1779 link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
1780 &link->cur_link_settings,
1781 avg_time_slots_per_mtp);
1782
1783 /* send ALLOCATE_PAYLOAD sideband message with updated pbn */
1784 dm_helpers_dp_mst_send_payload_allocation(
1785 stream->ctx,
1786 stream,
1787 true);
1788
1789 /* notify immediate branch device table update */
1790 if (dm_helpers_dp_mst_write_payload_allocation_table(
1791 stream->ctx,
1792 stream,
1793 &proposed_table,
1794 true)) {
1795 /* update mst stream allocation table software state */
1796 update_mst_stream_alloc_table(
1797 link,
1798 pipe_ctx->stream_res.stream_enc,
1799 pipe_ctx->stream_res.hpo_dp_stream_enc,
1800 &proposed_table);
1801 } else {
1802 DC_LOG_WARNING("Failed to update"
1803 "MST allocation table for"
1804 "pipe idx:%d\n",
1805 pipe_ctx->pipe_idx);
1806 }
1807
1808 DC_LOG_MST("%s "
1809 "stream_count: %d: \n ",
1810 __func__,
1811 link->mst_stream_alloc_table.stream_count);
1812
1813 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
1814 DC_LOG_MST("stream_enc[%d]: %p "
1815 "stream[%d].hpo_dp_stream_enc: %p "
1816 "stream[%d].vcp_id: %d "
1817 "stream[%d].slot_count: %d\n",
1818 i,
1819 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
1820 i,
1821 (void *) link->mst_stream_alloc_table.stream_allocations[i].hpo_dp_stream_enc,
1822 i,
1823 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
1824 i,
1825 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
1826 }
1827
1828 ASSERT(proposed_table.stream_count > 0);
1829
1830 /* update mst stream allocation table hardware state */
1831 if (link_hwss->ext.update_stream_allocation_table == NULL ||
1832 link_dp_get_encoding_format(&link->cur_link_settings) == DP_UNKNOWN_ENCODING) {
1833 DC_LOG_ERROR("Failure: unknown encoding format\n");
1834 return DC_ERROR_UNEXPECTED;
1835 }
1836
1837 link_hwss->ext.update_stream_allocation_table(link, &pipe_ctx->link_res,
1838 &link->mst_stream_alloc_table);
1839
1840 /* poll for immediate branch device ACT handled */
1841 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
1842 stream->ctx,
1843 stream);
1844
1845 return DC_OK;
1846 }
1847
link_increase_mst_payload(struct pipe_ctx * pipe_ctx,uint32_t bw_in_kbps)1848 enum dc_status link_increase_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t bw_in_kbps)
1849 {
1850 struct dc_stream_state *stream = pipe_ctx->stream;
1851 struct dc_link *link = stream->link;
1852 struct fixed31_32 avg_time_slots_per_mtp;
1853 struct fixed31_32 pbn;
1854 struct fixed31_32 pbn_per_slot;
1855 struct dc_dp_mst_stream_allocation_table proposed_table = {0};
1856 uint8_t i;
1857 enum act_return_status ret;
1858 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1859 DC_LOGGER_INIT(link->ctx->logger);
1860
1861 /* notify immediate branch device table update */
1862 if (dm_helpers_dp_mst_write_payload_allocation_table(
1863 stream->ctx,
1864 stream,
1865 &proposed_table,
1866 true)) {
1867 /* update mst stream allocation table software state */
1868 update_mst_stream_alloc_table(
1869 link,
1870 pipe_ctx->stream_res.stream_enc,
1871 pipe_ctx->stream_res.hpo_dp_stream_enc,
1872 &proposed_table);
1873 }
1874
1875 DC_LOG_MST("%s "
1876 "stream_count: %d: \n ",
1877 __func__,
1878 link->mst_stream_alloc_table.stream_count);
1879
1880 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
1881 DC_LOG_MST("stream_enc[%d]: %p "
1882 "stream[%d].hpo_dp_stream_enc: %p "
1883 "stream[%d].vcp_id: %d "
1884 "stream[%d].slot_count: %d\n",
1885 i,
1886 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
1887 i,
1888 (void *) link->mst_stream_alloc_table.stream_allocations[i].hpo_dp_stream_enc,
1889 i,
1890 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
1891 i,
1892 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
1893 }
1894
1895 ASSERT(proposed_table.stream_count > 0);
1896
1897 /* update mst stream allocation table hardware state */
1898 if (link_hwss->ext.update_stream_allocation_table == NULL ||
1899 link_dp_get_encoding_format(&link->cur_link_settings) == DP_UNKNOWN_ENCODING) {
1900 DC_LOG_ERROR("Failure: unknown encoding format\n");
1901 return DC_ERROR_UNEXPECTED;
1902 }
1903
1904 link_hwss->ext.update_stream_allocation_table(link, &pipe_ctx->link_res,
1905 &link->mst_stream_alloc_table);
1906
1907 /* poll for immediate branch device ACT handled */
1908 ret = dm_helpers_dp_mst_poll_for_allocation_change_trigger(
1909 stream->ctx,
1910 stream);
1911
1912 if (ret != ACT_LINK_LOST) {
1913 /* send ALLOCATE_PAYLOAD sideband message with updated pbn */
1914 dm_helpers_dp_mst_send_payload_allocation(
1915 stream->ctx,
1916 stream,
1917 true);
1918 }
1919
1920 /* increase throttled vcp size */
1921 pbn = get_pbn_from_bw_in_kbps(bw_in_kbps);
1922 pbn_per_slot = get_pbn_per_slot(stream);
1923 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
1924
1925 if (link_hwss->ext.set_throttled_vcp_size)
1926 link_hwss->ext.set_throttled_vcp_size(pipe_ctx, avg_time_slots_per_mtp);
1927 if (link_hwss->ext.set_hblank_min_symbol_width)
1928 link_hwss->ext.set_hblank_min_symbol_width(pipe_ctx,
1929 &link->cur_link_settings,
1930 avg_time_slots_per_mtp);
1931
1932 return DC_OK;
1933 }
1934
disable_link_dp(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)1935 static void disable_link_dp(struct dc_link *link,
1936 const struct link_resource *link_res,
1937 enum signal_type signal)
1938 {
1939 struct dc_link_settings link_settings = link->cur_link_settings;
1940
1941 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST &&
1942 link->mst_stream_alloc_table.stream_count > 0)
1943 /* disable MST link only when last vc payload is deallocated */
1944 return;
1945
1946 dp_disable_link_phy(link, link_res, signal);
1947
1948 if (link->connector_signal == SIGNAL_TYPE_EDP) {
1949 if (!link->skip_implict_edp_power_control)
1950 link->dc->hwss.edp_power_control(link, false);
1951 }
1952
1953 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
1954 /* set the sink to SST mode after disabling the link */
1955 enable_mst_on_sink(link, false);
1956
1957 if (link_dp_get_encoding_format(&link_settings) ==
1958 DP_8b_10b_ENCODING) {
1959 dp_set_fec_enable(link, false);
1960 dp_set_fec_ready(link, link_res, false);
1961 }
1962 }
1963
disable_link(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)1964 static void disable_link(struct dc_link *link,
1965 const struct link_resource *link_res,
1966 enum signal_type signal)
1967 {
1968 if (dc_is_dp_signal(signal)) {
1969 disable_link_dp(link, link_res, signal);
1970 } else if (signal != SIGNAL_TYPE_VIRTUAL) {
1971 link->dc->hwss.disable_link_output(link, link_res, signal);
1972 }
1973
1974 if (signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
1975 /* MST disable link only when no stream use the link */
1976 if (link->mst_stream_alloc_table.stream_count <= 0)
1977 link->link_status.link_active = false;
1978 } else {
1979 link->link_status.link_active = false;
1980 }
1981 }
1982
enable_link_hdmi(struct pipe_ctx * pipe_ctx)1983 static void enable_link_hdmi(struct pipe_ctx *pipe_ctx)
1984 {
1985 struct dc_stream_state *stream = pipe_ctx->stream;
1986 struct dc_link *link = stream->link;
1987 enum dc_color_depth display_color_depth;
1988 enum engine_id eng_id;
1989 struct ext_hdmi_settings settings = {0};
1990 bool is_over_340mhz = false;
1991 bool is_vga_mode = (stream->timing.h_addressable == 640)
1992 && (stream->timing.v_addressable == 480);
1993 struct dc *dc = pipe_ctx->stream->ctx->dc;
1994 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1995
1996 if (stream->phy_pix_clk == 0)
1997 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
1998 if (stream->phy_pix_clk > 340000)
1999 is_over_340mhz = true;
2000
2001 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2002 unsigned short masked_chip_caps = pipe_ctx->stream->link->chip_caps &
2003 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
2004 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
2005 /* DP159, Retimer settings */
2006 eng_id = pipe_ctx->stream_res.stream_enc->id;
2007
2008 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings)) {
2009 write_i2c_retimer_setting(pipe_ctx,
2010 is_vga_mode, is_over_340mhz, &settings);
2011 } else {
2012 write_i2c_default_retimer_setting(pipe_ctx,
2013 is_vga_mode, is_over_340mhz);
2014 }
2015 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
2016 /* PI3EQX1204, Redriver settings */
2017 write_i2c_redriver_setting(pipe_ctx, is_over_340mhz);
2018 }
2019 }
2020
2021 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2022 write_scdc_data(
2023 stream->link->ddc,
2024 stream->phy_pix_clk,
2025 stream->timing.flags.LTE_340MCSC_SCRAMBLE);
2026
2027 memset(&stream->link->cur_link_settings, 0,
2028 sizeof(struct dc_link_settings));
2029
2030 display_color_depth = stream->timing.display_color_depth;
2031 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
2032 display_color_depth = COLOR_DEPTH_888;
2033
2034 /* We need to enable stream encoder for TMDS first to apply 1/4 TMDS
2035 * character clock in case that beyond 340MHz.
2036 */
2037 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal))
2038 link_hwss->setup_stream_encoder(pipe_ctx);
2039
2040 dc->hwss.enable_tmds_link_output(
2041 link,
2042 &pipe_ctx->link_res,
2043 pipe_ctx->stream->signal,
2044 pipe_ctx->clock_source->id,
2045 display_color_depth,
2046 stream->phy_pix_clk);
2047
2048 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2049 read_scdc_data(link->ddc);
2050 }
2051
enable_link_dp(struct dc_state * state,struct pipe_ctx * pipe_ctx)2052 static enum dc_status enable_link_dp(struct dc_state *state,
2053 struct pipe_ctx *pipe_ctx)
2054 {
2055 struct dc_stream_state *stream = pipe_ctx->stream;
2056 enum dc_status status;
2057 bool skip_video_pattern;
2058 struct dc_link *link = stream->link;
2059 const struct dc_link_settings *link_settings =
2060 &pipe_ctx->link_config.dp_link_settings;
2061 bool fec_enable;
2062 int i;
2063 bool apply_seamless_boot_optimization = false;
2064 uint32_t bl_oled_enable_delay = 50; // in ms
2065 uint32_t post_oui_delay = 30; // 30ms
2066 /* Reduce link bandwidth between failed link training attempts. */
2067 bool do_fallback = false;
2068 int lt_attempts = LINK_TRAINING_ATTEMPTS;
2069
2070 // Increase retry count if attempting DP1.x on FIXED_VS link
2071 if ((link->chip_caps & EXT_DISPLAY_PATH_CAPS__DP_FIXED_VS_EN) &&
2072 link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING)
2073 lt_attempts = 10;
2074
2075 // check for seamless boot
2076 for (i = 0; i < state->stream_count; i++) {
2077 if (state->streams[i]->apply_seamless_boot_optimization) {
2078 apply_seamless_boot_optimization = true;
2079 break;
2080 }
2081 }
2082
2083 /* Train with fallback when enabling DPIA link. Conventional links are
2084 * trained with fallback during sink detection.
2085 */
2086 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
2087 do_fallback = true;
2088
2089 /*
2090 * Temporary w/a to get DP2.0 link rates to work with SST.
2091 * TODO DP2.0 - Workaround: Remove w/a if and when the issue is resolved.
2092 */
2093 if (link_dp_get_encoding_format(link_settings) == DP_128b_132b_ENCODING &&
2094 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
2095 link->dc->debug.set_mst_en_for_sst) {
2096 enable_mst_on_sink(link, true);
2097 }
2098 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
2099 /*in case it is not on*/
2100 if (!link->dc->config.edp_no_power_sequencing)
2101 link->dc->hwss.edp_power_control(link, true);
2102 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
2103 }
2104
2105 if (link_dp_get_encoding_format(link_settings) == DP_128b_132b_ENCODING) {
2106 /* TODO - DP2.0 HW: calculate 32 symbol clock for HPO encoder */
2107 } else {
2108 pipe_ctx->stream_res.pix_clk_params.requested_sym_clk =
2109 link_settings->link_rate * LINK_RATE_REF_FREQ_IN_KHZ;
2110 if (state->clk_mgr && !apply_seamless_boot_optimization)
2111 state->clk_mgr->funcs->update_clocks(state->clk_mgr,
2112 state, false);
2113 }
2114
2115 // during mode switch we do DP_SET_POWER off then on, and OUI is lost
2116 dpcd_set_source_specific_data(link);
2117 if (link->dpcd_sink_ext_caps.raw != 0) {
2118 post_oui_delay += link->panel_config.pps.extra_post_OUI_ms;
2119 msleep(post_oui_delay);
2120 }
2121
2122 // similarly, mode switch can cause loss of cable ID
2123 dpcd_write_cable_id_to_dprx(link);
2124
2125 skip_video_pattern = true;
2126
2127 if (link_settings->link_rate == LINK_RATE_LOW)
2128 skip_video_pattern = false;
2129
2130 if (perform_link_training_with_retries(link_settings,
2131 skip_video_pattern,
2132 lt_attempts,
2133 pipe_ctx,
2134 pipe_ctx->stream->signal,
2135 do_fallback)) {
2136 status = DC_OK;
2137 } else {
2138 status = DC_FAIL_DP_LINK_TRAINING;
2139 }
2140
2141 if (link->preferred_training_settings.fec_enable)
2142 fec_enable = *link->preferred_training_settings.fec_enable;
2143 else
2144 fec_enable = true;
2145
2146 if (link_dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING)
2147 dp_set_fec_enable(link, fec_enable);
2148
2149 // during mode set we do DP_SET_POWER off then on, aux writes are lost
2150 if (link->dpcd_sink_ext_caps.bits.oled == 1 ||
2151 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1 ||
2152 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1) {
2153 set_default_brightness_aux(link);
2154 if (link->dpcd_sink_ext_caps.bits.oled == 1)
2155 msleep(bl_oled_enable_delay);
2156 edp_backlight_enable_aux(link, true);
2157 }
2158
2159 return status;
2160 }
2161
enable_link_edp(struct dc_state * state,struct pipe_ctx * pipe_ctx)2162 static enum dc_status enable_link_edp(
2163 struct dc_state *state,
2164 struct pipe_ctx *pipe_ctx)
2165 {
2166 return enable_link_dp(state, pipe_ctx);
2167 }
2168
enable_link_lvds(struct pipe_ctx * pipe_ctx)2169 static void enable_link_lvds(struct pipe_ctx *pipe_ctx)
2170 {
2171 struct dc_stream_state *stream = pipe_ctx->stream;
2172 struct dc_link *link = stream->link;
2173 struct dc *dc = stream->ctx->dc;
2174
2175 if (stream->phy_pix_clk == 0)
2176 stream->phy_pix_clk = stream->timing.pix_clk_100hz / 10;
2177
2178 memset(&stream->link->cur_link_settings, 0,
2179 sizeof(struct dc_link_settings));
2180 dc->hwss.enable_lvds_link_output(
2181 link,
2182 &pipe_ctx->link_res,
2183 pipe_ctx->clock_source->id,
2184 stream->phy_pix_clk);
2185
2186 }
2187
enable_link_dp_mst(struct dc_state * state,struct pipe_ctx * pipe_ctx)2188 static enum dc_status enable_link_dp_mst(
2189 struct dc_state *state,
2190 struct pipe_ctx *pipe_ctx)
2191 {
2192 struct dc_link *link = pipe_ctx->stream->link;
2193 unsigned char mstm_cntl;
2194
2195 /* sink signal type after MST branch is MST. Multiple MST sinks
2196 * share one link. Link DP PHY is enable or training only once.
2197 */
2198 if (link->link_status.link_active)
2199 return DC_OK;
2200
2201 /* clear payload table */
2202 core_link_read_dpcd(link, DP_MSTM_CTRL, &mstm_cntl, 1);
2203 if (mstm_cntl & DP_MST_EN)
2204 dm_helpers_dp_mst_clear_payload_allocation_table(link->ctx, link);
2205
2206 /* to make sure the pending down rep can be processed
2207 * before enabling the link
2208 */
2209 dm_helpers_dp_mst_poll_pending_down_reply(link->ctx, link);
2210
2211 /* set the sink to MST mode before enabling the link */
2212 enable_mst_on_sink(link, true);
2213
2214 return enable_link_dp(state, pipe_ctx);
2215 }
2216
enable_link(struct dc_state * state,struct pipe_ctx * pipe_ctx)2217 static enum dc_status enable_link(
2218 struct dc_state *state,
2219 struct pipe_ctx *pipe_ctx)
2220 {
2221 enum dc_status status = DC_ERROR_UNEXPECTED;
2222 struct dc_stream_state *stream = pipe_ctx->stream;
2223 struct dc_link *link = stream->link;
2224
2225 /* There's some scenarios where driver is unloaded with display
2226 * still enabled. When driver is reloaded, it may cause a display
2227 * to not light up if there is a mismatch between old and new
2228 * link settings. Need to call disable first before enabling at
2229 * new link settings.
2230 */
2231 if (link->link_status.link_active)
2232 disable_link(link, &pipe_ctx->link_res, pipe_ctx->stream->signal);
2233
2234 switch (pipe_ctx->stream->signal) {
2235 case SIGNAL_TYPE_DISPLAY_PORT:
2236 status = enable_link_dp(state, pipe_ctx);
2237 break;
2238 case SIGNAL_TYPE_EDP:
2239 status = enable_link_edp(state, pipe_ctx);
2240 break;
2241 case SIGNAL_TYPE_DISPLAY_PORT_MST:
2242 status = enable_link_dp_mst(state, pipe_ctx);
2243 msleep(200);
2244 break;
2245 case SIGNAL_TYPE_DVI_SINGLE_LINK:
2246 case SIGNAL_TYPE_DVI_DUAL_LINK:
2247 case SIGNAL_TYPE_HDMI_TYPE_A:
2248 enable_link_hdmi(pipe_ctx);
2249 status = DC_OK;
2250 break;
2251 case SIGNAL_TYPE_LVDS:
2252 enable_link_lvds(pipe_ctx);
2253 status = DC_OK;
2254 break;
2255 case SIGNAL_TYPE_VIRTUAL:
2256 status = DC_OK;
2257 break;
2258 default:
2259 break;
2260 }
2261
2262 if (status == DC_OK) {
2263 pipe_ctx->stream->link->link_status.link_active = true;
2264 }
2265
2266 return status;
2267 }
2268
allocate_usb4_bandwidth_for_stream(struct dc_stream_state * stream,int bw)2269 static bool allocate_usb4_bandwidth_for_stream(struct dc_stream_state *stream, int bw)
2270 {
2271 return true;
2272 }
2273
allocate_usb4_bandwidth(struct dc_stream_state * stream)2274 static bool allocate_usb4_bandwidth(struct dc_stream_state *stream)
2275 {
2276 bool ret;
2277
2278 int bw = dc_bandwidth_in_kbps_from_timing(&stream->timing,
2279 dc_link_get_highest_encoding_format(stream->sink->link));
2280
2281 ret = allocate_usb4_bandwidth_for_stream(stream, bw);
2282
2283 return ret;
2284 }
2285
deallocate_usb4_bandwidth(struct dc_stream_state * stream)2286 static bool deallocate_usb4_bandwidth(struct dc_stream_state *stream)
2287 {
2288 bool ret;
2289
2290 ret = allocate_usb4_bandwidth_for_stream(stream, 0);
2291
2292 return ret;
2293 }
2294
link_set_dpms_off(struct pipe_ctx * pipe_ctx)2295 void link_set_dpms_off(struct pipe_ctx *pipe_ctx)
2296 {
2297 struct dc *dc = pipe_ctx->stream->ctx->dc;
2298 struct dc_stream_state *stream = pipe_ctx->stream;
2299 struct dc_link *link = stream->sink->link;
2300 struct vpg *vpg = pipe_ctx->stream_res.stream_enc->vpg;
2301
2302 ASSERT(is_master_pipe_for_link(link, pipe_ctx));
2303
2304 if (dp_is_128b_132b_signal(pipe_ctx))
2305 vpg = pipe_ctx->stream_res.hpo_dp_stream_enc->vpg;
2306
2307 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2308
2309 if (pipe_ctx->stream->sink) {
2310 if (pipe_ctx->stream->sink->sink_signal != SIGNAL_TYPE_VIRTUAL &&
2311 pipe_ctx->stream->sink->sink_signal != SIGNAL_TYPE_NONE) {
2312 DC_LOG_DC("%s pipe_ctx dispname=%s signal=%x\n", __func__,
2313 pipe_ctx->stream->sink->edid_caps.display_name,
2314 pipe_ctx->stream->signal);
2315 }
2316 }
2317
2318 if (dc_is_virtual_signal(pipe_ctx->stream->signal))
2319 return;
2320
2321 if (!pipe_ctx->stream->sink->edid_caps.panel_patch.skip_avmute) {
2322 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2323 set_avmute(pipe_ctx, true);
2324 }
2325
2326 dc->hwss.disable_audio_stream(pipe_ctx);
2327
2328 update_psp_stream_config(pipe_ctx, true);
2329 dc->hwss.blank_stream(pipe_ctx);
2330
2331 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
2332 deallocate_usb4_bandwidth(pipe_ctx->stream);
2333
2334 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
2335 deallocate_mst_payload(pipe_ctx);
2336 else if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
2337 dp_is_128b_132b_signal(pipe_ctx))
2338 update_sst_payload(pipe_ctx, false);
2339
2340 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2341 struct ext_hdmi_settings settings = {0};
2342 enum engine_id eng_id = pipe_ctx->stream_res.stream_enc->id;
2343
2344 unsigned short masked_chip_caps = link->chip_caps &
2345 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
2346 //Need to inform that sink is going to use legacy HDMI mode.
2347 write_scdc_data(
2348 link->ddc,
2349 165000,//vbios only handles 165Mhz.
2350 false);
2351 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
2352 /* DP159, Retimer settings */
2353 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings))
2354 write_i2c_retimer_setting(pipe_ctx,
2355 false, false, &settings);
2356 else
2357 write_i2c_default_retimer_setting(pipe_ctx,
2358 false, false);
2359 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
2360 /* PI3EQX1204, Redriver settings */
2361 write_i2c_redriver_setting(pipe_ctx, false);
2362 }
2363 }
2364
2365 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
2366 !dp_is_128b_132b_signal(pipe_ctx)) {
2367
2368 /* In DP1.x SST mode, our encoder will go to TPS1
2369 * when link is on but stream is off.
2370 * Disabling link before stream will avoid exposing TPS1 pattern
2371 * during the disable sequence as it will confuse some receivers
2372 * state machine.
2373 * In DP2 or MST mode, our encoder will stay video active
2374 */
2375 disable_link(pipe_ctx->stream->link, &pipe_ctx->link_res, pipe_ctx->stream->signal);
2376 dc->hwss.disable_stream(pipe_ctx);
2377 } else {
2378 dc->hwss.disable_stream(pipe_ctx);
2379 disable_link(pipe_ctx->stream->link, &pipe_ctx->link_res, pipe_ctx->stream->signal);
2380 }
2381
2382 if (pipe_ctx->stream->timing.flags.DSC) {
2383 if (dc_is_dp_signal(pipe_ctx->stream->signal))
2384 link_set_dsc_enable(pipe_ctx, false);
2385 }
2386 if (dp_is_128b_132b_signal(pipe_ctx)) {
2387 if (pipe_ctx->stream_res.tg->funcs->set_out_mux)
2388 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, OUT_MUX_DIO);
2389 }
2390
2391 if (vpg && vpg->funcs->vpg_powerdown)
2392 vpg->funcs->vpg_powerdown(vpg);
2393 }
2394
link_set_dpms_on(struct dc_state * state,struct pipe_ctx * pipe_ctx)2395 void link_set_dpms_on(
2396 struct dc_state *state,
2397 struct pipe_ctx *pipe_ctx)
2398 {
2399 struct dc *dc = pipe_ctx->stream->ctx->dc;
2400 struct dc_stream_state *stream = pipe_ctx->stream;
2401 struct dc_link *link = stream->sink->link;
2402 enum dc_status status;
2403 struct link_encoder *link_enc;
2404 enum otg_out_mux_dest otg_out_dest = OUT_MUX_DIO;
2405 struct vpg *vpg = pipe_ctx->stream_res.stream_enc->vpg;
2406 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
2407 bool apply_edp_fast_boot_optimization =
2408 pipe_ctx->stream->apply_edp_fast_boot_optimization;
2409
2410 ASSERT(is_master_pipe_for_link(link, pipe_ctx));
2411
2412 if (dp_is_128b_132b_signal(pipe_ctx))
2413 vpg = pipe_ctx->stream_res.hpo_dp_stream_enc->vpg;
2414
2415 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2416
2417 if (pipe_ctx->stream->sink) {
2418 if (pipe_ctx->stream->sink->sink_signal != SIGNAL_TYPE_VIRTUAL &&
2419 pipe_ctx->stream->sink->sink_signal != SIGNAL_TYPE_NONE) {
2420 DC_LOG_DC("%s pipe_ctx dispname=%s signal=%x\n", __func__,
2421 pipe_ctx->stream->sink->edid_caps.display_name,
2422 pipe_ctx->stream->signal);
2423 }
2424 }
2425
2426 if (dc_is_virtual_signal(pipe_ctx->stream->signal))
2427 return;
2428
2429 link_enc = link_enc_cfg_get_link_enc(link);
2430 ASSERT(link_enc);
2431
2432 if (!dc_is_virtual_signal(pipe_ctx->stream->signal)
2433 && !dp_is_128b_132b_signal(pipe_ctx)) {
2434 if (link_enc)
2435 link_enc->funcs->setup(
2436 link_enc,
2437 pipe_ctx->stream->signal);
2438 }
2439
2440 pipe_ctx->stream->link->link_state_valid = true;
2441
2442 if (pipe_ctx->stream_res.tg->funcs->set_out_mux) {
2443 if (dp_is_128b_132b_signal(pipe_ctx))
2444 otg_out_dest = OUT_MUX_HPO_DP;
2445 else
2446 otg_out_dest = OUT_MUX_DIO;
2447 pipe_ctx->stream_res.tg->funcs->set_out_mux(pipe_ctx->stream_res.tg, otg_out_dest);
2448 }
2449
2450 link_hwss->setup_stream_attribute(pipe_ctx);
2451
2452 pipe_ctx->stream->apply_edp_fast_boot_optimization = false;
2453
2454 // Enable VPG before building infoframe
2455 if (vpg && vpg->funcs->vpg_poweron)
2456 vpg->funcs->vpg_poweron(vpg);
2457
2458 resource_build_info_frame(pipe_ctx);
2459 dc->hwss.update_info_frame(pipe_ctx);
2460
2461 if (dc_is_dp_signal(pipe_ctx->stream->signal))
2462 dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
2463
2464 /* Do not touch link on seamless boot optimization. */
2465 if (pipe_ctx->stream->apply_seamless_boot_optimization) {
2466 pipe_ctx->stream->dpms_off = false;
2467
2468 /* Still enable stream features & audio on seamless boot for DP external displays */
2469 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT) {
2470 enable_stream_features(pipe_ctx);
2471 dc->hwss.enable_audio_stream(pipe_ctx);
2472 }
2473
2474 update_psp_stream_config(pipe_ctx, false);
2475 return;
2476 }
2477
2478 /* eDP lit up by bios already, no need to enable again. */
2479 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
2480 apply_edp_fast_boot_optimization &&
2481 !pipe_ctx->stream->timing.flags.DSC &&
2482 !pipe_ctx->next_odm_pipe) {
2483 pipe_ctx->stream->dpms_off = false;
2484 update_psp_stream_config(pipe_ctx, false);
2485 return;
2486 }
2487
2488 if (pipe_ctx->stream->dpms_off)
2489 return;
2490
2491 /* Have to setup DSC before DIG FE and BE are connected (which happens before the
2492 * link training). This is to make sure the bandwidth sent to DIG BE won't be
2493 * bigger than what the link and/or DIG BE can handle. VBID[6]/CompressedStream_flag
2494 * will be automatically set at a later time when the video is enabled
2495 * (DP_VID_STREAM_EN = 1).
2496 */
2497 if (pipe_ctx->stream->timing.flags.DSC) {
2498 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
2499 dc_is_virtual_signal(pipe_ctx->stream->signal))
2500 link_set_dsc_enable(pipe_ctx, true);
2501
2502 }
2503
2504 status = enable_link(state, pipe_ctx);
2505
2506 if (status != DC_OK) {
2507 DC_LOG_WARNING("enabling link %u failed: %d\n",
2508 pipe_ctx->stream->link->link_index,
2509 status);
2510
2511 /* Abort stream enable *unless* the failure was due to
2512 * DP link training - some DP monitors will recover and
2513 * show the stream anyway. But MST displays can't proceed
2514 * without link training.
2515 */
2516 if (status != DC_FAIL_DP_LINK_TRAINING ||
2517 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2518 if (false == stream->link->link_status.link_active)
2519 disable_link(stream->link, &pipe_ctx->link_res,
2520 pipe_ctx->stream->signal);
2521 BREAK_TO_DEBUGGER();
2522 return;
2523 }
2524 }
2525
2526 /* turn off otg test pattern if enable */
2527 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
2528 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
2529 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
2530 COLOR_DEPTH_UNDEFINED);
2531
2532 /* This second call is needed to reconfigure the DIG
2533 * as a workaround for the incorrect value being applied
2534 * from transmitter control.
2535 */
2536 if (!(dc_is_virtual_signal(pipe_ctx->stream->signal) ||
2537 dp_is_128b_132b_signal(pipe_ctx))) {
2538 if (link_enc)
2539 link_enc->funcs->setup(
2540 link_enc,
2541 pipe_ctx->stream->signal);
2542 }
2543
2544 dc->hwss.enable_stream(pipe_ctx);
2545
2546 /* Set DPS PPS SDP (AKA "info frames") */
2547 if (pipe_ctx->stream->timing.flags.DSC) {
2548 if (dc_is_dp_signal(pipe_ctx->stream->signal) ||
2549 dc_is_virtual_signal(pipe_ctx->stream->signal)) {
2550 dp_set_dsc_on_rx(pipe_ctx, true);
2551 link_set_dsc_pps_packet(pipe_ctx, true, true);
2552 }
2553 }
2554
2555 if (pipe_ctx->stream->link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA)
2556 allocate_usb4_bandwidth(pipe_ctx->stream);
2557
2558 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
2559 allocate_mst_payload(pipe_ctx);
2560 else if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT &&
2561 dp_is_128b_132b_signal(pipe_ctx))
2562 update_sst_payload(pipe_ctx, true);
2563
2564 dc->hwss.unblank_stream(pipe_ctx,
2565 &pipe_ctx->stream->link->cur_link_settings);
2566
2567 if (stream->sink_patches.delay_ignore_msa > 0)
2568 msleep(stream->sink_patches.delay_ignore_msa);
2569
2570 if (dc_is_dp_signal(pipe_ctx->stream->signal))
2571 enable_stream_features(pipe_ctx);
2572 update_psp_stream_config(pipe_ctx, false);
2573
2574 dc->hwss.enable_audio_stream(pipe_ctx);
2575
2576 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
2577 set_avmute(pipe_ctx, false);
2578 }
2579 }
2580