Skip to content

Commit b9d98ae

Browse files
committed
Allow retrieving accessory detection reference on
Merge series from "Nícolas F. R. A. Prado" <[email protected]>: 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.
2 parents 18abb37 + f35d834 commit b9d98ae

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ properties:
4040
hardware that provides additional audio functionalities if present.
4141
The AFE will link to ADSP when the phandle is provided.
4242

43+
mediatek,accdet:
44+
$ref: /schemas/types.yaml#/definitions/phandle
45+
description:
46+
The phandle to the MT6359 accessory detection block, which detects audio
47+
jack insertion and removal. This property should only be present if the
48+
accdet block is actually wired to the audio jack pins and to be used for
49+
jack detection.
50+
4351
patternProperties:
4452
"^dai-link-[0-9]+$":
4553
type: object

sound/soc/codecs/mt6359-accdet.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ struct mt6359_accdet {
123123
struct workqueue_struct *jd_workqueue;
124124
};
125125

126+
#if IS_ENABLED(CONFIG_SND_SOC_MT6359_ACCDET)
126127
int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
127128
struct snd_soc_jack *jack);
129+
#else
130+
static inline int
131+
mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
132+
struct snd_soc_jack *jack)
133+
{
134+
return -EOPNOTSUPP;
135+
}
136+
#endif
128137
#endif

sound/soc/mediatek/common/mtk-soc-card.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct mtk_soc_card_data {
1616
const struct mtk_sof_priv *sof_priv;
1717
struct list_head sof_dai_link_list;
1818
struct mtk_platform_card_data *card_data;
19+
struct snd_soc_component *accdet;
1920
void *mach_priv;
2021
};
2122

sound/soc/mediatek/common/mtk-soundcard-driver.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/module.h>
1010
#include <linux/of.h>
11+
#include <linux/of_platform.h>
1112
#include <sound/soc.h>
1213

1314
#include "mtk-dsp-sof-common.h"
@@ -192,7 +193,9 @@ EXPORT_SYMBOL_GPL(mtk_soundcard_common_capture_ops);
192193

193194
int mtk_soundcard_common_probe(struct platform_device *pdev)
194195
{
195-
struct device_node *platform_node, *adsp_node;
196+
struct device_node *platform_node, *adsp_node, *accdet_node;
197+
struct snd_soc_component *accdet_comp;
198+
struct platform_device *accdet_pdev;
196199
const struct mtk_soundcard_pdata *pdata;
197200
struct mtk_soc_card_data *soc_card_data;
198201
struct snd_soc_dai_link *orig_dai_link, *dai_link;
@@ -250,6 +253,20 @@ int mtk_soundcard_common_probe(struct platform_device *pdev)
250253

251254
soc_card_data->card_data->jacks = jacks;
252255

256+
accdet_node = of_parse_phandle(pdev->dev.of_node, "mediatek,accdet", 0);
257+
if (accdet_node) {
258+
accdet_pdev = of_find_device_by_node(accdet_node);
259+
if (accdet_pdev) {
260+
accdet_comp = snd_soc_lookup_component(&accdet_pdev->dev, NULL);
261+
if (accdet_comp)
262+
soc_card_data->accdet = accdet_comp;
263+
else
264+
dev_err(&pdev->dev, "No sound component found from mediatek,accdet property\n");
265+
} else {
266+
dev_err(&pdev->dev, "No device found from mediatek,accdet property\n");
267+
}
268+
}
269+
253270
platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
254271
if (!platform_node)
255272
return dev_err_probe(&pdev->dev, -EINVAL,

sound/soc/mediatek/mt8188/mt8188-mt6359.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mt8188-afe-common.h"
1818
#include "../../codecs/nau8825.h"
1919
#include "../../codecs/mt6359.h"
20+
#include "../../codecs/mt6359-accdet.h"
2021
#include "../../codecs/rt5682.h"
2122
#include "../common/mtk-afe-platform-driver.h"
2223
#include "../common/mtk-soundcard-driver.h"
@@ -271,6 +272,17 @@ static struct snd_soc_jack_pin nau8825_jack_pins[] = {
271272
},
272273
};
273274

275+
static struct snd_soc_jack_pin mt8188_headset_jack_pins[] = {
276+
{
277+
.pin = "Headphone",
278+
.mask = SND_JACK_HEADPHONE,
279+
},
280+
{
281+
.pin = "Headset Mic",
282+
.mask = SND_JACK_MICROPHONE,
283+
},
284+
};
285+
274286
static const struct snd_kcontrol_new mt8188_dumb_spk_controls[] = {
275287
SOC_DAPM_PIN_SWITCH("Ext Spk"),
276288
};
@@ -506,6 +518,35 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
506518
return 0;
507519
}
508520

521+
static int mt8188_mt6359_accdet_init(struct snd_soc_pcm_runtime *rtd)
522+
{
523+
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
524+
struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET];
525+
int ret;
526+
527+
if (!soc_card_data->accdet)
528+
return 0;
529+
530+
ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
531+
SND_JACK_HEADSET | SND_JACK_BTN_0 |
532+
SND_JACK_BTN_1 | SND_JACK_BTN_2 |
533+
SND_JACK_BTN_3,
534+
jack, mt8188_headset_jack_pins,
535+
ARRAY_SIZE(mt8188_headset_jack_pins));
536+
if (ret) {
537+
dev_err(rtd->dev, "Headset Jack create failed: %d\n", ret);
538+
return ret;
539+
}
540+
541+
ret = mt6359_accdet_enable_jack_detect(soc_card_data->accdet, jack);
542+
if (ret) {
543+
dev_err(rtd->dev, "Headset Jack enable failed: %d\n", ret);
544+
return ret;
545+
}
546+
547+
return 0;
548+
}
549+
509550
static int mt8188_mt6359_init(struct snd_soc_pcm_runtime *rtd)
510551
{
511552
struct snd_soc_component *cmpnt_codec =
@@ -518,6 +559,8 @@ static int mt8188_mt6359_init(struct snd_soc_pcm_runtime *rtd)
518559
/* mtkaif calibration */
519560
mt8188_mt6359_mtkaif_calibration(rtd);
520561

562+
mt8188_mt6359_accdet_init(rtd);
563+
521564
return 0;
522565
}
523566

0 commit comments

Comments
 (0)