aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-dmaengine-pcm.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-06-11 14:11:42 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-20 10:39:05 -0400
commit3528f27a5d4ac299e2d8cbe7297c1e9edd601ee6 (patch)
treed7cb76e7018f03f0490bcd7c6d6b258da5c27c4e /sound/soc/soc-dmaengine-pcm.c
parent9883ab229d61b884323f9186b1bd4a41373a491b (diff)
ASoC: dmaengine-pcm: Add support for querying stream position from DMA driver
Currently the sound dmaengine pcm helper functions implement the pcm_pointer callback by trying to count the number of elapsed periods. This is done by advancing the stream position in the dmaengine callback by one period. Unfortunately there is no guarantee that the callback will be called for each elapsed period. It may be possible that under high system load it is only called once for multiple elapsed periods. This patch addresses the issue by implementing support for querying the current stream position directly from the dmaengine driver. Since not all dmaengine drivers support reporting the stream position yet the old period counting implementation is kept for now. Furthermore the new mechanism allows to report the stream position with a sub-period granularity, given that the dmaengine driver supports this. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-dmaengine-pcm.c')
-rw-r--r--sound/soc/soc-dmaengine-pcm.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/sound/soc/soc-dmaengine-pcm.c b/sound/soc/soc-dmaengine-pcm.c
index 7c0877e3731c..2995334d8000 100644
--- a/sound/soc/soc-dmaengine-pcm.c
+++ b/sound/soc/soc-dmaengine-pcm.c
@@ -30,6 +30,7 @@
30 30
31struct dmaengine_pcm_runtime_data { 31struct dmaengine_pcm_runtime_data {
32 struct dma_chan *dma_chan; 32 struct dma_chan *dma_chan;
33 dma_cookie_t cookie;
33 34
34 unsigned int pos; 35 unsigned int pos;
35 36
@@ -153,7 +154,7 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
153 154
154 desc->callback = dmaengine_pcm_dma_complete; 155 desc->callback = dmaengine_pcm_dma_complete;
155 desc->callback_param = substream; 156 desc->callback_param = substream;
156 dmaengine_submit(desc); 157 prtd->cookie = dmaengine_submit(desc);
157 158
158 return 0; 159 return 0;
159} 160}
@@ -213,6 +214,32 @@ snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream
213} 214}
214EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue); 215EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue);
215 216
217/**
218 * snd_dmaengine_pcm_pointer - dmaengine based PCM pointer implementation
219 * @substream: PCM substream
220 *
221 * This function can be used as the PCM pointer callback for dmaengine based PCM
222 * driver implementations.
223 */
224snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream)
225{
226 struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
227 struct dma_tx_state state;
228 enum dma_status status;
229 unsigned int buf_size;
230 unsigned int pos = 0;
231
232 status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state);
233 if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) {
234 buf_size = snd_pcm_lib_buffer_bytes(substream);
235 if (state.residue > 0 && state.residue <= buf_size)
236 pos = buf_size - state.residue;
237 }
238
239 return bytes_to_frames(substream->runtime, pos);
240}
241EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer);
242
216static int dmaengine_pcm_request_channel(struct dmaengine_pcm_runtime_data *prtd, 243static int dmaengine_pcm_request_channel(struct dmaengine_pcm_runtime_data *prtd,
217 dma_filter_fn filter_fn, void *filter_data) 244 dma_filter_fn filter_fn, void *filter_data)
218{ 245{