Commit 13ce4d8f authored by Takashi Iwai's avatar Takashi Iwai

ASoC: bcm: Use managed PCM buffer allocation

As the standard buffer allocation helper supports WC pages now, we can
convert bcm 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-7-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 7f2da3d7
...@@ -46,10 +46,6 @@ static int bcm63xx_pcm_hw_params(struct snd_soc_component *component, ...@@ -46,10 +46,6 @@ static int bcm63xx_pcm_hw_params(struct snd_soc_component *component,
{ {
struct i2s_dma_desc *dma_desc; struct i2s_dma_desc *dma_desc;
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
runtime->dma_bytes = params_buffer_bytes(params);
dma_desc = kzalloc(sizeof(*dma_desc), GFP_NOWAIT); dma_desc = kzalloc(sizeof(*dma_desc), GFP_NOWAIT);
if (!dma_desc) if (!dma_desc)
...@@ -68,7 +64,6 @@ static int bcm63xx_pcm_hw_free(struct snd_soc_component *component, ...@@ -68,7 +64,6 @@ static int bcm63xx_pcm_hw_free(struct snd_soc_component *component,
dma_desc = snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream); dma_desc = snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream);
kfree(dma_desc); kfree(dma_desc);
snd_pcm_set_runtime_buffer(substream, NULL);
return 0; return 0;
} }
...@@ -190,19 +185,6 @@ bcm63xx_pcm_pointer(struct snd_soc_component *component, ...@@ -190,19 +185,6 @@ bcm63xx_pcm_pointer(struct snd_soc_component *component,
return x == substream->runtime->buffer_size ? 0 : x; return x == substream->runtime->buffer_size ? 0 : x;
} }
static int bcm63xx_pcm_mmap(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct vm_area_struct *vma)
{
struct snd_pcm_runtime *runtime = substream->runtime;
return dma_mmap_wc(substream->pcm->card->dev, vma,
runtime->dma_area,
runtime->dma_addr,
runtime->dma_bytes);
}
static int bcm63xx_pcm_open(struct snd_soc_component *component, static int bcm63xx_pcm_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
...@@ -362,25 +344,6 @@ static irqreturn_t i2s_dma_isr(int irq, void *bcm_i2s_priv) ...@@ -362,25 +344,6 @@ static irqreturn_t i2s_dma_isr(int irq, void *bcm_i2s_priv)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static int bcm63xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
{
struct snd_pcm_substream *substream = pcm->streams[stream].substream;
struct snd_dma_buffer *buf = &substream->dma_buffer;
size_t size = bcm63xx_pcm_hardware.buffer_bytes_max;
buf->dev.type = SNDRV_DMA_TYPE_DEV;
buf->dev.dev = pcm->card->dev;
buf->private_data = NULL;
buf->area = dma_alloc_wc(pcm->card->dev,
size, &buf->addr,
GFP_KERNEL);
if (!buf->area)
return -ENOMEM;
buf->bytes = size;
return 0;
}
static int bcm63xx_soc_pcm_new(struct snd_soc_component *component, static int bcm63xx_soc_pcm_new(struct snd_soc_component *component,
struct snd_soc_pcm_runtime *rtd) struct snd_soc_pcm_runtime *rtd)
{ {
...@@ -394,49 +357,18 @@ static int bcm63xx_soc_pcm_new(struct snd_soc_component *component, ...@@ -394,49 +357,18 @@ static int bcm63xx_soc_pcm_new(struct snd_soc_component *component,
ret = dma_coerce_mask_and_coherent(pcm->card->dev, DMA_BIT_MASK(32)); ret = dma_coerce_mask_and_coherent(pcm->card->dev, DMA_BIT_MASK(32));
if (ret) if (ret)
goto out; return ret;
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
ret = bcm63xx_pcm_preallocate_dma_buffer(pcm,
SNDRV_PCM_STREAM_PLAYBACK);
if (ret)
goto out;
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
i2s_priv->play_substream = i2s_priv->play_substream =
pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
} if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
ret = bcm63xx_pcm_preallocate_dma_buffer(pcm,
SNDRV_PCM_STREAM_CAPTURE);
if (ret)
goto out;
i2s_priv->capture_substream = i2s_priv->capture_substream =
pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
}
out: return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_WC,
return ret; pcm->card->dev,
} bcm63xx_pcm_hardware.buffer_bytes_max);
static void bcm63xx_pcm_free_dma_buffers(struct snd_soc_component *component,
struct snd_pcm *pcm)
{
int stream;
struct snd_dma_buffer *buf;
struct snd_pcm_substream *substream;
for (stream = 0; stream < 2; stream++) {
substream = pcm->streams[stream].substream;
if (!substream)
continue;
buf = &substream->dma_buffer;
if (!buf->area)
continue;
dma_free_wc(pcm->card->dev, buf->bytes,
buf->area, buf->addr);
buf->area = NULL;
}
} }
static const struct snd_soc_component_driver bcm63xx_soc_platform = { static const struct snd_soc_component_driver bcm63xx_soc_platform = {
...@@ -447,9 +379,7 @@ static const struct snd_soc_component_driver bcm63xx_soc_platform = { ...@@ -447,9 +379,7 @@ static const struct snd_soc_component_driver bcm63xx_soc_platform = {
.prepare = bcm63xx_pcm_prepare, .prepare = bcm63xx_pcm_prepare,
.trigger = bcm63xx_pcm_trigger, .trigger = bcm63xx_pcm_trigger,
.pointer = bcm63xx_pcm_pointer, .pointer = bcm63xx_pcm_pointer,
.mmap = bcm63xx_pcm_mmap,
.pcm_construct = bcm63xx_soc_pcm_new, .pcm_construct = bcm63xx_soc_pcm_new,
.pcm_destruct = bcm63xx_pcm_free_dma_buffers,
}; };
int bcm63xx_soc_platform_probe(struct platform_device *pdev, int bcm63xx_soc_platform_probe(struct platform_device *pdev,
......
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