教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

ALSA声卡驱动详解(11)

来源:网络收集 时间:2026-07-01
导读: struct device *dev; /* from parent - for debug */ struct snd_soc_codec *codec; /* parent codec */ struct snd_soc_platform *platform; /* parent platform */ struct snd_soc_card *card; /* parent card */

struct device *dev; /* from parent - for debug */ struct snd_soc_codec *codec; /* parent codec */

struct snd_soc_platform *platform; /* parent platform */

struct snd_soc_card *card; /* parent card */

/* used during DAPM updates */

enum snd_soc_bias_level target_bias_level; struct list_head list;

int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);

#ifdef CONFIG_DEBUG_FS

struct dentry *debugfs_dapm; #endif };

snd_soc_bias_level的取值范围是以下几种: SND_SOC_BIAS_OFF

SND_SOC_BIAS_STANDBY SND_SOC_BIAS_PREPARE SND_SOC_BIAS_ON

snd_soc_dapm_context被内嵌到代表codec、platform、card、dai的结构体中: [cpp] view plaincopy struct snd_soc_codec { ......

/* dapm */

struct snd_soc_dapm_context dapm; ...... };

struct snd_soc_platform {

28

......

/* dapm */

struct snd_soc_dapm_context dapm; ...... };

struct snd_soc_card { ......

/* dapm */

struct snd_soc_dapm_context dapm; ...... }; :

struct snd_soc_dai { ......

/* dapm */

struct snd_soc_dapm_widget *playback_widget; struct snd_soc_dapm_widget *capture_widget; struct snd_soc_dapm_context dapm; ...... };

代表widget结构snd_soc_dapm_widget中,有一个snd_soc_dapm_context结构指针,指向所属的codec、platform、card、或dai的dapm结构。同时,所有的dapm结构,通过它的list字段,链接到代表声卡的snd_soc_card结构的dapm_list链表头字段。 创建和注册widget

我们已经知道,一个widget用snd_soc_dapm_widget结构体来描述,通常,我们会根据音频硬件的组成,分别在声卡的codec驱动、platform驱动和machine驱动中定义一组widget,这些widget用数组进行组织,我们一般会使用dapm框架提供的大量的辅助宏来定义这些widget数组,辅助宏的说明请参考前一偏文章:ALSA声卡驱动中的DAPM详解之三:如何定义各种widget。 codec驱动中注册 我们知道,我们会通过ASoc提供的api函数

snd_soc_register_codec来注册一个codec驱动,该函数的第二个参数是一个snd_soc_codec_driver结构指针,这个snd_soc_codec_driver结构需要我们在codec驱动中显式地进行定义,其中有几个与dapm框架有关的字段: [cpp] view plaincopy

struct snd_soc_codec_driver { ......

/* Default control and setup, added after probe() is run */

const struct snd_kcontrol_new *controls; int num_controls;

29

const struct snd_soc_dapm_widget *dapm_widgets; int num_dapm_widgets;

const struct snd_soc_dapm_route *dapm_routes; int num_dapm_routes; ...... }

我们只要把我们定义好的snd_soc_dapm_widget结构数组的地址和widget的数量赋值到dapm_widgets和num_dapm_widgets字段即可,这样,经过

snd_soc_register_codec注册codec后,在machine驱动匹配上该codec时,系统会判断这两个字段是否被赋值,如果有,它会调佣dapm框架提供的api来创建和注册widget,注意这里我说还要创建这个词,你可能比较奇怪,既然代表

widget的snd_soc_dapm_widget结构数组已经在codec驱动中定义好了,为什么还要在创建?事实上,我们在codec驱动中定义的widget数组只是作为一个模板,dapm框架会根据该模板重新申请内存并初始化各个widget。我们看看实际的例子可能是这样的: [cpp] view plaincopy

static const struct snd_soc_dapm_widget wm8993_dapm_widgets[] = {

......

SND_SOC_DAPM_SUPPLY(\, SND_SOC_NOPM, 0, 0, NULL, 0),

SND_SOC_DAPM_AIF_IN(\, \, 0, SND_SOC_NOPM, 0, 0),

SND_SOC_DAPM_AIF_IN(\, \, 1, SND_SOC_NOPM, 0, 0),

...... };

static struct snd_soc_codec_driver soc_codec_dev_wm8993 = { .probe = codec_xxx_probe, ......

.dapm_widgets = &wm8993_dapm_widgets[0],

.num_dapm_widgets = ARRAY_SIZE(wm8993_dapm_widgets),

...... };

static int codec_wm8993_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) {

......

ret = snd_soc_register_codec(&i2c->dev,

&soc_codec_dev_wm8993, &wm8993_dai, 1); ......

30

…… 此处隐藏:877字,全部文档内容请下载后查看。喜欢就下载吧 ……
ALSA声卡驱动详解(11).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/520655.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)