dma.h 6.0 KB

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