mbox series

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

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

Message

Artur Weber May 3, 2024, 6:55 p.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

---
Artur Weber (3):
      ASoC: dt-bindings: samsung,midas-audio: Add GPIO-based headset jack detection
      ASoC: samsung: midas_wm1811: Add GPIO-based headset jack detection
      ARM: dts: samsung: exynos4212-tab3: Fix headset mic, add jack detection

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

Best regards,

Comments

Krzysztof Kozlowski May 6, 2024, 6:30 a.m. UTC | #1
On 03/05/2024 20:55, Artur Weber wrote:
> Some Samsung devices that use the midas_wm1811 driver use a GPIO-based
> method for detecting whether the headset jack is plugged in, as well as
> detecting which headset buttons are pressed. There are two GPIOs:
> a "headset detect" GPIO responsible for detecting jack insertion, and
> a "headset key" GPIO which triggers when a button on the headset is
> pressed. The plug type and the button pressed are determined based
> on information from an ADC channel.

...

>  
> @@ -433,6 +590,9 @@ static int midas_probe(struct platform_device *pdev)
>  	struct snd_soc_card *card = &midas_card;
>  	struct device *dev = &pdev->dev;
>  	static struct snd_soc_dai_link *dai_link;
> +	enum iio_chan_type channel_type;
> +	u32 fourpole_threshold[2];
> +	u32 button_threshold[3];
>  	struct midas_priv *priv;
>  	int ret, i;
>  
> @@ -468,6 +628,91 @@ static int midas_probe(struct platform_device *pdev)
>  		return PTR_ERR(priv->gpio_lineout_sel);
>  	}
>  
> +	priv->gpio_headset_detect = devm_gpiod_get_optional(dev,
> +				"headset-detect", GPIOD_IN);
> +	if (IS_ERR(priv->gpio_headset_detect)) {
> +		dev_err(dev, "Failed to get headset jack detect GPIO\n");

syntax is:
return dev_err_probe()

> +		return PTR_ERR(priv->gpio_headset_detect);
> +	}
> +
> +	if (priv->gpio_headset_detect) {
> +		priv->adc_headset_detect = devm_iio_channel_get(dev,
> +							"headset-detect");
> +		if (IS_ERR(priv->adc_headset_detect)) {
> +			dev_err(dev, "Failed to get ADC channel\n");

return dev_err_probe()

> +			return PTR_ERR(priv->adc_headset_detect);
> +		}
> +

> +		ret = iio_get_channel_type(priv->adc_headset_detect,
> +					   &channel_type);
> +		if (ret) {
> +			dev_err(dev, "Failed to get ADC channel type\n");
> +			return ret;
> +		}
> +
> +		if (channel_type != IIO_VOLTAGE) {
> +			dev_err(dev, "ADC channel is not voltage\n");
> +			return ret;
> +		}
> +
> +		priv->gpio_headset_key = devm_gpiod_get(dev, "headset-key",
> +							GPIOD_IN);
> +		if (IS_ERR(priv->gpio_headset_key)) {
> +			dev_err(dev, "Failed to get headset key gpio\n");

return dev_err_probe()



Best regards,
Krzysztof
Krzysztof Kozlowski May 7, 2024, 2:53 p.m. UTC | #2
On 07/05/2024 14:44, Artur Weber wrote:
> On 6.05.2024 08:31, Krzysztof Kozlowski wrote:
>> On 03/05/2024 20:55, Artur Weber wrote:
>>> Add the necessary properties to the samsung,midas-audio node to allow
>>> for headset jack detection, set up the mic bias regulator GPIO and fix
>>> some other small issues with the sound setup.
>>>
>>> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
>>
>> ...
>>
>>> +
>>>   &bus_acp {
>>>   	devfreq = <&bus_dmc>;
>>>   	status = "okay";
>>> @@ -505,12 +521,11 @@ &i2c_4 {
>>>   	wm1811: audio-codec@1a {
>>>   		compatible = "wlf,wm1811";
>>>   		reg = <0x1a>;
>>> -		clocks = <&pmu_system_controller 0>;
>>> -		clock-names = "MCLK1";
>>> +		clocks = <&pmu_system_controller 0>,
>>> +			 <&s5m8767_osc S2MPS11_CLK_BT>;
>>> +		clock-names = "MCLK1", "MCLK2";
>>>   		interrupt-controller;
>>>   		#interrupt-cells = <2>;
>>> -		interrupt-parent = <&gpx3>;
>>> -		interrupts = <6 IRQ_TYPE_LEVEL_HIGH>;
>>
>> Does not look related at all to the patch.
> 
> I rolled up two small changes to the wm1811 audio codec config here:


https://elixir.bootlin.com/linux/v6.8-rc5/source/Documentation/process/submitting-patches.rst#L171



Best regards,
Krzysztof