dw-axi-dmac.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. // SPDX-License-Identifier: GPL-2.0
  2. // (C) 2017-2018 Synopsys, Inc. (www.synopsys.com)
  3. /*
  4. * Synopsys DesignWare AXI DMA Controller driver.
  5. *
  6. * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
  7. */
  8. #ifndef _AXI_DMA_PLATFORM_H
  9. #define _AXI_DMA_PLATFORM_H
  10. #include <linux/bitops.h>
  11. #include <linux/clk.h>
  12. #include <linux/device.h>
  13. #include <linux/dmaengine.h>
  14. #include <linux/types.h>
  15. #include "../virt-dma.h"
  16. #define DMAC_MAX_CHANNELS 8
  17. #define DMAC_MAX_MASTERS 2
  18. #define DMAC_MAX_BLK_SIZE 0x200000
  19. struct dw_axi_dma_hcfg {
  20. u32 nr_channels;
  21. u32 nr_masters;
  22. u32 m_data_width;
  23. u32 block_size[DMAC_MAX_CHANNELS];
  24. u32 priority[DMAC_MAX_CHANNELS];
  25. /* maximum supported axi burst length */
  26. u32 axi_rw_burst_len;
  27. bool restrict_axi_burst_len;
  28. };
  29. struct axi_dma_chan {
  30. struct axi_dma_chip *chip;
  31. void __iomem *chan_regs;
  32. u8 id;
  33. atomic_t descs_allocated;
  34. struct virt_dma_chan vc;
  35. /* these other elements are all protected by vc.lock */
  36. bool is_paused;
  37. };
  38. struct dw_axi_dma {
  39. struct dma_device dma;
  40. struct dw_axi_dma_hcfg *hdata;
  41. struct dma_pool *desc_pool;
  42. /* channels */
  43. struct axi_dma_chan *chan;
  44. };
  45. struct axi_dma_chip {
  46. struct device *dev;
  47. int irq;
  48. void __iomem *regs;
  49. struct clk *core_clk;
  50. struct clk *cfgr_clk;
  51. struct dw_axi_dma *dw;
  52. };
  53. /* LLI == Linked List Item */
  54. struct __packed axi_dma_lli {
  55. __le64 sar;
  56. __le64 dar;
  57. __le32 block_ts_lo;
  58. __le32 block_ts_hi;
  59. __le64 llp;
  60. __le32 ctl_lo;
  61. __le32 ctl_hi;
  62. __le32 sstat;
  63. __le32 dstat;
  64. __le32 status_lo;
  65. __le32 ststus_hi;
  66. __le32 reserved_lo;
  67. __le32 reserved_hi;
  68. };
  69. struct axi_dma_desc {
  70. struct axi_dma_lli lli;
  71. struct virt_dma_desc vd;
  72. struct axi_dma_chan *chan;
  73. struct list_head xfer_list;
  74. };
  75. static inline struct device *dchan2dev(struct dma_chan *dchan)
  76. {
  77. return &dchan->dev->device;
  78. }
  79. static inline struct device *chan2dev(struct axi_dma_chan *chan)
  80. {
  81. return &chan->vc.chan.dev->device;
  82. }
  83. static inline struct axi_dma_desc *vd_to_axi_desc(struct virt_dma_desc *vd)
  84. {
  85. return container_of(vd, struct axi_dma_desc, vd);
  86. }
  87. static inline struct axi_dma_chan *vc_to_axi_dma_chan(struct virt_dma_chan *vc)
  88. {
  89. return container_of(vc, struct axi_dma_chan, vc);
  90. }
  91. static inline struct axi_dma_chan *dchan_to_axi_dma_chan(struct dma_chan *dchan)
  92. {
  93. return vc_to_axi_dma_chan(to_virt_chan(dchan));
  94. }
  95. #define COMMON_REG_LEN 0x100
  96. #define CHAN_REG_LEN 0x100
  97. /* Common registers offset */
  98. #define DMAC_ID 0x000 /* R DMAC ID */
  99. #define DMAC_COMPVER 0x008 /* R DMAC Component Version */
  100. #define DMAC_CFG 0x010 /* R/W DMAC Configuration */
  101. #define DMAC_CHEN 0x018 /* R/W DMAC Channel Enable */
  102. #define DMAC_CHEN_L 0x018 /* R/W DMAC Channel Enable 00-31 */
  103. #define DMAC_CHEN_H 0x01C /* R/W DMAC Channel Enable 32-63 */
  104. #define DMAC_INTSTATUS 0x030 /* R DMAC Interrupt Status */
  105. #define DMAC_COMMON_INTCLEAR 0x038 /* W DMAC Interrupt Clear */
  106. #define DMAC_COMMON_INTSTATUS_ENA 0x040 /* R DMAC Interrupt Status Enable */
  107. #define DMAC_COMMON_INTSIGNAL_ENA 0x048 /* R/W DMAC Interrupt Signal Enable */
  108. #define DMAC_COMMON_INTSTATUS 0x050 /* R DMAC Interrupt Status */
  109. #define DMAC_RESET 0x058 /* R DMAC Reset Register1 */
  110. /* DMA channel registers offset */
  111. #define CH_SAR 0x000 /* R/W Chan Source Address */
  112. #define CH_DAR 0x008 /* R/W Chan Destination Address */
  113. #define CH_BLOCK_TS 0x010 /* R/W Chan Block Transfer Size */
  114. #define CH_CTL 0x018 /* R/W Chan Control */
  115. #define CH_CTL_L 0x018 /* R/W Chan Control 00-31 */
  116. #define CH_CTL_H 0x01C /* R/W Chan Control 32-63 */
  117. #define CH_CFG 0x020 /* R/W Chan Configuration */
  118. #define CH_CFG_L 0x020 /* R/W Chan Configuration 00-31 */
  119. #define CH_CFG_H 0x024 /* R/W Chan Configuration 32-63 */
  120. #define CH_LLP 0x028 /* R/W Chan Linked List Pointer */
  121. #define CH_STATUS 0x030 /* R Chan Status */
  122. #define CH_SWHSSRC 0x038 /* R/W Chan SW Handshake Source */
  123. #define CH_SWHSDST 0x040 /* R/W Chan SW Handshake Destination */
  124. #define CH_BLK_TFR_RESUMEREQ 0x048 /* W Chan Block Transfer Resume Req */
  125. #define CH_AXI_ID 0x050 /* R/W Chan AXI ID */
  126. #define CH_AXI_QOS 0x058 /* R/W Chan AXI QOS */
  127. #define CH_SSTAT 0x060 /* R Chan Source Status */
  128. #define CH_DSTAT 0x068 /* R Chan Destination Status */
  129. #define CH_SSTATAR 0x070 /* R/W Chan Source Status Fetch Addr */
  130. #define CH_DSTATAR 0x078 /* R/W Chan Destination Status Fetch Addr */
  131. #define CH_INTSTATUS_ENA 0x080 /* R/W Chan Interrupt Status Enable */
  132. #define CH_INTSTATUS 0x088 /* R/W Chan Interrupt Status */
  133. #define CH_INTSIGNAL_ENA 0x090 /* R/W Chan Interrupt Signal Enable */
  134. #define CH_INTCLEAR 0x098 /* W Chan Interrupt Clear */
  135. /* DMAC_CFG */
  136. #define DMAC_EN_POS 0
  137. #define DMAC_EN_MASK BIT(DMAC_EN_POS)
  138. #define INT_EN_POS 1
  139. #define INT_EN_MASK BIT(INT_EN_POS)
  140. #define DMAC_CHAN_EN_SHIFT 0
  141. #define DMAC_CHAN_EN_WE_SHIFT 8
  142. #define DMAC_CHAN_SUSP_SHIFT 16
  143. #define DMAC_CHAN_SUSP_WE_SHIFT 24
  144. /* CH_CTL_H */
  145. #define CH_CTL_H_ARLEN_EN BIT(6)
  146. #define CH_CTL_H_ARLEN_POS 7
  147. #define CH_CTL_H_AWLEN_EN BIT(15)
  148. #define CH_CTL_H_AWLEN_POS 16
  149. enum {
  150. DWAXIDMAC_ARWLEN_1 = 0,
  151. DWAXIDMAC_ARWLEN_2 = 1,
  152. DWAXIDMAC_ARWLEN_4 = 3,
  153. DWAXIDMAC_ARWLEN_8 = 7,
  154. DWAXIDMAC_ARWLEN_16 = 15,
  155. DWAXIDMAC_ARWLEN_32 = 31,
  156. DWAXIDMAC_ARWLEN_64 = 63,
  157. DWAXIDMAC_ARWLEN_128 = 127,
  158. DWAXIDMAC_ARWLEN_256 = 255,
  159. DWAXIDMAC_ARWLEN_MIN = DWAXIDMAC_ARWLEN_1,
  160. DWAXIDMAC_ARWLEN_MAX = DWAXIDMAC_ARWLEN_256
  161. };
  162. #define CH_CTL_H_LLI_LAST BIT(30)
  163. #define CH_CTL_H_LLI_VALID BIT(31)
  164. /* CH_CTL_L */
  165. #define CH_CTL_L_LAST_WRITE_EN BIT(30)
  166. #define CH_CTL_L_DST_MSIZE_POS 18
  167. #define CH_CTL_L_SRC_MSIZE_POS 14
  168. enum {
  169. DWAXIDMAC_BURST_TRANS_LEN_1 = 0,
  170. DWAXIDMAC_BURST_TRANS_LEN_4,
  171. DWAXIDMAC_BURST_TRANS_LEN_8,
  172. DWAXIDMAC_BURST_TRANS_LEN_16,
  173. DWAXIDMAC_BURST_TRANS_LEN_32,
  174. DWAXIDMAC_BURST_TRANS_LEN_64,
  175. DWAXIDMAC_BURST_TRANS_LEN_128,
  176. DWAXIDMAC_BURST_TRANS_LEN_256,
  177. DWAXIDMAC_BURST_TRANS_LEN_512,
  178. DWAXIDMAC_BURST_TRANS_LEN_1024
  179. };
  180. #define CH_CTL_L_DST_WIDTH_POS 11
  181. #define CH_CTL_L_SRC_WIDTH_POS 8
  182. #define CH_CTL_L_DST_INC_POS 6
  183. #define CH_CTL_L_SRC_INC_POS 4
  184. enum {
  185. DWAXIDMAC_CH_CTL_L_INC = 0,
  186. DWAXIDMAC_CH_CTL_L_NOINC
  187. };
  188. #define CH_CTL_L_DST_MAST BIT(2)
  189. #define CH_CTL_L_SRC_MAST BIT(0)
  190. /* CH_CFG_H */
  191. #define CH_CFG_H_PRIORITY_POS 17
  192. #define CH_CFG_H_HS_SEL_DST_POS 4
  193. #define CH_CFG_H_HS_SEL_SRC_POS 3
  194. enum {
  195. DWAXIDMAC_HS_SEL_HW = 0,
  196. DWAXIDMAC_HS_SEL_SW
  197. };
  198. #define CH_CFG_H_TT_FC_POS 0
  199. enum {
  200. DWAXIDMAC_TT_FC_MEM_TO_MEM_DMAC = 0,
  201. DWAXIDMAC_TT_FC_MEM_TO_PER_DMAC,
  202. DWAXIDMAC_TT_FC_PER_TO_MEM_DMAC,
  203. DWAXIDMAC_TT_FC_PER_TO_PER_DMAC,
  204. DWAXIDMAC_TT_FC_PER_TO_MEM_SRC,
  205. DWAXIDMAC_TT_FC_PER_TO_PER_SRC,
  206. DWAXIDMAC_TT_FC_MEM_TO_PER_DST,
  207. DWAXIDMAC_TT_FC_PER_TO_PER_DST
  208. };
  209. /* CH_CFG_L */
  210. #define CH_CFG_L_DST_MULTBLK_TYPE_POS 2
  211. #define CH_CFG_L_SRC_MULTBLK_TYPE_POS 0
  212. enum {
  213. DWAXIDMAC_MBLK_TYPE_CONTIGUOUS = 0,
  214. DWAXIDMAC_MBLK_TYPE_RELOAD,
  215. DWAXIDMAC_MBLK_TYPE_SHADOW_REG,
  216. DWAXIDMAC_MBLK_TYPE_LL
  217. };
  218. /**
  219. * DW AXI DMA channel interrupts
  220. *
  221. * @DWAXIDMAC_IRQ_NONE: Bitmask of no one interrupt
  222. * @DWAXIDMAC_IRQ_BLOCK_TRF: Block transfer complete
  223. * @DWAXIDMAC_IRQ_DMA_TRF: Dma transfer complete
  224. * @DWAXIDMAC_IRQ_SRC_TRAN: Source transaction complete
  225. * @DWAXIDMAC_IRQ_DST_TRAN: Destination transaction complete
  226. * @DWAXIDMAC_IRQ_SRC_DEC_ERR: Source decode error
  227. * @DWAXIDMAC_IRQ_DST_DEC_ERR: Destination decode error
  228. * @DWAXIDMAC_IRQ_SRC_SLV_ERR: Source slave error
  229. * @DWAXIDMAC_IRQ_DST_SLV_ERR: Destination slave error
  230. * @DWAXIDMAC_IRQ_LLI_RD_DEC_ERR: LLI read decode error
  231. * @DWAXIDMAC_IRQ_LLI_WR_DEC_ERR: LLI write decode error
  232. * @DWAXIDMAC_IRQ_LLI_RD_SLV_ERR: LLI read slave error
  233. * @DWAXIDMAC_IRQ_LLI_WR_SLV_ERR: LLI write slave error
  234. * @DWAXIDMAC_IRQ_INVALID_ERR: LLI invalid error or Shadow register error
  235. * @DWAXIDMAC_IRQ_MULTIBLKTYPE_ERR: Slave Interface Multiblock type error
  236. * @DWAXIDMAC_IRQ_DEC_ERR: Slave Interface decode error
  237. * @DWAXIDMAC_IRQ_WR2RO_ERR: Slave Interface write to read only error
  238. * @DWAXIDMAC_IRQ_RD2RWO_ERR: Slave Interface read to write only error
  239. * @DWAXIDMAC_IRQ_WRONCHEN_ERR: Slave Interface write to channel error
  240. * @DWAXIDMAC_IRQ_SHADOWREG_ERR: Slave Interface shadow reg error
  241. * @DWAXIDMAC_IRQ_WRONHOLD_ERR: Slave Interface hold error
  242. * @DWAXIDMAC_IRQ_LOCK_CLEARED: Lock Cleared Status
  243. * @DWAXIDMAC_IRQ_SRC_SUSPENDED: Source Suspended Status
  244. * @DWAXIDMAC_IRQ_SUSPENDED: Channel Suspended Status
  245. * @DWAXIDMAC_IRQ_DISABLED: Channel Disabled Status
  246. * @DWAXIDMAC_IRQ_ABORTED: Channel Aborted Status
  247. * @DWAXIDMAC_IRQ_ALL_ERR: Bitmask of all error interrupts
  248. * @DWAXIDMAC_IRQ_ALL: Bitmask of all interrupts
  249. */
  250. enum {
  251. DWAXIDMAC_IRQ_NONE = 0,
  252. DWAXIDMAC_IRQ_BLOCK_TRF = BIT(0),
  253. DWAXIDMAC_IRQ_DMA_TRF = BIT(1),
  254. DWAXIDMAC_IRQ_SRC_TRAN = BIT(3),
  255. DWAXIDMAC_IRQ_DST_TRAN = BIT(4),
  256. DWAXIDMAC_IRQ_SRC_DEC_ERR = BIT(5),
  257. DWAXIDMAC_IRQ_DST_DEC_ERR = BIT(6),
  258. DWAXIDMAC_IRQ_SRC_SLV_ERR = BIT(7),
  259. DWAXIDMAC_IRQ_DST_SLV_ERR = BIT(8),
  260. DWAXIDMAC_IRQ_LLI_RD_DEC_ERR = BIT(9),
  261. DWAXIDMAC_IRQ_LLI_WR_DEC_ERR = BIT(10),
  262. DWAXIDMAC_IRQ_LLI_RD_SLV_ERR = BIT(11),
  263. DWAXIDMAC_IRQ_LLI_WR_SLV_ERR = BIT(12),
  264. DWAXIDMAC_IRQ_INVALID_ERR = BIT(13),
  265. DWAXIDMAC_IRQ_MULTIBLKTYPE_ERR = BIT(14),
  266. DWAXIDMAC_IRQ_DEC_ERR = BIT(16),
  267. DWAXIDMAC_IRQ_WR2RO_ERR = BIT(17),
  268. DWAXIDMAC_IRQ_RD2RWO_ERR = BIT(18),
  269. DWAXIDMAC_IRQ_WRONCHEN_ERR = BIT(19),
  270. DWAXIDMAC_IRQ_SHADOWREG_ERR = BIT(20),
  271. DWAXIDMAC_IRQ_WRONHOLD_ERR = BIT(21),
  272. DWAXIDMAC_IRQ_LOCK_CLEARED = BIT(27),
  273. DWAXIDMAC_IRQ_SRC_SUSPENDED = BIT(28),
  274. DWAXIDMAC_IRQ_SUSPENDED = BIT(29),
  275. DWAXIDMAC_IRQ_DISABLED = BIT(30),
  276. DWAXIDMAC_IRQ_ABORTED = BIT(31),
  277. DWAXIDMAC_IRQ_ALL_ERR = (GENMASK(21, 16) | GENMASK(14, 5)),
  278. DWAXIDMAC_IRQ_ALL = GENMASK(31, 0)
  279. };
  280. enum {
  281. DWAXIDMAC_TRANS_WIDTH_8 = 0,
  282. DWAXIDMAC_TRANS_WIDTH_16,
  283. DWAXIDMAC_TRANS_WIDTH_32,
  284. DWAXIDMAC_TRANS_WIDTH_64,
  285. DWAXIDMAC_TRANS_WIDTH_128,
  286. DWAXIDMAC_TRANS_WIDTH_256,
  287. DWAXIDMAC_TRANS_WIDTH_512,
  288. DWAXIDMAC_TRANS_WIDTH_MAX = DWAXIDMAC_TRANS_WIDTH_512
  289. };
  290. #endif /* _AXI_DMA_PLATFORM_H */