edma.h 8.4 KB

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