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

From: Artur Weber
Date: Sun May 19 2024 - 04:19:03 EST


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@xxxxxxxxx>
---
Changes in v2:
- Added this commit
---
sound/soc/samsung/midas_wm1811.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)

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");

--
2.45.0