I.MX6ULL 带有 SAI接口,正点原子的 I.MX6ULL ALPHA 开发板通过此接口外接了一个 WM8960 音频 DAC 芯片,本实验我们就来学习一下如何使能 WM8960 驱动,并且通过 WM8960 芯片来完成音乐播放与录音。音频的驱动框架在这里不进行分析。
一、修改设备树
WM8960 与 I.MX6ULL 之间有两个通信接口:I2C 和
SAI,因此设备树中会涉及到 I2C 和 SAI 两个设备节点。其中 I2C 用于配置 WM8960,SAI接口用于音频数据传输
1、wm8960 i2c 接口设备树
codec: wm8960@1a {
compatible = "wlf,wm8960";
reg = <0x1a>;
clocks = <&clks IMX6UL_CLK_SAI2>;
clock-names = "mclk";
wlf,shared-lrclk;
};
2、I.MX6ULL SAI 音频接口设备树
&sai2 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_sai2
&pinctrl_sai2_hp_det_b>;
assigned-clocks = <&clks IMX6UL_CLK_SAI2_SEL>,
<&clks IMX6UL_CLK_SAI2>;
assigned-clock-parents = <&clks IMX6UL_CLK_PLL4_AUDIO_DIV>;
assigned-clock-rates = <0>, <12288000>;
status = "okay";
};
3、I.MX6ULL sound 节点
sound {
compatible = "fsl,imx6ul-evk-wm8960",
"fsl,imx-audio-wm8960";
model = "wm8960-audio";
cpu-dai = <&sai2>;
audio-codec = <&codec>;
asrc-controller = <&asrc>;
codec-master;
gpr = <&gpr 4 0x100000 0x100000>;
/*
11 * hp-det = <hp-det-pin hp-det-polarity>;
12 * hp-det-pin: JD1 JD2 or JD3
13 * hp-det-polarity = 0: hp detect high for headphone
14 * hp-det-polarity = 1: hp detect high for speaker
15 */
hp-det = <3 0>;
/*hp-det-gpios = <&gpio5 4 0>;
mic-det-gpios = <&gpio5 4 0>;*/
audio-routing =
"Headphone Jack", "HP_L",
"Headphone Jack", "HP_R",
"Ext Spk", "SPK_LP",
"Ext Spk", "SPK_LN",
"Ext Spk", "SPK_RP",
"Ext Spk", "SPK_RN",
"LINPUT2", "Mic Jack",
"LINPUT3", "Mic Jack",
"RINPUT1", "Main MIC",
"RINPUT2", "Main MIC",
"Mic Jack", "MICB",
"Main MIC", "MICB",
"CPU-Playback", "ASRC-Playback",
"Playback", "CPU-Playback",
"ASRC-Capture", "CPU-Capture",
"CPU-Capture", "Capture";
};
二、使能内核的 WM8960 驱动
1、打开Linux内核图形化配置界面
Make menuconfig
2、取消 ALSA 模拟 OSS API
-> Device Drivers
-> Sound card support (SOUND [=y])
-> Advanced Linux Sound Architecture (SND [=y])
-> <> OSS Mixer API //不选择
-> <> OSS PCM (digital audio) API //不选择
3、使能 I.MX6ULL 的 WM8960 驱动
-> Device Drivers
-> Sound card support (SOUND [=y])
-> Advanced Linux Sound Architecture (SND [=y])
-> ALSA for SoC audio support (SND_SOC [=y])
-> SoC Audio for Freescale CPUs
-> <*> Asynchronous Sample Rate Converter (ASRC) module support
//选中
-> <*> SoC Audio support for i.MX boards with wm8960
//选中
三、alsa-lib 和 alsa-utils 移植
alsa-lib 和 alsa-utils的移植与配置详细见音频驱动实验。
四、amixer 使用方法
1、声卡设置与测试
amixer --help //查看 amixer 帮助信息
amixer scontrols //查看所有设置项
amixer scontents //查看设置值
amixer sset 设置项目 设置值 //设置声卡
amixer sget 设置项目 //获取声卡设置值
2、第一次使用声卡之前一定要先使用 amixer 设置声卡,打开耳机和喇叭,并且设置喇叭和耳
机音量,输入如下命令:
amixer sset Headphone 100,100
amixer sset Speaker 120,120
amixer sset 'Right Output Mixer PCM' on //打开右声道
amixer sset 'Left Output Mixer PCM' on //打开左声道
3、播放音乐
aplay test.wav //播放歌曲