dma.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #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. #define DMA_FLOW_STOP 0
  23. #define DMA_FLOW_AUTO 1
  24. #define DMA_FLOW_ARRAY 4
  25. #define DMA_FLOW_SMALL 6
  26. #define DMA_FLOW_LARGE 7
  27. #define DIMENSION_LINEAR 0
  28. #define DIMENSION_2D 1
  29. #define DIR_READ 0
  30. #define DIR_WRITE 1
  31. #define INTR_DISABLE 0
  32. #define INTR_ON_BUF 2
  33. #define INTR_ON_ROW 3
  34. #define DMA_NOSYNC_KEEP_DMA_BUF 0
  35. #define DMA_SYNC_RESTART 1
  36. struct dmasg {
  37. void *next_desc_addr;
  38. unsigned long start_addr;
  39. unsigned short cfg;
  40. unsigned short x_count;
  41. short x_modify;
  42. unsigned short y_count;
  43. short y_modify;
  44. } __attribute__((packed));
  45. struct dma_register {
  46. void *next_desc_ptr; /* DMA Next Descriptor Pointer register */
  47. unsigned long start_addr; /* DMA Start address register */
  48. unsigned short cfg; /* DMA Configuration register */
  49. unsigned short dummy1; /* DMA Configuration register */
  50. unsigned long reserved;
  51. unsigned short x_count; /* DMA x_count register */
  52. unsigned short dummy2;
  53. short x_modify; /* DMA x_modify register */
  54. unsigned short dummy3;
  55. unsigned short y_count; /* DMA y_count register */
  56. unsigned short dummy4;
  57. short y_modify; /* DMA y_modify register */
  58. unsigned short dummy5;
  59. void *curr_desc_ptr; /* DMA Current Descriptor Pointer
  60. register */
  61. unsigned long curr_addr_ptr; /* DMA Current Address Pointer
  62. register */
  63. unsigned short irq_status; /* DMA irq status register */
  64. unsigned short dummy6;
  65. unsigned short peripheral_map; /* DMA peripheral map register */
  66. unsigned short dummy7;
  67. unsigned short curr_x_count; /* DMA Current x-count register */
  68. unsigned short dummy8;
  69. unsigned long reserved2;
  70. unsigned short curr_y_count; /* DMA Current y-count register */
  71. unsigned short dummy9;
  72. unsigned long reserved3;
  73. };
  74. struct dma_channel {
  75. const char *device_id;
  76. atomic_t chan_status;
  77. volatile struct dma_register *regs;
  78. struct dmasg *sg; /* large mode descriptor */
  79. unsigned int irq;
  80. void *data;
  81. #ifdef CONFIG_PM
  82. unsigned short saved_peripheral_map;
  83. #endif
  84. };
  85. #ifdef CONFIG_PM
  86. int blackfin_dma_suspend(void);
  87. void blackfin_dma_resume(void);
  88. #endif
  89. /*******************************************************************************
  90. * DMA API's
  91. *******************************************************************************/
  92. extern struct dma_channel dma_ch[MAX_DMA_CHANNELS];
  93. extern struct dma_register * const dma_io_base_addr[MAX_DMA_CHANNELS];
  94. extern int channel2irq(unsigned int channel);
  95. static inline void set_dma_start_addr(unsigned int channel, unsigned long addr)
  96. {
  97. dma_ch[channel].regs->start_addr = addr;
  98. }
  99. static inline void set_dma_next_desc_addr(unsigned int channel, void *addr)
  100. {
  101. dma_ch[channel].regs->next_desc_ptr = addr;
  102. }
  103. static inline void set_dma_curr_desc_addr(unsigned int channel, void *addr)
  104. {
  105. dma_ch[channel].regs->curr_desc_ptr = addr;
  106. }
  107. static inline void set_dma_x_count(unsigned int channel, unsigned short x_count)
  108. {
  109. dma_ch[channel].regs->x_count = x_count;
  110. }
  111. static inline void set_dma_y_count(unsigned int channel, unsigned short y_count)
  112. {
  113. dma_ch[channel].regs->y_count = y_count;
  114. }
  115. static inline void set_dma_x_modify(unsigned int channel, short x_modify)
  116. {
  117. dma_ch[channel].regs->x_modify = x_modify;
  118. }
  119. static inline void set_dma_y_modify(unsigned int channel, short y_modify)
  120. {
  121. dma_ch[channel].regs->y_modify = y_modify;
  122. }
  123. static inline void set_dma_config(unsigned int channel, unsigned short config)
  124. {
  125. dma_ch[channel].regs->cfg = config;
  126. }
  127. static inline void set_dma_curr_addr(unsigned int channel, unsigned long addr)
  128. {
  129. dma_ch[channel].regs->curr_addr_ptr = addr;
  130. }
  131. static inline unsigned short
  132. set_bfin_dma_config(char direction, char flow_mode,
  133. char intr_mode, char dma_mode, char width, char syncmode)
  134. {
  135. return (direction << 1) | (width << 2) | (dma_mode << 4) |
  136. (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5);
  137. }
  138. static inline unsigned short get_dma_curr_irqstat(unsigned int channel)
  139. {
  140. return dma_ch[channel].regs->irq_status;
  141. }
  142. static inline unsigned short get_dma_curr_xcount(unsigned int channel)
  143. {
  144. return dma_ch[channel].regs->curr_x_count;
  145. }
  146. static inline unsigned short get_dma_curr_ycount(unsigned int channel)
  147. {
  148. return dma_ch[channel].regs->curr_y_count;
  149. }
  150. static inline void *get_dma_next_desc_ptr(unsigned int channel)
  151. {
  152. return dma_ch[channel].regs->next_desc_ptr;
  153. }
  154. static inline void *get_dma_curr_desc_ptr(unsigned int channel)
  155. {
  156. return dma_ch[channel].regs->curr_desc_ptr;
  157. }
  158. static inline unsigned short get_dma_config(unsigned int channel)
  159. {
  160. return dma_ch[channel].regs->cfg;
  161. }
  162. static inline unsigned long get_dma_curr_addr(unsigned int channel)
  163. {
  164. return dma_ch[channel].regs->curr_addr_ptr;
  165. }
  166. static inline void set_dma_sg(unsigned int channel, struct dmasg *sg, int ndsize)
  167. {
  168. /* Make sure the internal data buffers in the core are drained
  169. * so that the DMA descriptors are completely written when the
  170. * DMA engine goes to fetch them below.
  171. */
  172. SSYNC();
  173. dma_ch[channel].regs->next_desc_ptr = sg;
  174. dma_ch[channel].regs->cfg =
  175. (dma_ch[channel].regs->cfg & ~(0xf << 8)) |
  176. ((ndsize & 0xf) << 8);
  177. }
  178. static inline int dma_channel_active(unsigned int channel)
  179. {
  180. return atomic_read(&dma_ch[channel].chan_status);
  181. }
  182. static inline void disable_dma(unsigned int channel)
  183. {
  184. dma_ch[channel].regs->cfg &= ~DMAEN;
  185. SSYNC();
  186. }
  187. static inline void enable_dma(unsigned int channel)
  188. {
  189. dma_ch[channel].regs->curr_x_count = 0;
  190. dma_ch[channel].regs->curr_y_count = 0;
  191. dma_ch[channel].regs->cfg |= DMAEN;
  192. }
  193. int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data);
  194. static inline void dma_disable_irq(unsigned int channel)
  195. {
  196. disable_irq(dma_ch[channel].irq);
  197. }
  198. static inline void dma_disable_irq_nosync(unsigned int channel)
  199. {
  200. disable_irq_nosync(dma_ch[channel].irq);
  201. }
  202. static inline void dma_enable_irq(unsigned int channel)
  203. {
  204. enable_irq(dma_ch[channel].irq);
  205. }
  206. static inline void clear_dma_irqstat(unsigned int channel)
  207. {
  208. dma_ch[channel].regs->irq_status = DMA_DONE | DMA_ERR;
  209. }
  210. void *dma_memcpy(void *dest, const void *src, size_t count);
  211. void *dma_memcpy_nocache(void *dest, const void *src, size_t count);
  212. void *safe_dma_memcpy(void *dest, const void *src, size_t count);
  213. void blackfin_dma_early_init(void);
  214. void early_dma_memcpy(void *dest, const void *src, size_t count);
  215. void early_dma_memcpy_done(void);
  216. #endif