dma.h 7.0 KB

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