dmaengine_pcm.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 PCM is half duplex and the DMA channel is shared between capture and
  85. * playback.
  86. */
  87. #define SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX BIT(3)
  88. /*
  89. * The PCM streams have custom channel names specified.
  90. */
  91. #define SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME BIT(4)
  92. /**
  93. * struct snd_dmaengine_pcm_config - Configuration data for dmaengine based PCM
  94. * @prepare_slave_config: Callback used to fill in the DMA slave_config for a
  95. * PCM substream. Will be called from the PCM drivers hwparams callback.
  96. * @compat_request_channel: Callback to request a DMA channel for platforms
  97. * which do not use devicetree.
  98. * @compat_filter_fn: Will be used as the filter function when requesting a
  99. * channel for platforms which do not use devicetree. The filter parameter
  100. * will be the DAI's DMA data.
  101. * @dma_dev: If set, request DMA channel on this device rather than the DAI
  102. * device.
  103. * @chan_names: If set, these custom DMA channel names will be requested at
  104. * registration time.
  105. * @pcm_hardware: snd_pcm_hardware struct to be used for the PCM.
  106. * @prealloc_buffer_size: Size of the preallocated audio buffer.
  107. *
  108. * Note: If both compat_request_channel and compat_filter_fn are set
  109. * compat_request_channel will be used to request the channel and
  110. * compat_filter_fn will be ignored. Otherwise the channel will be requested
  111. * using dma_request_channel with compat_filter_fn as the filter function.
  112. */
  113. struct snd_dmaengine_pcm_config {
  114. int (*prepare_slave_config)(struct snd_pcm_substream *substream,
  115. struct snd_pcm_hw_params *params,
  116. struct dma_slave_config *slave_config);
  117. struct dma_chan *(*compat_request_channel)(
  118. struct snd_soc_pcm_runtime *rtd,
  119. struct snd_pcm_substream *substream);
  120. dma_filter_fn compat_filter_fn;
  121. struct device *dma_dev;
  122. const char *chan_names[SNDRV_PCM_STREAM_LAST + 1];
  123. const struct snd_pcm_hardware *pcm_hardware;
  124. unsigned int prealloc_buffer_size;
  125. };
  126. int snd_dmaengine_pcm_register(struct device *dev,
  127. const struct snd_dmaengine_pcm_config *config,
  128. unsigned int flags);
  129. void snd_dmaengine_pcm_unregister(struct device *dev);
  130. int devm_snd_dmaengine_pcm_register(struct device *dev,
  131. const struct snd_dmaengine_pcm_config *config,
  132. unsigned int flags);
  133. int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
  134. struct snd_pcm_hw_params *params,
  135. struct dma_slave_config *slave_config);
  136. #endif