1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
// SPDX-License-Identifier: GPL-2.0
//
// MediaTek ALSA SoC Audio Control
//
// Copyright (c) 2022 MediaTek Inc.
// Author: Jiaxin Yu <jiaxin.yu@mediatek.com>
#include "mt8186-afe-common.h"
#include <linux/pm_runtime.h>
enum {
MTK_AFE_RATE_8K = 0,
MTK_AFE_RATE_11K,
MTK_AFE_RATE_12K,
MTK_AFE_RATE_384K,
MTK_AFE_RATE_16K,
MTK_AFE_RATE_22K,
MTK_AFE_RATE_24K,
MTK_AFE_RATE_352K,
MTK_AFE_RATE_32K,
MTK_AFE_RATE_44K,
MTK_AFE_RATE_48K,
MTK_AFE_RATE_88K,
MTK_AFE_RATE_96K,
MTK_AFE_RATE_176K,
MTK_AFE_RATE_192K,
MTK_AFE_RATE_260K,
};
enum {
MTK_AFE_PCM_RATE_8K = 0,
MTK_AFE_PCM_RATE_16K,
MTK_AFE_PCM_RATE_32K,
MTK_AFE_PCM_RATE_48K,
};
enum {
MTK_AFE_TDM_RATE_8K = 0,
MTK_AFE_TDM_RATE_12K,
MTK_AFE_TDM_RATE_16K,
MTK_AFE_TDM_RATE_24K,
MTK_AFE_TDM_RATE_32K,
MTK_AFE_TDM_RATE_48K,
MTK_AFE_TDM_RATE_64K,
MTK_AFE_TDM_RATE_96K,
MTK_AFE_TDM_RATE_128K,
MTK_AFE_TDM_RATE_192K,
MTK_AFE_TDM_RATE_256K,
MTK_AFE_TDM_RATE_384K,
MTK_AFE_TDM_RATE_11K,
MTK_AFE_TDM_RATE_22K,
MTK_AFE_TDM_RATE_44K,
MTK_AFE_TDM_RATE_88K,
MTK_AFE_TDM_RATE_176K,
MTK_AFE_TDM_RATE_352K,
};
enum {
MTK_AFE_TDM_RELATCH_RATE_8K = 0,
MTK_AFE_TDM_RELATCH_RATE_11K,
MTK_AFE_TDM_RELATCH_RATE_12K,
MTK_AFE_TDM_RELATCH_RATE_16K,
MTK_AFE_TDM_RELATCH_RATE_22K,
MTK_AFE_TDM_RELATCH_RATE_24K,
MTK_AFE_TDM_RELATCH_RATE_32K,
MTK_AFE_TDM_RELATCH_RATE_44K,
MTK_AFE_TDM_RELATCH_RATE_48K,
MTK_AFE_TDM_RELATCH_RATE_88K,
MTK_AFE_TDM_RELATCH_RATE_96K,
MTK_AFE_TDM_RELATCH_RATE_176K,
MTK_AFE_TDM_RELATCH_RATE_192K,
MTK_AFE_TDM_RELATCH_RATE_352K,
MTK_AFE_TDM_RELATCH_RATE_384K,
};
unsigned int mt8186_general_rate_transform(struct device *dev, unsigned int rate)
{
switch (rate) {
case 8000:
return MTK_AFE_RATE_8K;
case 11025:
return MTK_AFE_RATE_11K;
case 12000:
return MTK_AFE_RATE_12K;
case 16000:
return MTK_AFE_RATE_16K;
case 22050:
return MTK_AFE_RATE_22K;
case 24000:
return MTK_AFE_RATE_24K;
case 32000:
return MTK_AFE_RATE_32K;
case 44100:
return MTK_AFE_RATE_44K;
case 48000:
return MTK_AFE_RATE_48K;
case 88200:
return MTK_AFE_RATE_88K;
case 96000:
return MTK_AFE_RATE_96K;
case 176400:
return MTK_AFE_RATE_176K;
case 192000:
return MTK_AFE_RATE_192K;
case 260000:
return MTK_AFE_RATE_260K;
case 352800:
return MTK_AFE_RATE_352K;
case 384000:
return MTK_AFE_RATE_384K;
default:
dev_err(dev, "%s(), rate %u invalid, use %d!!!\n",
__func__, rate, MTK_AFE_RATE_48K);
}
return MTK_AFE_RATE_48K;
}
static unsigned int tdm_rate_transform(struct device *dev, unsigned int rate)
{
switch (rate) {
case 8000:
return MTK_AFE_TDM_RATE_8K;
case 11025:
return MTK_AFE_TDM_RATE_11K;
case 12000:
return MTK_AFE_TDM_RATE_12K;
case 16000:
return MTK_AFE_TDM_RATE_16K;
case 22050:
return MTK_AFE_TDM_RATE_22K;
case 24000:
return MTK_AFE_TDM_RATE_24K;
case 32000:
return MTK_AFE_TDM_RATE_32K;
case 44100:
return MTK_AFE_TDM_RATE_44K;
case 48000:
return MTK_AFE_TDM_RATE_48K;
case 64000:
return MTK_AFE_TDM_RATE_64K;
case 88200:
return MTK_AFE_TDM_RATE_88K;
case 96000:
return MTK_AFE_TDM_RATE_96K;
case 128000:
return MTK_AFE_TDM_RATE_128K;
case 176400:
return MTK_AFE_TDM_RATE_176K;
case 192000:
return MTK_AFE_TDM_RATE_192K;
case 256000:
return MTK_AFE_TDM_RATE_256K;
case 352800:
return MTK_AFE_TDM_RATE_352K;
case 384000:
return MTK_AFE_TDM_RATE_384K;
default:
dev_err(dev, "%s(), rate %u invalid, use %d!!!\n",
__func__, rate, MTK_AFE_TDM_RATE_48K);
}
return MTK_AFE_TDM_RATE_48K;
}
static unsigned int pcm_rate_transform(struct device *dev, unsigned int rate)
{
switch (rate) {
case 8000:
return MTK_AFE_PCM_RATE_8K;
case 16000:
return MTK_AFE_PCM_RATE_16K;
case 32000:
return MTK_AFE_PCM_RATE_32K;
case 48000:
return MTK_AFE_PCM_RATE_48K;
default:
dev_err(dev, "%s(), rate %u invalid, use %d!!!\n",
__func__, rate, MTK_AFE_PCM_RATE_48K);
}
return MTK_AFE_PCM_RATE_48K;
}
unsigned int mt8186_tdm_relatch_rate_transform(struct device *dev, unsigned int rate)
{
switch (rate) {
case 8000:
return MTK_AFE_TDM_RELATCH_RATE_8K;
case 11025:
return MTK_AFE_TDM_RELATCH_RATE_11K;
case 12000:
return MTK_AFE_TDM_RELATCH_RATE_12K;
case 16000:
return MTK_AFE_TDM_RELATCH_RATE_16K;
case 22050:
return MTK_AFE_TDM_RELATCH_RATE_22K;
case 24000:
return MTK_AFE_TDM_RELATCH_RATE_24K;
case 32000:
return MTK_AFE_TDM_RELATCH_RATE_32K;
case 44100:
return MTK_AFE_TDM_RELATCH_RATE_44K;
case 48000:
return MTK_AFE_TDM_RELATCH_RATE_48K;
case 88200:
return MTK_AFE_TDM_RELATCH_RATE_88K;
case 96000:
return MTK_AFE_TDM_RELATCH_RATE_96K;
case 176400:
return MTK_AFE_TDM_RELATCH_RATE_176K;
case 192000:
return MTK_AFE_TDM_RELATCH_RATE_192K;
case 352800:
return MTK_AFE_TDM_RELATCH_RATE_352K;
case 384000:
return MTK_AFE_TDM_RELATCH_RATE_384K;
default:
dev_err(dev, "%s(), rate %u invalid, use %d!!!\n",
__func__, rate, MTK_AFE_TDM_RELATCH_RATE_48K);
}
return MTK_AFE_TDM_RELATCH_RATE_48K;
}
unsigned int mt8186_rate_transform(struct device *dev, unsigned int rate, int aud_blk)
{
switch (aud_blk) {
case MT8186_DAI_PCM:
return pcm_rate_transform(dev, rate);
case MT8186_DAI_TDM_IN:
return tdm_rate_transform(dev, rate);
default:
return mt8186_general_rate_transform(dev, rate);
}
}
int mt8186_dai_set_priv(struct mtk_base_afe *afe, int id, int priv_size, const void *priv_data)
{
struct mt8186_afe_private *afe_priv = afe->platform_priv;
void *temp_data;
temp_data = devm_kzalloc(afe->dev,
priv_size,
GFP_KERNEL);
if (!temp_data)
return -ENOMEM;
if (priv_data)
memcpy(temp_data, priv_data, priv_size);
afe_priv->dai_priv[id] = temp_data;
return 0;
}
|