Devicetree
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: "Nícolas F. R. A. Prado" <nfraprado@collabora.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Trevor Wu" <trevor.wu@mediatek.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>
Cc: kernel@collabora.com, linux-sound@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	Zoran Zhan <zoran.zhan@mediatek.com>
Subject: Re: [PATCH 3/3] ASoC: mediatek: mt8188-mt6359: Add headset jack detect support
Date: Tue, 4 Mar 2025 16:39:33 +0100	[thread overview]
Message-ID: <d976b28d-f44f-4d51-8b61-4c046c571412@collabora.com> (raw)
In-Reply-To: <20250214-mt8188-accdet-v1-3-6bbd5483855b@collabora.com>

Il 14/02/25 16:14, Nícolas F. R. A. Prado ha scritto:
> Enable headset jack detection for MT8188 platforms using the MT6359
> ACCDET block for it.
> 
> Co-developed-by: Zoran Zhan <zoran.zhan@mediatek.com>
> Signed-off-by: Zoran Zhan <zoran.zhan@mediatek.com>
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> ---
>   sound/soc/mediatek/mt8188/mt8188-mt6359.c | 43 +++++++++++++++++++++++++++++++
>   1 file changed, 43 insertions(+)
> 
> diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
> index 2d0d04e0232da07ba43a030b14853322427d55e7..4e19e6cfad1e1f42863b2e2f27131f880c5883bf 100644
> --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c
> +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
> @@ -17,6 +17,7 @@
>   #include "mt8188-afe-common.h"
>   #include "../../codecs/nau8825.h"
>   #include "../../codecs/mt6359.h"
> +#include "../../codecs/mt6359-accdet.h"
>   #include "../../codecs/rt5682.h"
>   #include "../common/mtk-afe-platform-driver.h"
>   #include "../common/mtk-soundcard-driver.h"
> @@ -266,6 +267,17 @@ static struct snd_soc_jack_pin nau8825_jack_pins[] = {
>   	},
>   };
>   
> +static struct snd_soc_jack_pin mt8188_headset_jack_pins[] = {

This is the same as nau8825_jack_pins... perhaps we could reuse that?

> +	{
> +		.pin    = "Headphone",
> +		.mask   = SND_JACK_HEADPHONE,
> +	},
> +	{
> +		.pin    = "Headset Mic",
> +		.mask   = SND_JACK_MICROPHONE,
> +	},
> +};
> +
>   static const struct snd_kcontrol_new mt8188_dumb_spk_controls[] = {
>   	SOC_DAPM_PIN_SWITCH("Ext Spk"),
>   };
> @@ -500,6 +512,35 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
>   	return 0;
>   }
>   
> +static int mt8188_mt6359_accdet_init(struct snd_soc_pcm_runtime *rtd)
> +{
> +	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
> +	struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET];
> +	int ret;
> +
> +	if (!soc_card_data->accdet)
> +		return 0;

I'm not sure... if we have mediatek,accdet (so accdet is present here), but we also
have a NAU8825, or RT5682S, or ES8326 codec, this function will create a headset
jack for MT6359, but then mt8188_headset_codec_init() will do the same again!

I think we should find a way to avoid that situation, as I'm mostly sure that this
will give issues in the long run.

Even if it wouldn't, having two headset jacks exposed, of which one doesn't work
because it doesn't exist on the physical board... would be confusing for the user.

I guess that the best option here would be:
  - Let the `for_each_card_prelinks()` loop finish
  - Check if any of the external codecs are providing 3.5mm jack
    - External codec providing jack means that the detection should be performed
      by the external codec, as the jack should not be physically routed to the
      MediaTek ACCDET related PMIC pins (right?)
    - No external codec means that the accessory detection can only be performed
      by the MediaTek ACCDET IP
  - If external codec manages 3.5mm jack: do nothing
  - If no external codec managing 3.5mm jack: check if accdet provided in DT and
    initialize it

....unless I'm wrong - and if I am, please explain why (and also add explanation
to the commit description).

Cheers,
Angelo

> +
> +	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, mt8188_headset_jack_pins,
> +				   ARRAY_SIZE(mt8188_headset_jack_pins));
> +	if (ret) {
> +		dev_err(rtd->dev, "Headset Jack create failed: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = mt6359_accdet_enable_jack_detect(soc_card_data->accdet, jack);
> +	if (ret) {
> +		dev_err(rtd->dev, "Headset Jack enable failed: %d\n", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>   static int mt8188_mt6359_init(struct snd_soc_pcm_runtime *rtd)
>   {
>   	struct snd_soc_component *cmpnt_codec =
> @@ -512,6 +553,8 @@ static int mt8188_mt6359_init(struct snd_soc_pcm_runtime *rtd)
>   	/* mtkaif calibration */
>   	mt8188_mt6359_mtkaif_calibration(rtd);
>   
> +	mt8188_mt6359_accdet_init(rtd);
> +
>   	return 0;
>   }
>   
> 

  reply	other threads:[~2025-03-04 15:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 15:14 [PATCH 0/3] Allow retrieving accessory detection reference on MT8188 Nícolas F. R. A. Prado
2025-02-14 15:14 ` [PATCH 1/3] ASoC: dt-bindings: mediatek,mt8188-mt6359: Add mediatek,accdet Nícolas F. R. A. Prado
2025-02-19 22:55   ` Rob Herring (Arm)
2025-03-04 15:39   ` AngeloGioacchino Del Regno
2025-02-14 15:14 ` [PATCH 2/3] ASoC: mediatek: common: Handle mediatek,accdet property Nícolas F. R. A. Prado
2025-03-04 15:39   ` AngeloGioacchino Del Regno
2025-02-14 15:14 ` [PATCH 3/3] ASoC: mediatek: mt8188-mt6359: Add headset jack detect support Nícolas F. R. A. Prado
2025-03-04 15:39   ` AngeloGioacchino Del Regno [this message]
2025-03-04 20:16     ` Nícolas F. R. A. Prado
2025-03-05 12:55       ` AngeloGioacchino Del Regno
2025-03-04 17:17   ` Mark Brown
2025-03-17 18:46 ` [PATCH 0/3] Allow retrieving accessory detection reference on MT8188 Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d976b28d-f44f-4d51-8b61-4c046c571412@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@collabora.com \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nfraprado@collabora.com \
    --cc=perex@perex.cz \
    --cc=robh@kernel.org \
    --cc=tiwai@suse.com \
    --cc=trevor.wu@mediatek.com \
    --cc=zoran.zhan@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox