Commit 18936487 authored by Takashi Iwai's avatar Takashi Iwai

ASoC: tegra: Use managed buffer allocation

As the standard buffer allocation helper supports WC pages now, we can
convert imx-pcm-rpmsg driver to use that.  This allows us to remove
lots of superfluous code.
Acked-by: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210802072815.13551-10-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 0e1b598f
...@@ -612,12 +612,9 @@ static const struct snd_soc_component_driver tegra210_admaif_cmpnt = { ...@@ -612,12 +612,9 @@ static const struct snd_soc_component_driver tegra210_admaif_cmpnt = {
.controls = tegra210_admaif_controls, .controls = tegra210_admaif_controls,
.num_controls = ARRAY_SIZE(tegra210_admaif_controls), .num_controls = ARRAY_SIZE(tegra210_admaif_controls),
.pcm_construct = tegra_pcm_construct, .pcm_construct = tegra_pcm_construct,
.pcm_destruct = tegra_pcm_destruct,
.open = tegra_pcm_open, .open = tegra_pcm_open,
.close = tegra_pcm_close, .close = tegra_pcm_close,
.hw_params = tegra_pcm_hw_params, .hw_params = tegra_pcm_hw_params,
.hw_free = tegra_pcm_hw_free,
.mmap = tegra_pcm_mmap,
.pointer = tegra_pcm_pointer, .pointer = tegra_pcm_pointer,
}; };
...@@ -625,12 +622,9 @@ static const struct snd_soc_component_driver tegra186_admaif_cmpnt = { ...@@ -625,12 +622,9 @@ static const struct snd_soc_component_driver tegra186_admaif_cmpnt = {
.controls = tegra186_admaif_controls, .controls = tegra186_admaif_controls,
.num_controls = ARRAY_SIZE(tegra186_admaif_controls), .num_controls = ARRAY_SIZE(tegra186_admaif_controls),
.pcm_construct = tegra_pcm_construct, .pcm_construct = tegra_pcm_construct,
.pcm_destruct = tegra_pcm_destruct,
.open = tegra_pcm_open, .open = tegra_pcm_open,
.close = tegra_pcm_close, .close = tegra_pcm_close,
.hw_params = tegra_pcm_hw_params, .hw_params = tegra_pcm_hw_params,
.hw_free = tegra_pcm_hw_free,
.mmap = tegra_pcm_mmap,
.pointer = tegra_pcm_pointer, .pointer = tegra_pcm_pointer,
}; };
......
...@@ -171,41 +171,10 @@ int tegra_pcm_hw_params(struct snd_soc_component *component, ...@@ -171,41 +171,10 @@ int tegra_pcm_hw_params(struct snd_soc_component *component,
return ret; return ret;
} }
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(tegra_pcm_hw_params); EXPORT_SYMBOL_GPL(tegra_pcm_hw_params);
int tegra_pcm_hw_free(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
if (rtd->dai_link->no_pcm)
return 0;
snd_pcm_set_runtime_buffer(substream, NULL);
return 0;
}
EXPORT_SYMBOL_GPL(tegra_pcm_hw_free);
int tegra_pcm_mmap(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct vm_area_struct *vma)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_pcm_runtime *runtime = substream->runtime;
if (rtd->dai_link->no_pcm)
return 0;
return dma_mmap_wc(substream->pcm->card->dev, vma, runtime->dma_area,
runtime->dma_addr, runtime->dma_bytes);
}
EXPORT_SYMBOL_GPL(tegra_pcm_mmap);
snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component, snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
...@@ -213,41 +182,6 @@ snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component, ...@@ -213,41 +182,6 @@ snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component,
} }
EXPORT_SYMBOL_GPL(tegra_pcm_pointer); EXPORT_SYMBOL_GPL(tegra_pcm_pointer);
static int tegra_pcm_preallocate_dma_buffer(struct device *dev, struct snd_pcm *pcm, int stream,
size_t size)
{
struct snd_pcm_substream *substream = pcm->streams[stream].substream;
struct snd_dma_buffer *buf = &substream->dma_buffer;
buf->area = dma_alloc_wc(dev, size, &buf->addr, GFP_KERNEL);
if (!buf->area)
return -ENOMEM;
buf->private_data = NULL;
buf->dev.type = SNDRV_DMA_TYPE_DEV;
buf->dev.dev = dev;
buf->bytes = size;
return 0;
}
static void tegra_pcm_deallocate_dma_buffer(struct snd_pcm *pcm, int stream)
{
struct snd_pcm_substream *substream;
struct snd_dma_buffer *buf;
substream = pcm->streams[stream].substream;
if (!substream)
return;
buf = &substream->dma_buffer;
if (!buf->area)
return;
dma_free_wc(buf->dev.dev, buf->bytes, buf->area, buf->addr);
buf->area = NULL;
}
static int tegra_pcm_dma_allocate(struct device *dev, struct snd_soc_pcm_runtime *rtd, static int tegra_pcm_dma_allocate(struct device *dev, struct snd_soc_pcm_runtime *rtd,
size_t size) size_t size)
{ {
...@@ -258,24 +192,7 @@ static int tegra_pcm_dma_allocate(struct device *dev, struct snd_soc_pcm_runtime ...@@ -258,24 +192,7 @@ static int tegra_pcm_dma_allocate(struct device *dev, struct snd_soc_pcm_runtime
if (ret < 0) if (ret < 0)
return ret; return ret;
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_WC, dev, size);
ret = tegra_pcm_preallocate_dma_buffer(dev, pcm, SNDRV_PCM_STREAM_PLAYBACK, size);
if (ret)
goto err;
}
if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
ret = tegra_pcm_preallocate_dma_buffer(dev, pcm, SNDRV_PCM_STREAM_CAPTURE, size);
if (ret)
goto err_free_play;
}
return 0;
err_free_play:
tegra_pcm_deallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_PLAYBACK);
err:
return ret;
} }
int tegra_pcm_construct(struct snd_soc_component *component, int tegra_pcm_construct(struct snd_soc_component *component,
...@@ -294,14 +211,6 @@ int tegra_pcm_construct(struct snd_soc_component *component, ...@@ -294,14 +211,6 @@ int tegra_pcm_construct(struct snd_soc_component *component,
} }
EXPORT_SYMBOL_GPL(tegra_pcm_construct); EXPORT_SYMBOL_GPL(tegra_pcm_construct);
void tegra_pcm_destruct(struct snd_soc_component *component,
struct snd_pcm *pcm)
{
tegra_pcm_deallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_CAPTURE);
tegra_pcm_deallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_PLAYBACK);
}
EXPORT_SYMBOL_GPL(tegra_pcm_destruct);
MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
MODULE_DESCRIPTION("Tegra PCM ASoC driver"); MODULE_DESCRIPTION("Tegra PCM ASoC driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
int tegra_pcm_construct(struct snd_soc_component *component, int tegra_pcm_construct(struct snd_soc_component *component,
struct snd_soc_pcm_runtime *rtd); struct snd_soc_pcm_runtime *rtd);
void tegra_pcm_destruct(struct snd_soc_component *component,
struct snd_pcm *pcm);
int tegra_pcm_open(struct snd_soc_component *component, int tegra_pcm_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream); struct snd_pcm_substream *substream);
int tegra_pcm_close(struct snd_soc_component *component, int tegra_pcm_close(struct snd_soc_component *component,
...@@ -31,11 +29,6 @@ int tegra_pcm_close(struct snd_soc_component *component, ...@@ -31,11 +29,6 @@ int tegra_pcm_close(struct snd_soc_component *component,
int tegra_pcm_hw_params(struct snd_soc_component *component, int tegra_pcm_hw_params(struct snd_soc_component *component,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params); struct snd_pcm_hw_params *params);
int tegra_pcm_hw_free(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int tegra_pcm_mmap(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct vm_area_struct *vma);
snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component, snd_pcm_uframes_t tegra_pcm_pointer(struct snd_soc_component *component,
struct snd_pcm_substream *substream); struct snd_pcm_substream *substream);
int tegra_pcm_platform_register(struct device *dev); int tegra_pcm_platform_register(struct device *dev);
......
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