txx9dmac.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * Driver for the TXx9 SoC DMA Controller
  3. *
  4. * Copyright (C) 2009 Atsushi Nemoto
  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. #ifndef TXX9DMAC_H
  11. #define TXX9DMAC_H
  12. #include <linux/dmaengine.h>
  13. #include <asm/txx9/dmac.h>
  14. /*
  15. * Design Notes:
  16. *
  17. * This DMAC have four channels and one FIFO buffer. Each channel can
  18. * be configured for memory-memory or device-memory transfer, but only
  19. * one channel can do alignment-free memory-memory transfer at a time
  20. * while the channel should occupy the FIFO buffer for effective
  21. * transfers.
  22. *
  23. * Instead of dynamically assign the FIFO buffer to channels, I chose
  24. * make one dedicated channel for memory-memory transfer. The
  25. * dedicated channel is public. Other channels are private and used
  26. * for slave transfer. Some devices in the SoC are wired to certain
  27. * DMA channel.
  28. */
  29. #ifdef CONFIG_MACH_TX49XX
  30. static inline bool txx9_dma_have_SMPCHN(void)
  31. {
  32. return true;
  33. }
  34. #define TXX9_DMA_USE_SIMPLE_CHAIN
  35. #else
  36. static inline bool txx9_dma_have_SMPCHN(void)
  37. {
  38. return false;
  39. }
  40. #endif
  41. #ifdef __LITTLE_ENDIAN
  42. #ifdef CONFIG_MACH_TX49XX
  43. #define CCR_LE TXX9_DMA_CCR_LE
  44. #define MCR_LE 0
  45. #else
  46. #define CCR_LE 0
  47. #define MCR_LE TXX9_DMA_MCR_LE
  48. #endif
  49. #else
  50. #define CCR_LE 0
  51. #define MCR_LE 0
  52. #endif
  53. /*
  54. * Redefine this macro to handle differences between 32- and 64-bit
  55. * addressing, big vs. little endian, etc.
  56. */
  57. #ifdef __BIG_ENDIAN
  58. #define TXX9_DMA_REG32(name) u32 __pad_##name; u32 name
  59. #else
  60. #define TXX9_DMA_REG32(name) u32 name; u32 __pad_##name
  61. #endif
  62. /* Hardware register definitions. */
  63. struct txx9dmac_cregs {
  64. #if defined(CONFIG_32BIT) && !defined(CONFIG_64BIT_PHYS_ADDR)
  65. TXX9_DMA_REG32(CHAR); /* Chain Address Register */
  66. #else
  67. u64 CHAR; /* Chain Address Register */
  68. #endif
  69. u64 SAR; /* Source Address Register */
  70. u64 DAR; /* Destination Address Register */
  71. TXX9_DMA_REG32(CNTR); /* Count Register */
  72. TXX9_DMA_REG32(SAIR); /* Source Address Increment Register */
  73. TXX9_DMA_REG32(DAIR); /* Destination Address Increment Register */
  74. TXX9_DMA_REG32(CCR); /* Channel Control Register */
  75. TXX9_DMA_REG32(CSR); /* Channel Status Register */
  76. };
  77. struct txx9dmac_cregs32 {
  78. u32 CHAR;
  79. u32 SAR;
  80. u32 DAR;
  81. u32 CNTR;
  82. u32 SAIR;
  83. u32 DAIR;
  84. u32 CCR;
  85. u32 CSR;
  86. };
  87. struct txx9dmac_regs {
  88. /* per-channel registers */
  89. struct txx9dmac_cregs CHAN[TXX9_DMA_MAX_NR_CHANNELS];
  90. u64 __pad[9];
  91. u64 MFDR; /* Memory Fill Data Register */
  92. TXX9_DMA_REG32(MCR); /* Master Control Register */
  93. };
  94. struct txx9dmac_regs32 {
  95. struct txx9dmac_cregs32 CHAN[TXX9_DMA_MAX_NR_CHANNELS];
  96. u32 __pad[9];
  97. u32 MFDR;
  98. u32 MCR;
  99. };
  100. /* bits for MCR */
  101. #define TXX9_DMA_MCR_EIS(ch) (0x10000000<<(ch))
  102. #define TXX9_DMA_MCR_DIS(ch) (0x01000000<<(ch))
  103. #define TXX9_DMA_MCR_RSFIF 0x00000080
  104. #define TXX9_DMA_MCR_FIFUM(ch) (0x00000008<<(ch))
  105. #define TXX9_DMA_MCR_LE 0x00000004
  106. #define TXX9_DMA_MCR_RPRT 0x00000002
  107. #define TXX9_DMA_MCR_MSTEN 0x00000001
  108. /* bits for CCRn */
  109. #define TXX9_DMA_CCR_IMMCHN 0x20000000
  110. #define TXX9_DMA_CCR_USEXFSZ 0x10000000
  111. #define TXX9_DMA_CCR_LE 0x08000000
  112. #define TXX9_DMA_CCR_DBINH 0x04000000
  113. #define TXX9_DMA_CCR_SBINH 0x02000000
  114. #define TXX9_DMA_CCR_CHRST 0x01000000
  115. #define TXX9_DMA_CCR_RVBYTE 0x00800000
  116. #define TXX9_DMA_CCR_ACKPOL 0x00400000
  117. #define TXX9_DMA_CCR_REQPL 0x00200000
  118. #define TXX9_DMA_CCR_EGREQ 0x00100000
  119. #define TXX9_DMA_CCR_CHDN 0x00080000
  120. #define TXX9_DMA_CCR_DNCTL 0x00060000
  121. #define TXX9_DMA_CCR_EXTRQ 0x00010000
  122. #define TXX9_DMA_CCR_INTRQD 0x0000e000
  123. #define TXX9_DMA_CCR_INTENE 0x00001000
  124. #define TXX9_DMA_CCR_INTENC 0x00000800
  125. #define TXX9_DMA_CCR_INTENT 0x00000400
  126. #define TXX9_DMA_CCR_CHNEN 0x00000200
  127. #define TXX9_DMA_CCR_XFACT 0x00000100
  128. #define TXX9_DMA_CCR_SMPCHN 0x00000020
  129. #define TXX9_DMA_CCR_XFSZ(order) (((order) << 2) & 0x0000001c)
  130. #define TXX9_DMA_CCR_XFSZ_1 TXX9_DMA_CCR_XFSZ(0)
  131. #define TXX9_DMA_CCR_XFSZ_2 TXX9_DMA_CCR_XFSZ(1)
  132. #define TXX9_DMA_CCR_XFSZ_4 TXX9_DMA_CCR_XFSZ(2)
  133. #define TXX9_DMA_CCR_XFSZ_8 TXX9_DMA_CCR_XFSZ(3)
  134. #define TXX9_DMA_CCR_XFSZ_X4 TXX9_DMA_CCR_XFSZ(4)
  135. #define TXX9_DMA_CCR_XFSZ_X8 TXX9_DMA_CCR_XFSZ(5)
  136. #define TXX9_DMA_CCR_XFSZ_X16 TXX9_DMA_CCR_XFSZ(6)
  137. #define TXX9_DMA_CCR_XFSZ_X32 TXX9_DMA_CCR_XFSZ(7)
  138. #define TXX9_DMA_CCR_MEMIO 0x00000002
  139. #define TXX9_DMA_CCR_SNGAD 0x00000001
  140. /* bits for CSRn */
  141. #define TXX9_DMA_CSR_CHNEN 0x00000400
  142. #define TXX9_DMA_CSR_STLXFER 0x00000200
  143. #define TXX9_DMA_CSR_XFACT 0x00000100
  144. #define TXX9_DMA_CSR_ABCHC 0x00000080
  145. #define TXX9_DMA_CSR_NCHNC 0x00000040
  146. #define TXX9_DMA_CSR_NTRNFC 0x00000020
  147. #define TXX9_DMA_CSR_EXTDN 0x00000010
  148. #define TXX9_DMA_CSR_CFERR 0x00000008
  149. #define TXX9_DMA_CSR_CHERR 0x00000004
  150. #define TXX9_DMA_CSR_DESERR 0x00000002
  151. #define TXX9_DMA_CSR_SORERR 0x00000001
  152. struct txx9dmac_chan {
  153. struct dma_chan chan;
  154. struct dma_device dma;
  155. struct txx9dmac_dev *ddev;
  156. void __iomem *ch_regs;
  157. struct tasklet_struct tasklet;
  158. int irq;
  159. u32 ccr;
  160. spinlock_t lock;
  161. /* these other elements are all protected by lock */
  162. dma_cookie_t completed;
  163. struct list_head active_list;
  164. struct list_head queue;
  165. struct list_head free_list;
  166. unsigned int descs_allocated;
  167. };
  168. struct txx9dmac_dev {
  169. void __iomem *regs;
  170. struct tasklet_struct tasklet;
  171. int irq;
  172. struct txx9dmac_chan *chan[TXX9_DMA_MAX_NR_CHANNELS];
  173. bool have_64bit_regs;
  174. unsigned int descsize;
  175. };
  176. static inline bool __is_dmac64(const struct txx9dmac_dev *ddev)
  177. {
  178. return ddev->have_64bit_regs;
  179. }
  180. static inline bool is_dmac64(const struct txx9dmac_chan *dc)
  181. {
  182. return __is_dmac64(dc->ddev);
  183. }
  184. #ifdef TXX9_DMA_USE_SIMPLE_CHAIN
  185. /* Hardware descriptor definition. (for simple-chain) */
  186. struct txx9dmac_hwdesc {
  187. #if defined(CONFIG_32BIT) && !defined(CONFIG_64BIT_PHYS_ADDR)
  188. TXX9_DMA_REG32(CHAR);
  189. #else
  190. u64 CHAR;
  191. #endif
  192. u64 SAR;
  193. u64 DAR;
  194. TXX9_DMA_REG32(CNTR);
  195. };
  196. struct txx9dmac_hwdesc32 {
  197. u32 CHAR;
  198. u32 SAR;
  199. u32 DAR;
  200. u32 CNTR;
  201. };
  202. #else
  203. #define txx9dmac_hwdesc txx9dmac_cregs
  204. #define txx9dmac_hwdesc32 txx9dmac_cregs32
  205. #endif
  206. struct txx9dmac_desc {
  207. /* FIRST values the hardware uses */
  208. union {
  209. struct txx9dmac_hwdesc hwdesc;
  210. struct txx9dmac_hwdesc32 hwdesc32;
  211. };
  212. /* THEN values for driver housekeeping */
  213. struct list_head desc_node ____cacheline_aligned;
  214. struct list_head tx_list;
  215. struct dma_async_tx_descriptor txd;
  216. size_t len;
  217. };
  218. #ifdef TXX9_DMA_USE_SIMPLE_CHAIN
  219. static inline bool txx9dmac_chan_INTENT(struct txx9dmac_chan *dc)
  220. {
  221. return (dc->ccr & TXX9_DMA_CCR_INTENT) != 0;
  222. }
  223. static inline void txx9dmac_chan_set_INTENT(struct txx9dmac_chan *dc)
  224. {
  225. dc->ccr |= TXX9_DMA_CCR_INTENT;
  226. }
  227. static inline void txx9dmac_desc_set_INTENT(struct txx9dmac_dev *ddev,
  228. struct txx9dmac_desc *desc)
  229. {
  230. }
  231. static inline void txx9dmac_chan_set_SMPCHN(struct txx9dmac_chan *dc)
  232. {
  233. dc->ccr |= TXX9_DMA_CCR_SMPCHN;
  234. }
  235. static inline void txx9dmac_desc_set_nosimple(struct txx9dmac_dev *ddev,
  236. struct txx9dmac_desc *desc,
  237. u32 sair, u32 dair, u32 ccr)
  238. {
  239. }
  240. #else /* TXX9_DMA_USE_SIMPLE_CHAIN */
  241. static inline bool txx9dmac_chan_INTENT(struct txx9dmac_chan *dc)
  242. {
  243. return true;
  244. }
  245. static void txx9dmac_chan_set_INTENT(struct txx9dmac_chan *dc)
  246. {
  247. }
  248. static inline void txx9dmac_desc_set_INTENT(struct txx9dmac_dev *ddev,
  249. struct txx9dmac_desc *desc)
  250. {
  251. if (__is_dmac64(ddev))
  252. desc->hwdesc.CCR |= TXX9_DMA_CCR_INTENT;
  253. else
  254. desc->hwdesc32.CCR |= TXX9_DMA_CCR_INTENT;
  255. }
  256. static inline void txx9dmac_chan_set_SMPCHN(struct txx9dmac_chan *dc)
  257. {
  258. }
  259. static inline void txx9dmac_desc_set_nosimple(struct txx9dmac_dev *ddev,
  260. struct txx9dmac_desc *desc,
  261. u32 sai, u32 dai, u32 ccr)
  262. {
  263. if (__is_dmac64(ddev)) {
  264. desc->hwdesc.SAIR = sai;
  265. desc->hwdesc.DAIR = dai;
  266. desc->hwdesc.CCR = ccr;
  267. } else {
  268. desc->hwdesc32.SAIR = sai;
  269. desc->hwdesc32.DAIR = dai;
  270. desc->hwdesc32.CCR = ccr;
  271. }
  272. }
  273. #endif /* TXX9_DMA_USE_SIMPLE_CHAIN */
  274. #endif /* TXX9DMAC_H */