xref: /linux/sound/soc/fsl/imx-pcm-dma.c (revision 36ec807b627b4c0a0a382f0ae48eac7187d14b2b)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2f19493a3SShawn Guo /*
3f19493a3SShawn Guo  * imx-pcm-dma-mx2.c  --  ALSA Soc Audio Layer
4f19493a3SShawn Guo  *
5f19493a3SShawn Guo  * Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
6f19493a3SShawn Guo  *
7f19493a3SShawn Guo  * This code is based on code copyrighted by Freescale,
8f19493a3SShawn Guo  * Liam Girdwood, Javier Martin and probably others.
9f19493a3SShawn Guo  */
10f19493a3SShawn Guo #include <linux/platform_device.h>
11f19493a3SShawn Guo #include <linux/dmaengine.h>
12f19493a3SShawn Guo #include <linux/types.h>
133c1c32d3SMark Brown #include <linux/module.h>
14f19493a3SShawn Guo 
15f19493a3SShawn Guo #include <sound/core.h>
16f19493a3SShawn Guo #include <sound/pcm.h>
17f19493a3SShawn Guo #include <sound/soc.h>
18f19493a3SShawn Guo #include <sound/dmaengine_pcm.h>
19f19493a3SShawn Guo 
20f19493a3SShawn Guo #include "imx-pcm.h"
21f19493a3SShawn Guo 
22f19493a3SShawn Guo static bool filter(struct dma_chan *chan, void *param)
23f19493a3SShawn Guo {
24f19493a3SShawn Guo 	if (!imx_dma_is_general_purpose(chan))
25f19493a3SShawn Guo 		return false;
26f19493a3SShawn Guo 
2790130d2eSMark Brown 	chan->private = param;
28f19493a3SShawn Guo 
29f19493a3SShawn Guo 	return true;
30f19493a3SShawn Guo }
31f19493a3SShawn Guo 
32adaa3229SLars-Peter Clausen static const struct snd_dmaengine_pcm_config imx_dmaengine_pcm_config = {
33adaa3229SLars-Peter Clausen 	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
34adaa3229SLars-Peter Clausen 	.compat_filter_fn = filter,
35f19493a3SShawn Guo };
36f19493a3SShawn Guo 
379b3ff637SSascha Hauer int imx_pcm_dma_init(struct platform_device *pdev)
38f19493a3SShawn Guo {
390d69e0ddSShengjiu Wang 	struct snd_dmaengine_pcm_config *config;
400d69e0ddSShengjiu Wang 
410d69e0ddSShengjiu Wang 	config = devm_kzalloc(&pdev->dev,
420d69e0ddSShengjiu Wang 			sizeof(struct snd_dmaengine_pcm_config), GFP_KERNEL);
4310974ccfSJulia Lawall 	if (!config)
4410974ccfSJulia Lawall 		return -ENOMEM;
450d69e0ddSShengjiu Wang 	*config = imx_dmaengine_pcm_config;
460d69e0ddSShengjiu Wang 
477e6d18acSLars-Peter Clausen 	return devm_snd_dmaengine_pcm_register(&pdev->dev,
480d69e0ddSShengjiu Wang 		config,
49adaa3229SLars-Peter Clausen 		SND_DMAENGINE_PCM_FLAG_COMPAT);
50adaa3229SLars-Peter Clausen }
51dbdf6b54SShawn Guo EXPORT_SYMBOL_GPL(imx_pcm_dma_init);
52adaa3229SLars-Peter Clausen 
53*7478e15bSJeff Johnson MODULE_DESCRIPTION("Freescale i.MX PCM DMA interface");
543c1c32d3SMark Brown MODULE_LICENSE("GPL");
55