xref: /openbmc/linux/sound/soc/ti/edma-pcm.c (revision 884caada)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * edma-pcm.c - eDMA PCM driver using dmaengine for AM3xxx, AM4xxx
4  *
5  * Copyright (C) 2014 Texas Instruments, Inc.
6  *
7  * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
8  *
9  * Based on: sound/soc/tegra/tegra_pcm.c
10  */
11 
12 #include <linux/module.h>
13 #include <sound/core.h>
14 #include <sound/pcm.h>
15 #include <sound/pcm_params.h>
16 #include <sound/soc.h>
17 #include <sound/dmaengine_pcm.h>
18 
19 #include "edma-pcm.h"
20 
21 static const struct snd_pcm_hardware edma_pcm_hardware = {
22 	.info			= SNDRV_PCM_INFO_MMAP |
23 				  SNDRV_PCM_INFO_MMAP_VALID |
24 				  SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
25 				  SNDRV_PCM_INFO_NO_PERIOD_WAKEUP |
26 				  SNDRV_PCM_INFO_INTERLEAVED,
27 	.buffer_bytes_max	= 128 * 1024,
28 	.period_bytes_min	= 32,
29 	.period_bytes_max	= 64 * 1024,
30 	.periods_min		= 2,
31 	.periods_max		= 19, /* Limit by edma dmaengine driver */
32 };
33 
34 static const struct snd_dmaengine_pcm_config edma_dmaengine_pcm_config = {
35 	.pcm_hardware = &edma_pcm_hardware,
36 	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
37 	.prealloc_buffer_size = 128 * 1024,
38 };
39 
40 int edma_pcm_platform_register(struct device *dev)
41 {
42 	struct snd_dmaengine_pcm_config *config;
43 
44 	if (dev->of_node)
45 		return devm_snd_dmaengine_pcm_register(dev,
46 						&edma_dmaengine_pcm_config, 0);
47 
48 	config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL);
49 	if (!config)
50 		return -ENOMEM;
51 
52 	*config = edma_dmaengine_pcm_config;
53 
54 	config->chan_names[0] = "tx";
55 	config->chan_names[1] = "rx";
56 
57 	return devm_snd_dmaengine_pcm_register(dev, config, 0);
58 }
59 EXPORT_SYMBOL_GPL(edma_pcm_platform_register);
60 
61 MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
62 MODULE_DESCRIPTION("eDMA PCM ASoC platform driver");
63 MODULE_LICENSE("GPL");
64