当前位置: 首页 > 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.gsyq.cn/news/1604441.html

相关文章:

  • 兰州大学论文插图残留AI水印遭调查,你的配图可能也藏雷!
  • 2025更新!植物大战僵尸杂交版2.51安装包下载
  • Blender CAD参数化设计:7个技巧从零掌握机械精度控制
  • 神奇弹幕:B站直播自动化的终极解决方案,让直播互动效率提升300%
  • 规则漂移是的第三代
  • 高速全差分放大器THS4504EVM实战:从PCB布局到信号完整性设计
  • 前后端一致AES加解密实战:原理、实现与安全增强
  • 【Springboot毕设全套源码+文档】基于springboot校园学生健康监测管理系统的设计与实现(丰富项目+远程调试+讲解+定制)
  • 天地图瓦片原理全解:从比例尺定义到行列号精准定位
  • python爬虫实战项目|第96篇:爬虫系统微服务化改造
  • 我写了 50 个 Claude Code Skill 才发现,前 30 个都白写了
  • 在皓贝一口腔医院就诊是怎样一种体验?
  • 文件上传漏洞攻防全解析:从Webshell原理到实战加固方案
  • 在混合IT环境中用BIND9无缝接管Windows AD的DNS服务
  • 如何快速掌握多机位剪辑:LosslessCut完整指南
  • EMI滤波电感差异化选型设计要点
  • 如何高效管理Windows窗口:3种简单方法释放任务栏空间
  • Linux时区修改为CST
  • 深入解析I2C控制器与目标模式:从协议到UNICOMM-I2C硬件实现
  • ProperTree终极指南:掌握跨平台Plist编辑器的完整使用技巧
  • 零成本自建PikPak网页版:手把手教你用GitHub与Cloudflare Workers搭建私有磁力网盘
  • 喜保宁与氯巴占联用还是单用,难治性局灶发作治疗策略解析
  • 正负样本比例不平衡
  • SVGnest 矢量嵌套算法深度解析:开源CNC材料优化终极指南
  • Xilinx FPGA LVDS接口设计:从IBUFDS到自环测试的工程实践
  • FastApiAdmin 后端接口开发好了,前端管理界面怎么调用与显示?
  • 如何完整恢复老旧iOS设备:5步快速降级与越狱教程
  • HarmonyOS技术精讲-应用间跳转:典型场景二——地图导航与位置服务
  • 当 leader 被隔离: etcd 网络分区深度分析
  • 从像素到光点:基于SSD1306 OLED的动态光源控制与传感应用