aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/pcm512x.c
diff options
context:
space:
mode:
authorPeter Rosin <peda@axentia.se>2015-02-16 16:02:47 -0500
committerMark Brown <broonie@kernel.org>2015-02-24 09:14:24 -0500
commit5890bd5256bc026c425361fa087dc05c7a24d853 (patch)
tree495b557ad562dbc70b28cce9003954c157268265 /sound/soc/codecs/pcm512x.c
parentc517d838eb7d07bbe9507871fab3931deccff539 (diff)
ASoC: pcm512x: Rearrange to not repeat dacsrc_rate / dac_div
Signed-off-by: Peter Rosin <peda@axentia.se> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/codecs/pcm512x.c')
-rw-r--r--sound/soc/codecs/pcm512x.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index 9974f201a08f..f11c76f1acfe 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -863,28 +863,29 @@ static int pcm512x_set_dividers(struct snd_soc_dai *dai,
863 dacsrc_rate = sck_rate; 863 dacsrc_rate = sck_rate;
864 } 864 }
865 865
866 osr_div = DIV_ROUND_CLOSEST(dac_rate, osr_rate);
867 if (osr_div > 128) {
868 dev_err(dev, "Failed to find OSR divider\n");
869 return -EINVAL;
870 }
871
866 dac_div = DIV_ROUND_CLOSEST(dacsrc_rate, dac_rate); 872 dac_div = DIV_ROUND_CLOSEST(dacsrc_rate, dac_rate);
867 if (dac_div > 128) { 873 if (dac_div > 128) {
868 dev_err(dev, "Failed to find DAC divider\n"); 874 dev_err(dev, "Failed to find DAC divider\n");
869 return -EINVAL; 875 return -EINVAL;
870 } 876 }
877 dac_rate = dacsrc_rate / dac_div;
871 878
872 ncp_div = DIV_ROUND_CLOSEST(dacsrc_rate / dac_div, 1536000); 879 ncp_div = DIV_ROUND_CLOSEST(dac_rate, 1536000);
873 if (ncp_div > 128 || dacsrc_rate / dac_div / ncp_div > 2048000) { 880 if (ncp_div > 128 || dac_rate / ncp_div > 2048000) {
874 /* run NCP no faster than 2048000 Hz, but why? */ 881 /* run NCP no faster than 2048000 Hz, but why? */
875 ncp_div = DIV_ROUND_UP(dacsrc_rate / dac_div, 2048000); 882 ncp_div = DIV_ROUND_UP(dac_rate, 2048000);
876 if (ncp_div > 128) { 883 if (ncp_div > 128) {
877 dev_err(dev, "Failed to find NCP divider\n"); 884 dev_err(dev, "Failed to find NCP divider\n");
878 return -EINVAL; 885 return -EINVAL;
879 } 886 }
880 } 887 }
881 888
882 osr_div = DIV_ROUND_CLOSEST(dac_rate, osr_rate);
883 if (osr_div > 128) {
884 dev_err(dev, "Failed to find OSR divider\n");
885 return -EINVAL;
886 }
887
888 idac = mck_rate / (dsp_div * sample_rate); 889 idac = mck_rate / (dsp_div * sample_rate);
889 890
890 ret = regmap_write(pcm512x->regmap, PCM512x_DSP_CLKDIV, dsp_div - 1); 891 ret = regmap_write(pcm512x->regmap, PCM512x_DSP_CLKDIV, dsp_div - 1);