查看“Linux内核-音频驱动移植”的源代码
←
Linux内核-音频驱动移植
跳转至:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==实验原理== FS-MP1A使用的是CS42L51音频芯片,SoC通过I2C和SAI与其进行数据交互,原理图如下:<br> <center>[[Image:57-1-1-1.png|640px]] </center><br> SAI2管脚对应关系: <center>[[Image:57-1-1-2.png]]</center> <br> <center>[[Image:57-1-1-3.png]]</center> <br> <center>[[Image:57-1-1-4.png]]</center> <br> I2C5管脚对应关系: <center>[[Image:57-1-1-5.png]]</center> <br> 芯片复位管脚对应关系: <center>[[Image:57-1-1-6.png]]</center> <br> {|align=center border=1 |- ! 原理图网络编号 !! 对应管脚 !! 管脚功能 !! 管脚功能码 |- | 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 |} <ol> <li>SAI2设备树节点</li> 参考文档: 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> <li>CS42L51设备树节点</li> 由于前文中已经增加过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> <li>1.8V电源设备节点</li> 前文已经说过如何添加电源节点,本节不再重复,在根节点添加&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> <li>SOC声卡驱动节点</li> 内核中包含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> </ol> ==实验目的== 熟悉基于Linux操作系统下的音频设备驱动移植配置过程。 ==实验平台== 华清远见开发环境,FS-MP1A平台; ==实验步骤== <ol> <li>导入交叉编译工具链</li> linux@ubuntu:$ source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi <li>添加SAI2节点</li> 修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在文件末尾添加如下内容: <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>; }; }; }; }; &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> <li>添加CS42L51节点</li> 修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在I2C5节点中添加如下内容: <pre> 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; }; }; }; </pre> <li>添加v1v8_audio电源节点</li> 修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在根节点中添加如下内容: <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> <li>添加Sound节点</li> 修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在根节点中添加如下内容: <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> <li>配置内核</li> 由于内核源码默认配置以及支持CS42L51,本节列出主要选项,如下: <pre><nowiki> linux@ubuntu:$ make menuconfig Device Drivers ---> <*> Sound card support ---> <*> Advanced Linux Sound Architecture ---> <*> ALSA for SoC audio support ---> STMicroelectronics STM32 SOC audio support ---> <*> STM32 SAI interface (Serial Audio Interface) support CODEC drivers ---> <*> Cirrus Logic CS42L51 CODEC (I2C) <*> ASoC Audio Graph sound card support </nowiki></pre> <li>编译内核及设备树</li> linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040 <li>重启测试</li> 将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,启动后启动信息中出现如下内容: [[Image:57-1-4-1.png]] <br> 插上耳机,终端输入录音命令: root@fsmp1a:# arecord -D record_codec -f S16_LE -d 10 test.wav 终端输入播放命令: root@fsmp1a:# aplay test.wav <font color="#FF0000"> 注意:由于3.5mm的4段式耳机接口还分为两种,一种是美标版(CTIA),也称为“苹果标准”,同时小米、魅族也是使用这种标准;另外一种是国标版(OMTP),也称为“诺基亚标准”,现在绝大多数诺基亚和大多数国产手机都是使用这种标准。FS_MP1A使用的是国标版,所以部分耳机并不能正常实现录播功能。 </font> </ol>
返回至
Linux内核-音频驱动移植
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
关于我们
联系我们
资料下载
STM32F103开发板
STM32U575开发板
STM32MP157开发板
Hi3861鸿蒙开发板
HaaS EDU开发板
ESP32开发板
i.MX8M Plus开发板
图书下载
嵌入式系列图书
物联网系列图书
Android系列图书
高校教仪
嵌入式实验室产品
物联网实验室产品
人工智能实验室产品
虚拟仿真实验室产品
行业应用实训室产品
虚拟仿真
嵌入式虚拟仿真平台
物联网虚拟仿真平台
人工智能虚拟仿真
友情链接
华清远见研发中心
元宇宙实验中心
华清远见硬件商城
工具
链入页面
相关更改
特殊页面
页面信息