ASoC: pcm512x: Rearrange to not repeat dacsrc_rate / dac_div
authorPeter Rosin <peda@axentia.se>
Mon, 16 Feb 2015 21:02:47 +0000 (22:02 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 24 Feb 2015 14:14:24 +0000 (23:14 +0900)
Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/pcm512x.c

index 9974f201a08f44ee25b109c7ff78e13440146c4b..f11c76f1acfedfd171df8c18d64c5d9412bea8c8 100644 (file)
@@ -863,28 +863,29 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai,
                dacsrc_rate = sck_rate;
        }
 
+       osr_div = DIV_ROUND_CLOSEST(dac_rate, osr_rate);
+       if (osr_div > 128) {
+               dev_err(dev, "Failed to find OSR divider\n");
+               return -EINVAL;
+       }
+
        dac_div = DIV_ROUND_CLOSEST(dacsrc_rate, dac_rate);
        if (dac_div > 128) {
                dev_err(dev, "Failed to find DAC divider\n");
                return -EINVAL;
        }
+       dac_rate = dacsrc_rate / dac_div;
 
-       ncp_div = DIV_ROUND_CLOSEST(dacsrc_rate / dac_div, 1536000);
-       if (ncp_div > 128 || dacsrc_rate / dac_div / ncp_div > 2048000) {
+       ncp_div = DIV_ROUND_CLOSEST(dac_rate, 1536000);
+       if (ncp_div > 128 || dac_rate / ncp_div > 2048000) {
                /* run NCP no faster than 2048000 Hz, but why? */
-               ncp_div = DIV_ROUND_UP(dacsrc_rate / dac_div, 2048000);
+               ncp_div = DIV_ROUND_UP(dac_rate, 2048000);
                if (ncp_div > 128) {
                        dev_err(dev, "Failed to find NCP divider\n");
                        return -EINVAL;
                }
        }
 
-       osr_div = DIV_ROUND_CLOSEST(dac_rate, osr_rate);
-       if (osr_div > 128) {
-               dev_err(dev, "Failed to find OSR divider\n");
-               return -EINVAL;
-       }
-
        idac = mck_rate / (dsp_div * sample_rate);
 
        ret = regmap_write(pcm512x->regmap, PCM512x_DSP_CLKDIV, dsp_div - 1);