dmaengine_pcm.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. */
  58. struct snd_dmaengine_dai_dma_data {
  59. dma_addr_t addr;
  60. enum dma_slave_buswidth addr_width;
  61. u32 maxburst;
  62. unsigned int slave_id;
  63. void *filter_data;
  64. };
  65. void snd_dmaengine_pcm_set_config_from_dai_data(
  66. const struct snd_pcm_substream *substream,
  67. const struct snd_dmaengine_dai_dma_data *dma_data,
  68. struct dma_slave_config *config);
  69. /*
  70. * Try to request the DMA channel using compat_request_channel or
  71. * compat_filter_fn if it couldn't be requested through devicetree.
  72. */
  73. #define SND_DMAENGINE_PCM_FLAG_COMPAT BIT(0)
  74. /*
  75. * Don't try to request the DMA channels through devicetree. This flag only
  76. * makes sense if SND_DMAENGINE_PCM_FLAG_COMPAT is set as well.
  77. */
  78. #define SND_DMAENGINE_PCM_FLAG_NO_DT BIT(1)
  79. /*
  80. * The platforms dmaengine driver does not support reporting the amount of
  81. * bytes that are still left to transfer.
  82. */
  83. #define SND_DMAENGINE_PCM_FLAG_NO_RESIDUE BIT(2)
  84. /*
  85. * The PCM is half duplex and the DMA channel is shared between capture and
  86. * playback.
  87. */
  88. #define SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX BIT(3)
  89. /**
  90. * struct snd_dmaengine_pcm_config - Configuration data for dmaengine based PCM
  91. * @prepare_slave_config: Callback used to fill in the DMA slave_config for a
  92. * PCM substream. Will be called from the PCM drivers hwparams callback.
  93. * @compat_request_channel: Callback to request a DMA channel for platforms
  94. * which do not use devicetree.
  95. * @compat_filter_fn: Will be used as the filter function when requesting a
  96. * channel for platforms which do not use devicetree. The filter parameter
  97. * will be the DAI's DMA data.
  98. * @pcm_hardware: snd_pcm_hardware struct to be used for the PCM.
  99. * @prealloc_buffer_size: Size of the preallocated audio buffer.
  100. *
  101. * Note: If both compat_request_channel and compat_filter_fn are set
  102. * compat_request_channel will be used to request the channel and
  103. * compat_filter_fn will be ignored. Otherwise the channel will be requested
  104. * using dma_request_channel with compat_filter_fn as the filter function.
  105. */
  106. struct snd_dmaengine_pcm_config {
  107. int (*prepare_slave_config)(struct snd_pcm_substream *substream,
  108. struct snd_pcm_hw_params *params,
  109. struct dma_slave_config *slave_config);
  110. struct dma_chan *(*compat_request_channel)(
  111. struct snd_soc_pcm_runtime *rtd,
  112. struct snd_pcm_substream *substream);
  113. dma_filter_fn compat_filter_fn;
  114. const struct snd_pcm_hardware *pcm_hardware;
  115. unsigned int prealloc_buffer_size;
  116. };
  117. int snd_dmaengine_pcm_register(struct device *dev,
  118. const struct snd_dmaengine_pcm_config *config,
  119. unsigned int flags);
  120. void snd_dmaengine_pcm_unregister(struct device *dev);
  121. int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
  122. struct snd_pcm_hw_params *params,
  123. struct dma_slave_config *slave_config);
  124. #endif