Linux 音频驱动

Linux 音频驱动

硬件介绍

WM8960与IMX6ULL之间有两个通信接口:I2C和I2S
其中I2C用于配置WM8960
I2S用于音频数据传输

修改设备树文件

编写I2C子节点设备树

codec: wm8960@1a { 
	compatible = "wlf,wm8960";
	reg = <0x1a>;
	clocks = <&clks IMX6UL_CLK_SAI2>;
	clock-names = "mclk"; 6 wlf,shared-lrclk; 
};

编写I2S子节点设备树

sai2: sai@0202c000 { 
	compatible = "fsl,imx6ul-sai", 
	"fsl,imx6sx-sai"; 
	reg = <0x0202c000 0x4000>;
	interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&clks IMX6UL_CLK_SAI2_IPG>,
	<&clks IMX6UL_CLK_DUMMY>,
	<&clks IMX6UL_CLK_SAI2>,
	<&clks 0>, <&clks 0>;
	clock-names = "bus", "mclk0", "mclk1", "mclk2", "mclk3";
	dma-names = "rx", "tx";
	dmas = <&sdma 37 24 0>, <&sdma 38 24 0>;
	status = "disabled";
};

&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";
};

pinctrl_sai2: sai2grp { 
	fsl,pins = < 
		MX6UL_PAD_JTAG_TDI__SAI2_TX_BCLK 0x17088
		MX6UL_PAD_JTAG_TDO__SAI2_TX_SYNC 0x17088
		MX6UL_PAD_JTAG_TRST_B__SAI2_TX_DATA 0x11088
		MX6UL_PAD_JTAG_TCK__SAI2_RX_DATA 0x11088
		MX6UL_PAD_JTAG_TMS__SAI2_MCLK 0x17088
	>;
};

pinctrl_sai2_hp_det_b: sai2_hp_det_grp {
	fsl,pins = <
		MX6ULL_PAD_SNVS_TAMPER4__GPIO5_IO04 0x17059
	>;
};

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>;
	/*
	* hp-det = ;
	* hp-det-pin: JD1 JD2 or JD3
	* hp-det-polarity = 0: hp detect high for headphone
	* hp-det-polarity = 1: hp detect high for speaker
	*/
	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";
};

配置Linux图形化文件

取消ALSA模拟OSS API

-> Device Drivers 
	-> Sound card support (SOUND [=y]) 
		-> Advanced Linux Sound Architecture (SND [=y]) 
			-> <> OSS Mixer API //不选择
			-> <> OSS PCM (digital audio) API //不选择

使能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文件

1.获取源文件

alsa-lib-1.2.2.tar.bz2 
alsa-utils-1.2.2.tar.bz2

2.解压文件

tar -vxjf alsa-lib-1.2.2.tar.bz2
tar -vxjf alsa-utils-1.2.2.tar.bz2

3.配置文件

//进入 alsa-lib 源码目录
cd alsa-lib-1.2.2/ 
./configure 
--host=arm-linux-gnueabihf 
--prefix=/home/zuozhongkai/linux/IMX6ULL/tool/alsa-lib 
--with-configdir=/usr/share/arm-alsa

//进入 alsa-utils源码目录
cd alsa-utils-1.2.2/ 
./configure 
--host=arm-linux-gnueabihf 
--prefix=/home/zuozhongkai/linux/IMX6ULL/tool/alsa-utils 
--with-alsa-inc-prefix=/home/zuozhongkai/linux/IMX6ULL/tool/alsa-lib/include/ 
--with-alsaprefix=/home/zuozhongkai/linux/IMX6ULL/tool/alsa-lib/lib/ 
--disable-alsamixer 
--disable-xmlto

4.编译文件

make

5.安装文件

sudo make install

6.移植文件

移植alsa-lib文件
cd alsa-lib //进入 alsa-lib
sudo cp lib/* /home/zuozhongkai/linux/nfs/rootfs/lib/ -af
cd /usr/share/arm-alsa //进入 arm-alsa 目录,拷贝配置文件
sudo cp * /home/zuozhongkai/linux/nfs/rootfs/usr/share/arm-alsa/ -raf

移植alsa-utils文件
cd alsa-utils
sudo cp bin/* /home/zuozhongkai/linux/nfs/rootfs/bin/ -rfa
sudo cp sbin/* /home/zuozhongkai/linux/nfs/rootfs/sbin/ -rfa
sudo cp share/* /home/zuozhongkai/linux/nfs/rootfs/usr/share/ -rfa
在开发板根目录/etc/profile添加内容
export ALSA_CONFIG_PATH=/usr/share/arm-alsa/alsa.conf

移植zlib库和mplayer

1.获取源文件

zlib-1.2.11.tar.gz
MPlayer-1.4.tar.gz

2.解压文件

tar -vxzf zlib-1.2.11.tar.gz
tar -vxzf MPlayer-1.4.tar.gz

3.配置文件

cd zlib-1.2.11/ //进去 zlib 源码
CC=arm-linux-gnueabihf-gcc 
LD=arm-linux-gnueabihf-ld 
AD=arm-linux-gnueabihf-as 
./configure 
--prefix=/home/zuozhongkai/linux/IMX6ULL/tool/zlib

cd MPlayer-1.4/ //进去 mplayer 源码
./configure 
--cc=arm-linux-gnueabihf-gcc 
--host-cc=gcc 
--target=arm-linux-gnueabihf 
--disable-ossaudio 
--enable-alsa 
--prefix=/home/zuozhongkai/linux/IMX6ULL/tool/mplayer 
--extra-cflags=
"-I /home/zuozhongkai/linux/IMX6ULL/tool/zlib/include -I /home/zuozhongkai/linux/IMX6ULL/tool/alsa-lib/include"
 --extra-ldflags=
 "-L/home/zuozhongkai/linux/IMX6ULL/tool/zlib/lib -Iz -L/home/zuozhongkai/linux/IMX6ULL/tool/alsa-lib/lib -lasound" 
 --enable-fbdev 
 --disable-mencoder

4.编译文件

make //编译

5.安装文件

make install

6.移植文件

将可执行文件拷贝到跟文件系统/bin目录下
sudo cp lib/* /home/zuozhongkai/linux/nfs/rootfs/lib/ -rfa

你可能感兴趣的:(Linux驱动,linux,音视频,运维)