xref: /linux/sound/soc/mediatek/mt6797/mt6797-mt6351.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
14135d8b6SKai Chieh Chuang // SPDX-License-Identifier: GPL-2.0
24135d8b6SKai Chieh Chuang //
34135d8b6SKai Chieh Chuang // mt6797-mt6351.c  --  MT6797 MT6351 ALSA SoC machine driver
44135d8b6SKai Chieh Chuang //
54135d8b6SKai Chieh Chuang // Copyright (c) 2018 MediaTek Inc.
64135d8b6SKai Chieh Chuang // Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
7f0ab0bf2SKai Chieh Chuang 
8f0ab0bf2SKai Chieh Chuang #include <linux/module.h>
9f0ab0bf2SKai Chieh Chuang #include <sound/soc.h>
10f0ab0bf2SKai Chieh Chuang 
11f0ab0bf2SKai Chieh Chuang #include "mt6797-afe-common.h"
12f0ab0bf2SKai Chieh Chuang 
139ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(playback_1,
149ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
159ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
169ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
179ded5f71SKuninori Morimoto 
189ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(playback_2,
199ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
209ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
219ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
229ded5f71SKuninori Morimoto 
239ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(playback_3,
249ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
259ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
269ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
279ded5f71SKuninori Morimoto 
289ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture_1,
299ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
309ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
319ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
329ded5f71SKuninori Morimoto 
339ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture_2,
349ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
359ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
369ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
379ded5f71SKuninori Morimoto 
389ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture_3,
399ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
409ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
419ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
429ded5f71SKuninori Morimoto 
439ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture_mono_1,
449ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
459ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
469ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
479ded5f71SKuninori Morimoto 
489ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(hostless_lpbk,
499ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("Hostless LPBK DAI")),
509ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
519ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
529ded5f71SKuninori Morimoto 
539ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(hostless_speech,
549ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("Hostless Speech DAI")),
559ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
569ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
579ded5f71SKuninori Morimoto 
589ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(primary_codec,
599ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
609ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "mt6351-snd-codec-aif1")),
619ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
629ded5f71SKuninori Morimoto 
639ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(pcm1,
649ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
659ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
669ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
679ded5f71SKuninori Morimoto 
689ded5f71SKuninori Morimoto SND_SOC_DAILINK_DEFS(pcm2,
699ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
709ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
719ded5f71SKuninori Morimoto 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
729ded5f71SKuninori Morimoto 
73f0ab0bf2SKai Chieh Chuang static struct snd_soc_dai_link mt6797_mt6351_dai_links[] = {
74f0ab0bf2SKai Chieh Chuang 	/* FE */
75f0ab0bf2SKai Chieh Chuang 	{
76f0ab0bf2SKai Chieh Chuang 		.name = "Playback_1",
77f0ab0bf2SKai Chieh Chuang 		.stream_name = "Playback_1",
78f0ab0bf2SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
79f0ab0bf2SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
80f0ab0bf2SKai Chieh Chuang 		.dynamic = 1,
81f0ab0bf2SKai Chieh Chuang 		.dpcm_playback = 1,
829ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(playback_1),
83f0ab0bf2SKai Chieh Chuang 	},
84f0ab0bf2SKai Chieh Chuang 	{
85f0ab0bf2SKai Chieh Chuang 		.name = "Playback_2",
86f0ab0bf2SKai Chieh Chuang 		.stream_name = "Playback_2",
87f0ab0bf2SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
88f0ab0bf2SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
89f0ab0bf2SKai Chieh Chuang 		.dynamic = 1,
90f0ab0bf2SKai Chieh Chuang 		.dpcm_playback = 1,
919ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(playback_2),
92f0ab0bf2SKai Chieh Chuang 	},
93f0ab0bf2SKai Chieh Chuang 	{
94f0ab0bf2SKai Chieh Chuang 		.name = "Playback_3",
95f0ab0bf2SKai Chieh Chuang 		.stream_name = "Playback_3",
96f0ab0bf2SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
97f0ab0bf2SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
98f0ab0bf2SKai Chieh Chuang 		.dynamic = 1,
99f0ab0bf2SKai Chieh Chuang 		.dpcm_playback = 1,
1009ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(playback_3),
101f0ab0bf2SKai Chieh Chuang 	},
102f0ab0bf2SKai Chieh Chuang 	{
103f0ab0bf2SKai Chieh Chuang 		.name = "Capture_1",
104f0ab0bf2SKai Chieh Chuang 		.stream_name = "Capture_1",
105f0ab0bf2SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
106f0ab0bf2SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
107f0ab0bf2SKai Chieh Chuang 		.dynamic = 1,
108f0ab0bf2SKai Chieh Chuang 		.dpcm_capture = 1,
1099ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(capture_1),
110f0ab0bf2SKai Chieh Chuang 	},
111f0ab0bf2SKai Chieh Chuang 	{
112f0ab0bf2SKai Chieh Chuang 		.name = "Capture_2",
113f0ab0bf2SKai Chieh Chuang 		.stream_name = "Capture_2",
114f0ab0bf2SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
115f0ab0bf2SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
116f0ab0bf2SKai Chieh Chuang 		.dynamic = 1,
117f0ab0bf2SKai Chieh Chuang 		.dpcm_capture = 1,
1189ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(capture_2),
119f0ab0bf2SKai Chieh Chuang 	},
120f0ab0bf2SKai Chieh Chuang 	{
121f0ab0bf2SKai Chieh Chuang 		.name = "Capture_3",
122f0ab0bf2SKai Chieh Chuang 		.stream_name = "Capture_3",
123f0ab0bf2SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
124f0ab0bf2SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
125f0ab0bf2SKai Chieh Chuang 		.dynamic = 1,
126f0ab0bf2SKai Chieh Chuang 		.dpcm_capture = 1,
1279ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(capture_3),
128f0ab0bf2SKai Chieh Chuang 	},
129f0ab0bf2SKai Chieh Chuang 	{
130f0ab0bf2SKai Chieh Chuang 		.name = "Capture_Mono_1",
131f0ab0bf2SKai Chieh Chuang 		.stream_name = "Capture_Mono_1",
132f0ab0bf2SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
133f0ab0bf2SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
134f0ab0bf2SKai Chieh Chuang 		.dynamic = 1,
135f0ab0bf2SKai Chieh Chuang 		.dpcm_capture = 1,
1369ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(capture_mono_1),
137f0ab0bf2SKai Chieh Chuang 	},
138983333c0SKai Chieh Chuang 	{
139983333c0SKai Chieh Chuang 		.name = "Hostless_LPBK",
140983333c0SKai Chieh Chuang 		.stream_name = "Hostless_LPBK",
141983333c0SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
142983333c0SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
143983333c0SKai Chieh Chuang 		.dynamic = 1,
144983333c0SKai Chieh Chuang 		.dpcm_playback = 1,
145983333c0SKai Chieh Chuang 		.dpcm_capture = 1,
146983333c0SKai Chieh Chuang 		.ignore_suspend = 1,
1479ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(hostless_lpbk),
148983333c0SKai Chieh Chuang 	},
149983333c0SKai Chieh Chuang 	{
150983333c0SKai Chieh Chuang 		.name = "Hostless_Speech",
151983333c0SKai Chieh Chuang 		.stream_name = "Hostless_Speech",
152983333c0SKai Chieh Chuang 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
153983333c0SKai Chieh Chuang 			    SND_SOC_DPCM_TRIGGER_PRE},
154983333c0SKai Chieh Chuang 		.dynamic = 1,
155983333c0SKai Chieh Chuang 		.dpcm_playback = 1,
156983333c0SKai Chieh Chuang 		.dpcm_capture = 1,
157983333c0SKai Chieh Chuang 		.ignore_suspend = 1,
1589ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(hostless_speech),
159983333c0SKai Chieh Chuang 	},
160f0ab0bf2SKai Chieh Chuang 	/* BE */
161f0ab0bf2SKai Chieh Chuang 	{
162f0ab0bf2SKai Chieh Chuang 		.name = "Primary Codec",
163f0ab0bf2SKai Chieh Chuang 		.no_pcm = 1,
164f0ab0bf2SKai Chieh Chuang 		.dpcm_playback = 1,
165f0ab0bf2SKai Chieh Chuang 		.dpcm_capture = 1,
166f0ab0bf2SKai Chieh Chuang 		.ignore_suspend = 1,
1679ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(primary_codec),
168f0ab0bf2SKai Chieh Chuang 	},
169983333c0SKai Chieh Chuang 	{
170983333c0SKai Chieh Chuang 		.name = "PCM 1",
171983333c0SKai Chieh Chuang 		.no_pcm = 1,
172983333c0SKai Chieh Chuang 		.dpcm_playback = 1,
173983333c0SKai Chieh Chuang 		.dpcm_capture = 1,
174983333c0SKai Chieh Chuang 		.ignore_suspend = 1,
1759ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(pcm1),
176983333c0SKai Chieh Chuang 	},
177983333c0SKai Chieh Chuang 	{
178983333c0SKai Chieh Chuang 		.name = "PCM 2",
179983333c0SKai Chieh Chuang 		.no_pcm = 1,
180983333c0SKai Chieh Chuang 		.dpcm_playback = 1,
181983333c0SKai Chieh Chuang 		.dpcm_capture = 1,
182983333c0SKai Chieh Chuang 		.ignore_suspend = 1,
1839ded5f71SKuninori Morimoto 		SND_SOC_DAILINK_REG(pcm2),
184983333c0SKai Chieh Chuang 	},
185f0ab0bf2SKai Chieh Chuang };
186f0ab0bf2SKai Chieh Chuang 
187f0ab0bf2SKai Chieh Chuang static struct snd_soc_card mt6797_mt6351_card = {
188f0ab0bf2SKai Chieh Chuang 	.name = "mt6797-mt6351",
189f0ab0bf2SKai Chieh Chuang 	.owner = THIS_MODULE,
190f0ab0bf2SKai Chieh Chuang 	.dai_link = mt6797_mt6351_dai_links,
191f0ab0bf2SKai Chieh Chuang 	.num_links = ARRAY_SIZE(mt6797_mt6351_dai_links),
192f0ab0bf2SKai Chieh Chuang };
193f0ab0bf2SKai Chieh Chuang 
mt6797_mt6351_dev_probe(struct platform_device * pdev)194f0ab0bf2SKai Chieh Chuang static int mt6797_mt6351_dev_probe(struct platform_device *pdev)
195f0ab0bf2SKai Chieh Chuang {
196f0ab0bf2SKai Chieh Chuang 	struct snd_soc_card *card = &mt6797_mt6351_card;
197f0ab0bf2SKai Chieh Chuang 	struct device_node *platform_node, *codec_node;
1987fe072b4SKuninori Morimoto 	struct snd_soc_dai_link *dai_link;
199f0ab0bf2SKai Chieh Chuang 	int ret, i;
200f0ab0bf2SKai Chieh Chuang 
201f0ab0bf2SKai Chieh Chuang 	card->dev = &pdev->dev;
202f0ab0bf2SKai Chieh Chuang 
203f0ab0bf2SKai Chieh Chuang 	platform_node = of_parse_phandle(pdev->dev.of_node,
204f0ab0bf2SKai Chieh Chuang 					 "mediatek,platform", 0);
205f0ab0bf2SKai Chieh Chuang 	if (!platform_node) {
206f0ab0bf2SKai Chieh Chuang 		dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
207f0ab0bf2SKai Chieh Chuang 		return -EINVAL;
208f0ab0bf2SKai Chieh Chuang 	}
2097fe072b4SKuninori Morimoto 	for_each_card_prelinks(card, i, dai_link) {
2109ded5f71SKuninori Morimoto 		if (dai_link->platforms->name)
211f0ab0bf2SKai Chieh Chuang 			continue;
2129ded5f71SKuninori Morimoto 		dai_link->platforms->of_node = platform_node;
213f0ab0bf2SKai Chieh Chuang 	}
214f0ab0bf2SKai Chieh Chuang 
215f0ab0bf2SKai Chieh Chuang 	codec_node = of_parse_phandle(pdev->dev.of_node,
216f0ab0bf2SKai Chieh Chuang 				      "mediatek,audio-codec", 0);
217f0ab0bf2SKai Chieh Chuang 	if (!codec_node) {
218f0ab0bf2SKai Chieh Chuang 		dev_err(&pdev->dev,
219f0ab0bf2SKai Chieh Chuang 			"Property 'audio-codec' missing or invalid\n");
2207472eb8dSMiaoqian Lin 		ret = -EINVAL;
2217472eb8dSMiaoqian Lin 		goto put_platform_node;
222f0ab0bf2SKai Chieh Chuang 	}
2237fe072b4SKuninori Morimoto 	for_each_card_prelinks(card, i, dai_link) {
2249ded5f71SKuninori Morimoto 		if (dai_link->codecs->name)
225f0ab0bf2SKai Chieh Chuang 			continue;
2269ded5f71SKuninori Morimoto 		dai_link->codecs->of_node = codec_node;
227f0ab0bf2SKai Chieh Chuang 	}
228f0ab0bf2SKai Chieh Chuang 
229f0ab0bf2SKai Chieh Chuang 	ret = devm_snd_soc_register_card(&pdev->dev, card);
230f0ab0bf2SKai Chieh Chuang 	if (ret)
231f0ab0bf2SKai Chieh Chuang 		dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
232f0ab0bf2SKai Chieh Chuang 			__func__, ret);
233f0ab0bf2SKai Chieh Chuang 
2347472eb8dSMiaoqian Lin 	of_node_put(codec_node);
2357472eb8dSMiaoqian Lin put_platform_node:
2367472eb8dSMiaoqian Lin 	of_node_put(platform_node);
237f0ab0bf2SKai Chieh Chuang 	return ret;
238f0ab0bf2SKai Chieh Chuang }
239f0ab0bf2SKai Chieh Chuang 
240f0ab0bf2SKai Chieh Chuang #ifdef CONFIG_OF
241f0ab0bf2SKai Chieh Chuang static const struct of_device_id mt6797_mt6351_dt_match[] = {
242f0ab0bf2SKai Chieh Chuang 	{.compatible = "mediatek,mt6797-mt6351-sound",},
243f0ab0bf2SKai Chieh Chuang 	{}
244f0ab0bf2SKai Chieh Chuang };
245*083e9480SNícolas F. R. A. Prado MODULE_DEVICE_TABLE(of, mt6797_mt6351_dt_match);
246f0ab0bf2SKai Chieh Chuang #endif
247f0ab0bf2SKai Chieh Chuang 
248f0ab0bf2SKai Chieh Chuang static struct platform_driver mt6797_mt6351_driver = {
249f0ab0bf2SKai Chieh Chuang 	.driver = {
250f0ab0bf2SKai Chieh Chuang 		.name = "mt6797-mt6351",
251f0ab0bf2SKai Chieh Chuang #ifdef CONFIG_OF
252f0ab0bf2SKai Chieh Chuang 		.of_match_table = mt6797_mt6351_dt_match,
253f0ab0bf2SKai Chieh Chuang #endif
254f0ab0bf2SKai Chieh Chuang 	},
255f0ab0bf2SKai Chieh Chuang 	.probe = mt6797_mt6351_dev_probe,
256f0ab0bf2SKai Chieh Chuang };
257f0ab0bf2SKai Chieh Chuang 
258f0ab0bf2SKai Chieh Chuang module_platform_driver(mt6797_mt6351_driver);
259f0ab0bf2SKai Chieh Chuang 
260f0ab0bf2SKai Chieh Chuang /* Module information */
261f0ab0bf2SKai Chieh Chuang MODULE_DESCRIPTION("MT6797 MT6351 ALSA SoC machine driver");
262f0ab0bf2SKai Chieh Chuang MODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>");
263f0ab0bf2SKai Chieh Chuang MODULE_LICENSE("GPL v2");
264f0ab0bf2SKai Chieh Chuang MODULE_ALIAS("mt6797 mt6351 soc card");
265f0ab0bf2SKai Chieh Chuang 
266