This source file includes following definitions.
- snd_soc_dai_set_sysclk
- snd_soc_dai_set_clkdiv
- snd_soc_dai_set_pll
- snd_soc_dai_set_bclk_ratio
- snd_soc_dai_set_fmt
- snd_soc_xlate_tdm_slot_mask
- snd_soc_dai_set_tdm_slot
- snd_soc_dai_set_channel_map
- snd_soc_dai_get_channel_map
- snd_soc_dai_set_tristate
- snd_soc_dai_digital_mute
- snd_soc_dai_hw_params
- snd_soc_dai_hw_free
- snd_soc_dai_startup
- snd_soc_dai_shutdown
- snd_soc_dai_prepare
- snd_soc_dai_trigger
- snd_soc_dai_bespoke_trigger
- snd_soc_dai_delay
- snd_soc_dai_suspend
- snd_soc_dai_resume
- snd_soc_dai_probe
- snd_soc_dai_remove
- snd_soc_dai_compress_new
- snd_soc_dai_stream_valid
1
2
3
4
5
6
7
8
9 #include <sound/soc.h>
10 #include <sound/soc-dai.h>
11
12
13
14
15
16
17
18
19
20
21 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
22 unsigned int freq, int dir)
23 {
24 if (dai->driver->ops->set_sysclk)
25 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
26
27 return snd_soc_component_set_sysclk(dai->component, clk_id, 0,
28 freq, dir);
29 }
30 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
31
32
33
34
35
36
37
38
39
40
41
42 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
43 int div_id, int div)
44 {
45 if (dai->driver->ops->set_clkdiv)
46 return dai->driver->ops->set_clkdiv(dai, div_id, div);
47 else
48 return -EINVAL;
49 }
50 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
51
52
53
54
55
56
57
58
59
60
61
62 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
63 unsigned int freq_in, unsigned int freq_out)
64 {
65 if (dai->driver->ops->set_pll)
66 return dai->driver->ops->set_pll(dai, pll_id, source,
67 freq_in, freq_out);
68
69 return snd_soc_component_set_pll(dai->component, pll_id, source,
70 freq_in, freq_out);
71 }
72 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
73
74
75
76
77
78
79
80
81 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
82 {
83 if (dai->driver->ops->set_bclk_ratio)
84 return dai->driver->ops->set_bclk_ratio(dai, ratio);
85 else
86 return -EINVAL;
87 }
88 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
89
90
91
92
93
94
95
96
97 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
98 {
99 if (dai->driver->ops->set_fmt == NULL)
100 return -ENOTSUPP;
101 return dai->driver->ops->set_fmt(dai, fmt);
102 }
103 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
104
105
106
107
108
109
110
111
112
113 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
114 unsigned int *tx_mask,
115 unsigned int *rx_mask)
116 {
117 if (*tx_mask || *rx_mask)
118 return 0;
119
120 if (!slots)
121 return -EINVAL;
122
123 *tx_mask = (1 << slots) - 1;
124 *rx_mask = (1 << slots) - 1;
125
126 return 0;
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 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
153 unsigned int tx_mask, unsigned int rx_mask,
154 int slots, int slot_width)
155 {
156 if (dai->driver->ops->xlate_tdm_slot_mask)
157 dai->driver->ops->xlate_tdm_slot_mask(slots,
158 &tx_mask, &rx_mask);
159 else
160 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
161
162 dai->tx_mask = tx_mask;
163 dai->rx_mask = rx_mask;
164
165 if (dai->driver->ops->set_tdm_slot)
166 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
167 slots, slot_width);
168 else
169 return -ENOTSUPP;
170 }
171 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
172
173
174
175
176
177
178
179
180
181
182
183
184
185 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
186 unsigned int tx_num, unsigned int *tx_slot,
187 unsigned int rx_num, unsigned int *rx_slot)
188 {
189 if (dai->driver->ops->set_channel_map)
190 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
191 rx_num, rx_slot);
192 else
193 return -ENOTSUPP;
194 }
195 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
196
197
198
199
200
201
202
203
204
205
206
207 int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai,
208 unsigned int *tx_num, unsigned int *tx_slot,
209 unsigned int *rx_num, unsigned int *rx_slot)
210 {
211 if (dai->driver->ops->get_channel_map)
212 return dai->driver->ops->get_channel_map(dai, tx_num, tx_slot,
213 rx_num, rx_slot);
214 else
215 return -ENOTSUPP;
216 }
217 EXPORT_SYMBOL_GPL(snd_soc_dai_get_channel_map);
218
219
220
221
222
223
224
225
226 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
227 {
228 if (dai->driver->ops->set_tristate)
229 return dai->driver->ops->set_tristate(dai, tristate);
230 else
231 return -EINVAL;
232 }
233 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
234
235
236
237
238
239
240
241
242
243 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
244 int direction)
245 {
246 if (dai->driver->ops->mute_stream)
247 return dai->driver->ops->mute_stream(dai, mute, direction);
248 else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
249 dai->driver->ops->digital_mute)
250 return dai->driver->ops->digital_mute(dai, mute);
251 else
252 return -ENOTSUPP;
253 }
254 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
255
256 int snd_soc_dai_hw_params(struct snd_soc_dai *dai,
257 struct snd_pcm_substream *substream,
258 struct snd_pcm_hw_params *params)
259 {
260 struct snd_soc_pcm_runtime *rtd = substream->private_data;
261 int ret;
262
263
264 if (rtd->dai_link->be_hw_params_fixup) {
265 ret = rtd->dai_link->be_hw_params_fixup(rtd, params);
266 if (ret < 0) {
267 dev_err(rtd->dev,
268 "ASoC: hw_params topology fixup failed %d\n",
269 ret);
270 return ret;
271 }
272 }
273
274 if (dai->driver->ops->hw_params) {
275 ret = dai->driver->ops->hw_params(substream, params, dai);
276 if (ret < 0) {
277 dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n",
278 dai->name, ret);
279 return ret;
280 }
281 }
282
283 return 0;
284 }
285
286 void snd_soc_dai_hw_free(struct snd_soc_dai *dai,
287 struct snd_pcm_substream *substream)
288 {
289 if (dai->driver->ops->hw_free)
290 dai->driver->ops->hw_free(substream, dai);
291 }
292
293 int snd_soc_dai_startup(struct snd_soc_dai *dai,
294 struct snd_pcm_substream *substream)
295 {
296 int ret = 0;
297
298 if (dai->driver->ops->startup)
299 ret = dai->driver->ops->startup(substream, dai);
300
301 return ret;
302 }
303
304 void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
305 struct snd_pcm_substream *substream)
306 {
307 if (dai->driver->ops->shutdown)
308 dai->driver->ops->shutdown(substream, dai);
309 }
310
311 int snd_soc_dai_prepare(struct snd_soc_dai *dai,
312 struct snd_pcm_substream *substream)
313 {
314 int ret = 0;
315
316 if (dai->driver->ops->prepare)
317 ret = dai->driver->ops->prepare(substream, dai);
318
319 return ret;
320 }
321
322 int snd_soc_dai_trigger(struct snd_soc_dai *dai,
323 struct snd_pcm_substream *substream,
324 int cmd)
325 {
326 int ret = 0;
327
328 if (dai->driver->ops->trigger)
329 ret = dai->driver->ops->trigger(substream, cmd, dai);
330
331 return ret;
332 }
333
334 int snd_soc_dai_bespoke_trigger(struct snd_soc_dai *dai,
335 struct snd_pcm_substream *substream,
336 int cmd)
337 {
338 int ret = 0;
339
340 if (dai->driver->ops->bespoke_trigger)
341 ret = dai->driver->ops->bespoke_trigger(substream, cmd, dai);
342
343 return ret;
344 }
345
346 snd_pcm_sframes_t snd_soc_dai_delay(struct snd_soc_dai *dai,
347 struct snd_pcm_substream *substream)
348 {
349 int delay = 0;
350
351 if (dai->driver->ops->delay)
352 delay = dai->driver->ops->delay(substream, dai);
353
354 return delay;
355 }
356
357 void snd_soc_dai_suspend(struct snd_soc_dai *dai)
358 {
359 if (dai->driver->suspend)
360 dai->driver->suspend(dai);
361 }
362
363 void snd_soc_dai_resume(struct snd_soc_dai *dai)
364 {
365 if (dai->driver->resume)
366 dai->driver->resume(dai);
367 }
368
369 int snd_soc_dai_probe(struct snd_soc_dai *dai)
370 {
371 if (dai->driver->probe)
372 return dai->driver->probe(dai);
373 return 0;
374 }
375
376 int snd_soc_dai_remove(struct snd_soc_dai *dai)
377 {
378 if (dai->driver->remove)
379 return dai->driver->remove(dai);
380 return 0;
381 }
382
383 int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
384 struct snd_soc_pcm_runtime *rtd, int num)
385 {
386 if (dai->driver->compress_new)
387 return dai->driver->compress_new(rtd, num);
388 return -ENOTSUPP;
389 }
390
391
392
393
394
395
396 bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int dir)
397 {
398 struct snd_soc_pcm_stream *stream;
399
400 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
401 stream = &dai->driver->playback;
402 else
403 stream = &dai->driver->capture;
404
405
406 return stream->channels_min;
407 }