Skip to content

Commit b010c78

Browse files
TE-N-ShengjiuWangbroonie
authored andcommitted
ASoC: fsl_asrc_dma: allocate memory from dma device
The dma-coherent property is used to indicate a device is capable of coherent DMA operations. On i.MX952, one of EDMA devices support such feature, in order to support the EDMA device, the memory needs to be allocated from the DMA device. Make this driver to support both non dma-coherent and dma-coherent dma engine. Remove dma coerce_mask_and coherent() because DMA provider already set it according to its capability. Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260206014805.3897764-5-shengjiu.wang@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 6a8c6f5 commit b010c78

1 file changed

Lines changed: 41 additions & 7 deletions

File tree

sound/soc/fsl/fsl_asrc_dma.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,52 @@ fsl_asrc_dma_pcm_pointer(struct snd_soc_component *component,
449449
static int fsl_asrc_dma_pcm_new(struct snd_soc_component *component,
450450
struct snd_soc_pcm_runtime *rtd)
451451
{
452-
struct snd_card *card = rtd->card->snd_card;
452+
struct device *dev = component->dev;
453+
struct fsl_asrc *asrc = dev_get_drvdata(dev);
454+
struct fsl_asrc_pair *pair;
453455
struct snd_pcm *pcm = rtd->pcm;
456+
struct dma_chan *chan;
454457
int ret;
455458

456-
ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
457-
if (ret) {
458-
dev_err(card->dev, "failed to set DMA mask\n");
459-
return ret;
459+
pair = kzalloc(size_add(sizeof(*pair), asrc->pair_priv_size), GFP_KERNEL);
460+
if (!pair)
461+
return -ENOMEM;
462+
463+
pair->asrc = asrc;
464+
pair->private = (void *)pair + sizeof(struct fsl_asrc_pair);
465+
466+
/* Request a pair, which will be released later.
467+
* Request pair function needs channel num as input, for this
468+
* pair, we just request "1" channel temporarily.
469+
*/
470+
ret = asrc->request_pair(1, pair);
471+
if (ret < 0) {
472+
dev_err(dev, "failed to request asrc pair\n");
473+
goto req_pair_err;
474+
}
475+
476+
/* Request a dma channel, which will be released later. */
477+
chan = asrc->get_dma_channel(pair, IN);
478+
if (!chan) {
479+
dev_err(dev, "failed to get dma channel\n");
480+
ret = -EINVAL;
481+
goto dma_chan_err;
460482
}
461483

462-
return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
463-
card->dev, FSL_ASRC_DMABUF_SIZE);
484+
ret = snd_pcm_set_fixed_buffer_all(pcm,
485+
SNDRV_DMA_TYPE_DEV,
486+
chan->device->dev,
487+
FSL_ASRC_DMABUF_SIZE);
488+
489+
dma_release_channel(chan);
490+
491+
dma_chan_err:
492+
asrc->release_pair(pair);
493+
494+
req_pair_err:
495+
kfree(pair);
496+
497+
return ret;
464498
}
465499

466500
struct snd_soc_component_driver fsl_asrc_component = {

0 commit comments

Comments
 (0)