edma.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * TI DAVINCI dma definitions
  3. *
  4. * Copyright (C) 2006-2009 Texas Instruments.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  14. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  18. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. */
  27. /*
  28. * This EDMA3 programming framework exposes two basic kinds of resource:
  29. *
  30. * Channel Triggers transfers, usually from a hardware event but
  31. * also manually or by "chaining" from DMA completions.
  32. * Each channel is coupled to a Parameter RAM (PaRAM) slot.
  33. *
  34. * Slot Each PaRAM slot holds a DMA transfer descriptor (PaRAM
  35. * "set"), source and destination addresses, a link to a
  36. * next PaRAM slot (if any), options for the transfer, and
  37. * instructions for updating those addresses. There are
  38. * more than twice as many slots as event channels.
  39. *
  40. * Each PaRAM set describes a sequence of transfers, either for one large
  41. * buffer or for several discontiguous smaller buffers. An EDMA transfer
  42. * is driven only from a channel, which performs the transfers specified
  43. * in its PaRAM slot until there are no more transfers. When that last
  44. * transfer completes, the "link" field may be used to reload the channel's
  45. * PaRAM slot with a new transfer descriptor.
  46. *
  47. * The EDMA Channel Controller (CC) maps requests from channels into physical
  48. * Transfer Controller (TC) requests when the channel triggers (by hardware
  49. * or software events, or by chaining). The two physical DMA channels provided
  50. * by the TCs are thus shared by many logical channels.
  51. *
  52. * DaVinci hardware also has a "QDMA" mechanism which is not currently
  53. * supported through this interface. (DSP firmware uses it though.)
  54. */
  55. #ifndef EDMA_H_
  56. #define EDMA_H_
  57. /* PaRAM slots are laid out like this */
  58. struct edmacc_param {
  59. unsigned int opt;
  60. unsigned int src;
  61. unsigned int a_b_cnt;
  62. unsigned int dst;
  63. unsigned int src_dst_bidx;
  64. unsigned int link_bcntrld;
  65. unsigned int src_dst_cidx;
  66. unsigned int ccnt;
  67. };
  68. #define CCINT0_INTERRUPT 16
  69. #define CCERRINT_INTERRUPT 17
  70. #define TCERRINT0_INTERRUPT 18
  71. #define TCERRINT1_INTERRUPT 19
  72. /* fields in edmacc_param.opt */
  73. #define SAM BIT(0)
  74. #define DAM BIT(1)
  75. #define SYNCDIM BIT(2)
  76. #define STATIC BIT(3)
  77. #define EDMA_FWID (0x07 << 8)
  78. #define TCCMODE BIT(11)
  79. #define EDMA_TCC(t) ((t) << 12)
  80. #define TCINTEN BIT(20)
  81. #define ITCINTEN BIT(21)
  82. #define TCCHEN BIT(22)
  83. #define ITCCHEN BIT(23)
  84. #define TRWORD (0x7<<2)
  85. #define PAENTRY (0x1ff<<5)
  86. /* Drivers should avoid using these symbolic names for dm644x
  87. * channels, and use platform_device IORESOURCE_DMA resources
  88. * instead. (Other DaVinci chips have different peripherals
  89. * and thus have different DMA channel mappings.)
  90. */
  91. #define DAVINCI_DMA_MCBSP_TX 2
  92. #define DAVINCI_DMA_MCBSP_RX 3
  93. #define DAVINCI_DMA_VPSS_HIST 4
  94. #define DAVINCI_DMA_VPSS_H3A 5
  95. #define DAVINCI_DMA_VPSS_PRVU 6
  96. #define DAVINCI_DMA_VPSS_RSZ 7
  97. #define DAVINCI_DMA_IMCOP_IMXINT 8
  98. #define DAVINCI_DMA_IMCOP_VLCDINT 9
  99. #define DAVINCI_DMA_IMCO_PASQINT 10
  100. #define DAVINCI_DMA_IMCOP_DSQINT 11
  101. #define DAVINCI_DMA_SPI_SPIX 16
  102. #define DAVINCI_DMA_SPI_SPIR 17
  103. #define DAVINCI_DMA_UART0_URXEVT0 18
  104. #define DAVINCI_DMA_UART0_UTXEVT0 19
  105. #define DAVINCI_DMA_UART1_URXEVT1 20
  106. #define DAVINCI_DMA_UART1_UTXEVT1 21
  107. #define DAVINCI_DMA_UART2_URXEVT2 22
  108. #define DAVINCI_DMA_UART2_UTXEVT2 23
  109. #define DAVINCI_DMA_MEMSTK_MSEVT 24
  110. #define DAVINCI_DMA_MMCRXEVT 26
  111. #define DAVINCI_DMA_MMCTXEVT 27
  112. #define DAVINCI_DMA_I2C_ICREVT 28
  113. #define DAVINCI_DMA_I2C_ICXEVT 29
  114. #define DAVINCI_DMA_GPIO_GPINT0 32
  115. #define DAVINCI_DMA_GPIO_GPINT1 33
  116. #define DAVINCI_DMA_GPIO_GPINT2 34
  117. #define DAVINCI_DMA_GPIO_GPINT3 35
  118. #define DAVINCI_DMA_GPIO_GPINT4 36
  119. #define DAVINCI_DMA_GPIO_GPINT5 37
  120. #define DAVINCI_DMA_GPIO_GPINT6 38
  121. #define DAVINCI_DMA_GPIO_GPINT7 39
  122. #define DAVINCI_DMA_GPIO_GPBNKINT0 40
  123. #define DAVINCI_DMA_GPIO_GPBNKINT1 41
  124. #define DAVINCI_DMA_GPIO_GPBNKINT2 42
  125. #define DAVINCI_DMA_GPIO_GPBNKINT3 43
  126. #define DAVINCI_DMA_GPIO_GPBNKINT4 44
  127. #define DAVINCI_DMA_TIMER0_TINT0 48
  128. #define DAVINCI_DMA_TIMER1_TINT1 49
  129. #define DAVINCI_DMA_TIMER2_TINT2 50
  130. #define DAVINCI_DMA_TIMER3_TINT3 51
  131. #define DAVINCI_DMA_PWM0 52
  132. #define DAVINCI_DMA_PWM1 53
  133. #define DAVINCI_DMA_PWM2 54
  134. /* DA830 specific EDMA3 information */
  135. #define EDMA_DA830_NUM_DMACH 32
  136. #define EDMA_DA830_NUM_TCC 32
  137. #define EDMA_DA830_NUM_PARAMENTRY 128
  138. #define EDMA_DA830_NUM_EVQUE 2
  139. #define EDMA_DA830_NUM_TC 2
  140. #define EDMA_DA830_CHMAP_EXIST 0
  141. #define EDMA_DA830_NUM_REGIONS 4
  142. #define DA830_DMACH2EVENT_MAP0 0x000FC03Fu
  143. #define DA830_DMACH2EVENT_MAP1 0x00000000u
  144. #define DA830_EDMA_ARM_OWN 0x30FFCCFFu
  145. /* DA830 specific EDMA3 Events Information */
  146. enum DA830_edma_ch {
  147. DA830_DMACH_MCASP0_RX,
  148. DA830_DMACH_MCASP0_TX,
  149. DA830_DMACH_MCASP1_RX,
  150. DA830_DMACH_MCASP1_TX,
  151. DA830_DMACH_MCASP2_RX,
  152. DA830_DMACH_MCASP2_TX,
  153. DA830_DMACH_GPIO_BNK0INT,
  154. DA830_DMACH_GPIO_BNK1INT,
  155. DA830_DMACH_UART0_RX,
  156. DA830_DMACH_UART0_TX,
  157. DA830_DMACH_TMR64P0_EVTOUT12,
  158. DA830_DMACH_TMR64P0_EVTOUT34,
  159. DA830_DMACH_UART1_RX,
  160. DA830_DMACH_UART1_TX,
  161. DA830_DMACH_SPI0_RX,
  162. DA830_DMACH_SPI0_TX,
  163. DA830_DMACH_MMCSD_RX,
  164. DA830_DMACH_MMCSD_TX,
  165. DA830_DMACH_SPI1_RX,
  166. DA830_DMACH_SPI1_TX,
  167. DA830_DMACH_DMAX_EVTOUT6,
  168. DA830_DMACH_DMAX_EVTOUT7,
  169. DA830_DMACH_GPIO_BNK2INT,
  170. DA830_DMACH_GPIO_BNK3INT,
  171. DA830_DMACH_I2C0_RX,
  172. DA830_DMACH_I2C0_TX,
  173. DA830_DMACH_I2C1_RX,
  174. DA830_DMACH_I2C1_TX,
  175. DA830_DMACH_GPIO_BNK4INT,
  176. DA830_DMACH_GPIO_BNK5INT,
  177. DA830_DMACH_UART2_RX,
  178. DA830_DMACH_UART2_TX
  179. };
  180. /*ch_status paramater of callback function possible values*/
  181. #define DMA_COMPLETE 1
  182. #define DMA_CC_ERROR 2
  183. #define DMA_TC1_ERROR 3
  184. #define DMA_TC2_ERROR 4
  185. enum address_mode {
  186. INCR = 0,
  187. FIFO = 1
  188. };
  189. enum fifo_width {
  190. W8BIT = 0,
  191. W16BIT = 1,
  192. W32BIT = 2,
  193. W64BIT = 3,
  194. W128BIT = 4,
  195. W256BIT = 5
  196. };
  197. enum dma_event_q {
  198. EVENTQ_0 = 0,
  199. EVENTQ_1 = 1,
  200. EVENTQ_2 = 2,
  201. EVENTQ_3 = 3,
  202. EVENTQ_DEFAULT = -1
  203. };
  204. enum sync_dimension {
  205. ASYNC = 0,
  206. ABSYNC = 1
  207. };
  208. #define EDMA_CTLR_CHAN(ctlr, chan) (((ctlr) << 16) | (chan))
  209. #define EDMA_CTLR(i) ((i) >> 16)
  210. #define EDMA_CHAN_SLOT(i) ((i) & 0xffff)
  211. #define EDMA_CHANNEL_ANY -1 /* for edma_alloc_channel() */
  212. #define EDMA_SLOT_ANY -1 /* for edma_alloc_slot() */
  213. #define EDMA_CONT_PARAMS_ANY 1001
  214. #define EDMA_CONT_PARAMS_FIXED_EXACT 1002
  215. #define EDMA_CONT_PARAMS_FIXED_NOT_EXACT 1003
  216. #define EDMA_MAX_CC 2
  217. /* alloc/free DMA channels and their dedicated parameter RAM slots */
  218. int edma_alloc_channel(int channel,
  219. void (*callback)(unsigned channel, u16 ch_status, void *data),
  220. void *data, enum dma_event_q);
  221. void edma_free_channel(unsigned channel);
  222. /* alloc/free parameter RAM slots */
  223. int edma_alloc_slot(unsigned ctlr, int slot);
  224. void edma_free_slot(unsigned slot);
  225. /* alloc/free a set of contiguous parameter RAM slots */
  226. int edma_alloc_cont_slots(unsigned ctlr, unsigned int id, int slot, int count);
  227. int edma_free_cont_slots(unsigned slot, int count);
  228. /* calls that operate on part of a parameter RAM slot */
  229. void edma_set_src(unsigned slot, dma_addr_t src_port,
  230. enum address_mode mode, enum fifo_width);
  231. void edma_set_dest(unsigned slot, dma_addr_t dest_port,
  232. enum address_mode mode, enum fifo_width);
  233. void edma_get_position(unsigned slot, dma_addr_t *src, dma_addr_t *dst);
  234. void edma_set_src_index(unsigned slot, s16 src_bidx, s16 src_cidx);
  235. void edma_set_dest_index(unsigned slot, s16 dest_bidx, s16 dest_cidx);
  236. void edma_set_transfer_params(unsigned slot, u16 acnt, u16 bcnt, u16 ccnt,
  237. u16 bcnt_rld, enum sync_dimension sync_mode);
  238. void edma_link(unsigned from, unsigned to);
  239. void edma_unlink(unsigned from);
  240. /* calls that operate on an entire parameter RAM slot */
  241. void edma_write_slot(unsigned slot, const struct edmacc_param *params);
  242. void edma_read_slot(unsigned slot, struct edmacc_param *params);
  243. /* channel control operations */
  244. int edma_start(unsigned channel);
  245. void edma_stop(unsigned channel);
  246. void edma_clean_channel(unsigned channel);
  247. void edma_clear_event(unsigned channel);
  248. void edma_pause(unsigned channel);
  249. void edma_resume(unsigned channel);
  250. struct edma_rsv_info {
  251. const s16 (*rsv_chans)[2];
  252. const s16 (*rsv_slots)[2];
  253. };
  254. /* platform_data for EDMA driver */
  255. struct edma_soc_info {
  256. /* how many dma resources of each type */
  257. unsigned n_channel;
  258. unsigned n_region;
  259. unsigned n_slot;
  260. unsigned n_tc;
  261. unsigned n_cc;
  262. enum dma_event_q default_queue;
  263. /* Resource reservation for other cores */
  264. struct edma_rsv_info *rsv;
  265. const s8 (*queue_tc_mapping)[2];
  266. const s8 (*queue_priority_mapping)[2];
  267. };
  268. #endif