diff mbox series

[v3,3/8] ASoC: samsung: midas_wm1811: Add headset mic bias supply support

Message ID 20240519-midas-wm1811-gpio-jack-v3-3-0c1736144c0e@gmail.com (mailing list archive)
State Superseded
Headers show
Series ASoC: samsung: midas-audio: Add GPIO-based headset jack detection | expand

Commit Message

Artur Weber May 19, 2024, 8:17 a.m. UTC
Some devices use a headset mic bias supply (sometimes referred to as
"ear mic bias") to enable/disable the headset mic.

Add support for getting the supply from DT and setting it up
accordingly to the value of the Headset Mic switch.

Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
---
Changes in v2:
- Added this commit
---
 sound/soc/samsung/midas_wm1811.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Mark Brown May 20, 2024, 2:35 p.m. UTC | #1
On Sun, May 19, 2024 at 10:17:49AM +0200, Artur Weber wrote:

> +static int midas_headset_mic_bias(struct snd_soc_dapm_widget *w,
> +			     struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct snd_soc_card *card = w->dapm->card;
> +	struct midas_priv *priv = snd_soc_card_get_drvdata(card);
> +
> +	if (!priv->reg_headset_mic_bias)
> +		return 0;
> +
> +	switch (event) {
> +	case SND_SOC_DAPM_PRE_PMU:
> +		return regulator_enable(priv->reg_headset_mic_bias);
> +	case SND_SOC_DAPM_POST_PMD:
> +		return regulator_disable(priv->reg_headset_mic_bias);
> +	}

We have SND_SOC_DAPM_REGULATOR_SUPPLY?
Artur Weber May 22, 2024, 4:20 p.m. UTC | #2
On 20.05.2024 16:35, Mark Brown wrote:
> On Sun, May 19, 2024 at 10:17:49AM +0200, Artur Weber wrote:
> 
>> +static int midas_headset_mic_bias(struct snd_soc_dapm_widget *w,
>> +			     struct snd_kcontrol *kcontrol, int event)
>> +{
>> +	struct snd_soc_card *card = w->dapm->card;
>> +	struct midas_priv *priv = snd_soc_card_get_drvdata(card);
>> +
>> +	if (!priv->reg_headset_mic_bias)
>> +		return 0;
>> +
>> +	switch (event) {
>> +	case SND_SOC_DAPM_PRE_PMU:
>> +		return regulator_enable(priv->reg_headset_mic_bias);
>> +	case SND_SOC_DAPM_POST_PMD:
>> +		return regulator_disable(priv->reg_headset_mic_bias);
>> +	}
> 
> We have SND_SOC_DAPM_REGULATOR_SUPPLY?

This is pretty much copied from the implementation of the mic bias
and sub mic bias regulator handling in the same driver; they all use
SND_SOC_DAPM_MIC combined with an enable/disable function like this one.

What would be the correct thing to do here - add a secondary DAPM widget
of type REGULATOR_SUPPLY and connect it to the MIC widget via audio-
routing, or replace the entire MIC widget with a REGULATOR_SUPPLY (or
something else entirely)?
And should this be done with the Main Mic and Sub Mic as well?

Best regards
Artur
Mark Brown May 22, 2024, 4:22 p.m. UTC | #3
On Wed, May 22, 2024 at 06:20:14PM +0200, Artur Weber wrote:

> What would be the correct thing to do here - add a secondary DAPM widget
> of type REGULATOR_SUPPLY and connect it to the MIC widget via audio-
> routing, or replace the entire MIC widget with a REGULATOR_SUPPLY (or
> something else entirely)?

The microphone is getting a supply so the first option seems better.

> And should this be done with the Main Mic and Sub Mic as well?

Probably yes.
diff mbox series

Patch

diff --git a/sound/soc/samsung/midas_wm1811.c b/sound/soc/samsung/midas_wm1811.c
index f31244156ff6..ab0a4804b45e 100644
--- a/sound/soc/samsung/midas_wm1811.c
+++ b/sound/soc/samsung/midas_wm1811.c
@@ -29,6 +29,7 @@ 
 struct midas_priv {
 	struct regulator *reg_mic_bias;
 	struct regulator *reg_submic_bias;
+	struct regulator *reg_headset_mic_bias;
 	struct gpio_desc *gpio_fm_sel;
 	struct gpio_desc *gpio_lineout_sel;
 	unsigned int fll1_rate;
@@ -201,6 +202,25 @@  static int midas_submic_bias(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int midas_headset_mic_bias(struct snd_soc_dapm_widget *w,
+			     struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_card *card = w->dapm->card;
+	struct midas_priv *priv = snd_soc_card_get_drvdata(card);
+
+	if (!priv->reg_headset_mic_bias)
+		return 0;
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		return regulator_enable(priv->reg_headset_mic_bias);
+	case SND_SOC_DAPM_POST_PMD:
+		return regulator_disable(priv->reg_headset_mic_bias);
+	}
+
+	return 0;
+}
+
 static int midas_fm_set(struct snd_soc_dapm_widget *w,
 			struct snd_kcontrol *kcontrol, int event)
 {
@@ -271,7 +291,7 @@  static const struct snd_soc_dapm_widget midas_dapm_widgets[] = {
 	SND_SOC_DAPM_LINE("FM In", midas_fm_set),
 
 	SND_SOC_DAPM_HP("Headphone", NULL),
-	SND_SOC_DAPM_MIC("Headset Mic", NULL),
+	SND_SOC_DAPM_MIC("Headset Mic", midas_headset_mic_bias),
 	SND_SOC_DAPM_MIC("Main Mic", midas_mic_bias),
 	SND_SOC_DAPM_MIC("Sub Mic", midas_submic_bias),
 };
@@ -455,6 +475,17 @@  static int midas_probe(struct platform_device *pdev)
 		return PTR_ERR(priv->reg_submic_bias);
 	}
 
+	priv->reg_headset_mic_bias = devm_regulator_get_optional(dev,
+							    "headset-mic-bias");
+	if (IS_ERR(priv->reg_headset_mic_bias)) {
+		ret = PTR_ERR(priv->reg_headset_mic_bias);
+		if (ret == -ENODEV)
+			priv->reg_headset_mic_bias = NULL;
+		else
+			return dev_err_probe(dev, ret,
+				     "Failed to get headset mic bias regulator\n");
+	}
+
 	priv->gpio_fm_sel = devm_gpiod_get_optional(dev, "fm-sel", GPIOD_OUT_HIGH);
 	if (IS_ERR(priv->gpio_fm_sel)) {
 		dev_err(dev, "Failed to get FM selection GPIO\n");