drm/radeon: use 64-bit math to calculate CTS values for audio (v2)
authorAlex Deucher <alexander.deucher@amd.com>
Fri, 27 Sep 2013 22:09:54 +0000 (18:09 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 9 Oct 2013 21:13:43 +0000 (17:13 -0400)
Avoid losing precision.  See bug:
https://bugs.freedesktop.org/show_bug.cgi?id=69675

v2: fix math as per Anssi's comments.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/r600_hdmi.c

index b0fa6002af3e98da440cbebfa1ae183163e8b07d..49043a5ac65c779b7c6ddd49ca9171f87650b0ef 100644 (file)
@@ -75,8 +75,15 @@ static const struct radeon_hdmi_acr r600_hdmi_predefined_acr[] = {
  */
 static void r600_hdmi_calc_cts(uint32_t clock, int *CTS, int N, int freq)
 {
-       if (*CTS == 0)
-               *CTS = clock * N / (128 * freq) * 1000;
+       u64 n;
+       u32 d;
+
+       if (*CTS == 0) {
+               n = (u64)clock * (u64)N * 1000ULL;
+               d = 128 * freq;
+               do_div(n, d);
+               *CTS = n;
+       }
        DRM_DEBUG("Using ACR timing N=%d CTS=%d for frequency %d\n",
                  N, *CTS, freq);
 }