xref: /openbmc/linux/sound/soc/samsung/dmaengine.c (revision 6d8e62c3)
1 /*
2  * dmaengine.c - Samsung dmaengine wrapper
3  *
4  * Author: Mark Brown <broonie@linaro.org>
5  * Copyright 2013 Linaro
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  */
17 
18 #include <linux/module.h>
19 #include <linux/amba/pl08x.h>
20 #include <linux/platform_data/dma-s3c24xx.h>
21 
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/dmaengine_pcm.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dai.h>
28 
29 #include "dma.h"
30 
31 #ifdef CONFIG_ARCH_S3C64XX
32 #define filter_fn pl08x_filter_id
33 #elif defined(CONFIG_ARCH_S3C24XX)
34 #define filter_fn s3c24xx_dma_filter
35 #else
36 #define filter_fn NULL
37 #endif
38 
39 static const struct snd_dmaengine_pcm_config samsung_dmaengine_pcm_config = {
40 	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
41 	.compat_filter_fn = filter_fn,
42 };
43 
44 void samsung_asoc_init_dma_data(struct snd_soc_dai *dai,
45 				struct s3c_dma_params *playback,
46 				struct s3c_dma_params *capture)
47 {
48 	struct snd_dmaengine_dai_dma_data *playback_data = NULL;
49 	struct snd_dmaengine_dai_dma_data *capture_data = NULL;
50 
51 	if (playback) {
52 		playback_data = &playback->dma_data;
53 		playback_data->filter_data = (void *)playback->channel;
54 		playback_data->chan_name = playback->ch_name;
55 		playback_data->addr = playback->dma_addr;
56 		playback_data->addr_width = playback->dma_size;
57 	}
58 	if (capture) {
59 		capture_data = &capture->dma_data;
60 		capture_data->filter_data = (void *)capture->channel;
61 		capture_data->chan_name = capture->ch_name;
62 		capture_data->addr = capture->dma_addr;
63 		capture_data->addr_width = capture->dma_size;
64 	}
65 
66 	snd_soc_dai_init_dma_data(dai, playback_data, capture_data);
67 }
68 EXPORT_SYMBOL_GPL(samsung_asoc_init_dma_data);
69 
70 int samsung_asoc_dma_platform_register(struct device *dev)
71 {
72 	return devm_snd_dmaengine_pcm_register(dev,
73 			&samsung_dmaengine_pcm_config,
74 			SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME |
75 			SND_DMAENGINE_PCM_FLAG_COMPAT);
76 }
77 EXPORT_SYMBOL_GPL(samsung_asoc_dma_platform_register);
78 
79 MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
80 MODULE_DESCRIPTION("Samsung dmaengine ASoC driver");
81 MODULE_LICENSE("GPL");
82