Allow retrieving accessory detection reference on

Merge series from "Nícolas F. R. A. Prado" <nfraprado@collabora.com>:

This series enables the MT8188-MT6359 sound driver to retrieve the
MT6359 ACCDET sound component from a mediatek,accdet DT property, which
allows detecting jack insertion/removal.

Patch 1 describes the new property in the binding. Patch 2 implements
the sound component retrieval in the common MTK soundcard driver. Patch
4 updates the MT8188-MT6359 sound driver to register the audio jack and
initialize the ACCDET driver for detection, if the property is present.

Patch 3 adds a stub to prevent a linker failure in case the
MT6359-ACCDET config is disabled.

Tested on the Genio 700 EVK board.
This commit is contained in:
Mark Brown
2025-03-17 18:10:49 +00:00
5 changed files with 79 additions and 1 deletions

View File

@@ -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

View File

@@ -123,6 +123,15 @@ struct mt6359_accdet {
struct workqueue_struct *jd_workqueue;
};
#if IS_ENABLED(CONFIG_SND_SOC_MT6359_ACCDET)
int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
struct snd_soc_jack *jack);
#else
static inline int
mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
struct snd_soc_jack *jack)
{
return -EOPNOTSUPP;
}
#endif
#endif

View File

@@ -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;
};

View File

@@ -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,20 @@ 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 (accdet_node) {
accdet_pdev = of_find_device_by_node(accdet_node);
if (accdet_pdev) {
accdet_comp = snd_soc_lookup_component(&accdet_pdev->dev, NULL);
if (accdet_comp)
soc_card_data->accdet = accdet_comp;
else
dev_err(&pdev->dev, "No sound component found from mediatek,accdet property\n");
} else {
dev_err(&pdev->dev, "No device found from mediatek,accdet property\n");
}
}
platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
if (!platform_node)
return dev_err_probe(&pdev->dev, -EINVAL,

View File

@@ -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;
}