最新由于项目需要,调试S5PV210开发板 Linux系统上面的音频功能,我们选择的音频编解码芯片是WM8960,连接到CPU的IIS接口,调试过 程中遇到了一系列的问题,现总结如下:
调试WM8960使之能播放音频,时钟的配置是很重要的一部分,首先我们需要确定时钟的配置是否正确。Linux启动以后,使用示波器测量 IIS的三个时钟CDClock(Codec Clock ),SClock(串行时钟),LRClock(左右声道选择时钟),发现这三个时钟未按着SPV210的Datasheet中音频子系统中描述的那样工作,正常工作后,三个时钟应该是(CDClock ~= 11.2MHZ, SClock ~= 1.41MHz, LRClock ~= 44KHZ ), 所以我用了一整天的时间来研究音频子系统中时钟的配置,下面的图片是SPV210
Datasheet中 音频子系统与IIS时钟配置重要说明:
首先我们要读懂上面图中时钟的路由,知道音频子系统部分的时钟源选择,我们选择的是EPLL,然后进行分频,分频后的时钟作为时钟源进入到IIS子系统,进入IIS子系统后,我们选择I2SCLK作为 IIS模块的时钟源,然后经过分频可以得到 Root时钟(RCLK),也就是Codec时钟(CodecClock),Root时钟再分频可以得到 BCLK,也就是位时钟也可以称为串行时钟(SClock). IIS 接口root时钟与LRClock时钟之间的关系如下图:
RFS( root 时钟)为256fs = 256*44.1KHz=11.2896 Mhz
另外:
模式寄存器中 BFS 和 RFS关键配置我们采用了默认值, Bit Clock=32 fs, Root clock=256 fs,这里的fs=44.1 MHZ 也就是Codec的采用频率,可以根据WM8960的Datasheet查到,从上面的时钟计算关系图中我们知道fs就是 LRCLK,左右声道选择时钟.
------------------------------------------ 下文转载与:http://sparklecliz.cublog.cn/------------------------------------------
一,前言:WM8960是一个音频CODEC,与CPU通过I2S进行数据传输,CPU通过I2C对WM8960进行控制。Kernel:linux- 2.6.28.10 +TCC8900平台二,实现I2C控制接口,在drivers/i2c/chips下加一个i2c驱动。Tcc_wm8960.c#include #include #include #include 2c.h>#define WM8960_SLAVE_ADDR 0x1astatic unsigned short probe_i2c[] = {0, WM8960_SLAVE_ADDR, I2C_CLIENT_END}; /* { i2c_num, i2c_addr } */static unsigned short dummy[] = {I2C_CLIENT_END};static struct i2c_client_address_data addr_data = { .normal_i2c = dummy, .probe = probe_i2c, .ignore = dummy,};static struct i2c_driver wm8960_i2c_driver;struct i2c_client *wm8960_i2c_client;EXPORT_SYMBOL(wm8960_i2c_client);static int wm8960_i2c_probe(struct i2c_adapter *adap, int addr, int kind){ struct i2c_client *i2c; i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); if (!i2c) return -ENOMEM; strcpy(i2c->name, "WM8960"); i2c->flags = 0; i2c->addr = addr; i2c->adapter = adap; i2c->driver = &wm8960_i2c_driver; wm8960_i2c_client = i2c; return i2c_attach_client(i2c);}static int wm8960_i2c_detach(struct i2c_client *client){ i2c_detach_client(client); kfree(wm8960_i2c_client); return 0;}static int wm8960_i2c_attach(struct i2c_adapter *adap){ return i2c_probe(adap, &addr_data, wm8960_i2c_probe);}static struct i2c_driver wm8960_i2c_driver = { .driver = { .name = "WM8960", .owner = THIS_MODULE, }, .id = -1, .attach_adapter = wm8960_i2c_attach, .detach_client = wm8960_i2c_detach,};static int __init wm8960_i2c_init(void){ return i2c_add_driver(&wm8960_i2c_driver);}static void __exit wm8960_i2c_exit(void){ i2c_del_driver(&wm8960_i2c_driver);}module_init(wm8960_i2c_init);module_exit(wm8960_i2c_exit);MODULE_AUTHOR("Telechips Inc. SYS4-3 linux@telechips.com");MODULE_DESCRIPTION("WM8960 I2C driver");MODULE_LICENSE("GPL");这个i2c驱动写得很简单,最重要的是导出了wm8960_i2c_client这样一个i2c_client,写wm8960寄存器就是通过这个i2c_client完成的。三,参照sound/soc/codecs目录下的wm8731.c写出一个wm8960.c。四,修改一下sound/soc/tcc/tcc_board.c,主要是与wm8960有联系的地方改一下。关于声卡驱动的架构以后有空再写一篇分析出来。五,修改一下相应目录下的Kconfig和Makefile。六,测试结果如下:/nand2/mplayer # ./mplayer-y justonelastdance.mp3 MPlayer SVN-r4-4.3.2 (C) 2000-2009 MPlayer TeamPlaying justonelastdance.mp3.Audio only file format detected.Clip info:Title: Just One Last DanceArtist: Sarah ConnorAlbum: Key To My SoulYear: 2003Comment: http://www.joyui.com Track: 3Genre: Pop==========================================================================Opening audio decoder: [mp3lib] MPEG layer-2, layer-3AUDIO: 44100 Hz, 2 ch, s16le, 192.0 kbit/13.61% (ratio: 24000->176400)Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)==========================================================================[AO OSS] audio_setup: Can't open audio device /dev/dsp: No such device or addressalsa-init: requested format: 44100 Hz, 2 channels, 9alsa-init: using ALSA 1.0.15soc_pcm_open[AO] device [default], mode [0], return [0]== alsa-debug == totsize=0x10000 period=0x4000 period num=4== alsa-debug == set_dma_outbuffer, addr[0x41040000], len[65536], period[16384]== alsa-debug == [set_dma_outbuffer] HwTxDaParam [0xFFF00004]== alsa-debug == [set_dma_outbuffer] HwTxDaTCnt [1023]====================================== set [2] channels======================================AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)Video: no videoStarting playback...A: 8.3 (08.2) of 268.0 (04:28.0) 10.4% MPlayer interrupted by signal 2 in module: play_audioA: 8.4 (08.4) of 268.0 (04:28.0) 10.4%动人的声音就出来了。