Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
Alexander A. Klimov | 3323a14 | 2020-07-18 13:24:03 +0200 | [diff] [blame] | 3 | * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com |
Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 4 | * Author: Peter Ujfalusi <peter.ujfalusi@ti.com> |
| 5 | */ |
| 6 | |
Peter Ujfalusi | 1cc0fe2 | 2018-05-15 09:43:35 +0300 | [diff] [blame] | 7 | #include <linux/device.h> |
Peter Ujfalusi | 7bf8ad1 | 2018-05-15 09:43:34 +0300 | [diff] [blame] | 8 | #include <linux/module.h> |
Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 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> |
Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 14 | |
| 15 | #include "sdma-pcm.h" |
| 16 | |
| 17 | static const struct snd_pcm_hardware sdma_pcm_hardware = { |
| 18 | .info = SNDRV_PCM_INFO_MMAP | |
| 19 | SNDRV_PCM_INFO_MMAP_VALID | |
| 20 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | |
| 21 | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP | |
| 22 | SNDRV_PCM_INFO_INTERLEAVED, |
| 23 | .period_bytes_min = 32, |
| 24 | .period_bytes_max = 64 * 1024, |
| 25 | .buffer_bytes_max = 128 * 1024, |
| 26 | .periods_min = 2, |
| 27 | .periods_max = 255, |
| 28 | }; |
| 29 | |
| 30 | static const struct snd_dmaengine_pcm_config sdma_dmaengine_pcm_config = { |
| 31 | .pcm_hardware = &sdma_pcm_hardware, |
| 32 | .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, |
Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 33 | .prealloc_buffer_size = 128 * 1024, |
| 34 | }; |
| 35 | |
| 36 | int sdma_pcm_platform_register(struct device *dev, |
| 37 | char *txdmachan, char *rxdmachan) |
| 38 | { |
| 39 | struct snd_dmaengine_pcm_config *config; |
Arnd Bergmann | 642aafe | 2019-03-07 16:16:08 +0100 | [diff] [blame] | 40 | unsigned int flags = 0; |
Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 41 | |
| 42 | /* Standard names for the directions: 'tx' and 'rx' */ |
| 43 | if (!txdmachan && !rxdmachan) |
| 44 | return devm_snd_dmaengine_pcm_register(dev, |
Arnd Bergmann | 642aafe | 2019-03-07 16:16:08 +0100 | [diff] [blame] | 45 | &sdma_dmaengine_pcm_config, 0); |
Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 46 | |
| 47 | config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); |
| 48 | if (!config) |
| 49 | return -ENOMEM; |
| 50 | |
| 51 | *config = sdma_dmaengine_pcm_config; |
| 52 | |
| 53 | if (!txdmachan || !rxdmachan) { |
| 54 | /* One direction only PCM */ |
| 55 | flags |= SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX; |
| 56 | if (!txdmachan) { |
| 57 | txdmachan = rxdmachan; |
| 58 | rxdmachan = NULL; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | config->chan_names[0] = txdmachan; |
| 63 | config->chan_names[1] = rxdmachan; |
| 64 | |
Peter Ujfalusi | dd7e8d9 | 2019-10-28 13:52:07 +0200 | [diff] [blame] | 65 | return devm_snd_dmaengine_pcm_register(dev, config, flags); |
Peter Ujfalusi | dde637f | 2018-05-07 11:49:54 +0300 | [diff] [blame] | 66 | } |
| 67 | EXPORT_SYMBOL_GPL(sdma_pcm_platform_register); |
Peter Ujfalusi | 7bf8ad1 | 2018-05-15 09:43:34 +0300 | [diff] [blame] | 68 | |
| 69 | MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>"); |
| 70 | MODULE_DESCRIPTION("sDMA PCM ASoC platform driver"); |
| 71 | MODULE_LICENSE("GPL v2"); |