dma.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 <asm/io.h>
  10. #include <linux/slab.h>
  11. #include <asm/irq.h>
  12. #include <asm/signal.h>
  13. #include <linux/kernel.h>
  14. #include <mach/dma.h>
  15. #include <linux/mm.h>
  16. #include <linux/interrupt.h>
  17. #include <asm/blackfin.h>
  18. #define MAX_DMA_ADDRESS PAGE_OFFSET
  19. /*****************************************************************************
  20. * Generic DMA Declarations
  21. *
  22. ****************************************************************************/
  23. enum dma_chan_status {
  24. DMA_CHANNEL_FREE,
  25. DMA_CHANNEL_REQUESTED,
  26. DMA_CHANNEL_ENABLED,
  27. };
  28. /*-------------------------
  29. * config reg bits value
  30. *-------------------------*/
  31. #define DATA_SIZE_8 0
  32. #define DATA_SIZE_16 1
  33. #define DATA_SIZE_32 2
  34. #define DMA_FLOW_STOP 0
  35. #define DMA_FLOW_AUTO 1
  36. #define DMA_FLOW_ARRAY 4
  37. #define DMA_FLOW_SMALL 6
  38. #define DMA_FLOW_LARGE 7
  39. #define DIMENSION_LINEAR 0
  40. #define DIMENSION_2D 1
  41. #define DIR_READ 0
  42. #define DIR_WRITE 1
  43. #define INTR_DISABLE 0
  44. #define INTR_ON_BUF 2
  45. #define INTR_ON_ROW 3
  46. #define DMA_NOSYNC_KEEP_DMA_BUF 0
  47. #define DMA_SYNC_RESTART 1
  48. struct dmasg {
  49. unsigned long next_desc_addr;
  50. unsigned long start_addr;
  51. unsigned short cfg;
  52. unsigned short x_count;
  53. short x_modify;
  54. unsigned short y_count;
  55. short y_modify;
  56. } __attribute__((packed));
  57. struct dma_register {
  58. unsigned long next_desc_ptr; /* DMA Next Descriptor Pointer register */
  59. unsigned long start_addr; /* DMA Start address register */
  60. unsigned short cfg; /* DMA Configuration register */
  61. unsigned short dummy1; /* DMA Configuration register */
  62. unsigned long reserved;
  63. unsigned short x_count; /* DMA x_count register */
  64. unsigned short dummy2;
  65. short x_modify; /* DMA x_modify register */
  66. unsigned short dummy3;
  67. unsigned short y_count; /* DMA y_count register */
  68. unsigned short dummy4;
  69. short y_modify; /* DMA y_modify register */
  70. unsigned short dummy5;
  71. unsigned long curr_desc_ptr; /* DMA Current Descriptor Pointer
  72. register */
  73. unsigned long curr_addr_ptr; /* DMA Current Address Pointer
  74. register */
  75. unsigned short irq_status; /* DMA irq status register */
  76. unsigned short dummy6;
  77. unsigned short peripheral_map; /* DMA peripheral map register */
  78. unsigned short dummy7;
  79. unsigned short curr_x_count; /* DMA Current x-count register */
  80. unsigned short dummy8;
  81. unsigned long reserved2;
  82. unsigned short curr_y_count; /* DMA Current y-count register */
  83. unsigned short dummy9;
  84. unsigned long reserved3;
  85. };
  86. struct dma_channel {
  87. struct mutex dmalock;
  88. const char *device_id;
  89. enum dma_chan_status chan_status;
  90. struct dma_register *regs;
  91. struct dmasg *sg; /* large mode descriptor */
  92. unsigned int ctrl_num; /* controller number */
  93. unsigned int irq;
  94. irq_handler_t irq_callback;
  95. void *data;
  96. unsigned int dma_enable_flag;
  97. unsigned int loopback_flag;
  98. #ifdef CONFIG_PM
  99. unsigned short saved_peripheral_map;
  100. #endif
  101. };
  102. #ifdef CONFIG_PM
  103. int blackfin_dma_suspend(void);
  104. void blackfin_dma_resume(void);
  105. #endif
  106. /*******************************************************************************
  107. * DMA API's
  108. *******************************************************************************/
  109. /* functions to set register mode */
  110. void set_dma_start_addr(unsigned int channel, unsigned long addr);
  111. void set_dma_next_desc_addr(unsigned int channel, unsigned long addr);
  112. void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr);
  113. void set_dma_x_count(unsigned int channel, unsigned short x_count);
  114. void set_dma_x_modify(unsigned int channel, short x_modify);
  115. void set_dma_y_count(unsigned int channel, unsigned short y_count);
  116. void set_dma_y_modify(unsigned int channel, short y_modify);
  117. void set_dma_config(unsigned int channel, unsigned short config);
  118. unsigned short set_bfin_dma_config(char direction, char flow_mode,
  119. char intr_mode, char dma_mode, char width,
  120. char syncmode);
  121. void set_dma_curr_addr(unsigned int channel, unsigned long addr);
  122. /* get curr status for polling */
  123. unsigned short get_dma_curr_irqstat(unsigned int channel);
  124. unsigned short get_dma_curr_xcount(unsigned int channel);
  125. unsigned short get_dma_curr_ycount(unsigned int channel);
  126. unsigned long get_dma_next_desc_ptr(unsigned int channel);
  127. unsigned long get_dma_curr_desc_ptr(unsigned int channel);
  128. unsigned long get_dma_curr_addr(unsigned int channel);
  129. /* set large DMA mode descriptor */
  130. void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg);
  131. /* check if current channel is in use */
  132. int dma_channel_active(unsigned int channel);
  133. /* common functions must be called in any mode */
  134. void free_dma(unsigned int channel);
  135. int dma_channel_active(unsigned int channel); /* check if a channel is in use */
  136. void disable_dma(unsigned int channel);
  137. void enable_dma(unsigned int channel);
  138. int request_dma(unsigned int channel, const char *device_id);
  139. int set_dma_callback(unsigned int channel, irq_handler_t callback,
  140. void *data);
  141. void dma_disable_irq(unsigned int channel);
  142. void dma_enable_irq(unsigned int channel);
  143. void clear_dma_irqstat(unsigned int channel);
  144. void *dma_memcpy(void *dest, const void *src, size_t count);
  145. void *safe_dma_memcpy(void *dest, const void *src, size_t count);
  146. void blackfin_dma_early_init(void);
  147. extern int channel2irq(unsigned int channel);
  148. extern struct dma_register *dma_io_base_addr[MAX_DMA_CHANNELS];
  149. #endif