dma.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * dma.h - Blackfin DMA defines/structures/etc...
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. * Licensed under the GPL-2 or later.
  6. */
  7. #ifndef _BLACKFIN_DMA_H_
  8. #define _BLACKFIN_DMA_H_
  9. #include <linux/interrupt.h>
  10. #include <mach/dma.h>
  11. #include <asm/atomic.h>
  12. #include <asm/blackfin.h>
  13. #include <asm/page.h>
  14. #include <asm-generic/dma.h>
  15. /* DMA_CONFIG Masks */
  16. #define DMAEN 0x0001 /* DMA Channel Enable */
  17. #define WNR 0x0002 /* Channel Direction (W/R*) */
  18. #define WDSIZE_8 0x0000 /* Transfer Word Size = 8 */
  19. #define WDSIZE_16 0x0004 /* Transfer Word Size = 16 */
  20. #define WDSIZE_32 0x0008 /* Transfer Word Size = 32 */
  21. #define DMA2D 0x0010 /* DMA Mode (2D/1D*) */
  22. #define RESTART 0x0020 /* DMA Buffer Clear */
  23. #define DI_SEL 0x0040 /* Data Interrupt Timing Select */
  24. #define DI_EN 0x0080 /* Data Interrupt Enable */
  25. #define NDSIZE_0 0x0000 /* Next Descriptor Size = 0 (Stop/Autobuffer) */
  26. #define NDSIZE_1 0x0100 /* Next Descriptor Size = 1 */
  27. #define NDSIZE_2 0x0200 /* Next Descriptor Size = 2 */
  28. #define NDSIZE_3 0x0300 /* Next Descriptor Size = 3 */
  29. #define NDSIZE_4 0x0400 /* Next Descriptor Size = 4 */
  30. #define NDSIZE_5 0x0500 /* Next Descriptor Size = 5 */
  31. #define NDSIZE_6 0x0600 /* Next Descriptor Size = 6 */
  32. #define NDSIZE_7 0x0700 /* Next Descriptor Size = 7 */
  33. #define NDSIZE_8 0x0800 /* Next Descriptor Size = 8 */
  34. #define NDSIZE_9 0x0900 /* Next Descriptor Size = 9 */
  35. #define NDSIZE 0x0f00 /* Next Descriptor Size */
  36. #define DMAFLOW 0x7000 /* Flow Control */
  37. #define DMAFLOW_STOP 0x0000 /* Stop Mode */
  38. #define DMAFLOW_AUTO 0x1000 /* Autobuffer Mode */
  39. #define DMAFLOW_ARRAY 0x4000 /* Descriptor Array Mode */
  40. #define DMAFLOW_SMALL 0x6000 /* Small Model Descriptor List Mode */
  41. #define DMAFLOW_LARGE 0x7000 /* Large Model Descriptor List Mode */
  42. /* DMA_IRQ_STATUS Masks */
  43. #define DMA_DONE 0x0001 /* DMA Completion Interrupt Status */
  44. #define DMA_ERR 0x0002 /* DMA Error Interrupt Status */
  45. #define DFETCH 0x0004 /* DMA Descriptor Fetch Indicator */
  46. #define DMA_RUN 0x0008 /* DMA Channel Running Indicator */
  47. /*-------------------------
  48. * config reg bits value
  49. *-------------------------*/
  50. #define DATA_SIZE_8 0
  51. #define DATA_SIZE_16 1
  52. #define DATA_SIZE_32 2
  53. #define DMA_FLOW_STOP 0
  54. #define DMA_FLOW_AUTO 1
  55. #define DMA_FLOW_ARRAY 4
  56. #define DMA_FLOW_SMALL 6
  57. #define DMA_FLOW_LARGE 7
  58. #define DIMENSION_LINEAR 0
  59. #define DIMENSION_2D 1
  60. #define DIR_READ 0
  61. #define DIR_WRITE 1
  62. #define INTR_DISABLE 0
  63. #define INTR_ON_BUF 2
  64. #define INTR_ON_ROW 3
  65. #define DMA_NOSYNC_KEEP_DMA_BUF 0
  66. #define DMA_SYNC_RESTART 1
  67. struct dmasg {
  68. void *next_desc_addr;
  69. unsigned long start_addr;
  70. unsigned short cfg;
  71. unsigned short x_count;
  72. short x_modify;
  73. unsigned short y_count;
  74. short y_modify;
  75. } __attribute__((packed));
  76. struct dma_register {
  77. void *next_desc_ptr; /* DMA Next Descriptor Pointer register */
  78. unsigned long start_addr; /* DMA Start address register */
  79. unsigned short cfg; /* DMA Configuration register */
  80. unsigned short dummy1; /* DMA Configuration register */
  81. unsigned long reserved;
  82. unsigned short x_count; /* DMA x_count register */
  83. unsigned short dummy2;
  84. short x_modify; /* DMA x_modify register */
  85. unsigned short dummy3;
  86. unsigned short y_count; /* DMA y_count register */
  87. unsigned short dummy4;
  88. short y_modify; /* DMA y_modify register */
  89. unsigned short dummy5;
  90. void *curr_desc_ptr; /* DMA Current Descriptor Pointer
  91. register */
  92. unsigned long curr_addr_ptr; /* DMA Current Address Pointer
  93. register */
  94. unsigned short irq_status; /* DMA irq status register */
  95. unsigned short dummy6;
  96. unsigned short peripheral_map; /* DMA peripheral map register */
  97. unsigned short dummy7;
  98. unsigned short curr_x_count; /* DMA Current x-count register */
  99. unsigned short dummy8;
  100. unsigned long reserved2;
  101. unsigned short curr_y_count; /* DMA Current y-count register */
  102. unsigned short dummy9;
  103. unsigned long reserved3;
  104. };
  105. struct dma_channel {
  106. const char *device_id;
  107. atomic_t chan_status;
  108. volatile struct dma_register *regs;
  109. struct dmasg *sg; /* large mode descriptor */
  110. unsigned int irq;
  111. void *data;
  112. #ifdef CONFIG_PM
  113. unsigned short saved_peripheral_map;
  114. #endif
  115. };
  116. #ifdef CONFIG_PM
  117. int blackfin_dma_suspend(void);
  118. void blackfin_dma_resume(void);
  119. #endif
  120. /*******************************************************************************
  121. * DMA API's
  122. *******************************************************************************/
  123. extern struct dma_channel dma_ch[MAX_DMA_CHANNELS];
  124. extern struct dma_register *dma_io_base_addr[MAX_DMA_CHANNELS];
  125. extern int channel2irq(unsigned int channel);
  126. static inline void set_dma_start_addr(unsigned int channel, unsigned long addr)
  127. {
  128. dma_ch[channel].regs->start_addr = addr;
  129. }
  130. static inline void set_dma_next_desc_addr(unsigned int channel, void *addr)
  131. {
  132. dma_ch[channel].regs->next_desc_ptr = addr;
  133. }
  134. static inline void set_dma_curr_desc_addr(unsigned int channel, void *addr)
  135. {
  136. dma_ch[channel].regs->curr_desc_ptr = addr;
  137. }
  138. static inline void set_dma_x_count(unsigned int channel, unsigned short x_count)
  139. {
  140. dma_ch[channel].regs->x_count = x_count;
  141. }
  142. static inline void set_dma_y_count(unsigned int channel, unsigned short y_count)
  143. {
  144. dma_ch[channel].regs->y_count = y_count;
  145. }
  146. static inline void set_dma_x_modify(unsigned int channel, short x_modify)
  147. {
  148. dma_ch[channel].regs->x_modify = x_modify;
  149. }
  150. static inline void set_dma_y_modify(unsigned int channel, short y_modify)
  151. {
  152. dma_ch[channel].regs->y_modify = y_modify;
  153. }
  154. static inline void set_dma_config(unsigned int channel, unsigned short config)
  155. {
  156. dma_ch[channel].regs->cfg = config;
  157. }
  158. static inline void set_dma_curr_addr(unsigned int channel, unsigned long addr)
  159. {
  160. dma_ch[channel].regs->curr_addr_ptr = addr;
  161. }
  162. static inline unsigned short
  163. set_bfin_dma_config(char direction, char flow_mode,
  164. char intr_mode, char dma_mode, char width, char syncmode)
  165. {
  166. return (direction << 1) | (width << 2) | (dma_mode << 4) |
  167. (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5);
  168. }
  169. static inline unsigned short get_dma_curr_irqstat(unsigned int channel)
  170. {
  171. return dma_ch[channel].regs->irq_status;
  172. }
  173. static inline unsigned short get_dma_curr_xcount(unsigned int channel)
  174. {
  175. return dma_ch[channel].regs->curr_x_count;
  176. }
  177. static inline unsigned short get_dma_curr_ycount(unsigned int channel)
  178. {
  179. return dma_ch[channel].regs->curr_y_count;
  180. }
  181. static inline void *get_dma_next_desc_ptr(unsigned int channel)
  182. {
  183. return dma_ch[channel].regs->next_desc_ptr;
  184. }
  185. static inline void *get_dma_curr_desc_ptr(unsigned int channel)
  186. {
  187. return dma_ch[channel].regs->curr_desc_ptr;
  188. }
  189. static inline unsigned short get_dma_config(unsigned int channel)
  190. {
  191. return dma_ch[channel].regs->cfg;
  192. }
  193. static inline unsigned long get_dma_curr_addr(unsigned int channel)
  194. {
  195. return dma_ch[channel].regs->curr_addr_ptr;
  196. }
  197. static inline void set_dma_sg(unsigned int channel, struct dmasg *sg, int ndsize)
  198. {
  199. /* Make sure the internal data buffers in the core are drained
  200. * so that the DMA descriptors are completely written when the
  201. * DMA engine goes to fetch them below.
  202. */
  203. SSYNC();
  204. dma_ch[channel].regs->next_desc_ptr = sg;
  205. dma_ch[channel].regs->cfg =
  206. (dma_ch[channel].regs->cfg & ~(0xf << 8)) |
  207. ((ndsize & 0xf) << 8);
  208. }
  209. static inline int dma_channel_active(unsigned int channel)
  210. {
  211. return atomic_read(&dma_ch[channel].chan_status);
  212. }
  213. static inline void disable_dma(unsigned int channel)
  214. {
  215. dma_ch[channel].regs->cfg &= ~DMAEN;
  216. SSYNC();
  217. }
  218. static inline void enable_dma(unsigned int channel)
  219. {
  220. dma_ch[channel].regs->curr_x_count = 0;
  221. dma_ch[channel].regs->curr_y_count = 0;
  222. dma_ch[channel].regs->cfg |= DMAEN;
  223. }
  224. int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data);
  225. static inline void dma_disable_irq(unsigned int channel)
  226. {
  227. disable_irq(dma_ch[channel].irq);
  228. }
  229. static inline void dma_enable_irq(unsigned int channel)
  230. {
  231. enable_irq(dma_ch[channel].irq);
  232. }
  233. static inline void clear_dma_irqstat(unsigned int channel)
  234. {
  235. dma_ch[channel].regs->irq_status = DMA_DONE | DMA_ERR;
  236. }
  237. void *dma_memcpy(void *dest, const void *src, size_t count);
  238. void *safe_dma_memcpy(void *dest, const void *src, size_t count);
  239. void blackfin_dma_early_init(void);
  240. void early_dma_memcpy(void *dest, const void *src, size_t count);
  241. void early_dma_memcpy_done(void);
  242. #endif