ASoC: sprd: Use managed buffer allocation
This patch simplifies the buffer pre-allocation code of sprd driver with the standard managed buffer helper. It uses the newly introduced fixed-size buffer allocation helper. Acked-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20210802072815.13551-16-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
8c505b773d
commit
ba447289fd
|
@ -204,8 +204,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component,
|
|||
if (!dma_params) {
|
||||
dev_warn(component->dev, "no dma parameters setting\n");
|
||||
dma_private->params = NULL;
|
||||
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
|
||||
runtime->dma_bytes = totsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -217,9 +215,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component,
|
|||
return ret;
|
||||
}
|
||||
|
||||
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
|
||||
|
||||
runtime->dma_bytes = totsize;
|
||||
sg_num = totsize / period;
|
||||
dma_private->dma_addr_offset = totsize / channels;
|
||||
|
||||
|
@ -310,7 +305,6 @@ sg_err:
|
|||
static int sprd_pcm_hw_free(struct snd_soc_component *component,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
snd_pcm_set_runtime_buffer(substream, NULL);
|
||||
sprd_pcm_release_dma_channel(substream);
|
||||
|
||||
return 0;
|
||||
|
@ -435,73 +429,20 @@ static snd_pcm_uframes_t sprd_pcm_pointer(struct snd_soc_component *component,
|
|||
return x;
|
||||
}
|
||||
|
||||
static int sprd_pcm_mmap(struct snd_soc_component *component,
|
||||
struct snd_pcm_substream *substream,
|
||||
struct vm_area_struct *vma)
|
||||
{
|
||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||
|
||||
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
|
||||
return remap_pfn_range(vma, vma->vm_start,
|
||||
runtime->dma_addr >> PAGE_SHIFT,
|
||||
vma->vm_end - vma->vm_start,
|
||||
vma->vm_page_prot);
|
||||
}
|
||||
|
||||
static int sprd_pcm_new(struct snd_soc_component *component,
|
||||
struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
struct snd_card *card = rtd->card->snd_card;
|
||||
struct snd_pcm *pcm = rtd->pcm;
|
||||
struct snd_pcm_substream *substream;
|
||||
int ret;
|
||||
|
||||
ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
||||
if (substream) {
|
||||
ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, card->dev,
|
||||
sprd_pcm_hardware.buffer_bytes_max,
|
||||
&substream->dma_buffer);
|
||||
if (ret) {
|
||||
dev_err(card->dev,
|
||||
"can't alloc playback dma buffer: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
|
||||
if (substream) {
|
||||
ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, card->dev,
|
||||
sprd_pcm_hardware.buffer_bytes_max,
|
||||
&substream->dma_buffer);
|
||||
if (ret) {
|
||||
dev_err(card->dev,
|
||||
"can't alloc capture dma buffer: %d\n", ret);
|
||||
snd_dma_free_pages(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->dma_buffer);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sprd_pcm_free(struct snd_soc_component *component,
|
||||
struct snd_pcm *pcm)
|
||||
{
|
||||
struct snd_pcm_substream *substream;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(pcm->streams); i++) {
|
||||
substream = pcm->streams[i].substream;
|
||||
if (substream) {
|
||||
snd_dma_free_pages(&substream->dma_buffer);
|
||||
substream->dma_buffer.area = NULL;
|
||||
substream->dma_buffer.addr = 0;
|
||||
}
|
||||
}
|
||||
return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
|
||||
card->dev,
|
||||
sprd_pcm_hardware.buffer_bytes_max);
|
||||
}
|
||||
|
||||
static const struct snd_soc_component_driver sprd_soc_component = {
|
||||
|
@ -512,9 +453,7 @@ static const struct snd_soc_component_driver sprd_soc_component = {
|
|||
.hw_free = sprd_pcm_hw_free,
|
||||
.trigger = sprd_pcm_trigger,
|
||||
.pointer = sprd_pcm_pointer,
|
||||
.mmap = sprd_pcm_mmap,
|
||||
.pcm_construct = sprd_pcm_new,
|
||||
.pcm_destruct = sprd_pcm_free,
|
||||
.compress_ops = &sprd_platform_compress_ops,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue