From: Austin Zheng <[email protected]>

Why:
Some EDIDs report a minimum refresh rate lower than what HW can support

How:
Add a check to calculate minimum supported refresh rate with current timing
and use that as the minimum if a lower one is passed in

Acked-by: Stylon Wang <[email protected]>
Signed-off-by: Austin Zheng <[email protected]>
Reviewed-by: Anthony Koo <[email protected]>
---
 drivers/gpu/drm/amd/display/dc/dc.h                   |  1 +
 drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c |  1 +
 .../gpu/drm/amd/display/dc/dcn302/dcn302_resource.c   |  1 +
 .../gpu/drm/amd/display/dc/dcn303/dcn303_resource.c   |  1 +
 drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c |  1 +
 .../gpu/drm/amd/display/dc/dcn321/dcn321_resource.c   |  1 +
 .../gpu/drm/amd/display/modules/freesync/freesync.c   | 11 +++++++++--
 7 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dc.h 
b/drivers/gpu/drm/amd/display/dc/dc.h
index 5c906b007e4d..a239dcd8e9fb 100644
--- a/drivers/gpu/drm/amd/display/dc/dc.h
+++ b/drivers/gpu/drm/amd/display/dc/dc.h
@@ -266,6 +266,7 @@ struct dc_caps {
        uint16_t subvp_pstate_allow_width_us;
        uint16_t subvp_vertical_int_margin_us;
        bool seamless_odm;
+       uint32_t max_v_total;
        uint8_t subvp_drr_vblank_start_margin_us;
 };
 
diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c
index f4ee4b3df596..1a0284a068b2 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c
@@ -2328,6 +2328,7 @@ static bool dcn30_resource_construct(
        dc->caps.color.mpc.ocsc = 1;
 
        dc->caps.dp_hdmi21_pcon_support = true;
+       dc->caps.max_v_total = (1 << 15) - 1;
 
        /* read VBIOS LTTPR caps */
        {
diff --git a/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c
index 93f42132c900..7dc065ea247a 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn302/dcn302_resource.c
@@ -1227,6 +1227,7 @@ static bool dcn302_resource_construct(
        dc->caps.force_dp_tps4_for_cp2520 = true;
        dc->caps.extended_aux_timeout_support = true;
        dc->caps.dmcub_support = true;
+       dc->caps.max_v_total = (1 << 15) - 1;
 
        /* Color pipeline capabilities */
        dc->caps.color.dpp.dcn_arch = 1;
diff --git a/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c
index f35514188a5c..6d9761395288 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn303/dcn303_resource.c
@@ -1152,6 +1152,7 @@ static bool dcn303_resource_construct(
        dc->caps.force_dp_tps4_for_cp2520 = true;
        dc->caps.extended_aux_timeout_support = true;
        dc->caps.dmcub_support = true;
+       dc->caps.max_v_total = (1 << 15) - 1;
 
        /* Color pipeline capabilities */
        dc->caps.color.dpp.dcn_arch = 1;
diff --git a/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c
index 8c9e15952a49..19f134caa8ad 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c
@@ -2175,6 +2175,7 @@ static bool dcn32_resource_construct(
        dc->caps.extended_aux_timeout_support = true;
        dc->caps.dmcub_support = true;
        dc->caps.seamless_odm = true;
+       dc->caps.max_v_total = (1 << 15) - 1;
 
        /* Color pipeline capabilities */
        dc->caps.color.dpp.dcn_arch = 1;
diff --git a/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c 
b/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c
index ee07ee340171..ea204742ad35 100644
--- a/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c
@@ -1718,6 +1718,7 @@ static bool dcn321_resource_construct(
        dc->caps.edp_dsc_support = true;
        dc->caps.extended_aux_timeout_support = true;
        dc->caps.dmcub_support = true;
+       dc->caps.max_v_total = (1 << 15) - 1;
 
        /* Color pipeline capabilities */
        dc->caps.color.dpp.dcn_arch = 1;
diff --git a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c 
b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
index 5798c0eafa1f..dbd60811f95d 100644
--- a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
+++ b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Advanced Micro Devices, Inc.
+ * Copyright 2016-2023 Advanced Micro Devices, Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -989,6 +989,7 @@ void mod_freesync_build_vrr_params(struct mod_freesync 
*mod_freesync,
        unsigned int refresh_range = 0;
        unsigned long long min_refresh_in_uhz = 0;
        unsigned long long max_refresh_in_uhz = 0;
+       unsigned long long min_hardware_refresh_in_uhz = 0;
 
        if (mod_freesync == NULL)
                return;
@@ -999,7 +1000,13 @@ void mod_freesync_build_vrr_params(struct mod_freesync 
*mod_freesync,
        nominal_field_rate_in_uhz =
                        mod_freesync_calc_nominal_field_rate(stream);
 
-       min_refresh_in_uhz = in_config->min_refresh_in_uhz;
+       if (stream->ctx->dc->caps.max_v_total != 0 && stream->timing.h_total != 
0) {
+               min_hardware_refresh_in_uhz = 
div64_u64((stream->timing.pix_clk_100hz * 100000000ULL),
+                       (stream->timing.h_total * 
stream->ctx->dc->caps.max_v_total));
+       }
+       /* Limit minimum refresh rate to what can be supported by hardware */
+       min_refresh_in_uhz = min_hardware_refresh_in_uhz > 
in_config->min_refresh_in_uhz ?
+               min_hardware_refresh_in_uhz : in_config->min_refresh_in_uhz;
        max_refresh_in_uhz = in_config->max_refresh_in_uhz;
 
        /* Full range may be larger than current video timing, so cap at 
nominal */
-- 
2.40.1

Reply via email to