ASoC: ml26124: Remove duplicate code
authorAxel Lin <axel.lin@ingics.com>
Sun, 14 Jun 2015 02:28:01 +0000 (10:28 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 15 Jun 2015 10:05:43 +0000 (11:05 +0100)
Current code has duplicate code for 16000, 32000 and 48000 sample rates.
get_srate() returns negative error code for unsupported rate, so we can
remove the duplicate code in the swith cases by calling get_srate() first.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/ml26124.c

index 711f55039522f473a5070cb1454a03132423f5d6..d19f3deebd3f0ba4984f43fb822a066ea5df53ac 100644 (file)
@@ -341,6 +341,7 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_codec *codec = dai->codec;
        struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
        int i = get_coeff(priv->mclk, params_rate(hw_params));
+       int srate;
 
        if (i < 0)
                return i;
@@ -370,53 +371,16 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream,
                                    BIT(0) | BIT(1), 0);
        }
 
-       switch (params_rate(hw_params)) {
-       case 16000:
-               snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
-                                   get_srate(params_rate(hw_params)));
-               snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
-                                   coeff_div[i].pllnl);
-               snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
-                                   coeff_div[i].pllnh);
-               snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
-                                   coeff_div[i].pllml);
-               snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
-                                   coeff_div[i].pllmh);
-               snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
-                                   coeff_div[i].plldiv);
-               break;
-       case 32000:
-               snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
-                                   get_srate(params_rate(hw_params)));
-               snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
-                                   coeff_div[i].pllnl);
-               snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
-                                   coeff_div[i].pllnh);
-               snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
-                                   coeff_div[i].pllml);
-               snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
-                                   coeff_div[i].pllmh);
-               snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
-                                   coeff_div[i].plldiv);
-               break;
-       case 48000:
-               snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
-                                   get_srate(params_rate(hw_params)));
-               snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
-                                   coeff_div[i].pllnl);
-               snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
-                                   coeff_div[i].pllnh);
-               snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
-                                   coeff_div[i].pllml);
-               snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
-                                   coeff_div[i].pllmh);
-               snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
-                                   coeff_div[i].plldiv);
-               break;
-       default:
-               pr_err("%s:this rate is no support for ml26124\n", __func__);
-               return -EINVAL;
-       }
+       srate = get_srate(params_rate(hw_params));
+       if (srate < 0)
+               return srate;
+
+       snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, srate);
+       snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, coeff_div[i].pllnl);
+       snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, coeff_div[i].pllnh);
+       snd_soc_update_bits(codec, ML26124_PLLML, 0xff, coeff_div[i].pllml);
+       snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, coeff_div[i].pllmh);
+       snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, coeff_div[i].plldiv);
 
        return 0;
 }