为了实现mp3播放,我们最近在sep4020上完成了i2s的驱动,主要经验总结如下:
1. 首先是要在probe函数里进行一系列的初始化,这些初始化对于i2s是很重要的,而且很多
● 配置操作codec的L3的gpio口线;
L3接口相对于一个混音器控制接口,也就是对应在驱动中的mixer结构体,在这里我们需要利用3根gpio口线实现对L3的控制,以下是初始化代码:
*(volatile unsigned long*)(GPIO_PORTD_DIR_V) &= ~(0xd<<1); //GPB[4:1]=00_0 Output(L3CLOCK):Output(L3DATA):Output(L3MODE)
*(volatile unsigned long*)(GPIO_PORTD_SEL_V) |= (0xd<<1);
//GPD[4:1] 1 1010
● 配置端口为放音功能,因为sep4020只支持单独放音和录音,不能全双工,因此我们在这里配置为放音,是通过一个口线置高置低实现的,具体代码:
*(volatile unsigned long*)(GPIO_PORTG_DIR_V) &= ~(0x1<<11);
*(volatile unsigned long*)(GPIO_PORTG_SEL_V) |= 0x1<<11;
*(volatile unsigned long*)(GPIO_PORTG_DATA_V) |= 0x1<<11;
● 配置pwm,实现对codec时钟的供给:
*(volatile unsigned long*)PWM4_CTRL_V =0x00;
*(volatile unsigned long*)PWM4_DIV_V =0x4; //88MHz/(4*2)=11Mhz 11M/256fs=42.96k
*(volatile unsigned long*)PWM4_PERIOD_V =0x2; //计数时钟为总线的DIV分频
*(volatile unsigned long*)PWM4_DATA_V =0x1; //周期为两个计数时钟
*(volatile unsigned long*)PWM_ENABLE_V =0x1<<3; //高电平为一个计数时钟
● 初始化codec(UDA1341),实际这一步是和第一步配置控制L3口线一起的,配置好口线后,通过这些口线将codec的参数配置好,当然具体codec的参数要看uda1341的手册,其中的uda1341_l3_address,uda1341_l3_data是单独为其编写的函数:
*(volatile unsigned long*)(GPIO_PORTD_DATA_V) &= ~(L3M|L3C|L3D);
*(volatile unsigned long*)(GPIO_PORTD_DATA_V) |= (L3M|L3C); //Start condition : L3M=H, L3C=H
//以下配置可能需要修改 marked at 11-08
uda1341_l3_address(0x14 + 2);
uda1341_l3_data(0x61); //1110 dc-filtering开不开无所谓 不能像三星的选成MSB
uda1341_l3_address(0x14 + 2);
uda1341_l3_data(0x21);
uda1341_l3_address(0x14 + 2);
uda1341_l3_data(0xc1); //Status 1,Gain of DAC 6 dB,Gain of ADC 0dB,ADC non-inverting,DAC non-inverting,Single speed playback,ADC-Off DAC-On
uda1341_l3_address(0x14 + 0);
uda1341_l3_data(0x0f); //00,00 ffff : Volume control (6 bits) -14dB
uda1341_l3_address(0x14 + 0);
uda1341_l3_data(0x7b); //01,11 10,11 : Data0, Bass Boost 18~24dB, Treble 6dB
uda1341_l3_address(0x14 + 0);
uda1341_l3_data(0x83);
● 配置dma,主要实现了对dma通道的使能,清除中断标志位,具体对dma的缓冲区分配等会在使用dma之前的一个dmasetup函数中实现,并且有对应的dmaclear清除缓冲区。
2. 音频驱动的audio结构体,和mixer结构体
在音频驱动中主要就是实现这两个结构体的operation函数:
static struct file_operations sep4020_audio_fops = {
llseek: sep4020_audio_llseek,
write: sep4020_audio_write,
read: sep4020_audio_read,
poll: sep4020_audio_poll,
ioctl: sep4020_audio_ioctl,
open: sep4020_audio_open,
release: sep4020_audio_release
};
static struct file_operations sep4020_mixer_fops = {
ioctl: sep4020_mixer_ioctl,
open: sep4020_mixer_open,
release: sep4020_mixer_release
};