xref: /openbmc/linux/sound/soc/sof/compress.c (revision c4a11bf4)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // Copyright 2021 NXP
4 //
5 // Author: Daniel Baluta <daniel.baluta@nxp.com>
6 
7 #include <sound/soc.h>
8 #include <sound/sof.h>
9 #include <sound/compress_driver.h>
10 #include "sof-audio.h"
11 #include "sof-priv.h"
12 
13 static void snd_sof_compr_fragment_elapsed_work(struct work_struct *work)
14 {
15 	struct snd_sof_pcm_stream *sps =
16 		container_of(work, struct snd_sof_pcm_stream,
17 			     period_elapsed_work);
18 
19 	snd_compr_fragment_elapsed(sps->cstream);
20 }
21 
22 void snd_sof_compr_init_elapsed_work(struct work_struct *work)
23 {
24 	INIT_WORK(work, snd_sof_compr_fragment_elapsed_work);
25 }
26 
27 /*
28  * sof compr fragment elapse, this could be called in irq thread context
29  */
30 void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream)
31 {
32 	struct snd_soc_component *component;
33 	struct snd_soc_pcm_runtime *rtd;
34 	struct snd_sof_pcm *spcm;
35 
36 	if (!cstream)
37 		return;
38 
39 	rtd = cstream->private_data;
40 	component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
41 
42 	spcm = snd_sof_find_spcm_dai(component, rtd);
43 	if (!spcm) {
44 		dev_err(component->dev,
45 			"fragment elapsed called for unknown stream!\n");
46 		return;
47 	}
48 
49 	/* use the same workqueue-based solution as for PCM, cf. snd_sof_pcm_elapsed */
50 	schedule_work(&spcm->stream[cstream->direction].period_elapsed_work);
51 }
52