- 爱易网页
-
Linux
- 小弟我对linux理解之alsa二
日期:2014-05-16 浏览次数:20759 次
我对linux理解之alsa二
我们接着上一节:
static int wm8994_probe(struct platform_device *pdev)
{
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
struct snd_soc_codec *codec = wm8994_codec;
int ret = 0;
socdev->card->codec = wm8994_codec;//已经在codec列表里
/* register pcms */
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);//注册pcms,1
if (ret < 0) {
dev_err(codec->dev, "failed to create pcms\n");
return ret;
}
snd_soc_add_controls(codec, wm8994_snd_controls,//添加控制,2
ARRAY_SIZE(wm8994_snd_controls));
snd_soc_dapm_new_controls(codec, wm8994_dapm_widgets,//添加dapm的widgets,3
ARRAY_SIZE(wm8994_dapm_widgets));
snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));//添加dapm的路径,4
// wm8994_audio_start_dac(codec);
// wm8994_audio_stop_speaker(codec);
if (tda19989_get_status()) {
wm8994_update_bit(codec, WM8994_POWER_MANAGEMENT_1,
0, WM8994_SPKOUTR_ENA_MASK | WM8994_SPKOUTL_ENA_MASK);
wm8994_update_bit(codec, WM8994_AIF1_DAC1_FILTERS_1,
WM8994_AIF1DAC1_MUTE, WM8994_AIF1DAC1_MUTE);
tda19989_pcm_mute((bool)1);
}
ret = snd_soc_init_card(socdev);//初始化card,5
if (ret < 0) {
printk(KERN_ERR "wm8994: failed to register card\n");
snd_soc_free_pcms(socdev);
snd_soc_dapm_free(socdev);
return ret;
}
INIT_WORK(&wm8994_trigger_event, wm8994_do_trigger);
return 0;
}
我们将分为上面标记的5部分进行分析。
1,snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1):
int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
{
struct snd_soc_card *card = socdev->card;
struct snd_soc_codec *codec = card->codec;
int ret = 0, i;
mutex_lock(&codec->mutex);
/* register a sound card */
ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card);//注册一个声卡,其中将会有control的ops注册到card的devices里面,1-1
if (ret < 0) {
printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
codec->name);
mutex_unlock(&codec->mutex);
return -ENODEV;
}
codec->socdev = socdev;
codec->card->dev = socdev->dev;
codec->card->private_data = codec;
strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
/* create the pcms */
for (i = 0; i < card->num_links; i++) {//根据dai连接数目,决定创建多少个pcm
ret = soc_new_pcm(socdev, &card->dai_link[i], i);//为每个card新建pcm流,1-2
if (ret < 0) {