mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-06 13:09:58 +00:00
ASoC: meson: Use managed DMA buffer allocation
Using a managed buffer will pre-allocate the buffer using snd_pcm_lib_preallocate_pages() and automatically free it when the PCM is destroyed. In addition it will call snd_pcm_lib_malloc_pages() before the driver's hw_params() callback and snd_pcm_lib_free_pages() after the driver's hw_free() callback. This slightly reduces the boilerplate code of the driver. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Reviewed-by: Jerome Brunet <jbrunet@baylibre.com> Tested-by: Jerome Brunet <jbrunet@baylibre.com> Link: https://lore.kernel.org/r/20201218154544.25513-1-lars@metafoo.de Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
57fc2bbc62
commit
e05cde84ea
@ -124,7 +124,6 @@ const struct snd_soc_dai_ops aiu_fifo_i2s_dai_ops = {
|
|||||||
.trigger = aiu_fifo_i2s_trigger,
|
.trigger = aiu_fifo_i2s_trigger,
|
||||||
.prepare = aiu_fifo_i2s_prepare,
|
.prepare = aiu_fifo_i2s_prepare,
|
||||||
.hw_params = aiu_fifo_i2s_hw_params,
|
.hw_params = aiu_fifo_i2s_hw_params,
|
||||||
.hw_free = aiu_fifo_hw_free,
|
|
||||||
.startup = aiu_fifo_startup,
|
.startup = aiu_fifo_startup,
|
||||||
.shutdown = aiu_fifo_shutdown,
|
.shutdown = aiu_fifo_shutdown,
|
||||||
};
|
};
|
||||||
|
@ -158,7 +158,6 @@ const struct snd_soc_dai_ops aiu_fifo_spdif_dai_ops = {
|
|||||||
.trigger = fifo_spdif_trigger,
|
.trigger = fifo_spdif_trigger,
|
||||||
.prepare = fifo_spdif_prepare,
|
.prepare = fifo_spdif_prepare,
|
||||||
.hw_params = fifo_spdif_hw_params,
|
.hw_params = fifo_spdif_hw_params,
|
||||||
.hw_free = aiu_fifo_hw_free,
|
|
||||||
.startup = aiu_fifo_startup,
|
.startup = aiu_fifo_startup,
|
||||||
.shutdown = aiu_fifo_shutdown,
|
.shutdown = aiu_fifo_shutdown,
|
||||||
};
|
};
|
||||||
|
@ -99,11 +99,6 @@ int aiu_fifo_hw_params(struct snd_pcm_substream *substream,
|
|||||||
struct snd_soc_component *component = dai->component;
|
struct snd_soc_component *component = dai->component;
|
||||||
struct aiu_fifo *fifo = dai->playback_dma_data;
|
struct aiu_fifo *fifo = dai->playback_dma_data;
|
||||||
dma_addr_t end;
|
dma_addr_t end;
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* Setup the fifo boundaries */
|
/* Setup the fifo boundaries */
|
||||||
end = runtime->dma_addr + runtime->dma_bytes - fifo->fifo_block;
|
end = runtime->dma_addr + runtime->dma_bytes - fifo->fifo_block;
|
||||||
@ -124,12 +119,6 @@ int aiu_fifo_hw_params(struct snd_pcm_substream *substream,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int aiu_fifo_hw_free(struct snd_pcm_substream *substream,
|
|
||||||
struct snd_soc_dai *dai)
|
|
||||||
{
|
|
||||||
return snd_pcm_lib_free_pages(substream);
|
|
||||||
}
|
|
||||||
|
|
||||||
static irqreturn_t aiu_fifo_isr(int irq, void *dev_id)
|
static irqreturn_t aiu_fifo_isr(int irq, void *dev_id)
|
||||||
{
|
{
|
||||||
struct snd_pcm_substream *playback = dev_id;
|
struct snd_pcm_substream *playback = dev_id;
|
||||||
@ -187,15 +176,12 @@ void aiu_fifo_shutdown(struct snd_pcm_substream *substream,
|
|||||||
int aiu_fifo_pcm_new(struct snd_soc_pcm_runtime *rtd,
|
int aiu_fifo_pcm_new(struct snd_soc_pcm_runtime *rtd,
|
||||||
struct snd_soc_dai *dai)
|
struct snd_soc_dai *dai)
|
||||||
{
|
{
|
||||||
struct snd_pcm_substream *substream =
|
|
||||||
rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
|
||||||
struct snd_card *card = rtd->card->snd_card;
|
struct snd_card *card = rtd->card->snd_card;
|
||||||
struct aiu_fifo *fifo = dai->playback_dma_data;
|
struct aiu_fifo *fifo = dai->playback_dma_data;
|
||||||
size_t size = fifo->pcm->buffer_bytes_max;
|
size_t size = fifo->pcm->buffer_bytes_max;
|
||||||
|
|
||||||
snd_pcm_lib_preallocate_pages(substream,
|
snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV,
|
||||||
SNDRV_DMA_TYPE_DEV,
|
card->dev, size, size);
|
||||||
card->dev, size, size);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user