WM8960驱动的移植记录

转载地址:http://blog.chinaunix.net/uid-22950545-id-2600582.html

一,前言:WM8960是一个音频CODEC,与CPU通过I2S进行数据传输,CPU通过I2CWM8960进行控制。

Kernel:linux- 2.6.28.10 +TCC8900平台

二,实现I2C控制接口,在drivers/i2c/chips下加一个i2c驱动。Tcc_wm8960.c

#include

#include

#include

#include <linux i2c.h>

 

#define WM8960_SLAVE_ADDR  0x1a

static 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有联系的地方改一下。关于声卡驱动的架构以后有空再写一篇分析出来。

五,修改一下相应目录下的KconfigMakefile

六,测试结果如下:

/nand2/mplayer # ./mplayer-y justonelastdance.mp3

MPlayer SVN-r4-4.3.2 (C) 2000-2009 MPlayer Team

 

Playing justonelastdance.mp3.

Audio only file format detected.

Clip info:

 Title: Just One Last Dance

 Artist: Sarah Connor

 Album: Key To My Soul

 Year: 2003

 Comment: http://www.joyui.com       

 Track: 3

 Genre: Pop

==========================================================================

Opening audio decoder: [mp3lib] MPEG layer-2, layer-3

AUDIO: 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 address

alsa-init: requested format: 44100 Hz, 2 channels, 9

alsa-init: using ALSA 1.0.15

soc_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 video

Starting playback...

A:   8.3 (08.2) of 268.0 (04:28.0) 10.4%                                       

 

MPlayer interrupted by signal 2 in module: play_audio

A:   8.4 (08.4) of 268.0 (04:28.0) 10.4%

 

动人的声音就出来了。

阅读更多
个人分类: kernel-driver-alsa
上一篇linux驱动开发: wm8960 codec代码分析
下一篇ALSA交叉编译
想对作者说点什么? 我来说一句

wm8960音频解码芯片驱动移植记录

2014年07月01日 955KB 下载

没有更多推荐了,返回首页

关闭
关闭