drm: i2c: tda998x: Select appropriate sound clock rate
authorAndrew Jackson <Andrew.Jackson@arm.com>
Fri, 29 Aug 2014 14:54:53 +0000 (15:54 +0100)
committerLiviu Dudau <Liviu.Dudau@arm.com>
Tue, 7 Oct 2014 11:10:58 +0000 (12:10 +0100)
The average CTS value is based upon the (pixel) clock rate.

Signed-off-by: Andrew Jackson <Andrew.Jackson@arm.com>
drivers/gpu/drm/i2c/tda998x_codec.c
drivers/gpu/drm/i2c/tda998x_drv.c

index 4f1d759..c84d2b5 100644 (file)
@@ -117,6 +117,7 @@ static int tda_hw_params(struct snd_pcm_substream *substream,
                tda998x_audio_start(priv, 0);
                return 0;
        }
+       priv->params.audio_sample_rate = params_rate(params);
        priv->params.audio_format = dai->id;
        priv->audio_sample_format = params_format(params);
        priv->params.audio_cfg =
index 10da2ca..7532b40 100644 (file)
@@ -627,7 +627,7 @@ tda998x_configure_audio(struct tda998x_priv *priv,
                struct drm_display_mode *mode, struct tda998x_encoder_params *p)
 {
        uint8_t buf[6], clksel_aip, clksel_fs, cts_n, adiv, aclk;
-       uint32_t n;
+       uint32_t n, cts;
 
        /* Enable audio ports */
        reg_write(priv, REG_ENA_AP, p->audio_cfg);
@@ -698,9 +698,25 @@ tda998x_configure_audio(struct tda998x_priv *priv,
        n = 128 * p->audio_sample_rate / 1000;
 
        /* Write the CTS and N values */
-       buf[0] = 0x44;
-       buf[1] = 0x42;
-       buf[2] = 0x01;
+       if ((n > 0) && (mode->clock > 0)) {
+               /*
+                * The average CTS value is calculated as:
+                *
+                *      fTMDS * n / (128 * fs)
+                *
+                * which equates to:
+                *
+                *      fTMDS / 1000
+                *
+                * for non-coherent clocks.
+                */
+               cts = mode->clock;
+       } else {
+               cts = 82500;
+       }
+       buf[0] = cts;
+       buf[1] = cts >> 8;
+       buf[2] = cts >> 16;
        buf[3] = n;
        buf[4] = n >> 8;
        buf[5] = n >> 16;