Skip to content

Commit e834341

Browse files
jailuthrabroonie
authored andcommitted
ALSA: dmaengine: Synchronize dma channel after drop()
Sometimes the stream may be stopped due to XRUN events, in which case the userspace can call snd_pcm_drop() and snd_pcm_prepare() to stop and start the stream again. In these cases, we must wait for the DMA channel to synchronize before marking the stream as prepared for playback, as the DMA channel gets stopped by drop() without any synchronization. Make sure the ALSA core synchronizes the DMA channel by adding a sync_stop() hook. Reviewed-by: Peter Ujfalusi <[email protected]> Signed-off-by: Jai Luthra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent b9dd212 commit e834341

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

include/sound/dmaengine_pcm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream
3636
int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
3737
struct dma_chan *chan);
3838
int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream);
39+
int snd_dmaengine_pcm_sync_stop(struct snd_pcm_substream *substream);
3940

4041
int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
4142
dma_filter_fn filter_fn, void *filter_data);

sound/core/pcm_dmaengine.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
349349
}
350350
EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan);
351351

352+
int snd_dmaengine_pcm_sync_stop(struct snd_pcm_substream *substream)
353+
{
354+
struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
355+
356+
dmaengine_synchronize(prtd->dma_chan);
357+
358+
return 0;
359+
}
360+
EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_sync_stop);
361+
352362
/**
353363
* snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
354364
* @substream: PCM substream

sound/soc/soc-generic-dmaengine-pcm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ static int dmaengine_copy(struct snd_soc_component *component,
318318
return 0;
319319
}
320320

321+
static int dmaengine_pcm_sync_stop(struct snd_soc_component *component,
322+
struct snd_pcm_substream *substream)
323+
{
324+
return snd_dmaengine_pcm_sync_stop(substream);
325+
}
326+
321327
static const struct snd_soc_component_driver dmaengine_pcm_component = {
322328
.name = SND_DMAENGINE_PCM_DRV_NAME,
323329
.probe_order = SND_SOC_COMP_ORDER_LATE,
@@ -327,6 +333,7 @@ static const struct snd_soc_component_driver dmaengine_pcm_component = {
327333
.trigger = dmaengine_pcm_trigger,
328334
.pointer = dmaengine_pcm_pointer,
329335
.pcm_construct = dmaengine_pcm_new,
336+
.sync_stop = dmaengine_pcm_sync_stop,
330337
};
331338

332339
static const struct snd_soc_component_driver dmaengine_pcm_component_process = {
@@ -339,6 +346,7 @@ static const struct snd_soc_component_driver dmaengine_pcm_component_process = {
339346
.pointer = dmaengine_pcm_pointer,
340347
.copy = dmaengine_copy,
341348
.pcm_construct = dmaengine_pcm_new,
349+
.sync_stop = dmaengine_pcm_sync_stop,
342350
};
343351

344352
static const char * const dmaengine_pcm_dma_channel_names[] = {

0 commit comments

Comments
 (0)