Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/sound/soc/mediatek/mt6797/mt6797-mt6351.c
26488 views
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 <[email protected]>
7
8
#include <linux/module.h>
9
#include <sound/soc.h>
10
11
#include "mt6797-afe-common.h"
12
13
SND_SOC_DAILINK_DEFS(playback_1,
14
DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
15
DAILINK_COMP_ARRAY(COMP_DUMMY()),
16
DAILINK_COMP_ARRAY(COMP_EMPTY()));
17
18
SND_SOC_DAILINK_DEFS(playback_2,
19
DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
20
DAILINK_COMP_ARRAY(COMP_DUMMY()),
21
DAILINK_COMP_ARRAY(COMP_EMPTY()));
22
23
SND_SOC_DAILINK_DEFS(playback_3,
24
DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
25
DAILINK_COMP_ARRAY(COMP_DUMMY()),
26
DAILINK_COMP_ARRAY(COMP_EMPTY()));
27
28
SND_SOC_DAILINK_DEFS(capture_1,
29
DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
30
DAILINK_COMP_ARRAY(COMP_DUMMY()),
31
DAILINK_COMP_ARRAY(COMP_EMPTY()));
32
33
SND_SOC_DAILINK_DEFS(capture_2,
34
DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
35
DAILINK_COMP_ARRAY(COMP_DUMMY()),
36
DAILINK_COMP_ARRAY(COMP_EMPTY()));
37
38
SND_SOC_DAILINK_DEFS(capture_3,
39
DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
40
DAILINK_COMP_ARRAY(COMP_DUMMY()),
41
DAILINK_COMP_ARRAY(COMP_EMPTY()));
42
43
SND_SOC_DAILINK_DEFS(capture_mono_1,
44
DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
45
DAILINK_COMP_ARRAY(COMP_DUMMY()),
46
DAILINK_COMP_ARRAY(COMP_EMPTY()));
47
48
SND_SOC_DAILINK_DEFS(hostless_lpbk,
49
DAILINK_COMP_ARRAY(COMP_CPU("Hostless LPBK DAI")),
50
DAILINK_COMP_ARRAY(COMP_DUMMY()),
51
DAILINK_COMP_ARRAY(COMP_EMPTY()));
52
53
SND_SOC_DAILINK_DEFS(hostless_speech,
54
DAILINK_COMP_ARRAY(COMP_CPU("Hostless Speech DAI")),
55
DAILINK_COMP_ARRAY(COMP_DUMMY()),
56
DAILINK_COMP_ARRAY(COMP_EMPTY()));
57
58
SND_SOC_DAILINK_DEFS(primary_codec,
59
DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
60
DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "mt6351-snd-codec-aif1")),
61
DAILINK_COMP_ARRAY(COMP_EMPTY()));
62
63
SND_SOC_DAILINK_DEFS(pcm1,
64
DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
65
DAILINK_COMP_ARRAY(COMP_DUMMY()),
66
DAILINK_COMP_ARRAY(COMP_EMPTY()));
67
68
SND_SOC_DAILINK_DEFS(pcm2,
69
DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
70
DAILINK_COMP_ARRAY(COMP_DUMMY()),
71
DAILINK_COMP_ARRAY(COMP_EMPTY()));
72
73
static struct snd_soc_dai_link mt6797_mt6351_dai_links[] = {
74
/* FE */
75
{
76
.name = "Playback_1",
77
.stream_name = "Playback_1",
78
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
79
SND_SOC_DPCM_TRIGGER_PRE},
80
.dynamic = 1,
81
.playback_only = 1,
82
SND_SOC_DAILINK_REG(playback_1),
83
},
84
{
85
.name = "Playback_2",
86
.stream_name = "Playback_2",
87
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
88
SND_SOC_DPCM_TRIGGER_PRE},
89
.dynamic = 1,
90
.playback_only = 1,
91
SND_SOC_DAILINK_REG(playback_2),
92
},
93
{
94
.name = "Playback_3",
95
.stream_name = "Playback_3",
96
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
97
SND_SOC_DPCM_TRIGGER_PRE},
98
.dynamic = 1,
99
.playback_only = 1,
100
SND_SOC_DAILINK_REG(playback_3),
101
},
102
{
103
.name = "Capture_1",
104
.stream_name = "Capture_1",
105
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
106
SND_SOC_DPCM_TRIGGER_PRE},
107
.dynamic = 1,
108
.capture_only = 1,
109
SND_SOC_DAILINK_REG(capture_1),
110
},
111
{
112
.name = "Capture_2",
113
.stream_name = "Capture_2",
114
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
115
SND_SOC_DPCM_TRIGGER_PRE},
116
.dynamic = 1,
117
.capture_only = 1,
118
SND_SOC_DAILINK_REG(capture_2),
119
},
120
{
121
.name = "Capture_3",
122
.stream_name = "Capture_3",
123
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
124
SND_SOC_DPCM_TRIGGER_PRE},
125
.dynamic = 1,
126
.capture_only = 1,
127
SND_SOC_DAILINK_REG(capture_3),
128
},
129
{
130
.name = "Capture_Mono_1",
131
.stream_name = "Capture_Mono_1",
132
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
133
SND_SOC_DPCM_TRIGGER_PRE},
134
.dynamic = 1,
135
.capture_only = 1,
136
SND_SOC_DAILINK_REG(capture_mono_1),
137
},
138
{
139
.name = "Hostless_LPBK",
140
.stream_name = "Hostless_LPBK",
141
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
142
SND_SOC_DPCM_TRIGGER_PRE},
143
.dynamic = 1,
144
.ignore_suspend = 1,
145
SND_SOC_DAILINK_REG(hostless_lpbk),
146
},
147
{
148
.name = "Hostless_Speech",
149
.stream_name = "Hostless_Speech",
150
.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
151
SND_SOC_DPCM_TRIGGER_PRE},
152
.dynamic = 1,
153
.ignore_suspend = 1,
154
SND_SOC_DAILINK_REG(hostless_speech),
155
},
156
/* BE */
157
{
158
.name = "Primary Codec",
159
.no_pcm = 1,
160
.ignore_suspend = 1,
161
SND_SOC_DAILINK_REG(primary_codec),
162
},
163
{
164
.name = "PCM 1",
165
.no_pcm = 1,
166
.ignore_suspend = 1,
167
SND_SOC_DAILINK_REG(pcm1),
168
},
169
{
170
.name = "PCM 2",
171
.no_pcm = 1,
172
.ignore_suspend = 1,
173
SND_SOC_DAILINK_REG(pcm2),
174
},
175
};
176
177
static struct snd_soc_card mt6797_mt6351_card = {
178
.name = "mt6797-mt6351",
179
.owner = THIS_MODULE,
180
.dai_link = mt6797_mt6351_dai_links,
181
.num_links = ARRAY_SIZE(mt6797_mt6351_dai_links),
182
};
183
184
static int mt6797_mt6351_dev_probe(struct platform_device *pdev)
185
{
186
struct snd_soc_card *card = &mt6797_mt6351_card;
187
struct device_node *platform_node, *codec_node;
188
struct snd_soc_dai_link *dai_link;
189
int ret, i;
190
191
card->dev = &pdev->dev;
192
193
platform_node = of_parse_phandle(pdev->dev.of_node,
194
"mediatek,platform", 0);
195
if (!platform_node) {
196
dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
197
return -EINVAL;
198
}
199
for_each_card_prelinks(card, i, dai_link) {
200
if (dai_link->platforms->name)
201
continue;
202
dai_link->platforms->of_node = platform_node;
203
}
204
205
codec_node = of_parse_phandle(pdev->dev.of_node,
206
"mediatek,audio-codec", 0);
207
if (!codec_node) {
208
dev_err(&pdev->dev,
209
"Property 'audio-codec' missing or invalid\n");
210
ret = -EINVAL;
211
goto put_platform_node;
212
}
213
for_each_card_prelinks(card, i, dai_link) {
214
if (dai_link->codecs->name)
215
continue;
216
dai_link->codecs->of_node = codec_node;
217
}
218
219
ret = devm_snd_soc_register_card(&pdev->dev, card);
220
if (ret)
221
dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
222
__func__, ret);
223
224
of_node_put(codec_node);
225
put_platform_node:
226
of_node_put(platform_node);
227
return ret;
228
}
229
230
#ifdef CONFIG_OF
231
static const struct of_device_id mt6797_mt6351_dt_match[] = {
232
{.compatible = "mediatek,mt6797-mt6351-sound",},
233
{}
234
};
235
MODULE_DEVICE_TABLE(of, mt6797_mt6351_dt_match);
236
#endif
237
238
static struct platform_driver mt6797_mt6351_driver = {
239
.driver = {
240
.name = "mt6797-mt6351",
241
#ifdef CONFIG_OF
242
.of_match_table = mt6797_mt6351_dt_match,
243
#endif
244
},
245
.probe = mt6797_mt6351_dev_probe,
246
};
247
248
module_platform_driver(mt6797_mt6351_driver);
249
250
/* Module information */
251
MODULE_DESCRIPTION("MT6797 MT6351 ALSA SoC machine driver");
252
MODULE_AUTHOR("KaiChieh Chuang <[email protected]>");
253
MODULE_LICENSE("GPL v2");
254
MODULE_ALIAS("mt6797 mt6351 soc card");
255
256
257