diff --git a/vcodec.c b/vcodec.c index b776b2716de95be2a818f027951f0e24b03e0206..9e6851bc927deac299e205962d59c705274c9dd7 100755 --- a/vcodec.c +++ b/vcodec.c @@ -13,6 +13,8 @@ enum reg { VCODEC_DAC_VOL_CTRL, + VCODEC_ADCL_REG, + VCODEC_DAC_REG, VCODEC_CTRL_NUM }; @@ -27,9 +29,100 @@ static const struct snd_kcontrol_new vcodec_codec_controls[] = { 0xFF, 0, dac_vol_tlv), }; +/* mic controls */ +static const struct snd_kcontrol_new mic1_input_mixer[] = { + SOC_DAPM_SINGLE("MIC1 Boost Switch", VCODEC_ADCL_REG, 0, 1, 0), +}; + +static int vcodec_capture_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *k, int event) { + //struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + + switch (event) { + case SND_SOC_DAPM_POST_PMU: + printk("-%s,SND_SOC_DAPM_POST_PMU\n",__func__); + break; + case SND_SOC_DAPM_POST_PMD: + printk("-%s,SND_SOC_DAPM_POST_PMD\n",__func__); + break; + default: + break; + } + return 0; +}; + +static int vcodec_playback_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *k, int event) { + //struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + + switch (event) { + case SND_SOC_DAPM_PRE_PMU: + printk("-%s,SND_SOC_DAPM_PRE_PMU\n",__func__); + break; + case SND_SOC_DAPM_POST_PMD: + printk("-%s,SND_SOC_DAPM_POST_PMD\n",__func__); + break; + default: + break; + } + return 0; +}; + +static int vcodec_hpspeaker_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *k, int event) { + //struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); + + switch (event) { + case SND_SOC_DAPM_POST_PMU: + printk("-%s,SND_SOC_DAPM_POST_PMU\n",__func__); + //这里可以拉高gpio, 使能功放 + break; + case SND_SOC_DAPM_PRE_PMD: + printk("-%s,SND_SOC_DAPM_PRE_PMD\n",__func__); + ////这里可以拉低gpio, 失能功放 + + break; + default: + break; + } + return 0; +} + +static const struct snd_soc_dapm_widget vcodec_dapm_widgets[] = { + SND_SOC_DAPM_INPUT("MIC1"), + SND_SOC_DAPM_MIXER("ADCL Input", SND_SOC_NOPM, 0, 0, + mic1_input_mixer, + ARRAY_SIZE(mic1_input_mixer)), + SND_SOC_DAPM_AIF_OUT_E("ADCL", "Capture", 0, VCODEC_ADCL_REG, + 8, 0, + vcodec_capture_event, + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), + + + SND_SOC_DAPM_AIF_IN_E("DACL", "Playback", 0, VCODEC_DAC_REG, + 0, 0, + vcodec_playback_event, + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + SND_SOC_DAPM_OUTPUT("HPOUTL"), + SND_SOC_DAPM_SPK("HpSpeaker", vcodec_hpspeaker_event), +}; + +static const struct snd_soc_dapm_route vcodec_dapm_routes[] = { + /* Mic input route */ + {"ADCL Input", "MIC1 Boost Switch", "MIC1"}, + {"ADCL", NULL, "ADCL Input"}, + + /* Headphone output route */ + {"HPOUTL", NULL, "DACL"}, + {"HpSpeaker", NULL, "HPOUTL"}, + +}; + static int vcodec_probe(struct snd_soc_codec *codec) { int ret = 0; + struct snd_soc_dapm_context *dapm = &codec->component.dapm; + printk("-%s,line:%d\n",__func__,__LINE__); /* 1.加controls */ @@ -40,7 +133,14 @@ static int vcodec_probe(struct snd_soc_codec *codec) return ret; } - /* 2.初始化codec */ + /* 2. 注册widgets和routes */ + snd_soc_dapm_new_controls(dapm, vcodec_dapm_widgets, + ARRAY_SIZE(vcodec_dapm_widgets)); + snd_soc_dapm_add_routes(dapm, vcodec_dapm_routes, + ARRAY_SIZE(vcodec_dapm_routes)); + + /* 3.初始化codec */ + reg_data[VCODEC_DAC_VOL_CTRL] = 0x0d0d; //初始化音量 return ret; } @@ -161,6 +261,7 @@ static struct snd_soc_dai_driver vcodec_dai[] = { { .name = "vcodec_dai", .playback = { + .stream_name = "Playback", .channels_min = 1, .channels_max = 2, .rates = SNDRV_PCM_RATE_8000_192000 | @@ -170,6 +271,7 @@ static struct snd_soc_dai_driver vcodec_dai[] = { SNDRV_PCM_FMTBIT_S32_LE, }, .capture = { + .stream_name = "Capture", .channels_min = 1, .channels_max = 2, .rates = SNDRV_PCM_RATE_8000_48000 |