Re: [RESEND v5 6/7] ASoC: codecs: wcd937x: add capture dapm widgets

From: Mohammad Rafi Shaik
Date: Tue Jun 11 2024 - 00:40:36 EST


On 6/10/2024 12:35 PM, Srinivas Kandagatla wrote:


On 27/05/2024 12:19, Mohammad Rafi Shaik wrote:
+static int __wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
+                      int event)
+{
+    struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+    int micb_num;
+
+    if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
+        micb_num = MIC_BIAS_1;
+    else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
+        micb_num = MIC_BIAS_2;
+    else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
+        micb_num = MIC_BIAS_3;
+    else
+        return -EINVAL;
+
See last comment..

+    switch (event) {
+    case SND_SOC_DAPM_PRE_PMU:
+        wcd937x_micbias_control(component, micb_num,
+                    MICB_ENABLE, true);
+        break;
+    case SND_SOC_DAPM_POST_PMU:
+        usleep_range(1000, 1100);
+        break;
+    case SND_SOC_DAPM_POST_PMD:
+        wcd937x_micbias_control(component, micb_num,
+                    MICB_DISABLE, true);
+        break;
+    }
+
+    return 0;
+}
+
+static int wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
+                    struct snd_kcontrol *kcontrol,
+                    int event)
+{
+    return __wcd937x_codec_enable_micbias(w, event);
+}
+
+static int __wcd937x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
+                         int event)
+{
+    struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+    int micb_num;
+
+    if (strnstr(w->name, "VA MIC BIAS1", sizeof("VA MIC BIAS1")))
+        micb_num = MIC_BIAS_1;
+    else if (strnstr(w->name, "VA MIC BIAS2", sizeof("VA MIC BIAS2")))
+        micb_num = MIC_BIAS_2;
+    else if (strnstr(w->name, "VA MIC BIAS3", sizeof("VA MIC BIAS3")))
+        micb_num = MIC_BIAS_3;
+    else
+        return -EINVAL;
+
same..
+    switch (event) {
+    case SND_SOC_DAPM_PRE_PMU:
+        wcd937x_micbias_control(component, micb_num, MICB_PULLUP_ENABLE, true);
+        break;
+    case SND_SOC_DAPM_POST_PMU:
+        usleep_range(1000, 1100);
+        break;
+    case SND_SOC_DAPM_POST_PMD:
+        wcd937x_micbias_control(component, micb_num, MICB_PULLUP_DISABLE, true);
+        break;
+    }
+
+    return 0;
+}
+

...

  static const struct snd_soc_dapm_widget wcd937x_dapm_widgets[] = {
...> +    /* MIC_BIAS widgets */
+    SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, 0, 0,
Please use shift here like
        SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, MIC_BIAS_1, 0,
        SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, MIC_BIAS_2, 0,

to avoid doing a string compares on wideget name.

--srini


ACK

Will remove the string compares on widget name and will use the shift here.

Thanks & Regards,
Rafi.

+                wcd937x_codec_enable_micbias,
+                SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+                SND_SOC_DAPM_POST_PMD),
+    SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, 0, 0,
+                wcd937x_codec_enable_micbias,
+                SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+                SND_SOC_DAPM_POST_PMD),
+    SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM, 0, 0,
+                wcd937x_codec_enable_micbias,
+                SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+                SND_SOC_DAPM_POST_PMD),
+
      SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0,
                  wcd937x_codec_enable_vdd_buck,
                  SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
@@ -2007,11 +2312,101 @@ static const struct snd_soc_dapm_widget wcd937x_dapm_widgets[] = {
      SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
                 hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
+    /* TX output widgets */
+    SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"),
+    SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"),
+    SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"),
+    SND_SOC_DAPM_OUTPUT("WCD_TX_OUTPUT"),
+
      /* RX output widgets */
      SND_SOC_DAPM_OUTPUT("EAR"),
      SND_SOC_DAPM_OUTPUT("AUX"),
      SND_SOC_DAPM_OUTPUT("HPHL"),
      SND_SOC_DAPM_OUTPUT("HPHR"),
+
+    /* MIC_BIAS pull up widgets */
+    SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
+                wcd937x_codec_enable_micbias_pullup,
+                SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+                SND_SOC_DAPM_POST_PMD),
+    SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", SND_SOC_NOPM, 0, 0,
+                wcd937x_codec_enable_micbias_pullup,
+                SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+                SND_SOC_DAPM_POST_PMD),
+    SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", SND_SOC_NOPM, 0, 0,
+                wcd937x_codec_enable_micbias_pullup,
+                SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+                SND_SOC_DAPM_POST_PMD),