1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // mt6797-mt6351.c  --  MT6797 MT6351 ALSA SoC machine driver
4 //
5 // Copyright (c) 2018 MediaTek Inc.
6 // Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
7 
8 #include <linux/module.h>
9 #include <sound/soc.h>
10 
11 #include "mt6797-afe-common.h"
12 
13 static struct snd_soc_dai_link mt6797_mt6351_dai_links[] = {
14 	/* FE */
15 	{
16 		.name = "Playback_1",
17 		.stream_name = "Playback_1",
18 		.cpu_dai_name = "DL1",
19 		.codec_name = "snd-soc-dummy",
20 		.codec_dai_name = "snd-soc-dummy-dai",
21 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
22 			    SND_SOC_DPCM_TRIGGER_PRE},
23 		.dynamic = 1,
24 		.dpcm_playback = 1,
25 	},
26 	{
27 		.name = "Playback_2",
28 		.stream_name = "Playback_2",
29 		.cpu_dai_name = "DL2",
30 		.codec_name = "snd-soc-dummy",
31 		.codec_dai_name = "snd-soc-dummy-dai",
32 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
33 			    SND_SOC_DPCM_TRIGGER_PRE},
34 		.dynamic = 1,
35 		.dpcm_playback = 1,
36 	},
37 	{
38 		.name = "Playback_3",
39 		.stream_name = "Playback_3",
40 		.cpu_dai_name = "DL3",
41 		.codec_name = "snd-soc-dummy",
42 		.codec_dai_name = "snd-soc-dummy-dai",
43 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
44 			    SND_SOC_DPCM_TRIGGER_PRE},
45 		.dynamic = 1,
46 		.dpcm_playback = 1,
47 	},
48 	{
49 		.name = "Capture_1",
50 		.stream_name = "Capture_1",
51 		.cpu_dai_name = "UL1",
52 		.codec_name = "snd-soc-dummy",
53 		.codec_dai_name = "snd-soc-dummy-dai",
54 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
55 			    SND_SOC_DPCM_TRIGGER_PRE},
56 		.dynamic = 1,
57 		.dpcm_capture = 1,
58 	},
59 	{
60 		.name = "Capture_2",
61 		.stream_name = "Capture_2",
62 		.cpu_dai_name = "UL2",
63 		.codec_name = "snd-soc-dummy",
64 		.codec_dai_name = "snd-soc-dummy-dai",
65 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
66 			    SND_SOC_DPCM_TRIGGER_PRE},
67 		.dynamic = 1,
68 		.dpcm_capture = 1,
69 	},
70 	{
71 		.name = "Capture_3",
72 		.stream_name = "Capture_3",
73 		.cpu_dai_name = "UL3",
74 		.codec_name = "snd-soc-dummy",
75 		.codec_dai_name = "snd-soc-dummy-dai",
76 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
77 			    SND_SOC_DPCM_TRIGGER_PRE},
78 		.dynamic = 1,
79 		.dpcm_capture = 1,
80 	},
81 	{
82 		.name = "Capture_Mono_1",
83 		.stream_name = "Capture_Mono_1",
84 		.cpu_dai_name = "UL_MONO_1",
85 		.codec_name = "snd-soc-dummy",
86 		.codec_dai_name = "snd-soc-dummy-dai",
87 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
88 			    SND_SOC_DPCM_TRIGGER_PRE},
89 		.dynamic = 1,
90 		.dpcm_capture = 1,
91 	},
92 	{
93 		.name = "Hostless_LPBK",
94 		.stream_name = "Hostless_LPBK",
95 		.cpu_dai_name = "Hostless LPBK DAI",
96 		.codec_name = "snd-soc-dummy",
97 		.codec_dai_name = "snd-soc-dummy-dai",
98 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
99 			    SND_SOC_DPCM_TRIGGER_PRE},
100 		.dynamic = 1,
101 		.dpcm_playback = 1,
102 		.dpcm_capture = 1,
103 		.ignore_suspend = 1,
104 	},
105 	{
106 		.name = "Hostless_Speech",
107 		.stream_name = "Hostless_Speech",
108 		.cpu_dai_name = "Hostless Speech DAI",
109 		.codec_name = "snd-soc-dummy",
110 		.codec_dai_name = "snd-soc-dummy-dai",
111 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
112 			    SND_SOC_DPCM_TRIGGER_PRE},
113 		.dynamic = 1,
114 		.dpcm_playback = 1,
115 		.dpcm_capture = 1,
116 		.ignore_suspend = 1,
117 	},
118 	/* BE */
119 	{
120 		.name = "Primary Codec",
121 		.cpu_dai_name = "ADDA",
122 		.codec_dai_name = "mt6351-snd-codec-aif1",
123 		.no_pcm = 1,
124 		.dpcm_playback = 1,
125 		.dpcm_capture = 1,
126 		.ignore_suspend = 1,
127 	},
128 	{
129 		.name = "PCM 1",
130 		.cpu_dai_name = "PCM 1",
131 		.codec_name = "snd-soc-dummy",
132 		.codec_dai_name = "snd-soc-dummy-dai",
133 		.no_pcm = 1,
134 		.dpcm_playback = 1,
135 		.dpcm_capture = 1,
136 		.ignore_suspend = 1,
137 	},
138 	{
139 		.name = "PCM 2",
140 		.cpu_dai_name = "PCM 2",
141 		.codec_name = "snd-soc-dummy",
142 		.codec_dai_name = "snd-soc-dummy-dai",
143 		.no_pcm = 1,
144 		.dpcm_playback = 1,
145 		.dpcm_capture = 1,
146 		.ignore_suspend = 1,
147 	},
148 };
149 
150 static struct snd_soc_card mt6797_mt6351_card = {
151 	.name = "mt6797-mt6351",
152 	.owner = THIS_MODULE,
153 	.dai_link = mt6797_mt6351_dai_links,
154 	.num_links = ARRAY_SIZE(mt6797_mt6351_dai_links),
155 };
156 
157 static int mt6797_mt6351_dev_probe(struct platform_device *pdev)
158 {
159 	struct snd_soc_card *card = &mt6797_mt6351_card;
160 	struct device_node *platform_node, *codec_node;
161 	struct snd_soc_dai_link *dai_link;
162 	int ret, i;
163 
164 	card->dev = &pdev->dev;
165 
166 	platform_node = of_parse_phandle(pdev->dev.of_node,
167 					 "mediatek,platform", 0);
168 	if (!platform_node) {
169 		dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
170 		return -EINVAL;
171 	}
172 	for_each_card_prelinks(card, i, dai_link) {
173 		if (dai_link->platform_name)
174 			continue;
175 		dai_link->platform_of_node = platform_node;
176 	}
177 
178 	codec_node = of_parse_phandle(pdev->dev.of_node,
179 				      "mediatek,audio-codec", 0);
180 	if (!codec_node) {
181 		dev_err(&pdev->dev,
182 			"Property 'audio-codec' missing or invalid\n");
183 		return -EINVAL;
184 	}
185 	for_each_card_prelinks(card, i, dai_link) {
186 		if (dai_link->codec_name)
187 			continue;
188 		dai_link->codec_of_node = codec_node;
189 	}
190 
191 	ret = devm_snd_soc_register_card(&pdev->dev, card);
192 	if (ret)
193 		dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
194 			__func__, ret);
195 
196 	return ret;
197 }
198 
199 #ifdef CONFIG_OF
200 static const struct of_device_id mt6797_mt6351_dt_match[] = {
201 	{.compatible = "mediatek,mt6797-mt6351-sound",},
202 	{}
203 };
204 #endif
205 
206 static struct platform_driver mt6797_mt6351_driver = {
207 	.driver = {
208 		.name = "mt6797-mt6351",
209 #ifdef CONFIG_OF
210 		.of_match_table = mt6797_mt6351_dt_match,
211 #endif
212 	},
213 	.probe = mt6797_mt6351_dev_probe,
214 };
215 
216 module_platform_driver(mt6797_mt6351_driver);
217 
218 /* Module information */
219 MODULE_DESCRIPTION("MT6797 MT6351 ALSA SoC machine driver");
220 MODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>");
221 MODULE_LICENSE("GPL v2");
222 MODULE_ALIAS("mt6797 mt6351 soc card");
223 
224