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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 31 Dec 2019 15:44:02 +0000 (16:44 +0100)
[ Upstream commit c59802313e84bede954235b3a5dd0dd5325f49c5 ]

[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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/display/modules/freesync/freesync.c

index ec70c9b..0978c69 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;
 
@@ -996,14 +1000,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;
 }