xref: /openbmc/linux/sound/soc/fsl/imx-pcm-dma.c (revision a44e4f3a)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * imx-pcm-dma-mx2.c  --  ALSA Soc Audio Layer
4  *
5  * Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
6  *
7  * This code is based on code copyrighted by Freescale,
8  * Liam Girdwood, Javier Martin and probably others.
9  */
10 #include <linux/platform_device.h>
11 #include <linux/dmaengine.h>
12 #include <linux/types.h>
13 #include <linux/module.h>
14 
15 #include <sound/core.h>
16 #include <sound/pcm.h>
17 #include <sound/soc.h>
18 #include <sound/dmaengine_pcm.h>
19 
20 #include "imx-pcm.h"
21 
22 static bool filter(struct dma_chan *chan, void *param)
23 {
24 	if (!imx_dma_is_general_purpose(chan))
25 		return false;
26 
27 	chan->private = param;
28 
29 	return true;
30 }
31 
32 static const struct snd_dmaengine_pcm_config imx_dmaengine_pcm_config = {
33 	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
34 	.compat_filter_fn = filter,
35 };
36 
37 int imx_pcm_dma_init(struct platform_device *pdev, size_t size)
38 {
39 	struct snd_dmaengine_pcm_config *config;
40 
41 	config = devm_kzalloc(&pdev->dev,
42 			sizeof(struct snd_dmaengine_pcm_config), GFP_KERNEL);
43 	if (!config)
44 		return -ENOMEM;
45 	*config = imx_dmaengine_pcm_config;
46 
47 	return devm_snd_dmaengine_pcm_register(&pdev->dev,
48 		config,
49 		SND_DMAENGINE_PCM_FLAG_COMPAT);
50 }
51 EXPORT_SYMBOL_GPL(imx_pcm_dma_init);
52 
53 MODULE_LICENSE("GPL");
54