PageRenderTime 60ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/dma/dw-axi-dmac/dw-axi-dmac.h

https://github.com/kvaneesh/linux
C Header | 366 lines | 269 code | 46 blank | 51 comment | 0 complexity | 3159efe7246506d7d544b76be51cbced MD5 | raw file
  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. u8 hw_handshake_num;
  34. atomic_t descs_allocated;
  35. struct dma_pool *desc_pool;
  36. struct virt_dma_chan vc;
  37. struct axi_dma_desc *desc;
  38. struct dma_slave_config config;
  39. enum dma_transfer_direction direction;
  40. bool cyclic;
  41. /* these other elements are all protected by vc.lock */
  42. bool is_paused;
  43. };
  44. struct dw_axi_dma {
  45. struct dma_device dma;
  46. struct dw_axi_dma_hcfg *hdata;
  47. struct device_dma_parameters dma_parms;
  48. /* channels */
  49. struct axi_dma_chan *chan;
  50. };
  51. struct axi_dma_chip {
  52. struct device *dev;
  53. int irq;
  54. void __iomem *regs;
  55. void __iomem *apb_regs;
  56. struct clk *core_clk;
  57. struct clk *cfgr_clk;
  58. struct dw_axi_dma *dw;
  59. };
  60. /* LLI == Linked List Item */
  61. struct __packed axi_dma_lli {
  62. __le64 sar;
  63. __le64 dar;
  64. __le32 block_ts_lo;
  65. __le32 block_ts_hi;
  66. __le64 llp;
  67. __le32 ctl_lo;
  68. __le32 ctl_hi;
  69. __le32 sstat;
  70. __le32 dstat;
  71. __le32 status_lo;
  72. __le32 status_hi;
  73. __le32 reserved_lo;
  74. __le32 reserved_hi;
  75. };
  76. struct axi_dma_hw_desc {
  77. struct axi_dma_lli *lli;
  78. dma_addr_t llp;
  79. u32 len;
  80. };
  81. struct axi_dma_desc {
  82. struct axi_dma_hw_desc *hw_desc;
  83. struct virt_dma_desc vd;
  84. struct axi_dma_chan *chan;
  85. u32 completed_blocks;
  86. u32 length;
  87. u32 period_len;
  88. };
  89. static inline struct device *dchan2dev(struct dma_chan *dchan)
  90. {
  91. return &dchan->dev->device;
  92. }
  93. static inline struct device *chan2dev(struct axi_dma_chan *chan)
  94. {
  95. return &chan->vc.chan.dev->device;
  96. }
  97. static inline struct axi_dma_desc *vd_to_axi_desc(struct virt_dma_desc *vd)
  98. {
  99. return container_of(vd, struct axi_dma_desc, vd);
  100. }
  101. static inline struct axi_dma_chan *vc_to_axi_dma_chan(struct virt_dma_chan *vc)
  102. {
  103. return container_of(vc, struct axi_dma_chan, vc);
  104. }
  105. static inline struct axi_dma_chan *dchan_to_axi_dma_chan(struct dma_chan *dchan)
  106. {
  107. return vc_to_axi_dma_chan(to_virt_chan(dchan));
  108. }
  109. #define COMMON_REG_LEN 0x100
  110. #define CHAN_REG_LEN 0x100
  111. /* Common registers offset */
  112. #define DMAC_ID 0x000 /* R DMAC ID */
  113. #define DMAC_COMPVER 0x008 /* R DMAC Component Version */
  114. #define DMAC_CFG 0x010 /* R/W DMAC Configuration */
  115. #define DMAC_CHEN 0x018 /* R/W DMAC Channel Enable */
  116. #define DMAC_CHEN_L 0x018 /* R/W DMAC Channel Enable 00-31 */
  117. #define DMAC_CHEN_H 0x01C /* R/W DMAC Channel Enable 32-63 */
  118. #define DMAC_INTSTATUS 0x030 /* R DMAC Interrupt Status */
  119. #define DMAC_COMMON_INTCLEAR 0x038 /* W DMAC Interrupt Clear */
  120. #define DMAC_COMMON_INTSTATUS_ENA 0x040 /* R DMAC Interrupt Status Enable */
  121. #define DMAC_COMMON_INTSIGNAL_ENA 0x048 /* R/W DMAC Interrupt Signal Enable */
  122. #define DMAC_COMMON_INTSTATUS 0x050 /* R DMAC Interrupt Status */
  123. #define DMAC_RESET 0x058 /* R DMAC Reset Register1 */
  124. /* DMA channel registers offset */
  125. #define CH_SAR 0x000 /* R/W Chan Source Address */
  126. #define CH_DAR 0x008 /* R/W Chan Destination Address */
  127. #define CH_BLOCK_TS 0x010 /* R/W Chan Block Transfer Size */
  128. #define CH_CTL 0x018 /* R/W Chan Control */
  129. #define CH_CTL_L 0x018 /* R/W Chan Control 00-31 */
  130. #define CH_CTL_H 0x01C /* R/W Chan Control 32-63 */
  131. #define CH_CFG 0x020 /* R/W Chan Configuration */
  132. #define CH_CFG_L 0x020 /* R/W Chan Configuration 00-31 */
  133. #define CH_CFG_H 0x024 /* R/W Chan Configuration 32-63 */
  134. #define CH_LLP 0x028 /* R/W Chan Linked List Pointer */
  135. #define CH_STATUS 0x030 /* R Chan Status */
  136. #define CH_SWHSSRC 0x038 /* R/W Chan SW Handshake Source */
  137. #define CH_SWHSDST 0x040 /* R/W Chan SW Handshake Destination */
  138. #define CH_BLK_TFR_RESUMEREQ 0x048 /* W Chan Block Transfer Resume Req */
  139. #define CH_AXI_ID 0x050 /* R/W Chan AXI ID */
  140. #define CH_AXI_QOS 0x058 /* R/W Chan AXI QOS */
  141. #define CH_SSTAT 0x060 /* R Chan Source Status */
  142. #define CH_DSTAT 0x068 /* R Chan Destination Status */
  143. #define CH_SSTATAR 0x070 /* R/W Chan Source Status Fetch Addr */
  144. #define CH_DSTATAR 0x078 /* R/W Chan Destination Status Fetch Addr */
  145. #define CH_INTSTATUS_ENA 0x080 /* R/W Chan Interrupt Status Enable */
  146. #define CH_INTSTATUS 0x088 /* R/W Chan Interrupt Status */
  147. #define CH_INTSIGNAL_ENA 0x090 /* R/W Chan Interrupt Signal Enable */
  148. #define CH_INTCLEAR 0x098 /* W Chan Interrupt Clear */
  149. /* These Apb registers are used by Intel KeemBay SoC */
  150. #define DMAC_APB_CFG 0x000 /* DMAC Apb Configuration Register */
  151. #define DMAC_APB_STAT 0x004 /* DMAC Apb Status Register */
  152. #define DMAC_APB_DEBUG_STAT_0 0x008 /* DMAC Apb Debug Status Register 0 */
  153. #define DMAC_APB_DEBUG_STAT_1 0x00C /* DMAC Apb Debug Status Register 1 */
  154. #define DMAC_APB_HW_HS_SEL_0 0x010 /* DMAC Apb HW HS register 0 */
  155. #define DMAC_APB_HW_HS_SEL_1 0x014 /* DMAC Apb HW HS register 1 */
  156. #define DMAC_APB_LPI 0x018 /* DMAC Apb Low Power Interface Reg */
  157. #define DMAC_APB_BYTE_WR_CH_EN 0x01C /* DMAC Apb Byte Write Enable */
  158. #define DMAC_APB_HALFWORD_WR_CH_EN 0x020 /* DMAC Halfword write enables */
  159. #define UNUSED_CHANNEL 0x3F /* Set unused DMA channel to 0x3F */
  160. #define DMA_APB_HS_SEL_BIT_SIZE 0x08 /* HW handshake bits per channel */
  161. #define DMA_APB_HS_SEL_MASK 0xFF /* HW handshake select masks */
  162. #define MAX_BLOCK_SIZE 0x1000 /* 1024 blocks * 4 bytes data width */
  163. /* DMAC_CFG */
  164. #define DMAC_EN_POS 0
  165. #define DMAC_EN_MASK BIT(DMAC_EN_POS)
  166. #define INT_EN_POS 1
  167. #define INT_EN_MASK BIT(INT_EN_POS)
  168. #define DMAC_CHAN_EN_SHIFT 0
  169. #define DMAC_CHAN_EN_WE_SHIFT 8
  170. #define DMAC_CHAN_SUSP_SHIFT 16
  171. #define DMAC_CHAN_SUSP_WE_SHIFT 24
  172. /* CH_CTL_H */
  173. #define CH_CTL_H_ARLEN_EN BIT(6)
  174. #define CH_CTL_H_ARLEN_POS 7
  175. #define CH_CTL_H_AWLEN_EN BIT(15)
  176. #define CH_CTL_H_AWLEN_POS 16
  177. enum {
  178. DWAXIDMAC_ARWLEN_1 = 0,
  179. DWAXIDMAC_ARWLEN_2 = 1,
  180. DWAXIDMAC_ARWLEN_4 = 3,
  181. DWAXIDMAC_ARWLEN_8 = 7,
  182. DWAXIDMAC_ARWLEN_16 = 15,
  183. DWAXIDMAC_ARWLEN_32 = 31,
  184. DWAXIDMAC_ARWLEN_64 = 63,
  185. DWAXIDMAC_ARWLEN_128 = 127,
  186. DWAXIDMAC_ARWLEN_256 = 255,
  187. DWAXIDMAC_ARWLEN_MIN = DWAXIDMAC_ARWLEN_1,
  188. DWAXIDMAC_ARWLEN_MAX = DWAXIDMAC_ARWLEN_256
  189. };
  190. #define CH_CTL_H_LLI_LAST BIT(30)
  191. #define CH_CTL_H_LLI_VALID BIT(31)
  192. /* CH_CTL_L */
  193. #define CH_CTL_L_LAST_WRITE_EN BIT(30)
  194. #define CH_CTL_L_DST_MSIZE_POS 18
  195. #define CH_CTL_L_SRC_MSIZE_POS 14
  196. enum {
  197. DWAXIDMAC_BURST_TRANS_LEN_1 = 0,
  198. DWAXIDMAC_BURST_TRANS_LEN_4,
  199. DWAXIDMAC_BURST_TRANS_LEN_8,
  200. DWAXIDMAC_BURST_TRANS_LEN_16,
  201. DWAXIDMAC_BURST_TRANS_LEN_32,
  202. DWAXIDMAC_BURST_TRANS_LEN_64,
  203. DWAXIDMAC_BURST_TRANS_LEN_128,
  204. DWAXIDMAC_BURST_TRANS_LEN_256,
  205. DWAXIDMAC_BURST_TRANS_LEN_512,
  206. DWAXIDMAC_BURST_TRANS_LEN_1024
  207. };
  208. #define CH_CTL_L_DST_WIDTH_POS 11
  209. #define CH_CTL_L_SRC_WIDTH_POS 8
  210. #define CH_CTL_L_DST_INC_POS 6
  211. #define CH_CTL_L_SRC_INC_POS 4
  212. enum {
  213. DWAXIDMAC_CH_CTL_L_INC = 0,
  214. DWAXIDMAC_CH_CTL_L_NOINC
  215. };
  216. #define CH_CTL_L_DST_MAST BIT(2)
  217. #define CH_CTL_L_SRC_MAST BIT(0)
  218. /* CH_CFG_H */
  219. #define CH_CFG_H_PRIORITY_POS 17
  220. #define CH_CFG_H_DST_PER_POS 12
  221. #define CH_CFG_H_SRC_PER_POS 7
  222. #define CH_CFG_H_HS_SEL_DST_POS 4
  223. #define CH_CFG_H_HS_SEL_SRC_POS 3
  224. enum {
  225. DWAXIDMAC_HS_SEL_HW = 0,
  226. DWAXIDMAC_HS_SEL_SW
  227. };
  228. #define CH_CFG_H_TT_FC_POS 0
  229. enum {
  230. DWAXIDMAC_TT_FC_MEM_TO_MEM_DMAC = 0,
  231. DWAXIDMAC_TT_FC_MEM_TO_PER_DMAC,
  232. DWAXIDMAC_TT_FC_PER_TO_MEM_DMAC,
  233. DWAXIDMAC_TT_FC_PER_TO_PER_DMAC,
  234. DWAXIDMAC_TT_FC_PER_TO_MEM_SRC,
  235. DWAXIDMAC_TT_FC_PER_TO_PER_SRC,
  236. DWAXIDMAC_TT_FC_MEM_TO_PER_DST,
  237. DWAXIDMAC_TT_FC_PER_TO_PER_DST
  238. };
  239. /* CH_CFG_L */
  240. #define CH_CFG_L_DST_MULTBLK_TYPE_POS 2
  241. #define CH_CFG_L_SRC_MULTBLK_TYPE_POS 0
  242. enum {
  243. DWAXIDMAC_MBLK_TYPE_CONTIGUOUS = 0,
  244. DWAXIDMAC_MBLK_TYPE_RELOAD,
  245. DWAXIDMAC_MBLK_TYPE_SHADOW_REG,
  246. DWAXIDMAC_MBLK_TYPE_LL
  247. };
  248. /**
  249. * DW AXI DMA channel interrupts
  250. *
  251. * @DWAXIDMAC_IRQ_NONE: Bitmask of no one interrupt
  252. * @DWAXIDMAC_IRQ_BLOCK_TRF: Block transfer complete
  253. * @DWAXIDMAC_IRQ_DMA_TRF: Dma transfer complete
  254. * @DWAXIDMAC_IRQ_SRC_TRAN: Source transaction complete
  255. * @DWAXIDMAC_IRQ_DST_TRAN: Destination transaction complete
  256. * @DWAXIDMAC_IRQ_SRC_DEC_ERR: Source decode error
  257. * @DWAXIDMAC_IRQ_DST_DEC_ERR: Destination decode error
  258. * @DWAXIDMAC_IRQ_SRC_SLV_ERR: Source slave error
  259. * @DWAXIDMAC_IRQ_DST_SLV_ERR: Destination slave error
  260. * @DWAXIDMAC_IRQ_LLI_RD_DEC_ERR: LLI read decode error
  261. * @DWAXIDMAC_IRQ_LLI_WR_DEC_ERR: LLI write decode error
  262. * @DWAXIDMAC_IRQ_LLI_RD_SLV_ERR: LLI read slave error
  263. * @DWAXIDMAC_IRQ_LLI_WR_SLV_ERR: LLI write slave error
  264. * @DWAXIDMAC_IRQ_INVALID_ERR: LLI invalid error or Shadow register error
  265. * @DWAXIDMAC_IRQ_MULTIBLKTYPE_ERR: Slave Interface Multiblock type error
  266. * @DWAXIDMAC_IRQ_DEC_ERR: Slave Interface decode error
  267. * @DWAXIDMAC_IRQ_WR2RO_ERR: Slave Interface write to read only error
  268. * @DWAXIDMAC_IRQ_RD2RWO_ERR: Slave Interface read to write only error
  269. * @DWAXIDMAC_IRQ_WRONCHEN_ERR: Slave Interface write to channel error
  270. * @DWAXIDMAC_IRQ_SHADOWREG_ERR: Slave Interface shadow reg error
  271. * @DWAXIDMAC_IRQ_WRONHOLD_ERR: Slave Interface hold error
  272. * @DWAXIDMAC_IRQ_LOCK_CLEARED: Lock Cleared Status
  273. * @DWAXIDMAC_IRQ_SRC_SUSPENDED: Source Suspended Status
  274. * @DWAXIDMAC_IRQ_SUSPENDED: Channel Suspended Status
  275. * @DWAXIDMAC_IRQ_DISABLED: Channel Disabled Status
  276. * @DWAXIDMAC_IRQ_ABORTED: Channel Aborted Status
  277. * @DWAXIDMAC_IRQ_ALL_ERR: Bitmask of all error interrupts
  278. * @DWAXIDMAC_IRQ_ALL: Bitmask of all interrupts
  279. */
  280. enum {
  281. DWAXIDMAC_IRQ_NONE = 0,
  282. DWAXIDMAC_IRQ_BLOCK_TRF = BIT(0),
  283. DWAXIDMAC_IRQ_DMA_TRF = BIT(1),
  284. DWAXIDMAC_IRQ_SRC_TRAN = BIT(3),
  285. DWAXIDMAC_IRQ_DST_TRAN = BIT(4),
  286. DWAXIDMAC_IRQ_SRC_DEC_ERR = BIT(5),
  287. DWAXIDMAC_IRQ_DST_DEC_ERR = BIT(6),
  288. DWAXIDMAC_IRQ_SRC_SLV_ERR = BIT(7),
  289. DWAXIDMAC_IRQ_DST_SLV_ERR = BIT(8),
  290. DWAXIDMAC_IRQ_LLI_RD_DEC_ERR = BIT(9),
  291. DWAXIDMAC_IRQ_LLI_WR_DEC_ERR = BIT(10),
  292. DWAXIDMAC_IRQ_LLI_RD_SLV_ERR = BIT(11),
  293. DWAXIDMAC_IRQ_LLI_WR_SLV_ERR = BIT(12),
  294. DWAXIDMAC_IRQ_INVALID_ERR = BIT(13),
  295. DWAXIDMAC_IRQ_MULTIBLKTYPE_ERR = BIT(14),
  296. DWAXIDMAC_IRQ_DEC_ERR = BIT(16),
  297. DWAXIDMAC_IRQ_WR2RO_ERR = BIT(17),
  298. DWAXIDMAC_IRQ_RD2RWO_ERR = BIT(18),
  299. DWAXIDMAC_IRQ_WRONCHEN_ERR = BIT(19),
  300. DWAXIDMAC_IRQ_SHADOWREG_ERR = BIT(20),
  301. DWAXIDMAC_IRQ_WRONHOLD_ERR = BIT(21),
  302. DWAXIDMAC_IRQ_LOCK_CLEARED = BIT(27),
  303. DWAXIDMAC_IRQ_SRC_SUSPENDED = BIT(28),
  304. DWAXIDMAC_IRQ_SUSPENDED = BIT(29),
  305. DWAXIDMAC_IRQ_DISABLED = BIT(30),
  306. DWAXIDMAC_IRQ_ABORTED = BIT(31),
  307. DWAXIDMAC_IRQ_ALL_ERR = (GENMASK(21, 16) | GENMASK(14, 5)),
  308. DWAXIDMAC_IRQ_ALL = GENMASK(31, 0)
  309. };
  310. enum {
  311. DWAXIDMAC_TRANS_WIDTH_8 = 0,
  312. DWAXIDMAC_TRANS_WIDTH_16,
  313. DWAXIDMAC_TRANS_WIDTH_32,
  314. DWAXIDMAC_TRANS_WIDTH_64,
  315. DWAXIDMAC_TRANS_WIDTH_128,
  316. DWAXIDMAC_TRANS_WIDTH_256,
  317. DWAXIDMAC_TRANS_WIDTH_512,
  318. DWAXIDMAC_TRANS_WIDTH_MAX = DWAXIDMAC_TRANS_WIDTH_512
  319. };
  320. #endif /* _AXI_DMA_PLATFORM_H */