dma.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Freescale i.MX28 APBH DMA
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * Based on code from LTIB:
  8. * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #ifndef __DMA_H__
  26. #define __DMA_H__
  27. #include <linux/list.h>
  28. #include <linux/compiler.h>
  29. #ifndef CONFIG_ARCH_DMA_PIO_WORDS
  30. #define DMA_PIO_WORDS 15
  31. #else
  32. #define DMA_PIO_WORDS CONFIG_ARCH_DMA_PIO_WORDS
  33. #endif
  34. #define MXS_DMA_ALIGNMENT 32
  35. /*
  36. * MXS DMA channels
  37. */
  38. #if defined(CONFIG_MX23)
  39. enum {
  40. MXS_DMA_CHANNEL_AHB_APBH_LCDIF = 0,
  41. MXS_DMA_CHANNEL_AHB_APBH_SSP0,
  42. MXS_DMA_CHANNEL_AHB_APBH_SSP1,
  43. MXS_DMA_CHANNEL_AHB_APBH_RESERVED0,
  44. MXS_DMA_CHANNEL_AHB_APBH_GPMI0,
  45. MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
  46. MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
  47. MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
  48. MXS_MAX_DMA_CHANNELS,
  49. };
  50. #elif defined(CONFIG_MX28)
  51. enum {
  52. MXS_DMA_CHANNEL_AHB_APBH_SSP0 = 0,
  53. MXS_DMA_CHANNEL_AHB_APBH_SSP1,
  54. MXS_DMA_CHANNEL_AHB_APBH_SSP2,
  55. MXS_DMA_CHANNEL_AHB_APBH_SSP3,
  56. MXS_DMA_CHANNEL_AHB_APBH_GPMI0,
  57. MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
  58. MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
  59. MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
  60. MXS_DMA_CHANNEL_AHB_APBH_GPMI4,
  61. MXS_DMA_CHANNEL_AHB_APBH_GPMI5,
  62. MXS_DMA_CHANNEL_AHB_APBH_GPMI6,
  63. MXS_DMA_CHANNEL_AHB_APBH_GPMI7,
  64. MXS_DMA_CHANNEL_AHB_APBH_HSADC,
  65. MXS_DMA_CHANNEL_AHB_APBH_LCDIF,
  66. MXS_DMA_CHANNEL_AHB_APBH_RESERVED0,
  67. MXS_DMA_CHANNEL_AHB_APBH_RESERVED1,
  68. MXS_MAX_DMA_CHANNELS,
  69. };
  70. #elif defined(CONFIG_MX6)
  71. enum {
  72. MXS_DMA_CHANNEL_AHB_APBH_GPMI0 = 0,
  73. MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
  74. MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
  75. MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
  76. MXS_DMA_CHANNEL_AHB_APBH_GPMI4,
  77. MXS_DMA_CHANNEL_AHB_APBH_GPMI5,
  78. MXS_DMA_CHANNEL_AHB_APBH_GPMI6,
  79. MXS_DMA_CHANNEL_AHB_APBH_GPMI7,
  80. MXS_MAX_DMA_CHANNELS,
  81. };
  82. #endif
  83. /*
  84. * MXS DMA hardware command.
  85. *
  86. * This structure describes the in-memory layout of an entire DMA command,
  87. * including space for the maximum number of PIO accesses. See the appropriate
  88. * reference manual for a detailed description of what these fields mean to the
  89. * DMA hardware.
  90. */
  91. #define MXS_DMA_DESC_COMMAND_MASK 0x3
  92. #define MXS_DMA_DESC_COMMAND_OFFSET 0
  93. #define MXS_DMA_DESC_COMMAND_NO_DMAXFER 0x0
  94. #define MXS_DMA_DESC_COMMAND_DMA_WRITE 0x1
  95. #define MXS_DMA_DESC_COMMAND_DMA_READ 0x2
  96. #define MXS_DMA_DESC_COMMAND_DMA_SENSE 0x3
  97. #define MXS_DMA_DESC_CHAIN (1 << 2)
  98. #define MXS_DMA_DESC_IRQ (1 << 3)
  99. #define MXS_DMA_DESC_NAND_LOCK (1 << 4)
  100. #define MXS_DMA_DESC_NAND_WAIT_4_READY (1 << 5)
  101. #define MXS_DMA_DESC_DEC_SEM (1 << 6)
  102. #define MXS_DMA_DESC_WAIT4END (1 << 7)
  103. #define MXS_DMA_DESC_HALT_ON_TERMINATE (1 << 8)
  104. #define MXS_DMA_DESC_TERMINATE_FLUSH (1 << 9)
  105. #define MXS_DMA_DESC_PIO_WORDS_MASK (0xf << 12)
  106. #define MXS_DMA_DESC_PIO_WORDS_OFFSET 12
  107. #define MXS_DMA_DESC_BYTES_MASK (0xffff << 16)
  108. #define MXS_DMA_DESC_BYTES_OFFSET 16
  109. struct mxs_dma_cmd {
  110. unsigned long next;
  111. unsigned long data;
  112. union {
  113. dma_addr_t address;
  114. unsigned long alternate;
  115. };
  116. unsigned long pio_words[DMA_PIO_WORDS];
  117. };
  118. /*
  119. * MXS DMA command descriptor.
  120. *
  121. * This structure incorporates an MXS DMA hardware command structure, along
  122. * with metadata.
  123. */
  124. #define MXS_DMA_DESC_FIRST (1 << 0)
  125. #define MXS_DMA_DESC_LAST (1 << 1)
  126. #define MXS_DMA_DESC_READY (1 << 31)
  127. struct mxs_dma_desc {
  128. struct mxs_dma_cmd cmd;
  129. unsigned int flags;
  130. dma_addr_t address;
  131. void *buffer;
  132. struct list_head node;
  133. } __aligned(MXS_DMA_ALIGNMENT);
  134. /**
  135. * MXS DMA channel
  136. *
  137. * This structure represents a single DMA channel. The MXS platform code
  138. * maintains an array of these structures to represent every DMA channel in the
  139. * system (see mxs_dma_channels).
  140. */
  141. #define MXS_DMA_FLAGS_IDLE 0
  142. #define MXS_DMA_FLAGS_BUSY (1 << 0)
  143. #define MXS_DMA_FLAGS_FREE 0
  144. #define MXS_DMA_FLAGS_ALLOCATED (1 << 16)
  145. #define MXS_DMA_FLAGS_VALID (1 << 31)
  146. struct mxs_dma_chan {
  147. const char *name;
  148. unsigned long dev;
  149. struct mxs_dma_device *dma;
  150. unsigned int flags;
  151. unsigned int active_num;
  152. unsigned int pending_num;
  153. struct list_head active;
  154. struct list_head done;
  155. };
  156. struct mxs_dma_desc *mxs_dma_desc_alloc(void);
  157. void mxs_dma_desc_free(struct mxs_dma_desc *);
  158. int mxs_dma_desc_append(int channel, struct mxs_dma_desc *pdesc);
  159. int mxs_dma_go(int chan);
  160. void mxs_dma_init(void);
  161. int mxs_dma_init_channel(int chan);
  162. int mxs_dma_release(int chan);
  163. #endif /* __DMA_H__ */