Commit ba447289 authored by Takashi Iwai's avatar Takashi Iwai

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: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210802072815.13551-16-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 8c505b77
...@@ -204,8 +204,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component, ...@@ -204,8 +204,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component,
if (!dma_params) { if (!dma_params) {
dev_warn(component->dev, "no dma parameters setting\n"); dev_warn(component->dev, "no dma parameters setting\n");
dma_private->params = NULL; dma_private->params = NULL;
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
runtime->dma_bytes = totsize;
return 0; return 0;
} }
...@@ -217,9 +215,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component, ...@@ -217,9 +215,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component,
return ret; return ret;
} }
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
runtime->dma_bytes = totsize;
sg_num = totsize / period; sg_num = totsize / period;
dma_private->dma_addr_offset = totsize / channels; dma_private->dma_addr_offset = totsize / channels;
...@@ -310,7 +305,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component, ...@@ -310,7 +305,6 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component,
static int sprd_pcm_hw_free(struct snd_soc_component *component, static int sprd_pcm_hw_free(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
snd_pcm_set_runtime_buffer(substream, NULL);
sprd_pcm_release_dma_channel(substream); sprd_pcm_release_dma_channel(substream);
return 0; return 0;
...@@ -435,73 +429,20 @@ static snd_pcm_uframes_t sprd_pcm_pointer(struct snd_soc_component *component, ...@@ -435,73 +429,20 @@ static snd_pcm_uframes_t sprd_pcm_pointer(struct snd_soc_component *component,
return x; 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, static int sprd_pcm_new(struct snd_soc_component *component,
struct snd_soc_pcm_runtime *rtd) struct snd_soc_pcm_runtime *rtd)
{ {
struct snd_card *card = rtd->card->snd_card; struct snd_card *card = rtd->card->snd_card;
struct snd_pcm *pcm = rtd->pcm; struct snd_pcm *pcm = rtd->pcm;
struct snd_pcm_substream *substream;
int ret; int ret;
ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
if (ret) if (ret)
return ret; return ret;
substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
if (substream) { card->dev,
ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, card->dev, sprd_pcm_hardware.buffer_bytes_max);
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;
}
}
} }
static const struct snd_soc_component_driver sprd_soc_component = { static const struct snd_soc_component_driver sprd_soc_component = {
...@@ -512,9 +453,7 @@ 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, .hw_free = sprd_pcm_hw_free,
.trigger = sprd_pcm_trigger, .trigger = sprd_pcm_trigger,
.pointer = sprd_pcm_pointer, .pointer = sprd_pcm_pointer,
.mmap = sprd_pcm_mmap,
.pcm_construct = sprd_pcm_new, .pcm_construct = sprd_pcm_new,
.pcm_destruct = sprd_pcm_free,
.compress_ops = &sprd_platform_compress_ops, .compress_ops = &sprd_platform_compress_ops,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment