dw_dmac_regs.h 5.9 KB

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