文章目录
平台 | os版本 | 内核 |
---|---|---|
MT6765 | Android 9.0 | kernel-4.9 |
概述
Platform
驱动的主要作用是完成音频数据的管理,最终通过CPU
的数字音频接口(DAI)把音频数据传输到Codec
中进行处理,最终由Codec
进行编解码处理后将音频数据输出到耳机或者是喇叭。在具体实现上,ASoC
又把Platform
驱动分为两个部分:snd_soc_platform_driver
和snd_soc_dai_driver
。其中,platform_driver
负责管理音频数据,把音频数据通过dma
或其他操作传送至cpu dai
中,dai_driver
则主要完成cpu
一侧的dai
的参数配置,同时也会通过一定的途径把必要的dma
等参数与snd_soc_platform_driver
进行交互。
我们知道kernel
中是存在多个平台的,比如atmel
,qcom
,mtk
等等,但是与平台相关的结构体mtk_soc_platform
最终是通过snd_soc_register_platform
来完成相应注册的。
audio驱动相关结构体 | 注释 |
---|---|
snd_soc_dai_driver | 音频数据接口描述及操作函数,根据 codec 端和 soc 端,分为 codec_dai 和 cpu_dai |
snd_soc_platform_driver | 音频平台设备描述及操作函数 |
platform驱动注册及加载流程分析
这里以录音为例分析audio
驱动里platform
驱动的加载流程。在kernel
中有多个同名的函数位于不同的文件目录中,比如函数mtk_capture_probe()
,在./sound/soc/mediatek/mt_soc_audio_8163/mt_soc_pcm_capture.c
和./sound/soc/mediatek/common_init/mtk-soc-pcm-capture.c
都存在。 那么如何确认具体使用是哪个文件夹下的函数mtk_capture_probe()
呢? 办法很简单,查看mt_soc_audio_8163
和common_init
所在文件目录mediatek
的Makefile
即可,打开Makefile
可以找到如下内容:
obj-$(CONFIG_SND_SOC_MEDIATEK) += common/
obj-$(CONFIG_SND_SOC_MTK_BTCVSD) += common_int/
obj-$(CONFIG_SND_SOC_MT8163) += mt_soc_audio_8163/
具体哪个Config
被设置为y
,可以在./kernel-4.9/arch/arm64/configs/xxx_debug_defconfig
文件中确认,比如任意打开一个deconfig
,比如k65v1_64_bsp_debug_defconfig
是CONFIG_SND_SOC_MTK_BTCVSD
被设置成y
的。
CONFIG_SND_SOC_MTK_BTCVSD=y
由此我么可以知道,使用的是common_init
文件夹里的内容。
mtk_soc_capture_platform_init
入口函数所在文件:
./kernel-4.9/sound/souc/mediatek/common_init/mtk-soc-pcm-capture.c
module_init(mtk_soc_capture_platform_init);
static int __init mtk_soc_capture_platform_init(void)
{
int ret = 0;
pr_warn("%s\n", __func__);
... /* 省略非关键代码 */
ret = platform_driver_register(&mtk_afe_capture_driver);
return ret;
}
通过模块入口函数注册平台 driver
,通过 device name
与 driver name
匹配
mtk_afe_capture_driver
需要被注册的结构体所在文件:
./kernel-4.9/sound/souc/mediatek/common_init/mtk-soc-pcm-capture.c
#ifdef CONFIG_OF
static const struct of_device_id mt_soc_pcm_capture_of_ids[] = {
{
.compatible = "mediatek,mt_soc_pcm_capture",
},
{
} };
#endif
static struct platform_driver mtk_afe_capture_driver = {
.driver = {