Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions sound/soc/apple/mca.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,42 @@ static int mca_close(struct snd_soc_component *component,
return snd_dmaengine_pcm_close(substream);
}

/*
* The STOP trigger only asks the DMA to stop: it may still write the burst in
* flight. ALSA calls this after a stop or a suspend, before it frees or
* reallocates the buffer (hw_free, hw_params) or prepares the stream again.
* Wait here until the DMA no longer touches the buffer.
*/
static int mca_sync_stop(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);

if (rtd->dai_link->no_pcm)
return 0;

return snd_dmaengine_pcm_sync_stop(substream);
}

/*
* A stream suspended while running keeps its transfer, paused, for RESUME.
* Dropped or prepared from the suspended state instead, it gets no STOP: the
* paused transfer would stay the channel's current one, still pointing into
* the old buffer, and the next START would queue behind it and never run.
* ALSA prepares before every START: end such a transfer here. After a stop
* the channel has no transfer left, and there is nothing to end.
*/
static int mca_pcm_prepare(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);

if (rtd->dai_link->no_pcm)
return 0;

return dmaengine_terminate_sync(snd_dmaengine_pcm_get_chan(substream));
}

/*
* The capture buffers are cacheable (SNDRV_DMA_TYPE_NONCOHERENT): reading
* them through an uncached mapping costs the reader several times the
Expand Down Expand Up @@ -1303,7 +1339,9 @@ static const struct snd_soc_component_driver mca_component = {
.open = mca_pcm_open,
.close = mca_close,
.hw_params = mca_hw_params,
.prepare = mca_pcm_prepare,
.trigger = mca_trigger,
.sync_stop = mca_sync_stop,
.pointer = mca_pointer,
.pcm_new = mca_pcm_new,
.pcm_free = mca_pcm_free,
Expand Down
Loading