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