From 56fcde849cc4be82a39cacfe375aa0164773be83 Mon Sep 17 00:00:00 2001 From: Alex Deucher Date: Fri, 27 Sep 2013 18:09:54 -0400 Subject: [PATCH 1/3] drm/radeon: use 64-bit math to calculate CTS values for audio Avoid losing precision. See bug: https://bugs.freedesktop.org/show_bug.cgi?id=69675 Signed-off-by: Alex Deucher --- drivers/gpu/drm/radeon/r600_hdmi.c | 15 +++++++++++---- drivers/gpu/drm/radeon/radeon.h | 12 ++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c b/drivers/gpu/drm/radeon/r600_hdmi.c index b0fa600..2ce2793 100644 --- a/drivers/gpu/drm/radeon/r600_hdmi.c +++ b/drivers/gpu/drm/radeon/r600_hdmi.c @@ -24,6 +24,7 @@ * Authors: Christian König */ #include +#include #include #include #include "radeon.h" @@ -73,11 +74,17 @@ static const struct radeon_hdmi_acr r600_hdmi_predefined_acr[] = { /* * calculate CTS value if it's not found in the table */ -static void r600_hdmi_calc_cts(uint32_t clock, int *CTS, int N, int freq) +static void r600_hdmi_calc_cts(u32 clock, u64 *CTS, u64 N, u32 freq) { - if (*CTS == 0) - *CTS = clock * N / (128 * freq) * 1000; - DRM_DEBUG("Using ACR timing N=%d CTS=%d for frequency %d\n", + u64 n, d; + + if (*CTS == 0) { + n = (u64)clock * N; + d = 128ULL * (u64)freq; + *CTS = div64_u64(n, d); + *CTS *= 1000ULL; + } + DRM_DEBUG("Using ACR timing N=%llu CTS=%llu for frequency %u\n", N, *CTS, freq); } diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index a400ac1..c230178 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -2740,14 +2740,14 @@ int r600_fmt_get_nblocksy(u32 format, u32 h); struct radeon_hdmi_acr { u32 clock; - int n_32khz; - int cts_32khz; + u64 n_32khz; + u64 cts_32khz; - int n_44_1khz; - int cts_44_1khz; + u64 n_44_1khz; + u64 cts_44_1khz; - int n_48khz; - int cts_48khz; + u64 n_48khz; + u64 cts_48khz; }; -- 1.8.3.1