xref: /openbmc/linux/sound/soc/ti/sdma-pcm.c (revision 69fad28c)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
4  *  Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
5  */
6 
7 #include <linux/device.h>
8 #include <linux/module.h>
9 #include <sound/core.h>
10 #include <sound/pcm.h>
11 #include <sound/pcm_params.h>
12 #include <sound/soc.h>
13 #include <sound/dmaengine_pcm.h>
14 #include <linux/omap-dmaengine.h>
15 
16 #include "sdma-pcm.h"
17 
18 static const struct snd_pcm_hardware sdma_pcm_hardware = {
19 	.info			= SNDRV_PCM_INFO_MMAP |
20 				  SNDRV_PCM_INFO_MMAP_VALID |
21 				  SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
22 				  SNDRV_PCM_INFO_NO_PERIOD_WAKEUP |
23 				  SNDRV_PCM_INFO_INTERLEAVED,
24 	.period_bytes_min	= 32,
25 	.period_bytes_max	= 64 * 1024,
26 	.buffer_bytes_max	= 128 * 1024,
27 	.periods_min		= 2,
28 	.periods_max		= 255,
29 };
30 
31 static const struct snd_dmaengine_pcm_config sdma_dmaengine_pcm_config = {
32 	.pcm_hardware = &sdma_pcm_hardware,
33 	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
34 	.compat_filter_fn = omap_dma_filter_fn,
35 	.prealloc_buffer_size = 128 * 1024,
36 };
37 
38 int sdma_pcm_platform_register(struct device *dev,
39 			       char *txdmachan, char *rxdmachan)
40 {
41 	struct snd_dmaengine_pcm_config *config;
42 	unsigned int flags = SND_DMAENGINE_PCM_FLAG_COMPAT;
43 
44 	/* Standard names for the directions: 'tx' and 'rx' */
45 	if (!txdmachan && !rxdmachan)
46 		return devm_snd_dmaengine_pcm_register(dev,
47 						&sdma_dmaengine_pcm_config,
48 						flags);
49 
50 	config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL);
51 	if (!config)
52 		return -ENOMEM;
53 
54 	*config = sdma_dmaengine_pcm_config;
55 
56 	if (!txdmachan || !rxdmachan) {
57 		/* One direction only PCM */
58 		flags |= SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX;
59 		if (!txdmachan) {
60 			txdmachan = rxdmachan;
61 			rxdmachan = NULL;
62 		}
63 	}
64 
65 	config->chan_names[0] = txdmachan;
66 	config->chan_names[1] = rxdmachan;
67 
68 	return devm_snd_dmaengine_pcm_register(dev, config, flags);
69 }
70 EXPORT_SYMBOL_GPL(sdma_pcm_platform_register);
71 
72 MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
73 MODULE_DESCRIPTION("sDMA PCM ASoC platform driver");
74 MODULE_LICENSE("GPL v2");
75