dw_dmac_regs.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Driver for the Synopsys DesignWare AHB DMA Controller
  3. *
  4. * Copyright (C) 2005-2007 Atmel Corporation
  5. * Copyright (C) 2010-2011 ST Microelectronics
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/dw_dmac.h>
  12. #define DW_DMA_MAX_NR_CHANNELS 8
  13. /*
  14. * Redefine this macro to handle differences between 32- and 64-bit
  15. * addressing, big vs. little endian, etc.
  16. */
  17. #define DW_REG(name) u32 name; u32 __pad_##name
  18. /* Hardware register definitions. */
  19. struct dw_dma_chan_regs {
  20. DW_REG(SAR); /* Source Address Register */
  21. DW_REG(DAR); /* Destination Address Register */
  22. DW_REG(LLP); /* Linked List Pointer */
  23. u32 CTL_LO; /* Control Register Low */
  24. u32 CTL_HI; /* Control Register High */
  25. DW_REG(SSTAT);
  26. DW_REG(DSTAT);
  27. DW_REG(SSTATAR);
  28. DW_REG(DSTATAR);
  29. u32 CFG_LO; /* Configuration Register Low */
  30. u32 CFG_HI; /* Configuration Register High */
  31. DW_REG(SGR);
  32. DW_REG(DSR);
  33. };
  34. struct dw_dma_irq_regs {
  35. DW_REG(XFER);
  36. DW_REG(BLOCK);
  37. DW_REG(SRC_TRAN);
  38. DW_REG(DST_TRAN);
  39. DW_REG(ERROR);
  40. };
  41. struct dw_dma_regs {
  42. /* per-channel registers */
  43. struct dw_dma_chan_regs CHAN[DW_DMA_MAX_NR_CHANNELS];
  44. /* irq handling */
  45. struct dw_dma_irq_regs RAW; /* r */
  46. struct dw_dma_irq_regs STATUS; /* r (raw & mask) */
  47. struct dw_dma_irq_regs MASK; /* rw (set = irq enabled) */
  48. struct dw_dma_irq_regs CLEAR; /* w (ack, affects "raw") */
  49. DW_REG(STATUS_INT); /* r */
  50. /* software handshaking */
  51. DW_REG(REQ_SRC);
  52. DW_REG(REQ_DST);
  53. DW_REG(SGL_REQ_SRC);
  54. DW_REG(SGL_REQ_DST);
  55. DW_REG(LAST_SRC);
  56. DW_REG(LAST_DST);
  57. /* miscellaneous */
  58. DW_REG(CFG);
  59. DW_REG(CH_EN);
  60. DW_REG(ID);
  61. DW_REG(TEST);
  62. /* optional encoded params, 0x3c8..0x3 */
  63. };
  64. /* Bitfields in CTL_LO */
  65. #define DWC_CTLL_INT_EN (1 << 0) /* irqs enabled? */
  66. #define DWC_CTLL_DST_WIDTH(n) ((n)<<1) /* bytes per element */
  67. #define DWC_CTLL_SRC_WIDTH(n) ((n)<<4)
  68. #define DWC_CTLL_DST_INC (0<<7) /* DAR update/not */
  69. #define DWC_CTLL_DST_DEC (1<<7)
  70. #define DWC_CTLL_DST_FIX (2<<7)
  71. #define DWC_CTLL_SRC_INC (0<<7) /* SAR update/not */
  72. #define DWC_CTLL_SRC_DEC (1<<9)
  73. #define DWC_CTLL_SRC_FIX (2<<9)
  74. #define DWC_CTLL_DST_MSIZE(n) ((n)<<11) /* burst, #elements */
  75. #define DWC_CTLL_SRC_MSIZE(n) ((n)<<14)
  76. #define DWC_CTLL_S_GATH_EN (1 << 17) /* src gather, !FIX */
  77. #define DWC_CTLL_D_SCAT_EN (1 << 18) /* dst scatter, !FIX */
  78. #define DWC_CTLL_FC(n) ((n) << 20)
  79. #define DWC_CTLL_FC_M2M (0 << 20) /* mem-to-mem */
  80. #define DWC_CTLL_FC_M2P (1 << 20) /* mem-to-periph */
  81. #define DWC_CTLL_FC_P2M (2 << 20) /* periph-to-mem */
  82. #define DWC_CTLL_FC_P2P (3 << 20) /* periph-to-periph */
  83. /* plus 4 transfer types for peripheral-as-flow-controller */
  84. #define DWC_CTLL_DMS(n) ((n)<<23) /* dst master select */
  85. #define DWC_CTLL_SMS(n) ((n)<<25) /* src master select */
  86. #define DWC_CTLL_LLP_D_EN (1 << 27) /* dest block chain */
  87. #define DWC_CTLL_LLP_S_EN (1 << 28) /* src block chain */
  88. /* Bitfields in CTL_HI */
  89. #define DWC_CTLH_DONE 0x00001000
  90. #define DWC_CTLH_BLOCK_TS_MASK 0x00000fff
  91. /* Bitfields in CFG_LO. Platform-configurable bits are in <linux/dw_dmac.h> */
  92. #define DWC_CFGL_CH_PRIOR_MASK (0x7 << 5) /* priority mask */
  93. #define DWC_CFGL_CH_PRIOR(x) ((x) << 5) /* priority */
  94. #define DWC_CFGL_CH_SUSP (1 << 8) /* pause xfer */
  95. #define DWC_CFGL_FIFO_EMPTY (1 << 9) /* pause xfer */
  96. #define DWC_CFGL_HS_DST (1 << 10) /* handshake w/dst */
  97. #define DWC_CFGL_HS_SRC (1 << 11) /* handshake w/src */
  98. #define DWC_CFGL_MAX_BURST(x) ((x) << 20)
  99. #define DWC_CFGL_RELOAD_SAR (1 << 30)
  100. #define DWC_CFGL_RELOAD_DAR (1 << 31)
  101. /* Bitfields in CFG_HI. Platform-configurable bits are in <linux/dw_dmac.h> */
  102. #define DWC_CFGH_DS_UPD_EN (1 << 5)
  103. #define DWC_CFGH_SS_UPD_EN (1 << 6)
  104. /* Bitfields in SGR */
  105. #define DWC_SGR_SGI(x) ((x) << 0)
  106. #define DWC_SGR_SGC(x) ((x) << 20)
  107. /* Bitfields in DSR */
  108. #define DWC_DSR_DSI(x) ((x) << 0)
  109. #define DWC_DSR_DSC(x) ((x) << 20)
  110. /* Bitfields in CFG */
  111. #define DW_CFG_DMA_EN (1 << 0)
  112. #define DW_REGLEN 0x400
  113. enum dw_dmac_flags {
  114. DW_DMA_IS_CYCLIC = 0,
  115. };
  116. struct dw_dma_chan {
  117. struct dma_chan chan;
  118. void __iomem *ch_regs;
  119. u8 mask;
  120. u8 priority;
  121. bool paused;
  122. spinlock_t lock;
  123. /* these other elements are all protected by lock */
  124. unsigned long flags;
  125. dma_cookie_t completed;
  126. struct list_head active_list;
  127. struct list_head queue;
  128. struct list_head free_list;
  129. struct dw_cyclic_desc *cdesc;
  130. unsigned int descs_allocated;
  131. };
  132. static inline struct dw_dma_chan_regs __iomem *
  133. __dwc_regs(struct dw_dma_chan *dwc)
  134. {
  135. return dwc->ch_regs;
  136. }
  137. #define channel_readl(dwc, name) \
  138. readl(&(__dwc_regs(dwc)->name))
  139. #define channel_writel(dwc, name, val) \
  140. writel((val), &(__dwc_regs(dwc)->name))
  141. static inline struct dw_dma_chan *to_dw_dma_chan(struct dma_chan *chan)
  142. {
  143. return container_of(chan, struct dw_dma_chan, chan);
  144. }
  145. struct dw_dma {
  146. struct dma_device dma;
  147. void __iomem *regs;
  148. struct tasklet_struct tasklet;
  149. struct clk *clk;
  150. u8 all_chan_mask;
  151. struct dw_dma_chan chan[0];
  152. };
  153. static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw)
  154. {
  155. return dw->regs;
  156. }
  157. #define dma_readl(dw, name) \
  158. readl(&(__dw_regs(dw)->name))
  159. #define dma_writel(dw, name, val) \
  160. writel((val), &(__dw_regs(dw)->name))
  161. #define channel_set_bit(dw, reg, mask) \
  162. dma_writel(dw, reg, ((mask) << 8) | (mask))
  163. #define channel_clear_bit(dw, reg, mask) \
  164. dma_writel(dw, reg, ((mask) << 8) | 0)
  165. static inline struct dw_dma *to_dw_dma(struct dma_device *ddev)
  166. {
  167. return container_of(ddev, struct dw_dma, dma);
  168. }
  169. /* LLI == Linked List Item; a.k.a. DMA block descriptor */
  170. struct dw_lli {
  171. /* values that are not changed by hardware */
  172. dma_addr_t sar;
  173. dma_addr_t dar;
  174. dma_addr_t llp; /* chain to next lli */
  175. u32 ctllo;
  176. /* values that may get written back: */
  177. u32 ctlhi;
  178. /* sstat and dstat can snapshot peripheral register state.
  179. * silicon config may discard either or both...
  180. */
  181. u32 sstat;
  182. u32 dstat;
  183. };
  184. struct dw_desc {
  185. /* FIRST values the hardware uses */
  186. struct dw_lli lli;
  187. /* THEN values for driver housekeeping */
  188. struct list_head desc_node;
  189. struct list_head tx_list;
  190. struct dma_async_tx_descriptor txd;
  191. size_t len;
  192. };
  193. static inline struct dw_desc *
  194. txd_to_dw_desc(struct dma_async_tx_descriptor *txd)
  195. {
  196. return container_of(txd, struct dw_desc, txd);
  197. }