“Linux内核-音频驱动移植”的版本间的差异

来自华清远见研发中心
跳转至: 导航搜索
(创建页面,内容为“==实验原理== ==实验目的== ==实验平台== ==实验步骤==”)
 
实验原理
第1行: 第1行:
 
==实验原理==
 
==实验原理==
 +
FS-MP1A使用的是CS42L51音频芯片,SoC通过I2C和SAI与其进行数据交互,原理图如下:<br>
 +
 +
[[Image:57-1-1-1.png]] <br>
 +
 +
SAI2管脚对应关系:
 +
 +
[[Image:57-1-1-2.png]] <br>
 +
 +
[[Image:57-1-1-3.png]] <br>
 +
 +
[[Image:57-1-1-4.png]] <br>
 +
 +
I2C5管脚对应关系:
 +
 +
[[Image:57-1-1-5.png]] <br>
 +
 +
芯片复位管脚对应关系:
 +
 +
[[Image:57-1-1-6.png]] <br>
 +
 +
{|class="wikitable"
 +
|-
 +
! 原理图网络编号 !! 对应管脚 !! 管脚功能 !! 管脚功能码
 +
|-
 +
| SAI2_MCLKA
 +
| PE0
 +
| SAI2_MCLK_A
 +
| AF10
 +
|-
 +
| SAI2_SDB
 +
| PF11
 +
| SDA2_SD_B
 +
| AF10
 +
|-
 +
| SAI2_SCKA
 +
| PI5
 +
| SAI2_SCK_A
 +
| AF10
 +
|-
 +
| SAI_SDA
 +
| PI6
 +
| SAI2_SD_A
 +
| AF10
 +
|-
 +
| SAI2_FSA
 +
| PI7
 +
| SAI2_FS_A
 +
| AF10
 +
|-
 +
| AUDIO_RST
 +
| PC0
 +
| IO
 +
| ANALOG
 +
|-
 +
| I2C5_SDA
 +
| PA11
 +
| I2C5_SDA
 +
| AF4
 +
|-
 +
| I2C5_SCL
 +
| PA12
 +
| I2C5_SDA
 +
| AF4
 +
|}
 +
*SAI2设备树节点<br>
 +
 +
参考文档:
 +
Documentation/devicetree/bindings/sound/st,stm32-sai.txt
 +
内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见:
 +
<pre><nowiki>
 +
sai2: sai@4400b000 {
 +
compatible = "st,stm32h7-sai";
 +
#address-cells = <1>;
 +
#size-cells = <1>;
 +
ranges = <0 0x4400b000 0x400>;
 +
reg = <0x4400b000 0x4>, <0x4400b3f0 0x10>;
 +
interrupts = <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>;
 +
resets = <&rcc SAI2_R>;
 +
status = "disabled";
 +
 +
sai2a: audio-controller@4400b004 {
 +
#sound-dai-cells = <0>;
 +
compatible = "st,stm32-sai-sub-a";
 +
reg = <0x4 0x1c>;
 +
clocks = <&rcc SAI2_K>;
 +
clock-names = "sai_ck";
 +
dmas = <&dmamux1 89 0x400 0x01>;
 +
status = "disabled";
 +
};
 +
 +
sai2b: audio-controller@4400b024 {
 +
#sound-dai-cells = <0>;
 +
compatible = "st,stm32-sai-sub-b";
 +
reg = <0x24 0x1c>;
 +
clocks = <&rcc SAI2_K>;
 +
clock-names = "sai_ck";
 +
dmas = <&dmamux1 90 0x400 0x01>;
 +
status = "disabled";
 +
};
 +
};
 +
</nowiki></pre>
 +
上述代码只对SAI2做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。<br>
 +
 +
参考stm32mp15xx-dkx.dtsi对于SAI2设备节点的描述,增加SAI2内容如下:
 +
<pre><nowiki>
 +
&sai2 {
 +
clocks = <&rcc SAI2>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
 +
clock-names = "pclk", "x8k", "x11k";
 +
pinctrl-names = "default", "sleep";
 +
pinctrl-0 = <&sai2a_pins_a>, <&sai2b_pins_b>;
 +
pinctrl-1 = <&sai2a_sleep_pins_a>, <&sai2b_sleep_pins_b>;
 +
status = "okay";
 +
 +
sai2a: audio-controller@4400b004 {
 +
#clock-cells = <0>;
 +
dma-names = "tx";
 +
clocks = <&rcc SAI2_K>;
 +
clock-names = "sai_ck";
 +
status = "okay";
 +
 +
sai2a_port: port {
 +
sai2a_endpoint: endpoint {
 +
remote-endpoint = <&cs42l51_tx_endpoint>;
 +
format = "i2s";
 +
mclk-fs = <256>;
 +
dai-tdm-slot-num = <2>;
 +
dai-tdm-slot-width = <32>;
 +
};
 +
};
 +
};
 +
 +
sai2b: audio-controller@4400b024 {
 +
dma-names = "rx";
 +
st,sync = <&sai2a 2>;
 +
clocks = <&rcc SAI2_K>, <&sai2a>;
 +
clock-names = "sai_ck", "MCLK";
 +
status = "okay";
 +
 +
sai2b_port: port {
 +
sai2b_endpoint: endpoint {
 +
remote-endpoint = <&cs42l51_rx_endpoint>;
 +
format = "i2s";
 +
mclk-fs = <256>;
 +
dai-tdm-slot-num = <2>;
 +
dai-tdm-slot-width = <32>;
 +
};
 +
};
 +
};
 +
};
 +
</nowiki></pre>
 +
由于stm32mp15-pinctrl.dtsi中对于SAI2管脚的定义与FS-MP1A实际使用管脚一致,所以无需修改。<br>
 +
 +
*CS42L51设备树节点<br>
 +
 +
由于前文中已经增加过I2C5的节点信息,本节就不再重复,在原有I2C5节点添加CS42L51内容即可。<br>
 +
 +
参考文档:
 +
Documentation/devicetree/bindings/sound/cs42l51.txt
 +
参考stm32mp15xx-dkx.dtsi对于codec芯片设备节点的描述,增加内容如下:
 +
<pre><nowiki>
 +
cs42l51: cs42l51@4a {
 +
compatible = "cirrus,cs42l51";
 +
reg = <0x4a>;
 +
#sound-dai-cells = <0>;
 +
VL-supply = <&v3v3>;
 +
VD-supply = <&v1v8_audio>;
 +
VA-supply = <&v1v8_audio>;
 +
VAHP-supply = <&v1v8_audio>;
 +
reset-gpios = <&gpioc 0 GPIO_ACTIVE_LOW>;
 +
clocks = <&sai2a>;
 +
clock-names = "MCLK";
 +
status = "okay";
 +
 +
cs42l51_port: port {
 +
#address-cells = <1>;
 +
#size-cells = <0>;
 +
 +
cs42l51_tx_endpoint: endpoint@0 {
 +
reg = <0>;
 +
remote-endpoint = <&sai2a_endpoint>;
 +
frame-master;
 +
bitclock-master;
 +
};
 +
 +
cs42l51_rx_endpoint: endpoint@1 {
 +
reg = <1>;
 +
remote-endpoint = <&sai2b_endpoint>;
 +
frame-master;
 +
bitclock-master;
 +
};
 +
};
 +
};
 +
</nowiki></pre>
 +
*1.8V电源设备节点<br>
 +
前文已经说过如何添加电源节点,本节不再重复,在根节点添加&v1v8_audio节点,内容如下:
 +
<pre><nowiki>
 +
v1v8_audio: regulator-v1v8_audio {
 +
compatible = "regulator-fixed";
 +
regulator-name = "v1v8_audio";
 +
regulator-min-microvolt = <1800000>;
 +
regulator-max-microvolt = <1800000>;
 +
regulator-always-on;
 +
regulator-boot-on;
 +
};
 +
</nowiki></pre>
 +
*SOC声卡驱动节点<br>
 +
 +
内核中包含audio-graph-card驱动,驱动将声卡各个部分关联起来,驱动正常工作需添加对应设备树节点。<br>
 +
 +
参考文档:
 +
Documentation/devicetree/bindings/sound/audio-graph-card.txt
 +
在根节点写下添加sound节点:
 +
<pre><nowiki>
 +
sound {
 +
compatible = "audio-graph-card";
 +
label = "STM32MP1-FSMP1A";
 +
routing =
 +
"Playback" , "MCLK",
 +
"Capture" , "MCLK",
 +
"MICL" , "Mic Bias";
 +
dais = <&sai2a_port &sai2b_port>;
 +
status = "okay";
 +
};
 +
</nowiki></pre>
 +
 
==实验目的==
 
==实验目的==
 
==实验平台==
 
==实验平台==
 
==实验步骤==
 
==实验步骤==

2020年7月28日 (二) 14:27的版本

实验原理

FS-MP1A使用的是CS42L51音频芯片,SoC通过I2C和SAI与其进行数据交互,原理图如下:

57-1-1-1.png

SAI2管脚对应关系:

57-1-1-2.png

57-1-1-3.png

57-1-1-4.png

I2C5管脚对应关系:

57-1-1-5.png

芯片复位管脚对应关系:

57-1-1-6.png

原理图网络编号 对应管脚 管脚功能 管脚功能码
SAI2_MCLKA PE0 SAI2_MCLK_A AF10
SAI2_SDB PF11 SDA2_SD_B AF10
SAI2_SCKA PI5 SAI2_SCK_A AF10
SAI_SDA PI6 SAI2_SD_A AF10
SAI2_FSA PI7 SAI2_FS_A AF10
AUDIO_RST PC0 IO ANALOG
I2C5_SDA PA11 I2C5_SDA AF4
I2C5_SCL PA12 I2C5_SDA AF4
  • SAI2设备树节点

参考文档:

Documentation/devicetree/bindings/sound/st,stm32-sai.txt

内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见:

sai2: sai@4400b000 {
	compatible = "st,stm32h7-sai";
	#address-cells = <1>;
	#size-cells = <1>;
	ranges = <0 0x4400b000 0x400>;
	reg = <0x4400b000 0x4>, <0x4400b3f0 0x10>;
	interrupts = <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>;
	resets = <&rcc SAI2_R>;
	status = "disabled";

	sai2a: audio-controller@4400b004 {
		#sound-dai-cells = <0>;
		compatible = "st,stm32-sai-sub-a";
		reg = <0x4 0x1c>;
		clocks = <&rcc SAI2_K>;
		clock-names = "sai_ck";
		dmas = <&dmamux1 89 0x400 0x01>;
		status = "disabled";
	};

	sai2b: audio-controller@4400b024 {
		#sound-dai-cells = <0>;
		compatible = "st,stm32-sai-sub-b";
		reg = <0x24 0x1c>;
		clocks = <&rcc SAI2_K>;
		clock-names = "sai_ck";
		dmas = <&dmamux1 90 0x400 0x01>;
		status = "disabled";
	};
};

上述代码只对SAI2做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。

参考stm32mp15xx-dkx.dtsi对于SAI2设备节点的描述,增加SAI2内容如下:

&sai2 {
	clocks = <&rcc SAI2>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
	clock-names = "pclk", "x8k", "x11k";
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sai2a_pins_a>, <&sai2b_pins_b>;
	pinctrl-1 = <&sai2a_sleep_pins_a>, <&sai2b_sleep_pins_b>;
	status = "okay";

	sai2a: audio-controller@4400b004 {
		#clock-cells = <0>;
		dma-names = "tx";
		clocks = <&rcc SAI2_K>;
		clock-names = "sai_ck";
		status = "okay";

		sai2a_port: port {
			sai2a_endpoint: endpoint {
				remote-endpoint = <&cs42l51_tx_endpoint>;
				format = "i2s";
				mclk-fs = <256>;
				dai-tdm-slot-num = <2>;
				dai-tdm-slot-width = <32>;
			};
		};
	};

	sai2b: audio-controller@4400b024 {
		dma-names = "rx";
		st,sync = <&sai2a 2>;
		clocks = <&rcc SAI2_K>, <&sai2a>;
		clock-names = "sai_ck", "MCLK";
		status = "okay";

		sai2b_port: port {
			sai2b_endpoint: endpoint {
				remote-endpoint = <&cs42l51_rx_endpoint>;
				format = "i2s";
				mclk-fs = <256>;
				dai-tdm-slot-num = <2>;
				dai-tdm-slot-width = <32>;
			};
		};
	};
};

由于stm32mp15-pinctrl.dtsi中对于SAI2管脚的定义与FS-MP1A实际使用管脚一致,所以无需修改。

  • CS42L51设备树节点

由于前文中已经增加过I2C5的节点信息,本节就不再重复,在原有I2C5节点添加CS42L51内容即可。

参考文档:

Documentation/devicetree/bindings/sound/cs42l51.txt

参考stm32mp15xx-dkx.dtsi对于codec芯片设备节点的描述,增加内容如下:

cs42l51: cs42l51@4a {
	compatible = "cirrus,cs42l51";
	reg = <0x4a>;
	#sound-dai-cells = <0>;
	VL-supply = <&v3v3>;
	VD-supply = <&v1v8_audio>;
	VA-supply = <&v1v8_audio>;
	VAHP-supply = <&v1v8_audio>;
	reset-gpios = <&gpioc 0 GPIO_ACTIVE_LOW>;
	clocks = <&sai2a>;
	clock-names = "MCLK";
	status = "okay";

	cs42l51_port: port {
		#address-cells = <1>;
		#size-cells = <0>;

		cs42l51_tx_endpoint: endpoint@0 {
			reg = <0>;
			remote-endpoint = <&sai2a_endpoint>;
			frame-master;
			bitclock-master;
		};

		cs42l51_rx_endpoint: endpoint@1 {
			reg = <1>;
			remote-endpoint = <&sai2b_endpoint>;
			frame-master;
			bitclock-master;
		};
	};
};
  • 1.8V电源设备节点

前文已经说过如何添加电源节点,本节不再重复,在根节点添加&v1v8_audio节点,内容如下:

v1v8_audio: regulator-v1v8_audio {
	compatible = "regulator-fixed";
	regulator-name = "v1v8_audio";
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;
	regulator-always-on;
	regulator-boot-on;
};
  • SOC声卡驱动节点

内核中包含audio-graph-card驱动,驱动将声卡各个部分关联起来,驱动正常工作需添加对应设备树节点。

参考文档:

Documentation/devicetree/bindings/sound/audio-graph-card.txt

在根节点写下添加sound节点:

sound {
	compatible = "audio-graph-card";
	label = "STM32MP1-FSMP1A";
	routing =
		"Playback" , "MCLK",
		"Capture" , "MCLK",
		"MICL" , "Mic Bias";
	dais = <&sai2a_port &sai2b_port>;
	status = "okay";
};

实验目的

实验平台

实验步骤