mbox series

[v3,0/8] ASoC: samsung: midas-audio: Add GPIO-based headset jack detection

Message ID 20240519-midas-wm1811-gpio-jack-v3-0-0c1736144c0e@gmail.com
Headers show
Series ASoC: samsung: midas-audio: Add GPIO-based headset jack detection | expand

Message

Artur Weber May 19, 2024, 8:17 a.m. UTC
Many of Samsung's Exynos 4 devices share the same midas-audio driver
to handle the codec setup. While most of these devices, including the
Midas itself, use the jack detection provided by the WM8994 driver,
other devices such as the Samsung Galaxy Tab 3 8.0 (lt01) use two GPIOs
and an ADC channel to determine jack insertion, the jack's type, and
button presses (for headsets with volume up/down/play buttons).

In the downstream kernel, this behavior is implemented in the sec-jack
driver[1], and the per-device settings are configured in *-jack.c files
in the mach folder (see e.g. the Tab 3's implementation[2]).

This patchset implements this mechanism in the midas_wm1811.c driver,
and adds new DTS options to allow for its configuration. It also
enables jack detection for the Samsung Galaxy Tab 3 8.0.

A very similar mechanism was already present in the aries_wm8994.c
driver[3]; this implementation heavily borrows from it, though there
are a few extra cleanups as well.

Signed-off-by: Artur Weber <aweber.kernel@gmail.com>

[1] https://github.com/gr8nole/android_kernel_samsung_smdk4x12/blob/lineage-14.1/drivers/misc/sec_jack.c
[2] https://github.com/gr8nole/android_kernel_samsung_smdk4x12/blob/lineage-14.1/arch/arm/mach-exynos/tab3-jack.c
[3] https://github.com/torvalds/linux/blob/master/sound/soc/samsung/aries_wm8994.c

---
Changes in v3:
- Re-added pipe (|) character to samsung,headset-button-threshold-microvolt
  description to prevent it from being parsed as a mapping (fixes syntax
  error)
- Split out "ASoC: dt-bindings: samsung,midas-audio: Add GPIO-based headset
  jack detection" into two patches
- Link to v2: https://lore.kernel.org/r/20240508-midas-wm1811-gpio-jack-v2-0-b4d36cd02c6e@gmail.com

Changes in v2:
- Added vendor prefix to threshold properties
- Added separate headset mic bias regulator
- Changed some cases of dev_err + return with return dev_err_probe
- Added an extra patch to replace some previous dev_err + return cases
  with dev_err_probe
- Moved tab3 DTS wm1811 codec config changes to separate commit

---
Artur Weber (8):
      ASoC: dt-bindings: samsung,midas-audio: Add headset mic bias supply
      ASoC: dt-bindings: samsung,midas-audio: Add GPIO-based headset jack detection
      ASoC: samsung: midas_wm1811: Add headset mic bias supply support
      ASoC: samsung: midas_wm1811: Add GPIO-based headset jack detection
      ASoC: samsung: midas_wm1811: Use dev_err_probe where appropriate
      ARM: dts: samsung: exynos4212-tab3: Fix headset mic, add jack detection
      ARM: dts: samsung: exynos4212-tab3: Add MCLK2 clock to WM1811 codec config
      ARM: dts: samsung: exynos4212-tab3: Drop interrupt from WM1811 codec

 .../bindings/sound/samsung,midas-audio.yaml        |  33 ++
 arch/arm/boot/dts/samsung/exynos4212-tab3.dtsi     |  31 +-
 sound/soc/samsung/Kconfig                          |   2 +-
 sound/soc/samsung/midas_wm1811.c                   | 343 +++++++++++++++++++--
 4 files changed, 379 insertions(+), 30 deletions(-)
---
base-commit: e67572cd2204894179d89bd7b984072f19313b03
change-id: 20240502-midas-wm1811-gpio-jack-b10226b17ecc

Best regards,

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.