drm/amd/display: Properly round nominal frequency for SPD
authorAric Cyr <aric.cyr@amd.com>
Wed, 11 Sep 2019 20:17:08 +0000 (16:17 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 11 Oct 2019 00:32:16 +0000 (19:32 -0500)
[Why]
Some displays rely on the SPD verticle frequency maximum value.
Must round the calculated refresh rate to the nearest integer.

[How]
Round the nominal calculated refresh rate to the nearest whole
integer.

Signed-off-by: Aric Cyr <aric.cyr@amd.com>
Reviewed-by: Anthony Koo <Anthony.Koo@amd.com>
Acked-by: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/modules/freesync/freesync.c

index 237dda75138087c787872f9e9ab141767815507b..ee89bd2f7fe478faf1f0f1beb95c38ca9047b6c7 100644 (file)
@@ -743,6 +743,10 @@ void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
        nominal_field_rate_in_uhz =
                        mod_freesync_calc_nominal_field_rate(stream);
 
+       /* Rounded to the nearest Hz */
+       nominal_field_rate_in_uhz = 1000000ULL *
+                       div_u64(nominal_field_rate_in_uhz + 500000, 1000000);
+
        min_refresh_in_uhz = in_config->min_refresh_in_uhz;
        max_refresh_in_uhz = in_config->max_refresh_in_uhz;
 
@@ -998,14 +1002,13 @@ unsigned long long mod_freesync_calc_nominal_field_rate(
                        const struct dc_stream_state *stream)
 {
        unsigned long long nominal_field_rate_in_uhz = 0;
+       unsigned int total = stream->timing.h_total * stream->timing.v_total;
 
-       /* Calculate nominal field rate for stream */
+       /* Calculate nominal field rate for stream, rounded up to nearest integer */
        nominal_field_rate_in_uhz = stream->timing.pix_clk_100hz / 10;
        nominal_field_rate_in_uhz *= 1000ULL * 1000ULL * 1000ULL;
-       nominal_field_rate_in_uhz = div_u64(nominal_field_rate_in_uhz,
-                                               stream->timing.h_total);
-       nominal_field_rate_in_uhz = div_u64(nominal_field_rate_in_uhz,
-                                               stream->timing.v_total);
+
+       nominal_field_rate_in_uhz =     div_u64(nominal_field_rate_in_uhz, total);
 
        return nominal_field_rate_in_uhz;
 }