xref: /linux/sound/soc/soc-dai.c (revision 497e6b37b0099dc415578488287fd84fb74433eb)
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // soc-dai.c
4 //
5 // Copyright (C) 2019 Renesas Electronics Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 //
8 
9 #include <sound/soc.h>
10 #include <sound/soc-dai.h>
11 #include <sound/soc-link.h>
12 
13 #define soc_dai_ret(dai, ret) _soc_dai_ret(dai, __func__, ret)
14 static inline int _soc_dai_ret(struct snd_soc_dai *dai,
15 			       const char *func, int ret)
16 {
17 	/* Positive, Zero values are not errors */
18 	if (ret >= 0)
19 		return ret;
20 
21 	/* Negative values might be errors */
22 	switch (ret) {
23 	case -EPROBE_DEFER:
24 	case -ENOTSUPP:
25 		break;
26 	default:
27 		dev_err(dai->dev,
28 			"ASoC: error at %s on %s: %d\n",
29 			func, dai->name, ret);
30 	}
31 
32 	return ret;
33 }
34 
35 /*
36  * We might want to check substream by using list.
37  * In such case, we can update these macros.
38  */
39 #define soc_dai_mark_push(dai, substream, tgt)	((dai)->mark_##tgt = substream)
40 #define soc_dai_mark_pop(dai, substream, tgt)	((dai)->mark_##tgt = NULL)
41 #define soc_dai_mark_match(dai, substream, tgt)	((dai)->mark_##tgt == substream)
42 
43 /**
44  * snd_soc_dai_set_sysclk - configure DAI system or master clock.
45  * @dai: DAI
46  * @clk_id: DAI specific clock ID
47  * @freq: new clock frequency in Hz
48  * @dir: new clock direction - input/output.
49  *
50  * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
51  */
52 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
53 			   unsigned int freq, int dir)
54 {
55 	int ret;
56 
57 	if (dai->driver->ops &&
58 	    dai->driver->ops->set_sysclk)
59 		ret = dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
60 	else
61 		ret = snd_soc_component_set_sysclk(dai->component, clk_id, 0,
62 						   freq, dir);
63 
64 	return soc_dai_ret(dai, ret);
65 }
66 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
67 
68 /**
69  * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
70  * @dai: DAI
71  * @div_id: DAI specific clock divider ID
72  * @div: new clock divisor.
73  *
74  * Configures the clock dividers. This is used to derive the best DAI bit and
75  * frame clocks from the system or master clock. It's best to set the DAI bit
76  * and frame clocks as low as possible to save system power.
77  */
78 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
79 			   int div_id, int div)
80 {
81 	int ret = -EINVAL;
82 
83 	if (dai->driver->ops &&
84 	    dai->driver->ops->set_clkdiv)
85 		ret = dai->driver->ops->set_clkdiv(dai, div_id, div);
86 
87 	return soc_dai_ret(dai, ret);
88 }
89 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
90 
91 /**
92  * snd_soc_dai_set_pll - configure DAI PLL.
93  * @dai: DAI
94  * @pll_id: DAI specific PLL ID
95  * @source: DAI specific source for the PLL
96  * @freq_in: PLL input clock frequency in Hz
97  * @freq_out: requested PLL output clock frequency in Hz
98  *
99  * Configures and enables PLL to generate output clock based on input clock.
100  */
101 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
102 			unsigned int freq_in, unsigned int freq_out)
103 {
104 	int ret;
105 
106 	if (dai->driver->ops &&
107 	    dai->driver->ops->set_pll)
108 		ret = dai->driver->ops->set_pll(dai, pll_id, source,
109 						freq_in, freq_out);
110 	else
111 		ret = snd_soc_component_set_pll(dai->component, pll_id, source,
112 						freq_in, freq_out);
113 
114 	return soc_dai_ret(dai, ret);
115 }
116 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
117 
118 /**
119  * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
120  * @dai: DAI
121  * @ratio: Ratio of BCLK to Sample rate.
122  *
123  * Configures the DAI for a preset BCLK to sample rate ratio.
124  */
125 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
126 {
127 	int ret = -ENOTSUPP;
128 
129 	if (dai->driver->ops &&
130 	    dai->driver->ops->set_bclk_ratio)
131 		ret = dai->driver->ops->set_bclk_ratio(dai, ratio);
132 
133 	return soc_dai_ret(dai, ret);
134 }
135 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
136 
137 int snd_soc_dai_get_fmt_max_priority(struct snd_soc_pcm_runtime *rtd)
138 {
139 	struct snd_soc_dai *dai;
140 	int i, max = 0;
141 
142 	/*
143 	 * return max num if *ALL* DAIs have .auto_selectable_formats
144 	 */
145 	for_each_rtd_dais(rtd, i, dai) {
146 		if (dai->driver->ops &&
147 		    dai->driver->ops->num_auto_selectable_formats)
148 			max = max(max, dai->driver->ops->num_auto_selectable_formats);
149 		else
150 			return 0;
151 	}
152 
153 	return max;
154 }
155 
156 /**
157  * snd_soc_dai_get_fmt - get supported audio format.
158  * @dai: DAI
159  * @priority: priority level of supported audio format.
160  *
161  * This should return only formats implemented with high
162  * quality by the DAI so that the core can configure a
163  * format which will work well with other devices.
164  * For example devices which don't support both edges of the
165  * LRCLK signal in I2S style formats should only list DSP
166  * modes.  This will mean that sometimes fewer formats
167  * are reported here than are supported by set_fmt().
168  */
169 u64 snd_soc_dai_get_fmt(struct snd_soc_dai *dai, int priority)
170 {
171 	const struct snd_soc_dai_ops *ops = dai->driver->ops;
172 	u64 fmt = 0;
173 	int i, max = 0, until = priority;
174 
175 	/*
176 	 * Collect auto_selectable_formats until priority
177 	 *
178 	 * ex)
179 	 *	auto_selectable_formats[] = { A, B, C };
180 	 *	(A, B, C = SND_SOC_POSSIBLE_DAIFMT_xxx)
181 	 *
182 	 * priority = 1 :	A
183 	 * priority = 2 :	A | B
184 	 * priority = 3 :	A | B | C
185 	 * priority = 4 :	A | B | C
186 	 * ...
187 	 */
188 	if (ops)
189 		max = ops->num_auto_selectable_formats;
190 
191 	if (max < until)
192 		until = max;
193 
194 	for (i = 0; i < until; i++)
195 		fmt |= ops->auto_selectable_formats[i];
196 
197 	return fmt;
198 }
199 
200 /**
201  * snd_soc_dai_set_fmt - configure DAI hardware audio format.
202  * @dai: DAI
203  * @fmt: SND_SOC_DAIFMT_* format value.
204  *
205  * Configures the DAI hardware format and clocking.
206  */
207 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
208 {
209 	int ret = -ENOTSUPP;
210 
211 	if (dai->driver->ops && dai->driver->ops->set_fmt)
212 		ret = dai->driver->ops->set_fmt(dai, fmt);
213 
214 	return soc_dai_ret(dai, ret);
215 }
216 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
217 
218 /**
219  * snd_soc_xlate_tdm_slot_mask - generate tx/rx slot mask.
220  * @slots: Number of slots in use.
221  * @tx_mask: bitmask representing active TX slots.
222  * @rx_mask: bitmask representing active RX slots.
223  *
224  * Generates the TDM tx and rx slot default masks for DAI.
225  */
226 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
227 				       unsigned int *tx_mask,
228 				       unsigned int *rx_mask)
229 {
230 	if (*tx_mask || *rx_mask)
231 		return 0;
232 
233 	if (!slots)
234 		return -EINVAL;
235 
236 	*tx_mask = (1 << slots) - 1;
237 	*rx_mask = (1 << slots) - 1;
238 
239 	return 0;
240 }
241 
242 /**
243  * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation
244  * @dai: The DAI to configure
245  * @tx_mask: bitmask representing active TX slots.
246  * @rx_mask: bitmask representing active RX slots.
247  * @slots: Number of slots in use.
248  * @slot_width: Width in bits for each slot.
249  *
250  * This function configures the specified DAI for TDM operation. @slot contains
251  * the total number of slots of the TDM stream and @slot_with the width of each
252  * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the
253  * active slots of the TDM stream for the specified DAI, i.e. which slots the
254  * DAI should write to or read from. If a bit is set the corresponding slot is
255  * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to
256  * the first slot, bit 1 to the second slot and so on. The first active slot
257  * maps to the first channel of the DAI, the second active slot to the second
258  * channel and so on.
259  *
260  * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask,
261  * @rx_mask and @slot_width will be ignored.
262  *
263  * Returns 0 on success, a negative error code otherwise.
264  */
265 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
266 			     unsigned int tx_mask, unsigned int rx_mask,
267 			     int slots, int slot_width)
268 {
269 	int ret = -ENOTSUPP;
270 
271 	if (dai->driver->ops &&
272 	    dai->driver->ops->xlate_tdm_slot_mask)
273 		dai->driver->ops->xlate_tdm_slot_mask(slots,
274 						      &tx_mask, &rx_mask);
275 	else
276 		snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
277 
278 	dai->tx_mask = tx_mask;
279 	dai->rx_mask = rx_mask;
280 
281 	if (dai->driver->ops &&
282 	    dai->driver->ops->set_tdm_slot)
283 		ret = dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
284 						      slots, slot_width);
285 	return soc_dai_ret(dai, ret);
286 }
287 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
288 
289 /**
290  * snd_soc_dai_set_channel_map - configure DAI audio channel map
291  * @dai: DAI
292  * @tx_num: how many TX channels
293  * @tx_slot: pointer to an array which imply the TX slot number channel
294  *           0~num-1 uses
295  * @rx_num: how many RX channels
296  * @rx_slot: pointer to an array which imply the RX slot number channel
297  *           0~num-1 uses
298  *
299  * configure the relationship between channel number and TDM slot number.
300  */
301 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
302 				unsigned int tx_num, unsigned int *tx_slot,
303 				unsigned int rx_num, unsigned int *rx_slot)
304 {
305 	int ret = -ENOTSUPP;
306 
307 	if (dai->driver->ops &&
308 	    dai->driver->ops->set_channel_map)
309 		ret = dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
310 							rx_num, rx_slot);
311 	return soc_dai_ret(dai, ret);
312 }
313 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
314 
315 /**
316  * snd_soc_dai_get_channel_map - Get DAI audio channel map
317  * @dai: DAI
318  * @tx_num: how many TX channels
319  * @tx_slot: pointer to an array which imply the TX slot number channel
320  *           0~num-1 uses
321  * @rx_num: how many RX channels
322  * @rx_slot: pointer to an array which imply the RX slot number channel
323  *           0~num-1 uses
324  */
325 int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai,
326 				unsigned int *tx_num, unsigned int *tx_slot,
327 				unsigned int *rx_num, unsigned int *rx_slot)
328 {
329 	int ret = -ENOTSUPP;
330 
331 	if (dai->driver->ops &&
332 	    dai->driver->ops->get_channel_map)
333 		ret = dai->driver->ops->get_channel_map(dai, tx_num, tx_slot,
334 							rx_num, rx_slot);
335 	return soc_dai_ret(dai, ret);
336 }
337 EXPORT_SYMBOL_GPL(snd_soc_dai_get_channel_map);
338 
339 /**
340  * snd_soc_dai_set_tristate - configure DAI system or master clock.
341  * @dai: DAI
342  * @tristate: tristate enable
343  *
344  * Tristates the DAI so that others can use it.
345  */
346 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
347 {
348 	int ret = -EINVAL;
349 
350 	if (dai->driver->ops &&
351 	    dai->driver->ops->set_tristate)
352 		ret = dai->driver->ops->set_tristate(dai, tristate);
353 
354 	return soc_dai_ret(dai, ret);
355 }
356 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
357 
358 /**
359  * snd_soc_dai_digital_mute - configure DAI system or master clock.
360  * @dai: DAI
361  * @mute: mute enable
362  * @direction: stream to mute
363  *
364  * Mutes the DAI DAC.
365  */
366 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
367 			     int direction)
368 {
369 	int ret = -ENOTSUPP;
370 
371 	/*
372 	 * ignore if direction was CAPTURE
373 	 * and it had .no_capture_mute flag
374 	 */
375 	if (dai->driver->ops &&
376 	    dai->driver->ops->mute_stream &&
377 	    (direction == SNDRV_PCM_STREAM_PLAYBACK ||
378 	     !dai->driver->ops->no_capture_mute))
379 		ret = dai->driver->ops->mute_stream(dai, mute, direction);
380 
381 	return soc_dai_ret(dai, ret);
382 }
383 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
384 
385 int snd_soc_dai_hw_params(struct snd_soc_dai *dai,
386 			  struct snd_pcm_substream *substream,
387 			  struct snd_pcm_hw_params *params)
388 {
389 	int ret = 0;
390 
391 	if (dai->driver->ops &&
392 	    dai->driver->ops->hw_params)
393 		ret = dai->driver->ops->hw_params(substream, params, dai);
394 
395 	/* mark substream if succeeded */
396 	if (ret == 0)
397 		soc_dai_mark_push(dai, substream, hw_params);
398 
399 	return soc_dai_ret(dai, ret);
400 }
401 
402 void snd_soc_dai_hw_free(struct snd_soc_dai *dai,
403 			 struct snd_pcm_substream *substream,
404 			 int rollback)
405 {
406 	if (rollback && !soc_dai_mark_match(dai, substream, hw_params))
407 		return;
408 
409 	if (dai->driver->ops &&
410 	    dai->driver->ops->hw_free)
411 		dai->driver->ops->hw_free(substream, dai);
412 
413 	/* remove marked substream */
414 	soc_dai_mark_pop(dai, substream, hw_params);
415 }
416 
417 int snd_soc_dai_startup(struct snd_soc_dai *dai,
418 			struct snd_pcm_substream *substream)
419 {
420 	int ret = 0;
421 
422 	if (dai->driver->ops &&
423 	    dai->driver->ops->startup)
424 		ret = dai->driver->ops->startup(substream, dai);
425 
426 	/* mark substream if succeeded */
427 	if (ret == 0)
428 		soc_dai_mark_push(dai, substream, startup);
429 
430 	return soc_dai_ret(dai, ret);
431 }
432 
433 void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
434 			  struct snd_pcm_substream *substream,
435 			  int rollback)
436 {
437 	if (rollback && !soc_dai_mark_match(dai, substream, startup))
438 		return;
439 
440 	if (dai->driver->ops &&
441 	    dai->driver->ops->shutdown)
442 		dai->driver->ops->shutdown(substream, dai);
443 
444 	/* remove marked substream */
445 	soc_dai_mark_pop(dai, substream, startup);
446 }
447 
448 int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
449 			     struct snd_soc_pcm_runtime *rtd, int num)
450 {
451 	int ret = -ENOTSUPP;
452 	if (dai->driver->compress_new)
453 		ret = dai->driver->compress_new(rtd, num);
454 	return soc_dai_ret(dai, ret);
455 }
456 
457 /*
458  * snd_soc_dai_stream_valid() - check if a DAI supports the given stream
459  *
460  * Returns true if the DAI supports the indicated stream type.
461  */
462 bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int dir)
463 {
464 	struct snd_soc_pcm_stream *stream = snd_soc_dai_get_pcm_stream(dai, dir);
465 
466 	/* If the codec specifies any channels at all, it supports the stream */
467 	return stream->channels_min;
468 }
469 
470 /*
471  * snd_soc_dai_link_set_capabilities() - set dai_link properties based on its DAIs
472  */
473 void snd_soc_dai_link_set_capabilities(struct snd_soc_dai_link *dai_link)
474 {
475 	bool supported[SNDRV_PCM_STREAM_LAST + 1];
476 	int direction;
477 
478 	for_each_pcm_streams(direction) {
479 		struct snd_soc_dai_link_component *cpu;
480 		struct snd_soc_dai_link_component *codec;
481 		struct snd_soc_dai *dai;
482 		bool supported_cpu = false;
483 		bool supported_codec = false;
484 		int i;
485 
486 		for_each_link_cpus(dai_link, i, cpu) {
487 			dai = snd_soc_find_dai_with_mutex(cpu);
488 			if (dai && snd_soc_dai_stream_valid(dai, direction)) {
489 				supported_cpu = true;
490 				break;
491 			}
492 		}
493 		for_each_link_codecs(dai_link, i, codec) {
494 			dai = snd_soc_find_dai_with_mutex(codec);
495 			if (dai && snd_soc_dai_stream_valid(dai, direction)) {
496 				supported_codec = true;
497 				break;
498 			}
499 		}
500 		supported[direction] = supported_cpu && supported_codec;
501 	}
502 
503 	dai_link->dpcm_playback = supported[SNDRV_PCM_STREAM_PLAYBACK];
504 	dai_link->dpcm_capture  = supported[SNDRV_PCM_STREAM_CAPTURE];
505 }
506 EXPORT_SYMBOL_GPL(snd_soc_dai_link_set_capabilities);
507 
508 void snd_soc_dai_action(struct snd_soc_dai *dai,
509 			int stream, int action)
510 {
511 	/* see snd_soc_dai_stream_active() */
512 	dai->stream_active[stream]	+= action;
513 
514 	/* see snd_soc_component_active() */
515 	dai->component->active		+= action;
516 }
517 EXPORT_SYMBOL_GPL(snd_soc_dai_action);
518 
519 int snd_soc_dai_active(struct snd_soc_dai *dai)
520 {
521 	int stream, active;
522 
523 	active = 0;
524 	for_each_pcm_streams(stream)
525 		active += dai->stream_active[stream];
526 
527 	return active;
528 }
529 EXPORT_SYMBOL_GPL(snd_soc_dai_active);
530 
531 int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order)
532 {
533 	struct snd_soc_dai *dai;
534 	int i;
535 
536 	for_each_rtd_dais(rtd, i, dai) {
537 		if (dai->driver->probe_order != order)
538 			continue;
539 
540 		if (dai->driver->probe) {
541 			int ret = dai->driver->probe(dai);
542 
543 			if (ret < 0)
544 				return soc_dai_ret(dai, ret);
545 		}
546 
547 		dai->probed = 1;
548 	}
549 
550 	return 0;
551 }
552 
553 int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order)
554 {
555 	struct snd_soc_dai *dai;
556 	int i, r, ret = 0;
557 
558 	for_each_rtd_dais(rtd, i, dai) {
559 		if (dai->driver->remove_order != order)
560 			continue;
561 
562 		if (dai->probed &&
563 		    dai->driver->remove) {
564 			r = dai->driver->remove(dai);
565 			if (r < 0)
566 				ret = r; /* use last error */
567 		}
568 
569 		dai->probed = 0;
570 	}
571 
572 	return ret;
573 }
574 
575 int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd)
576 {
577 	struct snd_soc_dai *dai;
578 	int i;
579 
580 	for_each_rtd_dais(rtd, i, dai) {
581 		if (dai->driver->pcm_new) {
582 			int ret = dai->driver->pcm_new(rtd, dai);
583 			if (ret < 0)
584 				return soc_dai_ret(dai, ret);
585 		}
586 	}
587 
588 	return 0;
589 }
590 
591 int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream)
592 {
593 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
594 	struct snd_soc_dai *dai;
595 	int i, ret;
596 
597 	for_each_rtd_dais(rtd, i, dai) {
598 		if (dai->driver->ops &&
599 		    dai->driver->ops->prepare) {
600 			ret = dai->driver->ops->prepare(substream, dai);
601 			if (ret < 0)
602 				return soc_dai_ret(dai, ret);
603 		}
604 	}
605 
606 	return 0;
607 }
608 
609 static int soc_dai_trigger(struct snd_soc_dai *dai,
610 			   struct snd_pcm_substream *substream, int cmd)
611 {
612 	int ret = 0;
613 
614 	if (dai->driver->ops &&
615 	    dai->driver->ops->trigger)
616 		ret = dai->driver->ops->trigger(substream, cmd, dai);
617 
618 	return soc_dai_ret(dai, ret);
619 }
620 
621 int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream,
622 			    int cmd, int rollback)
623 {
624 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
625 	struct snd_soc_dai *dai;
626 	int i, r, ret = 0;
627 
628 	switch (cmd) {
629 	case SNDRV_PCM_TRIGGER_START:
630 	case SNDRV_PCM_TRIGGER_RESUME:
631 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
632 		for_each_rtd_dais(rtd, i, dai) {
633 			ret = soc_dai_trigger(dai, substream, cmd);
634 			if (ret < 0)
635 				break;
636 			soc_dai_mark_push(dai, substream, trigger);
637 		}
638 		break;
639 	case SNDRV_PCM_TRIGGER_STOP:
640 	case SNDRV_PCM_TRIGGER_SUSPEND:
641 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
642 		for_each_rtd_dais(rtd, i, dai) {
643 			if (rollback && !soc_dai_mark_match(dai, substream, trigger))
644 				continue;
645 
646 			r = soc_dai_trigger(dai, substream, cmd);
647 			if (r < 0)
648 				ret = r; /* use last ret */
649 			soc_dai_mark_pop(dai, substream, trigger);
650 		}
651 	}
652 
653 	return ret;
654 }
655 
656 int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream,
657 				    int cmd)
658 {
659 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
660 	struct snd_soc_dai *dai;
661 	int i, ret;
662 
663 	for_each_rtd_dais(rtd, i, dai) {
664 		if (dai->driver->ops &&
665 		    dai->driver->ops->bespoke_trigger) {
666 			ret = dai->driver->ops->bespoke_trigger(substream,
667 								cmd, dai);
668 			if (ret < 0)
669 				return soc_dai_ret(dai, ret);
670 		}
671 	}
672 
673 	return 0;
674 }
675 
676 void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
677 			   snd_pcm_sframes_t *cpu_delay,
678 			   snd_pcm_sframes_t *codec_delay)
679 {
680 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
681 	struct snd_soc_dai *dai;
682 	int i;
683 
684 	/*
685 	 * We're looking for the delay through the full audio path so it needs to
686 	 * be the maximum of the DAIs doing transmit and the maximum of the DAIs
687 	 * doing receive (ie, all CPUs and all CODECs) rather than just the maximum
688 	 * of all DAIs.
689 	 */
690 
691 	/* for CPU */
692 	for_each_rtd_cpu_dais(rtd, i, dai)
693 		if (dai->driver->ops &&
694 		    dai->driver->ops->delay)
695 			*cpu_delay = max(*cpu_delay, dai->driver->ops->delay(substream, dai));
696 
697 	/* for Codec */
698 	for_each_rtd_codec_dais(rtd, i, dai)
699 		if (dai->driver->ops &&
700 		    dai->driver->ops->delay)
701 			*codec_delay = max(*codec_delay, dai->driver->ops->delay(substream, dai));
702 }
703 
704 int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
705 			      struct snd_compr_stream *cstream)
706 {
707 	int ret = 0;
708 
709 	if (dai->driver->cops &&
710 	    dai->driver->cops->startup)
711 		ret = dai->driver->cops->startup(cstream, dai);
712 
713 	/* mark cstream if succeeded */
714 	if (ret == 0)
715 		soc_dai_mark_push(dai, cstream, compr_startup);
716 
717 	return soc_dai_ret(dai, ret);
718 }
719 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_startup);
720 
721 void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
722 				struct snd_compr_stream *cstream,
723 				int rollback)
724 {
725 	if (rollback && !soc_dai_mark_match(dai, cstream, compr_startup))
726 		return;
727 
728 	if (dai->driver->cops &&
729 	    dai->driver->cops->shutdown)
730 		dai->driver->cops->shutdown(cstream, dai);
731 
732 	/* remove marked cstream */
733 	soc_dai_mark_pop(dai, cstream, compr_startup);
734 }
735 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_shutdown);
736 
737 int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai,
738 			      struct snd_compr_stream *cstream, int cmd)
739 {
740 	int ret = 0;
741 
742 	if (dai->driver->cops &&
743 	    dai->driver->cops->trigger)
744 		ret = dai->driver->cops->trigger(cstream, cmd, dai);
745 
746 	return soc_dai_ret(dai, ret);
747 }
748 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_trigger);
749 
750 int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai,
751 				 struct snd_compr_stream *cstream,
752 				 struct snd_compr_params *params)
753 {
754 	int ret = 0;
755 
756 	if (dai->driver->cops &&
757 	    dai->driver->cops->set_params)
758 		ret = dai->driver->cops->set_params(cstream, params, dai);
759 
760 	return soc_dai_ret(dai, ret);
761 }
762 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_set_params);
763 
764 int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai,
765 				 struct snd_compr_stream *cstream,
766 				 struct snd_codec *params)
767 {
768 	int ret = 0;
769 
770 	if (dai->driver->cops &&
771 	    dai->driver->cops->get_params)
772 		ret = dai->driver->cops->get_params(cstream, params, dai);
773 
774 	return soc_dai_ret(dai, ret);
775 }
776 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_get_params);
777 
778 int snd_soc_dai_compr_ack(struct snd_soc_dai *dai,
779 			  struct snd_compr_stream *cstream,
780 			  size_t bytes)
781 {
782 	int ret = 0;
783 
784 	if (dai->driver->cops &&
785 	    dai->driver->cops->ack)
786 		ret = dai->driver->cops->ack(cstream, bytes, dai);
787 
788 	return soc_dai_ret(dai, ret);
789 }
790 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_ack);
791 
792 int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
793 			      struct snd_compr_stream *cstream,
794 			      struct snd_compr_tstamp *tstamp)
795 {
796 	int ret = 0;
797 
798 	if (dai->driver->cops &&
799 	    dai->driver->cops->pointer)
800 		ret = dai->driver->cops->pointer(cstream, tstamp, dai);
801 
802 	return soc_dai_ret(dai, ret);
803 }
804 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_pointer);
805 
806 int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
807 				   struct snd_compr_stream *cstream,
808 				   struct snd_compr_metadata *metadata)
809 {
810 	int ret = 0;
811 
812 	if (dai->driver->cops &&
813 	    dai->driver->cops->set_metadata)
814 		ret = dai->driver->cops->set_metadata(cstream, metadata, dai);
815 
816 	return soc_dai_ret(dai, ret);
817 }
818 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_set_metadata);
819 
820 int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai,
821 				   struct snd_compr_stream *cstream,
822 				   struct snd_compr_metadata *metadata)
823 {
824 	int ret = 0;
825 
826 	if (dai->driver->cops &&
827 	    dai->driver->cops->get_metadata)
828 		ret = dai->driver->cops->get_metadata(cstream, metadata, dai);
829 
830 	return soc_dai_ret(dai, ret);
831 }
832 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_get_metadata);
833