【基于Linux4.19.X内核】Linux ALSA-ASoC驱动框架(一、Machine驱动框架及部分数据结构)

📅 2026/6/29 23:29:39
【基于Linux4.19.X内核】Linux ALSA-ASoC驱动框架(一、Machine驱动框架及部分数据结构)
一、一般规定一般的platform\codec驱动通常是可重用的Machine驱动不行Machine驱动通常包含了如耳机检测、gpio控功放等。DAPMDynamic Audio Power ManagementLinux ALSA 音频子系统的动态音频电源管理用于音频通路自动开关、省电。二、Machine驱动职责一般包含以下内容使用适当的CPU和codec DAI填充struct snd_soc_dai_link结构体。codec编解码器时钟设置如果有的话编解码器codec主从配置一般放在.hw_params回调里。DAPMDynamic Audio Power Management 动态音频电源管理。将运行时的采样频率传输到codec驱动程序。三、struct snd_soc_dai_link 数据结构//这里只是举例了一些常用或必要的结构体成员structsnd_soc_dai_link{//1.必选/* Codec name */constchar*name;//任意设置/* Stream name */constchar*stream_name;//该链接的流名称/* You MUST specify the DAI name within the codec */constchar*codec_dai_name;//必须与codec驱动中struct snd_soc_dai_driver下的.name字段相匹配//2.可选/* machine stream operations */conststructsnd_soc_ops*ops;/* * You MUST specify the links codec, either by device name, or by * DT/OF node, but not both. */constchar*codec_name;//一般是struct platform_driver下.driver.name或i2c_driver下.driver.name/* This DAI link can route to other DAI links at runtime (Frontend)*/unsignedintdynamic:1;/* pmdown_time is ignored at stop */unsignedintignore_pmdown_time:1;/* DPCM capture and Playback support */unsignedintdpcm_capture:1;unsignedintdpcm_playback:1;/* * You MAY specify the links platform/PCM/DMA driver, either by * device name, or by DT/OF node, but not both. Some forms of link * do not need a platform. */constchar*platform_name;/* Do not create a PCM for this DAI link (Backend link) */unsignedintno_pcm:1;/* optional hw_params re-writing for BE and FE sync */int(*be_hw_params_fixup)(structsnd_soc_pcm_runtime*rtd,structsnd_pcm_hw_params*params);//3.可不需要/* * You MAY specify the DAI name of the CPU DAI. If this information is * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node * only, which only works well when that device exposes a single DAI. */constchar*cpu_dai_name;// 必须和platform驱动中struct snd_soc_dai_driver下的.name字段相匹配可以都不填充/* codec/machine specific init - e.g. add machine controls */int(*init)(structsnd_soc_pcm_runtime*rtd);//DAI链接初始化回调函数}四、struct snd_soc_card 声卡数据结构/* SoC card */structsnd_soc_card{constchar*name;//声卡名structmodule*owner;//一般填写THIS_MODULE/* CPU -- Codec DAI links */structsnd_soc_dai_link*dai_link;//组成此声卡的DAI链接的数组如“imx_wm8960_dai”intnum_links;//组成此声卡的DAI链接的数组的大小conststructsnd_kcontrol_new*controls;//数组机器驱动程序设置的控件在IMX6ULL上没有设置intnum_controls;// 机器驱动程序设置的控件的大小/* * Card-specific routes and widgets. * Note: of_dapm_xxx for Device Tree; Otherwise for driver build-in. */conststructsnd_soc_dapm_widget*dapm_widgets;// 数组动态音频电源管理如“imx_wm8960_dapm_widgets”intnum_dapm_widgets;//动态音频电源管理数组大小structdevice*dev;// device代表声卡对应的设备conststructsnd_soc_dapm_route*of_dapm_routes;//对应信息在设备树“audio-routing”中对应成员“sink”和“source”intnum_of_dapm_routes;//以IMX6ULL为例为“audio-routing”的匹配对数...}声卡名填充snd_soc_of_parse_card_name(data-card, model)使用封装好的该函数解析dts中的model属性作为声卡名Machine驱动下的注册声卡int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)使用该函数进行声卡注册该函数在Machine驱动中的probe函数中执行在注册 Machine驱动声卡时会匹配和调用platform\codec驱动下的“probe”函数。为成功探测到的DAI链接创建一个新的PCM设备。