sdma-pcm.c 2.0 KB

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