dmaengine_pcm.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2012, Analog Devices Inc.
  3. * Author: Lars-Peter Clausen <lars@metafoo.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * You should have received a copy of the GNU General Public License along
  11. * with this program; if not, write to the Free Software Foundation, Inc.,
  12. * 675 Mass Ave, Cambridge, MA 02139, USA.
  13. *
  14. */
  15. #ifndef __SOUND_DMAENGINE_PCM_H__
  16. #define __SOUND_DMAENGINE_PCM_H__
  17. #include <sound/pcm.h>
  18. #include <sound/soc.h>
  19. #include <linux/dmaengine.h>
  20. /**
  21. * snd_pcm_substream_to_dma_direction - Get dma_transfer_direction for a PCM
  22. * substream
  23. * @substream: PCM substream
  24. */
  25. static inline enum dma_transfer_direction
  26. snd_pcm_substream_to_dma_direction(const struct snd_pcm_substream *substream)
  27. {
  28. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  29. return DMA_MEM_TO_DEV;
  30. else
  31. return DMA_DEV_TO_MEM;
  32. }
  33. int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream,
  34. const struct snd_pcm_hw_params *params, struct dma_slave_config *slave_config);
  35. int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd);
  36. snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream);
  37. snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream *substream);
  38. int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
  39. struct dma_chan *chan);
  40. int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream);
  41. int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
  42. dma_filter_fn filter_fn, void *filter_data);
  43. int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream);
  44. struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn,
  45. void *filter_data);
  46. struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream);
  47. /**
  48. * struct snd_dmaengine_dai_dma_data - DAI DMA configuration data
  49. * @addr: Address of the DAI data source or destination register.
  50. * @addr_width: Width of the DAI data source or destination register.
  51. * @maxburst: Maximum number of words(note: words, as in units of the
  52. * src_addr_width member, not bytes) that can be send to or received from the
  53. * DAI in one burst.
  54. * @slave_id: Slave requester id for the DMA channel.
  55. * @filter_data: Custom DMA channel filter data, this will usually be used when
  56. * requesting the DMA channel.
  57. * @chan_name: Custom channel name to use when requesting DMA channel.
  58. * @fifo_size: FIFO size of the DAI controller in bytes
  59. */
  60. struct snd_dmaengine_dai_dma_data {
  61. dma_addr_t addr;
  62. enum dma_slave_buswidth addr_width;
  63. u32 maxburst;
  64. unsigned int slave_id;
  65. void *filter_data;
  66. const char *chan_name;
  67. unsigned int fifo_size;
  68. };
  69. void snd_dmaengine_pcm_set_config_from_dai_data(
  70. const struct snd_pcm_substream *substream,
  71. const struct snd_dmaengine_dai_dma_data *dma_data,
  72. struct dma_slave_config *config);
  73. /*
  74. * Try to request the DMA channel using compat_request_channel or
  75. * compat_filter_fn if it couldn't be requested through devicetree.
  76. */
  77. #define SND_DMAENGINE_PCM_FLAG_COMPAT BIT(0)
  78. /*
  79. * Don't try to request the DMA channels through devicetree. This flag only
  80. * makes sense if SND_DMAENGINE_PCM_FLAG_COMPAT is set as well.
  81. */
  82. #define SND_DMAENGINE_PCM_FLAG_NO_DT BIT(1)
  83. /*
  84. * The platforms dmaengine driver does not support reporting the amount of
  85. * bytes that are still left to transfer.
  86. */
  87. #define SND_DMAENGINE_PCM_FLAG_NO_RESIDUE BIT(2)
  88. /*
  89. * The PCM is half duplex and the DMA channel is shared between capture and
  90. * playback.
  91. */
  92. #define SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX BIT(3)
  93. /*
  94. * The PCM streams have custom channel names specified.
  95. */
  96. #define SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME BIT(4)
  97. /**
  98. * struct snd_dmaengine_pcm_config - Configuration data for dmaengine based PCM
  99. * @prepare_slave_config: Callback used to fill in the DMA slave_config for a
  100. * PCM substream. Will be called from the PCM drivers hwparams callback.
  101. * @compat_request_channel: Callback to request a DMA channel for platforms
  102. * which do not use devicetree.
  103. * @compat_filter_fn: Will be used as the filter function when requesting a
  104. * channel for platforms which do not use devicetree. The filter parameter
  105. * will be the DAI's DMA data.
  106. * @pcm_hardware: snd_pcm_hardware struct to be used for the PCM.
  107. * @prealloc_buffer_size: Size of the preallocated audio buffer.
  108. *
  109. * Note: If both compat_request_channel and compat_filter_fn are set
  110. * compat_request_channel will be used to request the channel and
  111. * compat_filter_fn will be ignored. Otherwise the channel will be requested
  112. * using dma_request_channel with compat_filter_fn as the filter function.
  113. */
  114. struct snd_dmaengine_pcm_config {
  115. int (*prepare_slave_config)(struct snd_pcm_substream *substream,
  116. struct snd_pcm_hw_params *params,
  117. struct dma_slave_config *slave_config);
  118. struct dma_chan *(*compat_request_channel)(
  119. struct snd_soc_pcm_runtime *rtd,
  120. struct snd_pcm_substream *substream);
  121. dma_filter_fn compat_filter_fn;
  122. const struct snd_pcm_hardware *pcm_hardware;
  123. unsigned int prealloc_buffer_size;
  124. };
  125. int snd_dmaengine_pcm_register(struct device *dev,
  126. const struct snd_dmaengine_pcm_config *config,
  127. unsigned int flags);
  128. void snd_dmaengine_pcm_unregister(struct device *dev);
  129. int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
  130. struct snd_pcm_hw_params *params,
  131. struct dma_slave_config *slave_config);
  132. #endif