dma.h 6.7 KB

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