]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
ASoC: cs4270: allow passing freq=0 in set_dai_sysclk()
authorDaniel Mack <daniel@caiaq.de>
Fri, 15 Jan 2010 16:36:48 +0000 (17:36 +0100)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 15 Jan 2010 17:28:41 +0000 (17:28 +0000)
For setups with variable MCLKs, the current logic of limiting the
available sampling rates at startup time is not sufficient. We need to
be able to change the setting at a later point, and so the codec must
offer all possible rates until the hw_params are given.

This patches allows that by passing 0 as 'freq' argument to
cs4270_set_dai_sysclk().

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Acked-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
sound/soc/codecs/cs4270.c

index 8b5457542a0e7c1d138618bc893328f252d282d2..593bfc7a6986a6446c37fef41fabcaa377454fe4 100644 (file)
@@ -200,6 +200,11 @@ static struct cs4270_mode_ratios cs4270_mode_ratios[] = {
  * This function must be called by the machine driver's 'startup' function,
  * otherwise the list of supported sample rates will not be available in
  * time for ALSA.
+ *
+ * For setups with variable MCLKs, pass 0 as 'freq' argument. This will cause
+ * theoretically possible sample rates to be enabled. Call it again with a
+ * proper value set one the external clock is set (most probably you would do
+ * that from a machine's driver 'hw_param' hook.
  */
 static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                 int clk_id, unsigned int freq, int dir)
@@ -213,20 +218,27 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
 
        cs4270->mclk = freq;
 
-       for (i = 0; i < NUM_MCLK_RATIOS; i++) {
-               unsigned int rate = freq / cs4270_mode_ratios[i].ratio;
-               rates |= snd_pcm_rate_to_rate_bit(rate);
-               if (rate < rate_min)
-                       rate_min = rate;
-               if (rate > rate_max)
-                       rate_max = rate;
-       }
-       /* FIXME: soc should support a rate list */
-       rates &= ~SNDRV_PCM_RATE_KNOT;
+       if (cs4270->mclk) {
+               for (i = 0; i < NUM_MCLK_RATIOS; i++) {
+                       unsigned int rate = freq / cs4270_mode_ratios[i].ratio;
+                       rates |= snd_pcm_rate_to_rate_bit(rate);
+                       if (rate < rate_min)
+                               rate_min = rate;
+                       if (rate > rate_max)
+                               rate_max = rate;
+               }
+               /* FIXME: soc should support a rate list */
+               rates &= ~SNDRV_PCM_RATE_KNOT;
 
-       if (!rates) {
-               dev_err(codec->dev, "could not find a valid sample rate\n");
-               return -EINVAL;
+               if (!rates) {
+                       dev_err(codec->dev, "could not find a valid sample rate\n");
+                       return -EINVAL;
+               }
+       } else {
+               /* enable all possible rates */
+               rates = SNDRV_PCM_RATE_8000_192000;
+               rate_min = 8000;
+               rate_max = 192000;
        }
 
        codec_dai->playback.rates = rates;