* [PATCH v2 1/3] ASoC: dt-bindings: mediatek,mt8188-mt6359: Add mediatek,accdet
2025-03-04 21:35 [PATCH v2 0/3] Allow retrieving accessory detection reference on MT8188 Nícolas F. R. A. Prado
@ 2025-03-04 21:35 ` Nícolas F. R. A. Prado
2025-03-04 21:35 ` [PATCH v2 2/3] ASoC: mediatek: common: Handle mediatek,accdet property Nícolas F. R. A. Prado
2025-03-04 21:35 ` [PATCH v2 3/3] ASoC: mediatek: mt8188-mt6359: Add accdet headset jack detect support Nícolas F. R. A. Prado
2 siblings, 0 replies; 7+ messages in thread
From: Nícolas F. R. A. Prado @ 2025-03-04 21:35 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Trevor Wu, Jaroslav Kysela, Takashi Iwai
Cc: kernel, linux-sound, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, Nícolas F. R. A. Prado
Add a mediatek,accdet phandle property to allow getting a reference to
the MT6359 ACCDET block, which is responsible for detecting jack
insertion/removal.
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
.../devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml b/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml
index 8c77e7f68ad7b6f5b88b53cedccb291139a2eeea..76d5a437dc8f4ad1f31c21f84304bad326b0facd 100644
--- a/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml
+++ b/Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml
@@ -40,6 +40,14 @@ properties:
hardware that provides additional audio functionalities if present.
The AFE will link to ADSP when the phandle is provided.
+ mediatek,accdet:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ The phandle to the MT6359 accessory detection block, which detects audio
+ jack insertion and removal. This property should only be present if the
+ accdet block is actually wired to the audio jack pins and to be used for
+ jack detection.
+
patternProperties:
"^dai-link-[0-9]+$":
type: object
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 2/3] ASoC: mediatek: common: Handle mediatek,accdet property
2025-03-04 21:35 [PATCH v2 0/3] Allow retrieving accessory detection reference on MT8188 Nícolas F. R. A. Prado
2025-03-04 21:35 ` [PATCH v2 1/3] ASoC: dt-bindings: mediatek,mt8188-mt6359: Add mediatek,accdet Nícolas F. R. A. Prado
@ 2025-03-04 21:35 ` Nícolas F. R. A. Prado
2025-03-04 21:35 ` [PATCH v2 3/3] ASoC: mediatek: mt8188-mt6359: Add accdet headset jack detect support Nícolas F. R. A. Prado
2 siblings, 0 replies; 7+ messages in thread
From: Nícolas F. R. A. Prado @ 2025-03-04 21:35 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Trevor Wu, Jaroslav Kysela, Takashi Iwai
Cc: kernel, linux-sound, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, Nícolas F. R. A. Prado
Handle the optional mediatek,accdet property. When present, retrieve the
sound component from its phandle, so the machine sound driver can use it
to register the audio jack and initialize the MT6359 ACCDET for jack
detection.
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
sound/soc/mediatek/common/mtk-soc-card.h | 1 +
sound/soc/mediatek/common/mtk-soundcard-driver.c | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/sound/soc/mediatek/common/mtk-soc-card.h b/sound/soc/mediatek/common/mtk-soc-card.h
index 3f6e24dd22df13ddb3aef1625a77d2e29e46fccf..a1d2794ac1f717997fb47023d5951a9ac4897788 100644
--- a/sound/soc/mediatek/common/mtk-soc-card.h
+++ b/sound/soc/mediatek/common/mtk-soc-card.h
@@ -16,6 +16,7 @@ struct mtk_soc_card_data {
const struct mtk_sof_priv *sof_priv;
struct list_head sof_dai_link_list;
struct mtk_platform_card_data *card_data;
+ struct snd_soc_component *accdet;
void *mach_priv;
};
diff --git a/sound/soc/mediatek/common/mtk-soundcard-driver.c b/sound/soc/mediatek/common/mtk-soundcard-driver.c
index f4314dddc46075d554b4e3f3aae8bcb5498f8ab5..4e1c546a994f5e6b7068f70ac8dc2af7e87d141a 100644
--- a/sound/soc/mediatek/common/mtk-soundcard-driver.c
+++ b/sound/soc/mediatek/common/mtk-soundcard-driver.c
@@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_platform.h>
#include <sound/soc.h>
#include "mtk-dsp-sof-common.h"
@@ -192,7 +193,9 @@ EXPORT_SYMBOL_GPL(mtk_soundcard_common_capture_ops);
int mtk_soundcard_common_probe(struct platform_device *pdev)
{
- struct device_node *platform_node, *adsp_node;
+ struct device_node *platform_node, *adsp_node, *accdet_node;
+ struct snd_soc_component *accdet_comp;
+ struct platform_device *accdet_pdev;
const struct mtk_soundcard_pdata *pdata;
struct mtk_soc_card_data *soc_card_data;
struct snd_soc_dai_link *orig_dai_link, *dai_link;
@@ -250,6 +253,16 @@ int mtk_soundcard_common_probe(struct platform_device *pdev)
soc_card_data->card_data->jacks = jacks;
+ accdet_node = of_parse_phandle(pdev->dev.of_node, "mediatek,accdet", 0);
+ if (!IS_ERR(accdet_node)) {
+ accdet_pdev = of_find_device_by_node(accdet_node);
+ if (!IS_ERR(accdet_pdev)) {
+ accdet_comp = snd_soc_lookup_component(&accdet_pdev->dev, NULL);
+ if (!IS_ERR(accdet_comp))
+ soc_card_data->accdet = accdet_comp;
+ }
+ }
+
platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
if (!platform_node)
return dev_err_probe(&pdev->dev, -EINVAL,
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 3/3] ASoC: mediatek: mt8188-mt6359: Add accdet headset jack detect support
2025-03-04 21:35 [PATCH v2 0/3] Allow retrieving accessory detection reference on MT8188 Nícolas F. R. A. Prado
2025-03-04 21:35 ` [PATCH v2 1/3] ASoC: dt-bindings: mediatek,mt8188-mt6359: Add mediatek,accdet Nícolas F. R. A. Prado
2025-03-04 21:35 ` [PATCH v2 2/3] ASoC: mediatek: common: Handle mediatek,accdet property Nícolas F. R. A. Prado
@ 2025-03-04 21:35 ` Nícolas F. R. A. Prado
2025-03-05 17:18 ` AngeloGioacchino Del Regno
2 siblings, 1 reply; 7+ messages in thread
From: Nícolas F. R. A. Prado @ 2025-03-04 21:35 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Trevor Wu, Jaroslav Kysela, Takashi Iwai
Cc: kernel, linux-sound, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, Nícolas F. R. A. Prado, Zoran Zhan
Enable headset jack detection for MT8188 platforms that use the MT6359
ACCDET block for it, indicated by the mediatek,accdet property in DT.
For those platforms, register a jack and initialize the ACCDET block to
report jack events through 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/Kconfig | 1 +
sound/soc/mediatek/mt8188/mt8188-mt6359.c | 43 +++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
index 3033e2d3fe16840631a465dd967da77f7a6ff43c..64155ea7965a1cc50593fef442ce90761836f328 100644
--- a/sound/soc/mediatek/Kconfig
+++ b/sound/soc/mediatek/Kconfig
@@ -237,6 +237,7 @@ config SND_SOC_MT8188_MT6359
select SND_SOC_NAU8825
select SND_SOC_RT5682S
select SND_SOC_ES8326
+ select SND_SOC_MT6359_ACCDET
help
This adds support for ASoC machine driver for MediaTek MT8188
boards with the MT6359 and other I2S audio codecs.
diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
index 420b1427b71dc1424a52f7ab6140c14659036733..20dc9470ba76b2a750e79a5ae3dafabd7c597f40 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"
@@ -271,6 +272,17 @@ static struct snd_soc_jack_pin nau8825_jack_pins[] = {
},
};
+static struct snd_soc_jack_pin mt8188_headset_jack_pins[] = {
+ {
+ .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"),
};
@@ -506,6 +518,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;
+
+ 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 =
@@ -518,6 +559,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;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 3/3] ASoC: mediatek: mt8188-mt6359: Add accdet headset jack detect support
2025-03-04 21:35 ` [PATCH v2 3/3] ASoC: mediatek: mt8188-mt6359: Add accdet headset jack detect support Nícolas F. R. A. Prado
@ 2025-03-05 17:18 ` AngeloGioacchino Del Regno
2025-03-05 17:23 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-03-05 17:18 UTC (permalink / raw)
To: Nícolas F. R. A. Prado, Liam Girdwood, Mark Brown,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
Trevor Wu, Jaroslav Kysela, Takashi Iwai
Cc: kernel, linux-sound, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, Zoran Zhan
Il 04/03/25 22:35, Nícolas F. R. A. Prado ha scritto:
> Enable headset jack detection for MT8188 platforms that use the MT6359
> ACCDET block for it, indicated by the mediatek,accdet property in DT.
> For those platforms, register a jack and initialize the ACCDET block to
> report jack events through 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>
We chatted about the issue that I raised before with mt8188_headset_jack_pins[],
it's fine to have it for now, as whatever we do with that would still duplicate
things and there's no way around that for now.
The sound card driver should get a bigger cleanup anyway, and it's not really
possible even because otherwise we'd break UCM2 confs, so it is what it is.
> ---
> sound/soc/mediatek/Kconfig | 1 +
> sound/soc/mediatek/mt8188/mt8188-mt6359.c | 43 +++++++++++++++++++++++++++++++
> 2 files changed, 44 insertions(+)
>
> diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
> index 3033e2d3fe16840631a465dd967da77f7a6ff43c..64155ea7965a1cc50593fef442ce90761836f328 100644
> --- a/sound/soc/mediatek/Kconfig
> +++ b/sound/soc/mediatek/Kconfig
> @@ -237,6 +237,7 @@ config SND_SOC_MT8188_MT6359
> select SND_SOC_NAU8825
> select SND_SOC_RT5682S
> select SND_SOC_ES8326
> + select SND_SOC_MT6359_ACCDET
The only remaining complaint that I have is that this driver shouldn't really
add a select SND_SOC_MT6359_ACCDET.
Instead, the mt6359-accdet.h header should be modified to stub-ify the accdet
driver functions in the case in which it's not built in, or not available as a
module anyway.
This is because the accdet driver is not *mandatory* for this driver to work,
and being it an optional peripheral, adding a dependency doesn't really make
a lot of sense as it'd only force in bloat when not wanted.
So...
Get to that mt6359-accdet.h header and:
#if IS_ENABLED(CONFIG_SND_SOC_MT6359_ACCDET)
function signatures
#else
static .... { return -EINVAL; (or whatever else) }
#endif
That said, for the future v3 of this commit, after removing the select
SND_SOC_MT6359_ACCDET (and granted that the proposed header fix is in place),
you can add my
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cheers,
Angelo
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 3/3] ASoC: mediatek: mt8188-mt6359: Add accdet headset jack detect support
2025-03-05 17:18 ` AngeloGioacchino Del Regno
@ 2025-03-05 17:23 ` Mark Brown
2025-03-05 19:20 ` Nícolas F. R. A. Prado
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2025-03-05 17:23 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: Nícolas F. R. A. Prado, Liam Girdwood, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matthias Brugger, Trevor Wu,
Jaroslav Kysela, Takashi Iwai, kernel, linux-sound, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek, Zoran Zhan
[-- Attachment #1: Type: text/plain, Size: 466 bytes --]
On Wed, Mar 05, 2025 at 06:18:41PM +0100, AngeloGioacchino Del Regno wrote:
> Get to that mt6359-accdet.h header and:
> #if IS_ENABLED(CONFIG_SND_SOC_MT6359_ACCDET)
> function signatures
> #else
> static .... { return -EINVAL; (or whatever else) }
> #endif
>
It should probably be return 0 for the registration/unregistration
functions so the caller doesn't fail if it checks the return code when
the accessory detection is configured out.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 3/3] ASoC: mediatek: mt8188-mt6359: Add accdet headset jack detect support
2025-03-05 17:23 ` Mark Brown
@ 2025-03-05 19:20 ` Nícolas F. R. A. Prado
0 siblings, 0 replies; 7+ messages in thread
From: Nícolas F. R. A. Prado @ 2025-03-05 19:20 UTC (permalink / raw)
To: Mark Brown
Cc: AngeloGioacchino Del Regno, Liam Girdwood, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matthias Brugger, Trevor Wu,
Jaroslav Kysela, Takashi Iwai, kernel, linux-sound, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek, Zoran Zhan
On Wed, Mar 05, 2025 at 05:23:29PM +0000, Mark Brown wrote:
> On Wed, Mar 05, 2025 at 06:18:41PM +0100, AngeloGioacchino Del Regno wrote:
>
> > Get to that mt6359-accdet.h header and:
>
> > #if IS_ENABLED(CONFIG_SND_SOC_MT6359_ACCDET)
>
> > function signatures
>
> > #else
>
> > static .... { return -EINVAL; (or whatever else) }
>
> > #endif
> >
>
> It should probably be return 0 for the registration/unregistration
> functions so the caller doesn't fail if it checks the return code when
> the accessory detection is configured out.
Actually, given this function will only be called on platforms where the
accessory detection is present, I agree with Angelo that we should return an
error (and print the error message), so the user can easily figure out that the
accdet initialization failed due to the missing config.
Thanks,
Nícolas
^ permalink raw reply [flat|nested] 7+ messages in thread