edma.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * File : edma.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2010-11-13 weety first version
  23. */
  24. /*
  25. * This EDMA3 programming framework exposes two basic kinds of resource:
  26. *
  27. * Channel Triggers transfers, usually from a hardware event but
  28. * also manually or by "chaining" from DMA completions.
  29. * Each channel is coupled to a Parameter RAM (PaRAM) slot.
  30. *
  31. * Slot Each PaRAM slot holds a DMA transfer descriptor (PaRAM
  32. * "set"), source and destination addresses, a link to a
  33. * next PaRAM slot (if any), options for the transfer, and
  34. * instructions for updating those addresses. There are
  35. * more than twice as many slots as event channels.
  36. *
  37. * Each PaRAM set describes a sequence of transfers, either for one large
  38. * buffer or for several discontiguous smaller buffers. An EDMA transfer
  39. * is driven only from a channel, which performs the transfers specified
  40. * in its PaRAM slot until there are no more transfers. When that last
  41. * transfer completes, the "link" field may be used to reload the channel's
  42. * PaRAM slot with a new transfer descriptor.
  43. *
  44. * The EDMA Channel Controller (CC) maps requests from channels into physical
  45. * Transfer Controller (TC) requests when the channel triggers (by hardware
  46. * or software events, or by chaining). The two physical DMA channels provided
  47. * by the TCs are thus shared by many logical channels.
  48. *
  49. * DaVinci hardware also has a "QDMA" mechanism which is not currently
  50. * supported through this interface. (DSP firmware uses it though.)
  51. */
  52. #ifndef EDMA_H_
  53. #define EDMA_H_
  54. #include <rtthread.h>
  55. #include <dm36x.h>
  56. #ifdef RT_EDMA_DEBUG
  57. #define edma_dbg(fmt, ...) rt_kprintf(fmt, ##__VA_ARGS__)
  58. #else
  59. #define edma_dbg(fmt, ...)
  60. #endif
  61. /* PaRAM slots are laid out like this */
  62. struct edmacc_param {
  63. unsigned int opt;
  64. unsigned int src;
  65. unsigned int a_b_cnt;
  66. unsigned int dst;
  67. unsigned int src_dst_bidx;
  68. unsigned int link_bcntrld;
  69. unsigned int src_dst_cidx;
  70. unsigned int ccnt;
  71. };
  72. #define CCINT0_INTERRUPT 16
  73. #define CCERRINT_INTERRUPT 17
  74. #define TCERRINT0_INTERRUPT 18
  75. #define TCERRINT1_INTERRUPT 19
  76. /* fields in edmacc_param.opt */
  77. #define SAM BIT(0)
  78. #define DAM BIT(1)
  79. #define SYNCDIM BIT(2)
  80. #define STATIC BIT(3)
  81. #define EDMA_FWID (0x07 << 8)
  82. #define TCCMODE BIT(11)
  83. #define EDMA_TCC(t) ((t) << 12)
  84. #define TCINTEN BIT(20)
  85. #define ITCINTEN BIT(21)
  86. #define TCCHEN BIT(22)
  87. #define ITCCHEN BIT(23)
  88. #define TRWORD (0x7<<2)
  89. #define PAENTRY (0x1ff<<5)
  90. /* DM365 specific EDMA3 Events Information */
  91. enum dm365_edma_ch {
  92. DM365_DMA_TIMER3_TINT6,
  93. DM365_DMA_TIMER3_TINT7,
  94. DM365_DMA_MCBSP_TX = 2,
  95. DM365_DMA_VCIF_TX = 2,
  96. DM365_DMA_MCBSP_RX = 3,
  97. DM365_DMA_VCIF_RX = 3,
  98. DM365_DMA_VPSS_EVT1,
  99. DM365_DMA_VPSS_EVT2,
  100. DM365_DMA_VPSS_EVT3,
  101. DM365_DMA_VPSS_EVT4,
  102. DM365_DMA_TIMER2_TINT4,
  103. DM365_DMA_TIMER2_TINT5,
  104. DM365_DMA_SPI2XEVT,
  105. DM365_DMA_SPI2REVT,
  106. DM365_DMA_IMCOP_IMX0INT = 12,
  107. DM365_DMA_KALEIDO_ARMINT = 12,
  108. DM365_DMA_IMCOP_SEQINT,
  109. DM365_DMA_SPI1XEVT,
  110. DM365_DMA_SPI1REVT,
  111. DM365_DMA_SPI0XEVT,
  112. DM365_DMA_SPI0REVT,
  113. DM365_DMA_URXEVT0 = 18,
  114. DM365_DMA_SPI3XEVT = 18,
  115. DM365_DMA_UTXEVT0 = 19,
  116. DM365_DMA_SPI3REVT = 19,
  117. DM365_DMA_URXEVT1,
  118. DM365_DMA_UTXEVT1,
  119. DM365_DMA_TIMER4_TINT8,
  120. DM365_DMA_TIMER4_TINT9,
  121. DM365_DMA_RTOINT,
  122. DM365_DMA_GPIONT9,
  123. DM365_DMA_MMC0RXEVT = 26,
  124. DM365_DMA_MEMSTK_MSEVT = 26,
  125. DM365_DMA_MMC0TXEVT,
  126. DM365_DMA_I2C_ICREVT,
  127. DM365_DMA_I2C_ICXEVT,
  128. DM365_DMA_MMC1RXEVT,
  129. DM365_DMA_MMC1TXEVT,
  130. DM365_DMA_GPIOINT0,
  131. DM365_DMA_GPIOINT1,
  132. DM365_DMA_GPIOINT2,
  133. DM365_DMA_GPIOINT3,
  134. DM365_DMA_GPIOINT4,
  135. DM365_DMA_GPIOINT5,
  136. DM365_DMA_GPIOINT6,
  137. DM365_DMA_GPIOINT7,
  138. DM365_DMA_GPIOINT10 = 40,
  139. DM365_DMA_EMAC_RXTHREESH = 40,
  140. DM365_DMA_GPIOINT11 = 41,
  141. DM365_DMA_EMAC_RXPULSE = 41,
  142. DM365_DMA_GPIOINT12 = 42,
  143. DM365_DMA_EMAC_TXPULSE = 42,
  144. DM365_DMA_GPIOINT13 = 43,
  145. DM365_DMA_EMAC_MISCPULSE = 43,
  146. DM365_DMA_GPIOINT14 = 44,
  147. DM365_DMA_SPI4XEVT = 44,
  148. DM365_DMA_GPIOINT15 = 45,
  149. DM365_DMA_SPI4REVT = 45,
  150. DM365_DMA_ADC_ADINT,
  151. DM365_DMA_GPIOINT8,
  152. DM365_DMA_TIMER0_TINT0,
  153. DM365_DMA_TIMER0_TINT1,
  154. DM365_DMA_TIMER1_TINT2,
  155. DM365_DMA_TIMER1_TINT3,
  156. DM365_DMA_PWM0,
  157. DM365_DMA_PWM1 = 53,
  158. DM365_DMA_IMCOP_IMX1INT = 53,
  159. DM365_DMA_PWM2 = 54,
  160. DM365_DMA_IMCOP_NSFINT = 54,
  161. DM365_DMA_PWM3 = 55,
  162. DM365_DMA_KALEIDO6_CP_UNDEF = 55,
  163. DM365_DMA_IMCOP_VLCDINT = 56,
  164. DM365_DMA_KALEIDO5_CP_ECDCMP = 56,
  165. DM365_DMA_IMCOP_BIMINT = 57,
  166. DM365_DMA_KALEIDO8_CP_ME = 57,
  167. DM365_DMA_IMCOP_DCTINT = 58,
  168. DM365_DMA_KALEIDO1_CP_CALC = 58,
  169. DM365_DMA_IMCOP_QIQINT = 59,
  170. DM365_DMA_KALEIDO7_CP_IPE = 59,
  171. DM365_DMA_IMCOP_BPSINT = 60,
  172. DM365_DMA_KALEIDO2_CP_BS = 60,
  173. DM365_DMA_IMCOP_VLCDERRINT = 61,
  174. DM365_DMA_KALEIDO0_CP_LPF = 61,
  175. DM365_DMA_IMCOP_RCNTINT = 62,
  176. DM365_DMA_KALEIDO3_CP_MC = 62,
  177. DM365_DMA_IMCOP_COPCINT = 63,
  178. DM365_DMA_KALEIDO4_CP_ECDEND = 63,
  179. };
  180. /* end DM365 specific info */
  181. /*ch_status paramater of callback function possible values*/
  182. #define DMA_COMPLETE 1
  183. #define DMA_CC_ERROR 2
  184. #define DMA_TC1_ERROR 3
  185. #define DMA_TC2_ERROR 4
  186. enum address_mode {
  187. INCR = 0,
  188. FIFO = 1
  189. };
  190. enum fifo_width {
  191. W8BIT = 0,
  192. W16BIT = 1,
  193. W32BIT = 2,
  194. W64BIT = 3,
  195. W128BIT = 4,
  196. W256BIT = 5
  197. };
  198. enum dma_event_q {
  199. EVENTQ_0 = 0,
  200. EVENTQ_1 = 1,
  201. EVENTQ_2 = 2,
  202. EVENTQ_3 = 3,
  203. EVENTQ_DEFAULT = -1
  204. };
  205. enum sync_dimension {
  206. ASYNC = 0,
  207. ABSYNC = 1
  208. };
  209. #define EDMA_CTLR_CHAN(ctlr, chan) (((ctlr) << 16) | (chan))
  210. #define EDMA_CTLR(i) ((i) >> 16)
  211. #define EDMA_CHAN_SLOT(i) ((i) & 0xffff)
  212. #define EDMA_CHANNEL_ANY -1 /* for edma_alloc_channel() */
  213. #define EDMA_SLOT_ANY -1 /* for edma_alloc_slot() */
  214. #define EDMA_CONT_PARAMS_ANY 1001
  215. #define EDMA_CONT_PARAMS_FIXED_EXACT 1002
  216. #define EDMA_CONT_PARAMS_FIXED_NOT_EXACT 1003
  217. #define EDMA_MAX_CC 2
  218. /* alloc/free DMA channels and their dedicated parameter RAM slots */
  219. int edma_alloc_channel(int channel,
  220. void (*callback)(unsigned channel, rt_uint16_t ch_status, void *data),
  221. void *data, enum dma_event_q);
  222. void edma_free_channel(unsigned channel);
  223. /* alloc/free parameter RAM slots */
  224. int edma_alloc_slot(unsigned ctlr, int slot);
  225. void edma_free_slot(unsigned slot);
  226. /* alloc/free a set of contiguous parameter RAM slots */
  227. int edma_alloc_cont_slots(unsigned ctlr, unsigned int id, int slot, int count);
  228. int edma_free_cont_slots(unsigned slot, int count);
  229. /* calls that operate on part of a parameter RAM slot */
  230. void edma_set_src(unsigned slot, rt_uint32_t src_port,
  231. enum address_mode mode, enum fifo_width);
  232. void edma_set_dest(unsigned slot, rt_uint32_t dest_port,
  233. enum address_mode mode, enum fifo_width);
  234. void edma_get_position(unsigned slot, rt_uint32_t *src, rt_uint32_t *dst);
  235. void edma_set_src_index(unsigned slot, rt_int16_t src_bidx, rt_int16_t src_cidx);
  236. void edma_set_dest_index(unsigned slot, rt_int16_t dest_bidx, rt_int16_t dest_cidx);
  237. void edma_set_transfer_params(unsigned slot, rt_uint16_t acnt, rt_uint16_t bcnt, rt_uint16_t ccnt,
  238. rt_uint16_t bcnt_rld, enum sync_dimension sync_mode);
  239. void edma_link(unsigned from, unsigned to);
  240. void edma_unlink(unsigned from);
  241. /* calls that operate on an entire parameter RAM slot */
  242. void edma_write_slot(unsigned slot, const struct edmacc_param *params);
  243. void edma_read_slot(unsigned slot, struct edmacc_param *params);
  244. /* channel control operations */
  245. int edma_start(unsigned channel);
  246. void edma_stop(unsigned channel);
  247. void edma_clean_channel(unsigned channel);
  248. void edma_clear_event(unsigned channel);
  249. void edma_pause(unsigned channel);
  250. void edma_resume(unsigned channel);
  251. struct edma_rsv_info {
  252. const rt_int16_t (*rsv_chans)[2];
  253. const rt_int16_t (*rsv_slots)[2];
  254. };
  255. /* platform_data for EDMA driver */
  256. struct edma_soc_info {
  257. /* how many dma resources of each type */
  258. unsigned n_channel;
  259. unsigned n_region;
  260. unsigned n_slot;
  261. unsigned n_tc;
  262. unsigned n_cc;
  263. enum dma_event_q default_queue;
  264. /* Resource reservation for other cores */
  265. struct edma_rsv_info *rsv;
  266. const rt_int8_t (*queue_tc_mapping)[2];
  267. const rt_int8_t (*queue_priority_mapping)[2];
  268. };
  269. int edma_init(struct edma_soc_info **info);
  270. #endif