Linux Audio (6) DAPM-3 damp的kcontrol注册过程

  • damp的注册过程

在这里插入图片描述

普通kcontrol

定义:

static const struct snd_kcontrol_new wm8960_snd_controls[] = {
SOC_DOUBLE_R_TLV("Capture Volume", WM8960_LINVOL, WM8960_RINVOL,
		 0, 63, 0, adc_tlv),

Trace 普通的kcontrol是如何添加到内核中去的,其实在Linux Audio (4) DAPM-1 Kcontrol 中有分析过(uda1341为例),下面以wm8960为例:

wm8960_probe(struct snd_soc_codec *codec)
	snd_soc_add_codec_controls(codec, wm8960_snd_controls, ARRAY_SIZE(wm8960_snd_controls));
		snd_soc_add_controls(card, codec->dev, controls, num_controls, codec->name_prefix, codec);
			snd_ctl_add(card, snd_soc_cnew(control, data, control->name, prefix));
				list_add_tail(&kcontrol->list, &card->controls);
// snd_soc_cnew() 将snd_kcontrol_new转化为kcontrol

将数组中的每个snd_kcontrol_new转化为kcontrol并且挂到card->controls链表中。

DAMP kcontrol

Left Boost Mixer为例,该widget包含一个Mixer和三个kcontrol;而Muxer则只包含有一个kcontrol;
在这里插入图片描述

  • 第一步
    调用 snd_soc_dapm_new_controls 把widget放入dapm->card->widgets链表中

  • 第二步
    在注册machine驱动时,导致如下调用:
    soc_probe_dai_link --> soc_post_component_init --> snd_soc_dapm_new_widgets

    在 snd_soc_dapm_new_widgets 中:

    • 对于每一个widget,设置power_check函数(判断是否应该上电)
    • 对于mixer widget,取出其中的kcontrol_new构造出snd_kcontrol, 放入card->controls链表
    • 对于mixer widget,只有一个kcontrol_new,构造出snd_kcontrol, 放入card->controls链表

第一步 codec驱动add widget

将Mixer widget放入声卡链表中:

wm8960_probe(struct snd_soc_codec *codec)
	wm8960_add_widgets(codec);
		snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets,ARRAY_SIZE(wm8960_dapm_widgets));
			snd_soc_dapm_new_control(dapm, widget);
				list_add(&w->list, &dapm->card->widgets); //添加到声卡中的widgets链表中
				
		snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
			snd_soc_dapm_add_route(dapm, route); // for (i = 0; i < num; i++) {
				list_add(&path->list, &dapm->card->paths);
				list_add(&path->list_sink, &wsink->sources);
				list_add(&path->list_source, &wsource->sinks);

第二步 Mechine驱动add kcontrol

三个kcontrol的注册过程

snd_smdk_probe(struct platform_device *pdev) // Mechine驱动的probe()函数
	snd_soc_register_card(struct snd_soc_card *card)
		snd_soc_instantiate_card(struct snd_soc_card *card)
			soc_probe_dai_link()
				soc_post_component_init(card, codec, num, 0);
					snd_soc_dapm_new_widgets(&codec->dapm); //Make sure all DAPM widgets are instantiated

对于Mixer 和 Muxer有不同的处理
在这里插入图片描述

  • Mixer
snd_soc_dapm_new_widgets(&codec->dapm); //Make sure all DAPM widgets are instantiated
	dapm_new_mixer(w); //create new dapm mixer control
		for (i = 0; i < w->num_kcontrols; i++) {
			path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],wlist, path->long_name,prefix);
			snd_ctl_add(card, path->kcontrol);
				list_add_tail(&kcontrol->list, &card->controls);

path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],wlist, path->long_name,prefix);

创建kcontrol的命名规则是:
add dapm control with long name for dapm_mixer this is the concatenation of the mixer and kcontrol name for dapm_mixer_named_ctl this is simply the kcontrol name.

  • Muxer
snd_soc_dapm_new_widgets(&codec->dapm); //Make sure all DAPM widgets are instantiated
	dapm_new_mux(struct snd_soc_dapm_widget *w)
		kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,name + prefix_len, prefix);
			snd_ctl_add(card, kcontrol);
				list_add_tail(&kcontrol->list, &card->controls);
		list_for_each_entry(path, &w->sources, list_sink)
			path->kcontrol = kcontrol;	

创建kcontrol的命名规则是:
The control will get a prefix from the control creation process but we’re also using the same prefix for widgets so cut the prefix off the front of the widget name.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值