mbox series

[v3,0/6] ASoC: wcd938x: enable t14s audio headset

Message ID 20250324110606.32001-1-srinivas.kandagatla@linaro.org
Headers show
Series ASoC: wcd938x: enable t14s audio headset | expand

Message

Srinivas Kandagatla March 24, 2025, 11:06 a.m. UTC
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

On Lenovo ThinkPad T14s, the headset is connected via a HiFi Switch to
support CTIA and OMTP headsets. This switch is used to minimise pop and
click during headset type switching.

This patchset adds required bindings and changes to codec and dts to   
tnable the regulator required to power this switch along with wiring up
gpio that control the headset switching.

Without this patchset, there will be lots of noise on headset and mic
will not we functional.
   
Changes since v2:
	- udpated bindings as suggested by Rob and Krzysztof
	- cleaned up swap_gnd_mic callback
	- updated mux gpio to use dev_err_probe.
	- added Tested-by and reviewed-by tags 

Changes since v1:
	- moved to using mux-controls.
	- fixed typo in regulator naming.

Srinivas Kandagatla (6):
  dt-bindings: mux: add optional regulator binding to gpio mux
  mux: gpio: add optional regulator support
  ASoC: codecs: wcd-mbhc: cleanup swap_gnd_mic api
  ASoC: dt-bindings: wcd93xx: add bindings for audio mux controlling hp
  ASoC: codecs: wcd938x: add mux control support for hp audio mux
  arm64: dts: qcom: x1e78100-t14s: Enable audio headset support

 .../devicetree/bindings/mux/gpio-mux.yaml     |  4 ++
 .../bindings/sound/qcom,wcd938x.yaml          |  6 +++
 .../qcom/x1e78100-lenovo-thinkpad-t14s.dtsi   | 25 ++++++++++++
 drivers/mux/gpio.c                            |  5 +++
 sound/soc/codecs/Kconfig                      |  1 +
 sound/soc/codecs/wcd-mbhc-v2.c                |  2 +-
 sound/soc/codecs/wcd-mbhc-v2.h                |  2 +-
 sound/soc/codecs/wcd937x.c                    |  2 +-
 sound/soc/codecs/wcd938x.c                    | 40 ++++++++++++++-----
 sound/soc/codecs/wcd939x.c                    |  2 +-
 10 files changed, 76 insertions(+), 13 deletions(-)

Comments

Dmitry Baryshkov March 24, 2025, 11:20 a.m. UTC | #1
On 24/03/2025 13:06, srinivas.kandagatla@linaro.org wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> 
> On some platforms to minimise pop and click during switching between
> CTIA and OMTP headset an additional HiFi mux is used. Most common
> case is that this switch is switched on by default, but on some
> platforms this needs a regulator enable.
> 
> move to using mux control to enable both regulator and handle gpios,
> deprecate the usage of gpio.
> 
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> Tested-by: Christopher Obbard <christopher.obbard@linaro.org>
> ---
>   sound/soc/codecs/Kconfig   |  1 +
>   sound/soc/codecs/wcd938x.c | 38 ++++++++++++++++++++++++++++++--------
>   2 files changed, 31 insertions(+), 8 deletions(-)
> 
> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
> index ee35f3aa5521..a2829d76e108 100644
> --- a/sound/soc/codecs/Kconfig
> +++ b/sound/soc/codecs/Kconfig
> @@ -2226,6 +2226,7 @@ config SND_SOC_WCD938X
>   	tristate
>   	depends on SOUNDWIRE || !SOUNDWIRE
>   	select SND_SOC_WCD_CLASSH
> +	select MULTIPLEXER
>   
>   config SND_SOC_WCD938X_SDW
>   	tristate "WCD9380/WCD9385 Codec - SDW"
> diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
> index dfaa3de31164..948b5f6cc45a 100644
> --- a/sound/soc/codecs/wcd938x.c
> +++ b/sound/soc/codecs/wcd938x.c
> @@ -19,6 +19,7 @@
>   #include <linux/regmap.h>
>   #include <sound/soc.h>
>   #include <sound/soc-dapm.h>
> +#include <linux/mux/consumer.h>
>   #include <linux/regulator/consumer.h>
>   
>   #include "wcd-clsh-v2.h"
> @@ -178,6 +179,8 @@ struct wcd938x_priv {
>   	int variant;
>   	int reset_gpio;
>   	struct gpio_desc *us_euro_gpio;
> +	struct mux_control *us_euro_mux;
> +	u32 mux_state;
>   	u32 micb1_mv;
>   	u32 micb2_mv;
>   	u32 micb3_mv;
> @@ -3243,9 +3246,16 @@ static bool wcd938x_swap_gnd_mic(struct snd_soc_component *component)
>   
>   	wcd938x = snd_soc_component_get_drvdata(component);
>   
> -	value = gpiod_get_value(wcd938x->us_euro_gpio);
> +	if (!wcd938x->us_euro_mux) {
> +		value = gpiod_get_value(wcd938x->us_euro_gpio);
>   
> -	gpiod_set_value(wcd938x->us_euro_gpio, !value);
> +		gpiod_set_value(wcd938x->us_euro_gpio, !value);

Is it possible to use mux_state for both GPIO and MUX paths?

> +	} else {
> +		mux_control_deselect(wcd938x->us_euro_mux);
> +		wcd938x->mux_state = !wcd938x->mux_state;
> +		if (mux_control_select(wcd938x->us_euro_mux, wcd938x->mux_state))
> +			dev_err(component->dev, "Unable to select us/euro mux state\n");

This can lead to mux being deselected next time even if the 
mux_control_select returned an error. I think mux_control API needs a 
way to toggle the state without deselecting it first. Anyway, an error 
from mux_control_select() must prevent you from calling 
mux_control_deselect() next time.

> +	}
>   
>   	return true;
>   }
Srinivas Kandagatla March 24, 2025, 12:04 p.m. UTC | #2
On 24/03/2025 11:20, Dmitry Baryshkov wrote:
> On 24/03/2025 13:06, srinivas.kandagatla@linaro.org wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>>
>> On some platforms to minimise pop and click during switching between
>> CTIA and OMTP headset an additional HiFi mux is used. Most common
>> case is that this switch is switched on by default, but on some
>> platforms this needs a regulator enable.
>>
>> move to using mux control to enable both regulator and handle gpios,
>> deprecate the usage of gpio.
>>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>> Tested-by: Christopher Obbard <christopher.obbard@linaro.org>
>> ---
>>   sound/soc/codecs/Kconfig   |  1 +
>>   sound/soc/codecs/wcd938x.c | 38 ++++++++++++++++++++++++++++++--------
>>   2 files changed, 31 insertions(+), 8 deletions(-)
>>
>> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
>> index ee35f3aa5521..a2829d76e108 100644
>> --- a/sound/soc/codecs/Kconfig
>> +++ b/sound/soc/codecs/Kconfig
>> @@ -2226,6 +2226,7 @@ config SND_SOC_WCD938X
>>       tristate
>>       depends on SOUNDWIRE || !SOUNDWIRE
>>       select SND_SOC_WCD_CLASSH
>> +    select MULTIPLEXER
>>   config SND_SOC_WCD938X_SDW
>>       tristate "WCD9380/WCD9385 Codec - SDW"
>> diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
>> index dfaa3de31164..948b5f6cc45a 100644
>> --- a/sound/soc/codecs/wcd938x.c
>> +++ b/sound/soc/codecs/wcd938x.c
>> @@ -19,6 +19,7 @@
>>   #include <linux/regmap.h>
>>   #include <sound/soc.h>
>>   #include <sound/soc-dapm.h>
>> +#include <linux/mux/consumer.h>
>>   #include <linux/regulator/consumer.h>
>>   #include "wcd-clsh-v2.h"
>> @@ -178,6 +179,8 @@ struct wcd938x_priv {
>>       int variant;
>>       int reset_gpio;
>>       struct gpio_desc *us_euro_gpio;
>> +    struct mux_control *us_euro_mux;
>> +    u32 mux_state;
>>       u32 micb1_mv;
>>       u32 micb2_mv;
>>       u32 micb3_mv;
>> @@ -3243,9 +3246,16 @@ static bool wcd938x_swap_gnd_mic(struct 
>> snd_soc_component *component)
>>       wcd938x = snd_soc_component_get_drvdata(component);
>> -    value = gpiod_get_value(wcd938x->us_euro_gpio);
>> +    if (!wcd938x->us_euro_mux) {
>> +        value = gpiod_get_value(wcd938x->us_euro_gpio);
>> -    gpiod_set_value(wcd938x->us_euro_gpio, !value);
>> +        gpiod_set_value(wcd938x->us_euro_gpio, !value);
> 
> Is it possible to use mux_state for both GPIO and MUX paths?

Ideally I would like to do that the way that gpio is done, which is 
clear reflection of hw state, however mux f/w is lacking such api.


> 
>> +    } else {
>> +        mux_control_deselect(wcd938x->us_euro_mux);
>> +        wcd938x->mux_state = !wcd938x->mux_state;
>> +        if (mux_control_select(wcd938x->us_euro_mux, 
>> wcd938x->mux_state))
>> +            dev_err(component->dev, "Unable to select us/euro mux 
>> state\n");
> 
> This can lead to mux being deselected next time even if the 
> mux_control_select returned an error. I think mux_control API needs a 
> way to toggle the state without deselecting it first. Anyway, an error 
> from mux_control_select() must prevent you from calling 
> mux_control_deselect() next time.

We can rearrange deselect to be done only on successful select, that 
should cleanup some of this.

--srini
> 
>> +    }
>>       return true;
>>   }
> 
>