0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "amdgpu_dm_psr.h"
0027 #include "dc.h"
0028 #include "dm_helpers.h"
0029 #include "amdgpu_dm.h"
0030 #include "modules/power/power_helpers.h"
0031
0032 static bool link_supports_psrsu(struct dc_link *link)
0033 {
0034 struct dc *dc = link->ctx->dc;
0035
0036 if (!dc->caps.dmcub_support)
0037 return false;
0038
0039 if (dc->ctx->dce_version < DCN_VERSION_3_1)
0040 return false;
0041
0042 if (!is_psr_su_specific_panel(link))
0043 return false;
0044
0045 if (!link->dpcd_caps.alpm_caps.bits.AUX_WAKE_ALPM_CAP ||
0046 !link->dpcd_caps.psr_info.psr_dpcd_caps.bits.Y_COORDINATE_REQUIRED)
0047 return false;
0048
0049 if (link->dpcd_caps.psr_info.psr_dpcd_caps.bits.SU_GRANULARITY_REQUIRED &&
0050 !link->dpcd_caps.psr_info.psr2_su_y_granularity_cap)
0051 return false;
0052
0053 return true;
0054 }
0055
0056
0057
0058
0059
0060
0061 void amdgpu_dm_set_psr_caps(struct dc_link *link)
0062 {
0063 if (!(link->connector_signal & SIGNAL_TYPE_EDP))
0064 return;
0065
0066 if (link->type == dc_connection_none)
0067 return;
0068
0069 if (link->dpcd_caps.psr_info.psr_version == 0) {
0070 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
0071 link->psr_settings.psr_feature_enabled = false;
0072
0073 } else {
0074 if (link_supports_psrsu(link))
0075 link->psr_settings.psr_version = DC_PSR_VERSION_SU_1;
0076 else
0077 link->psr_settings.psr_version = DC_PSR_VERSION_1;
0078
0079 link->psr_settings.psr_feature_enabled = true;
0080 }
0081
0082 DRM_INFO("PSR support %d, DC PSR ver %d, sink PSR ver %d DPCD caps 0x%x su_y_granularity %d\n",
0083 link->psr_settings.psr_feature_enabled,
0084 link->psr_settings.psr_version,
0085 link->dpcd_caps.psr_info.psr_version,
0086 link->dpcd_caps.psr_info.psr_dpcd_caps.raw,
0087 link->dpcd_caps.psr_info.psr2_su_y_granularity_cap);
0088
0089 }
0090
0091
0092
0093
0094
0095
0096
0097 bool amdgpu_dm_link_setup_psr(struct dc_stream_state *stream)
0098 {
0099 struct dc_link *link = NULL;
0100 struct psr_config psr_config = {0};
0101 struct psr_context psr_context = {0};
0102 struct dc *dc = NULL;
0103 bool ret = false;
0104
0105 if (stream == NULL)
0106 return false;
0107
0108 link = stream->link;
0109 dc = link->ctx->dc;
0110
0111 if (link->psr_settings.psr_version != DC_PSR_VERSION_UNSUPPORTED) {
0112 mod_power_calc_psr_configs(&psr_config, link, stream);
0113
0114
0115 psr_config.allow_smu_optimizations =
0116 (amdgpu_dc_feature_mask & DC_PSR_ALLOW_SMU_OPT) &&
0117 mod_power_only_edp(dc->current_state, stream);
0118 psr_config.allow_multi_disp_optimizations =
0119 (amdgpu_dc_feature_mask & DC_PSR_ALLOW_MULTI_DISP_OPT);
0120
0121 ret = dc_link_setup_psr(link, stream, &psr_config, &psr_context);
0122
0123 }
0124 DRM_DEBUG_DRIVER("PSR link: %d\n", link->psr_settings.psr_feature_enabled);
0125
0126 return ret;
0127 }
0128
0129
0130
0131
0132
0133
0134
0135 bool amdgpu_dm_psr_enable(struct dc_stream_state *stream)
0136 {
0137 struct dc_link *link = stream->link;
0138 unsigned int vsync_rate_hz = 0;
0139 struct dc_static_screen_params params = {0};
0140
0141
0142
0143
0144 unsigned int num_frames_static = 2;
0145 unsigned int power_opt = 0;
0146 bool psr_enable = true;
0147
0148 DRM_DEBUG_DRIVER("Enabling psr...\n");
0149
0150 vsync_rate_hz = div64_u64(div64_u64((
0151 stream->timing.pix_clk_100hz * 100),
0152 stream->timing.v_total),
0153 stream->timing.h_total);
0154
0155
0156
0157
0158
0159 if (vsync_rate_hz != 0) {
0160 unsigned int frame_time_microsec = 1000000 / vsync_rate_hz;
0161 num_frames_static = (30000 / frame_time_microsec) + 1;
0162 }
0163
0164 params.triggers.cursor_update = true;
0165 params.triggers.overlay_update = true;
0166 params.triggers.surface_update = true;
0167 params.num_frames = num_frames_static;
0168
0169 dc_stream_set_static_screen_params(link->ctx->dc,
0170 &stream, 1,
0171 ¶ms);
0172
0173
0174
0175
0176
0177
0178 if (link->psr_settings.psr_version < DC_PSR_VERSION_SU_1)
0179 power_opt |= psr_power_opt_z10_static_screen;
0180
0181 return dc_link_set_psr_allow_active(link, &psr_enable, false, false, &power_opt);
0182 }
0183
0184
0185
0186
0187
0188
0189
0190 bool amdgpu_dm_psr_disable(struct dc_stream_state *stream)
0191 {
0192 unsigned int power_opt = 0;
0193 bool psr_enable = false;
0194
0195 DRM_DEBUG_DRIVER("Disabling psr...\n");
0196
0197 return dc_link_set_psr_allow_active(stream->link, &psr_enable, true, false, &power_opt);
0198 }
0199
0200
0201
0202
0203
0204
0205
0206 bool amdgpu_dm_psr_disable_all(struct amdgpu_display_manager *dm)
0207 {
0208 DRM_DEBUG_DRIVER("Disabling psr if psr is enabled on any stream\n");
0209 return dc_set_psr_allow_active(dm->dc, false);
0210 }
0211