大家好,最近调试在dm8168平台下调试tlv320aic3101这个芯片,开发包是DVRRDK_04.00.00.03
这个芯片的MCLK脚是27MHZ晶振提供的,一开始没注意到这个数值,发现有些情况的噪声无法很好去掉。
后面发现内核里面默认用24.576MHZ的频率,于是乎我修改内核代码中的这个文件:sound/soc/davinci/ti81xx-evm.c
diff --git a/sound/soc/davinci/ti81xx-evm.c b/sound/soc/davinci/ti81xx-evm.c index 4afed1d..88809f5 100755 --- a/sound/soc/davinci/ti81xx-evm.c +++ b/sound/soc/davinci/ti81xx-evm.c @@ -40,9 +40,10 @@ static int ti81xx_evm_hw_params(struct snd_pcm_substream *substream,struct snd_soc_dai *codec_dai = rtd->codec_dai;struct snd_soc_dai *cpu_dai = rtd->cpu_dai;unsigned sysclk, fmt = 0; +printk("==================In ti81xx_evm_hw_params\n");/* default */ -sysclk = 24576000; +sysclk = 27000000;if (!strcmp(rtd->dai_link->name, "TVP5158AUDIO")) {/* AFSR -> falling edge, ACLKX -> rising edge, 1 bitclock delay
修改后,发现声音听起来,间隔性的断,并且失真。
然后我怀疑是mcasp相关的驱动也需要修改?求指导?
Chris Meng:
你好,
DM81xx的音频驱动,应该都是外部codec做主(发送时钟和帧同步信号)。如果MCLK发生变化,应该是audio codec的配置需要修改,建议你看看AIC310的手册和相关代码。
大白他弟:
回复 Chris Meng:
你好,我修改了根据tlv320aic3101数据手册根据外部晶振提供给MCLK脚的时钟,计算WCLK等
#define AUDIO_24576_44100 0#define AUDIO_27000_44100 1#define AIC31XX_P 0#define AIC31XX_J 1#define AIC31XX_D_8MSB 2#define AIC31XX_D_6LSB 3#define AIC31XX_R 4#define AIC31XX_NCODEC 5static unsigned char SampleRate[2][6]={{0x91,0x0c,0x69,0x78,0x01,0x00}, /*24.576MHz,44100Hz*/{0x91,0x0c,0x35,0xec,0x01,0x00} /*27MHz,44100Hz*/};static int tlv320aic3xx_clk_setting( int sample_rate_index){//外部晶振是27MHZ,采样率要求时44.1KHZAI31XX_I2C_WRITE(3,SampleRate[sample_rate_index][AIC31XX_P]);//pll enable,P=1AI31XX_I2C_WRITE(4,SampleRate[sample_rate_index][AIC31XX_J]);//J=3//0b01101001 011110 00 = 6750AI31XX_I2C_WRITE(5,SampleRate[sample_rate_index][AIC31XX_D_8MSB]);//MSB 8 of DAI31XX_I2C_WRITE(6,SampleRate[sample_rate_index][AIC31XX_D_6LSB]);//LSB 6 of DAI31XX_I2C_WRITE(11,SampleRate[sample_rate_index][AIC31XX_R]);//R=1AI31XX_I2C_WRITE(7,0x8a);//L2L,R2R,与截图中的保持一致AI31XX_I2C_WRITE(101,0x00);//CODEC_CLKIN uses PLLDIV_OUTAI31XX_I2C_WRITE(102,0x02);//CLKDIV_IN uses MCLK;PLLCLK_IN uses MCLKAI31XX_I2C_WRITE(2,SampleRate[sample_rate_index][AIC31XX_NCODEC]);//adc and dac sample rate equal to f = 44100return 0;}//调用tlv320aic3xx_clk_setting(AUDIO_24576_44100);如我帖子所示,如果sysclk设置为24.576MHZ的话,声音听起来是连续的,如果改为27MHZ则声音则是间隔性的断,这边3101驱动该对应Pll也不行
AUDIO_27000_44100采样率要求是44100
Chris Meng:
回复 大白他弟:
你好,
下面是AIC3101手册上配置采样率的要求:
fS(ref) = (PLLCLK_IN × K × R)/(2048 × P),P = 1, 2, 3,…, 8R = 1, 2, …, 16K = J.DJ = 1, 2, 3, …, 63D = 0000, 0001, 0002, 0003, …, 9998, 9999PLLCLK_IN can be MCLK or BCLK, selected by Page 0, register 102, bits D5–D4When the PLL is enabled and D = 0000, the following conditions must be satisfied to meet specifiedperformance:2 MHz ≤ ( PLLCLK_IN/P ) ≤ 20 MHz80 MHz ≤ (PLLCLK _IN × K × R/P ) ≤ 110 MHz4 ≤ J ≤ 55When the PLL is enabled and D≠0000, the following conditions must be satisfied to meet specified performance:10 MHz ≤ PLLCLK _IN/P ≤ 20 MHz80 MHz ≤ PLLCLK _IN × K × R/P ≤ 110 MHz4 ≤ J ≤ 11R = 1
我根据上的要求以及输入MCLK是27Mhz,得到了下面的参数,请问你也是类似的配置么?
0.0441=27*10.0352/(2048*3)K=10.0352, J=10, D=352, P=3, R=1 ( PLL is enabled and D = 0000)
2 MHz ≤ ( PLLCLK_IN/P ) =9Mhz≤ 20 MHz80 MHz ≤ (PLLCLK _IN × K × R/P )=90.3168 ≤ 110 MHz4 ≤ J=10 ≤ 55
大白他弟:
回复 Chris Meng:
非常感谢你的提醒,我在计算这些参数的时候忽略了这些条件,我再试下效果。
Chris Meng:
回复 大白他弟:
你好,
如果你测试成功,请在帖子里面更新一下信息,谢谢!
大白他弟:
回复 Chris Meng:
我调整了,晶振为24.576MHZ的情况,从原来的R=1,P=1,J=3,D=6750调整为R=1 P=2 J=7 和D3500,这两组数据都能得到44100的采样率,不过后者符合数据手册中的限制条件。
(24576000*3.675*1)/(2048*1) = 44100
(24576000*7.35*1)/(2048*2) = 44100
修改完之后,发现效果一样,这个我在用专业仪器测试试下。
但是27MHZ的修改完之后,依旧会间隔一小段时间断一下,然后我发现我错了
你好,我搞错了。
我们的原理图中tlv320aic3101的MCLK脚并非由外部晶振提供(虽然画了一个27MHZ晶振但是没接),而是由8168的AN36脚提供,该脚功能是:MCA2_AHCLKX/MCB_CLKR。
这样的话,我如何确定MCLK的值是多大呢?
Chris Meng:
回复 大白他弟:
你好,
默认驱动应该是让audio codec配置为master 模式输出时钟和同步信号。你有修改代码让mcasp来输出时钟和同步信号了?
建议你阅读一下DM8168 MCASP相关章节,了解你现在配置mcasp内部时钟参数输出给audio codec的时钟是多少。
In the internal/mixed cases, the bit rate clock is generated internally and should be driven out on theACLKX (for transmit) or ACLKR (for receive) pins. In the internal case, an internally-generated highfrequencyclock may be driven out onto the AHCLKX or AHCLKR pins to serve as a reference clock forother components in the system.
大白他弟:
回复 Chris Meng:
你好我确认了我们板子的给8168的晶振大小是27MHZ,然后查看TI81XX_PSP_PM_CLOCK_FRAMEWORK_User_Guide文档。
最后,通过在文件系统里面得到mcasp2的auxclk大小,也就是
mount -t debugfs debugfs /sys/kernel/debug
cd /sys/kernel/debug/clock/sys_clkin_ck/main_pll_clk7_ck/audio_pll_clk3_ck/sysclk20_ck/mcasp2_fck
cat rate
得到24576000的大小。
然后查看mcasp2寄存器
mem_rdwr.out –rd 480500b4 1
得到
0x480500b4: 00008000
也就是AHCLKX时钟Internal transmit high-frequency clock source from output of programmable high clock divider
并且divide AUXCLK的系数是1,与AUXCLK的大小一致。
希望以上对大家有帮助。