至于simple-card framework在 kernelDocumenta
tiondevicetreebindingssoundsimple-card.txt有描述
其源码位于 kernel/sound/soc/generic/simple-card.c
下面我们实践操作,驱动alc5651音频芯片
1.设备树配置
rt5651-sound { //machine 匹配层的驱动节点。
status = "okay"; //默认打开
compatible = "simple-audio-card"; //simple-card framework框架
simple-audio-card,format = "i2s";
simple-audio-card,name = "realtek,rt5651-codec";
simple-audio-card,mclk-fs = <256>; //主控供给编解码芯片用的时钟
simple-audio-card,widgets = //指定相关组件
"Microphone", "Mic Jack", //mic
"Headphone", "Headphone Jack"; //耳机
simple-audio-card,routing = //音频路径,如mic输入、耳机输出走那些通路。
"Mic Jack", "MICBIAS1",
"IN1P", "Mic Jack",
"Headphone Jack", "HPOL",
"Headphone Jack", "HPOR";
simple-audio-card,cpu {
sound-dai = <&i2s0>; //指定cpu接入音频编解码的dai(数字化接口)
};
simple-audio-card,codec {
sound-dai = <&rt5651>; //指定编解码音频接入cpu的dai(数字化接口)
};
};
rt5651: rt5651
@1a {
#sound-dai-cells = <0>;
compatible = "rockchip,rt5651";
reg = <0x1a>;
clocks = <&cru SCLK_I2S_8CH_OUT>;
clock-names = "mclk";
pinctrl-names = "default";
pinctrl-0 = <&i2s_8ch_mclk>;
spk-con-gpio = <&gpio0 11 GPIO_ACTIVE_HIGH>;
hp-det-gpio = <&gpio4 28 GPIO_ACTIVE_LOW>;
};
2.内核配置
CONFIG_SND_SEQUENCER=y
CONFIG_SND_SEQ_DUMMY=y
CONFIG_SND_HRTIMER=y
CONFIG_SND_DYNAMIC_MINORS=y
CONFIG_SND_SOC=y
CONFIG_SND_SOC_ROCKCHIP=y
CONFIG_SND_SOC_ROCKCHIP_I2S=y
CONFIG_SND_SOC_RT5651=y //对应于 rt5651.c
CONFIG_SND_SIMPLE_CARD=y //对应于simple-card.c
3.编译并烧写内核
确认下声卡是否注册成功
#cat /proc/asound/cards
0 [realtekrt5651co]: realtek_rt5651- - realtek,rt5651-codec
realtek,rt5651-codec
#ls -l /dev/snd/
drwxr-xr-x 2 root root 60 Jan 18 10:27 by-path
crw-rw---- 1 root audio 116, 2 Jan 18 10:27 controlC0
crw-rw---- 1 root audio 116, 4 Jan 18 10:27 pcmC0D0c
crw-rw---- 1 root audio 116, 3 Jan 18 10:27 pcmC0D0p
crw-rw---- 1 root audio 116, 1 Jan 18 10:27 seq
crw-rw---- 1 root audio 116, 33 Jan 18 10:27 timer
通过命令行播放一个wav文件
#aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: realtekrt5651co [realtek,rt5651-codec], device 0: ff880000.i2s-rt5651-aif1 rt5651-aif1-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
#aplay file.wav -Dplug:default
Playing WAVE 'file.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
推荐一个Android下一个好用的app"文字装语音",通过它可以将文字生成wav语音放到板子上播放,
用aplay播放wav音频文件时,它会读取wav音频文件的文件头信息来确定pcm格式、采样率、通道数。
一般来说,配置设备树、编译驱动声卡就能起来了(不需要改代码)。
如果读者的驱动没有起来的话,确定三点
1.音频芯片对应的驱动是否参加编译
2.音频芯片对应的设备树节点是否正确并状态为okay、驱动的probe函数是否执行(建议在板端/sys/firmware/devicetree/base/查找你的节点)
3.驱动的控制信号-i2c信号是否正确。
如果实在不行就只能看官方提供的音频硬件威廉希尔官方网站
图、数据手册。看是否是卡在开机时许、威廉希尔官方网站
走线上。
原作者:jin-fa