dma.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 <linux/atomic.h>
  12. #include <asm/blackfin.h>
  13. #include <asm/page.h>
  14. #include <asm-generic/dma.h>
  15. #include <asm/bfin_dma.h>
  16. /*-------------------------
  17. * config reg bits value
  18. *-------------------------*/
  19. #define DATA_SIZE_8 0
  20. #define DATA_SIZE_16 1
  21. #define DATA_SIZE_32 2
  22. #ifdef CONFIG_BF60x
  23. #define DATA_SIZE_64 3
  24. #endif
  25. #define DMA_FLOW_STOP 0
  26. #define DMA_FLOW_AUTO 1
  27. #ifdef CONFIG_BF60x
  28. #define DMA_FLOW_LIST 4
  29. #define DMA_FLOW_ARRAY 5
  30. #define DMA_FLOW_LIST_DEMAND 6
  31. #define DMA_FLOW_ARRAY_DEMAND 7
  32. #else
  33. #define DMA_FLOW_ARRAY 4
  34. #define DMA_FLOW_SMALL 6
  35. #define DMA_FLOW_LARGE 7
  36. #endif
  37. #define DIMENSION_LINEAR 0
  38. #define DIMENSION_2D 1
  39. #define DIR_READ 0
  40. #define DIR_WRITE 1
  41. #define INTR_DISABLE 0
  42. #ifdef CONFIG_BF60x
  43. #define INTR_ON_PERI 1
  44. #endif
  45. #define INTR_ON_BUF 2
  46. #define INTR_ON_ROW 3
  47. #define DMA_NOSYNC_KEEP_DMA_BUF 0
  48. #define DMA_SYNC_RESTART 1
  49. #ifdef DMA_MMR_SIZE_32
  50. #define DMA_MMR_SIZE_TYPE long
  51. #define DMA_MMR_READ bfin_read32
  52. #define DMA_MMR_WRITE bfin_write32
  53. #else
  54. #define DMA_MMR_SIZE_TYPE short
  55. #define DMA_MMR_READ bfin_read16
  56. #define DMA_MMR_WRITE bfin_write16
  57. #endif
  58. struct dma_desc_array {
  59. unsigned long start_addr;
  60. unsigned DMA_MMR_SIZE_TYPE cfg;
  61. unsigned DMA_MMR_SIZE_TYPE x_count;
  62. DMA_MMR_SIZE_TYPE x_modify;
  63. } __attribute__((packed));
  64. struct dmasg {
  65. void *next_desc_addr;
  66. unsigned long start_addr;
  67. unsigned DMA_MMR_SIZE_TYPE cfg;
  68. unsigned DMA_MMR_SIZE_TYPE x_count;
  69. DMA_MMR_SIZE_TYPE x_modify;
  70. unsigned DMA_MMR_SIZE_TYPE y_count;
  71. DMA_MMR_SIZE_TYPE y_modify;
  72. } __attribute__((packed));
  73. struct dma_register {
  74. void *next_desc_ptr; /* DMA Next Descriptor Pointer register */
  75. unsigned long start_addr; /* DMA Start address register */
  76. #ifdef CONFIG_BF60x
  77. unsigned long cfg; /* DMA Configuration register */
  78. unsigned long x_count; /* DMA x_count register */
  79. long x_modify; /* DMA x_modify register */
  80. unsigned long y_count; /* DMA y_count register */
  81. long y_modify; /* DMA y_modify register */
  82. unsigned long reserved;
  83. unsigned long reserved2;
  84. void *curr_desc_ptr; /* DMA Current Descriptor Pointer
  85. register */
  86. void *prev_desc_ptr; /* DMA previous initial Descriptor Pointer
  87. register */
  88. unsigned long curr_addr_ptr; /* DMA Current Address Pointer
  89. register */
  90. unsigned long irq_status; /* DMA irq status register */
  91. unsigned long curr_x_count; /* DMA Current x-count register */
  92. unsigned long curr_y_count; /* DMA Current y-count register */
  93. unsigned long reserved3;
  94. unsigned long bw_limit_count; /* DMA band width limit count register */
  95. unsigned long curr_bw_limit_count; /* DMA Current band width limit
  96. count register */
  97. unsigned long bw_monitor_count; /* DMA band width limit count register */
  98. unsigned long curr_bw_monitor_count; /* DMA Current band width limit
  99. count register */
  100. #else
  101. unsigned short cfg; /* DMA Configuration register */
  102. unsigned short dummy1; /* DMA Configuration register */
  103. unsigned long reserved;
  104. unsigned short x_count; /* DMA x_count register */
  105. unsigned short dummy2;
  106. short x_modify; /* DMA x_modify register */
  107. unsigned short dummy3;
  108. unsigned short y_count; /* DMA y_count register */
  109. unsigned short dummy4;
  110. short y_modify; /* DMA y_modify register */
  111. unsigned short dummy5;
  112. void *curr_desc_ptr; /* DMA Current Descriptor Pointer
  113. register */
  114. unsigned long curr_addr_ptr; /* DMA Current Address Pointer
  115. register */
  116. unsigned short irq_status; /* DMA irq status register */
  117. unsigned short dummy6;
  118. unsigned short peripheral_map; /* DMA peripheral map register */
  119. unsigned short dummy7;
  120. unsigned short curr_x_count; /* DMA Current x-count register */
  121. unsigned short dummy8;
  122. unsigned long reserved2;
  123. unsigned short curr_y_count; /* DMA Current y-count register */
  124. unsigned short dummy9;
  125. unsigned long reserved3;
  126. #endif
  127. };
  128. struct dma_channel {
  129. const char *device_id;
  130. atomic_t chan_status;
  131. volatile struct dma_register *regs;
  132. struct dmasg *sg; /* large mode descriptor */
  133. unsigned int irq;
  134. void *data;
  135. #ifdef CONFIG_PM
  136. unsigned short saved_peripheral_map;
  137. #endif
  138. };
  139. #ifdef CONFIG_PM
  140. int blackfin_dma_suspend(void);
  141. void blackfin_dma_resume(void);
  142. #endif
  143. /*******************************************************************************
  144. * DMA API's
  145. *******************************************************************************/
  146. extern struct dma_channel dma_ch[MAX_DMA_CHANNELS];
  147. extern struct dma_register * const dma_io_base_addr[MAX_DMA_CHANNELS];
  148. extern int channel2irq(unsigned int channel);
  149. static inline void set_dma_start_addr(unsigned int channel, unsigned long addr)
  150. {
  151. dma_ch[channel].regs->start_addr = addr;
  152. }
  153. static inline void set_dma_next_desc_addr(unsigned int channel, void *addr)
  154. {
  155. dma_ch[channel].regs->next_desc_ptr = addr;
  156. }
  157. static inline void set_dma_curr_desc_addr(unsigned int channel, void *addr)
  158. {
  159. dma_ch[channel].regs->curr_desc_ptr = addr;
  160. }
  161. static inline void set_dma_x_count(unsigned int channel, unsigned DMA_MMR_SIZE_TYPE x_count)
  162. {
  163. dma_ch[channel].regs->x_count = x_count;
  164. }
  165. static inline void set_dma_y_count(unsigned int channel, unsigned DMA_MMR_SIZE_TYPE y_count)
  166. {
  167. dma_ch[channel].regs->y_count = y_count;
  168. }
  169. static inline void set_dma_x_modify(unsigned int channel, DMA_MMR_SIZE_TYPE x_modify)
  170. {
  171. dma_ch[channel].regs->x_modify = x_modify;
  172. }
  173. static inline void set_dma_y_modify(unsigned int channel, DMA_MMR_SIZE_TYPE y_modify)
  174. {
  175. dma_ch[channel].regs->y_modify = y_modify;
  176. }
  177. static inline void set_dma_config(unsigned int channel, unsigned DMA_MMR_SIZE_TYPE config)
  178. {
  179. dma_ch[channel].regs->cfg = config;
  180. }
  181. static inline void set_dma_curr_addr(unsigned int channel, unsigned long addr)
  182. {
  183. dma_ch[channel].regs->curr_addr_ptr = addr;
  184. }
  185. #ifdef CONFIG_BF60x
  186. static inline unsigned long
  187. set_bfin_dma_config2(char direction, char flow_mode, char intr_mode,
  188. char dma_mode, char mem_width, char syncmode, char peri_width)
  189. {
  190. unsigned long config = 0;
  191. switch (intr_mode) {
  192. case INTR_ON_BUF:
  193. if (dma_mode == DIMENSION_2D)
  194. config = DI_EN_Y;
  195. else
  196. config = DI_EN_X;
  197. break;
  198. case INTR_ON_ROW:
  199. config = DI_EN_X;
  200. break;
  201. case INTR_ON_PERI:
  202. config = DI_EN_P;
  203. break;
  204. };
  205. return config | (direction << 1) | (mem_width << 8) | (dma_mode << 26) |
  206. (flow_mode << 12) | (syncmode << 2) | (peri_width << 4);
  207. }
  208. #endif
  209. static inline unsigned DMA_MMR_SIZE_TYPE
  210. set_bfin_dma_config(char direction, char flow_mode,
  211. char intr_mode, char dma_mode, char mem_width, char syncmode)
  212. {
  213. #ifdef CONFIG_BF60x
  214. return set_bfin_dma_config2(direction, flow_mode, intr_mode, dma_mode,
  215. mem_width, syncmode, mem_width);
  216. #else
  217. return (direction << 1) | (mem_width << 2) | (dma_mode << 4) |
  218. (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5);
  219. #endif
  220. }
  221. static inline unsigned DMA_MMR_SIZE_TYPE get_dma_curr_irqstat(unsigned int channel)
  222. {
  223. return dma_ch[channel].regs->irq_status;
  224. }
  225. static inline unsigned DMA_MMR_SIZE_TYPE get_dma_curr_xcount(unsigned int channel)
  226. {
  227. return dma_ch[channel].regs->curr_x_count;
  228. }
  229. static inline unsigned DMA_MMR_SIZE_TYPE get_dma_curr_ycount(unsigned int channel)
  230. {
  231. return dma_ch[channel].regs->curr_y_count;
  232. }
  233. static inline void *get_dma_next_desc_ptr(unsigned int channel)
  234. {
  235. return dma_ch[channel].regs->next_desc_ptr;
  236. }
  237. static inline void *get_dma_curr_desc_ptr(unsigned int channel)
  238. {
  239. return dma_ch[channel].regs->curr_desc_ptr;
  240. }
  241. static inline unsigned DMA_MMR_SIZE_TYPE get_dma_config(unsigned int channel)
  242. {
  243. return dma_ch[channel].regs->cfg;
  244. }
  245. static inline unsigned long get_dma_curr_addr(unsigned int channel)
  246. {
  247. return dma_ch[channel].regs->curr_addr_ptr;
  248. }
  249. static inline void set_dma_sg(unsigned int channel, struct dmasg *sg, int ndsize)
  250. {
  251. /* Make sure the internal data buffers in the core are drained
  252. * so that the DMA descriptors are completely written when the
  253. * DMA engine goes to fetch them below.
  254. */
  255. SSYNC();
  256. dma_ch[channel].regs->next_desc_ptr = sg;
  257. dma_ch[channel].regs->cfg =
  258. (dma_ch[channel].regs->cfg & ~NDSIZE) |
  259. ((ndsize << NDSIZE_OFFSET) & NDSIZE);
  260. }
  261. static inline int dma_channel_active(unsigned int channel)
  262. {
  263. return atomic_read(&dma_ch[channel].chan_status);
  264. }
  265. static inline void disable_dma(unsigned int channel)
  266. {
  267. dma_ch[channel].regs->cfg &= ~DMAEN;
  268. SSYNC();
  269. }
  270. static inline void enable_dma(unsigned int channel)
  271. {
  272. dma_ch[channel].regs->curr_x_count = 0;
  273. dma_ch[channel].regs->curr_y_count = 0;
  274. dma_ch[channel].regs->cfg |= DMAEN;
  275. }
  276. int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data);
  277. static inline void dma_disable_irq(unsigned int channel)
  278. {
  279. disable_irq(dma_ch[channel].irq);
  280. }
  281. static inline void dma_disable_irq_nosync(unsigned int channel)
  282. {
  283. disable_irq_nosync(dma_ch[channel].irq);
  284. }
  285. static inline void dma_enable_irq(unsigned int channel)
  286. {
  287. enable_irq(dma_ch[channel].irq);
  288. }
  289. static inline void clear_dma_irqstat(unsigned int channel)
  290. {
  291. dma_ch[channel].regs->irq_status = DMA_DONE | DMA_ERR | DMA_PIRQ;
  292. }
  293. void *dma_memcpy(void *dest, const void *src, size_t count);
  294. void *dma_memcpy_nocache(void *dest, const void *src, size_t count);
  295. void *safe_dma_memcpy(void *dest, const void *src, size_t count);
  296. void blackfin_dma_early_init(void);
  297. void early_dma_memcpy(void *dest, const void *src, size_t count);
  298. void early_dma_memcpy_done(void);
  299. #endif