2 * Copyright 2022 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 /* FILE POLICY AND INTENDED USAGE:
27 * This file implements retrieval and configuration of eDP panel features such
28 * as PSR and ABM and it also manages specs defined eDP panel power sequences.
31 #include "link_edp_panel_control.h"
32 #include "link_dpcd.h"
33 #include "link_dp_capability.h"
34 #include "dm_helpers.h"
35 #include "dal_asic_id.h"
36 #include "dce/dmub_psr.h"
37 #include "dc/dc_dmub_srv.h"
38 #include "dce/dmub_replay.h"
40 #define DC_LOGGER_INIT(logger)
42 #define DP_SINK_PR_ENABLE_AND_CONFIGURATION 0x37B
45 static const uint8_t DP_VGA_LVDS_CONVERTER_ID_2[] = "sivarT";
47 static const uint8_t DP_VGA_LVDS_CONVERTER_ID_3[] = "dnomlA";
49 void dp_set_panel_mode(struct dc_link *link, enum dp_panel_mode panel_mode)
51 union dpcd_edp_config edp_config_set;
52 bool panel_mode_edp = false;
53 enum dc_status result;
55 memset(&edp_config_set, '\0', sizeof(union dpcd_edp_config));
58 case DP_PANEL_MODE_EDP:
59 case DP_PANEL_MODE_SPECIAL:
60 panel_mode_edp = true;
67 /*set edp panel mode in receiver*/
68 result = core_link_read_dpcd(
70 DP_EDP_CONFIGURATION_SET,
72 sizeof(edp_config_set.raw));
74 if (result == DC_OK &&
75 edp_config_set.bits.PANEL_MODE_EDP
78 edp_config_set.bits.PANEL_MODE_EDP =
80 result = core_link_write_dpcd(
82 DP_EDP_CONFIGURATION_SET,
84 sizeof(edp_config_set.raw));
86 ASSERT(result == DC_OK);
89 link->panel_mode = panel_mode;
90 DC_LOG_DETECTION_DP_CAPS("Link: %d eDP panel mode supported: %d "
91 "eDP panel mode enabled: %d \n",
93 link->dpcd_caps.panel_mode_edp,
97 enum dp_panel_mode dp_get_panel_mode(struct dc_link *link)
99 /* We need to explicitly check that connector
100 * is not DP. Some Travis_VGA get reported
101 * by video bios as DP.
103 if (link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT) {
105 switch (link->dpcd_caps.branch_dev_id) {
106 case DP_BRANCH_DEVICE_ID_0022B9:
107 /* alternate scrambler reset is required for Travis
108 * for the case when external chip does not
109 * provide sink device id, alternate scrambler
110 * scheme will be overriden later by querying
114 link->dpcd_caps.branch_dev_name,
115 DP_VGA_LVDS_CONVERTER_ID_2,
118 branch_dev_name)) == 0) {
119 return DP_PANEL_MODE_SPECIAL;
122 case DP_BRANCH_DEVICE_ID_00001A:
123 /* alternate scrambler reset is required for Travis
124 * for the case when external chip does not provide
125 * sink device id, alternate scrambler scheme will
126 * be overriden later by querying Encoder feature
128 if (strncmp(link->dpcd_caps.branch_dev_name,
129 DP_VGA_LVDS_CONVERTER_ID_3,
132 branch_dev_name)) == 0) {
133 return DP_PANEL_MODE_SPECIAL;
141 if (link->dpcd_caps.panel_mode_edp &&
142 (link->connector_signal == SIGNAL_TYPE_EDP ||
143 (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
144 link->is_internal_display))) {
145 return DP_PANEL_MODE_EDP;
148 return DP_PANEL_MODE_DEFAULT;
151 bool edp_set_backlight_level_nits(struct dc_link *link,
153 uint32_t backlight_millinits,
154 uint32_t transition_time_in_ms)
156 struct dpcd_source_backlight_set dpcd_backlight_set;
157 uint8_t backlight_control = isHDR ? 1 : 0;
159 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
160 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
163 // OLEDs have no PWM, they can only use AUX
164 if (link->dpcd_sink_ext_caps.bits.oled == 1)
165 backlight_control = 1;
167 *(uint32_t *)&dpcd_backlight_set.backlight_level_millinits = backlight_millinits;
168 *(uint16_t *)&dpcd_backlight_set.backlight_transition_time_ms = (uint16_t)transition_time_in_ms;
170 link->backlight_settings.backlight_millinits = backlight_millinits;
172 if (!link->dpcd_caps.panel_luminance_control) {
173 if (core_link_write_dpcd(link, DP_SOURCE_BACKLIGHT_LEVEL,
174 (uint8_t *)(&dpcd_backlight_set),
175 sizeof(dpcd_backlight_set)) != DC_OK)
178 if (core_link_write_dpcd(link, DP_SOURCE_BACKLIGHT_CONTROL,
179 &backlight_control, 1) != DC_OK)
182 const uint8_t backlight_enable = DP_EDP_PANEL_LUMINANCE_CONTROL_ENABLE;
183 struct target_luminance_value *target_luminance = NULL;
185 //if target luminance value is greater than 24 bits, clip the value to 24 bits
186 if (backlight_millinits > 0xFFFFFF)
187 backlight_millinits = 0xFFFFFF;
189 target_luminance = (struct target_luminance_value *)&backlight_millinits;
191 if (core_link_write_dpcd(link, DP_EDP_BACKLIGHT_MODE_SET_REGISTER,
193 sizeof(backlight_enable)) != DC_OK)
196 if (core_link_write_dpcd(link, DP_EDP_PANEL_TARGET_LUMINANCE_VALUE,
197 (uint8_t *)(target_luminance),
198 sizeof(struct target_luminance_value)) != DC_OK)
205 bool edp_get_backlight_level_nits(struct dc_link *link,
206 uint32_t *backlight_millinits_avg,
207 uint32_t *backlight_millinits_peak)
209 union dpcd_source_backlight_get dpcd_backlight_get;
211 memset(&dpcd_backlight_get, 0, sizeof(union dpcd_source_backlight_get));
213 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
214 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
217 if (!core_link_read_dpcd(link, DP_SOURCE_BACKLIGHT_CURRENT_PEAK,
218 dpcd_backlight_get.raw,
219 sizeof(union dpcd_source_backlight_get)))
222 *backlight_millinits_avg =
223 dpcd_backlight_get.bytes.backlight_millinits_avg;
224 *backlight_millinits_peak =
225 dpcd_backlight_get.bytes.backlight_millinits_peak;
227 /* On non-supported panels dpcd_read usually succeeds with 0 returned */
228 if (*backlight_millinits_avg == 0 ||
229 *backlight_millinits_avg > *backlight_millinits_peak)
235 bool edp_backlight_enable_aux(struct dc_link *link, bool enable)
237 uint8_t backlight_enable = enable ? 1 : 0;
239 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
240 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
243 if (core_link_write_dpcd(link, DP_SOURCE_BACKLIGHT_ENABLE,
244 &backlight_enable, 1) != DC_OK)
250 // we read default from 0x320 because we expect BIOS wrote it there
251 // regular get_backlight_nit reads from panel set at 0x326
252 static bool read_default_bl_aux(struct dc_link *link, uint32_t *backlight_millinits)
254 if (!link || (link->connector_signal != SIGNAL_TYPE_EDP &&
255 link->connector_signal != SIGNAL_TYPE_DISPLAY_PORT))
258 if (!link->dpcd_caps.panel_luminance_control) {
259 if (!core_link_read_dpcd(link, DP_SOURCE_BACKLIGHT_LEVEL,
260 (uint8_t *)backlight_millinits,
264 //setting to 0 as a precaution, since target_luminance_value is 3 bytes
265 memset(backlight_millinits, 0, sizeof(uint32_t));
267 if (!core_link_read_dpcd(link, DP_EDP_PANEL_TARGET_LUMINANCE_VALUE,
268 (uint8_t *)backlight_millinits,
269 sizeof(struct target_luminance_value)))
276 bool set_default_brightness_aux(struct dc_link *link)
278 uint32_t default_backlight;
280 if (link && link->dpcd_sink_ext_caps.bits.oled == 1) {
281 if (!read_default_bl_aux(link, &default_backlight))
282 default_backlight = 150000;
283 // if < 5 nits or > 5000, it might be wrong readback
284 if (default_backlight < 5000 || default_backlight > 5000000)
285 default_backlight = 150000; //
287 return edp_set_backlight_level_nits(link, true,
288 default_backlight, 0);
293 bool set_cached_brightness_aux(struct dc_link *link)
295 if (link->backlight_settings.backlight_millinits)
296 return edp_set_backlight_level_nits(link, true,
297 link->backlight_settings.backlight_millinits, 0);
299 return set_default_brightness_aux(link);
303 bool edp_is_ilr_optimization_required(struct dc_link *link,
304 struct dc_crtc_timing *crtc_timing)
306 struct dc_link_settings link_setting;
308 uint8_t link_rate_set;
310 union lane_count_set lane_count_set = {0};
312 ASSERT(link || crtc_timing); // invalid input
314 if (link->dpcd_caps.edp_supported_link_rates_count == 0 ||
315 !link->panel_config.ilr.optimize_edp_link_rate)
319 // Read DPCD 00100h to find if standard link rates are set
320 core_link_read_dpcd(link, DP_LINK_BW_SET,
321 &link_bw_set, sizeof(link_bw_set));
324 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: Optimization required, VBIOS used link_bw_set\n");
328 // Read DPCD 00115h to find the edp link rate set used
329 core_link_read_dpcd(link, DP_LINK_RATE_SET,
330 &link_rate_set, sizeof(link_rate_set));
332 // Read DPCD 00101h to find out the number of lanes currently set
333 core_link_read_dpcd(link, DP_LANE_COUNT_SET,
334 &lane_count_set.raw, sizeof(lane_count_set));
336 req_bw = dc_bandwidth_in_kbps_from_timing(crtc_timing, dc_link_get_highest_encoding_format(link));
338 if (!crtc_timing->flags.DSC)
339 edp_decide_link_settings(link, &link_setting, req_bw);
341 decide_edp_link_settings_with_dsc(link, &link_setting, req_bw, LINK_RATE_UNKNOWN);
343 if (link->dpcd_caps.edp_supported_link_rates[link_rate_set] != link_setting.link_rate ||
344 lane_count_set.bits.LANE_COUNT_SET != link_setting.lane_count) {
345 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: Optimization required, VBIOS link_rate_set not optimal\n");
349 DC_LOG_EVENT_LINK_TRAINING("eDP ILR: No optimization required, VBIOS set optimal link_rate_set\n");
353 void edp_panel_backlight_power_on(struct dc_link *link, bool wait_for_hpd)
355 if (link->connector_signal != SIGNAL_TYPE_EDP)
358 link->dc->hwss.edp_power_control(link, true);
360 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
361 if (link->dc->hwss.edp_backlight_control)
362 link->dc->hwss.edp_backlight_control(link, true);
365 bool edp_wait_for_t12(struct dc_link *link)
367 if (link->connector_signal == SIGNAL_TYPE_EDP && link->dc->hwss.edp_wait_for_T12) {
368 link->dc->hwss.edp_wait_for_T12(link);
376 void edp_add_delay_for_T9(struct dc_link *link)
378 if (link && link->panel_config.pps.extra_delay_backlight_off > 0)
379 fsleep(link->panel_config.pps.extra_delay_backlight_off * 1000);
382 bool edp_receiver_ready_T9(struct dc_link *link)
384 unsigned int tries = 0;
385 unsigned char sinkstatus = 0;
386 unsigned char edpRev = 0;
387 enum dc_status result = DC_OK;
389 result = core_link_read_dpcd(link, DP_EDP_DPCD_REV, &edpRev, sizeof(edpRev));
391 /* start from eDP version 1.2, SINK_STAUS indicate the sink is ready.*/
392 if (result == DC_OK && edpRev >= DP_EDP_12) {
395 result = core_link_read_dpcd(link, DP_SINK_STATUS, &sinkstatus, sizeof(sinkstatus));
400 udelay(100); //MAx T9
401 } while (++tries < 50);
407 bool edp_receiver_ready_T7(struct dc_link *link)
409 unsigned char sinkstatus = 0;
410 unsigned char edpRev = 0;
411 enum dc_status result = DC_OK;
413 /* use absolute time stamp to constrain max T7*/
414 unsigned long long enter_timestamp = 0;
415 unsigned long long finish_timestamp = 0;
416 unsigned long long time_taken_in_ns = 0;
418 result = core_link_read_dpcd(link, DP_EDP_DPCD_REV, &edpRev, sizeof(edpRev));
420 if (result == DC_OK && edpRev >= DP_EDP_12) {
421 /* start from eDP version 1.2, SINK_STAUS indicate the sink is ready.*/
422 enter_timestamp = dm_get_timestamp(link->ctx);
425 result = core_link_read_dpcd(link, DP_SINK_STATUS, &sinkstatus, sizeof(sinkstatus));
431 finish_timestamp = dm_get_timestamp(link->ctx);
432 time_taken_in_ns = dm_get_elapse_time_in_ns(link->ctx, finish_timestamp, enter_timestamp);
433 } while (time_taken_in_ns < 50 * 1000000); //MAx T7 is 50ms
436 if (link && link->panel_config.pps.extra_t7_ms > 0)
437 fsleep(link->panel_config.pps.extra_t7_ms * 1000);
442 bool edp_power_alpm_dpcd_enable(struct dc_link *link, bool enable)
445 union dpcd_alpm_configuration alpm_config;
447 if (link->psr_settings.psr_version == DC_PSR_VERSION_SU_1) {
448 memset(&alpm_config, 0, sizeof(alpm_config));
450 alpm_config.bits.ENABLE = (enable ? true : false);
451 ret = dm_helpers_dp_write_dpcd(link->ctx, link,
452 DP_RECEIVER_ALPM_CONFIG, &alpm_config.raw,
453 sizeof(alpm_config.raw));
458 static struct pipe_ctx *get_pipe_from_link(const struct dc_link *link)
461 struct dc *dc = link->ctx->dc;
462 struct pipe_ctx *pipe_ctx = NULL;
464 for (i = 0; i < MAX_PIPES; i++) {
465 if (dc->current_state->res_ctx.pipe_ctx[i].stream) {
466 if (dc->current_state->res_ctx.pipe_ctx[i].stream->link == link) {
467 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
476 bool edp_set_backlight_level(const struct dc_link *link,
477 uint32_t backlight_pwm_u16_16,
480 struct dc *dc = link->ctx->dc;
482 DC_LOGGER_INIT(link->ctx->logger);
483 DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n",
484 backlight_pwm_u16_16, backlight_pwm_u16_16);
486 if (dc_is_embedded_signal(link->connector_signal)) {
487 struct pipe_ctx *pipe_ctx = get_pipe_from_link(link);
490 /* Disable brightness ramping when the display is blanked
491 * as it can hang the DMCU
493 if (pipe_ctx->plane_state == NULL)
499 dc->hwss.set_backlight_level(
501 backlight_pwm_u16_16,
507 bool edp_set_psr_allow_active(struct dc_link *link, const bool *allow_active,
508 bool wait, bool force_static, const unsigned int *power_opts)
510 struct dc *dc = link->ctx->dc;
511 struct dmcu *dmcu = dc->res_pool->dmcu;
512 struct dmub_psr *psr = dc->res_pool->psr;
513 unsigned int panel_inst;
515 if (psr == NULL && force_static)
518 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
521 if ((allow_active != NULL) && (*allow_active == true) && (link->type == dc_connection_none)) {
522 // Don't enter PSR if panel is not connected
526 /* Set power optimization flag */
527 if (power_opts && link->psr_settings.psr_power_opt != *power_opts) {
528 link->psr_settings.psr_power_opt = *power_opts;
530 if (psr != NULL && link->psr_settings.psr_feature_enabled && psr->funcs->psr_set_power_opt)
531 psr->funcs->psr_set_power_opt(psr, link->psr_settings.psr_power_opt, panel_inst);
534 if (psr != NULL && link->psr_settings.psr_feature_enabled &&
535 force_static && psr->funcs->psr_force_static)
536 psr->funcs->psr_force_static(psr, panel_inst);
538 /* Enable or Disable PSR */
539 if (allow_active && link->psr_settings.psr_allow_active != *allow_active) {
540 link->psr_settings.psr_allow_active = *allow_active;
542 if (!link->psr_settings.psr_allow_active)
545 if (psr != NULL && link->psr_settings.psr_feature_enabled) {
546 psr->funcs->psr_enable(psr, link->psr_settings.psr_allow_active, wait, panel_inst);
547 } else if ((dmcu != NULL && dmcu->funcs->is_dmcu_initialized(dmcu)) &&
548 link->psr_settings.psr_feature_enabled)
549 dmcu->funcs->set_psr_enable(dmcu, link->psr_settings.psr_allow_active, wait);
556 bool edp_get_psr_state(const struct dc_link *link, enum dc_psr_state *state)
558 struct dc *dc = link->ctx->dc;
559 struct dmcu *dmcu = dc->res_pool->dmcu;
560 struct dmub_psr *psr = dc->res_pool->psr;
561 unsigned int panel_inst;
563 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
566 if (psr != NULL && link->psr_settings.psr_feature_enabled)
567 psr->funcs->psr_get_state(psr, state, panel_inst);
568 else if (dmcu != NULL && link->psr_settings.psr_feature_enabled)
569 dmcu->funcs->get_psr_state(dmcu, state);
574 static inline enum physical_phy_id
575 transmitter_to_phy_id(struct dc_link *link)
577 struct dc_context *dc_ctx = link->ctx;
578 enum transmitter transmitter_value = link->link_enc->transmitter;
580 switch (transmitter_value) {
581 case TRANSMITTER_UNIPHY_A:
583 case TRANSMITTER_UNIPHY_B:
585 case TRANSMITTER_UNIPHY_C:
587 case TRANSMITTER_UNIPHY_D:
589 case TRANSMITTER_UNIPHY_E:
591 case TRANSMITTER_UNIPHY_F:
593 case TRANSMITTER_NUTMEG_CRT:
595 case TRANSMITTER_TRAVIS_CRT:
597 case TRANSMITTER_TRAVIS_LCD:
599 case TRANSMITTER_UNIPHY_G:
601 case TRANSMITTER_COUNT:
603 case TRANSMITTER_UNKNOWN:
604 return PHYLD_UNKNOWN;
606 DC_ERROR("Unknown transmitter value %d\n", transmitter_value);
607 return PHYLD_UNKNOWN;
611 bool edp_setup_psr(struct dc_link *link,
612 const struct dc_stream_state *stream, struct psr_config *psr_config,
613 struct psr_context *psr_context)
617 struct dmub_psr *psr;
619 unsigned int panel_inst;
620 /* updateSinkPsrDpcdConfig*/
621 union dpcd_psr_configuration psr_configuration;
622 union dpcd_sink_active_vtotal_control_mode vtotal_control = {0};
624 psr_context->controllerId = CONTROLLER_ID_UNDEFINED;
630 dmcu = dc->res_pool->dmcu;
631 psr = dc->res_pool->psr;
636 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
640 memset(&psr_configuration, 0, sizeof(psr_configuration));
642 psr_configuration.bits.ENABLE = 1;
643 psr_configuration.bits.CRC_VERIFICATION = 1;
644 psr_configuration.bits.FRAME_CAPTURE_INDICATION =
645 psr_config->psr_frame_capture_indication_req;
647 /* Check for PSR v2*/
648 if (link->psr_settings.psr_version == DC_PSR_VERSION_SU_1) {
649 /* For PSR v2 selective update.
650 * Indicates whether sink should start capturing
651 * immediately following active scan line,
652 * or starting with the 2nd active scan line.
654 psr_configuration.bits.LINE_CAPTURE_INDICATION = 0;
655 /*For PSR v2, determines whether Sink should generate
656 * IRQ_HPD when CRC mismatch is detected.
658 psr_configuration.bits.IRQ_HPD_WITH_CRC_ERROR = 1;
659 /* For PSR v2, set the bit when the Source device will
660 * be enabling PSR2 operation.
662 psr_configuration.bits.ENABLE_PSR2 = 1;
663 /* For PSR v2, the Sink device must be able to receive
664 * SU region updates early in the frame time.
666 psr_configuration.bits.EARLY_TRANSPORT_ENABLE = 1;
669 dm_helpers_dp_write_dpcd(
673 &psr_configuration.raw,
674 sizeof(psr_configuration.raw));
676 if (link->psr_settings.psr_version == DC_PSR_VERSION_SU_1) {
677 edp_power_alpm_dpcd_enable(link, true);
678 psr_context->su_granularity_required =
679 psr_config->su_granularity_required;
680 psr_context->su_y_granularity =
681 psr_config->su_y_granularity;
682 psr_context->line_time_in_us = psr_config->line_time_in_us;
684 /* linux must be able to expose AMD Source DPCD definition
685 * in order to support FreeSync PSR
687 if (link->psr_settings.psr_vtotal_control_support) {
688 psr_context->rate_control_caps = psr_config->rate_control_caps;
689 vtotal_control.bits.ENABLE = true;
690 core_link_write_dpcd(link, DP_SINK_PSR_ACTIVE_VTOTAL_CONTROL_MODE,
691 &vtotal_control.raw, sizeof(vtotal_control.raw));
695 psr_context->channel = link->ddc->ddc_pin->hw_info.ddc_channel;
696 psr_context->transmitterId = link->link_enc->transmitter;
697 psr_context->engineId = link->link_enc->preferred_engine;
699 for (i = 0; i < MAX_PIPES; i++) {
700 if (dc->current_state->res_ctx.pipe_ctx[i].stream
702 /* dmcu -1 for all controller id values,
705 psr_context->controllerId =
706 dc->current_state->res_ctx.
707 pipe_ctx[i].stream_res.tg->inst + 1;
712 /* Hardcoded for now. Can be Pcie or Uniphy (or Unknown)*/
713 psr_context->phyType = PHY_TYPE_UNIPHY;
714 /*PhyId is associated with the transmitter id*/
715 psr_context->smuPhyId = transmitter_to_phy_id(link);
717 psr_context->crtcTimingVerticalTotal = stream->timing.v_total;
718 psr_context->vsync_rate_hz = div64_u64(div64_u64((stream->
719 timing.pix_clk_100hz * 100),
720 stream->timing.v_total),
721 stream->timing.h_total);
723 psr_context->psrSupportedDisplayConfig = true;
724 psr_context->psrExitLinkTrainingRequired =
725 psr_config->psr_exit_link_training_required;
726 psr_context->sdpTransmitLineNumDeadline =
727 psr_config->psr_sdp_transmit_line_num_deadline;
728 psr_context->psrFrameCaptureIndicationReq =
729 psr_config->psr_frame_capture_indication_req;
731 psr_context->skipPsrWaitForPllLock = 0; /* only = 1 in KV */
733 psr_context->numberOfControllers =
734 link->dc->res_pool->timing_generator_count;
736 psr_context->rfb_update_auto_en = true;
738 /* 2 frames before enter PSR. */
739 psr_context->timehyst_frames = 2;
741 * (units in 100 lines, i.e. a value of 1 represents 100 lines)
743 psr_context->hyst_lines = stream->timing.v_total / 2 / 100;
744 psr_context->aux_repeats = 10;
746 psr_context->psr_level.u32all = 0;
748 /*skip power down the single pipe since it blocks the cstate*/
749 if (link->ctx->asic_id.chip_family >= FAMILY_RV) {
750 switch (link->ctx->asic_id.chip_family) {
751 case FAMILY_YELLOW_CARP:
752 case AMDGPU_FAMILY_GC_10_3_6:
753 case AMDGPU_FAMILY_GC_11_0_1:
754 if (dc->debug.disable_z10 || dc->debug.psr_skip_crtc_disable)
755 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
758 psr_context->psr_level.bits.SKIP_CRTC_DISABLE = true;
763 /* SMU will perform additional powerdown sequence.
764 * For unsupported ASICs, set psr_level flag to skip PSR
765 * static screen notification to SMU.
766 * (Always set for DAL2, did not check ASIC)
768 psr_context->allow_smu_optimizations = psr_config->allow_smu_optimizations;
769 psr_context->allow_multi_disp_optimizations = psr_config->allow_multi_disp_optimizations;
771 /* Complete PSR entry before aborting to prevent intermittent
772 * freezes on certain eDPs
774 psr_context->psr_level.bits.DISABLE_PSR_ENTRY_ABORT = 1;
776 /* Disable ALPM first for compatible non-ALPM panel now */
777 psr_context->psr_level.bits.DISABLE_ALPM = 0;
778 psr_context->psr_level.bits.ALPM_DEFAULT_PD_MODE = 1;
780 /* Controls additional delay after remote frame capture before
781 * continuing power down, default = 0
783 psr_context->frame_delay = 0;
785 psr_context->dsc_slice_height = psr_config->dsc_slice_height;
788 link->psr_settings.psr_feature_enabled = psr->funcs->psr_copy_settings(psr,
789 link, psr_context, panel_inst);
790 link->psr_settings.psr_power_opt = 0;
791 link->psr_settings.psr_allow_active = 0;
793 link->psr_settings.psr_feature_enabled = dmcu->funcs->setup_psr(dmcu, link, psr_context);
796 /* psr_enabled == 0 indicates setup_psr did not succeed, but this
797 * should not happen since firmware should be running at this point
799 if (link->psr_settings.psr_feature_enabled == 0)
806 void edp_get_psr_residency(const struct dc_link *link, uint32_t *residency)
808 struct dc *dc = link->ctx->dc;
809 struct dmub_psr *psr = dc->res_pool->psr;
810 unsigned int panel_inst;
812 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
815 // PSR residency measurements only supported on DMCUB
816 if (psr != NULL && link->psr_settings.psr_feature_enabled)
817 psr->funcs->psr_get_residency(psr, residency, panel_inst);
821 bool edp_set_sink_vtotal_in_psr_active(const struct dc_link *link, uint16_t psr_vtotal_idle, uint16_t psr_vtotal_su)
823 struct dc *dc = link->ctx->dc;
824 struct dmub_psr *psr = dc->res_pool->psr;
826 if (psr == NULL || !link->psr_settings.psr_feature_enabled || !link->psr_settings.psr_vtotal_control_support)
829 psr->funcs->psr_set_sink_vtotal_in_psr_active(psr, psr_vtotal_idle, psr_vtotal_su);
834 bool edp_set_replay_allow_active(struct dc_link *link, const bool *allow_active,
835 bool wait, bool force_static, const unsigned int *power_opts)
837 struct dc *dc = link->ctx->dc;
838 struct dmub_replay *replay = dc->res_pool->replay;
839 unsigned int panel_inst;
841 if (replay == NULL && force_static)
844 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
847 /* Set power optimization flag */
848 if (power_opts && link->replay_settings.replay_power_opt_active != *power_opts) {
849 if (link->replay_settings.replay_feature_enabled && replay->funcs->replay_set_power_opt) {
850 replay->funcs->replay_set_power_opt(replay, *power_opts, panel_inst);
851 link->replay_settings.replay_power_opt_active = *power_opts;
855 /* Activate or deactivate Replay */
856 if (allow_active && link->replay_settings.replay_allow_active != *allow_active) {
857 // TODO: Handle mux change case if force_static is set
858 // If force_static is set, just change the replay_allow_active state directly
859 if (replay != NULL && link->replay_settings.replay_feature_enabled)
860 replay->funcs->replay_enable(replay, *allow_active, wait, panel_inst);
861 link->replay_settings.replay_allow_active = *allow_active;
867 bool edp_get_replay_state(const struct dc_link *link, uint64_t *state)
869 struct dc *dc = link->ctx->dc;
870 struct dmub_replay *replay = dc->res_pool->replay;
871 unsigned int panel_inst;
872 enum replay_state pr_state = REPLAY_STATE_0;
874 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
877 if (replay != NULL && link->replay_settings.replay_feature_enabled)
878 replay->funcs->replay_get_state(replay, &pr_state, panel_inst);
884 bool edp_setup_replay(struct dc_link *link, const struct dc_stream_state *stream)
886 /* To-do: Setup Replay */
887 struct dc *dc = link->ctx->dc;
888 struct dmub_replay *replay = dc->res_pool->replay;
890 unsigned int panel_inst;
891 struct replay_context replay_context = { 0 };
892 unsigned int lineTimeInNs = 0;
895 union replay_enable_and_configuration replay_config;
897 union dpcd_alpm_configuration alpm_config;
899 replay_context.controllerId = CONTROLLER_ID_UNDEFINED;
907 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
910 replay_context.aux_inst = link->ddc->ddc_pin->hw_info.ddc_channel;
911 replay_context.digbe_inst = link->link_enc->transmitter;
912 replay_context.digfe_inst = link->link_enc->preferred_engine;
914 for (i = 0; i < MAX_PIPES; i++) {
915 if (dc->current_state->res_ctx.pipe_ctx[i].stream
917 /* dmcu -1 for all controller id values,
920 replay_context.controllerId =
921 dc->current_state->res_ctx.pipe_ctx[i].stream_res.tg->inst + 1;
927 ((stream->timing.h_total * 1000000) /
928 (stream->timing.pix_clk_100hz / 10)) + 1;
930 replay_context.line_time_in_ns = lineTimeInNs;
933 link->replay_settings.replay_feature_enabled =
934 replay->funcs->replay_copy_settings(replay, link, &replay_context, panel_inst);
935 if (link->replay_settings.replay_feature_enabled) {
937 replay_config.bits.FREESYNC_PANEL_REPLAY_MODE = 1;
938 replay_config.bits.TIMING_DESYNC_ERROR_VERIFICATION =
939 link->replay_settings.config.replay_timing_sync_supported;
940 replay_config.bits.STATE_TRANSITION_ERROR_DETECTION = 1;
941 dm_helpers_dp_write_dpcd(link->ctx, link,
942 DP_SINK_PR_ENABLE_AND_CONFIGURATION,
943 (uint8_t *)&(replay_config.raw), sizeof(uint8_t));
945 memset(&alpm_config, 0, sizeof(alpm_config));
946 alpm_config.bits.ENABLE = 1;
947 dm_helpers_dp_write_dpcd(
950 DP_RECEIVER_ALPM_CONFIG,
952 sizeof(alpm_config.raw));
957 bool edp_set_coasting_vtotal(struct dc_link *link, uint16_t coasting_vtotal)
959 struct dc *dc = link->ctx->dc;
960 struct dmub_replay *replay = dc->res_pool->replay;
961 unsigned int panel_inst;
966 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
969 if (coasting_vtotal && link->replay_settings.coasting_vtotal != coasting_vtotal) {
970 replay->funcs->replay_set_coasting_vtotal(replay, coasting_vtotal, panel_inst);
971 link->replay_settings.coasting_vtotal = coasting_vtotal;
977 bool edp_replay_residency(const struct dc_link *link,
978 unsigned int *residency, const bool is_start, const bool is_alpm)
980 struct dc *dc = link->ctx->dc;
981 struct dmub_replay *replay = dc->res_pool->replay;
982 unsigned int panel_inst;
984 if (!dc_get_edp_link_panel_inst(dc, link, &panel_inst))
987 if (replay != NULL && link->replay_settings.replay_feature_enabled)
988 replay->funcs->replay_residency(replay, panel_inst, residency, is_start, is_alpm);
995 static struct abm *get_abm_from_stream_res(const struct dc_link *link)
998 struct dc *dc = link->ctx->dc;
999 struct abm *abm = NULL;
1001 for (i = 0; i < MAX_PIPES; i++) {
1002 struct pipe_ctx pipe_ctx = dc->current_state->res_ctx.pipe_ctx[i];
1003 struct dc_stream_state *stream = pipe_ctx.stream;
1005 if (stream && stream->link == link) {
1006 abm = pipe_ctx.stream_res.abm;
1013 int edp_get_backlight_level(const struct dc_link *link)
1015 struct abm *abm = get_abm_from_stream_res(link);
1016 struct panel_cntl *panel_cntl = link->panel_cntl;
1017 struct dc *dc = link->ctx->dc;
1018 struct dmcu *dmcu = dc->res_pool->dmcu;
1019 bool fw_set_brightness = true;
1022 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
1024 if (!fw_set_brightness && panel_cntl->funcs->get_current_backlight)
1025 return panel_cntl->funcs->get_current_backlight(panel_cntl);
1026 else if (abm != NULL && abm->funcs->get_current_backlight != NULL)
1027 return (int) abm->funcs->get_current_backlight(abm);
1029 return DC_ERROR_UNEXPECTED;
1032 int edp_get_target_backlight_pwm(const struct dc_link *link)
1034 struct abm *abm = get_abm_from_stream_res(link);
1036 if (abm == NULL || abm->funcs->get_target_backlight == NULL)
1037 return DC_ERROR_UNEXPECTED;
1039 return (int) abm->funcs->get_target_backlight(abm);