sprd-dma.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SPRD_DMA_H_
  3. #define _SPRD_DMA_H_
  4. #define SPRD_DMA_REQ_SHIFT 16
  5. #define SPRD_DMA_FLAGS(req_mode, int_type) \
  6. ((req_mode) << SPRD_DMA_REQ_SHIFT | (int_type))
  7. /*
  8. * enum sprd_dma_req_mode: define the DMA request mode
  9. * @SPRD_DMA_FRAG_REQ: fragment request mode
  10. * @SPRD_DMA_BLK_REQ: block request mode
  11. * @SPRD_DMA_TRANS_REQ: transaction request mode
  12. * @SPRD_DMA_LIST_REQ: link-list request mode
  13. *
  14. * We have 4 types request mode: fragment mode, block mode, transaction mode
  15. * and linklist mode. One transaction can contain several blocks, one block can
  16. * contain several fragments. Link-list mode means we can save several DMA
  17. * configuration into one reserved memory, then DMA can fetch each DMA
  18. * configuration automatically to start transfer.
  19. */
  20. enum sprd_dma_req_mode {
  21. SPRD_DMA_FRAG_REQ,
  22. SPRD_DMA_BLK_REQ,
  23. SPRD_DMA_TRANS_REQ,
  24. SPRD_DMA_LIST_REQ,
  25. };
  26. /*
  27. * enum sprd_dma_int_type: define the DMA interrupt type
  28. * @SPRD_DMA_NO_INT: do not need generate DMA interrupts.
  29. * @SPRD_DMA_FRAG_INT: fragment done interrupt when one fragment request
  30. * is done.
  31. * @SPRD_DMA_BLK_INT: block done interrupt when one block request is done.
  32. * @SPRD_DMA_BLK_FRAG_INT: block and fragment interrupt when one fragment
  33. * or one block request is done.
  34. * @SPRD_DMA_TRANS_INT: tansaction done interrupt when one transaction
  35. * request is done.
  36. * @SPRD_DMA_TRANS_FRAG_INT: transaction and fragment interrupt when one
  37. * transaction request or fragment request is done.
  38. * @SPRD_DMA_TRANS_BLK_INT: transaction and block interrupt when one
  39. * transaction request or block request is done.
  40. * @SPRD_DMA_LIST_INT: link-list done interrupt when one link-list request
  41. * is done.
  42. * @SPRD_DMA_CFGERR_INT: configure error interrupt when configuration is
  43. * incorrect.
  44. */
  45. enum sprd_dma_int_type {
  46. SPRD_DMA_NO_INT,
  47. SPRD_DMA_FRAG_INT,
  48. SPRD_DMA_BLK_INT,
  49. SPRD_DMA_BLK_FRAG_INT,
  50. SPRD_DMA_TRANS_INT,
  51. SPRD_DMA_TRANS_FRAG_INT,
  52. SPRD_DMA_TRANS_BLK_INT,
  53. SPRD_DMA_LIST_INT,
  54. SPRD_DMA_CFGERR_INT,
  55. };
  56. /*
  57. * struct sprd_dma_linklist - DMA link-list address structure
  58. * @virt_addr: link-list virtual address to configure link-list node
  59. * @phy_addr: link-list physical address to link DMA transfer
  60. *
  61. * The Spreadtrum DMA controller supports the link-list mode, that means slaves
  62. * can supply several groups configurations (each configuration represents one
  63. * DMA transfer) saved in memory, and DMA controller will link these groups
  64. * configurations by writing the physical address of each configuration into the
  65. * link-list register.
  66. *
  67. * Just as shown below, the link-list pointer register will be pointed to the
  68. * physical address of 'configuration 1', and the 'configuration 1' link-list
  69. * pointer will be pointed to 'configuration 2', and so on.
  70. * Once trigger the DMA transfer, the DMA controller will load 'configuration
  71. * 1' to its registers automatically, after 'configuration 1' transaction is
  72. * done, DMA controller will load 'configuration 2' automatically, until all
  73. * DMA transactions are done.
  74. *
  75. * Note: The last link-list pointer should point to the physical address
  76. * of 'configuration 1', which can avoid DMA controller loads incorrect
  77. * configuration when the last configuration transaction is done.
  78. *
  79. * DMA controller linklist memory
  80. * ====================== -----------------------
  81. *| | | configuration 1 |<---
  82. *| DMA controller | ------->| | |
  83. *| | | | | |
  84. *| | | | | |
  85. *| | | | | |
  86. *| linklist pointer reg |---- ----| linklist pointer | |
  87. * ====================== | ----------------------- |
  88. * | |
  89. * | ----------------------- |
  90. * | | configuration 2 | |
  91. * --->| | |
  92. * | | |
  93. * | | |
  94. * | | |
  95. * ----| linklist pointer | |
  96. * | ----------------------- |
  97. * | |
  98. * | ----------------------- |
  99. * | | configuration 3 | |
  100. * --->| | |
  101. * | | |
  102. * | . | |
  103. * . |
  104. * . |
  105. * . |
  106. * | . |
  107. * | ----------------------- |
  108. * | | configuration n | |
  109. * --->| | |
  110. * | | |
  111. * | | |
  112. * | | |
  113. * | linklist pointer |----
  114. * -----------------------
  115. *
  116. * To support the link-list mode, DMA slaves should allocate one segment memory
  117. * from always-on IRAM or dma coherent memory to store these groups of DMA
  118. * configuration, and pass the virtual and physical address to DMA controller.
  119. */
  120. struct sprd_dma_linklist {
  121. unsigned long virt_addr;
  122. phys_addr_t phy_addr;
  123. };
  124. #endif