dma.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * DOC: EP93xx DMA M2P memory to peripheral and peripheral to memory engine
  3. *
  4. * The EP93xx DMA M2P subsystem handles DMA transfers between memory and
  5. * peripherals. DMA M2P channels are available for audio, UARTs and IrDA.
  6. * See chapter 10 of the EP93xx users guide for full details on the DMA M2P
  7. * engine.
  8. *
  9. * See sound/soc/ep93xx/ep93xx-pcm.c for an example use of the DMA M2P code.
  10. *
  11. */
  12. #ifndef __ASM_ARCH_DMA_H
  13. #define __ASM_ARCH_DMA_H
  14. #include <linux/list.h>
  15. #include <linux/types.h>
  16. #include <linux/dmaengine.h>
  17. #include <linux/dma-mapping.h>
  18. /**
  19. * struct ep93xx_dma_buffer - Information about a buffer to be transferred
  20. * using the DMA M2P engine
  21. *
  22. * @list: Entry in DMA buffer list
  23. * @bus_addr: Physical address of the buffer
  24. * @size: Size of the buffer in bytes
  25. */
  26. struct ep93xx_dma_buffer {
  27. struct list_head list;
  28. u32 bus_addr;
  29. u16 size;
  30. };
  31. /**
  32. * struct ep93xx_dma_m2p_client - Information about a DMA M2P client
  33. *
  34. * @name: Unique name for this client
  35. * @flags: Client flags
  36. * @cookie: User data to pass to callback functions
  37. * @buffer_started: Non NULL function to call when a transfer is started.
  38. * The arguments are the user data cookie and the DMA
  39. * buffer which is starting.
  40. * @buffer_finished: Non NULL function to call when a transfer is completed.
  41. * The arguments are the user data cookie, the DMA buffer
  42. * which has completed, and a boolean flag indicating if
  43. * the transfer had an error.
  44. */
  45. struct ep93xx_dma_m2p_client {
  46. char *name;
  47. u8 flags;
  48. void *cookie;
  49. void (*buffer_started)(void *cookie,
  50. struct ep93xx_dma_buffer *buf);
  51. void (*buffer_finished)(void *cookie,
  52. struct ep93xx_dma_buffer *buf,
  53. int bytes, int error);
  54. /* private: Internal use only */
  55. void *channel;
  56. };
  57. /* DMA M2P ports */
  58. #define EP93XX_DMA_M2P_PORT_I2S1 0x00
  59. #define EP93XX_DMA_M2P_PORT_I2S2 0x01
  60. #define EP93XX_DMA_M2P_PORT_AAC1 0x02
  61. #define EP93XX_DMA_M2P_PORT_AAC2 0x03
  62. #define EP93XX_DMA_M2P_PORT_AAC3 0x04
  63. #define EP93XX_DMA_M2P_PORT_I2S3 0x05
  64. #define EP93XX_DMA_M2P_PORT_UART1 0x06
  65. #define EP93XX_DMA_M2P_PORT_UART2 0x07
  66. #define EP93XX_DMA_M2P_PORT_UART3 0x08
  67. #define EP93XX_DMA_M2P_PORT_IRDA 0x09
  68. #define EP93XX_DMA_M2P_PORT_MASK 0x0f
  69. /* DMA M2P client flags */
  70. #define EP93XX_DMA_M2P_TX 0x00 /* Memory to peripheral */
  71. #define EP93XX_DMA_M2P_RX 0x10 /* Peripheral to memory */
  72. /*
  73. * DMA M2P client error handling flags. See the EP93xx users guide
  74. * documentation on the DMA M2P CONTROL register for more details
  75. */
  76. #define EP93XX_DMA_M2P_ABORT_ON_ERROR 0x20 /* Abort on peripheral error */
  77. #define EP93XX_DMA_M2P_IGNORE_ERROR 0x40 /* Ignore peripheral errors */
  78. #define EP93XX_DMA_M2P_ERROR_MASK 0x60 /* Mask of error bits */
  79. /**
  80. * ep93xx_dma_m2p_client_register - Register a client with the DMA M2P
  81. * subsystem
  82. *
  83. * @m2p: Client information to register
  84. * returns 0 on success
  85. *
  86. * The DMA M2P subsystem allocates a channel and an interrupt line for the DMA
  87. * client
  88. */
  89. int ep93xx_dma_m2p_client_register(struct ep93xx_dma_m2p_client *m2p);
  90. /**
  91. * ep93xx_dma_m2p_client_unregister - Unregister a client from the DMA M2P
  92. * subsystem
  93. *
  94. * @m2p: Client to unregister
  95. *
  96. * Any transfers currently in progress will be completed in hardware, but
  97. * ignored in software.
  98. */
  99. void ep93xx_dma_m2p_client_unregister(struct ep93xx_dma_m2p_client *m2p);
  100. /**
  101. * ep93xx_dma_m2p_submit - Submit a DMA M2P transfer
  102. *
  103. * @m2p: DMA Client to submit the transfer on
  104. * @buf: DMA Buffer to submit
  105. *
  106. * If the current or next transfer positions are free on the M2P client then
  107. * the transfer is started immediately. If not, the transfer is added to the
  108. * list of pending transfers. This function must not be called from the
  109. * buffer_finished callback for an M2P channel.
  110. *
  111. */
  112. void ep93xx_dma_m2p_submit(struct ep93xx_dma_m2p_client *m2p,
  113. struct ep93xx_dma_buffer *buf);
  114. /**
  115. * ep93xx_dma_m2p_submit_recursive - Put a DMA transfer on the pending list
  116. * for an M2P channel
  117. *
  118. * @m2p: DMA Client to submit the transfer on
  119. * @buf: DMA Buffer to submit
  120. *
  121. * This function must only be called from the buffer_finished callback for an
  122. * M2P channel. It is commonly used to add the next transfer in a chained list
  123. * of DMA transfers.
  124. */
  125. void ep93xx_dma_m2p_submit_recursive(struct ep93xx_dma_m2p_client *m2p,
  126. struct ep93xx_dma_buffer *buf);
  127. /**
  128. * ep93xx_dma_m2p_flush - Flush all pending transfers on a DMA M2P client
  129. *
  130. * @m2p: DMA client to flush transfers on
  131. *
  132. * Any transfers currently in progress will be completed in hardware, but
  133. * ignored in software.
  134. *
  135. */
  136. void ep93xx_dma_m2p_flush(struct ep93xx_dma_m2p_client *m2p);
  137. /*
  138. * M2P channels.
  139. *
  140. * Note that these values are also directly used for setting the PPALLOC
  141. * register.
  142. */
  143. #define EP93XX_DMA_I2S1 0
  144. #define EP93XX_DMA_I2S2 1
  145. #define EP93XX_DMA_AAC1 2
  146. #define EP93XX_DMA_AAC2 3
  147. #define EP93XX_DMA_AAC3 4
  148. #define EP93XX_DMA_I2S3 5
  149. #define EP93XX_DMA_UART1 6
  150. #define EP93XX_DMA_UART2 7
  151. #define EP93XX_DMA_UART3 8
  152. #define EP93XX_DMA_IRDA 9
  153. /* M2M channels */
  154. #define EP93XX_DMA_SSP 10
  155. #define EP93XX_DMA_IDE 11
  156. /**
  157. * struct ep93xx_dma_data - configuration data for the EP93xx dmaengine
  158. * @port: peripheral which is requesting the channel
  159. * @direction: TX/RX channel
  160. * @name: optional name for the channel, this is displayed in /proc/interrupts
  161. *
  162. * This information is passed as private channel parameter in a filter
  163. * function. Note that this is only needed for slave/cyclic channels. For
  164. * memcpy channels %NULL data should be passed.
  165. */
  166. struct ep93xx_dma_data {
  167. int port;
  168. enum dma_data_direction direction;
  169. const char *name;
  170. };
  171. /**
  172. * struct ep93xx_dma_chan_data - platform specific data for a DMA channel
  173. * @name: name of the channel, used for getting the right clock for the channel
  174. * @base: mapped registers
  175. * @irq: interrupt number used by this channel
  176. */
  177. struct ep93xx_dma_chan_data {
  178. const char *name;
  179. void __iomem *base;
  180. int irq;
  181. };
  182. /**
  183. * struct ep93xx_dma_platform_data - platform data for the dmaengine driver
  184. * @channels: array of channels which are passed to the driver
  185. * @num_channels: number of channels in the array
  186. *
  187. * This structure is passed to the DMA engine driver via platform data. For
  188. * M2P channels, contract is that even channels are for TX and odd for RX.
  189. * There is no requirement for the M2M channels.
  190. */
  191. struct ep93xx_dma_platform_data {
  192. struct ep93xx_dma_chan_data *channels;
  193. size_t num_channels;
  194. };
  195. static inline bool ep93xx_dma_chan_is_m2p(struct dma_chan *chan)
  196. {
  197. return !strcmp(dev_name(chan->device->dev), "ep93xx-dma-m2p");
  198. }
  199. /**
  200. * ep93xx_dma_chan_direction - returns direction the channel can be used
  201. * @chan: channel
  202. *
  203. * This function can be used in filter functions to find out whether the
  204. * channel supports given DMA direction. Only M2P channels have such
  205. * limitation, for M2M channels the direction is configurable.
  206. */
  207. static inline enum dma_data_direction
  208. ep93xx_dma_chan_direction(struct dma_chan *chan)
  209. {
  210. if (!ep93xx_dma_chan_is_m2p(chan))
  211. return DMA_NONE;
  212. /* even channels are for TX, odd for RX */
  213. return (chan->chan_id % 2 == 0) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
  214. }
  215. #endif /* __ASM_ARCH_DMA_H */