@@ -189,46 +189,57 @@ static const struct aic31xx_rate_divs aic31xx_divs[] = {
189189 /* mclk rate pll: p j d dosr ndac mdac aors nadc madc */
190190 /* 8k rate */
191191 {12000000 , 8000 , 1 , 8 , 1920 , 128 , 48 , 2 , 128 , 48 , 2 },
192+ {12000000 , 8000 , 1 , 8 , 1920 , 128 , 32 , 3 , 128 , 32 , 3 },
192193 {24000000 , 8000 , 2 , 8 , 1920 , 128 , 48 , 2 , 128 , 48 , 2 },
193194 {25000000 , 8000 , 2 , 7 , 8643 , 128 , 48 , 2 , 128 , 48 , 2 },
194195 /* 11.025k rate */
195196 {12000000 , 11025 , 1 , 7 , 5264 , 128 , 32 , 2 , 128 , 32 , 2 },
197+ {12000000 , 11025 , 1 , 8 , 4672 , 128 , 24 , 3 , 128 , 24 , 3 },
196198 {24000000 , 11025 , 2 , 7 , 5264 , 128 , 32 , 2 , 128 , 32 , 2 },
197199 {25000000 , 11025 , 2 , 7 , 2253 , 128 , 32 , 2 , 128 , 32 , 2 },
198200 /* 16k rate */
199201 {12000000 , 16000 , 1 , 8 , 1920 , 128 , 24 , 2 , 128 , 24 , 2 },
202+ {12000000 , 16000 , 1 , 8 , 1920 , 128 , 16 , 3 , 128 , 16 , 3 },
200203 {24000000 , 16000 , 2 , 8 , 1920 , 128 , 24 , 2 , 128 , 24 , 2 },
201204 {25000000 , 16000 , 2 , 7 , 8643 , 128 , 24 , 2 , 128 , 24 , 2 },
202205 /* 22.05k rate */
203206 {12000000 , 22050 , 1 , 7 , 5264 , 128 , 16 , 2 , 128 , 16 , 2 },
207+ {12000000 , 22050 , 1 , 8 , 4672 , 128 , 12 , 3 , 128 , 12 , 3 },
204208 {24000000 , 22050 , 2 , 7 , 5264 , 128 , 16 , 2 , 128 , 16 , 2 },
205209 {25000000 , 22050 , 2 , 7 , 2253 , 128 , 16 , 2 , 128 , 16 , 2 },
206210 /* 32k rate */
207211 {12000000 , 32000 , 1 , 8 , 1920 , 128 , 12 , 2 , 128 , 12 , 2 },
212+ {12000000 , 32000 , 1 , 8 , 1920 , 128 , 8 , 3 , 128 , 8 , 3 },
208213 {24000000 , 32000 , 2 , 8 , 1920 , 128 , 12 , 2 , 128 , 12 , 2 },
209214 {25000000 , 32000 , 2 , 7 , 8643 , 128 , 12 , 2 , 128 , 12 , 2 },
210215 /* 44.1k rate */
211216 {12000000 , 44100 , 1 , 7 , 5264 , 128 , 8 , 2 , 128 , 8 , 2 },
217+ {12000000 , 44100 , 1 , 8 , 4672 , 128 , 6 , 3 , 128 , 6 , 3 },
212218 {24000000 , 44100 , 2 , 7 , 5264 , 128 , 8 , 2 , 128 , 8 , 2 },
213219 {25000000 , 44100 , 2 , 7 , 2253 , 128 , 8 , 2 , 128 , 8 , 2 },
214220 /* 48k rate */
215221 {12000000 , 48000 , 1 , 8 , 1920 , 128 , 8 , 2 , 128 , 8 , 2 },
222+ {12000000 , 48000 , 1 , 7 , 6800 , 96 , 5 , 4 , 96 , 5 , 4 },
216223 {24000000 , 48000 , 2 , 8 , 1920 , 128 , 8 , 2 , 128 , 8 , 2 },
217224 {25000000 , 48000 , 2 , 7 , 8643 , 128 , 8 , 2 , 128 , 8 , 2 },
218225 /* 88.2k rate */
219226 {12000000 , 88200 , 1 , 7 , 5264 , 64 , 8 , 2 , 64 , 8 , 2 },
227+ {12000000 , 88200 , 1 , 8 , 4672 , 64 , 6 , 3 , 64 , 6 , 3 },
220228 {24000000 , 88200 , 2 , 7 , 5264 , 64 , 8 , 2 , 64 , 8 , 2 },
221229 {25000000 , 88200 , 2 , 7 , 2253 , 64 , 8 , 2 , 64 , 8 , 2 },
222230 /* 96k rate */
223231 {12000000 , 96000 , 1 , 8 , 1920 , 64 , 8 , 2 , 64 , 8 , 2 },
232+ {12000000 , 96000 , 1 , 7 , 6800 , 48 , 5 , 4 , 48 , 5 , 4 },
224233 {24000000 , 96000 , 2 , 8 , 1920 , 64 , 8 , 2 , 64 , 8 , 2 },
225234 {25000000 , 96000 , 2 , 7 , 8643 , 64 , 8 , 2 , 64 , 8 , 2 },
226235 /* 176.4k rate */
227236 {12000000 , 176400 , 1 , 7 , 5264 , 32 , 8 , 2 , 32 , 8 , 2 },
237+ {12000000 , 176400 , 1 , 8 , 4672 , 32 , 6 , 3 , 32 , 6 , 3 },
228238 {24000000 , 176400 , 2 , 7 , 5264 , 32 , 8 , 2 , 32 , 8 , 2 },
229239 {25000000 , 176400 , 2 , 7 , 2253 , 32 , 8 , 2 , 32 , 8 , 2 },
230240 /* 192k rate */
231241 {12000000 , 192000 , 1 , 8 , 1920 , 32 , 8 , 2 , 32 , 8 , 2 },
242+ {12000000 , 192000 , 1 , 7 , 6800 , 24 , 5 , 4 , 24 , 5 , 4 },
232243 {24000000 , 192000 , 2 , 8 , 1920 , 32 , 8 , 2 , 32 , 8 , 2 },
233244 {25000000 , 192000 , 2 , 7 , 8643 , 32 , 8 , 2 , 32 , 8 , 2 },
234245};
@@ -680,7 +691,9 @@ static int aic31xx_setup_pll(struct snd_soc_codec *codec,
680691 struct snd_pcm_hw_params * params )
681692{
682693 struct aic31xx_priv * aic31xx = snd_soc_codec_get_drvdata (codec );
694+ int bclk_score = snd_soc_params_to_frame_size (params );
683695 int bclk_n = 0 ;
696+ int match = -1 ;
684697 int i ;
685698
686699 /* Use PLL as CODEC_CLKIN and DAC_CLK as BDIV_CLKIN */
@@ -691,15 +704,37 @@ static int aic31xx_setup_pll(struct snd_soc_codec *codec,
691704
692705 for (i = 0 ; i < ARRAY_SIZE (aic31xx_divs ); i ++ ) {
693706 if (aic31xx_divs [i ].rate == params_rate (params ) &&
694- aic31xx_divs [i ].mclk == aic31xx -> sysclk )
695- break ;
707+ aic31xx_divs [i ].mclk == aic31xx -> sysclk ) {
708+ int s = (aic31xx_divs [i ].dosr * aic31xx_divs [i ].mdac ) %
709+ snd_soc_params_to_frame_size (params );
710+ int bn = (aic31xx_divs [i ].dosr * aic31xx_divs [i ].mdac ) /
711+ snd_soc_params_to_frame_size (params );
712+ if (s < bclk_score && bn > 0 ) {
713+ match = i ;
714+ bclk_n = bn ;
715+ bclk_score = s ;
716+ }
717+ }
696718 }
697719
698- if (i == ARRAY_SIZE (aic31xx_divs )) {
699- dev_err (codec -> dev , "%s: Sampling rate %u not supported\n" ,
720+ if (match == -1 ) {
721+ dev_err (codec -> dev ,
722+ "%s: Sample rate (%u) and format not supported\n" ,
700723 __func__ , params_rate (params ));
724+ /* See bellow for details how fix this. */
701725 return - EINVAL ;
702726 }
727+ if (bclk_score != 0 ) {
728+ dev_warn (codec -> dev , "Can not produce exact bitclock" );
729+ /* This is fine if using dsp format, but if using i2s
730+ there may be trouble. To fix the issue edit the
731+ aic31xx_divs table for your mclk and sample
732+ rate. Details can be found from:
733+ http://www.ti.com/lit/ds/symlink/tlv320aic3100.pdf
734+ Section: 5.6 CLOCK Generation and PLL
735+ */
736+ }
737+ i = match ;
703738
704739 /* PLL configuration */
705740 snd_soc_update_bits (codec , AIC31XX_PLLPR , AIC31XX_PLL_MASK ,
@@ -729,14 +764,6 @@ static int aic31xx_setup_pll(struct snd_soc_codec *codec,
729764 snd_soc_write (codec , AIC31XX_AOSR , aic31xx_divs [i ].aosr );
730765
731766 /* Bit clock divider configuration. */
732- bclk_n = (aic31xx_divs [i ].dosr * aic31xx_divs [i ].mdac )
733- / snd_soc_params_to_frame_size (params );
734- if (bclk_n == 0 ) {
735- dev_err (codec -> dev , "%s: Not enough BLCK bandwidth\n" ,
736- __func__ );
737- return - EINVAL ;
738- }
739-
740767 snd_soc_update_bits (codec , AIC31XX_BCLKN ,
741768 AIC31XX_PLL_MASK , bclk_n );
742769
0 commit comments