aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Niederprüm <niederp@physik.uni-kl.de>2015-01-21 18:01:57 -0500
committerMark Brown <broonie@kernel.org>2015-01-27 12:13:24 -0500
commit1c34c876c4abb219381dcb7096206f1a609f119b (patch)
tree131f3f8613a67dcf0ff831d7f8923995b8f4f249
parent88483f59d95f06e43dc9152afc81402df687bd27 (diff)
ASoC: sta32x: move code to calculate mclk divider and extrapolation ratio to sta32x_hw_params()
Signed-off-by: Thomas Niederprüm <niederp@physik.uni-kl.de> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/sta32x.c87
1 files changed, 32 insertions, 55 deletions
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index b808c65788fa..ec2372498c92 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -554,17 +554,12 @@ static struct {
554}; 554};
555 555
556/* MCLK to fs clock ratios */ 556/* MCLK to fs clock ratios */
557static struct { 557static int mcs_ratio_table[3][7] = {
558 int ratio; 558 { 768, 512, 384, 256, 128, 576, 0 },
559 int mcs; 559 { 384, 256, 192, 128, 64, 0 },
560} mclk_ratios[3][7] = { 560 { 384, 256, 192, 128, 64, 0 },
561 { { 768, 0 }, { 512, 1 }, { 384, 2 }, { 256, 3 },
562 { 128, 4 }, { 576, 5 }, { 0, 0 } },
563 { { 384, 2 }, { 256, 3 }, { 192, 4 }, { 128, 5 }, {64, 0 }, { 0, 0 } },
564 { { 384, 2 }, { 256, 3 }, { 192, 4 }, { 128, 5 }, {64, 0 }, { 0, 0 } },
565}; 561};
566 562
567
568/** 563/**
569 * sta32x_set_dai_sysclk - configure MCLK 564 * sta32x_set_dai_sysclk - configure MCLK
570 * @codec_dai: the codec DAI 565 * @codec_dai: the codec DAI
@@ -589,46 +584,10 @@ static int sta32x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
589{ 584{
590 struct snd_soc_codec *codec = codec_dai->codec; 585 struct snd_soc_codec *codec = codec_dai->codec;
591 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 586 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
592 int i, j, ir, fs;
593 unsigned int rates = 0;
594 unsigned int rate_min = -1;
595 unsigned int rate_max = 0;
596 587
597 pr_debug("mclk=%u\n", freq); 588 dev_dbg(codec->dev, "mclk=%u\n", freq);
598 sta32x->mclk = freq; 589 sta32x->mclk = freq;
599 590
600 if (sta32x->mclk) {
601 for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++) {
602 ir = interpolation_ratios[i].ir;
603 fs = interpolation_ratios[i].fs;
604 for (j = 0; mclk_ratios[ir][j].ratio; j++) {
605 if (mclk_ratios[ir][j].ratio * fs == freq) {
606 rates |= snd_pcm_rate_to_rate_bit(fs);
607 if (fs < rate_min)
608 rate_min = fs;
609 if (fs > rate_max)
610 rate_max = fs;
611 break;
612 }
613 }
614 }
615 /* FIXME: soc should support a rate list */
616 rates &= ~SNDRV_PCM_RATE_KNOT;
617
618 if (!rates) {
619 dev_err(codec->dev, "could not find a valid sample rate\n");
620 return -EINVAL;
621 }
622 } else {
623 /* enable all possible rates */
624 rates = STA32X_RATES;
625 rate_min = 32000;
626 rate_max = 192000;
627 }
628
629 codec_dai->driver->playback.rates = rates;
630 codec_dai->driver->playback.rate_min = rate_min;
631 codec_dai->driver->playback.rate_max = rate_max;
632 return 0; 591 return 0;
633} 592}
634 593
@@ -694,26 +653,44 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
694{ 653{
695 struct snd_soc_codec *codec = dai->codec; 654 struct snd_soc_codec *codec = dai->codec;
696 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 655 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
697 unsigned int rate; 656 int i, mcs = -EINVAL, ir = -EINVAL;
698 int i, mcs = -1, ir = -1;
699 unsigned int confa, confb; 657 unsigned int confa, confb;
658 unsigned int rate, ratio;
659 int ret;
660
661 if (!sta32x->mclk) {
662 dev_err(codec->dev,
663 "sta32x->mclk is unset. Unable to determine ratio\n");
664 return -EIO;
665 }
700 666
701 rate = params_rate(params); 667 rate = params_rate(params);
702 pr_debug("rate: %u\n", rate); 668 ratio = sta32x->mclk / rate;
703 for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++) 669 dev_dbg(codec->dev, "rate: %u, ratio: %u\n", rate, ratio);
670
671 for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++) {
704 if (interpolation_ratios[i].fs == rate) { 672 if (interpolation_ratios[i].fs == rate) {
705 ir = interpolation_ratios[i].ir; 673 ir = interpolation_ratios[i].ir;
706 break; 674 break;
707 } 675 }
708 if (ir < 0) 676 }
677
678 if (ir < 0) {
679 dev_err(codec->dev, "Unsupported samplerate: %u\n", rate);
709 return -EINVAL; 680 return -EINVAL;
710 for (i = 0; mclk_ratios[ir][i].ratio; i++) 681 }
711 if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk) { 682
712 mcs = mclk_ratios[ir][i].mcs; 683 for (i = 0; i < 6; i++) {
684 if (mcs_ratio_table[ir][i] == ratio) {
685 mcs = i;
713 break; 686 break;
714 } 687 }
715 if (mcs < 0) 688 }
689
690 if (mcs < 0) {
691 dev_err(codec->dev, "Unresolvable ratio: %u\n", ratio);
716 return -EINVAL; 692 return -EINVAL;
693 }
717 694
718 confa = (ir << STA32X_CONFA_IR_SHIFT) | 695 confa = (ir << STA32X_CONFA_IR_SHIFT) |
719 (mcs << STA32X_CONFA_MCS_SHIFT); 696 (mcs << STA32X_CONFA_MCS_SHIFT);