dma.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * File: include/asm-blackfin/simple_bf533_dma.h
  3. * Based on: none - original work
  4. * Author: LG Soft India
  5. * Copyright (C) 2004-2005 Analog Devices Inc.
  6. * Created: Tue Sep 21 2004
  7. * Description: This file contains the major Data structures and constants
  8. * used for DMA Implementation in BF533
  9. * Modified:
  10. *
  11. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2, or (at your option)
  16. * any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; see the file COPYING.
  25. * If not, write to the Free Software Foundation,
  26. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. */
  28. #ifndef _BLACKFIN_DMA_H_
  29. #define _BLACKFIN_DMA_H_
  30. #include <asm/io.h>
  31. #include <linux/slab.h>
  32. #include <asm/irq.h>
  33. #include <asm/signal.h>
  34. #include <linux/kernel.h>
  35. #include <mach/dma.h>
  36. #include <linux/mm.h>
  37. #include <linux/interrupt.h>
  38. #include <asm/blackfin.h>
  39. #define MAX_DMA_ADDRESS PAGE_OFFSET
  40. /*****************************************************************************
  41. * Generic DMA Declarations
  42. *
  43. ****************************************************************************/
  44. enum dma_chan_status {
  45. DMA_CHANNEL_FREE,
  46. DMA_CHANNEL_REQUESTED,
  47. DMA_CHANNEL_ENABLED,
  48. };
  49. /*-------------------------
  50. * config reg bits value
  51. *-------------------------*/
  52. #define DATA_SIZE_8 0
  53. #define DATA_SIZE_16 1
  54. #define DATA_SIZE_32 2
  55. #define DMA_FLOW_STOP 0
  56. #define DMA_FLOW_AUTO 1
  57. #define DMA_FLOW_ARRAY 4
  58. #define DMA_FLOW_SMALL 6
  59. #define DMA_FLOW_LARGE 7
  60. #define DIMENSION_LINEAR 0
  61. #define DIMENSION_2D 1
  62. #define DIR_READ 0
  63. #define DIR_WRITE 1
  64. #define INTR_DISABLE 0
  65. #define INTR_ON_BUF 2
  66. #define INTR_ON_ROW 3
  67. #define DMA_NOSYNC_KEEP_DMA_BUF 0
  68. #define DMA_SYNC_RESTART 1
  69. struct dmasg {
  70. unsigned long next_desc_addr;
  71. unsigned long start_addr;
  72. unsigned short cfg;
  73. unsigned short x_count;
  74. short x_modify;
  75. unsigned short y_count;
  76. short y_modify;
  77. } __attribute__((packed));
  78. struct dma_register {
  79. unsigned long next_desc_ptr; /* DMA Next Descriptor Pointer register */
  80. unsigned long start_addr; /* DMA Start address register */
  81. unsigned short cfg; /* DMA Configuration register */
  82. unsigned short dummy1; /* DMA Configuration register */
  83. unsigned long reserved;
  84. unsigned short x_count; /* DMA x_count register */
  85. unsigned short dummy2;
  86. short x_modify; /* DMA x_modify register */
  87. unsigned short dummy3;
  88. unsigned short y_count; /* DMA y_count register */
  89. unsigned short dummy4;
  90. short y_modify; /* DMA y_modify register */
  91. unsigned short dummy5;
  92. unsigned long curr_desc_ptr; /* DMA Current Descriptor Pointer
  93. register */
  94. unsigned long curr_addr_ptr; /* DMA Current Address Pointer
  95. register */
  96. unsigned short irq_status; /* DMA irq status register */
  97. unsigned short dummy6;
  98. unsigned short peripheral_map; /* DMA peripheral map register */
  99. unsigned short dummy7;
  100. unsigned short curr_x_count; /* DMA Current x-count register */
  101. unsigned short dummy8;
  102. unsigned long reserved2;
  103. unsigned short curr_y_count; /* DMA Current y-count register */
  104. unsigned short dummy9;
  105. unsigned long reserved3;
  106. };
  107. typedef irqreturn_t(*dma_interrupt_t) (int irq, void *dev_id);
  108. struct dma_channel {
  109. struct mutex dmalock;
  110. char *device_id;
  111. enum dma_chan_status chan_status;
  112. struct dma_register *regs;
  113. struct dmasg *sg; /* large mode descriptor */
  114. unsigned int ctrl_num; /* controller number */
  115. dma_interrupt_t irq_callback;
  116. void *data;
  117. unsigned int dma_enable_flag;
  118. unsigned int loopback_flag;
  119. #ifdef CONFIG_PM
  120. unsigned short saved_peripheral_map;
  121. #endif
  122. };
  123. #ifdef CONFIG_PM
  124. int blackfin_dma_suspend(void);
  125. void blackfin_dma_resume(void);
  126. #endif
  127. /*******************************************************************************
  128. * DMA API's
  129. *******************************************************************************/
  130. /* functions to set register mode */
  131. void set_dma_start_addr(unsigned int channel, unsigned long addr);
  132. void set_dma_next_desc_addr(unsigned int channel, unsigned long addr);
  133. void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr);
  134. void set_dma_x_count(unsigned int channel, unsigned short x_count);
  135. void set_dma_x_modify(unsigned int channel, short x_modify);
  136. void set_dma_y_count(unsigned int channel, unsigned short y_count);
  137. void set_dma_y_modify(unsigned int channel, short y_modify);
  138. void set_dma_config(unsigned int channel, unsigned short config);
  139. unsigned short set_bfin_dma_config(char direction, char flow_mode,
  140. char intr_mode, char dma_mode, char width,
  141. char syncmode);
  142. void set_dma_curr_addr(unsigned int channel, unsigned long addr);
  143. /* get curr status for polling */
  144. unsigned short get_dma_curr_irqstat(unsigned int channel);
  145. unsigned short get_dma_curr_xcount(unsigned int channel);
  146. unsigned short get_dma_curr_ycount(unsigned int channel);
  147. unsigned long get_dma_next_desc_ptr(unsigned int channel);
  148. unsigned long get_dma_curr_desc_ptr(unsigned int channel);
  149. unsigned long get_dma_curr_addr(unsigned int channel);
  150. /* set large DMA mode descriptor */
  151. void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg);
  152. /* check if current channel is in use */
  153. int dma_channel_active(unsigned int channel);
  154. /* common functions must be called in any mode */
  155. void free_dma(unsigned int channel);
  156. int dma_channel_active(unsigned int channel); /* check if a channel is in use */
  157. void disable_dma(unsigned int channel);
  158. void enable_dma(unsigned int channel);
  159. int request_dma(unsigned int channel, char *device_id);
  160. int set_dma_callback(unsigned int channel, dma_interrupt_t callback,
  161. void *data);
  162. void dma_disable_irq(unsigned int channel);
  163. void dma_enable_irq(unsigned int channel);
  164. void clear_dma_irqstat(unsigned int channel);
  165. void *dma_memcpy(void *dest, const void *src, size_t count);
  166. void *safe_dma_memcpy(void *dest, const void *src, size_t count);
  167. extern int channel2irq(unsigned int channel);
  168. extern struct dma_register *dma_io_base_addr[MAX_BLACKFIN_DMA_CHANNEL];
  169. #endif