Skip to contentSkip to conversation

ASoC: mediatek: Allow separate handling of headphone and headset mic jack

PATCH In review Nícolas F. R. A. Prado 3 participants 14 messages Sep 23, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ASoC: mediatek: Allow separate handling of headphone and headset mic jack

This series allows the headphone and headset mic jack status to be handled separately by userspace on MT8192, MT8195 and MT8186.

Changes based on commit d0508b4f1604 ("ASoC: rk3399_gru_sound: Add DAPM pins, kcontrols for jack detection"). Found while searching for an alternative for JackSwitch [1].

[1] https://lore.kernel.org/all/[email protected]/

Nícolas F. R. A. Prado (6):
ASoC: mediatek: mt8192-mt6359: Expose individual headset jack pins
ASoC: mediatek: mt8195: Expose individual headset jack pins
ASoC: mediatek: mt8186-da7219: Add headset widgets with switches
ASoC: mediatek: mt8186-da7219: Expose individual headset jack pins
ASoC: mediatek: mt8186-rt5682: Add headset widgets with switches
ASoC: mediatek: mt8186-rt5682: Expose individual headset jack pins

 .../mt8186/mt8186-mt6366-da7219-max98357.c    | 25 +++++++++++++++++--
 .../mt8186/mt8186-mt6366-rt1019-rt5682s.c     | 25 +++++++++++++++++--
 .../mt8192/mt8192-mt6359-rt1015-rt5682.c      | 17 +++++++++++--
 sound/soc/mediatek/mt8195/mt8195-mt6359.c     | 17 +++++++++++--
 4 files changed, 76 insertions(+), 8 deletions(-)
Signature · 1 line
2.37.3
#1 lore raw

PATCH 1/6 ASoC: mediatek: mt8192-mt6359: Expose individual headset jack pins

The rt5682 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8192-mt6359 driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

---

 .../mt8192/mt8192-mt6359-rt1015-rt5682.c        | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c +15 -2
index 044d6ab71f0a..ff40ccd36f7e 100644
@@ -41,6 +41,18 @@ struct mt8192_mt6359_priv {
 	struct snd_soc_jack hdmi_jack;
 };
 
+/* Headset jack detection DAPM pins */
+static struct snd_soc_jack_pin mt8192_jack_pins[] = {
+	{
+		.pin = "Headphone Jack",
+		.mask = SND_JACK_HEADPHONE,
+	},
+	{
+		.pin = "Headset Mic",
+		.mask = SND_JACK_MICROPHONE,
+	},
+};
+
 static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
 				       struct snd_pcm_hw_params *params)
 {
@@ -326,11 +338,12 @@ static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd)
 		return ret;
 	}
 
-	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
+	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
 				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
 				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
 				    SND_JACK_BTN_3,
-				    jack);
+				    jack, mt8192_jack_pins,
+				    ARRAY_SIZE(mt8192_jack_pins));
 	if (ret) {
 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
 		return ret;
Signature · 1 line
2.37.3
maintainer Reviewed-by Tested-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] ASoC: mediatek: mt8192-mt6359: Expose individual headset jack pins

Il 23/09/22 01:59, Nícolas F. R. A. Prado ha scritto:

Quoted 11 lines

The rt5682 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8192-mt6359 driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

[On MT8192 Asurada Spherion Chromebook]
#3 lore raw

PATCH 2/6 ASoC: mediatek: mt8195: Expose individual headset jack pins

In reply to Nícolas F. R. A. Prado

The rt5682 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8195 ASoC driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

---

 sound/soc/mediatek/mt8195/mt8195-mt6359.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
sound/soc/mediatek/mt8195/mt8195-mt6359.c +15 -2
index 961e769602d6..17d4c4108a9d 100644
@@ -63,6 +63,18 @@ struct mt8195_mt6359_priv {
 	struct clk *i2so1_mclk;
 };
 
+/* Headset jack detection DAPM pins */
+static struct snd_soc_jack_pin mt8195_jack_pins[] = {
+	{
+		.pin = "Headphone",
+		.mask = SND_JACK_HEADPHONE,
+	},
+	{
+		.pin = "Headset Mic",
+		.mask = SND_JACK_MICROPHONE,
+	},
+};
+
 static const struct snd_soc_dapm_widget mt8195_mt6359_widgets[] = {
 	SND_SOC_DAPM_HP("Headphone", NULL),
 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
@@ -563,11 +575,12 @@ static int mt8195_rt5682_init(struct snd_soc_pcm_runtime *rtd)
 
 	priv->i2so1_mclk = afe_priv->clk[MT8195_CLK_TOP_APLL12_DIV2];
 
-	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
+	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
 				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
 				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
 				    SND_JACK_BTN_3,
-				    jack);
+				    jack, mt8195_jack_pins,
+				    ARRAY_SIZE(mt8195_jack_pins));
 	if (ret) {
 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
 		return ret;
Signature · 1 line
2.37.3
maintainer Reviewed-by Tested-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] ASoC: mediatek: mt8195: Expose individual headset jack pins

Il 23/09/22 01:59, Nícolas F. R. A. Prado ha scritto:

Quoted 6 lines

The rt5682 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8195 ASoC driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Quoted 6 lines

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

Nit: for the title... ASoC: mediatek: mt8195-mt6359: ....

Apart from that,

[On MT8195 Cherry Tomato Chromebook]
#5 lore raw

PATCH 3/6 ASoC: mediatek: mt8186-da7219: Add headset widgets with switches

In reply to Nícolas F. R. A. Prado

Add DAPM widgets for headphones and headset microphone, with matching switches, to allow toggling these paths based on the jack connection status.

Note that differently from others (mt8192, mt8195 and mt8186-rt5682), the widget here is named "Headphones" (with an 's'), since "Headphone Switch" was already registered by da7219.

---

 sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c | 8 ++++++++
 1 file changed, 8 insertions(+)
sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c +8 -0
index 6f93f9dd4623..8d428bc4a3b2 100644
@@ -950,6 +950,8 @@ static struct snd_soc_dai_link mt8186_mt6366_da7219_max98357_dai_links[] = {
 static const struct snd_soc_dapm_widget
 mt8186_mt6366_da7219_max98357_widgets[] = {
 	SND_SOC_DAPM_SPK("Speakers", NULL),
+	SND_SOC_DAPM_HP("Headphones", NULL),
+	SND_SOC_DAPM_MIC("Headset Mic", NULL),
 	SND_SOC_DAPM_OUTPUT("HDMI1"),
 	SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0),
 	SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -961,6 +963,10 @@ static const struct snd_soc_dapm_route
 mt8186_mt6366_da7219_max98357_routes[] = {
 	/* SPK */
 	{ "Speakers", NULL, "Speaker"},
+	/* Headset */
+	{ "Headphones", NULL, "HPL" },
+	{ "Headphones", NULL, "HPR" },
+	{ "MIC", NULL, "Headset Mic" },
 	/* HDMI */
 	{ "HDMI1", NULL, "TX"},
 	/* SOF Uplink */
@@ -976,6 +982,8 @@ mt8186_mt6366_da7219_max98357_routes[] = {
 static const struct snd_kcontrol_new
 mt8186_mt6366_da7219_max98357_controls[] = {
 	SOC_DAPM_PIN_SWITCH("Speakers"),
+	SOC_DAPM_PIN_SWITCH("Headphones"),
+	SOC_DAPM_PIN_SWITCH("Headset Mic"),
 	SOC_DAPM_PIN_SWITCH("HDMI1"),
 };
 
Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] ASoC: mediatek: mt8186-da7219: Add headset widgets with switches

Il 23/09/22 01:59, Nícolas F. R. A. Prado ha scritto:

Quoted 9 lines

Add DAPM widgets for headphones and headset microphone, with matching switches, to allow toggling these paths based on the jack connection status.

Note that differently from others (mt8192, mt8195 and mt8186-rt5682), the widget here is named "Headphones" (with an 's'), since "Headphone Switch" was already registered by da7219.

#7 lore raw

PATCH 4/6 ASoC: mediatek: mt8186-da7219: Expose individual headset jack pins

In reply to Nícolas F. R. A. Prado

The da7219 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8186-da7219 driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

---

 .../mt8186/mt8186-mt6366-da7219-max98357.c      | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c +15 -2
index 8d428bc4a3b2..cfca6bdee834 100644
@@ -37,6 +37,18 @@ struct mt8186_mt6366_da7219_max98357_priv {
 	struct snd_soc_jack headset_jack, hdmi_jack;
 };
 
+/* Headset jack detection DAPM pins */
+static struct snd_soc_jack_pin mt8186_jack_pins[] = {
+	{
+		.pin = "Headphones",
+		.mask = SND_JACK_HEADPHONE,
+	},
+	{
+		.pin = "Headset Mic",
+		.mask = SND_JACK_MICROPHONE,
+	},
+};
+
 static struct snd_soc_codec_conf mt8186_mt6366_da7219_max98357_codec_conf[] = {
 	{
 		.dlc = COMP_CODEC_CONF("mt6358-sound"),
@@ -72,11 +84,12 @@ static int mt8186_da7219_init(struct snd_soc_pcm_runtime *rtd)
 	}
 
 	/* Enable Headset and 4 Buttons Jack detection */
-	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
+	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
 				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
 				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
 				    SND_JACK_BTN_3 | SND_JACK_LINEOUT,
-				    jack);
+				    jack, mt8186_jack_pins,
+				    ARRAY_SIZE(mt8186_jack_pins));
 	if (ret) {
 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
 		return ret;
Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 4/6
#8 lore raw

Re: [PATCH 4/6] ASoC: mediatek: mt8186-da7219: Expose individual headset jack pins

Il 23/09/22 01:59, Nícolas F. R. A. Prado ha scritto:

Quoted 11 lines

The da7219 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8186-da7219 driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

#9 lore raw

PATCH 5/6 ASoC: mediatek: mt8186-rt5682: Add headset widgets with switches

In reply to Nícolas F. R. A. Prado

Add DAPM widgets for headphones and headset microphone, with matching switches, to allow toggling these paths based on the jack connection status.

---

 sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c | 8 ++++++++
 1 file changed, 8 insertions(+)
sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c +8 -0
index 247f20f594d9..4360871bfc44 100644
@@ -926,6 +926,8 @@ static struct snd_soc_dai_link mt8186_mt6366_rt1019_rt5682s_dai_links[] = {
 static const struct snd_soc_dapm_widget
 mt8186_mt6366_rt1019_rt5682s_widgets[] = {
 	SND_SOC_DAPM_SPK("Speakers", NULL),
+	SND_SOC_DAPM_HP("Headphone", NULL),
+	SND_SOC_DAPM_MIC("Headset Mic", NULL),
 	SND_SOC_DAPM_OUTPUT("HDMI1"),
 	SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0),
 	SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -937,6 +939,10 @@ static const struct snd_soc_dapm_route
 mt8186_mt6366_rt1019_rt5682s_routes[] = {
 	/* SPK */
 	{ "Speakers", NULL, "Speaker" },
+	/* Headset */
+	{ "Headphone", NULL, "HPOL" },
+	{ "Headphone", NULL, "HPOR" },
+	{ "IN1P", NULL, "Headset Mic" },
 	/* HDMI */
 	{ "HDMI1", NULL, "TX" },
 	/* SOF Uplink */
@@ -952,6 +958,8 @@ mt8186_mt6366_rt1019_rt5682s_routes[] = {
 static const struct snd_kcontrol_new
 mt8186_mt6366_rt1019_rt5682s_controls[] = {
 	SOC_DAPM_PIN_SWITCH("Speakers"),
+	SOC_DAPM_PIN_SWITCH("Headphone"),
+	SOC_DAPM_PIN_SWITCH("Headset Mic"),
 	SOC_DAPM_PIN_SWITCH("HDMI1"),
 };
 
Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 5/6
#10 lore raw

Re: [PATCH 5/6] ASoC: mediatek: mt8186-rt5682: Add headset widgets with switches

Il 23/09/22 01:59, Nícolas F. R. A. Prado ha scritto:

Quoted 5 lines

Add DAPM widgets for headphones and headset microphone, with matching switches, to allow toggling these paths based on the jack connection status.

#11 lore raw

PATCH 6/6 ASoC: mediatek: mt8186-rt5682: Expose individual headset jack pins

In reply to Nícolas F. R. A. Prado

The rt5682 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8186-rt5682 driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

---

 .../mt8186/mt8186-mt6366-rt1019-rt5682s.c       | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c +15 -2
index 4360871bfc44..2414c5b77233 100644
@@ -41,6 +41,18 @@ struct mt8186_mt6366_rt1019_rt5682s_priv {
 	struct snd_soc_jack headset_jack, hdmi_jack;
 };
 
+/* Headset jack detection DAPM pins */
+static struct snd_soc_jack_pin mt8186_jack_pins[] = {
+	{
+		.pin = "Headphone",
+		.mask = SND_JACK_HEADPHONE,
+	},
+	{
+		.pin = "Headset Mic",
+		.mask = SND_JACK_MICROPHONE,
+	},
+};
+
 static struct snd_soc_codec_conf mt8186_mt6366_rt1019_rt5682s_codec_conf[] = {
 	{
 		.dlc = COMP_CODEC_CONF("mt6358-sound"),
@@ -75,11 +87,12 @@ static int mt8186_rt5682s_init(struct snd_soc_pcm_runtime *rtd)
 		return ret;
 	}
 
-	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
+	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
 				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
 				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
 				    SND_JACK_BTN_3,
-				    jack);
+				    jack, mt8186_jack_pins,
+				    ARRAY_SIZE(mt8186_jack_pins));
 	if (ret) {
 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
 		return ret;
Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 6/6
#12 lore raw

Re: [PATCH 6/6] ASoC: mediatek: mt8186-rt5682: Expose individual headset jack pins

Il 23/09/22 01:59, Nícolas F. R. A. Prado ha scritto:

Quoted 11 lines

The rt5682 codec is able to distinguish between two event types:
headphone insertion/removal and headset microphone insertion/removal. However, currently, the mt8186-rt5682 driver exposes a single kcontrol for the headset jack, so userspace isn't able to differentiate between the two events.

Add a definition for the headset jack pins, so that a separate jack kcontrol is created for each one, allowing userspace to track and handle them individually.

maintainer
#13 lore raw
In reply to Nícolas F. R. A. Prado
Quoted 8 lines · Nícolas F. R. A. Prado

This series allows the headphone and headset mic jack status to be handled separately by userspace on MT8192, MT8195 and MT8186.

Changes based on commit d0508b4f1604 ("ASoC: rk3399_gru_sound: Add DAPM pins, kcontrols for jack detection"). Found while searching for an alternative for JackSwitch [1].

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/6] ASoC: mediatek: mt8192-mt6359: Expose individual headset jack pins

      commit: 194ff8db03782d1dae41b7b42ea65da5748884c2
[2/6] ASoC: mediatek: mt8195: Expose individual headset jack pins
      commit: aa51e3c127a43cf4862db5f0081da281f1aa6429
[3/6] ASoC: mediatek: mt8186-da7219: Add headset widgets with switches
      commit: 13bee4a16ac5c5f0e3a5db868df991be57e74aa5
[4/6] ASoC: mediatek: mt8186-da7219: Expose individual headset jack pins
      commit: 8e986748680629a82398c65da0c5bda4c6a01b3d
[5/6] ASoC: mediatek: mt8186-rt5682: Add headset widgets with switches
      commit: d888e7afa03f06d8091ecdd43f87d5396dfbf907
[6/6] ASoC: mediatek: mt8186-rt5682: Expose individual headset jack pins
      commit: 42de42c22453064ffc9b72c259b2ab901dd766dc

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark