dmaengine_pcm.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. * The DAI supports packed transfers, eg 2 16-bit samples in a 32-bit word.
  49. * If this flag is set the dmaengine driver won't put any restriction on
  50. * the supported sample formats and set the DMA transfer size to undefined.
  51. * The DAI driver is responsible to disable any unsupported formats in it's
  52. * configuration and catch corner cases that are not already handled in
  53. * the ALSA core.
  54. */
  55. #define SND_DMAENGINE_PCM_DAI_FLAG_PACK BIT(0)
  56. /**
  57. * struct snd_dmaengine_dai_dma_data - DAI DMA configuration data
  58. * @addr: Address of the DAI data source or destination register.
  59. * @addr_width: Width of the DAI data source or destination register.
  60. * @maxburst: Maximum number of words(note: words, as in units of the
  61. * src_addr_width member, not bytes) that can be send to or received from the
  62. * DAI in one burst.
  63. * @slave_id: Slave requester id for the DMA channel.
  64. * @filter_data: Custom DMA channel filter data, this will usually be used when
  65. * requesting the DMA channel.
  66. * @chan_name: Custom channel name to use when requesting DMA channel.
  67. * @fifo_size: FIFO size of the DAI controller in bytes
  68. * @flags: PCM_DAI flags, only SND_DMAENGINE_PCM_DAI_FLAG_PACK for now
  69. */
  70. struct snd_dmaengine_dai_dma_data {
  71. dma_addr_t addr;
  72. enum dma_slave_buswidth addr_width;
  73. u32 maxburst;
  74. unsigned int slave_id;
  75. void *filter_data;
  76. const char *chan_name;
  77. unsigned int fifo_size;
  78. unsigned int flags;
  79. };
  80. void snd_dmaengine_pcm_set_config_from_dai_data(
  81. const struct snd_pcm_substream *substream,
  82. const struct snd_dmaengine_dai_dma_data *dma_data,
  83. struct dma_slave_config *config);
  84. /*
  85. * Try to request the DMA channel using compat_request_channel or
  86. * compat_filter_fn if it couldn't be requested through devicetree.
  87. */
  88. #define SND_DMAENGINE_PCM_FLAG_COMPAT BIT(0)
  89. /*
  90. * Don't try to request the DMA channels through devicetree. This flag only
  91. * makes sense if SND_DMAENGINE_PCM_FLAG_COMPAT is set as well.
  92. */
  93. #define SND_DMAENGINE_PCM_FLAG_NO_DT BIT(1)
  94. /*
  95. * The PCM is half duplex and the DMA channel is shared between capture and
  96. * playback.
  97. */
  98. #define SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX BIT(3)
  99. /*
  100. * The PCM streams have custom channel names specified.
  101. */
  102. #define SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME BIT(4)
  103. /**
  104. * struct snd_dmaengine_pcm_config - Configuration data for dmaengine based PCM
  105. * @prepare_slave_config: Callback used to fill in the DMA slave_config for a
  106. * PCM substream. Will be called from the PCM drivers hwparams callback.
  107. * @compat_request_channel: Callback to request a DMA channel for platforms
  108. * which do not use devicetree.
  109. * @compat_filter_fn: Will be used as the filter function when requesting a
  110. * channel for platforms which do not use devicetree. The filter parameter
  111. * will be the DAI's DMA data.
  112. * @dma_dev: If set, request DMA channel on this device rather than the DAI
  113. * device.
  114. * @chan_names: If set, these custom DMA channel names will be requested at
  115. * registration time.
  116. * @pcm_hardware: snd_pcm_hardware struct to be used for the PCM.
  117. * @prealloc_buffer_size: Size of the preallocated audio buffer.
  118. *
  119. * Note: If both compat_request_channel and compat_filter_fn are set
  120. * compat_request_channel will be used to request the channel and
  121. * compat_filter_fn will be ignored. Otherwise the channel will be requested
  122. * using dma_request_channel with compat_filter_fn as the filter function.
  123. */
  124. struct snd_dmaengine_pcm_config {
  125. int (*prepare_slave_config)(struct snd_pcm_substream *substream,
  126. struct snd_pcm_hw_params *params,
  127. struct dma_slave_config *slave_config);
  128. struct dma_chan *(*compat_request_channel)(
  129. struct snd_soc_pcm_runtime *rtd,
  130. struct snd_pcm_substream *substream);
  131. dma_filter_fn compat_filter_fn;
  132. struct device *dma_dev;
  133. const char *chan_names[SNDRV_PCM_STREAM_LAST + 1];
  134. const struct snd_pcm_hardware *pcm_hardware;
  135. unsigned int prealloc_buffer_size;
  136. };
  137. int snd_dmaengine_pcm_register(struct device *dev,
  138. const struct snd_dmaengine_pcm_config *config,
  139. unsigned int flags);
  140. void snd_dmaengine_pcm_unregister(struct device *dev);
  141. int devm_snd_dmaengine_pcm_register(struct device *dev,
  142. const struct snd_dmaengine_pcm_config *config,
  143. unsigned int flags);
  144. int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
  145. struct snd_pcm_hw_params *params,
  146. struct dma_slave_config *slave_config);
  147. #endif