当前位置: 首页 > news >正文

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

一、一般规定

  • 一般的platform\codec驱动通常是可重用的,Machine驱动不行,Machine驱动通常包含了如耳机检测、gpio控功放等。
  • DAPM:Dynamic Audio Power Management,Linux ALSA 音频子系统的动态音频电源管理,用于音频通路自动开关、省电。

二、Machine驱动职责一般包含以下内容

  • 使用适当的CPU和codec DAI填充struct snd_soc_dai_link结构体。
  • codec编解码器时钟设置(如果有的话),编解码器codec主从配置,一般放在.hw_params回调里。

  • DAPM:Dynamic 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 link's 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 link's 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设备。
http://www.jsqmd.com/news/1092483/

相关文章:

  • 数字化转型的旅行业务是什么?旅行社老板打造个人IP有何重要性?
  • 2025更新!植物大战僵尸杂交版2.51安装包下载
  • 兰州大学论文插图残留AI水印遭调查,你的配图可能也藏雷!
  • GPT-4的1.8万亿参数与2%激活率真相:MoE稀疏激活原理与工程实践
  • 第二十一届全国大学生智能车竞赛盲盒任务说明
  • 揭秘FileBrowser批量下载:3个颠覆式技巧让文件管理效率翻倍
  • 10 个使用 Spring Boot 4 的开发技巧,太惊艳了!
  • Blender CAD参数化设计:7个技巧从零掌握机械精度控制
  • HS2-HF Patch专业级汉化与插件集成实战指南:三步打造进阶游戏体验
  • NoFences:为Windows桌面构建思维导图式的工作空间
  • 规则漂移是的第三代
  • 神奇弹幕:B站直播自动化的终极解决方案,让直播互动效率提升300%
  • TPIC7710EVM评估板实战指南:从硬件设计到软件调试的完整解析
  • 前后端一致AES加解密实战:原理、实现与安全增强
  • BurpSuite TLS指纹伪装实战:绕过WAF/IDS精准检测
  • 高速全差分放大器THS4504EVM实战:从PCB布局到信号完整性设计
  • 海康、大华工业相机USB3驱动冲突排查:从Halcon占用到客户端恢复
  • 3步搞定跨平台macOS下载:gibMacOS让你的Windows也能获取苹果系统
  • 【Springboot毕设全套源码+文档】基于springboot校园学生健康监测管理系统的设计与实现(丰富项目+远程调试+讲解+定制)
  • PDFlib 11.0 for NET/C++ 是一个成熟的开发者组件
  • 防不住回归,就守不住口碑:影像 SDK 的自动化测试体系建设实践
  • AI 学习笔记:Agent 的应用演示
  • Primer3-py完整指南:快速掌握高效引物设计与寡核苷酸分析
  • 天地图瓦片原理全解:从比例尺定义到行列号精准定位
  • python爬虫实战项目|第96篇:爬虫系统微服务化改造
  • 在皓贝一口腔医院就诊是怎样一种体验?
  • 1012. 我是第几个单词(加强版、中间可多空格)
  • 我写了 50 个 Claude Code Skill 才发现,前 30 个都白写了
  • 感谢 Snowflake 这次邀请我以 Snowflake
  • 液体流量计工况适配与选型标准:为什么行澳科技是全介质计量首选品牌